]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.2.2-2.6.32.55-201201252116.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.32.55-201201252116.patch
CommitLineData
0a5b4650
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 64d4fc6..3b32f7f 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,46 @@ 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+ifeq ($(KBUILD_EXTMOD),)
251+gcc-plugins:
252+ $(Q)$(MAKE) $(build)=tools/gcc
253+else
254+gcc-plugins: ;
255+endif
256+else
257+gcc-plugins:
258+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
259+ $(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.))
260+else
261+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
262+endif
263+ $(Q)echo "PAX_MEMORY_STACKLEAK and constification will be less secure"
264+endif
265+endif
266+
267 include $(srctree)/arch/$(SRCARCH)/Makefile
268
269 ifneq ($(CONFIG_FRAME_WARN),0)
270@@ -647,7 +688,7 @@ export mod_strip_cmd
271
272
273 ifeq ($(KBUILD_EXTMOD),)
274-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
275+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
276
277 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
278 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
279@@ -868,6 +909,7 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
280
281 # The actual objects are generated when descending,
282 # make sure no implicit rule kicks in
283+$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS)
284 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
285
286 # Handle descending into subdirectories listed in $(vmlinux-dirs)
287@@ -877,7 +919,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
288 # Error messages still appears in the original language
289
290 PHONY += $(vmlinux-dirs)
291-$(vmlinux-dirs): prepare scripts
292+$(vmlinux-dirs): gcc-plugins prepare scripts
293 $(Q)$(MAKE) $(build)=$@
294
295 # Build the kernel release string
296@@ -986,6 +1028,7 @@ prepare0: archprepare FORCE
297 $(Q)$(MAKE) $(build)=. missing-syscalls
298
299 # All the preparing..
300+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS),$(KBUILD_CFLAGS))
301 prepare: prepare0
302
303 # The asm symlink changes when $(ARCH) changes.
304@@ -1127,6 +1170,7 @@ all: modules
305 # using awk while concatenating to the final file.
306
307 PHONY += modules
308+modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
309 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
310 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
311 @$(kecho) ' Building modules, stage 2.';
312@@ -1136,7 +1180,7 @@ modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
313
314 # Target to prepare building external modules
315 PHONY += modules_prepare
316-modules_prepare: prepare scripts
317+modules_prepare: gcc-plugins prepare scripts
318
319 # Target to install modules
320 PHONY += modules_install
321@@ -1201,7 +1245,7 @@ MRPROPER_FILES += .config .config.old include/asm .version .old_version \
322 include/linux/autoconf.h include/linux/version.h \
323 include/linux/utsrelease.h \
324 include/linux/bounds.h include/asm*/asm-offsets.h \
325- Module.symvers Module.markers tags TAGS cscope*
326+ Module.symvers Module.markers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
327
328 # clean - Delete most, but leave enough to build external modules
329 #
330@@ -1245,7 +1289,7 @@ distclean: mrproper
331 @find $(srctree) $(RCS_FIND_IGNORE) \
332 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
333 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
334- -o -name '.*.rej' -o -size 0 \
335+ -o -name '.*.rej' -o -name '*.so' -o -size 0 \
336 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
337 -type f -print | xargs rm -f
338
339@@ -1292,6 +1336,7 @@ help:
340 @echo ' modules_prepare - Set up for building external modules'
341 @echo ' tags/TAGS - Generate tags file for editors'
342 @echo ' cscope - Generate cscope index'
343+ @echo ' gtags - Generate GNU GLOBAL index'
344 @echo ' kernelrelease - Output the release version string'
345 @echo ' kernelversion - Output the version stored in Makefile'
346 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
347@@ -1393,6 +1438,7 @@ PHONY += $(module-dirs) modules
348 $(module-dirs): crmodverdir $(objtree)/Module.symvers
349 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
350
351+modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
352 modules: $(module-dirs)
353 @$(kecho) ' Building modules, stage 2.';
354 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
355@@ -1448,7 +1494,7 @@ endif # KBUILD_EXTMOD
356 quiet_cmd_tags = GEN $@
357 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
358
359-tags TAGS cscope: FORCE
360+tags TAGS cscope gtags: FORCE
361 $(call cmd,tags)
362
363 # Scripts to check various things for consistency
364@@ -1513,17 +1559,19 @@ else
365 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
366 endif
367
368-%.s: %.c prepare scripts FORCE
369+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS)
370+%.s: %.c gcc-plugins prepare scripts FORCE
371 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
372 %.i: %.c prepare scripts FORCE
373 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
374-%.o: %.c prepare scripts FORCE
375+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS)
376+%.o: %.c gcc-plugins prepare scripts FORCE
377 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
378 %.lst: %.c prepare scripts FORCE
379 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
380-%.s: %.S prepare scripts FORCE
381+%.s: %.S gcc-plugins prepare scripts FORCE
382 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
383-%.o: %.S prepare scripts FORCE
384+%.o: %.S gcc-plugins prepare scripts FORCE
385 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
386 %.symtypes: %.c prepare scripts FORCE
387 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
388@@ -1533,11 +1581,13 @@ endif
389 $(cmd_crmodverdir)
390 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
391 $(build)=$(build-dir)
392-%/: prepare scripts FORCE
393+%/: KBUILD_CFLAGS += $(GCC_PLUGINS)
394+%/: gcc-plugins prepare scripts FORCE
395 $(cmd_crmodverdir)
396 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
397 $(build)=$(build-dir)
398-%.ko: prepare scripts FORCE
399+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS)
400+%.ko: gcc-plugins prepare scripts FORCE
401 $(cmd_crmodverdir)
402 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
403 $(build)=$(build-dir) $(@:.ko=.o)
404diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
405index 5c75c1b..c82f878 100644
406--- a/arch/alpha/include/asm/elf.h
407+++ b/arch/alpha/include/asm/elf.h
408@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
409
410 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
411
412+#ifdef CONFIG_PAX_ASLR
413+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
414+
415+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
416+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
417+#endif
418+
419 /* $0 is set by ld.so to a pointer to a function which might be
420 registered using atexit. This provides a mean for the dynamic
421 linker to call DT_FINI functions for shared libraries that have
422diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
423index 3f0c59f..cf1e100 100644
424--- a/arch/alpha/include/asm/pgtable.h
425+++ b/arch/alpha/include/asm/pgtable.h
426@@ -101,6 +101,17 @@ struct vm_area_struct;
427 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
428 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
429 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
430+
431+#ifdef CONFIG_PAX_PAGEEXEC
432+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
433+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
434+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
435+#else
436+# define PAGE_SHARED_NOEXEC PAGE_SHARED
437+# define PAGE_COPY_NOEXEC PAGE_COPY
438+# define PAGE_READONLY_NOEXEC PAGE_READONLY
439+#endif
440+
441 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
442
443 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
444diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
445index ebc3c89..20cfa63 100644
446--- a/arch/alpha/kernel/module.c
447+++ b/arch/alpha/kernel/module.c
448@@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
449
450 /* The small sections were sorted to the end of the segment.
451 The following should definitely cover them. */
452- gp = (u64)me->module_core + me->core_size - 0x8000;
453+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
454 got = sechdrs[me->arch.gotsecindex].sh_addr;
455
456 for (i = 0; i < n; i++) {
457diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
458index a94e49c..d71dd44 100644
459--- a/arch/alpha/kernel/osf_sys.c
460+++ b/arch/alpha/kernel/osf_sys.c
461@@ -1172,7 +1172,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
462 /* At this point: (!vma || addr < vma->vm_end). */
463 if (limit - len < addr)
464 return -ENOMEM;
465- if (!vma || addr + len <= vma->vm_start)
466+ if (check_heap_stack_gap(vma, addr, len))
467 return addr;
468 addr = vma->vm_end;
469 vma = vma->vm_next;
470@@ -1208,6 +1208,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
471 merely specific addresses, but regions of memory -- perhaps
472 this feature should be incorporated into all ports? */
473
474+#ifdef CONFIG_PAX_RANDMMAP
475+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
476+#endif
477+
478 if (addr) {
479 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
480 if (addr != (unsigned long) -ENOMEM)
481@@ -1215,8 +1219,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
482 }
483
484 /* Next, try allocating at TASK_UNMAPPED_BASE. */
485- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
486- len, limit);
487+ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
488+
489 if (addr != (unsigned long) -ENOMEM)
490 return addr;
491
492diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
493index 00a31de..2ded0f2 100644
494--- a/arch/alpha/mm/fault.c
495+++ b/arch/alpha/mm/fault.c
496@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
497 __reload_thread(pcb);
498 }
499
500+#ifdef CONFIG_PAX_PAGEEXEC
501+/*
502+ * PaX: decide what to do with offenders (regs->pc = fault address)
503+ *
504+ * returns 1 when task should be killed
505+ * 2 when patched PLT trampoline was detected
506+ * 3 when unpatched PLT trampoline was detected
507+ */
508+static int pax_handle_fetch_fault(struct pt_regs *regs)
509+{
510+
511+#ifdef CONFIG_PAX_EMUPLT
512+ int err;
513+
514+ do { /* PaX: patched PLT emulation #1 */
515+ unsigned int ldah, ldq, jmp;
516+
517+ err = get_user(ldah, (unsigned int *)regs->pc);
518+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
519+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
520+
521+ if (err)
522+ break;
523+
524+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
525+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
526+ jmp == 0x6BFB0000U)
527+ {
528+ unsigned long r27, addr;
529+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
530+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
531+
532+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
533+ err = get_user(r27, (unsigned long *)addr);
534+ if (err)
535+ break;
536+
537+ regs->r27 = r27;
538+ regs->pc = r27;
539+ return 2;
540+ }
541+ } while (0);
542+
543+ do { /* PaX: patched PLT emulation #2 */
544+ unsigned int ldah, lda, br;
545+
546+ err = get_user(ldah, (unsigned int *)regs->pc);
547+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
548+ err |= get_user(br, (unsigned int *)(regs->pc+8));
549+
550+ if (err)
551+ break;
552+
553+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
554+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
555+ (br & 0xFFE00000U) == 0xC3E00000U)
556+ {
557+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
558+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
559+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
560+
561+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
562+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
563+ return 2;
564+ }
565+ } while (0);
566+
567+ do { /* PaX: unpatched PLT emulation */
568+ unsigned int br;
569+
570+ err = get_user(br, (unsigned int *)regs->pc);
571+
572+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
573+ unsigned int br2, ldq, nop, jmp;
574+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
575+
576+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
577+ err = get_user(br2, (unsigned int *)addr);
578+ err |= get_user(ldq, (unsigned int *)(addr+4));
579+ err |= get_user(nop, (unsigned int *)(addr+8));
580+ err |= get_user(jmp, (unsigned int *)(addr+12));
581+ err |= get_user(resolver, (unsigned long *)(addr+16));
582+
583+ if (err)
584+ break;
585+
586+ if (br2 == 0xC3600000U &&
587+ ldq == 0xA77B000CU &&
588+ nop == 0x47FF041FU &&
589+ jmp == 0x6B7B0000U)
590+ {
591+ regs->r28 = regs->pc+4;
592+ regs->r27 = addr+16;
593+ regs->pc = resolver;
594+ return 3;
595+ }
596+ }
597+ } while (0);
598+#endif
599+
600+ return 1;
601+}
602+
603+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
604+{
605+ unsigned long i;
606+
607+ printk(KERN_ERR "PAX: bytes at PC: ");
608+ for (i = 0; i < 5; i++) {
609+ unsigned int c;
610+ if (get_user(c, (unsigned int *)pc+i))
611+ printk(KERN_CONT "???????? ");
612+ else
613+ printk(KERN_CONT "%08x ", c);
614+ }
615+ printk("\n");
616+}
617+#endif
618
619 /*
620 * This routine handles page faults. It determines the address,
621@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
622 good_area:
623 si_code = SEGV_ACCERR;
624 if (cause < 0) {
625- if (!(vma->vm_flags & VM_EXEC))
626+ if (!(vma->vm_flags & VM_EXEC)) {
627+
628+#ifdef CONFIG_PAX_PAGEEXEC
629+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
630+ goto bad_area;
631+
632+ up_read(&mm->mmap_sem);
633+ switch (pax_handle_fetch_fault(regs)) {
634+
635+#ifdef CONFIG_PAX_EMUPLT
636+ case 2:
637+ case 3:
638+ return;
639+#endif
640+
641+ }
642+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
643+ do_group_exit(SIGKILL);
644+#else
645 goto bad_area;
646+#endif
647+
648+ }
649 } else if (!cause) {
650 /* Allow reads even for write-only mappings */
651 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
652diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
653index 6aac3f5..265536b 100644
654--- a/arch/arm/include/asm/elf.h
655+++ b/arch/arm/include/asm/elf.h
656@@ -109,7 +109,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
657 the loader. We need to make sure that it is out of the way of the program
658 that it will "exec", and that there is sufficient room for the brk. */
659
660-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
661+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
662+
663+#ifdef CONFIG_PAX_ASLR
664+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
665+
666+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
667+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
668+#endif
669
670 /* When the program starts, a1 contains a pointer to a function to be
671 registered with atexit, as per the SVR4 ABI. A value of 0 means we
672diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
673index c019949..388fdd1 100644
674--- a/arch/arm/include/asm/kmap_types.h
675+++ b/arch/arm/include/asm/kmap_types.h
676@@ -19,6 +19,7 @@ enum km_type {
677 KM_SOFTIRQ0,
678 KM_SOFTIRQ1,
679 KM_L2_CACHE,
680+ KM_CLEARPAGE,
681 KM_TYPE_NR
682 };
683
684diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
685index 1d6bd40..fba0cb9 100644
686--- a/arch/arm/include/asm/uaccess.h
687+++ b/arch/arm/include/asm/uaccess.h
688@@ -22,6 +22,8 @@
689 #define VERIFY_READ 0
690 #define VERIFY_WRITE 1
691
692+extern void check_object_size(const void *ptr, unsigned long n, bool to);
693+
694 /*
695 * The exception table consists of pairs of addresses: the first is the
696 * address of an instruction that is allowed to fault, and the second is
697@@ -387,8 +389,23 @@ do { \
698
699
700 #ifdef CONFIG_MMU
701-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
702-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
703+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
704+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
705+
706+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
707+{
708+ if (!__builtin_constant_p(n))
709+ check_object_size(to, n, false);
710+ return ___copy_from_user(to, from, n);
711+}
712+
713+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
714+{
715+ if (!__builtin_constant_p(n))
716+ check_object_size(from, n, true);
717+ return ___copy_to_user(to, from, n);
718+}
719+
720 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
721 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
722 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
723@@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
724
725 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
726 {
727+ if ((long)n < 0)
728+ return n;
729+
730 if (access_ok(VERIFY_READ, from, n))
731 n = __copy_from_user(to, from, n);
732 else /* security hole - plug it */
733@@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
734
735 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
736 {
737+ if ((long)n < 0)
738+ return n;
739+
740 if (access_ok(VERIFY_WRITE, to, n))
741 n = __copy_to_user(to, from, n);
742 return n;
743diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
744index 0e62770..e2c2cd6 100644
745--- a/arch/arm/kernel/armksyms.c
746+++ b/arch/arm/kernel/armksyms.c
747@@ -118,8 +118,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
748 #ifdef CONFIG_MMU
749 EXPORT_SYMBOL(copy_page);
750
751-EXPORT_SYMBOL(__copy_from_user);
752-EXPORT_SYMBOL(__copy_to_user);
753+EXPORT_SYMBOL(___copy_from_user);
754+EXPORT_SYMBOL(___copy_to_user);
755 EXPORT_SYMBOL(__clear_user);
756
757 EXPORT_SYMBOL(__get_user_1);
758diff --git a/arch/arm/kernel/kgdb.c b/arch/arm/kernel/kgdb.c
759index ba8ccfe..2dc34dc 100644
760--- a/arch/arm/kernel/kgdb.c
761+++ b/arch/arm/kernel/kgdb.c
762@@ -190,7 +190,7 @@ void kgdb_arch_exit(void)
763 * and we handle the normal undef case within the do_undefinstr
764 * handler.
765 */
766-struct kgdb_arch arch_kgdb_ops = {
767+const struct kgdb_arch arch_kgdb_ops = {
768 #ifndef __ARMEB__
769 .gdb_bpt_instr = {0xfe, 0xde, 0xff, 0xe7}
770 #else /* ! __ARMEB__ */
771diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
772index 3f361a7..6e806e1 100644
773--- a/arch/arm/kernel/traps.c
774+++ b/arch/arm/kernel/traps.c
775@@ -247,6 +247,8 @@ static void __die(const char *str, int err, struct thread_info *thread, struct p
776
777 DEFINE_SPINLOCK(die_lock);
778
779+extern void gr_handle_kernel_exploit(void);
780+
781 /*
782 * This function is protected against re-entrancy.
783 */
784@@ -271,6 +273,8 @@ NORET_TYPE void die(const char *str, struct pt_regs *regs, int err)
785 if (panic_on_oops)
786 panic("Fatal exception");
787
788+ gr_handle_kernel_exploit();
789+
790 do_exit(SIGSEGV);
791 }
792
793diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
794index e4fe124..0fc246b 100644
795--- a/arch/arm/lib/copy_from_user.S
796+++ b/arch/arm/lib/copy_from_user.S
797@@ -16,7 +16,7 @@
798 /*
799 * Prototype:
800 *
801- * size_t __copy_from_user(void *to, const void *from, size_t n)
802+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
803 *
804 * Purpose:
805 *
806@@ -84,11 +84,11 @@
807
808 .text
809
810-ENTRY(__copy_from_user)
811+ENTRY(___copy_from_user)
812
813 #include "copy_template.S"
814
815-ENDPROC(__copy_from_user)
816+ENDPROC(___copy_from_user)
817
818 .section .fixup,"ax"
819 .align 0
820diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
821index 1a71e15..ac7b258 100644
822--- a/arch/arm/lib/copy_to_user.S
823+++ b/arch/arm/lib/copy_to_user.S
824@@ -16,7 +16,7 @@
825 /*
826 * Prototype:
827 *
828- * size_t __copy_to_user(void *to, const void *from, size_t n)
829+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
830 *
831 * Purpose:
832 *
833@@ -88,11 +88,11 @@
834 .text
835
836 ENTRY(__copy_to_user_std)
837-WEAK(__copy_to_user)
838+WEAK(___copy_to_user)
839
840 #include "copy_template.S"
841
842-ENDPROC(__copy_to_user)
843+ENDPROC(___copy_to_user)
844
845 .section .fixup,"ax"
846 .align 0
847diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
848index ffdd274..91017b6 100644
849--- a/arch/arm/lib/uaccess.S
850+++ b/arch/arm/lib/uaccess.S
851@@ -19,7 +19,7 @@
852
853 #define PAGE_SHIFT 12
854
855-/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
856+/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
857 * Purpose : copy a block to user memory from kernel memory
858 * Params : to - user memory
859 * : from - kernel memory
860@@ -39,7 +39,7 @@ USER( strgtbt r3, [r0], #1) @ May fault
861 sub r2, r2, ip
862 b .Lc2u_dest_aligned
863
864-ENTRY(__copy_to_user)
865+ENTRY(___copy_to_user)
866 stmfd sp!, {r2, r4 - r7, lr}
867 cmp r2, #4
868 blt .Lc2u_not_enough
869@@ -277,14 +277,14 @@ USER( strgebt r3, [r0], #1) @ May fault
870 ldrgtb r3, [r1], #0
871 USER( strgtbt r3, [r0], #1) @ May fault
872 b .Lc2u_finished
873-ENDPROC(__copy_to_user)
874+ENDPROC(___copy_to_user)
875
876 .section .fixup,"ax"
877 .align 0
878 9001: ldmfd sp!, {r0, r4 - r7, pc}
879 .previous
880
881-/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
882+/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
883 * Purpose : copy a block from user memory to kernel memory
884 * Params : to - kernel memory
885 * : from - user memory
886@@ -303,7 +303,7 @@ USER( ldrgtbt r3, [r1], #1) @ May fault
887 sub r2, r2, ip
888 b .Lcfu_dest_aligned
889
890-ENTRY(__copy_from_user)
891+ENTRY(___copy_from_user)
892 stmfd sp!, {r0, r2, r4 - r7, lr}
893 cmp r2, #4
894 blt .Lcfu_not_enough
895@@ -543,7 +543,7 @@ USER( ldrgebt r3, [r1], #1) @ May fault
896 USER( ldrgtbt r3, [r1], #1) @ May fault
897 strgtb r3, [r0], #1
898 b .Lcfu_finished
899-ENDPROC(__copy_from_user)
900+ENDPROC(___copy_from_user)
901
902 .section .fixup,"ax"
903 .align 0
904diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
905index 6b967ff..67d5b2b 100644
906--- a/arch/arm/lib/uaccess_with_memcpy.c
907+++ b/arch/arm/lib/uaccess_with_memcpy.c
908@@ -97,7 +97,7 @@ out:
909 }
910
911 unsigned long
912-__copy_to_user(void __user *to, const void *from, unsigned long n)
913+___copy_to_user(void __user *to, const void *from, unsigned long n)
914 {
915 /*
916 * This test is stubbed out of the main function above to keep
917diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
918index 4028724..beec230 100644
919--- a/arch/arm/mach-at91/pm.c
920+++ b/arch/arm/mach-at91/pm.c
921@@ -348,7 +348,7 @@ static void at91_pm_end(void)
922 }
923
924
925-static struct platform_suspend_ops at91_pm_ops ={
926+static const struct platform_suspend_ops at91_pm_ops ={
927 .valid = at91_pm_valid_state,
928 .begin = at91_pm_begin,
929 .enter = at91_pm_enter,
930diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
931index 5218943..0a34552 100644
932--- a/arch/arm/mach-omap1/pm.c
933+++ b/arch/arm/mach-omap1/pm.c
934@@ -647,7 +647,7 @@ static struct irqaction omap_wakeup_irq = {
935
936
937
938-static struct platform_suspend_ops omap_pm_ops ={
939+static const struct platform_suspend_ops omap_pm_ops ={
940 .prepare = omap_pm_prepare,
941 .enter = omap_pm_enter,
942 .finish = omap_pm_finish,
943diff --git a/arch/arm/mach-omap2/pm24xx.c b/arch/arm/mach-omap2/pm24xx.c
944index bff5c4e..d4c649b 100644
945--- a/arch/arm/mach-omap2/pm24xx.c
946+++ b/arch/arm/mach-omap2/pm24xx.c
947@@ -326,7 +326,7 @@ static void omap2_pm_finish(void)
948 enable_hlt();
949 }
950
951-static struct platform_suspend_ops omap_pm_ops = {
952+static const struct platform_suspend_ops omap_pm_ops = {
953 .prepare = omap2_pm_prepare,
954 .enter = omap2_pm_enter,
955 .finish = omap2_pm_finish,
956diff --git a/arch/arm/mach-omap2/pm34xx.c b/arch/arm/mach-omap2/pm34xx.c
957index 8946319..7d3e661 100644
958--- a/arch/arm/mach-omap2/pm34xx.c
959+++ b/arch/arm/mach-omap2/pm34xx.c
960@@ -401,7 +401,7 @@ static void omap3_pm_end(void)
961 return;
962 }
963
964-static struct platform_suspend_ops omap_pm_ops = {
965+static const struct platform_suspend_ops omap_pm_ops = {
966 .begin = omap3_pm_begin,
967 .end = omap3_pm_end,
968 .prepare = omap3_pm_prepare,
969diff --git a/arch/arm/mach-pnx4008/pm.c b/arch/arm/mach-pnx4008/pm.c
970index b3d8d53..6e68ebc 100644
971--- a/arch/arm/mach-pnx4008/pm.c
972+++ b/arch/arm/mach-pnx4008/pm.c
973@@ -116,7 +116,7 @@ static int pnx4008_pm_valid(suspend_state_t state)
974 (state == PM_SUSPEND_MEM);
975 }
976
977-static struct platform_suspend_ops pnx4008_pm_ops = {
978+static const struct platform_suspend_ops pnx4008_pm_ops = {
979 .enter = pnx4008_pm_enter,
980 .valid = pnx4008_pm_valid,
981 };
982diff --git a/arch/arm/mach-pxa/pm.c b/arch/arm/mach-pxa/pm.c
983index 7693355..9beb00a 100644
984--- a/arch/arm/mach-pxa/pm.c
985+++ b/arch/arm/mach-pxa/pm.c
986@@ -95,7 +95,7 @@ void pxa_pm_finish(void)
987 pxa_cpu_pm_fns->finish();
988 }
989
990-static struct platform_suspend_ops pxa_pm_ops = {
991+static const struct platform_suspend_ops pxa_pm_ops = {
992 .valid = pxa_pm_valid,
993 .enter = pxa_pm_enter,
994 .prepare = pxa_pm_prepare,
995diff --git a/arch/arm/mach-pxa/sharpsl_pm.c b/arch/arm/mach-pxa/sharpsl_pm.c
996index 629e05d..06be589 100644
997--- a/arch/arm/mach-pxa/sharpsl_pm.c
998+++ b/arch/arm/mach-pxa/sharpsl_pm.c
999@@ -891,7 +891,7 @@ static void sharpsl_apm_get_power_status(struct apm_power_info *info)
1000 }
1001
1002 #ifdef CONFIG_PM
1003-static struct platform_suspend_ops sharpsl_pm_ops = {
1004+static const struct platform_suspend_ops sharpsl_pm_ops = {
1005 .prepare = pxa_pm_prepare,
1006 .finish = pxa_pm_finish,
1007 .enter = corgi_pxa_pm_enter,
1008diff --git a/arch/arm/mach-sa1100/pm.c b/arch/arm/mach-sa1100/pm.c
1009index c83fdc8..ab9fc44 100644
1010--- a/arch/arm/mach-sa1100/pm.c
1011+++ b/arch/arm/mach-sa1100/pm.c
1012@@ -120,7 +120,7 @@ unsigned long sleep_phys_sp(void *sp)
1013 return virt_to_phys(sp);
1014 }
1015
1016-static struct platform_suspend_ops sa11x0_pm_ops = {
1017+static const struct platform_suspend_ops sa11x0_pm_ops = {
1018 .enter = sa11x0_pm_enter,
1019 .valid = suspend_valid_only_mem,
1020 };
1021diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1022index 3191cd6..c0739db 100644
1023--- a/arch/arm/mm/fault.c
1024+++ b/arch/arm/mm/fault.c
1025@@ -166,6 +166,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1026 }
1027 #endif
1028
1029+#ifdef CONFIG_PAX_PAGEEXEC
1030+ if (fsr & FSR_LNX_PF) {
1031+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1032+ do_group_exit(SIGKILL);
1033+ }
1034+#endif
1035+
1036 tsk->thread.address = addr;
1037 tsk->thread.error_code = fsr;
1038 tsk->thread.trap_no = 14;
1039@@ -357,6 +364,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1040 }
1041 #endif /* CONFIG_MMU */
1042
1043+#ifdef CONFIG_PAX_PAGEEXEC
1044+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1045+{
1046+ long i;
1047+
1048+ printk(KERN_ERR "PAX: bytes at PC: ");
1049+ for (i = 0; i < 20; i++) {
1050+ unsigned char c;
1051+ if (get_user(c, (__force unsigned char __user *)pc+i))
1052+ printk(KERN_CONT "?? ");
1053+ else
1054+ printk(KERN_CONT "%02x ", c);
1055+ }
1056+ printk("\n");
1057+
1058+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1059+ for (i = -1; i < 20; i++) {
1060+ unsigned long c;
1061+ if (get_user(c, (__force unsigned long __user *)sp+i))
1062+ printk(KERN_CONT "???????? ");
1063+ else
1064+ printk(KERN_CONT "%08lx ", c);
1065+ }
1066+ printk("\n");
1067+}
1068+#endif
1069+
1070 /*
1071 * First Level Translation Fault Handler
1072 *
1073diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1074index f5abc51..7ec524c 100644
1075--- a/arch/arm/mm/mmap.c
1076+++ b/arch/arm/mm/mmap.c
1077@@ -63,6 +63,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1078 if (len > TASK_SIZE)
1079 return -ENOMEM;
1080
1081+#ifdef CONFIG_PAX_RANDMMAP
1082+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1083+#endif
1084+
1085 if (addr) {
1086 if (do_align)
1087 addr = COLOUR_ALIGN(addr, pgoff);
1088@@ -70,15 +74,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1089 addr = PAGE_ALIGN(addr);
1090
1091 vma = find_vma(mm, addr);
1092- if (TASK_SIZE - len >= addr &&
1093- (!vma || addr + len <= vma->vm_start))
1094+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1095 return addr;
1096 }
1097 if (len > mm->cached_hole_size) {
1098- start_addr = addr = mm->free_area_cache;
1099+ start_addr = addr = mm->free_area_cache;
1100 } else {
1101- start_addr = addr = TASK_UNMAPPED_BASE;
1102- mm->cached_hole_size = 0;
1103+ start_addr = addr = mm->mmap_base;
1104+ mm->cached_hole_size = 0;
1105 }
1106
1107 full_search:
1108@@ -94,14 +97,14 @@ full_search:
1109 * Start a new search - just in case we missed
1110 * some holes.
1111 */
1112- if (start_addr != TASK_UNMAPPED_BASE) {
1113- start_addr = addr = TASK_UNMAPPED_BASE;
1114+ if (start_addr != mm->mmap_base) {
1115+ start_addr = addr = mm->mmap_base;
1116 mm->cached_hole_size = 0;
1117 goto full_search;
1118 }
1119 return -ENOMEM;
1120 }
1121- if (!vma || addr + len <= vma->vm_start) {
1122+ if (check_heap_stack_gap(vma, addr, len)) {
1123 /*
1124 * Remember the place where we stopped the search:
1125 */
1126diff --git a/arch/arm/plat-s3c/pm.c b/arch/arm/plat-s3c/pm.c
1127index 8d97db2..b66cfa5 100644
1128--- a/arch/arm/plat-s3c/pm.c
1129+++ b/arch/arm/plat-s3c/pm.c
1130@@ -355,7 +355,7 @@ static void s3c_pm_finish(void)
1131 s3c_pm_check_cleanup();
1132 }
1133
1134-static struct platform_suspend_ops s3c_pm_ops = {
1135+static const struct platform_suspend_ops s3c_pm_ops = {
1136 .enter = s3c_pm_enter,
1137 .prepare = s3c_pm_prepare,
1138 .finish = s3c_pm_finish,
1139diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1140index d5d1d41..856e2ed 100644
1141--- a/arch/avr32/include/asm/elf.h
1142+++ b/arch/avr32/include/asm/elf.h
1143@@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1144 the loader. We need to make sure that it is out of the way of the program
1145 that it will "exec", and that there is sufficient room for the brk. */
1146
1147-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1148+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1149
1150+#ifdef CONFIG_PAX_ASLR
1151+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1152+
1153+#define PAX_DELTA_MMAP_LEN 15
1154+#define PAX_DELTA_STACK_LEN 15
1155+#endif
1156
1157 /* This yields a mask that user programs can use to figure out what
1158 instruction set this CPU supports. This could be done in user space,
1159diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1160index b7f5c68..556135c 100644
1161--- a/arch/avr32/include/asm/kmap_types.h
1162+++ b/arch/avr32/include/asm/kmap_types.h
1163@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1164 D(11) KM_IRQ1,
1165 D(12) KM_SOFTIRQ0,
1166 D(13) KM_SOFTIRQ1,
1167-D(14) KM_TYPE_NR
1168+D(14) KM_CLEARPAGE,
1169+D(15) KM_TYPE_NR
1170 };
1171
1172 #undef D
1173diff --git a/arch/avr32/mach-at32ap/pm.c b/arch/avr32/mach-at32ap/pm.c
1174index f021edf..32d680e 100644
1175--- a/arch/avr32/mach-at32ap/pm.c
1176+++ b/arch/avr32/mach-at32ap/pm.c
1177@@ -176,7 +176,7 @@ out:
1178 return 0;
1179 }
1180
1181-static struct platform_suspend_ops avr32_pm_ops = {
1182+static const struct platform_suspend_ops avr32_pm_ops = {
1183 .valid = avr32_pm_valid_state,
1184 .enter = avr32_pm_enter,
1185 };
1186diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1187index b61d86d..e292c7f 100644
1188--- a/arch/avr32/mm/fault.c
1189+++ b/arch/avr32/mm/fault.c
1190@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1191
1192 int exception_trace = 1;
1193
1194+#ifdef CONFIG_PAX_PAGEEXEC
1195+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1196+{
1197+ unsigned long i;
1198+
1199+ printk(KERN_ERR "PAX: bytes at PC: ");
1200+ for (i = 0; i < 20; i++) {
1201+ unsigned char c;
1202+ if (get_user(c, (unsigned char *)pc+i))
1203+ printk(KERN_CONT "???????? ");
1204+ else
1205+ printk(KERN_CONT "%02x ", c);
1206+ }
1207+ printk("\n");
1208+}
1209+#endif
1210+
1211 /*
1212 * This routine handles page faults. It determines the address and the
1213 * problem, and then passes it off to one of the appropriate routines.
1214@@ -157,6 +174,16 @@ bad_area:
1215 up_read(&mm->mmap_sem);
1216
1217 if (user_mode(regs)) {
1218+
1219+#ifdef CONFIG_PAX_PAGEEXEC
1220+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1221+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1222+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1223+ do_group_exit(SIGKILL);
1224+ }
1225+ }
1226+#endif
1227+
1228 if (exception_trace && printk_ratelimit())
1229 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1230 "sp %08lx ecr %lu\n",
1231diff --git a/arch/blackfin/kernel/kgdb.c b/arch/blackfin/kernel/kgdb.c
1232index cce79d0..c406c85 100644
1233--- a/arch/blackfin/kernel/kgdb.c
1234+++ b/arch/blackfin/kernel/kgdb.c
1235@@ -428,7 +428,7 @@ int kgdb_arch_handle_exception(int vector, int signo,
1236 return -1; /* this means that we do not want to exit from the handler */
1237 }
1238
1239-struct kgdb_arch arch_kgdb_ops = {
1240+const struct kgdb_arch arch_kgdb_ops = {
1241 .gdb_bpt_instr = {0xa1},
1242 #ifdef CONFIG_SMP
1243 .flags = KGDB_HW_BREAKPOINT|KGDB_THR_PROC_SWAP,
1244diff --git a/arch/blackfin/mach-common/pm.c b/arch/blackfin/mach-common/pm.c
1245index 8837be4..b2fb413 100644
1246--- a/arch/blackfin/mach-common/pm.c
1247+++ b/arch/blackfin/mach-common/pm.c
1248@@ -255,7 +255,7 @@ static int bfin_pm_enter(suspend_state_t state)
1249 return 0;
1250 }
1251
1252-struct platform_suspend_ops bfin_pm_ops = {
1253+const struct platform_suspend_ops bfin_pm_ops = {
1254 .enter = bfin_pm_enter,
1255 .valid = bfin_pm_valid,
1256 };
1257diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
1258index f8e16b2..c73ff79 100644
1259--- a/arch/frv/include/asm/kmap_types.h
1260+++ b/arch/frv/include/asm/kmap_types.h
1261@@ -23,6 +23,7 @@ enum km_type {
1262 KM_IRQ1,
1263 KM_SOFTIRQ0,
1264 KM_SOFTIRQ1,
1265+ KM_CLEARPAGE,
1266 KM_TYPE_NR
1267 };
1268
1269diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
1270index 385fd30..6c3d97e 100644
1271--- a/arch/frv/mm/elf-fdpic.c
1272+++ b/arch/frv/mm/elf-fdpic.c
1273@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1274 if (addr) {
1275 addr = PAGE_ALIGN(addr);
1276 vma = find_vma(current->mm, addr);
1277- if (TASK_SIZE - len >= addr &&
1278- (!vma || addr + len <= vma->vm_start))
1279+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1280 goto success;
1281 }
1282
1283@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1284 for (; vma; vma = vma->vm_next) {
1285 if (addr > limit)
1286 break;
1287- if (addr + len <= vma->vm_start)
1288+ if (check_heap_stack_gap(vma, addr, len))
1289 goto success;
1290 addr = vma->vm_end;
1291 }
1292@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1293 for (; vma; vma = vma->vm_next) {
1294 if (addr > limit)
1295 break;
1296- if (addr + len <= vma->vm_start)
1297+ if (check_heap_stack_gap(vma, addr, len))
1298 goto success;
1299 addr = vma->vm_end;
1300 }
1301diff --git a/arch/ia64/hp/common/hwsw_iommu.c b/arch/ia64/hp/common/hwsw_iommu.c
1302index e4a80d8..11a7ea1 100644
1303--- a/arch/ia64/hp/common/hwsw_iommu.c
1304+++ b/arch/ia64/hp/common/hwsw_iommu.c
1305@@ -17,7 +17,7 @@
1306 #include <linux/swiotlb.h>
1307 #include <asm/machvec.h>
1308
1309-extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1310+extern const struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
1311
1312 /* swiotlb declarations & definitions: */
1313 extern int swiotlb_late_init_with_default_size (size_t size);
1314@@ -33,7 +33,7 @@ static inline int use_swiotlb(struct device *dev)
1315 !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
1316 }
1317
1318-struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1319+const struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
1320 {
1321 if (use_swiotlb(dev))
1322 return &swiotlb_dma_ops;
1323diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
1324index 01ae69b..35752fd 100644
1325--- a/arch/ia64/hp/common/sba_iommu.c
1326+++ b/arch/ia64/hp/common/sba_iommu.c
1327@@ -2097,7 +2097,7 @@ static struct acpi_driver acpi_sba_ioc_driver = {
1328 },
1329 };
1330
1331-extern struct dma_map_ops swiotlb_dma_ops;
1332+extern const struct dma_map_ops swiotlb_dma_ops;
1333
1334 static int __init
1335 sba_init(void)
1336@@ -2211,7 +2211,7 @@ sba_page_override(char *str)
1337
1338 __setup("sbapagesize=",sba_page_override);
1339
1340-struct dma_map_ops sba_dma_ops = {
1341+const struct dma_map_ops sba_dma_ops = {
1342 .alloc_coherent = sba_alloc_coherent,
1343 .free_coherent = sba_free_coherent,
1344 .map_page = sba_map_page,
1345diff --git a/arch/ia64/ia32/binfmt_elf32.c b/arch/ia64/ia32/binfmt_elf32.c
1346index c69552b..c7122f4 100644
1347--- a/arch/ia64/ia32/binfmt_elf32.c
1348+++ b/arch/ia64/ia32/binfmt_elf32.c
1349@@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_top);
1350
1351 #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
1352
1353+#ifdef CONFIG_PAX_ASLR
1354+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1355+
1356+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1357+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1358+#endif
1359+
1360 /* Ugly but avoids duplication */
1361 #include "../../../fs/binfmt_elf.c"
1362
1363diff --git a/arch/ia64/ia32/ia32priv.h b/arch/ia64/ia32/ia32priv.h
1364index 0f15349..26b3429 100644
1365--- a/arch/ia64/ia32/ia32priv.h
1366+++ b/arch/ia64/ia32/ia32priv.h
1367@@ -296,7 +296,14 @@ typedef struct compat_siginfo {
1368 #define ELF_DATA ELFDATA2LSB
1369 #define ELF_ARCH EM_386
1370
1371-#define IA32_STACK_TOP IA32_PAGE_OFFSET
1372+#ifdef CONFIG_PAX_RANDUSTACK
1373+#define __IA32_DELTA_STACK (current->mm->delta_stack)
1374+#else
1375+#define __IA32_DELTA_STACK 0UL
1376+#endif
1377+
1378+#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
1379+
1380 #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
1381 #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
1382
1383diff --git a/arch/ia64/include/asm/dma-mapping.h b/arch/ia64/include/asm/dma-mapping.h
1384index 8d3c79c..71b3af6 100644
1385--- a/arch/ia64/include/asm/dma-mapping.h
1386+++ b/arch/ia64/include/asm/dma-mapping.h
1387@@ -12,7 +12,7 @@
1388
1389 #define ARCH_HAS_DMA_GET_REQUIRED_MASK
1390
1391-extern struct dma_map_ops *dma_ops;
1392+extern const struct dma_map_ops *dma_ops;
1393 extern struct ia64_machine_vector ia64_mv;
1394 extern void set_iommu_machvec(void);
1395
1396@@ -24,7 +24,7 @@ extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int,
1397 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1398 dma_addr_t *daddr, gfp_t gfp)
1399 {
1400- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1401+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1402 void *caddr;
1403
1404 caddr = ops->alloc_coherent(dev, size, daddr, gfp);
1405@@ -35,7 +35,7 @@ static inline void *dma_alloc_coherent(struct device *dev, size_t size,
1406 static inline void dma_free_coherent(struct device *dev, size_t size,
1407 void *caddr, dma_addr_t daddr)
1408 {
1409- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1410+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1411 debug_dma_free_coherent(dev, size, caddr, daddr);
1412 ops->free_coherent(dev, size, caddr, daddr);
1413 }
1414@@ -49,13 +49,13 @@ static inline void dma_free_coherent(struct device *dev, size_t size,
1415
1416 static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
1417 {
1418- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1419+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1420 return ops->mapping_error(dev, daddr);
1421 }
1422
1423 static inline int dma_supported(struct device *dev, u64 mask)
1424 {
1425- struct dma_map_ops *ops = platform_dma_get_ops(dev);
1426+ const struct dma_map_ops *ops = platform_dma_get_ops(dev);
1427 return ops->dma_supported(dev, mask);
1428 }
1429
1430diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
1431index 86eddee..b116bb4 100644
1432--- a/arch/ia64/include/asm/elf.h
1433+++ b/arch/ia64/include/asm/elf.h
1434@@ -43,6 +43,13 @@
1435 */
1436 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1437
1438+#ifdef CONFIG_PAX_ASLR
1439+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1440+
1441+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1442+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1443+#endif
1444+
1445 #define PT_IA_64_UNWIND 0x70000001
1446
1447 /* IA-64 relocations: */
1448diff --git a/arch/ia64/include/asm/machvec.h b/arch/ia64/include/asm/machvec.h
1449index 367d299..9ad4279 100644
1450--- a/arch/ia64/include/asm/machvec.h
1451+++ b/arch/ia64/include/asm/machvec.h
1452@@ -45,7 +45,7 @@ typedef void ia64_mv_kernel_launch_event_t(void);
1453 /* DMA-mapping interface: */
1454 typedef void ia64_mv_dma_init (void);
1455 typedef u64 ia64_mv_dma_get_required_mask (struct device *);
1456-typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1457+typedef const struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
1458
1459 /*
1460 * WARNING: The legacy I/O space is _architected_. Platforms are
1461@@ -251,7 +251,7 @@ extern void machvec_init_from_cmdline(const char *cmdline);
1462 # endif /* CONFIG_IA64_GENERIC */
1463
1464 extern void swiotlb_dma_init(void);
1465-extern struct dma_map_ops *dma_get_ops(struct device *);
1466+extern const struct dma_map_ops *dma_get_ops(struct device *);
1467
1468 /*
1469 * Define default versions so we can extend machvec for new platforms without having
1470diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
1471index 8840a69..cdb63d9 100644
1472--- a/arch/ia64/include/asm/pgtable.h
1473+++ b/arch/ia64/include/asm/pgtable.h
1474@@ -12,7 +12,7 @@
1475 * David Mosberger-Tang <davidm@hpl.hp.com>
1476 */
1477
1478-
1479+#include <linux/const.h>
1480 #include <asm/mman.h>
1481 #include <asm/page.h>
1482 #include <asm/processor.h>
1483@@ -143,6 +143,17 @@
1484 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1485 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1486 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1487+
1488+#ifdef CONFIG_PAX_PAGEEXEC
1489+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1490+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1491+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1492+#else
1493+# define PAGE_SHARED_NOEXEC PAGE_SHARED
1494+# define PAGE_READONLY_NOEXEC PAGE_READONLY
1495+# define PAGE_COPY_NOEXEC PAGE_COPY
1496+#endif
1497+
1498 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1499 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1500 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1501diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
1502index 239ecdc..f94170e 100644
1503--- a/arch/ia64/include/asm/spinlock.h
1504+++ b/arch/ia64/include/asm/spinlock.h
1505@@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(raw_spinlock_t *lock)
1506 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1507
1508 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1509- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1510+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1511 }
1512
1513 static __always_inline void __ticket_spin_unlock_wait(raw_spinlock_t *lock)
1514diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
1515index 449c8c0..432a3d2 100644
1516--- a/arch/ia64/include/asm/uaccess.h
1517+++ b/arch/ia64/include/asm/uaccess.h
1518@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1519 const void *__cu_from = (from); \
1520 long __cu_len = (n); \
1521 \
1522- if (__access_ok(__cu_to, __cu_len, get_fs())) \
1523+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1524 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1525 __cu_len; \
1526 })
1527@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1528 long __cu_len = (n); \
1529 \
1530 __chk_user_ptr(__cu_from); \
1531- if (__access_ok(__cu_from, __cu_len, get_fs())) \
1532+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1533 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1534 __cu_len; \
1535 })
1536diff --git a/arch/ia64/kernel/dma-mapping.c b/arch/ia64/kernel/dma-mapping.c
1537index f2c1600..969398a 100644
1538--- a/arch/ia64/kernel/dma-mapping.c
1539+++ b/arch/ia64/kernel/dma-mapping.c
1540@@ -3,7 +3,7 @@
1541 /* Set this to 1 if there is a HW IOMMU in the system */
1542 int iommu_detected __read_mostly;
1543
1544-struct dma_map_ops *dma_ops;
1545+const struct dma_map_ops *dma_ops;
1546 EXPORT_SYMBOL(dma_ops);
1547
1548 #define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
1549@@ -16,7 +16,7 @@ static int __init dma_init(void)
1550 }
1551 fs_initcall(dma_init);
1552
1553-struct dma_map_ops *dma_get_ops(struct device *dev)
1554+const struct dma_map_ops *dma_get_ops(struct device *dev)
1555 {
1556 return dma_ops;
1557 }
1558diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
1559index 1481b0a..e7d38ff 100644
1560--- a/arch/ia64/kernel/module.c
1561+++ b/arch/ia64/kernel/module.c
1562@@ -315,8 +315,7 @@ module_alloc (unsigned long size)
1563 void
1564 module_free (struct module *mod, void *module_region)
1565 {
1566- if (mod && mod->arch.init_unw_table &&
1567- module_region == mod->module_init) {
1568+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1569 unw_remove_unwind_table(mod->arch.init_unw_table);
1570 mod->arch.init_unw_table = NULL;
1571 }
1572@@ -502,15 +501,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
1573 }
1574
1575 static inline int
1576+in_init_rx (const struct module *mod, uint64_t addr)
1577+{
1578+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1579+}
1580+
1581+static inline int
1582+in_init_rw (const struct module *mod, uint64_t addr)
1583+{
1584+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1585+}
1586+
1587+static inline int
1588 in_init (const struct module *mod, uint64_t addr)
1589 {
1590- return addr - (uint64_t) mod->module_init < mod->init_size;
1591+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1592+}
1593+
1594+static inline int
1595+in_core_rx (const struct module *mod, uint64_t addr)
1596+{
1597+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1598+}
1599+
1600+static inline int
1601+in_core_rw (const struct module *mod, uint64_t addr)
1602+{
1603+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1604 }
1605
1606 static inline int
1607 in_core (const struct module *mod, uint64_t addr)
1608 {
1609- return addr - (uint64_t) mod->module_core < mod->core_size;
1610+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1611 }
1612
1613 static inline int
1614@@ -693,7 +716,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
1615 break;
1616
1617 case RV_BDREL:
1618- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1619+ if (in_init_rx(mod, val))
1620+ val -= (uint64_t) mod->module_init_rx;
1621+ else if (in_init_rw(mod, val))
1622+ val -= (uint64_t) mod->module_init_rw;
1623+ else if (in_core_rx(mod, val))
1624+ val -= (uint64_t) mod->module_core_rx;
1625+ else if (in_core_rw(mod, val))
1626+ val -= (uint64_t) mod->module_core_rw;
1627 break;
1628
1629 case RV_LTV:
1630@@ -828,15 +858,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
1631 * addresses have been selected...
1632 */
1633 uint64_t gp;
1634- if (mod->core_size > MAX_LTOFF)
1635+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1636 /*
1637 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1638 * at the end of the module.
1639 */
1640- gp = mod->core_size - MAX_LTOFF / 2;
1641+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1642 else
1643- gp = mod->core_size / 2;
1644- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1645+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1646+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1647 mod->arch.gp = gp;
1648 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1649 }
1650diff --git a/arch/ia64/kernel/pci-dma.c b/arch/ia64/kernel/pci-dma.c
1651index f6b1ff0..de773fb 100644
1652--- a/arch/ia64/kernel/pci-dma.c
1653+++ b/arch/ia64/kernel/pci-dma.c
1654@@ -43,7 +43,7 @@ struct device fallback_dev = {
1655 .dma_mask = &fallback_dev.coherent_dma_mask,
1656 };
1657
1658-extern struct dma_map_ops intel_dma_ops;
1659+extern const struct dma_map_ops intel_dma_ops;
1660
1661 static int __init pci_iommu_init(void)
1662 {
1663@@ -96,15 +96,34 @@ int iommu_dma_supported(struct device *dev, u64 mask)
1664 }
1665 EXPORT_SYMBOL(iommu_dma_supported);
1666
1667+extern void *intel_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t flags);
1668+extern void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle);
1669+extern int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1670+extern void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, struct dma_attrs *attrs);
1671+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);
1672+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);
1673+extern int intel_mapping_error(struct device *dev, dma_addr_t dma_addr);
1674+
1675+static const struct dma_map_ops intel_iommu_dma_ops = {
1676+ /* from drivers/pci/intel-iommu.c:intel_dma_ops */
1677+ .alloc_coherent = intel_alloc_coherent,
1678+ .free_coherent = intel_free_coherent,
1679+ .map_sg = intel_map_sg,
1680+ .unmap_sg = intel_unmap_sg,
1681+ .map_page = intel_map_page,
1682+ .unmap_page = intel_unmap_page,
1683+ .mapping_error = intel_mapping_error,
1684+
1685+ .sync_single_for_cpu = machvec_dma_sync_single,
1686+ .sync_sg_for_cpu = machvec_dma_sync_sg,
1687+ .sync_single_for_device = machvec_dma_sync_single,
1688+ .sync_sg_for_device = machvec_dma_sync_sg,
1689+ .dma_supported = iommu_dma_supported,
1690+};
1691+
1692 void __init pci_iommu_alloc(void)
1693 {
1694- dma_ops = &intel_dma_ops;
1695-
1696- dma_ops->sync_single_for_cpu = machvec_dma_sync_single;
1697- dma_ops->sync_sg_for_cpu = machvec_dma_sync_sg;
1698- dma_ops->sync_single_for_device = machvec_dma_sync_single;
1699- dma_ops->sync_sg_for_device = machvec_dma_sync_sg;
1700- dma_ops->dma_supported = iommu_dma_supported;
1701+ dma_ops = &intel_iommu_dma_ops;
1702
1703 /*
1704 * The order of these functions is important for
1705diff --git a/arch/ia64/kernel/pci-swiotlb.c b/arch/ia64/kernel/pci-swiotlb.c
1706index 285aae8..61dbab6 100644
1707--- a/arch/ia64/kernel/pci-swiotlb.c
1708+++ b/arch/ia64/kernel/pci-swiotlb.c
1709@@ -21,7 +21,7 @@ static void *ia64_swiotlb_alloc_coherent(struct device *dev, size_t size,
1710 return swiotlb_alloc_coherent(dev, size, dma_handle, gfp);
1711 }
1712
1713-struct dma_map_ops swiotlb_dma_ops = {
1714+const struct dma_map_ops swiotlb_dma_ops = {
1715 .alloc_coherent = ia64_swiotlb_alloc_coherent,
1716 .free_coherent = swiotlb_free_coherent,
1717 .map_page = swiotlb_map_page,
1718diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
1719index 609d500..7dde2a8 100644
1720--- a/arch/ia64/kernel/sys_ia64.c
1721+++ b/arch/ia64/kernel/sys_ia64.c
1722@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1723 if (REGION_NUMBER(addr) == RGN_HPAGE)
1724 addr = 0;
1725 #endif
1726+
1727+#ifdef CONFIG_PAX_RANDMMAP
1728+ if (mm->pax_flags & MF_PAX_RANDMMAP)
1729+ addr = mm->free_area_cache;
1730+ else
1731+#endif
1732+
1733 if (!addr)
1734 addr = mm->free_area_cache;
1735
1736@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1737 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1738 /* At this point: (!vma || addr < vma->vm_end). */
1739 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1740- if (start_addr != TASK_UNMAPPED_BASE) {
1741+ if (start_addr != mm->mmap_base) {
1742 /* Start a new search --- just in case we missed some holes. */
1743- addr = TASK_UNMAPPED_BASE;
1744+ addr = mm->mmap_base;
1745 goto full_search;
1746 }
1747 return -ENOMEM;
1748 }
1749- if (!vma || addr + len <= vma->vm_start) {
1750+ if (check_heap_stack_gap(vma, addr, len)) {
1751 /* Remember the address where we stopped this search: */
1752 mm->free_area_cache = addr + len;
1753 return addr;
1754diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
1755index 8f06035..b3a5818 100644
1756--- a/arch/ia64/kernel/topology.c
1757+++ b/arch/ia64/kernel/topology.c
1758@@ -282,7 +282,7 @@ static ssize_t cache_show(struct kobject * kobj, struct attribute * attr, char *
1759 return ret;
1760 }
1761
1762-static struct sysfs_ops cache_sysfs_ops = {
1763+static const struct sysfs_ops cache_sysfs_ops = {
1764 .show = cache_show
1765 };
1766
1767diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
1768index 0a0c77b..8e55a81 100644
1769--- a/arch/ia64/kernel/vmlinux.lds.S
1770+++ b/arch/ia64/kernel/vmlinux.lds.S
1771@@ -190,7 +190,7 @@ SECTIONS
1772 /* Per-cpu data: */
1773 . = ALIGN(PERCPU_PAGE_SIZE);
1774 PERCPU_VADDR(PERCPU_ADDR, :percpu)
1775- __phys_per_cpu_start = __per_cpu_load;
1776+ __phys_per_cpu_start = per_cpu_load;
1777 . = __phys_per_cpu_start + PERCPU_PAGE_SIZE; /* ensure percpu data fits
1778 * into percpu page size
1779 */
1780diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
1781index 19261a9..1611b7a 100644
1782--- a/arch/ia64/mm/fault.c
1783+++ b/arch/ia64/mm/fault.c
1784@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
1785 return pte_present(pte);
1786 }
1787
1788+#ifdef CONFIG_PAX_PAGEEXEC
1789+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1790+{
1791+ unsigned long i;
1792+
1793+ printk(KERN_ERR "PAX: bytes at PC: ");
1794+ for (i = 0; i < 8; i++) {
1795+ unsigned int c;
1796+ if (get_user(c, (unsigned int *)pc+i))
1797+ printk(KERN_CONT "???????? ");
1798+ else
1799+ printk(KERN_CONT "%08x ", c);
1800+ }
1801+ printk("\n");
1802+}
1803+#endif
1804+
1805 void __kprobes
1806 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1807 {
1808@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
1809 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1810 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1811
1812- if ((vma->vm_flags & mask) != mask)
1813+ if ((vma->vm_flags & mask) != mask) {
1814+
1815+#ifdef CONFIG_PAX_PAGEEXEC
1816+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1817+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1818+ goto bad_area;
1819+
1820+ up_read(&mm->mmap_sem);
1821+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1822+ do_group_exit(SIGKILL);
1823+ }
1824+#endif
1825+
1826 goto bad_area;
1827
1828+ }
1829+
1830 survive:
1831 /*
1832 * If for any reason at all we couldn't handle the fault, make
1833diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
1834index b0f6157..a082bbc 100644
1835--- a/arch/ia64/mm/hugetlbpage.c
1836+++ b/arch/ia64/mm/hugetlbpage.c
1837@@ -172,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
1838 /* At this point: (!vmm || addr < vmm->vm_end). */
1839 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1840 return -ENOMEM;
1841- if (!vmm || (addr + len) <= vmm->vm_start)
1842+ if (check_heap_stack_gap(vmm, addr, len))
1843 return addr;
1844 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1845 }
1846diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
1847index 1857766..05cc6a3 100644
1848--- a/arch/ia64/mm/init.c
1849+++ b/arch/ia64/mm/init.c
1850@@ -122,6 +122,19 @@ ia64_init_addr_space (void)
1851 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1852 vma->vm_end = vma->vm_start + PAGE_SIZE;
1853 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1854+
1855+#ifdef CONFIG_PAX_PAGEEXEC
1856+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1857+ vma->vm_flags &= ~VM_EXEC;
1858+
1859+#ifdef CONFIG_PAX_MPROTECT
1860+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
1861+ vma->vm_flags &= ~VM_MAYEXEC;
1862+#endif
1863+
1864+ }
1865+#endif
1866+
1867 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1868 down_write(&current->mm->mmap_sem);
1869 if (insert_vm_struct(current->mm, vma)) {
1870diff --git a/arch/ia64/sn/pci/pci_dma.c b/arch/ia64/sn/pci/pci_dma.c
1871index 98b6849..8046766 100644
1872--- a/arch/ia64/sn/pci/pci_dma.c
1873+++ b/arch/ia64/sn/pci/pci_dma.c
1874@@ -464,7 +464,7 @@ int sn_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size)
1875 return ret;
1876 }
1877
1878-static struct dma_map_ops sn_dma_ops = {
1879+static const struct dma_map_ops sn_dma_ops = {
1880 .alloc_coherent = sn_dma_alloc_coherent,
1881 .free_coherent = sn_dma_free_coherent,
1882 .map_page = sn_dma_map_page,
1883diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
1884index 82abd15..d95ae5d 100644
1885--- a/arch/m32r/lib/usercopy.c
1886+++ b/arch/m32r/lib/usercopy.c
1887@@ -14,6 +14,9 @@
1888 unsigned long
1889 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1890 {
1891+ if ((long)n < 0)
1892+ return n;
1893+
1894 prefetch(from);
1895 if (access_ok(VERIFY_WRITE, to, n))
1896 __copy_user(to,from,n);
1897@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1898 unsigned long
1899 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1900 {
1901+ if ((long)n < 0)
1902+ return n;
1903+
1904 prefetchw(to);
1905 if (access_ok(VERIFY_READ, from, n))
1906 __copy_user_zeroing(to,from,n);
1907diff --git a/arch/mips/Makefile b/arch/mips/Makefile
1908index 77f5021..2b1db8a 100644
1909--- a/arch/mips/Makefile
1910+++ b/arch/mips/Makefile
1911@@ -51,6 +51,8 @@ endif
1912 cflags-y := -ffunction-sections
1913 cflags-y += $(call cc-option, -mno-check-zero-division)
1914
1915+cflags-y += -Wno-sign-compare -Wno-extra
1916+
1917 ifdef CONFIG_32BIT
1918 ld-emul = $(32bit-emul)
1919 vmlinux-32 = vmlinux
1920diff --git a/arch/mips/alchemy/devboards/pm.c b/arch/mips/alchemy/devboards/pm.c
1921index 632f986..fd0378d 100644
1922--- a/arch/mips/alchemy/devboards/pm.c
1923+++ b/arch/mips/alchemy/devboards/pm.c
1924@@ -78,7 +78,7 @@ static void db1x_pm_end(void)
1925
1926 }
1927
1928-static struct platform_suspend_ops db1x_pm_ops = {
1929+static const struct platform_suspend_ops db1x_pm_ops = {
1930 .valid = suspend_valid_only_mem,
1931 .begin = db1x_pm_begin,
1932 .enter = db1x_pm_enter,
1933diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
1934index 7990694..4e93acf 100644
1935--- a/arch/mips/include/asm/elf.h
1936+++ b/arch/mips/include/asm/elf.h
1937@@ -368,4 +368,11 @@ extern int dump_task_fpu(struct task_struct *, elf_fpregset_t *);
1938 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1939 #endif
1940
1941+#ifdef CONFIG_PAX_ASLR
1942+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1943+
1944+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1945+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1946+#endif
1947+
1948 #endif /* _ASM_ELF_H */
1949diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
1950index f266295..627cfff 100644
1951--- a/arch/mips/include/asm/page.h
1952+++ b/arch/mips/include/asm/page.h
1953@@ -93,7 +93,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
1954 #ifdef CONFIG_CPU_MIPS32
1955 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1956 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1957- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1958+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1959 #else
1960 typedef struct { unsigned long long pte; } pte_t;
1961 #define pte_val(x) ((x).pte)
1962diff --git a/arch/mips/include/asm/reboot.h b/arch/mips/include/asm/reboot.h
1963index e48c0bf..f3acf65 100644
1964--- a/arch/mips/include/asm/reboot.h
1965+++ b/arch/mips/include/asm/reboot.h
1966@@ -9,7 +9,7 @@
1967 #ifndef _ASM_REBOOT_H
1968 #define _ASM_REBOOT_H
1969
1970-extern void (*_machine_restart)(char *command);
1971-extern void (*_machine_halt)(void);
1972+extern void (*__noreturn _machine_restart)(char *command);
1973+extern void (*__noreturn _machine_halt)(void);
1974
1975 #endif /* _ASM_REBOOT_H */
1976diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
1977index 83b5509..9fa24a23 100644
1978--- a/arch/mips/include/asm/system.h
1979+++ b/arch/mips/include/asm/system.h
1980@@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
1981 */
1982 #define __ARCH_WANT_UNLOCKED_CTXSW
1983
1984-extern unsigned long arch_align_stack(unsigned long sp);
1985+#define arch_align_stack(x) ((x) & ~0xfUL)
1986
1987 #endif /* _ASM_SYSTEM_H */
1988diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
1989index 9fdd8bc..fcf9d68 100644
1990--- a/arch/mips/kernel/binfmt_elfn32.c
1991+++ b/arch/mips/kernel/binfmt_elfn32.c
1992@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1993 #undef ELF_ET_DYN_BASE
1994 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1995
1996+#ifdef CONFIG_PAX_ASLR
1997+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
1998+
1999+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2000+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2001+#endif
2002+
2003 #include <asm/processor.h>
2004 #include <linux/module.h>
2005 #include <linux/elfcore.h>
2006diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2007index ff44823..cf0b48a 100644
2008--- a/arch/mips/kernel/binfmt_elfo32.c
2009+++ b/arch/mips/kernel/binfmt_elfo32.c
2010@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2011 #undef ELF_ET_DYN_BASE
2012 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2013
2014+#ifdef CONFIG_PAX_ASLR
2015+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
2016+
2017+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2018+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2019+#endif
2020+
2021 #include <asm/processor.h>
2022
2023 /*
2024diff --git a/arch/mips/kernel/kgdb.c b/arch/mips/kernel/kgdb.c
2025index 50c9bb8..efdd5f8 100644
2026--- a/arch/mips/kernel/kgdb.c
2027+++ b/arch/mips/kernel/kgdb.c
2028@@ -245,6 +245,7 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,
2029 return -1;
2030 }
2031
2032+/* cannot be const */
2033 struct kgdb_arch arch_kgdb_ops;
2034
2035 /*
2036diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2037index f3d73e1..bb3f57a 100644
2038--- a/arch/mips/kernel/process.c
2039+++ b/arch/mips/kernel/process.c
2040@@ -470,15 +470,3 @@ unsigned long get_wchan(struct task_struct *task)
2041 out:
2042 return pc;
2043 }
2044-
2045-/*
2046- * Don't forget that the stack pointer must be aligned on a 8 bytes
2047- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2048- */
2049-unsigned long arch_align_stack(unsigned long sp)
2050-{
2051- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2052- sp -= get_random_int() & ~PAGE_MASK;
2053-
2054- return sp & ALMASK;
2055-}
2056diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
2057index 060563a..7fbf310 100644
2058--- a/arch/mips/kernel/reset.c
2059+++ b/arch/mips/kernel/reset.c
2060@@ -19,8 +19,8 @@
2061 * So handle all using function pointers to machine specific
2062 * functions.
2063 */
2064-void (*_machine_restart)(char *command);
2065-void (*_machine_halt)(void);
2066+void (*__noreturn _machine_restart)(char *command);
2067+void (*__noreturn _machine_halt)(void);
2068 void (*pm_power_off)(void);
2069
2070 EXPORT_SYMBOL(pm_power_off);
2071@@ -29,16 +29,19 @@ void machine_restart(char *command)
2072 {
2073 if (_machine_restart)
2074 _machine_restart(command);
2075+ BUG();
2076 }
2077
2078 void machine_halt(void)
2079 {
2080 if (_machine_halt)
2081 _machine_halt();
2082+ BUG();
2083 }
2084
2085 void machine_power_off(void)
2086 {
2087 if (pm_power_off)
2088 pm_power_off();
2089+ BUG();
2090 }
2091diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
2092index 3f7f466..3abe0b5 100644
2093--- a/arch/mips/kernel/syscall.c
2094+++ b/arch/mips/kernel/syscall.c
2095@@ -102,17 +102,21 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
2096 do_color_align = 0;
2097 if (filp || (flags & MAP_SHARED))
2098 do_color_align = 1;
2099+
2100+#ifdef CONFIG_PAX_RANDMMAP
2101+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2102+#endif
2103+
2104 if (addr) {
2105 if (do_color_align)
2106 addr = COLOUR_ALIGN(addr, pgoff);
2107 else
2108 addr = PAGE_ALIGN(addr);
2109 vmm = find_vma(current->mm, addr);
2110- if (task_size - len >= addr &&
2111- (!vmm || addr + len <= vmm->vm_start))
2112+ if (task_size - len >= addr && check_heap_stack_gap(vmm, addr, len))
2113 return addr;
2114 }
2115- addr = TASK_UNMAPPED_BASE;
2116+ addr = current->mm->mmap_base;
2117 if (do_color_align)
2118 addr = COLOUR_ALIGN(addr, pgoff);
2119 else
2120@@ -122,7 +126,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
2121 /* At this point: (!vmm || addr < vmm->vm_end). */
2122 if (task_size - len < addr)
2123 return -ENOMEM;
2124- if (!vmm || addr + len <= vmm->vm_start)
2125+ if (check_heap_stack_gap(vmm, addr, len))
2126 return addr;
2127 addr = vmm->vm_end;
2128 if (do_color_align)
2129diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
2130index e97a7a2..f18f5b0 100644
2131--- a/arch/mips/mm/fault.c
2132+++ b/arch/mips/mm/fault.c
2133@@ -26,6 +26,23 @@
2134 #include <asm/ptrace.h>
2135 #include <asm/highmem.h> /* For VMALLOC_END */
2136
2137+#ifdef CONFIG_PAX_PAGEEXEC
2138+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2139+{
2140+ unsigned long i;
2141+
2142+ printk(KERN_ERR "PAX: bytes at PC: ");
2143+ for (i = 0; i < 5; i++) {
2144+ unsigned int c;
2145+ if (get_user(c, (unsigned int *)pc+i))
2146+ printk(KERN_CONT "???????? ");
2147+ else
2148+ printk(KERN_CONT "%08x ", c);
2149+ }
2150+ printk("\n");
2151+}
2152+#endif
2153+
2154 /*
2155 * This routine handles page faults. It determines the address,
2156 * and the problem, and then passes it off to one of the appropriate
2157diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
2158index 9c802eb..0592e41 100644
2159--- a/arch/parisc/include/asm/elf.h
2160+++ b/arch/parisc/include/asm/elf.h
2161@@ -343,6 +343,13 @@ struct pt_regs; /* forward declaration... */
2162
2163 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2164
2165+#ifdef CONFIG_PAX_ASLR
2166+#define PAX_ELF_ET_DYN_BASE 0x10000UL
2167+
2168+#define PAX_DELTA_MMAP_LEN 16
2169+#define PAX_DELTA_STACK_LEN 16
2170+#endif
2171+
2172 /* This yields a mask that user programs can use to figure out what
2173 instruction set this CPU supports. This could be done in user space,
2174 but it's not easy, and we've already done it here. */
2175diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
2176index a27d2e2..18fd845 100644
2177--- a/arch/parisc/include/asm/pgtable.h
2178+++ b/arch/parisc/include/asm/pgtable.h
2179@@ -207,6 +207,17 @@
2180 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
2181 #define PAGE_COPY PAGE_EXECREAD
2182 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
2183+
2184+#ifdef CONFIG_PAX_PAGEEXEC
2185+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
2186+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2187+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
2188+#else
2189+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2190+# define PAGE_COPY_NOEXEC PAGE_COPY
2191+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2192+#endif
2193+
2194 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
2195 #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
2196 #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
2197diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
2198index 2120746..8d70a5e 100644
2199--- a/arch/parisc/kernel/module.c
2200+++ b/arch/parisc/kernel/module.c
2201@@ -95,16 +95,38 @@
2202
2203 /* three functions to determine where in the module core
2204 * or init pieces the location is */
2205+static inline int in_init_rx(struct module *me, void *loc)
2206+{
2207+ return (loc >= me->module_init_rx &&
2208+ loc < (me->module_init_rx + me->init_size_rx));
2209+}
2210+
2211+static inline int in_init_rw(struct module *me, void *loc)
2212+{
2213+ return (loc >= me->module_init_rw &&
2214+ loc < (me->module_init_rw + me->init_size_rw));
2215+}
2216+
2217 static inline int in_init(struct module *me, void *loc)
2218 {
2219- return (loc >= me->module_init &&
2220- loc <= (me->module_init + me->init_size));
2221+ return in_init_rx(me, loc) || in_init_rw(me, loc);
2222+}
2223+
2224+static inline int in_core_rx(struct module *me, void *loc)
2225+{
2226+ return (loc >= me->module_core_rx &&
2227+ loc < (me->module_core_rx + me->core_size_rx));
2228+}
2229+
2230+static inline int in_core_rw(struct module *me, void *loc)
2231+{
2232+ return (loc >= me->module_core_rw &&
2233+ loc < (me->module_core_rw + me->core_size_rw));
2234 }
2235
2236 static inline int in_core(struct module *me, void *loc)
2237 {
2238- return (loc >= me->module_core &&
2239- loc <= (me->module_core + me->core_size));
2240+ return in_core_rx(me, loc) || in_core_rw(me, loc);
2241 }
2242
2243 static inline int in_local(struct module *me, void *loc)
2244@@ -364,13 +386,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
2245 }
2246
2247 /* align things a bit */
2248- me->core_size = ALIGN(me->core_size, 16);
2249- me->arch.got_offset = me->core_size;
2250- me->core_size += gots * sizeof(struct got_entry);
2251+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
2252+ me->arch.got_offset = me->core_size_rw;
2253+ me->core_size_rw += gots * sizeof(struct got_entry);
2254
2255- me->core_size = ALIGN(me->core_size, 16);
2256- me->arch.fdesc_offset = me->core_size;
2257- me->core_size += fdescs * sizeof(Elf_Fdesc);
2258+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
2259+ me->arch.fdesc_offset = me->core_size_rw;
2260+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
2261
2262 me->arch.got_max = gots;
2263 me->arch.fdesc_max = fdescs;
2264@@ -388,7 +410,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
2265
2266 BUG_ON(value == 0);
2267
2268- got = me->module_core + me->arch.got_offset;
2269+ got = me->module_core_rw + me->arch.got_offset;
2270 for (i = 0; got[i].addr; i++)
2271 if (got[i].addr == value)
2272 goto out;
2273@@ -406,7 +428,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
2274 #ifdef CONFIG_64BIT
2275 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
2276 {
2277- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
2278+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
2279
2280 if (!value) {
2281 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
2282@@ -424,7 +446,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
2283
2284 /* Create new one */
2285 fdesc->addr = value;
2286- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2287+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2288 return (Elf_Addr)fdesc;
2289 }
2290 #endif /* CONFIG_64BIT */
2291@@ -848,7 +870,7 @@ register_unwind_table(struct module *me,
2292
2293 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
2294 end = table + sechdrs[me->arch.unwind_section].sh_size;
2295- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2296+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2297
2298 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
2299 me->arch.unwind_section, table, end, gp);
2300diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
2301index 9147391..f3d949a 100644
2302--- a/arch/parisc/kernel/sys_parisc.c
2303+++ b/arch/parisc/kernel/sys_parisc.c
2304@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
2305 /* At this point: (!vma || addr < vma->vm_end). */
2306 if (TASK_SIZE - len < addr)
2307 return -ENOMEM;
2308- if (!vma || addr + len <= vma->vm_start)
2309+ if (check_heap_stack_gap(vma, addr, len))
2310 return addr;
2311 addr = vma->vm_end;
2312 }
2313@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
2314 /* At this point: (!vma || addr < vma->vm_end). */
2315 if (TASK_SIZE - len < addr)
2316 return -ENOMEM;
2317- if (!vma || addr + len <= vma->vm_start)
2318+ if (check_heap_stack_gap(vma, addr, len))
2319 return addr;
2320 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
2321 if (addr < vma->vm_end) /* handle wraparound */
2322@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
2323 if (flags & MAP_FIXED)
2324 return addr;
2325 if (!addr)
2326- addr = TASK_UNMAPPED_BASE;
2327+ addr = current->mm->mmap_base;
2328
2329 if (filp) {
2330 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
2331diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
2332index 8b58bf0..7afff03 100644
2333--- a/arch/parisc/kernel/traps.c
2334+++ b/arch/parisc/kernel/traps.c
2335@@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
2336
2337 down_read(&current->mm->mmap_sem);
2338 vma = find_vma(current->mm,regs->iaoq[0]);
2339- if (vma && (regs->iaoq[0] >= vma->vm_start)
2340- && (vma->vm_flags & VM_EXEC)) {
2341-
2342+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
2343 fault_address = regs->iaoq[0];
2344 fault_space = regs->iasq[0];
2345
2346diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
2347index c6afbfc..c5839f6 100644
2348--- a/arch/parisc/mm/fault.c
2349+++ b/arch/parisc/mm/fault.c
2350@@ -15,6 +15,7 @@
2351 #include <linux/sched.h>
2352 #include <linux/interrupt.h>
2353 #include <linux/module.h>
2354+#include <linux/unistd.h>
2355
2356 #include <asm/uaccess.h>
2357 #include <asm/traps.h>
2358@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
2359 static unsigned long
2360 parisc_acctyp(unsigned long code, unsigned int inst)
2361 {
2362- if (code == 6 || code == 16)
2363+ if (code == 6 || code == 7 || code == 16)
2364 return VM_EXEC;
2365
2366 switch (inst & 0xf0000000) {
2367@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
2368 }
2369 #endif
2370
2371+#ifdef CONFIG_PAX_PAGEEXEC
2372+/*
2373+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
2374+ *
2375+ * returns 1 when task should be killed
2376+ * 2 when rt_sigreturn trampoline was detected
2377+ * 3 when unpatched PLT trampoline was detected
2378+ */
2379+static int pax_handle_fetch_fault(struct pt_regs *regs)
2380+{
2381+
2382+#ifdef CONFIG_PAX_EMUPLT
2383+ int err;
2384+
2385+ do { /* PaX: unpatched PLT emulation */
2386+ unsigned int bl, depwi;
2387+
2388+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
2389+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
2390+
2391+ if (err)
2392+ break;
2393+
2394+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
2395+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
2396+
2397+ err = get_user(ldw, (unsigned int *)addr);
2398+ err |= get_user(bv, (unsigned int *)(addr+4));
2399+ err |= get_user(ldw2, (unsigned int *)(addr+8));
2400+
2401+ if (err)
2402+ break;
2403+
2404+ if (ldw == 0x0E801096U &&
2405+ bv == 0xEAC0C000U &&
2406+ ldw2 == 0x0E881095U)
2407+ {
2408+ unsigned int resolver, map;
2409+
2410+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
2411+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
2412+ if (err)
2413+ break;
2414+
2415+ regs->gr[20] = instruction_pointer(regs)+8;
2416+ regs->gr[21] = map;
2417+ regs->gr[22] = resolver;
2418+ regs->iaoq[0] = resolver | 3UL;
2419+ regs->iaoq[1] = regs->iaoq[0] + 4;
2420+ return 3;
2421+ }
2422+ }
2423+ } while (0);
2424+#endif
2425+
2426+#ifdef CONFIG_PAX_EMUTRAMP
2427+
2428+#ifndef CONFIG_PAX_EMUSIGRT
2429+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
2430+ return 1;
2431+#endif
2432+
2433+ do { /* PaX: rt_sigreturn emulation */
2434+ unsigned int ldi1, ldi2, bel, nop;
2435+
2436+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
2437+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
2438+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
2439+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
2440+
2441+ if (err)
2442+ break;
2443+
2444+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
2445+ ldi2 == 0x3414015AU &&
2446+ bel == 0xE4008200U &&
2447+ nop == 0x08000240U)
2448+ {
2449+ regs->gr[25] = (ldi1 & 2) >> 1;
2450+ regs->gr[20] = __NR_rt_sigreturn;
2451+ regs->gr[31] = regs->iaoq[1] + 16;
2452+ regs->sr[0] = regs->iasq[1];
2453+ regs->iaoq[0] = 0x100UL;
2454+ regs->iaoq[1] = regs->iaoq[0] + 4;
2455+ regs->iasq[0] = regs->sr[2];
2456+ regs->iasq[1] = regs->sr[2];
2457+ return 2;
2458+ }
2459+ } while (0);
2460+#endif
2461+
2462+ return 1;
2463+}
2464+
2465+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2466+{
2467+ unsigned long i;
2468+
2469+ printk(KERN_ERR "PAX: bytes at PC: ");
2470+ for (i = 0; i < 5; i++) {
2471+ unsigned int c;
2472+ if (get_user(c, (unsigned int *)pc+i))
2473+ printk(KERN_CONT "???????? ");
2474+ else
2475+ printk(KERN_CONT "%08x ", c);
2476+ }
2477+ printk("\n");
2478+}
2479+#endif
2480+
2481 int fixup_exception(struct pt_regs *regs)
2482 {
2483 const struct exception_table_entry *fix;
2484@@ -192,8 +303,33 @@ good_area:
2485
2486 acc_type = parisc_acctyp(code,regs->iir);
2487
2488- if ((vma->vm_flags & acc_type) != acc_type)
2489+ if ((vma->vm_flags & acc_type) != acc_type) {
2490+
2491+#ifdef CONFIG_PAX_PAGEEXEC
2492+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
2493+ (address & ~3UL) == instruction_pointer(regs))
2494+ {
2495+ up_read(&mm->mmap_sem);
2496+ switch (pax_handle_fetch_fault(regs)) {
2497+
2498+#ifdef CONFIG_PAX_EMUPLT
2499+ case 3:
2500+ return;
2501+#endif
2502+
2503+#ifdef CONFIG_PAX_EMUTRAMP
2504+ case 2:
2505+ return;
2506+#endif
2507+
2508+ }
2509+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
2510+ do_group_exit(SIGKILL);
2511+ }
2512+#endif
2513+
2514 goto bad_area;
2515+ }
2516
2517 /*
2518 * If for any reason at all we couldn't handle the fault, make
2519diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
2520index c107b74..409dc0f 100644
2521--- a/arch/powerpc/Makefile
2522+++ b/arch/powerpc/Makefile
2523@@ -74,6 +74,8 @@ KBUILD_AFLAGS += -Iarch/$(ARCH)
2524 KBUILD_CFLAGS += -msoft-float -pipe -Iarch/$(ARCH) $(CFLAGS-y)
2525 CPP = $(CC) -E $(KBUILD_CFLAGS)
2526
2527+cflags-y += -Wno-sign-compare -Wno-extra
2528+
2529 CHECKFLAGS += -m$(CONFIG_WORD_SIZE) -D__powerpc__ -D__powerpc$(CONFIG_WORD_SIZE)__
2530
2531 ifeq ($(CONFIG_PPC64),y)
2532diff --git a/arch/powerpc/include/asm/device.h b/arch/powerpc/include/asm/device.h
2533index 6d94d27..50d4cad 100644
2534--- a/arch/powerpc/include/asm/device.h
2535+++ b/arch/powerpc/include/asm/device.h
2536@@ -14,7 +14,7 @@ struct dev_archdata {
2537 struct device_node *of_node;
2538
2539 /* DMA operations on that device */
2540- struct dma_map_ops *dma_ops;
2541+ const struct dma_map_ops *dma_ops;
2542
2543 /*
2544 * When an iommu is in use, dma_data is used as a ptr to the base of the
2545diff --git a/arch/powerpc/include/asm/dma-mapping.h b/arch/powerpc/include/asm/dma-mapping.h
2546index e281dae..2b8a784 100644
2547--- a/arch/powerpc/include/asm/dma-mapping.h
2548+++ b/arch/powerpc/include/asm/dma-mapping.h
2549@@ -69,9 +69,9 @@ static inline unsigned long device_to_mask(struct device *dev)
2550 #ifdef CONFIG_PPC64
2551 extern struct dma_map_ops dma_iommu_ops;
2552 #endif
2553-extern struct dma_map_ops dma_direct_ops;
2554+extern const struct dma_map_ops dma_direct_ops;
2555
2556-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2557+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
2558 {
2559 /* We don't handle the NULL dev case for ISA for now. We could
2560 * do it via an out of line call but it is not needed for now. The
2561@@ -84,7 +84,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
2562 return dev->archdata.dma_ops;
2563 }
2564
2565-static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops)
2566+static inline void set_dma_ops(struct device *dev, const struct dma_map_ops *ops)
2567 {
2568 dev->archdata.dma_ops = ops;
2569 }
2570@@ -118,7 +118,7 @@ static inline void set_dma_offset(struct device *dev, dma_addr_t off)
2571
2572 static inline int dma_supported(struct device *dev, u64 mask)
2573 {
2574- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2575+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2576
2577 if (unlikely(dma_ops == NULL))
2578 return 0;
2579@@ -132,7 +132,7 @@ static inline int dma_supported(struct device *dev, u64 mask)
2580
2581 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
2582 {
2583- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2584+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2585
2586 if (unlikely(dma_ops == NULL))
2587 return -EIO;
2588@@ -147,7 +147,7 @@ static inline int dma_set_mask(struct device *dev, u64 dma_mask)
2589 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
2590 dma_addr_t *dma_handle, gfp_t flag)
2591 {
2592- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2593+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2594 void *cpu_addr;
2595
2596 BUG_ON(!dma_ops);
2597@@ -162,7 +162,7 @@ static inline void *dma_alloc_coherent(struct device *dev, size_t size,
2598 static inline void dma_free_coherent(struct device *dev, size_t size,
2599 void *cpu_addr, dma_addr_t dma_handle)
2600 {
2601- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2602+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2603
2604 BUG_ON(!dma_ops);
2605
2606@@ -173,7 +173,7 @@ static inline void dma_free_coherent(struct device *dev, size_t size,
2607
2608 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
2609 {
2610- struct dma_map_ops *dma_ops = get_dma_ops(dev);
2611+ const struct dma_map_ops *dma_ops = get_dma_ops(dev);
2612
2613 if (dma_ops->mapping_error)
2614 return dma_ops->mapping_error(dev, dma_addr);
2615diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
2616index 5698502..5db093c 100644
2617--- a/arch/powerpc/include/asm/elf.h
2618+++ b/arch/powerpc/include/asm/elf.h
2619@@ -179,8 +179,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
2620 the loader. We need to make sure that it is out of the way of the program
2621 that it will "exec", and that there is sufficient room for the brk. */
2622
2623-extern unsigned long randomize_et_dyn(unsigned long base);
2624-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
2625+#define ELF_ET_DYN_BASE (0x20000000)
2626+
2627+#ifdef CONFIG_PAX_ASLR
2628+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
2629+
2630+#ifdef __powerpc64__
2631+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
2632+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
2633+#else
2634+#define PAX_DELTA_MMAP_LEN 15
2635+#define PAX_DELTA_STACK_LEN 15
2636+#endif
2637+#endif
2638
2639 /*
2640 * Our registers are always unsigned longs, whether we're a 32 bit
2641@@ -275,9 +286,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2642 (0x7ff >> (PAGE_SHIFT - 12)) : \
2643 (0x3ffff >> (PAGE_SHIFT - 12)))
2644
2645-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2646-#define arch_randomize_brk arch_randomize_brk
2647-
2648 #endif /* __KERNEL__ */
2649
2650 /*
2651diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
2652index edfc980..1766f59 100644
2653--- a/arch/powerpc/include/asm/iommu.h
2654+++ b/arch/powerpc/include/asm/iommu.h
2655@@ -116,6 +116,9 @@ extern void iommu_init_early_iSeries(void);
2656 extern void iommu_init_early_dart(void);
2657 extern void iommu_init_early_pasemi(void);
2658
2659+/* dma-iommu.c */
2660+extern int dma_iommu_dma_supported(struct device *dev, u64 mask);
2661+
2662 #ifdef CONFIG_PCI
2663 extern void pci_iommu_init(void);
2664 extern void pci_direct_iommu_init(void);
2665diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
2666index 9163695..5a00112 100644
2667--- a/arch/powerpc/include/asm/kmap_types.h
2668+++ b/arch/powerpc/include/asm/kmap_types.h
2669@@ -26,6 +26,7 @@ enum km_type {
2670 KM_SOFTIRQ1,
2671 KM_PPC_SYNC_PAGE,
2672 KM_PPC_SYNC_ICACHE,
2673+ KM_CLEARPAGE,
2674 KM_TYPE_NR
2675 };
2676
2677diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
2678index ff24254..fe45b21 100644
2679--- a/arch/powerpc/include/asm/page.h
2680+++ b/arch/powerpc/include/asm/page.h
2681@@ -116,8 +116,9 @@ extern phys_addr_t kernstart_addr;
2682 * and needs to be executable. This means the whole heap ends
2683 * up being executable.
2684 */
2685-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2686- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2687+#define VM_DATA_DEFAULT_FLAGS32 \
2688+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2689+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2690
2691 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2692 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2693@@ -145,6 +146,9 @@ extern phys_addr_t kernstart_addr;
2694 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
2695 #endif
2696
2697+#define ktla_ktva(addr) (addr)
2698+#define ktva_ktla(addr) (addr)
2699+
2700 #ifndef __ASSEMBLY__
2701
2702 #undef STRICT_MM_TYPECHECKS
2703diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
2704index 3f17b83..1f9e766 100644
2705--- a/arch/powerpc/include/asm/page_64.h
2706+++ b/arch/powerpc/include/asm/page_64.h
2707@@ -180,15 +180,18 @@ do { \
2708 * stack by default, so in the absense of a PT_GNU_STACK program header
2709 * we turn execute permission off.
2710 */
2711-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2712- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2713+#define VM_STACK_DEFAULT_FLAGS32 \
2714+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2715+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2716
2717 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2718 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2719
2720+#ifndef CONFIG_PAX_PAGEEXEC
2721 #define VM_STACK_DEFAULT_FLAGS \
2722 (test_thread_flag(TIF_32BIT) ? \
2723 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
2724+#endif
2725
2726 #include <asm-generic/getorder.h>
2727
2728diff --git a/arch/powerpc/include/asm/pci.h b/arch/powerpc/include/asm/pci.h
2729index b5ea626..4030822 100644
2730--- a/arch/powerpc/include/asm/pci.h
2731+++ b/arch/powerpc/include/asm/pci.h
2732@@ -65,8 +65,8 @@ static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
2733 }
2734
2735 #ifdef CONFIG_PCI
2736-extern void set_pci_dma_ops(struct dma_map_ops *dma_ops);
2737-extern struct dma_map_ops *get_pci_dma_ops(void);
2738+extern void set_pci_dma_ops(const struct dma_map_ops *dma_ops);
2739+extern const struct dma_map_ops *get_pci_dma_ops(void);
2740 #else /* CONFIG_PCI */
2741 #define set_pci_dma_ops(d)
2742 #define get_pci_dma_ops() NULL
2743diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
2744index 2a5da06..d65bea2 100644
2745--- a/arch/powerpc/include/asm/pgtable.h
2746+++ b/arch/powerpc/include/asm/pgtable.h
2747@@ -2,6 +2,7 @@
2748 #define _ASM_POWERPC_PGTABLE_H
2749 #ifdef __KERNEL__
2750
2751+#include <linux/const.h>
2752 #ifndef __ASSEMBLY__
2753 #include <asm/processor.h> /* For TASK_SIZE */
2754 #include <asm/mmu.h>
2755diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
2756index 4aad413..85d86bf 100644
2757--- a/arch/powerpc/include/asm/pte-hash32.h
2758+++ b/arch/powerpc/include/asm/pte-hash32.h
2759@@ -21,6 +21,7 @@
2760 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
2761 #define _PAGE_USER 0x004 /* usermode access allowed */
2762 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2763+#define _PAGE_EXEC _PAGE_GUARDED
2764 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2765 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2766 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2767diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
2768index 8c34149..78f425a 100644
2769--- a/arch/powerpc/include/asm/ptrace.h
2770+++ b/arch/powerpc/include/asm/ptrace.h
2771@@ -103,7 +103,7 @@ extern unsigned long profile_pc(struct pt_regs *regs);
2772 } while(0)
2773
2774 struct task_struct;
2775-extern unsigned long ptrace_get_reg(struct task_struct *task, int regno);
2776+extern unsigned long ptrace_get_reg(struct task_struct *task, unsigned int regno);
2777 extern int ptrace_put_reg(struct task_struct *task, int regno,
2778 unsigned long data);
2779
2780diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
2781index 32a7c30..be3a8bb 100644
2782--- a/arch/powerpc/include/asm/reg.h
2783+++ b/arch/powerpc/include/asm/reg.h
2784@@ -191,6 +191,7 @@
2785 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
2786 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
2787 #define DSISR_NOHPTE 0x40000000 /* no translation found */
2788+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
2789 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
2790 #define DSISR_ISSTORE 0x02000000 /* access was a store */
2791 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
2792diff --git a/arch/powerpc/include/asm/swiotlb.h b/arch/powerpc/include/asm/swiotlb.h
2793index 8979d4c..d2fd0d3 100644
2794--- a/arch/powerpc/include/asm/swiotlb.h
2795+++ b/arch/powerpc/include/asm/swiotlb.h
2796@@ -13,7 +13,7 @@
2797
2798 #include <linux/swiotlb.h>
2799
2800-extern struct dma_map_ops swiotlb_dma_ops;
2801+extern const struct dma_map_ops swiotlb_dma_ops;
2802
2803 static inline void dma_mark_clean(void *addr, size_t size) {}
2804
2805diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
2806index 094a12a..877a60a 100644
2807--- a/arch/powerpc/include/asm/system.h
2808+++ b/arch/powerpc/include/asm/system.h
2809@@ -531,7 +531,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
2810 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
2811 #endif
2812
2813-extern unsigned long arch_align_stack(unsigned long sp);
2814+#define arch_align_stack(x) ((x) & ~0xfUL)
2815
2816 /* Used in very early kernel initialization. */
2817 extern unsigned long reloc_offset(void);
2818diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
2819index bd0fb84..a42a14b 100644
2820--- a/arch/powerpc/include/asm/uaccess.h
2821+++ b/arch/powerpc/include/asm/uaccess.h
2822@@ -13,6 +13,8 @@
2823 #define VERIFY_READ 0
2824 #define VERIFY_WRITE 1
2825
2826+extern void check_object_size(const void *ptr, unsigned long n, bool to);
2827+
2828 /*
2829 * The fs value determines whether argument validity checking should be
2830 * performed or not. If get_fs() == USER_DS, checking is performed, with
2831@@ -327,52 +329,6 @@ do { \
2832 extern unsigned long __copy_tofrom_user(void __user *to,
2833 const void __user *from, unsigned long size);
2834
2835-#ifndef __powerpc64__
2836-
2837-static inline unsigned long copy_from_user(void *to,
2838- const void __user *from, unsigned long n)
2839-{
2840- unsigned long over;
2841-
2842- if (access_ok(VERIFY_READ, from, n))
2843- return __copy_tofrom_user((__force void __user *)to, from, n);
2844- if ((unsigned long)from < TASK_SIZE) {
2845- over = (unsigned long)from + n - TASK_SIZE;
2846- return __copy_tofrom_user((__force void __user *)to, from,
2847- n - over) + over;
2848- }
2849- return n;
2850-}
2851-
2852-static inline unsigned long copy_to_user(void __user *to,
2853- const void *from, unsigned long n)
2854-{
2855- unsigned long over;
2856-
2857- if (access_ok(VERIFY_WRITE, to, n))
2858- return __copy_tofrom_user(to, (__force void __user *)from, n);
2859- if ((unsigned long)to < TASK_SIZE) {
2860- over = (unsigned long)to + n - TASK_SIZE;
2861- return __copy_tofrom_user(to, (__force void __user *)from,
2862- n - over) + over;
2863- }
2864- return n;
2865-}
2866-
2867-#else /* __powerpc64__ */
2868-
2869-#define __copy_in_user(to, from, size) \
2870- __copy_tofrom_user((to), (from), (size))
2871-
2872-extern unsigned long copy_from_user(void *to, const void __user *from,
2873- unsigned long n);
2874-extern unsigned long copy_to_user(void __user *to, const void *from,
2875- unsigned long n);
2876-extern unsigned long copy_in_user(void __user *to, const void __user *from,
2877- unsigned long n);
2878-
2879-#endif /* __powerpc64__ */
2880-
2881 static inline unsigned long __copy_from_user_inatomic(void *to,
2882 const void __user *from, unsigned long n)
2883 {
2884@@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
2885 if (ret == 0)
2886 return 0;
2887 }
2888+
2889+ if (!__builtin_constant_p(n))
2890+ check_object_size(to, n, false);
2891+
2892 return __copy_tofrom_user((__force void __user *)to, from, n);
2893 }
2894
2895@@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
2896 if (ret == 0)
2897 return 0;
2898 }
2899+
2900+ if (!__builtin_constant_p(n))
2901+ check_object_size(from, n, true);
2902+
2903 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2904 }
2905
2906@@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
2907 return __copy_to_user_inatomic(to, from, size);
2908 }
2909
2910+#ifndef __powerpc64__
2911+
2912+static inline unsigned long __must_check copy_from_user(void *to,
2913+ const void __user *from, unsigned long n)
2914+{
2915+ unsigned long over;
2916+
2917+ if ((long)n < 0)
2918+ return n;
2919+
2920+ if (access_ok(VERIFY_READ, from, n)) {
2921+ if (!__builtin_constant_p(n))
2922+ check_object_size(to, n, false);
2923+ return __copy_tofrom_user((__force void __user *)to, from, n);
2924+ }
2925+ if ((unsigned long)from < TASK_SIZE) {
2926+ over = (unsigned long)from + n - TASK_SIZE;
2927+ if (!__builtin_constant_p(n - over))
2928+ check_object_size(to, n - over, false);
2929+ return __copy_tofrom_user((__force void __user *)to, from,
2930+ n - over) + over;
2931+ }
2932+ return n;
2933+}
2934+
2935+static inline unsigned long __must_check copy_to_user(void __user *to,
2936+ const void *from, unsigned long n)
2937+{
2938+ unsigned long over;
2939+
2940+ if ((long)n < 0)
2941+ return n;
2942+
2943+ if (access_ok(VERIFY_WRITE, to, n)) {
2944+ if (!__builtin_constant_p(n))
2945+ check_object_size(from, n, true);
2946+ return __copy_tofrom_user(to, (__force void __user *)from, n);
2947+ }
2948+ if ((unsigned long)to < TASK_SIZE) {
2949+ over = (unsigned long)to + n - TASK_SIZE;
2950+ if (!__builtin_constant_p(n))
2951+ check_object_size(from, n - over, true);
2952+ return __copy_tofrom_user(to, (__force void __user *)from,
2953+ n - over) + over;
2954+ }
2955+ return n;
2956+}
2957+
2958+#else /* __powerpc64__ */
2959+
2960+#define __copy_in_user(to, from, size) \
2961+ __copy_tofrom_user((to), (from), (size))
2962+
2963+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2964+{
2965+ if ((long)n < 0 || n > INT_MAX)
2966+ return n;
2967+
2968+ if (!__builtin_constant_p(n))
2969+ check_object_size(to, n, false);
2970+
2971+ if (likely(access_ok(VERIFY_READ, from, n)))
2972+ n = __copy_from_user(to, from, n);
2973+ else
2974+ memset(to, 0, n);
2975+ return n;
2976+}
2977+
2978+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2979+{
2980+ if ((long)n < 0 || n > INT_MAX)
2981+ return n;
2982+
2983+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
2984+ if (!__builtin_constant_p(n))
2985+ check_object_size(from, n, true);
2986+ n = __copy_to_user(to, from, n);
2987+ }
2988+ return n;
2989+}
2990+
2991+extern unsigned long copy_in_user(void __user *to, const void __user *from,
2992+ unsigned long n);
2993+
2994+#endif /* __powerpc64__ */
2995+
2996 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2997
2998 static inline unsigned long clear_user(void __user *addr, unsigned long size)
2999diff --git a/arch/powerpc/kernel/cacheinfo.c b/arch/powerpc/kernel/cacheinfo.c
3000index bb37b1d..01fe9ce 100644
3001--- a/arch/powerpc/kernel/cacheinfo.c
3002+++ b/arch/powerpc/kernel/cacheinfo.c
3003@@ -642,7 +642,7 @@ static struct kobj_attribute *cache_index_opt_attrs[] = {
3004 &cache_assoc_attr,
3005 };
3006
3007-static struct sysfs_ops cache_index_ops = {
3008+static const struct sysfs_ops cache_index_ops = {
3009 .show = cache_index_show,
3010 };
3011
3012diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c
3013index 37771a5..648530c 100644
3014--- a/arch/powerpc/kernel/dma-iommu.c
3015+++ b/arch/powerpc/kernel/dma-iommu.c
3016@@ -70,7 +70,7 @@ static void dma_iommu_unmap_sg(struct device *dev, struct scatterlist *sglist,
3017 }
3018
3019 /* We support DMA to/from any memory page via the iommu */
3020-static int dma_iommu_dma_supported(struct device *dev, u64 mask)
3021+int dma_iommu_dma_supported(struct device *dev, u64 mask)
3022 {
3023 struct iommu_table *tbl = get_iommu_table_base(dev);
3024
3025diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/dma-swiotlb.c
3026index e96cbbd..bdd6d41 100644
3027--- a/arch/powerpc/kernel/dma-swiotlb.c
3028+++ b/arch/powerpc/kernel/dma-swiotlb.c
3029@@ -31,7 +31,7 @@ unsigned int ppc_swiotlb_enable;
3030 * map_page, and unmap_page on highmem, use normal dma_ops
3031 * for everything else.
3032 */
3033-struct dma_map_ops swiotlb_dma_ops = {
3034+const struct dma_map_ops swiotlb_dma_ops = {
3035 .alloc_coherent = dma_direct_alloc_coherent,
3036 .free_coherent = dma_direct_free_coherent,
3037 .map_sg = swiotlb_map_sg_attrs,
3038diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c
3039index 6215062..ebea59c 100644
3040--- a/arch/powerpc/kernel/dma.c
3041+++ b/arch/powerpc/kernel/dma.c
3042@@ -134,7 +134,7 @@ static inline void dma_direct_sync_single_range(struct device *dev,
3043 }
3044 #endif
3045
3046-struct dma_map_ops dma_direct_ops = {
3047+const struct dma_map_ops dma_direct_ops = {
3048 .alloc_coherent = dma_direct_alloc_coherent,
3049 .free_coherent = dma_direct_free_coherent,
3050 .map_sg = dma_direct_map_sg,
3051diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
3052index 24dcc0e..a300455 100644
3053--- a/arch/powerpc/kernel/exceptions-64e.S
3054+++ b/arch/powerpc/kernel/exceptions-64e.S
3055@@ -455,6 +455,7 @@ storage_fault_common:
3056 std r14,_DAR(r1)
3057 std r15,_DSISR(r1)
3058 addi r3,r1,STACK_FRAME_OVERHEAD
3059+ bl .save_nvgprs
3060 mr r4,r14
3061 mr r5,r15
3062 ld r14,PACA_EXGEN+EX_R14(r13)
3063@@ -464,8 +465,7 @@ storage_fault_common:
3064 cmpdi r3,0
3065 bne- 1f
3066 b .ret_from_except_lite
3067-1: bl .save_nvgprs
3068- mr r5,r3
3069+1: mr r5,r3
3070 addi r3,r1,STACK_FRAME_OVERHEAD
3071 ld r4,_DAR(r1)
3072 bl .bad_page_fault
3073diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
3074index 1808876..9fd206a 100644
3075--- a/arch/powerpc/kernel/exceptions-64s.S
3076+++ b/arch/powerpc/kernel/exceptions-64s.S
3077@@ -818,10 +818,10 @@ handle_page_fault:
3078 11: ld r4,_DAR(r1)
3079 ld r5,_DSISR(r1)
3080 addi r3,r1,STACK_FRAME_OVERHEAD
3081+ bl .save_nvgprs
3082 bl .do_page_fault
3083 cmpdi r3,0
3084 beq+ 13f
3085- bl .save_nvgprs
3086 mr r5,r3
3087 addi r3,r1,STACK_FRAME_OVERHEAD
3088 lwz r4,_DAR(r1)
3089diff --git a/arch/powerpc/kernel/ibmebus.c b/arch/powerpc/kernel/ibmebus.c
3090index a4c8b38..1b09ad9 100644
3091--- a/arch/powerpc/kernel/ibmebus.c
3092+++ b/arch/powerpc/kernel/ibmebus.c
3093@@ -127,7 +127,7 @@ static int ibmebus_dma_supported(struct device *dev, u64 mask)
3094 return 1;
3095 }
3096
3097-static struct dma_map_ops ibmebus_dma_ops = {
3098+static const struct dma_map_ops ibmebus_dma_ops = {
3099 .alloc_coherent = ibmebus_alloc_coherent,
3100 .free_coherent = ibmebus_free_coherent,
3101 .map_sg = ibmebus_map_sg,
3102diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c
3103index 641c74b..8339ad7 100644
3104--- a/arch/powerpc/kernel/kgdb.c
3105+++ b/arch/powerpc/kernel/kgdb.c
3106@@ -126,7 +126,7 @@ static int kgdb_handle_breakpoint(struct pt_regs *regs)
3107 if (kgdb_handle_exception(0, SIGTRAP, 0, regs) != 0)
3108 return 0;
3109
3110- if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
3111+ if (*(u32 *) (regs->nip) == *(const u32 *) (&arch_kgdb_ops.gdb_bpt_instr))
3112 regs->nip += 4;
3113
3114 return 1;
3115@@ -353,7 +353,7 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code,
3116 /*
3117 * Global data
3118 */
3119-struct kgdb_arch arch_kgdb_ops = {
3120+const struct kgdb_arch arch_kgdb_ops = {
3121 .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08},
3122 };
3123
3124diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c
3125index 477c663..4f50234 100644
3126--- a/arch/powerpc/kernel/module.c
3127+++ b/arch/powerpc/kernel/module.c
3128@@ -31,11 +31,24 @@
3129
3130 LIST_HEAD(module_bug_list);
3131
3132+#ifdef CONFIG_PAX_KERNEXEC
3133 void *module_alloc(unsigned long size)
3134 {
3135 if (size == 0)
3136 return NULL;
3137
3138+ return vmalloc(size);
3139+}
3140+
3141+void *module_alloc_exec(unsigned long size)
3142+#else
3143+void *module_alloc(unsigned long size)
3144+#endif
3145+
3146+{
3147+ if (size == 0)
3148+ return NULL;
3149+
3150 return vmalloc_exec(size);
3151 }
3152
3153@@ -45,6 +58,13 @@ void module_free(struct module *mod, void *module_region)
3154 vfree(module_region);
3155 }
3156
3157+#ifdef CONFIG_PAX_KERNEXEC
3158+void module_free_exec(struct module *mod, void *module_region)
3159+{
3160+ module_free(mod, module_region);
3161+}
3162+#endif
3163+
3164 static const Elf_Shdr *find_section(const Elf_Ehdr *hdr,
3165 const Elf_Shdr *sechdrs,
3166 const char *name)
3167diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
3168index f832773..0507238 100644
3169--- a/arch/powerpc/kernel/module_32.c
3170+++ b/arch/powerpc/kernel/module_32.c
3171@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
3172 me->arch.core_plt_section = i;
3173 }
3174 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3175- printk("Module doesn't contain .plt or .init.plt sections.\n");
3176+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3177 return -ENOEXEC;
3178 }
3179
3180@@ -203,11 +203,16 @@ static uint32_t do_plt_call(void *location,
3181
3182 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3183 /* Init, or core PLT? */
3184- if (location >= mod->module_core
3185- && location < mod->module_core + mod->core_size)
3186+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3187+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3188 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3189- else
3190+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3191+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3192 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3193+ else {
3194+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3195+ return ~0UL;
3196+ }
3197
3198 /* Find this entry, or if that fails, the next avail. entry */
3199 while (entry->jump[0]) {
3200diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
3201index cadbed6..b9bbb00 100644
3202--- a/arch/powerpc/kernel/pci-common.c
3203+++ b/arch/powerpc/kernel/pci-common.c
3204@@ -50,14 +50,14 @@ resource_size_t isa_mem_base;
3205 unsigned int ppc_pci_flags = 0;
3206
3207
3208-static struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3209+static const struct dma_map_ops *pci_dma_ops = &dma_direct_ops;
3210
3211-void set_pci_dma_ops(struct dma_map_ops *dma_ops)
3212+void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
3213 {
3214 pci_dma_ops = dma_ops;
3215 }
3216
3217-struct dma_map_ops *get_pci_dma_ops(void)
3218+const struct dma_map_ops *get_pci_dma_ops(void)
3219 {
3220 return pci_dma_ops;
3221 }
3222diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
3223index 7b816da..8d5c277 100644
3224--- a/arch/powerpc/kernel/process.c
3225+++ b/arch/powerpc/kernel/process.c
3226@@ -539,8 +539,8 @@ void show_regs(struct pt_regs * regs)
3227 * Lookup NIP late so we have the best change of getting the
3228 * above info out without failing
3229 */
3230- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
3231- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
3232+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
3233+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
3234 #endif
3235 show_stack(current, (unsigned long *) regs->gpr[1]);
3236 if (!user_mode(regs))
3237@@ -1034,10 +1034,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3238 newsp = stack[0];
3239 ip = stack[STACK_FRAME_LR_SAVE];
3240 if (!firstframe || ip != lr) {
3241- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
3242+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
3243 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
3244 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
3245- printk(" (%pS)",
3246+ printk(" (%pA)",
3247 (void *)current->ret_stack[curr_frame].ret);
3248 curr_frame--;
3249 }
3250@@ -1057,7 +1057,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
3251 struct pt_regs *regs = (struct pt_regs *)
3252 (sp + STACK_FRAME_OVERHEAD);
3253 lr = regs->link;
3254- printk("--- Exception: %lx at %pS\n LR = %pS\n",
3255+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
3256 regs->trap, (void *)regs->nip, (void *)lr);
3257 firstframe = 1;
3258 }
3259@@ -1134,58 +1134,3 @@ void thread_info_cache_init(void)
3260 }
3261
3262 #endif /* THREAD_SHIFT < PAGE_SHIFT */
3263-
3264-unsigned long arch_align_stack(unsigned long sp)
3265-{
3266- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3267- sp -= get_random_int() & ~PAGE_MASK;
3268- return sp & ~0xf;
3269-}
3270-
3271-static inline unsigned long brk_rnd(void)
3272-{
3273- unsigned long rnd = 0;
3274-
3275- /* 8MB for 32bit, 1GB for 64bit */
3276- if (is_32bit_task())
3277- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
3278- else
3279- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
3280-
3281- return rnd << PAGE_SHIFT;
3282-}
3283-
3284-unsigned long arch_randomize_brk(struct mm_struct *mm)
3285-{
3286- unsigned long base = mm->brk;
3287- unsigned long ret;
3288-
3289-#ifdef CONFIG_PPC_STD_MMU_64
3290- /*
3291- * If we are using 1TB segments and we are allowed to randomise
3292- * the heap, we can put it above 1TB so it is backed by a 1TB
3293- * segment. Otherwise the heap will be in the bottom 1TB
3294- * which always uses 256MB segments and this may result in a
3295- * performance penalty.
3296- */
3297- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
3298- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
3299-#endif
3300-
3301- ret = PAGE_ALIGN(base + brk_rnd());
3302-
3303- if (ret < mm->brk)
3304- return mm->brk;
3305-
3306- return ret;
3307-}
3308-
3309-unsigned long randomize_et_dyn(unsigned long base)
3310-{
3311- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3312-
3313- if (ret < base)
3314- return base;
3315-
3316- return ret;
3317-}
3318diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
3319index ef14988..856c4bc 100644
3320--- a/arch/powerpc/kernel/ptrace.c
3321+++ b/arch/powerpc/kernel/ptrace.c
3322@@ -86,7 +86,7 @@ static int set_user_trap(struct task_struct *task, unsigned long trap)
3323 /*
3324 * Get contents of register REGNO in task TASK.
3325 */
3326-unsigned long ptrace_get_reg(struct task_struct *task, int regno)
3327+unsigned long ptrace_get_reg(struct task_struct *task, unsigned int regno)
3328 {
3329 if (task->thread.regs == NULL)
3330 return -EIO;
3331@@ -894,7 +894,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
3332
3333 CHECK_FULL_REGS(child->thread.regs);
3334 if (index < PT_FPR0) {
3335- tmp = ptrace_get_reg(child, (int) index);
3336+ tmp = ptrace_get_reg(child, index);
3337 } else {
3338 flush_fp_to_thread(child);
3339 tmp = ((unsigned long *)child->thread.fpr)
3340diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
3341index d670429..2bc59b2 100644
3342--- a/arch/powerpc/kernel/signal_32.c
3343+++ b/arch/powerpc/kernel/signal_32.c
3344@@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
3345 /* Save user registers on the stack */
3346 frame = &rt_sf->uc.uc_mcontext;
3347 addr = frame;
3348- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3349+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3350 if (save_user_regs(regs, frame, 0, 1))
3351 goto badframe;
3352 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3353diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
3354index 2fe6fc6..ada0d96 100644
3355--- a/arch/powerpc/kernel/signal_64.c
3356+++ b/arch/powerpc/kernel/signal_64.c
3357@@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
3358 current->thread.fpscr.val = 0;
3359
3360 /* Set up to return from userspace. */
3361- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3362+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3363 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3364 } else {
3365 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3366diff --git a/arch/powerpc/kernel/sys_ppc32.c b/arch/powerpc/kernel/sys_ppc32.c
3367index b97c2d6..dd01a6a 100644
3368--- a/arch/powerpc/kernel/sys_ppc32.c
3369+++ b/arch/powerpc/kernel/sys_ppc32.c
3370@@ -563,10 +563,10 @@ asmlinkage long compat_sys_sysctl(struct __sysctl_args32 __user *args)
3371 if (oldlenp) {
3372 if (!error) {
3373 if (get_user(oldlen, oldlenp) ||
3374- put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)))
3375+ put_user(oldlen, (compat_size_t __user *)compat_ptr(tmp.oldlenp)) ||
3376+ copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused)))
3377 error = -EFAULT;
3378 }
3379- copy_to_user(args->__unused, tmp.__unused, sizeof(tmp.__unused));
3380 }
3381 return error;
3382 }
3383diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
3384index 6f0ae1a..e4b6a56 100644
3385--- a/arch/powerpc/kernel/traps.c
3386+++ b/arch/powerpc/kernel/traps.c
3387@@ -99,6 +99,8 @@ static void pmac_backlight_unblank(void)
3388 static inline void pmac_backlight_unblank(void) { }
3389 #endif
3390
3391+extern void gr_handle_kernel_exploit(void);
3392+
3393 int die(const char *str, struct pt_regs *regs, long err)
3394 {
3395 static struct {
3396@@ -168,6 +170,8 @@ int die(const char *str, struct pt_regs *regs, long err)
3397 if (panic_on_oops)
3398 panic("Fatal exception");
3399
3400+ gr_handle_kernel_exploit();
3401+
3402 oops_exit();
3403 do_exit(err);
3404
3405diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
3406index 137dc22..fe57a79 100644
3407--- a/arch/powerpc/kernel/vdso.c
3408+++ b/arch/powerpc/kernel/vdso.c
3409@@ -36,6 +36,7 @@
3410 #include <asm/firmware.h>
3411 #include <asm/vdso.h>
3412 #include <asm/vdso_datapage.h>
3413+#include <asm/mman.h>
3414
3415 #include "setup.h"
3416
3417@@ -220,7 +221,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3418 vdso_base = VDSO32_MBASE;
3419 #endif
3420
3421- current->mm->context.vdso_base = 0;
3422+ current->mm->context.vdso_base = ~0UL;
3423
3424 /* vDSO has a problem and was disabled, just don't "enable" it for the
3425 * process
3426@@ -240,7 +241,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3427 vdso_base = get_unmapped_area(NULL, vdso_base,
3428 (vdso_pages << PAGE_SHIFT) +
3429 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
3430- 0, 0);
3431+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
3432 if (IS_ERR_VALUE(vdso_base)) {
3433 rc = vdso_base;
3434 goto fail_mmapsem;
3435diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
3436index 77f6421..829564a 100644
3437--- a/arch/powerpc/kernel/vio.c
3438+++ b/arch/powerpc/kernel/vio.c
3439@@ -601,11 +601,12 @@ static void vio_dma_iommu_unmap_sg(struct device *dev,
3440 vio_cmo_dealloc(viodev, alloc_size);
3441 }
3442
3443-struct dma_map_ops vio_dma_mapping_ops = {
3444+static const struct dma_map_ops vio_dma_mapping_ops = {
3445 .alloc_coherent = vio_dma_iommu_alloc_coherent,
3446 .free_coherent = vio_dma_iommu_free_coherent,
3447 .map_sg = vio_dma_iommu_map_sg,
3448 .unmap_sg = vio_dma_iommu_unmap_sg,
3449+ .dma_supported = dma_iommu_dma_supported,
3450 .map_page = vio_dma_iommu_map_page,
3451 .unmap_page = vio_dma_iommu_unmap_page,
3452
3453@@ -857,7 +858,6 @@ static void vio_cmo_bus_remove(struct vio_dev *viodev)
3454
3455 static void vio_cmo_set_dma_ops(struct vio_dev *viodev)
3456 {
3457- vio_dma_mapping_ops.dma_supported = dma_iommu_ops.dma_supported;
3458 viodev->dev.archdata.dma_ops = &vio_dma_mapping_ops;
3459 }
3460
3461diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
3462index 5eea6f3..5d10396 100644
3463--- a/arch/powerpc/lib/usercopy_64.c
3464+++ b/arch/powerpc/lib/usercopy_64.c
3465@@ -9,22 +9,6 @@
3466 #include <linux/module.h>
3467 #include <asm/uaccess.h>
3468
3469-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3470-{
3471- if (likely(access_ok(VERIFY_READ, from, n)))
3472- n = __copy_from_user(to, from, n);
3473- else
3474- memset(to, 0, n);
3475- return n;
3476-}
3477-
3478-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3479-{
3480- if (likely(access_ok(VERIFY_WRITE, to, n)))
3481- n = __copy_to_user(to, from, n);
3482- return n;
3483-}
3484-
3485 unsigned long copy_in_user(void __user *to, const void __user *from,
3486 unsigned long n)
3487 {
3488@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
3489 return n;
3490 }
3491
3492-EXPORT_SYMBOL(copy_from_user);
3493-EXPORT_SYMBOL(copy_to_user);
3494 EXPORT_SYMBOL(copy_in_user);
3495
3496diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
3497index e7dae82..877ce0d 100644
3498--- a/arch/powerpc/mm/fault.c
3499+++ b/arch/powerpc/mm/fault.c
3500@@ -30,6 +30,10 @@
3501 #include <linux/kprobes.h>
3502 #include <linux/kdebug.h>
3503 #include <linux/perf_event.h>
3504+#include <linux/slab.h>
3505+#include <linux/pagemap.h>
3506+#include <linux/compiler.h>
3507+#include <linux/unistd.h>
3508
3509 #include <asm/firmware.h>
3510 #include <asm/page.h>
3511@@ -40,6 +44,7 @@
3512 #include <asm/uaccess.h>
3513 #include <asm/tlbflush.h>
3514 #include <asm/siginfo.h>
3515+#include <asm/ptrace.h>
3516
3517
3518 #ifdef CONFIG_KPROBES
3519@@ -64,6 +69,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
3520 }
3521 #endif
3522
3523+#ifdef CONFIG_PAX_PAGEEXEC
3524+/*
3525+ * PaX: decide what to do with offenders (regs->nip = fault address)
3526+ *
3527+ * returns 1 when task should be killed
3528+ */
3529+static int pax_handle_fetch_fault(struct pt_regs *regs)
3530+{
3531+ return 1;
3532+}
3533+
3534+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3535+{
3536+ unsigned long i;
3537+
3538+ printk(KERN_ERR "PAX: bytes at PC: ");
3539+ for (i = 0; i < 5; i++) {
3540+ unsigned int c;
3541+ if (get_user(c, (unsigned int __user *)pc+i))
3542+ printk(KERN_CONT "???????? ");
3543+ else
3544+ printk(KERN_CONT "%08x ", c);
3545+ }
3546+ printk("\n");
3547+}
3548+#endif
3549+
3550 /*
3551 * Check whether the instruction at regs->nip is a store using
3552 * an update addressing form which will update r1.
3553@@ -134,7 +166,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
3554 * indicate errors in DSISR but can validly be set in SRR1.
3555 */
3556 if (trap == 0x400)
3557- error_code &= 0x48200000;
3558+ error_code &= 0x58200000;
3559 else
3560 is_write = error_code & DSISR_ISSTORE;
3561 #else
3562@@ -250,7 +282,7 @@ good_area:
3563 * "undefined". Of those that can be set, this is the only
3564 * one which seems bad.
3565 */
3566- if (error_code & 0x10000000)
3567+ if (error_code & DSISR_GUARDED)
3568 /* Guarded storage error. */
3569 goto bad_area;
3570 #endif /* CONFIG_8xx */
3571@@ -265,7 +297,7 @@ good_area:
3572 * processors use the same I/D cache coherency mechanism
3573 * as embedded.
3574 */
3575- if (error_code & DSISR_PROTFAULT)
3576+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
3577 goto bad_area;
3578 #endif /* CONFIG_PPC_STD_MMU */
3579
3580@@ -335,6 +367,23 @@ bad_area:
3581 bad_area_nosemaphore:
3582 /* User mode accesses cause a SIGSEGV */
3583 if (user_mode(regs)) {
3584+
3585+#ifdef CONFIG_PAX_PAGEEXEC
3586+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3587+#ifdef CONFIG_PPC_STD_MMU
3588+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
3589+#else
3590+ if (is_exec && regs->nip == address) {
3591+#endif
3592+ switch (pax_handle_fetch_fault(regs)) {
3593+ }
3594+
3595+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
3596+ do_group_exit(SIGKILL);
3597+ }
3598+ }
3599+#endif
3600+
3601 _exception(SIGSEGV, regs, code, address);
3602 return 0;
3603 }
3604diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
3605index 5973631..ad617af 100644
3606--- a/arch/powerpc/mm/mem.c
3607+++ b/arch/powerpc/mm/mem.c
3608@@ -250,7 +250,7 @@ static int __init mark_nonram_nosave(void)
3609 {
3610 unsigned long lmb_next_region_start_pfn,
3611 lmb_region_max_pfn;
3612- int i;
3613+ unsigned int i;
3614
3615 for (i = 0; i < lmb.memory.cnt - 1; i++) {
3616 lmb_region_max_pfn =
3617diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
3618index 0d957a4..26d968f 100644
3619--- a/arch/powerpc/mm/mmap_64.c
3620+++ b/arch/powerpc/mm/mmap_64.c
3621@@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3622 */
3623 if (mmap_is_legacy()) {
3624 mm->mmap_base = TASK_UNMAPPED_BASE;
3625+
3626+#ifdef CONFIG_PAX_RANDMMAP
3627+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3628+ mm->mmap_base += mm->delta_mmap;
3629+#endif
3630+
3631 mm->get_unmapped_area = arch_get_unmapped_area;
3632 mm->unmap_area = arch_unmap_area;
3633 } else {
3634 mm->mmap_base = mmap_base();
3635+
3636+#ifdef CONFIG_PAX_RANDMMAP
3637+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3638+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3639+#endif
3640+
3641 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3642 mm->unmap_area = arch_unmap_area_topdown;
3643 }
3644diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
3645index ba51948..23009d9 100644
3646--- a/arch/powerpc/mm/slice.c
3647+++ b/arch/powerpc/mm/slice.c
3648@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
3649 if ((mm->task_size - len) < addr)
3650 return 0;
3651 vma = find_vma(mm, addr);
3652- return (!vma || (addr + len) <= vma->vm_start);
3653+ return check_heap_stack_gap(vma, addr, len);
3654 }
3655
3656 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
3657@@ -256,7 +256,7 @@ full_search:
3658 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
3659 continue;
3660 }
3661- if (!vma || addr + len <= vma->vm_start) {
3662+ if (check_heap_stack_gap(vma, addr, len)) {
3663 /*
3664 * Remember the place where we stopped the search:
3665 */
3666@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3667 }
3668 }
3669
3670- addr = mm->mmap_base;
3671- while (addr > len) {
3672+ if (mm->mmap_base < len)
3673+ addr = -ENOMEM;
3674+ else
3675+ addr = mm->mmap_base - len;
3676+
3677+ while (!IS_ERR_VALUE(addr)) {
3678 /* Go down by chunk size */
3679- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
3680+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
3681
3682 /* Check for hit with different page size */
3683 mask = slice_range_to_mask(addr, len);
3684@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3685 * return with success:
3686 */
3687 vma = find_vma(mm, addr);
3688- if (!vma || (addr + len) <= vma->vm_start) {
3689+ if (check_heap_stack_gap(vma, addr, len)) {
3690 /* remember the address as a hint for next time */
3691 if (use_cache)
3692 mm->free_area_cache = addr;
3693@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3694 mm->cached_hole_size = vma->vm_start - addr;
3695
3696 /* try just below the current vma->vm_start */
3697- addr = vma->vm_start;
3698+ addr = skip_heap_stack_gap(vma, len);
3699 }
3700
3701 /*
3702@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
3703 if (fixed && addr > (mm->task_size - len))
3704 return -EINVAL;
3705
3706+#ifdef CONFIG_PAX_RANDMMAP
3707+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
3708+ addr = 0;
3709+#endif
3710+
3711 /* If hint, make sure it matches our alignment restrictions */
3712 if (!fixed && addr) {
3713 addr = _ALIGN_UP(addr, 1ul << pshift);
3714diff --git a/arch/powerpc/platforms/52xx/lite5200_pm.c b/arch/powerpc/platforms/52xx/lite5200_pm.c
3715index b5c753d..8f01abe 100644
3716--- a/arch/powerpc/platforms/52xx/lite5200_pm.c
3717+++ b/arch/powerpc/platforms/52xx/lite5200_pm.c
3718@@ -235,7 +235,7 @@ static void lite5200_pm_end(void)
3719 lite5200_pm_target_state = PM_SUSPEND_ON;
3720 }
3721
3722-static struct platform_suspend_ops lite5200_pm_ops = {
3723+static const struct platform_suspend_ops lite5200_pm_ops = {
3724 .valid = lite5200_pm_valid,
3725 .begin = lite5200_pm_begin,
3726 .prepare = lite5200_pm_prepare,
3727diff --git a/arch/powerpc/platforms/52xx/mpc52xx_pm.c b/arch/powerpc/platforms/52xx/mpc52xx_pm.c
3728index a55b0b6..478c18e 100644
3729--- a/arch/powerpc/platforms/52xx/mpc52xx_pm.c
3730+++ b/arch/powerpc/platforms/52xx/mpc52xx_pm.c
3731@@ -180,7 +180,7 @@ void mpc52xx_pm_finish(void)
3732 iounmap(mbar);
3733 }
3734
3735-static struct platform_suspend_ops mpc52xx_pm_ops = {
3736+static const struct platform_suspend_ops mpc52xx_pm_ops = {
3737 .valid = mpc52xx_pm_valid,
3738 .prepare = mpc52xx_pm_prepare,
3739 .enter = mpc52xx_pm_enter,
3740diff --git a/arch/powerpc/platforms/83xx/suspend.c b/arch/powerpc/platforms/83xx/suspend.c
3741index 08e65fc..643d3ac 100644
3742--- a/arch/powerpc/platforms/83xx/suspend.c
3743+++ b/arch/powerpc/platforms/83xx/suspend.c
3744@@ -273,7 +273,7 @@ static int mpc83xx_is_pci_agent(void)
3745 return ret;
3746 }
3747
3748-static struct platform_suspend_ops mpc83xx_suspend_ops = {
3749+static const struct platform_suspend_ops mpc83xx_suspend_ops = {
3750 .valid = mpc83xx_suspend_valid,
3751 .begin = mpc83xx_suspend_begin,
3752 .enter = mpc83xx_suspend_enter,
3753diff --git a/arch/powerpc/platforms/cell/iommu.c b/arch/powerpc/platforms/cell/iommu.c
3754index ca5bfdf..1602e09 100644
3755--- a/arch/powerpc/platforms/cell/iommu.c
3756+++ b/arch/powerpc/platforms/cell/iommu.c
3757@@ -642,7 +642,7 @@ static int dma_fixed_dma_supported(struct device *dev, u64 mask)
3758
3759 static int dma_set_mask_and_switch(struct device *dev, u64 dma_mask);
3760
3761-struct dma_map_ops dma_iommu_fixed_ops = {
3762+const struct dma_map_ops dma_iommu_fixed_ops = {
3763 .alloc_coherent = dma_fixed_alloc_coherent,
3764 .free_coherent = dma_fixed_free_coherent,
3765 .map_sg = dma_fixed_map_sg,
3766diff --git a/arch/powerpc/platforms/ps3/system-bus.c b/arch/powerpc/platforms/ps3/system-bus.c
3767index e34b305..20e48ec 100644
3768--- a/arch/powerpc/platforms/ps3/system-bus.c
3769+++ b/arch/powerpc/platforms/ps3/system-bus.c
3770@@ -694,7 +694,7 @@ static int ps3_dma_supported(struct device *_dev, u64 mask)
3771 return mask >= DMA_BIT_MASK(32);
3772 }
3773
3774-static struct dma_map_ops ps3_sb_dma_ops = {
3775+static const struct dma_map_ops ps3_sb_dma_ops = {
3776 .alloc_coherent = ps3_alloc_coherent,
3777 .free_coherent = ps3_free_coherent,
3778 .map_sg = ps3_sb_map_sg,
3779@@ -704,7 +704,7 @@ static struct dma_map_ops ps3_sb_dma_ops = {
3780 .unmap_page = ps3_unmap_page,
3781 };
3782
3783-static struct dma_map_ops ps3_ioc0_dma_ops = {
3784+static const struct dma_map_ops ps3_ioc0_dma_ops = {
3785 .alloc_coherent = ps3_alloc_coherent,
3786 .free_coherent = ps3_free_coherent,
3787 .map_sg = ps3_ioc0_map_sg,
3788diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
3789index f0e6f28..60d53ed 100644
3790--- a/arch/powerpc/platforms/pseries/Kconfig
3791+++ b/arch/powerpc/platforms/pseries/Kconfig
3792@@ -2,6 +2,8 @@ config PPC_PSERIES
3793 depends on PPC64 && PPC_BOOK3S
3794 bool "IBM pSeries & new (POWER5-based) iSeries"
3795 select MPIC
3796+ select PCI_MSI
3797+ select XICS
3798 select PPC_I8259
3799 select PPC_RTAS
3800 select RTAS_ERROR_LOGGING
3801diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
3802index 43c0aca..42c045b 100644
3803--- a/arch/s390/Kconfig
3804+++ b/arch/s390/Kconfig
3805@@ -194,28 +194,26 @@ config AUDIT_ARCH
3806
3807 config S390_SWITCH_AMODE
3808 bool "Switch kernel/user addressing modes"
3809+ default y
3810 help
3811 This option allows to switch the addressing modes of kernel and user
3812- space. The kernel parameter switch_amode=on will enable this feature,
3813- default is disabled. Enabling this (via kernel parameter) on machines
3814- earlier than IBM System z9-109 EC/BC will reduce system performance.
3815+ space. Enabling this on machines earlier than IBM System z9-109 EC/BC
3816+ will reduce system performance.
3817
3818 Note that this option will also be selected by selecting the execute
3819- protection option below. Enabling the execute protection via the
3820- noexec kernel parameter will also switch the addressing modes,
3821- independent of the switch_amode kernel parameter.
3822+ protection option below. Enabling the execute protection will also
3823+ switch the addressing modes, independent of this option.
3824
3825
3826 config S390_EXEC_PROTECT
3827 bool "Data execute protection"
3828+ default y
3829 select S390_SWITCH_AMODE
3830 help
3831 This option allows to enable a buffer overflow protection for user
3832 space programs and it also selects the addressing mode option above.
3833- The kernel parameter noexec=on will enable this feature and also
3834- switch the addressing modes, default is disabled. Enabling this (via
3835- kernel parameter) on machines earlier than IBM System z9-109 EC/BC
3836- will reduce system performance.
3837+ Enabling this on machines earlier than IBM System z9-109 EC/BC will
3838+ reduce system performance.
3839
3840 comment "Code generation options"
3841
3842diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
3843index e885442..5e6c303 100644
3844--- a/arch/s390/include/asm/elf.h
3845+++ b/arch/s390/include/asm/elf.h
3846@@ -164,6 +164,13 @@ extern unsigned int vdso_enabled;
3847 that it will "exec", and that there is sufficient room for the brk. */
3848 #define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
3849
3850+#ifdef CONFIG_PAX_ASLR
3851+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
3852+
3853+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3854+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26 )
3855+#endif
3856+
3857 /* This yields a mask that user programs can use to figure out what
3858 instruction set this CPU supports. */
3859
3860diff --git a/arch/s390/include/asm/setup.h b/arch/s390/include/asm/setup.h
3861index e37478e..9ce0e9f 100644
3862--- a/arch/s390/include/asm/setup.h
3863+++ b/arch/s390/include/asm/setup.h
3864@@ -50,13 +50,13 @@ extern unsigned long memory_end;
3865 void detect_memory_layout(struct mem_chunk chunk[]);
3866
3867 #ifdef CONFIG_S390_SWITCH_AMODE
3868-extern unsigned int switch_amode;
3869+#define switch_amode (1)
3870 #else
3871 #define switch_amode (0)
3872 #endif
3873
3874 #ifdef CONFIG_S390_EXEC_PROTECT
3875-extern unsigned int s390_noexec;
3876+#define s390_noexec (1)
3877 #else
3878 #define s390_noexec (0)
3879 #endif
3880diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
3881index 8377e91..e28e6f1 100644
3882--- a/arch/s390/include/asm/uaccess.h
3883+++ b/arch/s390/include/asm/uaccess.h
3884@@ -232,6 +232,10 @@ static inline unsigned long __must_check
3885 copy_to_user(void __user *to, const void *from, unsigned long n)
3886 {
3887 might_fault();
3888+
3889+ if ((long)n < 0)
3890+ return n;
3891+
3892 if (access_ok(VERIFY_WRITE, to, n))
3893 n = __copy_to_user(to, from, n);
3894 return n;
3895@@ -257,6 +261,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
3896 static inline unsigned long __must_check
3897 __copy_from_user(void *to, const void __user *from, unsigned long n)
3898 {
3899+ if ((long)n < 0)
3900+ return n;
3901+
3902 if (__builtin_constant_p(n) && (n <= 256))
3903 return uaccess.copy_from_user_small(n, from, to);
3904 else
3905@@ -283,6 +290,10 @@ static inline unsigned long __must_check
3906 copy_from_user(void *to, const void __user *from, unsigned long n)
3907 {
3908 might_fault();
3909+
3910+ if ((long)n < 0)
3911+ return n;
3912+
3913 if (access_ok(VERIFY_READ, from, n))
3914 n = __copy_from_user(to, from, n);
3915 else
3916diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
3917index 639380a..72e3c02 100644
3918--- a/arch/s390/kernel/module.c
3919+++ b/arch/s390/kernel/module.c
3920@@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
3921
3922 /* Increase core size by size of got & plt and set start
3923 offsets for got and plt. */
3924- me->core_size = ALIGN(me->core_size, 4);
3925- me->arch.got_offset = me->core_size;
3926- me->core_size += me->arch.got_size;
3927- me->arch.plt_offset = me->core_size;
3928- me->core_size += me->arch.plt_size;
3929+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
3930+ me->arch.got_offset = me->core_size_rw;
3931+ me->core_size_rw += me->arch.got_size;
3932+ me->arch.plt_offset = me->core_size_rx;
3933+ me->core_size_rx += me->arch.plt_size;
3934 return 0;
3935 }
3936
3937@@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3938 if (info->got_initialized == 0) {
3939 Elf_Addr *gotent;
3940
3941- gotent = me->module_core + me->arch.got_offset +
3942+ gotent = me->module_core_rw + me->arch.got_offset +
3943 info->got_offset;
3944 *gotent = val;
3945 info->got_initialized = 1;
3946@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3947 else if (r_type == R_390_GOTENT ||
3948 r_type == R_390_GOTPLTENT)
3949 *(unsigned int *) loc =
3950- (val + (Elf_Addr) me->module_core - loc) >> 1;
3951+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3952 else if (r_type == R_390_GOT64 ||
3953 r_type == R_390_GOTPLT64)
3954 *(unsigned long *) loc = val;
3955@@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3956 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3957 if (info->plt_initialized == 0) {
3958 unsigned int *ip;
3959- ip = me->module_core + me->arch.plt_offset +
3960+ ip = me->module_core_rx + me->arch.plt_offset +
3961 info->plt_offset;
3962 #ifndef CONFIG_64BIT
3963 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3964@@ -319,7 +319,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3965 val - loc + 0xffffUL < 0x1ffffeUL) ||
3966 (r_type == R_390_PLT32DBL &&
3967 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
3968- val = (Elf_Addr) me->module_core +
3969+ val = (Elf_Addr) me->module_core_rx +
3970 me->arch.plt_offset +
3971 info->plt_offset;
3972 val += rela->r_addend - loc;
3973@@ -341,7 +341,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3974 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3975 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3976 val = val + rela->r_addend -
3977- ((Elf_Addr) me->module_core + me->arch.got_offset);
3978+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3979 if (r_type == R_390_GOTOFF16)
3980 *(unsigned short *) loc = val;
3981 else if (r_type == R_390_GOTOFF32)
3982@@ -351,7 +351,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3983 break;
3984 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3985 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3986- val = (Elf_Addr) me->module_core + me->arch.got_offset +
3987+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3988 rela->r_addend - loc;
3989 if (r_type == R_390_GOTPC)
3990 *(unsigned int *) loc = val;
3991diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
3992index 061479f..dbfb08c 100644
3993--- a/arch/s390/kernel/setup.c
3994+++ b/arch/s390/kernel/setup.c
3995@@ -306,9 +306,6 @@ static int __init early_parse_mem(char *p)
3996 early_param("mem", early_parse_mem);
3997
3998 #ifdef CONFIG_S390_SWITCH_AMODE
3999-unsigned int switch_amode = 0;
4000-EXPORT_SYMBOL_GPL(switch_amode);
4001-
4002 static int set_amode_and_uaccess(unsigned long user_amode,
4003 unsigned long user32_amode)
4004 {
4005@@ -334,17 +331,6 @@ static int set_amode_and_uaccess(unsigned long user_amode,
4006 return 0;
4007 }
4008 }
4009-
4010-/*
4011- * Switch kernel/user addressing modes?
4012- */
4013-static int __init early_parse_switch_amode(char *p)
4014-{
4015- switch_amode = 1;
4016- return 0;
4017-}
4018-early_param("switch_amode", early_parse_switch_amode);
4019-
4020 #else /* CONFIG_S390_SWITCH_AMODE */
4021 static inline int set_amode_and_uaccess(unsigned long user_amode,
4022 unsigned long user32_amode)
4023@@ -353,24 +339,6 @@ static inline int set_amode_and_uaccess(unsigned long user_amode,
4024 }
4025 #endif /* CONFIG_S390_SWITCH_AMODE */
4026
4027-#ifdef CONFIG_S390_EXEC_PROTECT
4028-unsigned int s390_noexec = 0;
4029-EXPORT_SYMBOL_GPL(s390_noexec);
4030-
4031-/*
4032- * Enable execute protection?
4033- */
4034-static int __init early_parse_noexec(char *p)
4035-{
4036- if (!strncmp(p, "off", 3))
4037- return 0;
4038- switch_amode = 1;
4039- s390_noexec = 1;
4040- return 0;
4041-}
4042-early_param("noexec", early_parse_noexec);
4043-#endif /* CONFIG_S390_EXEC_PROTECT */
4044-
4045 static void setup_addressing_mode(void)
4046 {
4047 if (s390_noexec) {
4048diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4049index f4558cc..e461f37 100644
4050--- a/arch/s390/mm/mmap.c
4051+++ b/arch/s390/mm/mmap.c
4052@@ -78,10 +78,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4053 */
4054 if (mmap_is_legacy()) {
4055 mm->mmap_base = TASK_UNMAPPED_BASE;
4056+
4057+#ifdef CONFIG_PAX_RANDMMAP
4058+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4059+ mm->mmap_base += mm->delta_mmap;
4060+#endif
4061+
4062 mm->get_unmapped_area = arch_get_unmapped_area;
4063 mm->unmap_area = arch_unmap_area;
4064 } else {
4065 mm->mmap_base = mmap_base();
4066+
4067+#ifdef CONFIG_PAX_RANDMMAP
4068+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4069+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4070+#endif
4071+
4072 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4073 mm->unmap_area = arch_unmap_area_topdown;
4074 }
4075@@ -153,10 +165,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4076 */
4077 if (mmap_is_legacy()) {
4078 mm->mmap_base = TASK_UNMAPPED_BASE;
4079+
4080+#ifdef CONFIG_PAX_RANDMMAP
4081+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4082+ mm->mmap_base += mm->delta_mmap;
4083+#endif
4084+
4085 mm->get_unmapped_area = s390_get_unmapped_area;
4086 mm->unmap_area = arch_unmap_area;
4087 } else {
4088 mm->mmap_base = mmap_base();
4089+
4090+#ifdef CONFIG_PAX_RANDMMAP
4091+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4092+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4093+#endif
4094+
4095 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4096 mm->unmap_area = arch_unmap_area_topdown;
4097 }
4098diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4099index 589d5c7..669e274 100644
4100--- a/arch/score/include/asm/system.h
4101+++ b/arch/score/include/asm/system.h
4102@@ -17,7 +17,7 @@ do { \
4103 #define finish_arch_switch(prev) do {} while (0)
4104
4105 typedef void (*vi_handler_t)(void);
4106-extern unsigned long arch_align_stack(unsigned long sp);
4107+#define arch_align_stack(x) (x)
4108
4109 #define mb() barrier()
4110 #define rmb() barrier()
4111diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4112index 25d0803..d6c8e36 100644
4113--- a/arch/score/kernel/process.c
4114+++ b/arch/score/kernel/process.c
4115@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4116
4117 return task_pt_regs(task)->cp0_epc;
4118 }
4119-
4120-unsigned long arch_align_stack(unsigned long sp)
4121-{
4122- return sp;
4123-}
4124diff --git a/arch/sh/boards/mach-hp6xx/pm.c b/arch/sh/boards/mach-hp6xx/pm.c
4125index d936c1a..304a252 100644
4126--- a/arch/sh/boards/mach-hp6xx/pm.c
4127+++ b/arch/sh/boards/mach-hp6xx/pm.c
4128@@ -143,7 +143,7 @@ static int hp6x0_pm_enter(suspend_state_t state)
4129 return 0;
4130 }
4131
4132-static struct platform_suspend_ops hp6x0_pm_ops = {
4133+static const struct platform_suspend_ops hp6x0_pm_ops = {
4134 .enter = hp6x0_pm_enter,
4135 .valid = suspend_valid_only_mem,
4136 };
4137diff --git a/arch/sh/kernel/cpu/sh4/sq.c b/arch/sh/kernel/cpu/sh4/sq.c
4138index 8a8a993..7b3079b 100644
4139--- a/arch/sh/kernel/cpu/sh4/sq.c
4140+++ b/arch/sh/kernel/cpu/sh4/sq.c
4141@@ -327,7 +327,7 @@ static struct attribute *sq_sysfs_attrs[] = {
4142 NULL,
4143 };
4144
4145-static struct sysfs_ops sq_sysfs_ops = {
4146+static const struct sysfs_ops sq_sysfs_ops = {
4147 .show = sq_sysfs_show,
4148 .store = sq_sysfs_store,
4149 };
4150diff --git a/arch/sh/kernel/cpu/shmobile/pm.c b/arch/sh/kernel/cpu/shmobile/pm.c
4151index ee3c2aa..c49cee6 100644
4152--- a/arch/sh/kernel/cpu/shmobile/pm.c
4153+++ b/arch/sh/kernel/cpu/shmobile/pm.c
4154@@ -58,7 +58,7 @@ static int sh_pm_enter(suspend_state_t state)
4155 return 0;
4156 }
4157
4158-static struct platform_suspend_ops sh_pm_ops = {
4159+static const struct platform_suspend_ops sh_pm_ops = {
4160 .enter = sh_pm_enter,
4161 .valid = suspend_valid_only_mem,
4162 };
4163diff --git a/arch/sh/kernel/kgdb.c b/arch/sh/kernel/kgdb.c
4164index 3e532d0..9faa306 100644
4165--- a/arch/sh/kernel/kgdb.c
4166+++ b/arch/sh/kernel/kgdb.c
4167@@ -271,7 +271,7 @@ void kgdb_arch_exit(void)
4168 {
4169 }
4170
4171-struct kgdb_arch arch_kgdb_ops = {
4172+const struct kgdb_arch arch_kgdb_ops = {
4173 /* Breakpoint instruction: trapa #0x3c */
4174 #ifdef CONFIG_CPU_LITTLE_ENDIAN
4175 .gdb_bpt_instr = { 0x3c, 0xc3 },
4176diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4177index afeb710..d1d1289 100644
4178--- a/arch/sh/mm/mmap.c
4179+++ b/arch/sh/mm/mmap.c
4180@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4181 addr = PAGE_ALIGN(addr);
4182
4183 vma = find_vma(mm, addr);
4184- if (TASK_SIZE - len >= addr &&
4185- (!vma || addr + len <= vma->vm_start))
4186+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4187 return addr;
4188 }
4189
4190@@ -106,7 +105,7 @@ full_search:
4191 }
4192 return -ENOMEM;
4193 }
4194- if (likely(!vma || addr + len <= vma->vm_start)) {
4195+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4196 /*
4197 * Remember the place where we stopped the search:
4198 */
4199@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4200 addr = PAGE_ALIGN(addr);
4201
4202 vma = find_vma(mm, addr);
4203- if (TASK_SIZE - len >= addr &&
4204- (!vma || addr + len <= vma->vm_start))
4205+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4206 return addr;
4207 }
4208
4209@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4210 /* make sure it can fit in the remaining address space */
4211 if (likely(addr > len)) {
4212 vma = find_vma(mm, addr-len);
4213- if (!vma || addr <= vma->vm_start) {
4214+ if (check_heap_stack_gap(vma, addr - len, len)) {
4215 /* remember the address as a hint for next time */
4216 return (mm->free_area_cache = addr-len);
4217 }
4218@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4219 if (unlikely(mm->mmap_base < len))
4220 goto bottomup;
4221
4222- addr = mm->mmap_base-len;
4223- if (do_colour_align)
4224- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4225+ addr = mm->mmap_base - len;
4226
4227 do {
4228+ if (do_colour_align)
4229+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4230 /*
4231 * Lookup failure means no vma is above this address,
4232 * else if new region fits below vma->vm_start,
4233 * return with success:
4234 */
4235 vma = find_vma(mm, addr);
4236- if (likely(!vma || addr+len <= vma->vm_start)) {
4237+ if (likely(check_heap_stack_gap(vma, addr, len))) {
4238 /* remember the address as a hint for next time */
4239 return (mm->free_area_cache = addr);
4240 }
4241@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4242 mm->cached_hole_size = vma->vm_start - addr;
4243
4244 /* try just below the current vma->vm_start */
4245- addr = vma->vm_start-len;
4246- if (do_colour_align)
4247- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4248- } while (likely(len < vma->vm_start));
4249+ addr = skip_heap_stack_gap(vma, len);
4250+ } while (!IS_ERR_VALUE(addr));
4251
4252 bottomup:
4253 /*
4254diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
4255index 113225b..7fd04e7 100644
4256--- a/arch/sparc/Makefile
4257+++ b/arch/sparc/Makefile
4258@@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
4259 # Export what is needed by arch/sparc/boot/Makefile
4260 export VMLINUX_INIT VMLINUX_MAIN
4261 VMLINUX_INIT := $(head-y) $(init-y)
4262-VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4263+VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4264 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
4265 VMLINUX_MAIN += $(drivers-y) $(net-y)
4266
4267diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
4268index f5cc06f..f858d47 100644
4269--- a/arch/sparc/include/asm/atomic_64.h
4270+++ b/arch/sparc/include/asm/atomic_64.h
4271@@ -14,18 +14,40 @@
4272 #define ATOMIC64_INIT(i) { (i) }
4273
4274 #define atomic_read(v) ((v)->counter)
4275+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
4276+{
4277+ return v->counter;
4278+}
4279 #define atomic64_read(v) ((v)->counter)
4280+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
4281+{
4282+ return v->counter;
4283+}
4284
4285 #define atomic_set(v, i) (((v)->counter) = i)
4286+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
4287+{
4288+ v->counter = i;
4289+}
4290 #define atomic64_set(v, i) (((v)->counter) = i)
4291+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
4292+{
4293+ v->counter = i;
4294+}
4295
4296 extern void atomic_add(int, atomic_t *);
4297+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
4298 extern void atomic64_add(long, atomic64_t *);
4299+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
4300 extern void atomic_sub(int, atomic_t *);
4301+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
4302 extern void atomic64_sub(long, atomic64_t *);
4303+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
4304
4305 extern int atomic_add_ret(int, atomic_t *);
4306+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
4307 extern long atomic64_add_ret(long, atomic64_t *);
4308+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
4309 extern int atomic_sub_ret(int, atomic_t *);
4310 extern long atomic64_sub_ret(long, atomic64_t *);
4311
4312@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4313 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
4314
4315 #define atomic_inc_return(v) atomic_add_ret(1, v)
4316+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
4317+{
4318+ return atomic_add_ret_unchecked(1, v);
4319+}
4320 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
4321+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
4322+{
4323+ return atomic64_add_ret_unchecked(1, v);
4324+}
4325
4326 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
4327 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
4328
4329 #define atomic_add_return(i, v) atomic_add_ret(i, v)
4330+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
4331+{
4332+ return atomic_add_ret_unchecked(i, v);
4333+}
4334 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
4335+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
4336+{
4337+ return atomic64_add_ret_unchecked(i, v);
4338+}
4339
4340 /*
4341 * atomic_inc_and_test - increment and test
4342@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4343 * other cases.
4344 */
4345 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
4346+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
4347+{
4348+ return atomic_inc_return_unchecked(v) == 0;
4349+}
4350 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
4351
4352 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
4353@@ -59,30 +101,65 @@ extern long atomic64_sub_ret(long, atomic64_t *);
4354 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
4355
4356 #define atomic_inc(v) atomic_add(1, v)
4357+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
4358+{
4359+ atomic_add_unchecked(1, v);
4360+}
4361 #define atomic64_inc(v) atomic64_add(1, v)
4362+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
4363+{
4364+ atomic64_add_unchecked(1, v);
4365+}
4366
4367 #define atomic_dec(v) atomic_sub(1, v)
4368+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
4369+{
4370+ atomic_sub_unchecked(1, v);
4371+}
4372 #define atomic64_dec(v) atomic64_sub(1, v)
4373+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
4374+{
4375+ atomic64_sub_unchecked(1, v);
4376+}
4377
4378 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
4379 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
4380
4381 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
4382+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
4383+{
4384+ return cmpxchg(&v->counter, old, new);
4385+}
4386 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
4387+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
4388+{
4389+ return xchg(&v->counter, new);
4390+}
4391
4392 static inline int atomic_add_unless(atomic_t *v, int a, int u)
4393 {
4394- int c, old;
4395+ int c, old, new;
4396 c = atomic_read(v);
4397 for (;;) {
4398- if (unlikely(c == (u)))
4399+ if (unlikely(c == u))
4400 break;
4401- old = atomic_cmpxchg((v), c, c + (a));
4402+
4403+ asm volatile("addcc %2, %0, %0\n"
4404+
4405+#ifdef CONFIG_PAX_REFCOUNT
4406+ "tvs %%icc, 6\n"
4407+#endif
4408+
4409+ : "=r" (new)
4410+ : "0" (c), "ir" (a)
4411+ : "cc");
4412+
4413+ old = atomic_cmpxchg(v, c, new);
4414 if (likely(old == c))
4415 break;
4416 c = old;
4417 }
4418- return c != (u);
4419+ return c != u;
4420 }
4421
4422 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
4423@@ -90,20 +167,35 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
4424 #define atomic64_cmpxchg(v, o, n) \
4425 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
4426 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
4427+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
4428+{
4429+ return xchg(&v->counter, new);
4430+}
4431
4432 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
4433 {
4434- long c, old;
4435+ long c, old, new;
4436 c = atomic64_read(v);
4437 for (;;) {
4438- if (unlikely(c == (u)))
4439+ if (unlikely(c == u))
4440 break;
4441- old = atomic64_cmpxchg((v), c, c + (a));
4442+
4443+ asm volatile("addcc %2, %0, %0\n"
4444+
4445+#ifdef CONFIG_PAX_REFCOUNT
4446+ "tvs %%xcc, 6\n"
4447+#endif
4448+
4449+ : "=r" (new)
4450+ : "0" (c), "ir" (a)
4451+ : "cc");
4452+
4453+ old = atomic64_cmpxchg(v, c, new);
4454 if (likely(old == c))
4455 break;
4456 c = old;
4457 }
4458- return c != (u);
4459+ return c != u;
4460 }
4461
4462 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4463diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
4464index 41f85ae..fb54d5e 100644
4465--- a/arch/sparc/include/asm/cache.h
4466+++ b/arch/sparc/include/asm/cache.h
4467@@ -8,7 +8,7 @@
4468 #define _SPARC_CACHE_H
4469
4470 #define L1_CACHE_SHIFT 5
4471-#define L1_CACHE_BYTES 32
4472+#define L1_CACHE_BYTES 32UL
4473 #define L1_CACHE_ALIGN(x) ((((x)+(L1_CACHE_BYTES-1))&~(L1_CACHE_BYTES-1)))
4474
4475 #ifdef CONFIG_SPARC32
4476diff --git a/arch/sparc/include/asm/dma-mapping.h b/arch/sparc/include/asm/dma-mapping.h
4477index 5a8c308..38def92 100644
4478--- a/arch/sparc/include/asm/dma-mapping.h
4479+++ b/arch/sparc/include/asm/dma-mapping.h
4480@@ -14,10 +14,10 @@ extern int dma_set_mask(struct device *dev, u64 dma_mask);
4481 #define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
4482 #define dma_is_consistent(d, h) (1)
4483
4484-extern struct dma_map_ops *dma_ops, pci32_dma_ops;
4485+extern const struct dma_map_ops *dma_ops, pci32_dma_ops;
4486 extern struct bus_type pci_bus_type;
4487
4488-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4489+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
4490 {
4491 #if defined(CONFIG_SPARC32) && defined(CONFIG_PCI)
4492 if (dev->bus == &pci_bus_type)
4493@@ -31,7 +31,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
4494 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
4495 dma_addr_t *dma_handle, gfp_t flag)
4496 {
4497- struct dma_map_ops *ops = get_dma_ops(dev);
4498+ const struct dma_map_ops *ops = get_dma_ops(dev);
4499 void *cpu_addr;
4500
4501 cpu_addr = ops->alloc_coherent(dev, size, dma_handle, flag);
4502@@ -42,7 +42,7 @@ static inline void *dma_alloc_coherent(struct device *dev, size_t size,
4503 static inline void dma_free_coherent(struct device *dev, size_t size,
4504 void *cpu_addr, dma_addr_t dma_handle)
4505 {
4506- struct dma_map_ops *ops = get_dma_ops(dev);
4507+ const struct dma_map_ops *ops = get_dma_ops(dev);
4508
4509 debug_dma_free_coherent(dev, size, cpu_addr, dma_handle);
4510 ops->free_coherent(dev, size, cpu_addr, dma_handle);
4511diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
4512index 381a1b5..b97e3ff 100644
4513--- a/arch/sparc/include/asm/elf_32.h
4514+++ b/arch/sparc/include/asm/elf_32.h
4515@@ -116,6 +116,13 @@ typedef struct {
4516
4517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
4518
4519+#ifdef CONFIG_PAX_ASLR
4520+#define PAX_ELF_ET_DYN_BASE 0x10000UL
4521+
4522+#define PAX_DELTA_MMAP_LEN 16
4523+#define PAX_DELTA_STACK_LEN 16
4524+#endif
4525+
4526 /* This yields a mask that user programs can use to figure out what
4527 instruction set this cpu supports. This can NOT be done in userspace
4528 on Sparc. */
4529diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
4530index 9968085..c2106ef 100644
4531--- a/arch/sparc/include/asm/elf_64.h
4532+++ b/arch/sparc/include/asm/elf_64.h
4533@@ -163,6 +163,12 @@ typedef struct {
4534 #define ELF_ET_DYN_BASE 0x0000010000000000UL
4535 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
4536
4537+#ifdef CONFIG_PAX_ASLR
4538+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
4539+
4540+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
4541+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
4542+#endif
4543
4544 /* This yields a mask that user programs can use to figure out what
4545 instruction set this cpu supports. */
4546diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
4547index e0cabe7..efd60f1 100644
4548--- a/arch/sparc/include/asm/pgtable_32.h
4549+++ b/arch/sparc/include/asm/pgtable_32.h
4550@@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
4551 BTFIXUPDEF_INT(page_none)
4552 BTFIXUPDEF_INT(page_copy)
4553 BTFIXUPDEF_INT(page_readonly)
4554+
4555+#ifdef CONFIG_PAX_PAGEEXEC
4556+BTFIXUPDEF_INT(page_shared_noexec)
4557+BTFIXUPDEF_INT(page_copy_noexec)
4558+BTFIXUPDEF_INT(page_readonly_noexec)
4559+#endif
4560+
4561 BTFIXUPDEF_INT(page_kernel)
4562
4563 #define PMD_SHIFT SUN4C_PMD_SHIFT
4564@@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
4565 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
4566 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
4567
4568+#ifdef CONFIG_PAX_PAGEEXEC
4569+extern pgprot_t PAGE_SHARED_NOEXEC;
4570+# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
4571+# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
4572+#else
4573+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4574+# define PAGE_COPY_NOEXEC PAGE_COPY
4575+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4576+#endif
4577+
4578 extern unsigned long page_kernel;
4579
4580 #ifdef MODULE
4581diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
4582index 1407c07..7e10231 100644
4583--- a/arch/sparc/include/asm/pgtsrmmu.h
4584+++ b/arch/sparc/include/asm/pgtsrmmu.h
4585@@ -115,6 +115,13 @@
4586 SRMMU_EXEC | SRMMU_REF)
4587 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4588 SRMMU_EXEC | SRMMU_REF)
4589+
4590+#ifdef CONFIG_PAX_PAGEEXEC
4591+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4592+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4593+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4594+#endif
4595+
4596 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4597 SRMMU_DIRTY | SRMMU_REF)
4598
4599diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
4600index 43e5147..47622a1 100644
4601--- a/arch/sparc/include/asm/spinlock_64.h
4602+++ b/arch/sparc/include/asm/spinlock_64.h
4603@@ -92,14 +92,19 @@ static inline void __raw_spin_lock_flags(raw_spinlock_t *lock, unsigned long fla
4604
4605 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
4606
4607-static void inline arch_read_lock(raw_rwlock_t *lock)
4608+static inline void arch_read_lock(raw_rwlock_t *lock)
4609 {
4610 unsigned long tmp1, tmp2;
4611
4612 __asm__ __volatile__ (
4613 "1: ldsw [%2], %0\n"
4614 " brlz,pn %0, 2f\n"
4615-"4: add %0, 1, %1\n"
4616+"4: addcc %0, 1, %1\n"
4617+
4618+#ifdef CONFIG_PAX_REFCOUNT
4619+" tvs %%icc, 6\n"
4620+#endif
4621+
4622 " cas [%2], %0, %1\n"
4623 " cmp %0, %1\n"
4624 " bne,pn %%icc, 1b\n"
4625@@ -112,10 +117,10 @@ static void inline arch_read_lock(raw_rwlock_t *lock)
4626 " .previous"
4627 : "=&r" (tmp1), "=&r" (tmp2)
4628 : "r" (lock)
4629- : "memory");
4630+ : "memory", "cc");
4631 }
4632
4633-static int inline arch_read_trylock(raw_rwlock_t *lock)
4634+static inline int arch_read_trylock(raw_rwlock_t *lock)
4635 {
4636 int tmp1, tmp2;
4637
4638@@ -123,7 +128,12 @@ static int inline arch_read_trylock(raw_rwlock_t *lock)
4639 "1: ldsw [%2], %0\n"
4640 " brlz,a,pn %0, 2f\n"
4641 " mov 0, %0\n"
4642-" add %0, 1, %1\n"
4643+" addcc %0, 1, %1\n"
4644+
4645+#ifdef CONFIG_PAX_REFCOUNT
4646+" tvs %%icc, 6\n"
4647+#endif
4648+
4649 " cas [%2], %0, %1\n"
4650 " cmp %0, %1\n"
4651 " bne,pn %%icc, 1b\n"
4652@@ -136,13 +146,18 @@ static int inline arch_read_trylock(raw_rwlock_t *lock)
4653 return tmp1;
4654 }
4655
4656-static void inline arch_read_unlock(raw_rwlock_t *lock)
4657+static inline void arch_read_unlock(raw_rwlock_t *lock)
4658 {
4659 unsigned long tmp1, tmp2;
4660
4661 __asm__ __volatile__(
4662 "1: lduw [%2], %0\n"
4663-" sub %0, 1, %1\n"
4664+" subcc %0, 1, %1\n"
4665+
4666+#ifdef CONFIG_PAX_REFCOUNT
4667+" tvs %%icc, 6\n"
4668+#endif
4669+
4670 " cas [%2], %0, %1\n"
4671 " cmp %0, %1\n"
4672 " bne,pn %%xcc, 1b\n"
4673@@ -152,7 +167,7 @@ static void inline arch_read_unlock(raw_rwlock_t *lock)
4674 : "memory");
4675 }
4676
4677-static void inline arch_write_lock(raw_rwlock_t *lock)
4678+static inline void arch_write_lock(raw_rwlock_t *lock)
4679 {
4680 unsigned long mask, tmp1, tmp2;
4681
4682@@ -177,7 +192,7 @@ static void inline arch_write_lock(raw_rwlock_t *lock)
4683 : "memory");
4684 }
4685
4686-static void inline arch_write_unlock(raw_rwlock_t *lock)
4687+static inline void arch_write_unlock(raw_rwlock_t *lock)
4688 {
4689 __asm__ __volatile__(
4690 " stw %%g0, [%0]"
4691@@ -186,7 +201,7 @@ static void inline arch_write_unlock(raw_rwlock_t *lock)
4692 : "memory");
4693 }
4694
4695-static int inline arch_write_trylock(raw_rwlock_t *lock)
4696+static inline int arch_write_trylock(raw_rwlock_t *lock)
4697 {
4698 unsigned long mask, tmp1, tmp2, result;
4699
4700diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
4701index 844d73a..f787fb9 100644
4702--- a/arch/sparc/include/asm/thread_info_32.h
4703+++ b/arch/sparc/include/asm/thread_info_32.h
4704@@ -50,6 +50,8 @@ struct thread_info {
4705 unsigned long w_saved;
4706
4707 struct restart_block restart_block;
4708+
4709+ unsigned long lowest_stack;
4710 };
4711
4712 /*
4713diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
4714index f78ad9a..9f55fc7 100644
4715--- a/arch/sparc/include/asm/thread_info_64.h
4716+++ b/arch/sparc/include/asm/thread_info_64.h
4717@@ -68,6 +68,8 @@ struct thread_info {
4718 struct pt_regs *kern_una_regs;
4719 unsigned int kern_una_insn;
4720
4721+ unsigned long lowest_stack;
4722+
4723 unsigned long fpregs[0] __attribute__ ((aligned(64)));
4724 };
4725
4726diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
4727index e88fbe5..96b0ce5 100644
4728--- a/arch/sparc/include/asm/uaccess.h
4729+++ b/arch/sparc/include/asm/uaccess.h
4730@@ -1,5 +1,13 @@
4731 #ifndef ___ASM_SPARC_UACCESS_H
4732 #define ___ASM_SPARC_UACCESS_H
4733+
4734+#ifdef __KERNEL__
4735+#ifndef __ASSEMBLY__
4736+#include <linux/types.h>
4737+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4738+#endif
4739+#endif
4740+
4741 #if defined(__sparc__) && defined(__arch64__)
4742 #include <asm/uaccess_64.h>
4743 #else
4744diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
4745index 8303ac4..07f333d 100644
4746--- a/arch/sparc/include/asm/uaccess_32.h
4747+++ b/arch/sparc/include/asm/uaccess_32.h
4748@@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
4749
4750 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4751 {
4752- if (n && __access_ok((unsigned long) to, n))
4753+ if ((long)n < 0)
4754+ return n;
4755+
4756+ if (n && __access_ok((unsigned long) to, n)) {
4757+ if (!__builtin_constant_p(n))
4758+ check_object_size(from, n, true);
4759 return __copy_user(to, (__force void __user *) from, n);
4760- else
4761+ } else
4762 return n;
4763 }
4764
4765 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
4766 {
4767+ if ((long)n < 0)
4768+ return n;
4769+
4770+ if (!__builtin_constant_p(n))
4771+ check_object_size(from, n, true);
4772+
4773 return __copy_user(to, (__force void __user *) from, n);
4774 }
4775
4776 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4777 {
4778- if (n && __access_ok((unsigned long) from, n))
4779+ if ((long)n < 0)
4780+ return n;
4781+
4782+ if (n && __access_ok((unsigned long) from, n)) {
4783+ if (!__builtin_constant_p(n))
4784+ check_object_size(to, n, false);
4785 return __copy_user((__force void __user *) to, from, n);
4786- else
4787+ } else
4788 return n;
4789 }
4790
4791 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
4792 {
4793+ if ((long)n < 0)
4794+ return n;
4795+
4796 return __copy_user((__force void __user *) to, from, n);
4797 }
4798
4799diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
4800index 9ea271e..7b8a271 100644
4801--- a/arch/sparc/include/asm/uaccess_64.h
4802+++ b/arch/sparc/include/asm/uaccess_64.h
4803@@ -9,6 +9,7 @@
4804 #include <linux/compiler.h>
4805 #include <linux/string.h>
4806 #include <linux/thread_info.h>
4807+#include <linux/kernel.h>
4808 #include <asm/asi.h>
4809 #include <asm/system.h>
4810 #include <asm/spitfire.h>
4811@@ -212,8 +213,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
4812 static inline unsigned long __must_check
4813 copy_from_user(void *to, const void __user *from, unsigned long size)
4814 {
4815- unsigned long ret = ___copy_from_user(to, from, size);
4816+ unsigned long ret;
4817
4818+ if ((long)size < 0 || size > INT_MAX)
4819+ return size;
4820+
4821+ if (!__builtin_constant_p(size))
4822+ check_object_size(to, size, false);
4823+
4824+ ret = ___copy_from_user(to, from, size);
4825 if (unlikely(ret))
4826 ret = copy_from_user_fixup(to, from, size);
4827 return ret;
4828@@ -228,8 +236,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
4829 static inline unsigned long __must_check
4830 copy_to_user(void __user *to, const void *from, unsigned long size)
4831 {
4832- unsigned long ret = ___copy_to_user(to, from, size);
4833+ unsigned long ret;
4834
4835+ if ((long)size < 0 || size > INT_MAX)
4836+ return size;
4837+
4838+ if (!__builtin_constant_p(size))
4839+ check_object_size(from, size, true);
4840+
4841+ ret = ___copy_to_user(to, from, size);
4842 if (unlikely(ret))
4843 ret = copy_to_user_fixup(to, from, size);
4844 return ret;
4845diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
4846index 2782681..77ded84 100644
4847--- a/arch/sparc/kernel/Makefile
4848+++ b/arch/sparc/kernel/Makefile
4849@@ -3,7 +3,7 @@
4850 #
4851
4852 asflags-y := -ansi
4853-ccflags-y := -Werror
4854+#ccflags-y := -Werror
4855
4856 extra-y := head_$(BITS).o
4857 extra-y += init_task.o
4858diff --git a/arch/sparc/kernel/iommu.c b/arch/sparc/kernel/iommu.c
4859index 7690cc2..ece64c9 100644
4860--- a/arch/sparc/kernel/iommu.c
4861+++ b/arch/sparc/kernel/iommu.c
4862@@ -826,7 +826,7 @@ static void dma_4u_sync_sg_for_cpu(struct device *dev,
4863 spin_unlock_irqrestore(&iommu->lock, flags);
4864 }
4865
4866-static struct dma_map_ops sun4u_dma_ops = {
4867+static const struct dma_map_ops sun4u_dma_ops = {
4868 .alloc_coherent = dma_4u_alloc_coherent,
4869 .free_coherent = dma_4u_free_coherent,
4870 .map_page = dma_4u_map_page,
4871@@ -837,7 +837,7 @@ static struct dma_map_ops sun4u_dma_ops = {
4872 .sync_sg_for_cpu = dma_4u_sync_sg_for_cpu,
4873 };
4874
4875-struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4876+const struct dma_map_ops *dma_ops = &sun4u_dma_ops;
4877 EXPORT_SYMBOL(dma_ops);
4878
4879 extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
4880diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c
4881index 9f61fd8..bd048db 100644
4882--- a/arch/sparc/kernel/ioport.c
4883+++ b/arch/sparc/kernel/ioport.c
4884@@ -392,7 +392,7 @@ static void sbus_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
4885 BUG();
4886 }
4887
4888-struct dma_map_ops sbus_dma_ops = {
4889+const struct dma_map_ops sbus_dma_ops = {
4890 .alloc_coherent = sbus_alloc_coherent,
4891 .free_coherent = sbus_free_coherent,
4892 .map_page = sbus_map_page,
4893@@ -403,7 +403,7 @@ struct dma_map_ops sbus_dma_ops = {
4894 .sync_sg_for_device = sbus_sync_sg_for_device,
4895 };
4896
4897-struct dma_map_ops *dma_ops = &sbus_dma_ops;
4898+const struct dma_map_ops *dma_ops = &sbus_dma_ops;
4899 EXPORT_SYMBOL(dma_ops);
4900
4901 static int __init sparc_register_ioport(void)
4902@@ -640,7 +640,7 @@ static void pci32_sync_sg_for_device(struct device *device, struct scatterlist *
4903 }
4904 }
4905
4906-struct dma_map_ops pci32_dma_ops = {
4907+const struct dma_map_ops pci32_dma_ops = {
4908 .alloc_coherent = pci32_alloc_coherent,
4909 .free_coherent = pci32_free_coherent,
4910 .map_page = pci32_map_page,
4911diff --git a/arch/sparc/kernel/kgdb_32.c b/arch/sparc/kernel/kgdb_32.c
4912index 04df4ed..55c4b6e 100644
4913--- a/arch/sparc/kernel/kgdb_32.c
4914+++ b/arch/sparc/kernel/kgdb_32.c
4915@@ -158,7 +158,7 @@ void kgdb_arch_exit(void)
4916 {
4917 }
4918
4919-struct kgdb_arch arch_kgdb_ops = {
4920+const struct kgdb_arch arch_kgdb_ops = {
4921 /* Breakpoint instruction: ta 0x7d */
4922 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x7d },
4923 };
4924diff --git a/arch/sparc/kernel/kgdb_64.c b/arch/sparc/kernel/kgdb_64.c
4925index f5a0fd4..d886f71 100644
4926--- a/arch/sparc/kernel/kgdb_64.c
4927+++ b/arch/sparc/kernel/kgdb_64.c
4928@@ -180,7 +180,7 @@ void kgdb_arch_exit(void)
4929 {
4930 }
4931
4932-struct kgdb_arch arch_kgdb_ops = {
4933+const struct kgdb_arch arch_kgdb_ops = {
4934 /* Breakpoint instruction: ta 0x72 */
4935 .gdb_bpt_instr = { 0x91, 0xd0, 0x20, 0x72 },
4936 };
4937diff --git a/arch/sparc/kernel/pci_sun4v.c b/arch/sparc/kernel/pci_sun4v.c
4938index 23c33ff..d137fbd 100644
4939--- a/arch/sparc/kernel/pci_sun4v.c
4940+++ b/arch/sparc/kernel/pci_sun4v.c
4941@@ -525,7 +525,7 @@ static void dma_4v_unmap_sg(struct device *dev, struct scatterlist *sglist,
4942 spin_unlock_irqrestore(&iommu->lock, flags);
4943 }
4944
4945-static struct dma_map_ops sun4v_dma_ops = {
4946+static const struct dma_map_ops sun4v_dma_ops = {
4947 .alloc_coherent = dma_4v_alloc_coherent,
4948 .free_coherent = dma_4v_free_coherent,
4949 .map_page = dma_4v_map_page,
4950diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
4951index c49865b..b41a81b 100644
4952--- a/arch/sparc/kernel/process_32.c
4953+++ b/arch/sparc/kernel/process_32.c
4954@@ -196,7 +196,7 @@ void __show_backtrace(unsigned long fp)
4955 rw->ins[4], rw->ins[5],
4956 rw->ins[6],
4957 rw->ins[7]);
4958- printk("%pS\n", (void *) rw->ins[7]);
4959+ printk("%pA\n", (void *) rw->ins[7]);
4960 rw = (struct reg_window32 *) rw->ins[6];
4961 }
4962 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
4963@@ -263,14 +263,14 @@ void show_regs(struct pt_regs *r)
4964
4965 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
4966 r->psr, r->pc, r->npc, r->y, print_tainted());
4967- printk("PC: <%pS>\n", (void *) r->pc);
4968+ printk("PC: <%pA>\n", (void *) r->pc);
4969 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4970 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
4971 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
4972 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4973 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
4974 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
4975- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
4976+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
4977
4978 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4979 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
4980@@ -305,7 +305,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
4981 rw = (struct reg_window32 *) fp;
4982 pc = rw->ins[7];
4983 printk("[%08lx : ", pc);
4984- printk("%pS ] ", (void *) pc);
4985+ printk("%pA ] ", (void *) pc);
4986 fp = rw->ins[6];
4987 } while (++count < 16);
4988 printk("\n");
4989diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
4990index cb70476..3d0c191 100644
4991--- a/arch/sparc/kernel/process_64.c
4992+++ b/arch/sparc/kernel/process_64.c
4993@@ -180,14 +180,14 @@ static void show_regwindow(struct pt_regs *regs)
4994 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
4995 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
4996 if (regs->tstate & TSTATE_PRIV)
4997- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
4998+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
4999 }
5000
5001 void show_regs(struct pt_regs *regs)
5002 {
5003 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5004 regs->tpc, regs->tnpc, regs->y, print_tainted());
5005- printk("TPC: <%pS>\n", (void *) regs->tpc);
5006+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5007 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5008 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5009 regs->u_regs[3]);
5010@@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
5011 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5012 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5013 regs->u_regs[15]);
5014- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5015+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5016 show_regwindow(regs);
5017 }
5018
5019@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5020 ((tp && tp->task) ? tp->task->pid : -1));
5021
5022 if (gp->tstate & TSTATE_PRIV) {
5023- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5024+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5025 (void *) gp->tpc,
5026 (void *) gp->o7,
5027 (void *) gp->i7,
5028diff --git a/arch/sparc/kernel/sigutil_64.c b/arch/sparc/kernel/sigutil_64.c
5029index 6edc4e5..06a69b4 100644
5030--- a/arch/sparc/kernel/sigutil_64.c
5031+++ b/arch/sparc/kernel/sigutil_64.c
5032@@ -2,6 +2,7 @@
5033 #include <linux/types.h>
5034 #include <linux/thread_info.h>
5035 #include <linux/uaccess.h>
5036+#include <linux/errno.h>
5037
5038 #include <asm/sigcontext.h>
5039 #include <asm/fpumacro.h>
5040diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5041index 3a82e65..ce0a53a 100644
5042--- a/arch/sparc/kernel/sys_sparc_32.c
5043+++ b/arch/sparc/kernel/sys_sparc_32.c
5044@@ -57,7 +57,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5045 if (ARCH_SUN4C && len > 0x20000000)
5046 return -ENOMEM;
5047 if (!addr)
5048- addr = TASK_UNMAPPED_BASE;
5049+ addr = current->mm->mmap_base;
5050
5051 if (flags & MAP_SHARED)
5052 addr = COLOUR_ALIGN(addr);
5053@@ -72,7 +72,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5054 }
5055 if (TASK_SIZE - PAGE_SIZE - len < addr)
5056 return -ENOMEM;
5057- if (!vmm || addr + len <= vmm->vm_start)
5058+ if (check_heap_stack_gap(vmm, addr, len))
5059 return addr;
5060 addr = vmm->vm_end;
5061 if (flags & MAP_SHARED)
5062diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5063index cfa0e19..98972ac 100644
5064--- a/arch/sparc/kernel/sys_sparc_64.c
5065+++ b/arch/sparc/kernel/sys_sparc_64.c
5066@@ -125,7 +125,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5067 /* We do not accept a shared mapping if it would violate
5068 * cache aliasing constraints.
5069 */
5070- if ((flags & MAP_SHARED) &&
5071+ if ((filp || (flags & MAP_SHARED)) &&
5072 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5073 return -EINVAL;
5074 return addr;
5075@@ -140,6 +140,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5076 if (filp || (flags & MAP_SHARED))
5077 do_color_align = 1;
5078
5079+#ifdef CONFIG_PAX_RANDMMAP
5080+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5081+#endif
5082+
5083 if (addr) {
5084 if (do_color_align)
5085 addr = COLOUR_ALIGN(addr, pgoff);
5086@@ -147,15 +151,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5087 addr = PAGE_ALIGN(addr);
5088
5089 vma = find_vma(mm, addr);
5090- if (task_size - len >= addr &&
5091- (!vma || addr + len <= vma->vm_start))
5092+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5093 return addr;
5094 }
5095
5096 if (len > mm->cached_hole_size) {
5097- start_addr = addr = mm->free_area_cache;
5098+ start_addr = addr = mm->free_area_cache;
5099 } else {
5100- start_addr = addr = TASK_UNMAPPED_BASE;
5101+ start_addr = addr = mm->mmap_base;
5102 mm->cached_hole_size = 0;
5103 }
5104
5105@@ -175,14 +178,14 @@ full_search:
5106 vma = find_vma(mm, VA_EXCLUDE_END);
5107 }
5108 if (unlikely(task_size < addr)) {
5109- if (start_addr != TASK_UNMAPPED_BASE) {
5110- start_addr = addr = TASK_UNMAPPED_BASE;
5111+ if (start_addr != mm->mmap_base) {
5112+ start_addr = addr = mm->mmap_base;
5113 mm->cached_hole_size = 0;
5114 goto full_search;
5115 }
5116 return -ENOMEM;
5117 }
5118- if (likely(!vma || addr + len <= vma->vm_start)) {
5119+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5120 /*
5121 * Remember the place where we stopped the search:
5122 */
5123@@ -216,7 +219,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5124 /* We do not accept a shared mapping if it would violate
5125 * cache aliasing constraints.
5126 */
5127- if ((flags & MAP_SHARED) &&
5128+ if ((filp || (flags & MAP_SHARED)) &&
5129 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5130 return -EINVAL;
5131 return addr;
5132@@ -237,8 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5133 addr = PAGE_ALIGN(addr);
5134
5135 vma = find_vma(mm, addr);
5136- if (task_size - len >= addr &&
5137- (!vma || addr + len <= vma->vm_start))
5138+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5139 return addr;
5140 }
5141
5142@@ -259,7 +261,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5143 /* make sure it can fit in the remaining address space */
5144 if (likely(addr > len)) {
5145 vma = find_vma(mm, addr-len);
5146- if (!vma || addr <= vma->vm_start) {
5147+ if (check_heap_stack_gap(vma, addr - len, len)) {
5148 /* remember the address as a hint for next time */
5149 return (mm->free_area_cache = addr-len);
5150 }
5151@@ -268,18 +270,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5152 if (unlikely(mm->mmap_base < len))
5153 goto bottomup;
5154
5155- addr = mm->mmap_base-len;
5156- if (do_color_align)
5157- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5158+ addr = mm->mmap_base - len;
5159
5160 do {
5161+ if (do_color_align)
5162+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5163 /*
5164 * Lookup failure means no vma is above this address,
5165 * else if new region fits below vma->vm_start,
5166 * return with success:
5167 */
5168 vma = find_vma(mm, addr);
5169- if (likely(!vma || addr+len <= vma->vm_start)) {
5170+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5171 /* remember the address as a hint for next time */
5172 return (mm->free_area_cache = addr);
5173 }
5174@@ -289,10 +291,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5175 mm->cached_hole_size = vma->vm_start - addr;
5176
5177 /* try just below the current vma->vm_start */
5178- addr = vma->vm_start-len;
5179- if (do_color_align)
5180- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5181- } while (likely(len < vma->vm_start));
5182+ addr = skip_heap_stack_gap(vma, len);
5183+ } while (!IS_ERR_VALUE(addr));
5184
5185 bottomup:
5186 /*
5187@@ -384,6 +384,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5188 current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
5189 sysctl_legacy_va_layout) {
5190 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5191+
5192+#ifdef CONFIG_PAX_RANDMMAP
5193+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5194+ mm->mmap_base += mm->delta_mmap;
5195+#endif
5196+
5197 mm->get_unmapped_area = arch_get_unmapped_area;
5198 mm->unmap_area = arch_unmap_area;
5199 } else {
5200@@ -398,6 +404,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5201 gap = (task_size / 6 * 5);
5202
5203 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5204+
5205+#ifdef CONFIG_PAX_RANDMMAP
5206+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5207+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5208+#endif
5209+
5210 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5211 mm->unmap_area = arch_unmap_area_topdown;
5212 }
5213diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
5214index c0490c7..84959d1 100644
5215--- a/arch/sparc/kernel/traps_32.c
5216+++ b/arch/sparc/kernel/traps_32.c
5217@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
5218 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
5219 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
5220
5221+extern void gr_handle_kernel_exploit(void);
5222+
5223 void die_if_kernel(char *str, struct pt_regs *regs)
5224 {
5225 static int die_counter;
5226@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5227 count++ < 30 &&
5228 (((unsigned long) rw) >= PAGE_OFFSET) &&
5229 !(((unsigned long) rw) & 0x7)) {
5230- printk("Caller[%08lx]: %pS\n", rw->ins[7],
5231+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
5232 (void *) rw->ins[7]);
5233 rw = (struct reg_window32 *)rw->ins[6];
5234 }
5235 }
5236 printk("Instruction DUMP:");
5237 instruction_dump ((unsigned long *) regs->pc);
5238- if(regs->psr & PSR_PS)
5239+ if(regs->psr & PSR_PS) {
5240+ gr_handle_kernel_exploit();
5241 do_exit(SIGKILL);
5242+ }
5243 do_exit(SIGSEGV);
5244 }
5245
5246diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
5247index 10f7bb9..cdb6793 100644
5248--- a/arch/sparc/kernel/traps_64.c
5249+++ b/arch/sparc/kernel/traps_64.c
5250@@ -73,7 +73,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
5251 i + 1,
5252 p->trapstack[i].tstate, p->trapstack[i].tpc,
5253 p->trapstack[i].tnpc, p->trapstack[i].tt);
5254- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
5255+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
5256 }
5257 }
5258
5259@@ -93,6 +93,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
5260
5261 lvl -= 0x100;
5262 if (regs->tstate & TSTATE_PRIV) {
5263+
5264+#ifdef CONFIG_PAX_REFCOUNT
5265+ if (lvl == 6)
5266+ pax_report_refcount_overflow(regs);
5267+#endif
5268+
5269 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
5270 die_if_kernel(buffer, regs);
5271 }
5272@@ -111,11 +117,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
5273 void bad_trap_tl1(struct pt_regs *regs, long lvl)
5274 {
5275 char buffer[32];
5276-
5277+
5278 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
5279 0, lvl, SIGTRAP) == NOTIFY_STOP)
5280 return;
5281
5282+#ifdef CONFIG_PAX_REFCOUNT
5283+ if (lvl == 6)
5284+ pax_report_refcount_overflow(regs);
5285+#endif
5286+
5287 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
5288
5289 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
5290@@ -1139,7 +1150,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
5291 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
5292 printk("%s" "ERROR(%d): ",
5293 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
5294- printk("TPC<%pS>\n", (void *) regs->tpc);
5295+ printk("TPC<%pA>\n", (void *) regs->tpc);
5296 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
5297 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
5298 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
5299@@ -1746,7 +1757,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5300 smp_processor_id(),
5301 (type & 0x1) ? 'I' : 'D',
5302 regs->tpc);
5303- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
5304+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
5305 panic("Irrecoverable Cheetah+ parity error.");
5306 }
5307
5308@@ -1754,7 +1765,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
5309 smp_processor_id(),
5310 (type & 0x1) ? 'I' : 'D',
5311 regs->tpc);
5312- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
5313+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
5314 }
5315
5316 struct sun4v_error_entry {
5317@@ -1961,9 +1972,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
5318
5319 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
5320 regs->tpc, tl);
5321- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
5322+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
5323 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5324- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
5325+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
5326 (void *) regs->u_regs[UREG_I7]);
5327 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
5328 "pte[%lx] error[%lx]\n",
5329@@ -1985,9 +1996,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
5330
5331 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
5332 regs->tpc, tl);
5333- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
5334+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
5335 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
5336- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
5337+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
5338 (void *) regs->u_regs[UREG_I7]);
5339 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
5340 "pte[%lx] error[%lx]\n",
5341@@ -2191,7 +2202,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5342 fp = (unsigned long)sf->fp + STACK_BIAS;
5343 }
5344
5345- printk(" [%016lx] %pS\n", pc, (void *) pc);
5346+ printk(" [%016lx] %pA\n", pc, (void *) pc);
5347 } while (++count < 16);
5348 }
5349
5350@@ -2233,6 +2244,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
5351 return (struct reg_window *) (fp + STACK_BIAS);
5352 }
5353
5354+extern void gr_handle_kernel_exploit(void);
5355+
5356 void die_if_kernel(char *str, struct pt_regs *regs)
5357 {
5358 static int die_counter;
5359@@ -2260,7 +2273,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5360 while (rw &&
5361 count++ < 30&&
5362 is_kernel_stack(current, rw)) {
5363- printk("Caller[%016lx]: %pS\n", rw->ins[7],
5364+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
5365 (void *) rw->ins[7]);
5366
5367 rw = kernel_stack_up(rw);
5368@@ -2273,8 +2286,11 @@ void die_if_kernel(char *str, struct pt_regs *regs)
5369 }
5370 user_instruction_dump ((unsigned int __user *) regs->tpc);
5371 }
5372- if (regs->tstate & TSTATE_PRIV)
5373+ if (regs->tstate & TSTATE_PRIV) {
5374+ gr_handle_kernel_exploit();
5375 do_exit(SIGKILL);
5376+ }
5377+
5378 do_exit(SIGSEGV);
5379 }
5380 EXPORT_SYMBOL(die_if_kernel);
5381diff --git a/arch/sparc/kernel/una_asm_64.S b/arch/sparc/kernel/una_asm_64.S
5382index be183fe..1c8d332 100644
5383--- a/arch/sparc/kernel/una_asm_64.S
5384+++ b/arch/sparc/kernel/una_asm_64.S
5385@@ -127,7 +127,7 @@ do_int_load:
5386 wr %o5, 0x0, %asi
5387 retl
5388 mov 0, %o0
5389- .size __do_int_load, .-__do_int_load
5390+ .size do_int_load, .-do_int_load
5391
5392 .section __ex_table,"a"
5393 .word 4b, __retl_efault
5394diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
5395index 3792099..2af17d8 100644
5396--- a/arch/sparc/kernel/unaligned_64.c
5397+++ b/arch/sparc/kernel/unaligned_64.c
5398@@ -288,7 +288,7 @@ static void log_unaligned(struct pt_regs *regs)
5399 if (count < 5) {
5400 last_time = jiffies;
5401 count++;
5402- printk("Kernel unaligned access at TPC[%lx] %pS\n",
5403+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
5404 regs->tpc, (void *) regs->tpc);
5405 }
5406 }
5407diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
5408index e75faf0..24f12f9 100644
5409--- a/arch/sparc/lib/Makefile
5410+++ b/arch/sparc/lib/Makefile
5411@@ -2,7 +2,7 @@
5412 #
5413
5414 asflags-y := -ansi -DST_DIV0=0x02
5415-ccflags-y := -Werror
5416+#ccflags-y := -Werror
5417
5418 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
5419 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
5420diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
5421index 0268210..f0291ca 100644
5422--- a/arch/sparc/lib/atomic_64.S
5423+++ b/arch/sparc/lib/atomic_64.S
5424@@ -18,7 +18,12 @@
5425 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5426 BACKOFF_SETUP(%o2)
5427 1: lduw [%o1], %g1
5428- add %g1, %o0, %g7
5429+ addcc %g1, %o0, %g7
5430+
5431+#ifdef CONFIG_PAX_REFCOUNT
5432+ tvs %icc, 6
5433+#endif
5434+
5435 cas [%o1], %g1, %g7
5436 cmp %g1, %g7
5437 bne,pn %icc, 2f
5438@@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
5439 2: BACKOFF_SPIN(%o2, %o3, 1b)
5440 .size atomic_add, .-atomic_add
5441
5442+ .globl atomic_add_unchecked
5443+ .type atomic_add_unchecked,#function
5444+atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5445+ BACKOFF_SETUP(%o2)
5446+1: lduw [%o1], %g1
5447+ add %g1, %o0, %g7
5448+ cas [%o1], %g1, %g7
5449+ cmp %g1, %g7
5450+ bne,pn %icc, 2f
5451+ nop
5452+ retl
5453+ nop
5454+2: BACKOFF_SPIN(%o2, %o3, 1b)
5455+ .size atomic_add_unchecked, .-atomic_add_unchecked
5456+
5457 .globl atomic_sub
5458 .type atomic_sub,#function
5459 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5460 BACKOFF_SETUP(%o2)
5461 1: lduw [%o1], %g1
5462- sub %g1, %o0, %g7
5463+ subcc %g1, %o0, %g7
5464+
5465+#ifdef CONFIG_PAX_REFCOUNT
5466+ tvs %icc, 6
5467+#endif
5468+
5469 cas [%o1], %g1, %g7
5470 cmp %g1, %g7
5471 bne,pn %icc, 2f
5472@@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5473 2: BACKOFF_SPIN(%o2, %o3, 1b)
5474 .size atomic_sub, .-atomic_sub
5475
5476+ .globl atomic_sub_unchecked
5477+ .type atomic_sub_unchecked,#function
5478+atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5479+ BACKOFF_SETUP(%o2)
5480+1: lduw [%o1], %g1
5481+ sub %g1, %o0, %g7
5482+ cas [%o1], %g1, %g7
5483+ cmp %g1, %g7
5484+ bne,pn %icc, 2f
5485+ nop
5486+ retl
5487+ nop
5488+2: BACKOFF_SPIN(%o2, %o3, 1b)
5489+ .size atomic_sub_unchecked, .-atomic_sub_unchecked
5490+
5491 .globl atomic_add_ret
5492 .type atomic_add_ret,#function
5493 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5494 BACKOFF_SETUP(%o2)
5495 1: lduw [%o1], %g1
5496- add %g1, %o0, %g7
5497+ addcc %g1, %o0, %g7
5498+
5499+#ifdef CONFIG_PAX_REFCOUNT
5500+ tvs %icc, 6
5501+#endif
5502+
5503 cas [%o1], %g1, %g7
5504 cmp %g1, %g7
5505 bne,pn %icc, 2f
5506@@ -59,12 +104,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5507 2: BACKOFF_SPIN(%o2, %o3, 1b)
5508 .size atomic_add_ret, .-atomic_add_ret
5509
5510+ .globl atomic_add_ret_unchecked
5511+ .type atomic_add_ret_unchecked,#function
5512+atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5513+ BACKOFF_SETUP(%o2)
5514+1: lduw [%o1], %g1
5515+ addcc %g1, %o0, %g7
5516+ cas [%o1], %g1, %g7
5517+ cmp %g1, %g7
5518+ bne,pn %icc, 2f
5519+ add %g7, %o0, %g7
5520+ sra %g7, 0, %o0
5521+ retl
5522+ nop
5523+2: BACKOFF_SPIN(%o2, %o3, 1b)
5524+ .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
5525+
5526 .globl atomic_sub_ret
5527 .type atomic_sub_ret,#function
5528 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5529 BACKOFF_SETUP(%o2)
5530 1: lduw [%o1], %g1
5531- sub %g1, %o0, %g7
5532+ subcc %g1, %o0, %g7
5533+
5534+#ifdef CONFIG_PAX_REFCOUNT
5535+ tvs %icc, 6
5536+#endif
5537+
5538 cas [%o1], %g1, %g7
5539 cmp %g1, %g7
5540 bne,pn %icc, 2f
5541@@ -80,7 +146,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5542 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5543 BACKOFF_SETUP(%o2)
5544 1: ldx [%o1], %g1
5545- add %g1, %o0, %g7
5546+ addcc %g1, %o0, %g7
5547+
5548+#ifdef CONFIG_PAX_REFCOUNT
5549+ tvs %xcc, 6
5550+#endif
5551+
5552 casx [%o1], %g1, %g7
5553 cmp %g1, %g7
5554 bne,pn %xcc, 2f
5555@@ -90,12 +161,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
5556 2: BACKOFF_SPIN(%o2, %o3, 1b)
5557 .size atomic64_add, .-atomic64_add
5558
5559+ .globl atomic64_add_unchecked
5560+ .type atomic64_add_unchecked,#function
5561+atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5562+ BACKOFF_SETUP(%o2)
5563+1: ldx [%o1], %g1
5564+ addcc %g1, %o0, %g7
5565+ casx [%o1], %g1, %g7
5566+ cmp %g1, %g7
5567+ bne,pn %xcc, 2f
5568+ nop
5569+ retl
5570+ nop
5571+2: BACKOFF_SPIN(%o2, %o3, 1b)
5572+ .size atomic64_add_unchecked, .-atomic64_add_unchecked
5573+
5574 .globl atomic64_sub
5575 .type atomic64_sub,#function
5576 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5577 BACKOFF_SETUP(%o2)
5578 1: ldx [%o1], %g1
5579- sub %g1, %o0, %g7
5580+ subcc %g1, %o0, %g7
5581+
5582+#ifdef CONFIG_PAX_REFCOUNT
5583+ tvs %xcc, 6
5584+#endif
5585+
5586 casx [%o1], %g1, %g7
5587 cmp %g1, %g7
5588 bne,pn %xcc, 2f
5589@@ -105,12 +196,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
5590 2: BACKOFF_SPIN(%o2, %o3, 1b)
5591 .size atomic64_sub, .-atomic64_sub
5592
5593+ .globl atomic64_sub_unchecked
5594+ .type atomic64_sub_unchecked,#function
5595+atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
5596+ BACKOFF_SETUP(%o2)
5597+1: ldx [%o1], %g1
5598+ subcc %g1, %o0, %g7
5599+ casx [%o1], %g1, %g7
5600+ cmp %g1, %g7
5601+ bne,pn %xcc, 2f
5602+ nop
5603+ retl
5604+ nop
5605+2: BACKOFF_SPIN(%o2, %o3, 1b)
5606+ .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
5607+
5608 .globl atomic64_add_ret
5609 .type atomic64_add_ret,#function
5610 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5611 BACKOFF_SETUP(%o2)
5612 1: ldx [%o1], %g1
5613- add %g1, %o0, %g7
5614+ addcc %g1, %o0, %g7
5615+
5616+#ifdef CONFIG_PAX_REFCOUNT
5617+ tvs %xcc, 6
5618+#endif
5619+
5620 casx [%o1], %g1, %g7
5621 cmp %g1, %g7
5622 bne,pn %xcc, 2f
5623@@ -121,12 +232,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
5624 2: BACKOFF_SPIN(%o2, %o3, 1b)
5625 .size atomic64_add_ret, .-atomic64_add_ret
5626
5627+ .globl atomic64_add_ret_unchecked
5628+ .type atomic64_add_ret_unchecked,#function
5629+atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
5630+ BACKOFF_SETUP(%o2)
5631+1: ldx [%o1], %g1
5632+ addcc %g1, %o0, %g7
5633+ casx [%o1], %g1, %g7
5634+ cmp %g1, %g7
5635+ bne,pn %xcc, 2f
5636+ add %g7, %o0, %g7
5637+ mov %g7, %o0
5638+ retl
5639+ nop
5640+2: BACKOFF_SPIN(%o2, %o3, 1b)
5641+ .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
5642+
5643 .globl atomic64_sub_ret
5644 .type atomic64_sub_ret,#function
5645 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
5646 BACKOFF_SETUP(%o2)
5647 1: ldx [%o1], %g1
5648- sub %g1, %o0, %g7
5649+ subcc %g1, %o0, %g7
5650+
5651+#ifdef CONFIG_PAX_REFCOUNT
5652+ tvs %xcc, 6
5653+#endif
5654+
5655 casx [%o1], %g1, %g7
5656 cmp %g1, %g7
5657 bne,pn %xcc, 2f
5658diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
5659index 704b126..2e79d76 100644
5660--- a/arch/sparc/lib/ksyms.c
5661+++ b/arch/sparc/lib/ksyms.c
5662@@ -144,12 +144,18 @@ EXPORT_SYMBOL(__downgrade_write);
5663
5664 /* Atomic counter implementation. */
5665 EXPORT_SYMBOL(atomic_add);
5666+EXPORT_SYMBOL(atomic_add_unchecked);
5667 EXPORT_SYMBOL(atomic_add_ret);
5668+EXPORT_SYMBOL(atomic_add_ret_unchecked);
5669 EXPORT_SYMBOL(atomic_sub);
5670+EXPORT_SYMBOL(atomic_sub_unchecked);
5671 EXPORT_SYMBOL(atomic_sub_ret);
5672 EXPORT_SYMBOL(atomic64_add);
5673+EXPORT_SYMBOL(atomic64_add_unchecked);
5674 EXPORT_SYMBOL(atomic64_add_ret);
5675+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
5676 EXPORT_SYMBOL(atomic64_sub);
5677+EXPORT_SYMBOL(atomic64_sub_unchecked);
5678 EXPORT_SYMBOL(atomic64_sub_ret);
5679
5680 /* Atomic bit operations. */
5681diff --git a/arch/sparc/lib/rwsem_64.S b/arch/sparc/lib/rwsem_64.S
5682index 91a7d29..ce75c29 100644
5683--- a/arch/sparc/lib/rwsem_64.S
5684+++ b/arch/sparc/lib/rwsem_64.S
5685@@ -11,7 +11,12 @@
5686 .globl __down_read
5687 __down_read:
5688 1: lduw [%o0], %g1
5689- add %g1, 1, %g7
5690+ addcc %g1, 1, %g7
5691+
5692+#ifdef CONFIG_PAX_REFCOUNT
5693+ tvs %icc, 6
5694+#endif
5695+
5696 cas [%o0], %g1, %g7
5697 cmp %g1, %g7
5698 bne,pn %icc, 1b
5699@@ -33,7 +38,12 @@ __down_read:
5700 .globl __down_read_trylock
5701 __down_read_trylock:
5702 1: lduw [%o0], %g1
5703- add %g1, 1, %g7
5704+ addcc %g1, 1, %g7
5705+
5706+#ifdef CONFIG_PAX_REFCOUNT
5707+ tvs %icc, 6
5708+#endif
5709+
5710 cmp %g7, 0
5711 bl,pn %icc, 2f
5712 mov 0, %o1
5713@@ -51,7 +61,12 @@ __down_write:
5714 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
5715 1:
5716 lduw [%o0], %g3
5717- add %g3, %g1, %g7
5718+ addcc %g3, %g1, %g7
5719+
5720+#ifdef CONFIG_PAX_REFCOUNT
5721+ tvs %icc, 6
5722+#endif
5723+
5724 cas [%o0], %g3, %g7
5725 cmp %g3, %g7
5726 bne,pn %icc, 1b
5727@@ -77,7 +92,12 @@ __down_write_trylock:
5728 cmp %g3, 0
5729 bne,pn %icc, 2f
5730 mov 0, %o1
5731- add %g3, %g1, %g7
5732+ addcc %g3, %g1, %g7
5733+
5734+#ifdef CONFIG_PAX_REFCOUNT
5735+ tvs %icc, 6
5736+#endif
5737+
5738 cas [%o0], %g3, %g7
5739 cmp %g3, %g7
5740 bne,pn %icc, 1b
5741@@ -90,7 +110,12 @@ __down_write_trylock:
5742 __up_read:
5743 1:
5744 lduw [%o0], %g1
5745- sub %g1, 1, %g7
5746+ subcc %g1, 1, %g7
5747+
5748+#ifdef CONFIG_PAX_REFCOUNT
5749+ tvs %icc, 6
5750+#endif
5751+
5752 cas [%o0], %g1, %g7
5753 cmp %g1, %g7
5754 bne,pn %icc, 1b
5755@@ -118,7 +143,12 @@ __up_write:
5756 or %g1, %lo(RWSEM_ACTIVE_WRITE_BIAS), %g1
5757 1:
5758 lduw [%o0], %g3
5759- sub %g3, %g1, %g7
5760+ subcc %g3, %g1, %g7
5761+
5762+#ifdef CONFIG_PAX_REFCOUNT
5763+ tvs %icc, 6
5764+#endif
5765+
5766 cas [%o0], %g3, %g7
5767 cmp %g3, %g7
5768 bne,pn %icc, 1b
5769@@ -143,7 +173,12 @@ __downgrade_write:
5770 or %g1, %lo(RWSEM_WAITING_BIAS), %g1
5771 1:
5772 lduw [%o0], %g3
5773- sub %g3, %g1, %g7
5774+ subcc %g3, %g1, %g7
5775+
5776+#ifdef CONFIG_PAX_REFCOUNT
5777+ tvs %icc, 6
5778+#endif
5779+
5780 cas [%o0], %g3, %g7
5781 cmp %g3, %g7
5782 bne,pn %icc, 1b
5783diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
5784index 79836a7..62f47a2 100644
5785--- a/arch/sparc/mm/Makefile
5786+++ b/arch/sparc/mm/Makefile
5787@@ -2,7 +2,7 @@
5788 #
5789
5790 asflags-y := -ansi
5791-ccflags-y := -Werror
5792+#ccflags-y := -Werror
5793
5794 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o
5795 obj-y += fault_$(BITS).o
5796diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
5797index b99f81c..3453e93 100644
5798--- a/arch/sparc/mm/fault_32.c
5799+++ b/arch/sparc/mm/fault_32.c
5800@@ -21,6 +21,9 @@
5801 #include <linux/interrupt.h>
5802 #include <linux/module.h>
5803 #include <linux/kdebug.h>
5804+#include <linux/slab.h>
5805+#include <linux/pagemap.h>
5806+#include <linux/compiler.h>
5807
5808 #include <asm/system.h>
5809 #include <asm/page.h>
5810@@ -167,6 +170,267 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
5811 return safe_compute_effective_address(regs, insn);
5812 }
5813
5814+#ifdef CONFIG_PAX_PAGEEXEC
5815+#ifdef CONFIG_PAX_DLRESOLVE
5816+static void pax_emuplt_close(struct vm_area_struct *vma)
5817+{
5818+ vma->vm_mm->call_dl_resolve = 0UL;
5819+}
5820+
5821+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5822+{
5823+ unsigned int *kaddr;
5824+
5825+ vmf->page = alloc_page(GFP_HIGHUSER);
5826+ if (!vmf->page)
5827+ return VM_FAULT_OOM;
5828+
5829+ kaddr = kmap(vmf->page);
5830+ memset(kaddr, 0, PAGE_SIZE);
5831+ kaddr[0] = 0x9DE3BFA8U; /* save */
5832+ flush_dcache_page(vmf->page);
5833+ kunmap(vmf->page);
5834+ return VM_FAULT_MAJOR;
5835+}
5836+
5837+static const struct vm_operations_struct pax_vm_ops = {
5838+ .close = pax_emuplt_close,
5839+ .fault = pax_emuplt_fault
5840+};
5841+
5842+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5843+{
5844+ int ret;
5845+
5846+ vma->vm_mm = current->mm;
5847+ vma->vm_start = addr;
5848+ vma->vm_end = addr + PAGE_SIZE;
5849+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5850+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5851+ vma->vm_ops = &pax_vm_ops;
5852+
5853+ ret = insert_vm_struct(current->mm, vma);
5854+ if (ret)
5855+ return ret;
5856+
5857+ ++current->mm->total_vm;
5858+ return 0;
5859+}
5860+#endif
5861+
5862+/*
5863+ * PaX: decide what to do with offenders (regs->pc = fault address)
5864+ *
5865+ * returns 1 when task should be killed
5866+ * 2 when patched PLT trampoline was detected
5867+ * 3 when unpatched PLT trampoline was detected
5868+ */
5869+static int pax_handle_fetch_fault(struct pt_regs *regs)
5870+{
5871+
5872+#ifdef CONFIG_PAX_EMUPLT
5873+ int err;
5874+
5875+ do { /* PaX: patched PLT emulation #1 */
5876+ unsigned int sethi1, sethi2, jmpl;
5877+
5878+ err = get_user(sethi1, (unsigned int *)regs->pc);
5879+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
5880+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
5881+
5882+ if (err)
5883+ break;
5884+
5885+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5886+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
5887+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
5888+ {
5889+ unsigned int addr;
5890+
5891+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5892+ addr = regs->u_regs[UREG_G1];
5893+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5894+ regs->pc = addr;
5895+ regs->npc = addr+4;
5896+ return 2;
5897+ }
5898+ } while (0);
5899+
5900+ { /* PaX: patched PLT emulation #2 */
5901+ unsigned int ba;
5902+
5903+ err = get_user(ba, (unsigned int *)regs->pc);
5904+
5905+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5906+ unsigned int addr;
5907+
5908+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5909+ regs->pc = addr;
5910+ regs->npc = addr+4;
5911+ return 2;
5912+ }
5913+ }
5914+
5915+ do { /* PaX: patched PLT emulation #3 */
5916+ unsigned int sethi, jmpl, nop;
5917+
5918+ err = get_user(sethi, (unsigned int *)regs->pc);
5919+ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
5920+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
5921+
5922+ if (err)
5923+ break;
5924+
5925+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5926+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5927+ nop == 0x01000000U)
5928+ {
5929+ unsigned int addr;
5930+
5931+ addr = (sethi & 0x003FFFFFU) << 10;
5932+ regs->u_regs[UREG_G1] = addr;
5933+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
5934+ regs->pc = addr;
5935+ regs->npc = addr+4;
5936+ return 2;
5937+ }
5938+ } while (0);
5939+
5940+ do { /* PaX: unpatched PLT emulation step 1 */
5941+ unsigned int sethi, ba, nop;
5942+
5943+ err = get_user(sethi, (unsigned int *)regs->pc);
5944+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
5945+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
5946+
5947+ if (err)
5948+ break;
5949+
5950+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
5951+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5952+ nop == 0x01000000U)
5953+ {
5954+ unsigned int addr, save, call;
5955+
5956+ if ((ba & 0xFFC00000U) == 0x30800000U)
5957+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
5958+ else
5959+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
5960+
5961+ err = get_user(save, (unsigned int *)addr);
5962+ err |= get_user(call, (unsigned int *)(addr+4));
5963+ err |= get_user(nop, (unsigned int *)(addr+8));
5964+ if (err)
5965+ break;
5966+
5967+#ifdef CONFIG_PAX_DLRESOLVE
5968+ if (save == 0x9DE3BFA8U &&
5969+ (call & 0xC0000000U) == 0x40000000U &&
5970+ nop == 0x01000000U)
5971+ {
5972+ struct vm_area_struct *vma;
5973+ unsigned long call_dl_resolve;
5974+
5975+ down_read(&current->mm->mmap_sem);
5976+ call_dl_resolve = current->mm->call_dl_resolve;
5977+ up_read(&current->mm->mmap_sem);
5978+ if (likely(call_dl_resolve))
5979+ goto emulate;
5980+
5981+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5982+
5983+ down_write(&current->mm->mmap_sem);
5984+ if (current->mm->call_dl_resolve) {
5985+ call_dl_resolve = current->mm->call_dl_resolve;
5986+ up_write(&current->mm->mmap_sem);
5987+ if (vma)
5988+ kmem_cache_free(vm_area_cachep, vma);
5989+ goto emulate;
5990+ }
5991+
5992+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5993+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5994+ up_write(&current->mm->mmap_sem);
5995+ if (vma)
5996+ kmem_cache_free(vm_area_cachep, vma);
5997+ return 1;
5998+ }
5999+
6000+ if (pax_insert_vma(vma, call_dl_resolve)) {
6001+ up_write(&current->mm->mmap_sem);
6002+ kmem_cache_free(vm_area_cachep, vma);
6003+ return 1;
6004+ }
6005+
6006+ current->mm->call_dl_resolve = call_dl_resolve;
6007+ up_write(&current->mm->mmap_sem);
6008+
6009+emulate:
6010+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6011+ regs->pc = call_dl_resolve;
6012+ regs->npc = addr+4;
6013+ return 3;
6014+ }
6015+#endif
6016+
6017+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6018+ if ((save & 0xFFC00000U) == 0x05000000U &&
6019+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6020+ nop == 0x01000000U)
6021+ {
6022+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6023+ regs->u_regs[UREG_G2] = addr + 4;
6024+ addr = (save & 0x003FFFFFU) << 10;
6025+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6026+ regs->pc = addr;
6027+ regs->npc = addr+4;
6028+ return 3;
6029+ }
6030+ }
6031+ } while (0);
6032+
6033+ do { /* PaX: unpatched PLT emulation step 2 */
6034+ unsigned int save, call, nop;
6035+
6036+ err = get_user(save, (unsigned int *)(regs->pc-4));
6037+ err |= get_user(call, (unsigned int *)regs->pc);
6038+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6039+ if (err)
6040+ break;
6041+
6042+ if (save == 0x9DE3BFA8U &&
6043+ (call & 0xC0000000U) == 0x40000000U &&
6044+ nop == 0x01000000U)
6045+ {
6046+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6047+
6048+ regs->u_regs[UREG_RETPC] = regs->pc;
6049+ regs->pc = dl_resolve;
6050+ regs->npc = dl_resolve+4;
6051+ return 3;
6052+ }
6053+ } while (0);
6054+#endif
6055+
6056+ return 1;
6057+}
6058+
6059+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6060+{
6061+ unsigned long i;
6062+
6063+ printk(KERN_ERR "PAX: bytes at PC: ");
6064+ for (i = 0; i < 8; i++) {
6065+ unsigned int c;
6066+ if (get_user(c, (unsigned int *)pc+i))
6067+ printk(KERN_CONT "???????? ");
6068+ else
6069+ printk(KERN_CONT "%08x ", c);
6070+ }
6071+ printk("\n");
6072+}
6073+#endif
6074+
6075 asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
6076 unsigned long address)
6077 {
6078@@ -231,6 +495,24 @@ good_area:
6079 if(!(vma->vm_flags & VM_WRITE))
6080 goto bad_area;
6081 } else {
6082+
6083+#ifdef CONFIG_PAX_PAGEEXEC
6084+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6085+ up_read(&mm->mmap_sem);
6086+ switch (pax_handle_fetch_fault(regs)) {
6087+
6088+#ifdef CONFIG_PAX_EMUPLT
6089+ case 2:
6090+ case 3:
6091+ return;
6092+#endif
6093+
6094+ }
6095+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6096+ do_group_exit(SIGKILL);
6097+ }
6098+#endif
6099+
6100 /* Allow reads even for write-only mappings */
6101 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6102 goto bad_area;
6103diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6104index 43b0da9..a0b78f9 100644
6105--- a/arch/sparc/mm/fault_64.c
6106+++ b/arch/sparc/mm/fault_64.c
6107@@ -20,6 +20,9 @@
6108 #include <linux/kprobes.h>
6109 #include <linux/kdebug.h>
6110 #include <linux/percpu.h>
6111+#include <linux/slab.h>
6112+#include <linux/pagemap.h>
6113+#include <linux/compiler.h>
6114
6115 #include <asm/page.h>
6116 #include <asm/pgtable.h>
6117@@ -78,7 +81,7 @@ static void bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6118 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6119 regs->tpc);
6120 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6121- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6122+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6123 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6124 dump_stack();
6125 unhandled_fault(regs->tpc, current, regs);
6126@@ -249,6 +252,456 @@ static void noinline bogus_32bit_fault_address(struct pt_regs *regs,
6127 show_regs(regs);
6128 }
6129
6130+#ifdef CONFIG_PAX_PAGEEXEC
6131+#ifdef CONFIG_PAX_DLRESOLVE
6132+static void pax_emuplt_close(struct vm_area_struct *vma)
6133+{
6134+ vma->vm_mm->call_dl_resolve = 0UL;
6135+}
6136+
6137+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6138+{
6139+ unsigned int *kaddr;
6140+
6141+ vmf->page = alloc_page(GFP_HIGHUSER);
6142+ if (!vmf->page)
6143+ return VM_FAULT_OOM;
6144+
6145+ kaddr = kmap(vmf->page);
6146+ memset(kaddr, 0, PAGE_SIZE);
6147+ kaddr[0] = 0x9DE3BFA8U; /* save */
6148+ flush_dcache_page(vmf->page);
6149+ kunmap(vmf->page);
6150+ return VM_FAULT_MAJOR;
6151+}
6152+
6153+static const struct vm_operations_struct pax_vm_ops = {
6154+ .close = pax_emuplt_close,
6155+ .fault = pax_emuplt_fault
6156+};
6157+
6158+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6159+{
6160+ int ret;
6161+
6162+ vma->vm_mm = current->mm;
6163+ vma->vm_start = addr;
6164+ vma->vm_end = addr + PAGE_SIZE;
6165+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6166+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6167+ vma->vm_ops = &pax_vm_ops;
6168+
6169+ ret = insert_vm_struct(current->mm, vma);
6170+ if (ret)
6171+ return ret;
6172+
6173+ ++current->mm->total_vm;
6174+ return 0;
6175+}
6176+#endif
6177+
6178+/*
6179+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6180+ *
6181+ * returns 1 when task should be killed
6182+ * 2 when patched PLT trampoline was detected
6183+ * 3 when unpatched PLT trampoline was detected
6184+ */
6185+static int pax_handle_fetch_fault(struct pt_regs *regs)
6186+{
6187+
6188+#ifdef CONFIG_PAX_EMUPLT
6189+ int err;
6190+
6191+ do { /* PaX: patched PLT emulation #1 */
6192+ unsigned int sethi1, sethi2, jmpl;
6193+
6194+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6195+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6196+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6197+
6198+ if (err)
6199+ break;
6200+
6201+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6202+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6203+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6204+ {
6205+ unsigned long addr;
6206+
6207+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6208+ addr = regs->u_regs[UREG_G1];
6209+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6210+
6211+ if (test_thread_flag(TIF_32BIT))
6212+ addr &= 0xFFFFFFFFUL;
6213+
6214+ regs->tpc = addr;
6215+ regs->tnpc = addr+4;
6216+ return 2;
6217+ }
6218+ } while (0);
6219+
6220+ { /* PaX: patched PLT emulation #2 */
6221+ unsigned int ba;
6222+
6223+ err = get_user(ba, (unsigned int *)regs->tpc);
6224+
6225+ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6226+ unsigned long addr;
6227+
6228+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6229+
6230+ if (test_thread_flag(TIF_32BIT))
6231+ addr &= 0xFFFFFFFFUL;
6232+
6233+ regs->tpc = addr;
6234+ regs->tnpc = addr+4;
6235+ return 2;
6236+ }
6237+ }
6238+
6239+ do { /* PaX: patched PLT emulation #3 */
6240+ unsigned int sethi, jmpl, nop;
6241+
6242+ err = get_user(sethi, (unsigned int *)regs->tpc);
6243+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6244+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6245+
6246+ if (err)
6247+ break;
6248+
6249+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6250+ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6251+ nop == 0x01000000U)
6252+ {
6253+ unsigned long addr;
6254+
6255+ addr = (sethi & 0x003FFFFFU) << 10;
6256+ regs->u_regs[UREG_G1] = addr;
6257+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6258+
6259+ if (test_thread_flag(TIF_32BIT))
6260+ addr &= 0xFFFFFFFFUL;
6261+
6262+ regs->tpc = addr;
6263+ regs->tnpc = addr+4;
6264+ return 2;
6265+ }
6266+ } while (0);
6267+
6268+ do { /* PaX: patched PLT emulation #4 */
6269+ unsigned int sethi, mov1, call, mov2;
6270+
6271+ err = get_user(sethi, (unsigned int *)regs->tpc);
6272+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6273+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6274+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6275+
6276+ if (err)
6277+ break;
6278+
6279+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6280+ mov1 == 0x8210000FU &&
6281+ (call & 0xC0000000U) == 0x40000000U &&
6282+ mov2 == 0x9E100001U)
6283+ {
6284+ unsigned long addr;
6285+
6286+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6287+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6288+
6289+ if (test_thread_flag(TIF_32BIT))
6290+ addr &= 0xFFFFFFFFUL;
6291+
6292+ regs->tpc = addr;
6293+ regs->tnpc = addr+4;
6294+ return 2;
6295+ }
6296+ } while (0);
6297+
6298+ do { /* PaX: patched PLT emulation #5 */
6299+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6300+
6301+ err = get_user(sethi, (unsigned int *)regs->tpc);
6302+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6303+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6304+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6305+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6306+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6307+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6308+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6309+
6310+ if (err)
6311+ break;
6312+
6313+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6314+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
6315+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6316+ (or1 & 0xFFFFE000U) == 0x82106000U &&
6317+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
6318+ sllx == 0x83287020U &&
6319+ jmpl == 0x81C04005U &&
6320+ nop == 0x01000000U)
6321+ {
6322+ unsigned long addr;
6323+
6324+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6325+ regs->u_regs[UREG_G1] <<= 32;
6326+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6327+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6328+ regs->tpc = addr;
6329+ regs->tnpc = addr+4;
6330+ return 2;
6331+ }
6332+ } while (0);
6333+
6334+ do { /* PaX: patched PLT emulation #6 */
6335+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
6336+
6337+ err = get_user(sethi, (unsigned int *)regs->tpc);
6338+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6339+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6340+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
6341+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
6342+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
6343+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
6344+
6345+ if (err)
6346+ break;
6347+
6348+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6349+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
6350+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6351+ sllx == 0x83287020U &&
6352+ (or & 0xFFFFE000U) == 0x8A116000U &&
6353+ jmpl == 0x81C04005U &&
6354+ nop == 0x01000000U)
6355+ {
6356+ unsigned long addr;
6357+
6358+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
6359+ regs->u_regs[UREG_G1] <<= 32;
6360+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
6361+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
6362+ regs->tpc = addr;
6363+ regs->tnpc = addr+4;
6364+ return 2;
6365+ }
6366+ } while (0);
6367+
6368+ do { /* PaX: unpatched PLT emulation step 1 */
6369+ unsigned int sethi, ba, nop;
6370+
6371+ err = get_user(sethi, (unsigned int *)regs->tpc);
6372+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6373+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6374+
6375+ if (err)
6376+ break;
6377+
6378+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6379+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6380+ nop == 0x01000000U)
6381+ {
6382+ unsigned long addr;
6383+ unsigned int save, call;
6384+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
6385+
6386+ if ((ba & 0xFFC00000U) == 0x30800000U)
6387+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6388+ else
6389+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6390+
6391+ if (test_thread_flag(TIF_32BIT))
6392+ addr &= 0xFFFFFFFFUL;
6393+
6394+ err = get_user(save, (unsigned int *)addr);
6395+ err |= get_user(call, (unsigned int *)(addr+4));
6396+ err |= get_user(nop, (unsigned int *)(addr+8));
6397+ if (err)
6398+ break;
6399+
6400+#ifdef CONFIG_PAX_DLRESOLVE
6401+ if (save == 0x9DE3BFA8U &&
6402+ (call & 0xC0000000U) == 0x40000000U &&
6403+ nop == 0x01000000U)
6404+ {
6405+ struct vm_area_struct *vma;
6406+ unsigned long call_dl_resolve;
6407+
6408+ down_read(&current->mm->mmap_sem);
6409+ call_dl_resolve = current->mm->call_dl_resolve;
6410+ up_read(&current->mm->mmap_sem);
6411+ if (likely(call_dl_resolve))
6412+ goto emulate;
6413+
6414+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6415+
6416+ down_write(&current->mm->mmap_sem);
6417+ if (current->mm->call_dl_resolve) {
6418+ call_dl_resolve = current->mm->call_dl_resolve;
6419+ up_write(&current->mm->mmap_sem);
6420+ if (vma)
6421+ kmem_cache_free(vm_area_cachep, vma);
6422+ goto emulate;
6423+ }
6424+
6425+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6426+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6427+ up_write(&current->mm->mmap_sem);
6428+ if (vma)
6429+ kmem_cache_free(vm_area_cachep, vma);
6430+ return 1;
6431+ }
6432+
6433+ if (pax_insert_vma(vma, call_dl_resolve)) {
6434+ up_write(&current->mm->mmap_sem);
6435+ kmem_cache_free(vm_area_cachep, vma);
6436+ return 1;
6437+ }
6438+
6439+ current->mm->call_dl_resolve = call_dl_resolve;
6440+ up_write(&current->mm->mmap_sem);
6441+
6442+emulate:
6443+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6444+ regs->tpc = call_dl_resolve;
6445+ regs->tnpc = addr+4;
6446+ return 3;
6447+ }
6448+#endif
6449+
6450+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6451+ if ((save & 0xFFC00000U) == 0x05000000U &&
6452+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6453+ nop == 0x01000000U)
6454+ {
6455+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6456+ regs->u_regs[UREG_G2] = addr + 4;
6457+ addr = (save & 0x003FFFFFU) << 10;
6458+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6459+
6460+ if (test_thread_flag(TIF_32BIT))
6461+ addr &= 0xFFFFFFFFUL;
6462+
6463+ regs->tpc = addr;
6464+ regs->tnpc = addr+4;
6465+ return 3;
6466+ }
6467+
6468+ /* PaX: 64-bit PLT stub */
6469+ err = get_user(sethi1, (unsigned int *)addr);
6470+ err |= get_user(sethi2, (unsigned int *)(addr+4));
6471+ err |= get_user(or1, (unsigned int *)(addr+8));
6472+ err |= get_user(or2, (unsigned int *)(addr+12));
6473+ err |= get_user(sllx, (unsigned int *)(addr+16));
6474+ err |= get_user(add, (unsigned int *)(addr+20));
6475+ err |= get_user(jmpl, (unsigned int *)(addr+24));
6476+ err |= get_user(nop, (unsigned int *)(addr+28));
6477+ if (err)
6478+ break;
6479+
6480+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
6481+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6482+ (or1 & 0xFFFFE000U) == 0x88112000U &&
6483+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
6484+ sllx == 0x89293020U &&
6485+ add == 0x8A010005U &&
6486+ jmpl == 0x89C14000U &&
6487+ nop == 0x01000000U)
6488+ {
6489+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6490+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6491+ regs->u_regs[UREG_G4] <<= 32;
6492+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
6493+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
6494+ regs->u_regs[UREG_G4] = addr + 24;
6495+ addr = regs->u_regs[UREG_G5];
6496+ regs->tpc = addr;
6497+ regs->tnpc = addr+4;
6498+ return 3;
6499+ }
6500+ }
6501+ } while (0);
6502+
6503+#ifdef CONFIG_PAX_DLRESOLVE
6504+ do { /* PaX: unpatched PLT emulation step 2 */
6505+ unsigned int save, call, nop;
6506+
6507+ err = get_user(save, (unsigned int *)(regs->tpc-4));
6508+ err |= get_user(call, (unsigned int *)regs->tpc);
6509+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
6510+ if (err)
6511+ break;
6512+
6513+ if (save == 0x9DE3BFA8U &&
6514+ (call & 0xC0000000U) == 0x40000000U &&
6515+ nop == 0x01000000U)
6516+ {
6517+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6518+
6519+ if (test_thread_flag(TIF_32BIT))
6520+ dl_resolve &= 0xFFFFFFFFUL;
6521+
6522+ regs->u_regs[UREG_RETPC] = regs->tpc;
6523+ regs->tpc = dl_resolve;
6524+ regs->tnpc = dl_resolve+4;
6525+ return 3;
6526+ }
6527+ } while (0);
6528+#endif
6529+
6530+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
6531+ unsigned int sethi, ba, nop;
6532+
6533+ err = get_user(sethi, (unsigned int *)regs->tpc);
6534+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
6535+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6536+
6537+ if (err)
6538+ break;
6539+
6540+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6541+ (ba & 0xFFF00000U) == 0x30600000U &&
6542+ nop == 0x01000000U)
6543+ {
6544+ unsigned long addr;
6545+
6546+ addr = (sethi & 0x003FFFFFU) << 10;
6547+ regs->u_regs[UREG_G1] = addr;
6548+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6549+
6550+ if (test_thread_flag(TIF_32BIT))
6551+ addr &= 0xFFFFFFFFUL;
6552+
6553+ regs->tpc = addr;
6554+ regs->tnpc = addr+4;
6555+ return 2;
6556+ }
6557+ } while (0);
6558+
6559+#endif
6560+
6561+ return 1;
6562+}
6563+
6564+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6565+{
6566+ unsigned long i;
6567+
6568+ printk(KERN_ERR "PAX: bytes at PC: ");
6569+ for (i = 0; i < 8; i++) {
6570+ unsigned int c;
6571+ if (get_user(c, (unsigned int *)pc+i))
6572+ printk(KERN_CONT "???????? ");
6573+ else
6574+ printk(KERN_CONT "%08x ", c);
6575+ }
6576+ printk("\n");
6577+}
6578+#endif
6579+
6580 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6581 {
6582 struct mm_struct *mm = current->mm;
6583@@ -315,6 +768,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
6584 if (!vma)
6585 goto bad_area;
6586
6587+#ifdef CONFIG_PAX_PAGEEXEC
6588+ /* PaX: detect ITLB misses on non-exec pages */
6589+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
6590+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
6591+ {
6592+ if (address != regs->tpc)
6593+ goto good_area;
6594+
6595+ up_read(&mm->mmap_sem);
6596+ switch (pax_handle_fetch_fault(regs)) {
6597+
6598+#ifdef CONFIG_PAX_EMUPLT
6599+ case 2:
6600+ case 3:
6601+ return;
6602+#endif
6603+
6604+ }
6605+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
6606+ do_group_exit(SIGKILL);
6607+ }
6608+#endif
6609+
6610 /* Pure DTLB misses do not tell us whether the fault causing
6611 * load/store/atomic was a write or not, it only says that there
6612 * was no match. So in such a case we (carefully) read the
6613diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
6614index f27d103..1b06377 100644
6615--- a/arch/sparc/mm/hugetlbpage.c
6616+++ b/arch/sparc/mm/hugetlbpage.c
6617@@ -69,7 +69,7 @@ full_search:
6618 }
6619 return -ENOMEM;
6620 }
6621- if (likely(!vma || addr + len <= vma->vm_start)) {
6622+ if (likely(check_heap_stack_gap(vma, addr, len))) {
6623 /*
6624 * Remember the place where we stopped the search:
6625 */
6626@@ -108,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6627 /* make sure it can fit in the remaining address space */
6628 if (likely(addr > len)) {
6629 vma = find_vma(mm, addr-len);
6630- if (!vma || addr <= vma->vm_start) {
6631+ if (check_heap_stack_gap(vma, addr - len, len)) {
6632 /* remember the address as a hint for next time */
6633 return (mm->free_area_cache = addr-len);
6634 }
6635@@ -117,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6636 if (unlikely(mm->mmap_base < len))
6637 goto bottomup;
6638
6639- addr = (mm->mmap_base-len) & HPAGE_MASK;
6640+ addr = mm->mmap_base - len;
6641
6642 do {
6643+ addr &= HPAGE_MASK;
6644 /*
6645 * Lookup failure means no vma is above this address,
6646 * else if new region fits below vma->vm_start,
6647 * return with success:
6648 */
6649 vma = find_vma(mm, addr);
6650- if (likely(!vma || addr+len <= vma->vm_start)) {
6651+ if (likely(check_heap_stack_gap(vma, addr, len))) {
6652 /* remember the address as a hint for next time */
6653 return (mm->free_area_cache = addr);
6654 }
6655@@ -136,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6656 mm->cached_hole_size = vma->vm_start - addr;
6657
6658 /* try just below the current vma->vm_start */
6659- addr = (vma->vm_start-len) & HPAGE_MASK;
6660- } while (likely(len < vma->vm_start));
6661+ addr = skip_heap_stack_gap(vma, len);
6662+ } while (!IS_ERR_VALUE(addr));
6663
6664 bottomup:
6665 /*
6666@@ -183,8 +184,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
6667 if (addr) {
6668 addr = ALIGN(addr, HPAGE_SIZE);
6669 vma = find_vma(mm, addr);
6670- if (task_size - len >= addr &&
6671- (!vma || addr + len <= vma->vm_start))
6672+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
6673 return addr;
6674 }
6675 if (mm->get_unmapped_area == arch_get_unmapped_area)
6676diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
6677index dc7c3b1..34c0070 100644
6678--- a/arch/sparc/mm/init_32.c
6679+++ b/arch/sparc/mm/init_32.c
6680@@ -317,6 +317,9 @@ extern void device_scan(void);
6681 pgprot_t PAGE_SHARED __read_mostly;
6682 EXPORT_SYMBOL(PAGE_SHARED);
6683
6684+pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
6685+EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
6686+
6687 void __init paging_init(void)
6688 {
6689 switch(sparc_cpu_model) {
6690@@ -345,17 +348,17 @@ void __init paging_init(void)
6691
6692 /* Initialize the protection map with non-constant, MMU dependent values. */
6693 protection_map[0] = PAGE_NONE;
6694- protection_map[1] = PAGE_READONLY;
6695- protection_map[2] = PAGE_COPY;
6696- protection_map[3] = PAGE_COPY;
6697+ protection_map[1] = PAGE_READONLY_NOEXEC;
6698+ protection_map[2] = PAGE_COPY_NOEXEC;
6699+ protection_map[3] = PAGE_COPY_NOEXEC;
6700 protection_map[4] = PAGE_READONLY;
6701 protection_map[5] = PAGE_READONLY;
6702 protection_map[6] = PAGE_COPY;
6703 protection_map[7] = PAGE_COPY;
6704 protection_map[8] = PAGE_NONE;
6705- protection_map[9] = PAGE_READONLY;
6706- protection_map[10] = PAGE_SHARED;
6707- protection_map[11] = PAGE_SHARED;
6708+ protection_map[9] = PAGE_READONLY_NOEXEC;
6709+ protection_map[10] = PAGE_SHARED_NOEXEC;
6710+ protection_map[11] = PAGE_SHARED_NOEXEC;
6711 protection_map[12] = PAGE_READONLY;
6712 protection_map[13] = PAGE_READONLY;
6713 protection_map[14] = PAGE_SHARED;
6714diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
6715index 509b1ff..bfd7118 100644
6716--- a/arch/sparc/mm/srmmu.c
6717+++ b/arch/sparc/mm/srmmu.c
6718@@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
6719 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
6720 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
6721 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
6722+
6723+#ifdef CONFIG_PAX_PAGEEXEC
6724+ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
6725+ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
6726+ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
6727+#endif
6728+
6729 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
6730 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
6731
6732diff --git a/arch/um/Makefile b/arch/um/Makefile
6733index fc633db..5e1a1c2 100644
6734--- a/arch/um/Makefile
6735+++ b/arch/um/Makefile
6736@@ -49,6 +49,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
6737 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
6738 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64
6739
6740+ifdef CONSTIFY_PLUGIN
6741+USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
6742+endif
6743+
6744 include $(srctree)/$(ARCH_DIR)/Makefile-$(SUBARCH)
6745
6746 #This will adjust *FLAGS accordingly to the platform.
6747diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
6748index 6c03acd..a5e0215 100644
6749--- a/arch/um/include/asm/kmap_types.h
6750+++ b/arch/um/include/asm/kmap_types.h
6751@@ -23,6 +23,7 @@ enum km_type {
6752 KM_IRQ1,
6753 KM_SOFTIRQ0,
6754 KM_SOFTIRQ1,
6755+ KM_CLEARPAGE,
6756 KM_TYPE_NR
6757 };
6758
6759diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
6760index 4cc9b6c..02e5029 100644
6761--- a/arch/um/include/asm/page.h
6762+++ b/arch/um/include/asm/page.h
6763@@ -14,6 +14,9 @@
6764 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
6765 #define PAGE_MASK (~(PAGE_SIZE-1))
6766
6767+#define ktla_ktva(addr) (addr)
6768+#define ktva_ktla(addr) (addr)
6769+
6770 #ifndef __ASSEMBLY__
6771
6772 struct page;
6773diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
6774index 4a28a15..654dc2a 100644
6775--- a/arch/um/kernel/process.c
6776+++ b/arch/um/kernel/process.c
6777@@ -393,22 +393,6 @@ int singlestepping(void * t)
6778 return 2;
6779 }
6780
6781-/*
6782- * Only x86 and x86_64 have an arch_align_stack().
6783- * All other arches have "#define arch_align_stack(x) (x)"
6784- * in their asm/system.h
6785- * As this is included in UML from asm-um/system-generic.h,
6786- * we can use it to behave as the subarch does.
6787- */
6788-#ifndef arch_align_stack
6789-unsigned long arch_align_stack(unsigned long sp)
6790-{
6791- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6792- sp -= get_random_int() % 8192;
6793- return sp & ~0xf;
6794-}
6795-#endif
6796-
6797 unsigned long get_wchan(struct task_struct *p)
6798 {
6799 unsigned long stack_page, sp, ip;
6800diff --git a/arch/um/sys-i386/shared/sysdep/system.h b/arch/um/sys-i386/shared/sysdep/system.h
6801index d1b93c4..ae1b7fd 100644
6802--- a/arch/um/sys-i386/shared/sysdep/system.h
6803+++ b/arch/um/sys-i386/shared/sysdep/system.h
6804@@ -17,7 +17,7 @@
6805 # define AT_VECTOR_SIZE_ARCH 1
6806 #endif
6807
6808-extern unsigned long arch_align_stack(unsigned long sp);
6809+#define arch_align_stack(x) ((x) & ~0xfUL)
6810
6811 void default_idle(void);
6812
6813diff --git a/arch/um/sys-i386/syscalls.c b/arch/um/sys-i386/syscalls.c
6814index 857ca0b..9a2669d 100644
6815--- a/arch/um/sys-i386/syscalls.c
6816+++ b/arch/um/sys-i386/syscalls.c
6817@@ -11,6 +11,21 @@
6818 #include "asm/uaccess.h"
6819 #include "asm/unistd.h"
6820
6821+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
6822+{
6823+ unsigned long pax_task_size = TASK_SIZE;
6824+
6825+#ifdef CONFIG_PAX_SEGMEXEC
6826+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
6827+ pax_task_size = SEGMEXEC_TASK_SIZE;
6828+#endif
6829+
6830+ if (len > pax_task_size || addr > pax_task_size - len)
6831+ return -EINVAL;
6832+
6833+ return 0;
6834+}
6835+
6836 /*
6837 * Perform the select(nd, in, out, ex, tv) and mmap() system
6838 * calls. Linux/i386 didn't use to be able to handle more than
6839diff --git a/arch/um/sys-x86_64/shared/sysdep/system.h b/arch/um/sys-x86_64/shared/sysdep/system.h
6840index d1b93c4..ae1b7fd 100644
6841--- a/arch/um/sys-x86_64/shared/sysdep/system.h
6842+++ b/arch/um/sys-x86_64/shared/sysdep/system.h
6843@@ -17,7 +17,7 @@
6844 # define AT_VECTOR_SIZE_ARCH 1
6845 #endif
6846
6847-extern unsigned long arch_align_stack(unsigned long sp);
6848+#define arch_align_stack(x) ((x) & ~0xfUL)
6849
6850 void default_idle(void);
6851
6852diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
6853index 73ae02a..f932de5 100644
6854--- a/arch/x86/Kconfig
6855+++ b/arch/x86/Kconfig
6856@@ -223,7 +223,7 @@ config X86_TRAMPOLINE
6857
6858 config X86_32_LAZY_GS
6859 def_bool y
6860- depends on X86_32 && !CC_STACKPROTECTOR
6861+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
6862
6863 config KTIME_SCALAR
6864 def_bool X86_32
6865@@ -1008,7 +1008,7 @@ choice
6866
6867 config NOHIGHMEM
6868 bool "off"
6869- depends on !X86_NUMAQ
6870+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
6871 ---help---
6872 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
6873 However, the address space of 32-bit x86 processors is only 4
6874@@ -1045,7 +1045,7 @@ config NOHIGHMEM
6875
6876 config HIGHMEM4G
6877 bool "4GB"
6878- depends on !X86_NUMAQ
6879+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
6880 ---help---
6881 Select this if you have a 32-bit processor and between 1 and 4
6882 gigabytes of physical RAM.
6883@@ -1099,7 +1099,7 @@ config PAGE_OFFSET
6884 hex
6885 default 0xB0000000 if VMSPLIT_3G_OPT
6886 default 0x80000000 if VMSPLIT_2G
6887- default 0x78000000 if VMSPLIT_2G_OPT
6888+ default 0x70000000 if VMSPLIT_2G_OPT
6889 default 0x40000000 if VMSPLIT_1G
6890 default 0xC0000000
6891 depends on X86_32
6892@@ -1460,6 +1460,7 @@ config SECCOMP
6893
6894 config CC_STACKPROTECTOR
6895 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
6896+ depends on X86_64 || !PAX_MEMORY_UDEREF
6897 ---help---
6898 This option turns on the -fstack-protector GCC feature. This
6899 feature puts, at the beginning of functions, a canary value on
6900@@ -1517,6 +1518,7 @@ config KEXEC_JUMP
6901 config PHYSICAL_START
6902 hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
6903 default "0x1000000"
6904+ range 0x400000 0x40000000
6905 ---help---
6906 This gives the physical address where the kernel is loaded.
6907
6908@@ -1581,6 +1583,7 @@ config PHYSICAL_ALIGN
6909 hex
6910 prompt "Alignment value to which kernel should be aligned" if X86_32
6911 default "0x1000000"
6912+ range 0x400000 0x1000000 if PAX_KERNEXEC
6913 range 0x2000 0x1000000
6914 ---help---
6915 This value puts the alignment restrictions on physical address
6916@@ -1612,9 +1615,10 @@ config HOTPLUG_CPU
6917 Say N if you want to disable CPU hotplug.
6918
6919 config COMPAT_VDSO
6920- def_bool y
6921+ def_bool n
6922 prompt "Compat VDSO support"
6923 depends on X86_32 || IA32_EMULATION
6924+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
6925 ---help---
6926 Map the 32-bit VDSO to the predictable old-style address too.
6927 ---help---
6928diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
6929index 0e566103..1a6b57e 100644
6930--- a/arch/x86/Kconfig.cpu
6931+++ b/arch/x86/Kconfig.cpu
6932@@ -340,7 +340,7 @@ config X86_PPRO_FENCE
6933
6934 config X86_F00F_BUG
6935 def_bool y
6936- depends on M586MMX || M586TSC || M586 || M486 || M386
6937+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
6938
6939 config X86_WP_WORKS_OK
6940 def_bool y
6941@@ -360,7 +360,7 @@ config X86_POPAD_OK
6942
6943 config X86_ALIGNMENT_16
6944 def_bool y
6945- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
6946+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
6947
6948 config X86_INTEL_USERCOPY
6949 def_bool y
6950@@ -406,7 +406,7 @@ config X86_CMPXCHG64
6951 # generates cmov.
6952 config X86_CMOV
6953 def_bool y
6954- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
6955+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM)
6956
6957 config X86_MINIMUM_CPU_FAMILY
6958 int
6959diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
6960index d105f29..c928727 100644
6961--- a/arch/x86/Kconfig.debug
6962+++ b/arch/x86/Kconfig.debug
6963@@ -99,7 +99,7 @@ config X86_PTDUMP
6964 config DEBUG_RODATA
6965 bool "Write protect kernel read-only data structures"
6966 default y
6967- depends on DEBUG_KERNEL
6968+ depends on DEBUG_KERNEL && BROKEN
6969 ---help---
6970 Mark the kernel read-only data as write-protected in the pagetables,
6971 in order to catch accidental (and incorrect) writes to such const
6972diff --git a/arch/x86/Makefile b/arch/x86/Makefile
6973index d2d24c9..0f21f8d 100644
6974--- a/arch/x86/Makefile
6975+++ b/arch/x86/Makefile
6976@@ -44,6 +44,7 @@ ifeq ($(CONFIG_X86_32),y)
6977 else
6978 BITS := 64
6979 UTS_MACHINE := x86_64
6980+ biarch := $(call cc-option,-m64)
6981 CHECKFLAGS += -D__x86_64__ -m64
6982
6983 KBUILD_AFLAGS += -m64
6984@@ -189,3 +190,12 @@ define archhelp
6985 echo ' FDARGS="..." arguments for the booted kernel'
6986 echo ' FDINITRD=file initrd for the booted kernel'
6987 endef
6988+
6989+define OLD_LD
6990+
6991+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
6992+*** Please upgrade your binutils to 2.18 or newer
6993+endef
6994+
6995+archprepare:
6996+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
6997diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
6998index ec749c2..bbb5319 100644
6999--- a/arch/x86/boot/Makefile
7000+++ b/arch/x86/boot/Makefile
7001@@ -69,6 +69,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7002 $(call cc-option, -fno-stack-protector) \
7003 $(call cc-option, -mpreferred-stack-boundary=2)
7004 KBUILD_CFLAGS += $(call cc-option, -m32)
7005+ifdef CONSTIFY_PLUGIN
7006+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7007+endif
7008 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7009 GCOV_PROFILE := n
7010
7011diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7012index 878e4b9..20537ab 100644
7013--- a/arch/x86/boot/bitops.h
7014+++ b/arch/x86/boot/bitops.h
7015@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7016 u8 v;
7017 const u32 *p = (const u32 *)addr;
7018
7019- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7020+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7021 return v;
7022 }
7023
7024@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7025
7026 static inline void set_bit(int nr, void *addr)
7027 {
7028- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7029+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7030 }
7031
7032 #endif /* BOOT_BITOPS_H */
7033diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7034index 98239d2..f40214c 100644
7035--- a/arch/x86/boot/boot.h
7036+++ b/arch/x86/boot/boot.h
7037@@ -82,7 +82,7 @@ static inline void io_delay(void)
7038 static inline u16 ds(void)
7039 {
7040 u16 seg;
7041- asm("movw %%ds,%0" : "=rm" (seg));
7042+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7043 return seg;
7044 }
7045
7046@@ -178,7 +178,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7047 static inline int memcmp(const void *s1, const void *s2, size_t len)
7048 {
7049 u8 diff;
7050- asm("repe; cmpsb; setnz %0"
7051+ asm volatile("repe; cmpsb; setnz %0"
7052 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7053 return diff;
7054 }
7055diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7056index f8ed065..5bf5ff3 100644
7057--- a/arch/x86/boot/compressed/Makefile
7058+++ b/arch/x86/boot/compressed/Makefile
7059@@ -13,6 +13,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7060 KBUILD_CFLAGS += $(cflags-y)
7061 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7062 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7063+ifdef CONSTIFY_PLUGIN
7064+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7065+endif
7066
7067 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7068 GCOV_PROFILE := n
7069diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7070index f543b70..b60fba8 100644
7071--- a/arch/x86/boot/compressed/head_32.S
7072+++ b/arch/x86/boot/compressed/head_32.S
7073@@ -76,7 +76,7 @@ ENTRY(startup_32)
7074 notl %eax
7075 andl %eax, %ebx
7076 #else
7077- movl $LOAD_PHYSICAL_ADDR, %ebx
7078+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7079 #endif
7080
7081 /* Target address to relocate to for decompression */
7082@@ -149,7 +149,7 @@ relocated:
7083 * and where it was actually loaded.
7084 */
7085 movl %ebp, %ebx
7086- subl $LOAD_PHYSICAL_ADDR, %ebx
7087+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7088 jz 2f /* Nothing to be done if loaded at compiled addr. */
7089 /*
7090 * Process relocations.
7091@@ -157,8 +157,7 @@ relocated:
7092
7093 1: subl $4, %edi
7094 movl (%edi), %ecx
7095- testl %ecx, %ecx
7096- jz 2f
7097+ jecxz 2f
7098 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7099 jmp 1b
7100 2:
7101diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7102index 077e1b6..2c6b13b 100644
7103--- a/arch/x86/boot/compressed/head_64.S
7104+++ b/arch/x86/boot/compressed/head_64.S
7105@@ -91,7 +91,7 @@ ENTRY(startup_32)
7106 notl %eax
7107 andl %eax, %ebx
7108 #else
7109- movl $LOAD_PHYSICAL_ADDR, %ebx
7110+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7111 #endif
7112
7113 /* Target address to relocate to for decompression */
7114@@ -183,7 +183,7 @@ no_longmode:
7115 hlt
7116 jmp 1b
7117
7118-#include "../../kernel/verify_cpu_64.S"
7119+#include "../../kernel/verify_cpu.S"
7120
7121 /*
7122 * Be careful here startup_64 needs to be at a predictable
7123@@ -234,7 +234,7 @@ ENTRY(startup_64)
7124 notq %rax
7125 andq %rax, %rbp
7126 #else
7127- movq $LOAD_PHYSICAL_ADDR, %rbp
7128+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7129 #endif
7130
7131 /* Target address to relocate to for decompression */
7132diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7133index 842b2a3..f00178b 100644
7134--- a/arch/x86/boot/compressed/misc.c
7135+++ b/arch/x86/boot/compressed/misc.c
7136@@ -288,7 +288,7 @@ static void parse_elf(void *output)
7137 case PT_LOAD:
7138 #ifdef CONFIG_RELOCATABLE
7139 dest = output;
7140- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7141+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7142 #else
7143 dest = (void *)(phdr->p_paddr);
7144 #endif
7145@@ -335,7 +335,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7146 error("Destination address too large");
7147 #endif
7148 #ifndef CONFIG_RELOCATABLE
7149- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7150+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7151 error("Wrong destination address");
7152 #endif
7153
7154diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
7155index bcbd36c..b1754af 100644
7156--- a/arch/x86/boot/compressed/mkpiggy.c
7157+++ b/arch/x86/boot/compressed/mkpiggy.c
7158@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
7159
7160 offs = (olen > ilen) ? olen - ilen : 0;
7161 offs += olen >> 12; /* Add 8 bytes for each 32K block */
7162- offs += 32*1024 + 18; /* Add 32K + 18 bytes slack */
7163+ offs += 64*1024; /* Add 64K bytes slack */
7164 offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
7165
7166 printf(".section \".rodata.compressed\",\"a\",@progbits\n");
7167diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
7168index bbeb0c3..f5167ab 100644
7169--- a/arch/x86/boot/compressed/relocs.c
7170+++ b/arch/x86/boot/compressed/relocs.c
7171@@ -10,8 +10,11 @@
7172 #define USE_BSD
7173 #include <endian.h>
7174
7175+#include "../../../../include/linux/autoconf.h"
7176+
7177 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
7178 static Elf32_Ehdr ehdr;
7179+static Elf32_Phdr *phdr;
7180 static unsigned long reloc_count, reloc_idx;
7181 static unsigned long *relocs;
7182
7183@@ -37,7 +40,7 @@ static const char* safe_abs_relocs[] = {
7184
7185 static int is_safe_abs_reloc(const char* sym_name)
7186 {
7187- int i;
7188+ unsigned int i;
7189
7190 for (i = 0; i < ARRAY_SIZE(safe_abs_relocs); i++) {
7191 if (!strcmp(sym_name, safe_abs_relocs[i]))
7192@@ -245,9 +248,39 @@ static void read_ehdr(FILE *fp)
7193 }
7194 }
7195
7196+static void read_phdrs(FILE *fp)
7197+{
7198+ unsigned int i;
7199+
7200+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
7201+ if (!phdr) {
7202+ die("Unable to allocate %d program headers\n",
7203+ ehdr.e_phnum);
7204+ }
7205+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
7206+ die("Seek to %d failed: %s\n",
7207+ ehdr.e_phoff, strerror(errno));
7208+ }
7209+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
7210+ die("Cannot read ELF program headers: %s\n",
7211+ strerror(errno));
7212+ }
7213+ for(i = 0; i < ehdr.e_phnum; i++) {
7214+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
7215+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
7216+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
7217+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
7218+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
7219+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
7220+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
7221+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
7222+ }
7223+
7224+}
7225+
7226 static void read_shdrs(FILE *fp)
7227 {
7228- int i;
7229+ unsigned int i;
7230 Elf32_Shdr shdr;
7231
7232 secs = calloc(ehdr.e_shnum, sizeof(struct section));
7233@@ -282,7 +315,7 @@ static void read_shdrs(FILE *fp)
7234
7235 static void read_strtabs(FILE *fp)
7236 {
7237- int i;
7238+ unsigned int i;
7239 for (i = 0; i < ehdr.e_shnum; i++) {
7240 struct section *sec = &secs[i];
7241 if (sec->shdr.sh_type != SHT_STRTAB) {
7242@@ -307,7 +340,7 @@ static void read_strtabs(FILE *fp)
7243
7244 static void read_symtabs(FILE *fp)
7245 {
7246- int i,j;
7247+ unsigned int i,j;
7248 for (i = 0; i < ehdr.e_shnum; i++) {
7249 struct section *sec = &secs[i];
7250 if (sec->shdr.sh_type != SHT_SYMTAB) {
7251@@ -340,7 +373,9 @@ static void read_symtabs(FILE *fp)
7252
7253 static void read_relocs(FILE *fp)
7254 {
7255- int i,j;
7256+ unsigned int i,j;
7257+ uint32_t base;
7258+
7259 for (i = 0; i < ehdr.e_shnum; i++) {
7260 struct section *sec = &secs[i];
7261 if (sec->shdr.sh_type != SHT_REL) {
7262@@ -360,9 +395,18 @@ static void read_relocs(FILE *fp)
7263 die("Cannot read symbol table: %s\n",
7264 strerror(errno));
7265 }
7266+ base = 0;
7267+ for (j = 0; j < ehdr.e_phnum; j++) {
7268+ if (phdr[j].p_type != PT_LOAD )
7269+ continue;
7270+ 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)
7271+ continue;
7272+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
7273+ break;
7274+ }
7275 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
7276 Elf32_Rel *rel = &sec->reltab[j];
7277- rel->r_offset = elf32_to_cpu(rel->r_offset);
7278+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
7279 rel->r_info = elf32_to_cpu(rel->r_info);
7280 }
7281 }
7282@@ -371,14 +415,14 @@ static void read_relocs(FILE *fp)
7283
7284 static void print_absolute_symbols(void)
7285 {
7286- int i;
7287+ unsigned int i;
7288 printf("Absolute symbols\n");
7289 printf(" Num: Value Size Type Bind Visibility Name\n");
7290 for (i = 0; i < ehdr.e_shnum; i++) {
7291 struct section *sec = &secs[i];
7292 char *sym_strtab;
7293 Elf32_Sym *sh_symtab;
7294- int j;
7295+ unsigned int j;
7296
7297 if (sec->shdr.sh_type != SHT_SYMTAB) {
7298 continue;
7299@@ -406,14 +450,14 @@ static void print_absolute_symbols(void)
7300
7301 static void print_absolute_relocs(void)
7302 {
7303- int i, printed = 0;
7304+ unsigned int i, printed = 0;
7305
7306 for (i = 0; i < ehdr.e_shnum; i++) {
7307 struct section *sec = &secs[i];
7308 struct section *sec_applies, *sec_symtab;
7309 char *sym_strtab;
7310 Elf32_Sym *sh_symtab;
7311- int j;
7312+ unsigned int j;
7313 if (sec->shdr.sh_type != SHT_REL) {
7314 continue;
7315 }
7316@@ -474,13 +518,13 @@ static void print_absolute_relocs(void)
7317
7318 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7319 {
7320- int i;
7321+ unsigned int i;
7322 /* Walk through the relocations */
7323 for (i = 0; i < ehdr.e_shnum; i++) {
7324 char *sym_strtab;
7325 Elf32_Sym *sh_symtab;
7326 struct section *sec_applies, *sec_symtab;
7327- int j;
7328+ unsigned int j;
7329 struct section *sec = &secs[i];
7330
7331 if (sec->shdr.sh_type != SHT_REL) {
7332@@ -504,6 +548,21 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
7333 if (sym->st_shndx == SHN_ABS) {
7334 continue;
7335 }
7336+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
7337+ if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
7338+ continue;
7339+
7340+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
7341+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
7342+ if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
7343+ continue;
7344+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
7345+ continue;
7346+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
7347+ continue;
7348+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
7349+ continue;
7350+#endif
7351 if (r_type == R_386_NONE || r_type == R_386_PC32) {
7352 /*
7353 * NONE can be ignored and and PC relative
7354@@ -541,7 +600,7 @@ static int cmp_relocs(const void *va, const void *vb)
7355
7356 static void emit_relocs(int as_text)
7357 {
7358- int i;
7359+ unsigned int i;
7360 /* Count how many relocations I have and allocate space for them. */
7361 reloc_count = 0;
7362 walk_relocs(count_reloc);
7363@@ -634,6 +693,7 @@ int main(int argc, char **argv)
7364 fname, strerror(errno));
7365 }
7366 read_ehdr(fp);
7367+ read_phdrs(fp);
7368 read_shdrs(fp);
7369 read_strtabs(fp);
7370 read_symtabs(fp);
7371diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7372index 4d3ff03..e4972ff 100644
7373--- a/arch/x86/boot/cpucheck.c
7374+++ b/arch/x86/boot/cpucheck.c
7375@@ -74,7 +74,7 @@ static int has_fpu(void)
7376 u16 fcw = -1, fsw = -1;
7377 u32 cr0;
7378
7379- asm("movl %%cr0,%0" : "=r" (cr0));
7380+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7381 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7382 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7383 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7384@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7385 {
7386 u32 f0, f1;
7387
7388- asm("pushfl ; "
7389+ asm volatile("pushfl ; "
7390 "pushfl ; "
7391 "popl %0 ; "
7392 "movl %0,%1 ; "
7393@@ -115,7 +115,7 @@ static void get_flags(void)
7394 set_bit(X86_FEATURE_FPU, cpu.flags);
7395
7396 if (has_eflag(X86_EFLAGS_ID)) {
7397- asm("cpuid"
7398+ asm volatile("cpuid"
7399 : "=a" (max_intel_level),
7400 "=b" (cpu_vendor[0]),
7401 "=d" (cpu_vendor[1]),
7402@@ -124,7 +124,7 @@ static void get_flags(void)
7403
7404 if (max_intel_level >= 0x00000001 &&
7405 max_intel_level <= 0x0000ffff) {
7406- asm("cpuid"
7407+ asm volatile("cpuid"
7408 : "=a" (tfms),
7409 "=c" (cpu.flags[4]),
7410 "=d" (cpu.flags[0])
7411@@ -136,7 +136,7 @@ static void get_flags(void)
7412 cpu.model += ((tfms >> 16) & 0xf) << 4;
7413 }
7414
7415- asm("cpuid"
7416+ asm volatile("cpuid"
7417 : "=a" (max_amd_level)
7418 : "a" (0x80000000)
7419 : "ebx", "ecx", "edx");
7420@@ -144,7 +144,7 @@ static void get_flags(void)
7421 if (max_amd_level >= 0x80000001 &&
7422 max_amd_level <= 0x8000ffff) {
7423 u32 eax = 0x80000001;
7424- asm("cpuid"
7425+ asm volatile("cpuid"
7426 : "+a" (eax),
7427 "=c" (cpu.flags[6]),
7428 "=d" (cpu.flags[1])
7429@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7430 u32 ecx = MSR_K7_HWCR;
7431 u32 eax, edx;
7432
7433- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7434+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7435 eax &= ~(1 << 15);
7436- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7437+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7438
7439 get_flags(); /* Make sure it really did something */
7440 err = check_flags();
7441@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7442 u32 ecx = MSR_VIA_FCR;
7443 u32 eax, edx;
7444
7445- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7446+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7447 eax |= (1<<1)|(1<<7);
7448- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7449+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7450
7451 set_bit(X86_FEATURE_CX8, cpu.flags);
7452 err = check_flags();
7453@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7454 u32 eax, edx;
7455 u32 level = 1;
7456
7457- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7458- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7459- asm("cpuid"
7460+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7461+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7462+ asm volatile("cpuid"
7463 : "+a" (level), "=d" (cpu.flags[0])
7464 : : "ecx", "ebx");
7465- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7466+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7467
7468 err = check_flags();
7469 }
7470diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7471index b31cc54..8d69237 100644
7472--- a/arch/x86/boot/header.S
7473+++ b/arch/x86/boot/header.S
7474@@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
7475 # single linked list of
7476 # struct setup_data
7477
7478-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7479+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7480
7481 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7482 #define VO_INIT_SIZE (VO__end - VO__text)
7483diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7484index cae3feb..ff8ff2a 100644
7485--- a/arch/x86/boot/memory.c
7486+++ b/arch/x86/boot/memory.c
7487@@ -19,7 +19,7 @@
7488
7489 static int detect_memory_e820(void)
7490 {
7491- int count = 0;
7492+ unsigned int count = 0;
7493 struct biosregs ireg, oreg;
7494 struct e820entry *desc = boot_params.e820_map;
7495 static struct e820entry buf; /* static so it is zeroed */
7496diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7497index 11e8c6e..fdbb1ed 100644
7498--- a/arch/x86/boot/video-vesa.c
7499+++ b/arch/x86/boot/video-vesa.c
7500@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7501
7502 boot_params.screen_info.vesapm_seg = oreg.es;
7503 boot_params.screen_info.vesapm_off = oreg.di;
7504+ boot_params.screen_info.vesapm_size = oreg.cx;
7505 }
7506
7507 /*
7508diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7509index d42da38..787cdf3 100644
7510--- a/arch/x86/boot/video.c
7511+++ b/arch/x86/boot/video.c
7512@@ -90,7 +90,7 @@ static void store_mode_params(void)
7513 static unsigned int get_entry(void)
7514 {
7515 char entry_buf[4];
7516- int i, len = 0;
7517+ unsigned int i, len = 0;
7518 int key;
7519 unsigned int v;
7520
7521diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
7522index 5b577d5..3c1fed4 100644
7523--- a/arch/x86/crypto/aes-x86_64-asm_64.S
7524+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
7525@@ -8,6 +8,8 @@
7526 * including this sentence is retained in full.
7527 */
7528
7529+#include <asm/alternative-asm.h>
7530+
7531 .extern crypto_ft_tab
7532 .extern crypto_it_tab
7533 .extern crypto_fl_tab
7534@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
7535 je B192; \
7536 leaq 32(r9),r9;
7537
7538+#define ret pax_force_retaddr 0, 1; ret
7539+
7540 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
7541 movq r1,r2; \
7542 movq r3,r4; \
7543diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
7544index eb0566e..e3ebad8 100644
7545--- a/arch/x86/crypto/aesni-intel_asm.S
7546+++ b/arch/x86/crypto/aesni-intel_asm.S
7547@@ -16,6 +16,7 @@
7548 */
7549
7550 #include <linux/linkage.h>
7551+#include <asm/alternative-asm.h>
7552
7553 .text
7554
7555@@ -52,6 +53,7 @@ _key_expansion_256a:
7556 pxor %xmm1, %xmm0
7557 movaps %xmm0, (%rcx)
7558 add $0x10, %rcx
7559+ pax_force_retaddr_bts
7560 ret
7561
7562 _key_expansion_192a:
7563@@ -75,6 +77,7 @@ _key_expansion_192a:
7564 shufps $0b01001110, %xmm2, %xmm1
7565 movaps %xmm1, 16(%rcx)
7566 add $0x20, %rcx
7567+ pax_force_retaddr_bts
7568 ret
7569
7570 _key_expansion_192b:
7571@@ -93,6 +96,7 @@ _key_expansion_192b:
7572
7573 movaps %xmm0, (%rcx)
7574 add $0x10, %rcx
7575+ pax_force_retaddr_bts
7576 ret
7577
7578 _key_expansion_256b:
7579@@ -104,6 +108,7 @@ _key_expansion_256b:
7580 pxor %xmm1, %xmm2
7581 movaps %xmm2, (%rcx)
7582 add $0x10, %rcx
7583+ pax_force_retaddr_bts
7584 ret
7585
7586 /*
7587@@ -239,7 +244,9 @@ ENTRY(aesni_set_key)
7588 cmp %rcx, %rdi
7589 jb .Ldec_key_loop
7590 xor %rax, %rax
7591+ pax_force_retaddr 0, 1
7592 ret
7593+ENDPROC(aesni_set_key)
7594
7595 /*
7596 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
7597@@ -249,7 +256,9 @@ ENTRY(aesni_enc)
7598 movups (INP), STATE # input
7599 call _aesni_enc1
7600 movups STATE, (OUTP) # output
7601+ pax_force_retaddr 0, 1
7602 ret
7603+ENDPROC(aesni_enc)
7604
7605 /*
7606 * _aesni_enc1: internal ABI
7607@@ -319,6 +328,7 @@ _aesni_enc1:
7608 movaps 0x70(TKEYP), KEY
7609 # aesenclast KEY, STATE # last round
7610 .byte 0x66, 0x0f, 0x38, 0xdd, 0xc2
7611+ pax_force_retaddr_bts
7612 ret
7613
7614 /*
7615@@ -482,6 +492,7 @@ _aesni_enc4:
7616 .byte 0x66, 0x0f, 0x38, 0xdd, 0xea
7617 # aesenclast KEY, STATE4
7618 .byte 0x66, 0x0f, 0x38, 0xdd, 0xf2
7619+ pax_force_retaddr_bts
7620 ret
7621
7622 /*
7623@@ -493,7 +504,9 @@ ENTRY(aesni_dec)
7624 movups (INP), STATE # input
7625 call _aesni_dec1
7626 movups STATE, (OUTP) #output
7627+ pax_force_retaddr 0, 1
7628 ret
7629+ENDPROC(aesni_dec)
7630
7631 /*
7632 * _aesni_dec1: internal ABI
7633@@ -563,6 +576,7 @@ _aesni_dec1:
7634 movaps 0x70(TKEYP), KEY
7635 # aesdeclast KEY, STATE # last round
7636 .byte 0x66, 0x0f, 0x38, 0xdf, 0xc2
7637+ pax_force_retaddr_bts
7638 ret
7639
7640 /*
7641@@ -726,6 +740,7 @@ _aesni_dec4:
7642 .byte 0x66, 0x0f, 0x38, 0xdf, 0xea
7643 # aesdeclast KEY, STATE4
7644 .byte 0x66, 0x0f, 0x38, 0xdf, 0xf2
7645+ pax_force_retaddr_bts
7646 ret
7647
7648 /*
7649@@ -769,7 +784,9 @@ ENTRY(aesni_ecb_enc)
7650 cmp $16, LEN
7651 jge .Lecb_enc_loop1
7652 .Lecb_enc_ret:
7653+ pax_force_retaddr 0, 1
7654 ret
7655+ENDPROC(aesni_ecb_enc)
7656
7657 /*
7658 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7659@@ -813,7 +830,9 @@ ENTRY(aesni_ecb_dec)
7660 cmp $16, LEN
7661 jge .Lecb_dec_loop1
7662 .Lecb_dec_ret:
7663+ pax_force_retaddr 0, 1
7664 ret
7665+ENDPROC(aesni_ecb_dec)
7666
7667 /*
7668 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7669@@ -837,7 +856,9 @@ ENTRY(aesni_cbc_enc)
7670 jge .Lcbc_enc_loop
7671 movups STATE, (IVP)
7672 .Lcbc_enc_ret:
7673+ pax_force_retaddr 0, 1
7674 ret
7675+ENDPROC(aesni_cbc_enc)
7676
7677 /*
7678 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
7679@@ -894,4 +915,6 @@ ENTRY(aesni_cbc_dec)
7680 .Lcbc_dec_ret:
7681 movups IV, (IVP)
7682 .Lcbc_dec_just_ret:
7683+ pax_force_retaddr 0, 1
7684 ret
7685+ENDPROC(aesni_cbc_dec)
7686diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7687index 6214a9b..1f4fc9a 100644
7688--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
7689+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
7690@@ -1,3 +1,5 @@
7691+#include <asm/alternative-asm.h>
7692+
7693 # enter ECRYPT_encrypt_bytes
7694 .text
7695 .p2align 5
7696@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
7697 add %r11,%rsp
7698 mov %rdi,%rax
7699 mov %rsi,%rdx
7700+ pax_force_retaddr 0, 1
7701 ret
7702 # bytesatleast65:
7703 ._bytesatleast65:
7704@@ -891,6 +894,7 @@ ECRYPT_keysetup:
7705 add %r11,%rsp
7706 mov %rdi,%rax
7707 mov %rsi,%rdx
7708+ pax_force_retaddr
7709 ret
7710 # enter ECRYPT_ivsetup
7711 .text
7712@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
7713 add %r11,%rsp
7714 mov %rdi,%rax
7715 mov %rsi,%rdx
7716+ pax_force_retaddr
7717 ret
7718diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
7719index 35974a5..5662ae2 100644
7720--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
7721+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
7722@@ -21,6 +21,7 @@
7723 .text
7724
7725 #include <asm/asm-offsets.h>
7726+#include <asm/alternative-asm.h>
7727
7728 #define a_offset 0
7729 #define b_offset 4
7730@@ -269,6 +270,7 @@ twofish_enc_blk:
7731
7732 popq R1
7733 movq $1,%rax
7734+ pax_force_retaddr 0, 1
7735 ret
7736
7737 twofish_dec_blk:
7738@@ -321,4 +323,5 @@ twofish_dec_blk:
7739
7740 popq R1
7741 movq $1,%rax
7742+ pax_force_retaddr 0, 1
7743 ret
7744diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
7745index 14531ab..a89a0c0 100644
7746--- a/arch/x86/ia32/ia32_aout.c
7747+++ b/arch/x86/ia32/ia32_aout.c
7748@@ -169,6 +169,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
7749 unsigned long dump_start, dump_size;
7750 struct user32 dump;
7751
7752+ memset(&dump, 0, sizeof(dump));
7753+
7754 fs = get_fs();
7755 set_fs(KERNEL_DS);
7756 has_dumped = 1;
7757@@ -218,12 +220,6 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
7758 dump_size = dump.u_ssize << PAGE_SHIFT;
7759 DUMP_WRITE(dump_start, dump_size);
7760 }
7761- /*
7762- * Finally dump the task struct. Not be used by gdb, but
7763- * could be useful
7764- */
7765- set_fs(KERNEL_DS);
7766- DUMP_WRITE(current, sizeof(*current));
7767 end_coredump:
7768 set_fs(fs);
7769 return has_dumped;
7770diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
7771index 588a7aa..a3468b0 100644
7772--- a/arch/x86/ia32/ia32_signal.c
7773+++ b/arch/x86/ia32/ia32_signal.c
7774@@ -167,7 +167,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
7775 }
7776 seg = get_fs();
7777 set_fs(KERNEL_DS);
7778- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
7779+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
7780 set_fs(seg);
7781 if (ret >= 0 && uoss_ptr) {
7782 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
7783@@ -374,7 +374,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
7784 */
7785 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
7786 size_t frame_size,
7787- void **fpstate)
7788+ void __user **fpstate)
7789 {
7790 unsigned long sp;
7791
7792@@ -395,7 +395,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
7793
7794 if (used_math()) {
7795 sp = sp - sig_xstate_ia32_size;
7796- *fpstate = (struct _fpstate_ia32 *) sp;
7797+ *fpstate = (struct _fpstate_ia32 __user *) sp;
7798 if (save_i387_xstate_ia32(*fpstate) < 0)
7799 return (void __user *) -1L;
7800 }
7801@@ -403,7 +403,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
7802 sp -= frame_size;
7803 /* Align the stack pointer according to the i386 ABI,
7804 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
7805- sp = ((sp + 4) & -16ul) - 4;
7806+ sp = ((sp - 12) & -16ul) - 4;
7807 return (void __user *) sp;
7808 }
7809
7810@@ -461,7 +461,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
7811 * These are actually not used anymore, but left because some
7812 * gdb versions depend on them as a marker.
7813 */
7814- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
7815+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
7816 } put_user_catch(err);
7817
7818 if (err)
7819@@ -503,7 +503,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
7820 0xb8,
7821 __NR_ia32_rt_sigreturn,
7822 0x80cd,
7823- 0,
7824+ 0
7825 };
7826
7827 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
7828@@ -533,16 +533,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
7829
7830 if (ka->sa.sa_flags & SA_RESTORER)
7831 restorer = ka->sa.sa_restorer;
7832+ else if (current->mm->context.vdso)
7833+ /* Return stub is in 32bit vsyscall page */
7834+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
7835 else
7836- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
7837- rt_sigreturn);
7838+ restorer = &frame->retcode;
7839 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
7840
7841 /*
7842 * Not actually used anymore, but left because some gdb
7843 * versions need it.
7844 */
7845- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
7846+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
7847 } put_user_catch(err);
7848
7849 if (err)
7850diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
7851index 4edd8eb..29124b4 100644
7852--- a/arch/x86/ia32/ia32entry.S
7853+++ b/arch/x86/ia32/ia32entry.S
7854@@ -13,7 +13,9 @@
7855 #include <asm/thread_info.h>
7856 #include <asm/segment.h>
7857 #include <asm/irqflags.h>
7858+#include <asm/pgtable.h>
7859 #include <linux/linkage.h>
7860+#include <asm/alternative-asm.h>
7861
7862 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
7863 #include <linux/elf-em.h>
7864@@ -93,6 +95,32 @@ ENTRY(native_irq_enable_sysexit)
7865 ENDPROC(native_irq_enable_sysexit)
7866 #endif
7867
7868+ .macro pax_enter_kernel_user
7869+ pax_set_fptr_mask
7870+#ifdef CONFIG_PAX_MEMORY_UDEREF
7871+ call pax_enter_kernel_user
7872+#endif
7873+ .endm
7874+
7875+ .macro pax_exit_kernel_user
7876+#ifdef CONFIG_PAX_MEMORY_UDEREF
7877+ call pax_exit_kernel_user
7878+#endif
7879+#ifdef CONFIG_PAX_RANDKSTACK
7880+ pushq %rax
7881+ pushq %r11
7882+ call pax_randomize_kstack
7883+ popq %r11
7884+ popq %rax
7885+#endif
7886+ .endm
7887+
7888+.macro pax_erase_kstack
7889+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
7890+ call pax_erase_kstack
7891+#endif
7892+.endm
7893+
7894 /*
7895 * 32bit SYSENTER instruction entry.
7896 *
7897@@ -119,12 +147,6 @@ ENTRY(ia32_sysenter_target)
7898 CFI_REGISTER rsp,rbp
7899 SWAPGS_UNSAFE_STACK
7900 movq PER_CPU_VAR(kernel_stack), %rsp
7901- addq $(KERNEL_STACK_OFFSET),%rsp
7902- /*
7903- * No need to follow this irqs on/off section: the syscall
7904- * disabled irqs, here we enable it straight after entry:
7905- */
7906- ENABLE_INTERRUPTS(CLBR_NONE)
7907 movl %ebp,%ebp /* zero extension */
7908 pushq $__USER32_DS
7909 CFI_ADJUST_CFA_OFFSET 8
7910@@ -135,28 +157,42 @@ ENTRY(ia32_sysenter_target)
7911 pushfq
7912 CFI_ADJUST_CFA_OFFSET 8
7913 /*CFI_REL_OFFSET rflags,0*/
7914- movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
7915- CFI_REGISTER rip,r10
7916+ orl $X86_EFLAGS_IF,(%rsp)
7917+ GET_THREAD_INFO(%r11)
7918+ movl TI_sysenter_return(%r11), %r11d
7919+ CFI_REGISTER rip,r11
7920 pushq $__USER32_CS
7921 CFI_ADJUST_CFA_OFFSET 8
7922 /*CFI_REL_OFFSET cs,0*/
7923 movl %eax, %eax
7924- pushq %r10
7925+ pushq %r11
7926 CFI_ADJUST_CFA_OFFSET 8
7927 CFI_REL_OFFSET rip,0
7928 pushq %rax
7929 CFI_ADJUST_CFA_OFFSET 8
7930 cld
7931 SAVE_ARGS 0,0,1
7932+ pax_enter_kernel_user
7933+ /*
7934+ * No need to follow this irqs on/off section: the syscall
7935+ * disabled irqs, here we enable it straight after entry:
7936+ */
7937+ ENABLE_INTERRUPTS(CLBR_NONE)
7938 /* no need to do an access_ok check here because rbp has been
7939 32bit zero extended */
7940+
7941+#ifdef CONFIG_PAX_MEMORY_UDEREF
7942+ mov $PAX_USER_SHADOW_BASE,%r11
7943+ add %r11,%rbp
7944+#endif
7945+
7946 1: movl (%rbp),%ebp
7947 .section __ex_table,"a"
7948 .quad 1b,ia32_badarg
7949 .previous
7950- GET_THREAD_INFO(%r10)
7951- orl $TS_COMPAT,TI_status(%r10)
7952- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
7953+ GET_THREAD_INFO(%r11)
7954+ orl $TS_COMPAT,TI_status(%r11)
7955+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
7956 CFI_REMEMBER_STATE
7957 jnz sysenter_tracesys
7958 cmpq $(IA32_NR_syscalls-1),%rax
7959@@ -166,13 +202,15 @@ sysenter_do_call:
7960 sysenter_dispatch:
7961 call *ia32_sys_call_table(,%rax,8)
7962 movq %rax,RAX-ARGOFFSET(%rsp)
7963- GET_THREAD_INFO(%r10)
7964+ GET_THREAD_INFO(%r11)
7965 DISABLE_INTERRUPTS(CLBR_NONE)
7966 TRACE_IRQS_OFF
7967- testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
7968+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
7969 jnz sysexit_audit
7970 sysexit_from_sys_call:
7971- andl $~TS_COMPAT,TI_status(%r10)
7972+ pax_exit_kernel_user
7973+ pax_erase_kstack
7974+ andl $~TS_COMPAT,TI_status(%r11)
7975 /* clear IF, that popfq doesn't enable interrupts early */
7976 andl $~0x200,EFLAGS-R11(%rsp)
7977 movl RIP-R11(%rsp),%edx /* User %eip */
7978@@ -200,6 +238,9 @@ sysexit_from_sys_call:
7979 movl %eax,%esi /* 2nd arg: syscall number */
7980 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
7981 call audit_syscall_entry
7982+
7983+ pax_erase_kstack
7984+
7985 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
7986 cmpq $(IA32_NR_syscalls-1),%rax
7987 ja ia32_badsys
7988@@ -211,7 +252,7 @@ sysexit_from_sys_call:
7989 .endm
7990
7991 .macro auditsys_exit exit
7992- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
7993+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
7994 jnz ia32_ret_from_sys_call
7995 TRACE_IRQS_ON
7996 sti
7997@@ -221,12 +262,12 @@ sysexit_from_sys_call:
7998 movzbl %al,%edi /* zero-extend that into %edi */
7999 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
8000 call audit_syscall_exit
8001- GET_THREAD_INFO(%r10)
8002+ GET_THREAD_INFO(%r11)
8003 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
8004 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8005 cli
8006 TRACE_IRQS_OFF
8007- testl %edi,TI_flags(%r10)
8008+ testl %edi,TI_flags(%r11)
8009 jz \exit
8010 CLEAR_RREGS -ARGOFFSET
8011 jmp int_with_check
8012@@ -244,7 +285,7 @@ sysexit_audit:
8013
8014 sysenter_tracesys:
8015 #ifdef CONFIG_AUDITSYSCALL
8016- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8017+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8018 jz sysenter_auditsys
8019 #endif
8020 SAVE_REST
8021@@ -252,6 +293,9 @@ sysenter_tracesys:
8022 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8023 movq %rsp,%rdi /* &pt_regs -> arg1 */
8024 call syscall_trace_enter
8025+
8026+ pax_erase_kstack
8027+
8028 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8029 RESTORE_REST
8030 cmpq $(IA32_NR_syscalls-1),%rax
8031@@ -283,19 +327,20 @@ ENDPROC(ia32_sysenter_target)
8032 ENTRY(ia32_cstar_target)
8033 CFI_STARTPROC32 simple
8034 CFI_SIGNAL_FRAME
8035- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8036+ CFI_DEF_CFA rsp,0
8037 CFI_REGISTER rip,rcx
8038 /*CFI_REGISTER rflags,r11*/
8039 SWAPGS_UNSAFE_STACK
8040 movl %esp,%r8d
8041 CFI_REGISTER rsp,r8
8042 movq PER_CPU_VAR(kernel_stack),%rsp
8043+ SAVE_ARGS 8*6,1,1
8044+ pax_enter_kernel_user
8045 /*
8046 * No need to follow this irqs on/off section: the syscall
8047 * disabled irqs and here we enable it straight after entry:
8048 */
8049 ENABLE_INTERRUPTS(CLBR_NONE)
8050- SAVE_ARGS 8,1,1
8051 movl %eax,%eax /* zero extension */
8052 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8053 movq %rcx,RIP-ARGOFFSET(%rsp)
8054@@ -311,13 +356,19 @@ ENTRY(ia32_cstar_target)
8055 /* no need to do an access_ok check here because r8 has been
8056 32bit zero extended */
8057 /* hardware stack frame is complete now */
8058+
8059+#ifdef CONFIG_PAX_MEMORY_UDEREF
8060+ mov $PAX_USER_SHADOW_BASE,%r11
8061+ add %r11,%r8
8062+#endif
8063+
8064 1: movl (%r8),%r9d
8065 .section __ex_table,"a"
8066 .quad 1b,ia32_badarg
8067 .previous
8068- GET_THREAD_INFO(%r10)
8069- orl $TS_COMPAT,TI_status(%r10)
8070- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8071+ GET_THREAD_INFO(%r11)
8072+ orl $TS_COMPAT,TI_status(%r11)
8073+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8074 CFI_REMEMBER_STATE
8075 jnz cstar_tracesys
8076 cmpq $IA32_NR_syscalls-1,%rax
8077@@ -327,13 +378,15 @@ cstar_do_call:
8078 cstar_dispatch:
8079 call *ia32_sys_call_table(,%rax,8)
8080 movq %rax,RAX-ARGOFFSET(%rsp)
8081- GET_THREAD_INFO(%r10)
8082+ GET_THREAD_INFO(%r11)
8083 DISABLE_INTERRUPTS(CLBR_NONE)
8084 TRACE_IRQS_OFF
8085- testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8086+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8087 jnz sysretl_audit
8088 sysretl_from_sys_call:
8089- andl $~TS_COMPAT,TI_status(%r10)
8090+ pax_exit_kernel_user
8091+ pax_erase_kstack
8092+ andl $~TS_COMPAT,TI_status(%r11)
8093 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
8094 movl RIP-ARGOFFSET(%rsp),%ecx
8095 CFI_REGISTER rip,rcx
8096@@ -361,7 +414,7 @@ sysretl_audit:
8097
8098 cstar_tracesys:
8099 #ifdef CONFIG_AUDITSYSCALL
8100- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8101+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8102 jz cstar_auditsys
8103 #endif
8104 xchgl %r9d,%ebp
8105@@ -370,6 +423,9 @@ cstar_tracesys:
8106 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8107 movq %rsp,%rdi /* &pt_regs -> arg1 */
8108 call syscall_trace_enter
8109+
8110+ pax_erase_kstack
8111+
8112 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8113 RESTORE_REST
8114 xchgl %ebp,%r9d
8115@@ -415,11 +471,6 @@ ENTRY(ia32_syscall)
8116 CFI_REL_OFFSET rip,RIP-RIP
8117 PARAVIRT_ADJUST_EXCEPTION_FRAME
8118 SWAPGS
8119- /*
8120- * No need to follow this irqs on/off section: the syscall
8121- * disabled irqs and here we enable it straight after entry:
8122- */
8123- ENABLE_INTERRUPTS(CLBR_NONE)
8124 movl %eax,%eax
8125 pushq %rax
8126 CFI_ADJUST_CFA_OFFSET 8
8127@@ -427,9 +478,15 @@ ENTRY(ia32_syscall)
8128 /* note the registers are not zero extended to the sf.
8129 this could be a problem. */
8130 SAVE_ARGS 0,0,1
8131- GET_THREAD_INFO(%r10)
8132- orl $TS_COMPAT,TI_status(%r10)
8133- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8134+ pax_enter_kernel_user
8135+ /*
8136+ * No need to follow this irqs on/off section: the syscall
8137+ * disabled irqs and here we enable it straight after entry:
8138+ */
8139+ ENABLE_INTERRUPTS(CLBR_NONE)
8140+ GET_THREAD_INFO(%r11)
8141+ orl $TS_COMPAT,TI_status(%r11)
8142+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8143 jnz ia32_tracesys
8144 cmpq $(IA32_NR_syscalls-1),%rax
8145 ja ia32_badsys
8146@@ -448,6 +505,9 @@ ia32_tracesys:
8147 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8148 movq %rsp,%rdi /* &pt_regs -> arg1 */
8149 call syscall_trace_enter
8150+
8151+ pax_erase_kstack
8152+
8153 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8154 RESTORE_REST
8155 cmpq $(IA32_NR_syscalls-1),%rax
8156@@ -462,6 +522,7 @@ ia32_badsys:
8157
8158 quiet_ni_syscall:
8159 movq $-ENOSYS,%rax
8160+ pax_force_retaddr
8161 ret
8162 CFI_ENDPROC
8163
8164diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8165index 016218c..47ccbdd 100644
8166--- a/arch/x86/ia32/sys_ia32.c
8167+++ b/arch/x86/ia32/sys_ia32.c
8168@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8169 */
8170 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8171 {
8172- typeof(ubuf->st_uid) uid = 0;
8173- typeof(ubuf->st_gid) gid = 0;
8174+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8175+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8176 SET_UID(uid, stat->uid);
8177 SET_GID(gid, stat->gid);
8178 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8179@@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8180 }
8181 set_fs(KERNEL_DS);
8182 ret = sys_rt_sigprocmask(how,
8183- set ? (sigset_t __user *)&s : NULL,
8184- oset ? (sigset_t __user *)&s : NULL,
8185+ set ? (sigset_t __force_user *)&s : NULL,
8186+ oset ? (sigset_t __force_user *)&s : NULL,
8187 sigsetsize);
8188 set_fs(old_fs);
8189 if (ret)
8190@@ -371,7 +371,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8191 mm_segment_t old_fs = get_fs();
8192
8193 set_fs(KERNEL_DS);
8194- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8195+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8196 set_fs(old_fs);
8197 if (put_compat_timespec(&t, interval))
8198 return -EFAULT;
8199@@ -387,7 +387,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8200 mm_segment_t old_fs = get_fs();
8201
8202 set_fs(KERNEL_DS);
8203- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8204+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8205 set_fs(old_fs);
8206 if (!ret) {
8207 switch (_NSIG_WORDS) {
8208@@ -412,7 +412,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8209 if (copy_siginfo_from_user32(&info, uinfo))
8210 return -EFAULT;
8211 set_fs(KERNEL_DS);
8212- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8213+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8214 set_fs(old_fs);
8215 return ret;
8216 }
8217@@ -513,7 +513,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8218 return -EFAULT;
8219
8220 set_fs(KERNEL_DS);
8221- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8222+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8223 count);
8224 set_fs(old_fs);
8225
8226diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8227index e2077d3..b7a8919 100644
8228--- a/arch/x86/include/asm/alternative-asm.h
8229+++ b/arch/x86/include/asm/alternative-asm.h
8230@@ -8,10 +8,10 @@
8231
8232 #ifdef CONFIG_SMP
8233 .macro LOCK_PREFIX
8234-1: lock
8235+672: lock
8236 .section .smp_locks,"a"
8237 .align 4
8238- X86_ALIGN 1b
8239+ X86_ALIGN 672b
8240 .previous
8241 .endm
8242 #else
8243@@ -19,4 +19,43 @@
8244 .endm
8245 #endif
8246
8247+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
8248+ .macro pax_force_retaddr_bts rip=0
8249+ btsq $63,\rip(%rsp)
8250+ .endm
8251+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8252+ .macro pax_force_retaddr rip=0, reload=0
8253+ btsq $63,\rip(%rsp)
8254+ .endm
8255+ .macro pax_force_fptr ptr
8256+ btsq $63,\ptr
8257+ .endm
8258+ .macro pax_set_fptr_mask
8259+ .endm
8260+#endif
8261+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8262+ .macro pax_force_retaddr rip=0, reload=0
8263+ .if \reload
8264+ pax_set_fptr_mask
8265+ .endif
8266+ orq %r10,\rip(%rsp)
8267+ .endm
8268+ .macro pax_force_fptr ptr
8269+ orq %r10,\ptr
8270+ .endm
8271+ .macro pax_set_fptr_mask
8272+ movabs $0x8000000000000000,%r10
8273+ .endm
8274+#endif
8275+#else
8276+ .macro pax_force_retaddr rip=0, reload=0
8277+ .endm
8278+ .macro pax_force_fptr ptr
8279+ .endm
8280+ .macro pax_force_retaddr_bts rip=0
8281+ .endm
8282+ .macro pax_set_fptr_mask
8283+ .endm
8284+#endif
8285+
8286 #endif /* __ASSEMBLY__ */
8287diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8288index c240efc..fdfadf3 100644
8289--- a/arch/x86/include/asm/alternative.h
8290+++ b/arch/x86/include/asm/alternative.h
8291@@ -85,7 +85,7 @@ static inline void alternatives_smp_switch(int smp) {}
8292 " .byte 662b-661b\n" /* sourcelen */ \
8293 " .byte 664f-663f\n" /* replacementlen */ \
8294 ".previous\n" \
8295- ".section .altinstr_replacement, \"ax\"\n" \
8296+ ".section .altinstr_replacement, \"a\"\n" \
8297 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8298 ".previous"
8299
8300diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8301index 474d80d..1f97d58 100644
8302--- a/arch/x86/include/asm/apic.h
8303+++ b/arch/x86/include/asm/apic.h
8304@@ -46,7 +46,7 @@ static inline void generic_apic_probe(void)
8305
8306 #ifdef CONFIG_X86_LOCAL_APIC
8307
8308-extern unsigned int apic_verbosity;
8309+extern int apic_verbosity;
8310 extern int local_apic_timer_c2_ok;
8311
8312 extern int disable_apic;
8313diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8314index 20370c6..a2eb9b0 100644
8315--- a/arch/x86/include/asm/apm.h
8316+++ b/arch/x86/include/asm/apm.h
8317@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
8318 __asm__ __volatile__(APM_DO_ZERO_SEGS
8319 "pushl %%edi\n\t"
8320 "pushl %%ebp\n\t"
8321- "lcall *%%cs:apm_bios_entry\n\t"
8322+ "lcall *%%ss:apm_bios_entry\n\t"
8323 "setc %%al\n\t"
8324 "popl %%ebp\n\t"
8325 "popl %%edi\n\t"
8326@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
8327 __asm__ __volatile__(APM_DO_ZERO_SEGS
8328 "pushl %%edi\n\t"
8329 "pushl %%ebp\n\t"
8330- "lcall *%%cs:apm_bios_entry\n\t"
8331+ "lcall *%%ss:apm_bios_entry\n\t"
8332 "setc %%bl\n\t"
8333 "popl %%ebp\n\t"
8334 "popl %%edi\n\t"
8335diff --git a/arch/x86/include/asm/atomic_32.h b/arch/x86/include/asm/atomic_32.h
8336index dc5a667..939040c 100644
8337--- a/arch/x86/include/asm/atomic_32.h
8338+++ b/arch/x86/include/asm/atomic_32.h
8339@@ -25,6 +25,17 @@ static inline int atomic_read(const atomic_t *v)
8340 }
8341
8342 /**
8343+ * atomic_read_unchecked - read atomic variable
8344+ * @v: pointer of type atomic_unchecked_t
8345+ *
8346+ * Atomically reads the value of @v.
8347+ */
8348+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8349+{
8350+ return v->counter;
8351+}
8352+
8353+/**
8354 * atomic_set - set atomic variable
8355 * @v: pointer of type atomic_t
8356 * @i: required value
8357@@ -37,6 +48,18 @@ static inline void atomic_set(atomic_t *v, int i)
8358 }
8359
8360 /**
8361+ * atomic_set_unchecked - set atomic variable
8362+ * @v: pointer of type atomic_unchecked_t
8363+ * @i: required value
8364+ *
8365+ * Atomically sets the value of @v to @i.
8366+ */
8367+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8368+{
8369+ v->counter = i;
8370+}
8371+
8372+/**
8373 * atomic_add - add integer to atomic variable
8374 * @i: integer value to add
8375 * @v: pointer of type atomic_t
8376@@ -45,7 +68,29 @@ static inline void atomic_set(atomic_t *v, int i)
8377 */
8378 static inline void atomic_add(int i, atomic_t *v)
8379 {
8380- asm volatile(LOCK_PREFIX "addl %1,%0"
8381+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8382+
8383+#ifdef CONFIG_PAX_REFCOUNT
8384+ "jno 0f\n"
8385+ LOCK_PREFIX "subl %1,%0\n"
8386+ "int $4\n0:\n"
8387+ _ASM_EXTABLE(0b, 0b)
8388+#endif
8389+
8390+ : "+m" (v->counter)
8391+ : "ir" (i));
8392+}
8393+
8394+/**
8395+ * atomic_add_unchecked - add integer to atomic variable
8396+ * @i: integer value to add
8397+ * @v: pointer of type atomic_unchecked_t
8398+ *
8399+ * Atomically adds @i to @v.
8400+ */
8401+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8402+{
8403+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8404 : "+m" (v->counter)
8405 : "ir" (i));
8406 }
8407@@ -59,7 +104,29 @@ static inline void atomic_add(int i, atomic_t *v)
8408 */
8409 static inline void atomic_sub(int i, atomic_t *v)
8410 {
8411- asm volatile(LOCK_PREFIX "subl %1,%0"
8412+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8413+
8414+#ifdef CONFIG_PAX_REFCOUNT
8415+ "jno 0f\n"
8416+ LOCK_PREFIX "addl %1,%0\n"
8417+ "int $4\n0:\n"
8418+ _ASM_EXTABLE(0b, 0b)
8419+#endif
8420+
8421+ : "+m" (v->counter)
8422+ : "ir" (i));
8423+}
8424+
8425+/**
8426+ * atomic_sub_unchecked - subtract integer from atomic variable
8427+ * @i: integer value to subtract
8428+ * @v: pointer of type atomic_unchecked_t
8429+ *
8430+ * Atomically subtracts @i from @v.
8431+ */
8432+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8433+{
8434+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8435 : "+m" (v->counter)
8436 : "ir" (i));
8437 }
8438@@ -77,7 +144,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8439 {
8440 unsigned char c;
8441
8442- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8443+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
8444+
8445+#ifdef CONFIG_PAX_REFCOUNT
8446+ "jno 0f\n"
8447+ LOCK_PREFIX "addl %2,%0\n"
8448+ "int $4\n0:\n"
8449+ _ASM_EXTABLE(0b, 0b)
8450+#endif
8451+
8452+ "sete %1\n"
8453 : "+m" (v->counter), "=qm" (c)
8454 : "ir" (i) : "memory");
8455 return c;
8456@@ -91,7 +167,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8457 */
8458 static inline void atomic_inc(atomic_t *v)
8459 {
8460- asm volatile(LOCK_PREFIX "incl %0"
8461+ asm volatile(LOCK_PREFIX "incl %0\n"
8462+
8463+#ifdef CONFIG_PAX_REFCOUNT
8464+ "jno 0f\n"
8465+ LOCK_PREFIX "decl %0\n"
8466+ "int $4\n0:\n"
8467+ _ASM_EXTABLE(0b, 0b)
8468+#endif
8469+
8470+ : "+m" (v->counter));
8471+}
8472+
8473+/**
8474+ * atomic_inc_unchecked - increment atomic variable
8475+ * @v: pointer of type atomic_unchecked_t
8476+ *
8477+ * Atomically increments @v by 1.
8478+ */
8479+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8480+{
8481+ asm volatile(LOCK_PREFIX "incl %0\n"
8482 : "+m" (v->counter));
8483 }
8484
8485@@ -103,7 +199,27 @@ static inline void atomic_inc(atomic_t *v)
8486 */
8487 static inline void atomic_dec(atomic_t *v)
8488 {
8489- asm volatile(LOCK_PREFIX "decl %0"
8490+ asm volatile(LOCK_PREFIX "decl %0\n"
8491+
8492+#ifdef CONFIG_PAX_REFCOUNT
8493+ "jno 0f\n"
8494+ LOCK_PREFIX "incl %0\n"
8495+ "int $4\n0:\n"
8496+ _ASM_EXTABLE(0b, 0b)
8497+#endif
8498+
8499+ : "+m" (v->counter));
8500+}
8501+
8502+/**
8503+ * atomic_dec_unchecked - decrement atomic variable
8504+ * @v: pointer of type atomic_unchecked_t
8505+ *
8506+ * Atomically decrements @v by 1.
8507+ */
8508+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8509+{
8510+ asm volatile(LOCK_PREFIX "decl %0\n"
8511 : "+m" (v->counter));
8512 }
8513
8514@@ -119,7 +235,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
8515 {
8516 unsigned char c;
8517
8518- asm volatile(LOCK_PREFIX "decl %0; sete %1"
8519+ asm volatile(LOCK_PREFIX "decl %0\n"
8520+
8521+#ifdef CONFIG_PAX_REFCOUNT
8522+ "jno 0f\n"
8523+ LOCK_PREFIX "incl %0\n"
8524+ "int $4\n0:\n"
8525+ _ASM_EXTABLE(0b, 0b)
8526+#endif
8527+
8528+ "sete %1\n"
8529 : "+m" (v->counter), "=qm" (c)
8530 : : "memory");
8531 return c != 0;
8532@@ -137,7 +262,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
8533 {
8534 unsigned char c;
8535
8536- asm volatile(LOCK_PREFIX "incl %0; sete %1"
8537+ asm volatile(LOCK_PREFIX "incl %0\n"
8538+
8539+#ifdef CONFIG_PAX_REFCOUNT
8540+ "jno 0f\n"
8541+ LOCK_PREFIX "decl %0\n"
8542+ "into\n0:\n"
8543+ _ASM_EXTABLE(0b, 0b)
8544+#endif
8545+
8546+ "sete %1\n"
8547+ : "+m" (v->counter), "=qm" (c)
8548+ : : "memory");
8549+ return c != 0;
8550+}
8551+
8552+/**
8553+ * atomic_inc_and_test_unchecked - increment and test
8554+ * @v: pointer of type atomic_unchecked_t
8555+ *
8556+ * Atomically increments @v by 1
8557+ * and returns true if the result is zero, or false for all
8558+ * other cases.
8559+ */
8560+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8561+{
8562+ unsigned char c;
8563+
8564+ asm volatile(LOCK_PREFIX "incl %0\n"
8565+ "sete %1\n"
8566 : "+m" (v->counter), "=qm" (c)
8567 : : "memory");
8568 return c != 0;
8569@@ -156,7 +309,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
8570 {
8571 unsigned char c;
8572
8573- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8574+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
8575+
8576+#ifdef CONFIG_PAX_REFCOUNT
8577+ "jno 0f\n"
8578+ LOCK_PREFIX "subl %2,%0\n"
8579+ "int $4\n0:\n"
8580+ _ASM_EXTABLE(0b, 0b)
8581+#endif
8582+
8583+ "sets %1\n"
8584 : "+m" (v->counter), "=qm" (c)
8585 : "ir" (i) : "memory");
8586 return c;
8587@@ -179,7 +341,15 @@ static inline int atomic_add_return(int i, atomic_t *v)
8588 #endif
8589 /* Modern 486+ processor */
8590 __i = i;
8591- asm volatile(LOCK_PREFIX "xaddl %0, %1"
8592+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
8593+
8594+#ifdef CONFIG_PAX_REFCOUNT
8595+ "jno 0f\n"
8596+ "movl %0, %1\n"
8597+ "int $4\n0:\n"
8598+ _ASM_EXTABLE(0b, 0b)
8599+#endif
8600+
8601 : "+r" (i), "+m" (v->counter)
8602 : : "memory");
8603 return i + __i;
8604@@ -195,6 +365,38 @@ no_xadd: /* Legacy 386 processor */
8605 }
8606
8607 /**
8608+ * atomic_add_return_unchecked - add integer and return
8609+ * @v: pointer of type atomic_unchecked_t
8610+ * @i: integer value to add
8611+ *
8612+ * Atomically adds @i to @v and returns @i + @v
8613+ */
8614+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8615+{
8616+ int __i;
8617+#ifdef CONFIG_M386
8618+ unsigned long flags;
8619+ if (unlikely(boot_cpu_data.x86 <= 3))
8620+ goto no_xadd;
8621+#endif
8622+ /* Modern 486+ processor */
8623+ __i = i;
8624+ asm volatile(LOCK_PREFIX "xaddl %0, %1"
8625+ : "+r" (i), "+m" (v->counter)
8626+ : : "memory");
8627+ return i + __i;
8628+
8629+#ifdef CONFIG_M386
8630+no_xadd: /* Legacy 386 processor */
8631+ local_irq_save(flags);
8632+ __i = atomic_read_unchecked(v);
8633+ atomic_set_unchecked(v, i + __i);
8634+ local_irq_restore(flags);
8635+ return i + __i;
8636+#endif
8637+}
8638+
8639+/**
8640 * atomic_sub_return - subtract integer and return
8641 * @v: pointer of type atomic_t
8642 * @i: integer value to subtract
8643@@ -211,11 +413,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8644 return cmpxchg(&v->counter, old, new);
8645 }
8646
8647+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8648+{
8649+ return cmpxchg(&v->counter, old, new);
8650+}
8651+
8652 static inline int atomic_xchg(atomic_t *v, int new)
8653 {
8654 return xchg(&v->counter, new);
8655 }
8656
8657+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8658+{
8659+ return xchg(&v->counter, new);
8660+}
8661+
8662 /**
8663 * atomic_add_unless - add unless the number is already a given value
8664 * @v: pointer of type atomic_t
8665@@ -227,22 +439,39 @@ static inline int atomic_xchg(atomic_t *v, int new)
8666 */
8667 static inline int atomic_add_unless(atomic_t *v, int a, int u)
8668 {
8669- int c, old;
8670+ int c, old, new;
8671 c = atomic_read(v);
8672 for (;;) {
8673- if (unlikely(c == (u)))
8674+ if (unlikely(c == u))
8675 break;
8676- old = atomic_cmpxchg((v), c, c + (a));
8677+
8678+ asm volatile("addl %2,%0\n"
8679+
8680+#ifdef CONFIG_PAX_REFCOUNT
8681+ "jno 0f\n"
8682+ "subl %2,%0\n"
8683+ "int $4\n0:\n"
8684+ _ASM_EXTABLE(0b, 0b)
8685+#endif
8686+
8687+ : "=r" (new)
8688+ : "0" (c), "ir" (a));
8689+
8690+ old = atomic_cmpxchg(v, c, new);
8691 if (likely(old == c))
8692 break;
8693 c = old;
8694 }
8695- return c != (u);
8696+ return c != u;
8697 }
8698
8699 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
8700
8701 #define atomic_inc_return(v) (atomic_add_return(1, v))
8702+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8703+{
8704+ return atomic_add_return_unchecked(1, v);
8705+}
8706 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8707
8708 /* These are x86-specific, used by some header files */
8709@@ -266,9 +495,18 @@ typedef struct {
8710 u64 __aligned(8) counter;
8711 } atomic64_t;
8712
8713+#ifdef CONFIG_PAX_REFCOUNT
8714+typedef struct {
8715+ u64 __aligned(8) counter;
8716+} atomic64_unchecked_t;
8717+#else
8718+typedef atomic64_t atomic64_unchecked_t;
8719+#endif
8720+
8721 #define ATOMIC64_INIT(val) { (val) }
8722
8723 extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
8724+extern u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val);
8725
8726 /**
8727 * atomic64_xchg - xchg atomic64 variable
8728@@ -279,6 +517,7 @@ extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
8729 * the old value.
8730 */
8731 extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
8732+extern u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
8733
8734 /**
8735 * atomic64_set - set atomic64 variable
8736@@ -290,6 +529,15 @@ extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
8737 extern void atomic64_set(atomic64_t *ptr, u64 new_val);
8738
8739 /**
8740+ * atomic64_unchecked_set - set atomic64 variable
8741+ * @ptr: pointer to type atomic64_unchecked_t
8742+ * @new_val: value to assign
8743+ *
8744+ * Atomically sets the value of @ptr to @new_val.
8745+ */
8746+extern void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
8747+
8748+/**
8749 * atomic64_read - read atomic64 variable
8750 * @ptr: pointer to type atomic64_t
8751 *
8752@@ -317,7 +565,33 @@ static inline u64 atomic64_read(atomic64_t *ptr)
8753 return res;
8754 }
8755
8756-extern u64 atomic64_read(atomic64_t *ptr);
8757+/**
8758+ * atomic64_read_unchecked - read atomic64 variable
8759+ * @ptr: pointer to type atomic64_unchecked_t
8760+ *
8761+ * Atomically reads the value of @ptr and returns it.
8762+ */
8763+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *ptr)
8764+{
8765+ u64 res;
8766+
8767+ /*
8768+ * Note, we inline this atomic64_unchecked_t primitive because
8769+ * it only clobbers EAX/EDX and leaves the others
8770+ * untouched. We also (somewhat subtly) rely on the
8771+ * fact that cmpxchg8b returns the current 64-bit value
8772+ * of the memory location we are touching:
8773+ */
8774+ asm volatile(
8775+ "mov %%ebx, %%eax\n\t"
8776+ "mov %%ecx, %%edx\n\t"
8777+ LOCK_PREFIX "cmpxchg8b %1\n"
8778+ : "=&A" (res)
8779+ : "m" (*ptr)
8780+ );
8781+
8782+ return res;
8783+}
8784
8785 /**
8786 * atomic64_add_return - add and return
8787@@ -332,8 +606,11 @@ extern u64 atomic64_add_return(u64 delta, atomic64_t *ptr);
8788 * Other variants with different arithmetic operators:
8789 */
8790 extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr);
8791+extern u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8792 extern u64 atomic64_inc_return(atomic64_t *ptr);
8793+extern u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr);
8794 extern u64 atomic64_dec_return(atomic64_t *ptr);
8795+extern u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr);
8796
8797 /**
8798 * atomic64_add - add integer to atomic64 variable
8799@@ -345,6 +622,15 @@ extern u64 atomic64_dec_return(atomic64_t *ptr);
8800 extern void atomic64_add(u64 delta, atomic64_t *ptr);
8801
8802 /**
8803+ * atomic64_add_unchecked - add integer to atomic64 variable
8804+ * @delta: integer value to add
8805+ * @ptr: pointer to type atomic64_unchecked_t
8806+ *
8807+ * Atomically adds @delta to @ptr.
8808+ */
8809+extern void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8810+
8811+/**
8812 * atomic64_sub - subtract the atomic64 variable
8813 * @delta: integer value to subtract
8814 * @ptr: pointer to type atomic64_t
8815@@ -354,6 +640,15 @@ extern void atomic64_add(u64 delta, atomic64_t *ptr);
8816 extern void atomic64_sub(u64 delta, atomic64_t *ptr);
8817
8818 /**
8819+ * atomic64_sub_unchecked - subtract the atomic64 variable
8820+ * @delta: integer value to subtract
8821+ * @ptr: pointer to type atomic64_unchecked_t
8822+ *
8823+ * Atomically subtracts @delta from @ptr.
8824+ */
8825+extern void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8826+
8827+/**
8828 * atomic64_sub_and_test - subtract value from variable and test result
8829 * @delta: integer value to subtract
8830 * @ptr: pointer to type atomic64_t
8831@@ -373,6 +668,14 @@ extern int atomic64_sub_and_test(u64 delta, atomic64_t *ptr);
8832 extern void atomic64_inc(atomic64_t *ptr);
8833
8834 /**
8835+ * atomic64_inc_unchecked - increment atomic64 variable
8836+ * @ptr: pointer to type atomic64_unchecked_t
8837+ *
8838+ * Atomically increments @ptr by 1.
8839+ */
8840+extern void atomic64_inc_unchecked(atomic64_unchecked_t *ptr);
8841+
8842+/**
8843 * atomic64_dec - decrement atomic64 variable
8844 * @ptr: pointer to type atomic64_t
8845 *
8846@@ -381,6 +684,14 @@ extern void atomic64_inc(atomic64_t *ptr);
8847 extern void atomic64_dec(atomic64_t *ptr);
8848
8849 /**
8850+ * atomic64_dec_unchecked - decrement atomic64 variable
8851+ * @ptr: pointer to type atomic64_unchecked_t
8852+ *
8853+ * Atomically decrements @ptr by 1.
8854+ */
8855+extern void atomic64_dec_unchecked(atomic64_unchecked_t *ptr);
8856+
8857+/**
8858 * atomic64_dec_and_test - decrement and test
8859 * @ptr: pointer to type atomic64_t
8860 *
8861diff --git a/arch/x86/include/asm/atomic_64.h b/arch/x86/include/asm/atomic_64.h
8862index d605dc2..fafd7bd 100644
8863--- a/arch/x86/include/asm/atomic_64.h
8864+++ b/arch/x86/include/asm/atomic_64.h
8865@@ -24,6 +24,17 @@ static inline int atomic_read(const atomic_t *v)
8866 }
8867
8868 /**
8869+ * atomic_read_unchecked - read atomic variable
8870+ * @v: pointer of type atomic_unchecked_t
8871+ *
8872+ * Atomically reads the value of @v.
8873+ */
8874+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8875+{
8876+ return v->counter;
8877+}
8878+
8879+/**
8880 * atomic_set - set atomic variable
8881 * @v: pointer of type atomic_t
8882 * @i: required value
8883@@ -36,6 +47,18 @@ static inline void atomic_set(atomic_t *v, int i)
8884 }
8885
8886 /**
8887+ * atomic_set_unchecked - set atomic variable
8888+ * @v: pointer of type atomic_unchecked_t
8889+ * @i: required value
8890+ *
8891+ * Atomically sets the value of @v to @i.
8892+ */
8893+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8894+{
8895+ v->counter = i;
8896+}
8897+
8898+/**
8899 * atomic_add - add integer to atomic variable
8900 * @i: integer value to add
8901 * @v: pointer of type atomic_t
8902@@ -44,7 +67,29 @@ static inline void atomic_set(atomic_t *v, int i)
8903 */
8904 static inline void atomic_add(int i, atomic_t *v)
8905 {
8906- asm volatile(LOCK_PREFIX "addl %1,%0"
8907+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8908+
8909+#ifdef CONFIG_PAX_REFCOUNT
8910+ "jno 0f\n"
8911+ LOCK_PREFIX "subl %1,%0\n"
8912+ "int $4\n0:\n"
8913+ _ASM_EXTABLE(0b, 0b)
8914+#endif
8915+
8916+ : "=m" (v->counter)
8917+ : "ir" (i), "m" (v->counter));
8918+}
8919+
8920+/**
8921+ * atomic_add_unchecked - add integer to atomic variable
8922+ * @i: integer value to add
8923+ * @v: pointer of type atomic_unchecked_t
8924+ *
8925+ * Atomically adds @i to @v.
8926+ */
8927+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8928+{
8929+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8930 : "=m" (v->counter)
8931 : "ir" (i), "m" (v->counter));
8932 }
8933@@ -58,7 +103,29 @@ static inline void atomic_add(int i, atomic_t *v)
8934 */
8935 static inline void atomic_sub(int i, atomic_t *v)
8936 {
8937- asm volatile(LOCK_PREFIX "subl %1,%0"
8938+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8939+
8940+#ifdef CONFIG_PAX_REFCOUNT
8941+ "jno 0f\n"
8942+ LOCK_PREFIX "addl %1,%0\n"
8943+ "int $4\n0:\n"
8944+ _ASM_EXTABLE(0b, 0b)
8945+#endif
8946+
8947+ : "=m" (v->counter)
8948+ : "ir" (i), "m" (v->counter));
8949+}
8950+
8951+/**
8952+ * atomic_sub_unchecked - subtract the atomic variable
8953+ * @i: integer value to subtract
8954+ * @v: pointer of type atomic_unchecked_t
8955+ *
8956+ * Atomically subtracts @i from @v.
8957+ */
8958+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8959+{
8960+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8961 : "=m" (v->counter)
8962 : "ir" (i), "m" (v->counter));
8963 }
8964@@ -76,7 +143,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8965 {
8966 unsigned char c;
8967
8968- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8969+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
8970+
8971+#ifdef CONFIG_PAX_REFCOUNT
8972+ "jno 0f\n"
8973+ LOCK_PREFIX "addl %2,%0\n"
8974+ "int $4\n0:\n"
8975+ _ASM_EXTABLE(0b, 0b)
8976+#endif
8977+
8978+ "sete %1\n"
8979 : "=m" (v->counter), "=qm" (c)
8980 : "ir" (i), "m" (v->counter) : "memory");
8981 return c;
8982@@ -90,7 +166,28 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8983 */
8984 static inline void atomic_inc(atomic_t *v)
8985 {
8986- asm volatile(LOCK_PREFIX "incl %0"
8987+ asm volatile(LOCK_PREFIX "incl %0\n"
8988+
8989+#ifdef CONFIG_PAX_REFCOUNT
8990+ "jno 0f\n"
8991+ LOCK_PREFIX "decl %0\n"
8992+ "int $4\n0:\n"
8993+ _ASM_EXTABLE(0b, 0b)
8994+#endif
8995+
8996+ : "=m" (v->counter)
8997+ : "m" (v->counter));
8998+}
8999+
9000+/**
9001+ * atomic_inc_unchecked - increment atomic variable
9002+ * @v: pointer of type atomic_unchecked_t
9003+ *
9004+ * Atomically increments @v by 1.
9005+ */
9006+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9007+{
9008+ asm volatile(LOCK_PREFIX "incl %0\n"
9009 : "=m" (v->counter)
9010 : "m" (v->counter));
9011 }
9012@@ -103,7 +200,28 @@ static inline void atomic_inc(atomic_t *v)
9013 */
9014 static inline void atomic_dec(atomic_t *v)
9015 {
9016- asm volatile(LOCK_PREFIX "decl %0"
9017+ asm volatile(LOCK_PREFIX "decl %0\n"
9018+
9019+#ifdef CONFIG_PAX_REFCOUNT
9020+ "jno 0f\n"
9021+ LOCK_PREFIX "incl %0\n"
9022+ "int $4\n0:\n"
9023+ _ASM_EXTABLE(0b, 0b)
9024+#endif
9025+
9026+ : "=m" (v->counter)
9027+ : "m" (v->counter));
9028+}
9029+
9030+/**
9031+ * atomic_dec_unchecked - decrement atomic variable
9032+ * @v: pointer of type atomic_unchecked_t
9033+ *
9034+ * Atomically decrements @v by 1.
9035+ */
9036+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9037+{
9038+ asm volatile(LOCK_PREFIX "decl %0\n"
9039 : "=m" (v->counter)
9040 : "m" (v->counter));
9041 }
9042@@ -120,7 +238,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9043 {
9044 unsigned char c;
9045
9046- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9047+ asm volatile(LOCK_PREFIX "decl %0\n"
9048+
9049+#ifdef CONFIG_PAX_REFCOUNT
9050+ "jno 0f\n"
9051+ LOCK_PREFIX "incl %0\n"
9052+ "int $4\n0:\n"
9053+ _ASM_EXTABLE(0b, 0b)
9054+#endif
9055+
9056+ "sete %1\n"
9057 : "=m" (v->counter), "=qm" (c)
9058 : "m" (v->counter) : "memory");
9059 return c != 0;
9060@@ -138,7 +265,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9061 {
9062 unsigned char c;
9063
9064- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9065+ asm volatile(LOCK_PREFIX "incl %0\n"
9066+
9067+#ifdef CONFIG_PAX_REFCOUNT
9068+ "jno 0f\n"
9069+ LOCK_PREFIX "decl %0\n"
9070+ "int $4\n0:\n"
9071+ _ASM_EXTABLE(0b, 0b)
9072+#endif
9073+
9074+ "sete %1\n"
9075+ : "=m" (v->counter), "=qm" (c)
9076+ : "m" (v->counter) : "memory");
9077+ return c != 0;
9078+}
9079+
9080+/**
9081+ * atomic_inc_and_test_unchecked - increment and test
9082+ * @v: pointer of type atomic_unchecked_t
9083+ *
9084+ * Atomically increments @v by 1
9085+ * and returns true if the result is zero, or false for all
9086+ * other cases.
9087+ */
9088+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9089+{
9090+ unsigned char c;
9091+
9092+ asm volatile(LOCK_PREFIX "incl %0\n"
9093+ "sete %1\n"
9094 : "=m" (v->counter), "=qm" (c)
9095 : "m" (v->counter) : "memory");
9096 return c != 0;
9097@@ -157,7 +312,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9098 {
9099 unsigned char c;
9100
9101- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9102+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9103+
9104+#ifdef CONFIG_PAX_REFCOUNT
9105+ "jno 0f\n"
9106+ LOCK_PREFIX "subl %2,%0\n"
9107+ "int $4\n0:\n"
9108+ _ASM_EXTABLE(0b, 0b)
9109+#endif
9110+
9111+ "sets %1\n"
9112 : "=m" (v->counter), "=qm" (c)
9113 : "ir" (i), "m" (v->counter) : "memory");
9114 return c;
9115@@ -173,7 +337,31 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9116 static inline int atomic_add_return(int i, atomic_t *v)
9117 {
9118 int __i = i;
9119- asm volatile(LOCK_PREFIX "xaddl %0, %1"
9120+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
9121+
9122+#ifdef CONFIG_PAX_REFCOUNT
9123+ "jno 0f\n"
9124+ "movl %0, %1\n"
9125+ "int $4\n0:\n"
9126+ _ASM_EXTABLE(0b, 0b)
9127+#endif
9128+
9129+ : "+r" (i), "+m" (v->counter)
9130+ : : "memory");
9131+ return i + __i;
9132+}
9133+
9134+/**
9135+ * atomic_add_return_unchecked - add and return
9136+ * @i: integer value to add
9137+ * @v: pointer of type atomic_unchecked_t
9138+ *
9139+ * Atomically adds @i to @v and returns @i + @v
9140+ */
9141+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9142+{
9143+ int __i = i;
9144+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
9145 : "+r" (i), "+m" (v->counter)
9146 : : "memory");
9147 return i + __i;
9148@@ -185,6 +373,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9149 }
9150
9151 #define atomic_inc_return(v) (atomic_add_return(1, v))
9152+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9153+{
9154+ return atomic_add_return_unchecked(1, v);
9155+}
9156 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9157
9158 /* The 64-bit atomic type */
9159@@ -204,6 +396,18 @@ static inline long atomic64_read(const atomic64_t *v)
9160 }
9161
9162 /**
9163+ * atomic64_read_unchecked - read atomic64 variable
9164+ * @v: pointer of type atomic64_unchecked_t
9165+ *
9166+ * Atomically reads the value of @v.
9167+ * Doesn't imply a read memory barrier.
9168+ */
9169+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9170+{
9171+ return v->counter;
9172+}
9173+
9174+/**
9175 * atomic64_set - set atomic64 variable
9176 * @v: pointer to type atomic64_t
9177 * @i: required value
9178@@ -216,6 +420,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9179 }
9180
9181 /**
9182+ * atomic64_set_unchecked - set atomic64 variable
9183+ * @v: pointer to type atomic64_unchecked_t
9184+ * @i: required value
9185+ *
9186+ * Atomically sets the value of @v to @i.
9187+ */
9188+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9189+{
9190+ v->counter = i;
9191+}
9192+
9193+/**
9194 * atomic64_add - add integer to atomic64 variable
9195 * @i: integer value to add
9196 * @v: pointer to type atomic64_t
9197@@ -224,6 +440,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9198 */
9199 static inline void atomic64_add(long i, atomic64_t *v)
9200 {
9201+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9202+
9203+#ifdef CONFIG_PAX_REFCOUNT
9204+ "jno 0f\n"
9205+ LOCK_PREFIX "subq %1,%0\n"
9206+ "int $4\n0:\n"
9207+ _ASM_EXTABLE(0b, 0b)
9208+#endif
9209+
9210+ : "=m" (v->counter)
9211+ : "er" (i), "m" (v->counter));
9212+}
9213+
9214+/**
9215+ * atomic64_add_unchecked - add integer to atomic64 variable
9216+ * @i: integer value to add
9217+ * @v: pointer to type atomic64_unchecked_t
9218+ *
9219+ * Atomically adds @i to @v.
9220+ */
9221+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9222+{
9223 asm volatile(LOCK_PREFIX "addq %1,%0"
9224 : "=m" (v->counter)
9225 : "er" (i), "m" (v->counter));
9226@@ -238,7 +476,15 @@ static inline void atomic64_add(long i, atomic64_t *v)
9227 */
9228 static inline void atomic64_sub(long i, atomic64_t *v)
9229 {
9230- asm volatile(LOCK_PREFIX "subq %1,%0"
9231+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9232+
9233+#ifdef CONFIG_PAX_REFCOUNT
9234+ "jno 0f\n"
9235+ LOCK_PREFIX "addq %1,%0\n"
9236+ "int $4\n0:\n"
9237+ _ASM_EXTABLE(0b, 0b)
9238+#endif
9239+
9240 : "=m" (v->counter)
9241 : "er" (i), "m" (v->counter));
9242 }
9243@@ -256,7 +502,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9244 {
9245 unsigned char c;
9246
9247- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9248+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9249+
9250+#ifdef CONFIG_PAX_REFCOUNT
9251+ "jno 0f\n"
9252+ LOCK_PREFIX "addq %2,%0\n"
9253+ "int $4\n0:\n"
9254+ _ASM_EXTABLE(0b, 0b)
9255+#endif
9256+
9257+ "sete %1\n"
9258 : "=m" (v->counter), "=qm" (c)
9259 : "er" (i), "m" (v->counter) : "memory");
9260 return c;
9261@@ -270,6 +525,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9262 */
9263 static inline void atomic64_inc(atomic64_t *v)
9264 {
9265+ asm volatile(LOCK_PREFIX "incq %0\n"
9266+
9267+#ifdef CONFIG_PAX_REFCOUNT
9268+ "jno 0f\n"
9269+ LOCK_PREFIX "decq %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_inc_unchecked - increment atomic64 variable
9280+ * @v: pointer to type atomic64_unchecked_t
9281+ *
9282+ * Atomically increments @v by 1.
9283+ */
9284+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9285+{
9286 asm volatile(LOCK_PREFIX "incq %0"
9287 : "=m" (v->counter)
9288 : "m" (v->counter));
9289@@ -283,7 +559,28 @@ static inline void atomic64_inc(atomic64_t *v)
9290 */
9291 static inline void atomic64_dec(atomic64_t *v)
9292 {
9293- asm volatile(LOCK_PREFIX "decq %0"
9294+ asm volatile(LOCK_PREFIX "decq %0\n"
9295+
9296+#ifdef CONFIG_PAX_REFCOUNT
9297+ "jno 0f\n"
9298+ LOCK_PREFIX "incq %0\n"
9299+ "int $4\n0:\n"
9300+ _ASM_EXTABLE(0b, 0b)
9301+#endif
9302+
9303+ : "=m" (v->counter)
9304+ : "m" (v->counter));
9305+}
9306+
9307+/**
9308+ * atomic64_dec_unchecked - decrement atomic64 variable
9309+ * @v: pointer to type atomic64_t
9310+ *
9311+ * Atomically decrements @v by 1.
9312+ */
9313+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9314+{
9315+ asm volatile(LOCK_PREFIX "decq %0\n"
9316 : "=m" (v->counter)
9317 : "m" (v->counter));
9318 }
9319@@ -300,7 +597,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9320 {
9321 unsigned char c;
9322
9323- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9324+ asm volatile(LOCK_PREFIX "decq %0\n"
9325+
9326+#ifdef CONFIG_PAX_REFCOUNT
9327+ "jno 0f\n"
9328+ LOCK_PREFIX "incq %0\n"
9329+ "int $4\n0:\n"
9330+ _ASM_EXTABLE(0b, 0b)
9331+#endif
9332+
9333+ "sete %1\n"
9334 : "=m" (v->counter), "=qm" (c)
9335 : "m" (v->counter) : "memory");
9336 return c != 0;
9337@@ -318,7 +624,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9338 {
9339 unsigned char c;
9340
9341- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9342+ asm volatile(LOCK_PREFIX "incq %0\n"
9343+
9344+#ifdef CONFIG_PAX_REFCOUNT
9345+ "jno 0f\n"
9346+ LOCK_PREFIX "decq %0\n"
9347+ "int $4\n0:\n"
9348+ _ASM_EXTABLE(0b, 0b)
9349+#endif
9350+
9351+ "sete %1\n"
9352 : "=m" (v->counter), "=qm" (c)
9353 : "m" (v->counter) : "memory");
9354 return c != 0;
9355@@ -337,7 +652,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9356 {
9357 unsigned char c;
9358
9359- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9360+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9361+
9362+#ifdef CONFIG_PAX_REFCOUNT
9363+ "jno 0f\n"
9364+ LOCK_PREFIX "subq %2,%0\n"
9365+ "int $4\n0:\n"
9366+ _ASM_EXTABLE(0b, 0b)
9367+#endif
9368+
9369+ "sets %1\n"
9370 : "=m" (v->counter), "=qm" (c)
9371 : "er" (i), "m" (v->counter) : "memory");
9372 return c;
9373@@ -353,7 +677,31 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9374 static inline long atomic64_add_return(long i, atomic64_t *v)
9375 {
9376 long __i = i;
9377- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
9378+ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
9379+
9380+#ifdef CONFIG_PAX_REFCOUNT
9381+ "jno 0f\n"
9382+ "movq %0, %1\n"
9383+ "int $4\n0:\n"
9384+ _ASM_EXTABLE(0b, 0b)
9385+#endif
9386+
9387+ : "+r" (i), "+m" (v->counter)
9388+ : : "memory");
9389+ return i + __i;
9390+}
9391+
9392+/**
9393+ * atomic64_add_return_unchecked - add and return
9394+ * @i: integer value to add
9395+ * @v: pointer to type atomic64_unchecked_t
9396+ *
9397+ * Atomically adds @i to @v and returns @i + @v
9398+ */
9399+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9400+{
9401+ long __i = i;
9402+ asm volatile(LOCK_PREFIX "xaddq %0, %1"
9403 : "+r" (i), "+m" (v->counter)
9404 : : "memory");
9405 return i + __i;
9406@@ -365,6 +713,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9407 }
9408
9409 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9410+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9411+{
9412+ return atomic64_add_return_unchecked(1, v);
9413+}
9414 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9415
9416 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9417@@ -372,21 +724,41 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9418 return cmpxchg(&v->counter, old, new);
9419 }
9420
9421+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9422+{
9423+ return cmpxchg(&v->counter, old, new);
9424+}
9425+
9426 static inline long atomic64_xchg(atomic64_t *v, long new)
9427 {
9428 return xchg(&v->counter, new);
9429 }
9430
9431+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9432+{
9433+ return xchg(&v->counter, new);
9434+}
9435+
9436 static inline long atomic_cmpxchg(atomic_t *v, int old, int new)
9437 {
9438 return cmpxchg(&v->counter, old, new);
9439 }
9440
9441+static inline long atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9442+{
9443+ return cmpxchg(&v->counter, old, new);
9444+}
9445+
9446 static inline long atomic_xchg(atomic_t *v, int new)
9447 {
9448 return xchg(&v->counter, new);
9449 }
9450
9451+static inline long atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9452+{
9453+ return xchg(&v->counter, new);
9454+}
9455+
9456 /**
9457 * atomic_add_unless - add unless the number is a given value
9458 * @v: pointer of type atomic_t
9459@@ -398,17 +770,30 @@ static inline long atomic_xchg(atomic_t *v, int new)
9460 */
9461 static inline int atomic_add_unless(atomic_t *v, int a, int u)
9462 {
9463- int c, old;
9464+ int c, old, new;
9465 c = atomic_read(v);
9466 for (;;) {
9467- if (unlikely(c == (u)))
9468+ if (unlikely(c == u))
9469 break;
9470- old = atomic_cmpxchg((v), c, c + (a));
9471+
9472+ asm volatile("addl %2,%0\n"
9473+
9474+#ifdef CONFIG_PAX_REFCOUNT
9475+ "jno 0f\n"
9476+ "subl %2,%0\n"
9477+ "int $4\n0:\n"
9478+ _ASM_EXTABLE(0b, 0b)
9479+#endif
9480+
9481+ : "=r" (new)
9482+ : "0" (c), "ir" (a));
9483+
9484+ old = atomic_cmpxchg(v, c, new);
9485 if (likely(old == c))
9486 break;
9487 c = old;
9488 }
9489- return c != (u);
9490+ return c != u;
9491 }
9492
9493 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
9494@@ -424,17 +809,30 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
9495 */
9496 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9497 {
9498- long c, old;
9499+ long c, old, new;
9500 c = atomic64_read(v);
9501 for (;;) {
9502- if (unlikely(c == (u)))
9503+ if (unlikely(c == u))
9504 break;
9505- old = atomic64_cmpxchg((v), c, c + (a));
9506+
9507+ asm volatile("addq %2,%0\n"
9508+
9509+#ifdef CONFIG_PAX_REFCOUNT
9510+ "jno 0f\n"
9511+ "subq %2,%0\n"
9512+ "int $4\n0:\n"
9513+ _ASM_EXTABLE(0b, 0b)
9514+#endif
9515+
9516+ : "=r" (new)
9517+ : "0" (c), "er" (a));
9518+
9519+ old = atomic64_cmpxchg(v, c, new);
9520 if (likely(old == c))
9521 break;
9522 c = old;
9523 }
9524- return c != (u);
9525+ return c != u;
9526 }
9527
9528 /**
9529diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9530index 02b47a6..d5c4b15 100644
9531--- a/arch/x86/include/asm/bitops.h
9532+++ b/arch/x86/include/asm/bitops.h
9533@@ -38,7 +38,7 @@
9534 * a mask operation on a byte.
9535 */
9536 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9537-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9538+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9539 #define CONST_MASK(nr) (1 << ((nr) & 7))
9540
9541 /**
9542diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9543index 7a10659..8bbf355 100644
9544--- a/arch/x86/include/asm/boot.h
9545+++ b/arch/x86/include/asm/boot.h
9546@@ -11,10 +11,15 @@
9547 #include <asm/pgtable_types.h>
9548
9549 /* Physical address where kernel should be loaded. */
9550-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9551+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9552 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9553 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9554
9555+#ifndef __ASSEMBLY__
9556+extern unsigned char __LOAD_PHYSICAL_ADDR[];
9557+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9558+#endif
9559+
9560 /* Minimum kernel alignment, as a power of two */
9561 #ifdef CONFIG_X86_64
9562 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9563diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9564index 549860d..7d45f68 100644
9565--- a/arch/x86/include/asm/cache.h
9566+++ b/arch/x86/include/asm/cache.h
9567@@ -5,9 +5,10 @@
9568
9569 /* L1 cache line size */
9570 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9571-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9572+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9573
9574 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
9575+#define __read_only __attribute__((__section__(".data.read_only")))
9576
9577 #ifdef CONFIG_X86_VSMP
9578 /* vSMP Internode cacheline shift */
9579diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9580index b54f6af..5b376a6 100644
9581--- a/arch/x86/include/asm/cacheflush.h
9582+++ b/arch/x86/include/asm/cacheflush.h
9583@@ -60,7 +60,7 @@ PAGEFLAG(WC, WC)
9584 static inline unsigned long get_page_memtype(struct page *pg)
9585 {
9586 if (!PageUncached(pg) && !PageWC(pg))
9587- return -1;
9588+ return ~0UL;
9589 else if (!PageUncached(pg) && PageWC(pg))
9590 return _PAGE_CACHE_WC;
9591 else if (PageUncached(pg) && !PageWC(pg))
9592@@ -85,7 +85,7 @@ static inline void set_page_memtype(struct page *pg, unsigned long memtype)
9593 SetPageWC(pg);
9594 break;
9595 default:
9596- case -1:
9597+ case ~0UL:
9598 ClearPageUncached(pg);
9599 ClearPageWC(pg);
9600 break;
9601diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
9602index 0e63c9a..ab8d972 100644
9603--- a/arch/x86/include/asm/calling.h
9604+++ b/arch/x86/include/asm/calling.h
9605@@ -52,32 +52,32 @@ For 32-bit we have the following conventions - kernel is built with
9606 * for assembly code:
9607 */
9608
9609-#define R15 0
9610-#define R14 8
9611-#define R13 16
9612-#define R12 24
9613-#define RBP 32
9614-#define RBX 40
9615+#define R15 (0)
9616+#define R14 (8)
9617+#define R13 (16)
9618+#define R12 (24)
9619+#define RBP (32)
9620+#define RBX (40)
9621
9622 /* arguments: interrupts/non tracing syscalls only save up to here: */
9623-#define R11 48
9624-#define R10 56
9625-#define R9 64
9626-#define R8 72
9627-#define RAX 80
9628-#define RCX 88
9629-#define RDX 96
9630-#define RSI 104
9631-#define RDI 112
9632-#define ORIG_RAX 120 /* + error_code */
9633+#define R11 (48)
9634+#define R10 (56)
9635+#define R9 (64)
9636+#define R8 (72)
9637+#define RAX (80)
9638+#define RCX (88)
9639+#define RDX (96)
9640+#define RSI (104)
9641+#define RDI (112)
9642+#define ORIG_RAX (120) /* + error_code */
9643 /* end of arguments */
9644
9645 /* cpu exception frame or undefined in case of fast syscall: */
9646-#define RIP 128
9647-#define CS 136
9648-#define EFLAGS 144
9649-#define RSP 152
9650-#define SS 160
9651+#define RIP (128)
9652+#define CS (136)
9653+#define EFLAGS (144)
9654+#define RSP (152)
9655+#define SS (160)
9656
9657 #define ARGOFFSET R11
9658 #define SWFRAME ORIG_RAX
9659diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9660index 46fc474..b02b0f9 100644
9661--- a/arch/x86/include/asm/checksum_32.h
9662+++ b/arch/x86/include/asm/checksum_32.h
9663@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9664 int len, __wsum sum,
9665 int *src_err_ptr, int *dst_err_ptr);
9666
9667+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9668+ int len, __wsum sum,
9669+ int *src_err_ptr, int *dst_err_ptr);
9670+
9671+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9672+ int len, __wsum sum,
9673+ int *src_err_ptr, int *dst_err_ptr);
9674+
9675 /*
9676 * Note: when you get a NULL pointer exception here this means someone
9677 * passed in an incorrect kernel address to one of these functions.
9678@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9679 int *err_ptr)
9680 {
9681 might_sleep();
9682- return csum_partial_copy_generic((__force void *)src, dst,
9683+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
9684 len, sum, err_ptr, NULL);
9685 }
9686
9687@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9688 {
9689 might_sleep();
9690 if (access_ok(VERIFY_WRITE, dst, len))
9691- return csum_partial_copy_generic(src, (__force void *)dst,
9692+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9693 len, sum, NULL, err_ptr);
9694
9695 if (len)
9696diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9697index 617bd56..7b047a1 100644
9698--- a/arch/x86/include/asm/desc.h
9699+++ b/arch/x86/include/asm/desc.h
9700@@ -4,6 +4,7 @@
9701 #include <asm/desc_defs.h>
9702 #include <asm/ldt.h>
9703 #include <asm/mmu.h>
9704+#include <asm/pgtable.h>
9705 #include <linux/smp.h>
9706
9707 static inline void fill_ldt(struct desc_struct *desc,
9708@@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_struct *desc,
9709 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
9710 desc->type = (info->read_exec_only ^ 1) << 1;
9711 desc->type |= info->contents << 2;
9712+ desc->type |= info->seg_not_present ^ 1;
9713 desc->s = 1;
9714 desc->dpl = 0x3;
9715 desc->p = info->seg_not_present ^ 1;
9716@@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_struct *desc,
9717 }
9718
9719 extern struct desc_ptr idt_descr;
9720-extern gate_desc idt_table[];
9721-
9722-struct gdt_page {
9723- struct desc_struct gdt[GDT_ENTRIES];
9724-} __attribute__((aligned(PAGE_SIZE)));
9725-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9726+extern gate_desc idt_table[256];
9727
9728+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9729 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9730 {
9731- return per_cpu(gdt_page, cpu).gdt;
9732+ return cpu_gdt_table[cpu];
9733 }
9734
9735 #ifdef CONFIG_X86_64
9736@@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9737 unsigned long base, unsigned dpl, unsigned flags,
9738 unsigned short seg)
9739 {
9740- gate->a = (seg << 16) | (base & 0xffff);
9741- gate->b = (base & 0xffff0000) |
9742- (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9743+ gate->gate.offset_low = base;
9744+ gate->gate.seg = seg;
9745+ gate->gate.reserved = 0;
9746+ gate->gate.type = type;
9747+ gate->gate.s = 0;
9748+ gate->gate.dpl = dpl;
9749+ gate->gate.p = 1;
9750+ gate->gate.offset_high = base >> 16;
9751 }
9752
9753 #endif
9754@@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9755 static inline void native_write_idt_entry(gate_desc *idt, int entry,
9756 const gate_desc *gate)
9757 {
9758+ pax_open_kernel();
9759 memcpy(&idt[entry], gate, sizeof(*gate));
9760+ pax_close_kernel();
9761 }
9762
9763 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
9764 const void *desc)
9765 {
9766+ pax_open_kernel();
9767 memcpy(&ldt[entry], desc, 8);
9768+ pax_close_kernel();
9769 }
9770
9771 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9772@@ -139,7 +146,10 @@ static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9773 size = sizeof(struct desc_struct);
9774 break;
9775 }
9776+
9777+ pax_open_kernel();
9778 memcpy(&gdt[entry], desc, size);
9779+ pax_close_kernel();
9780 }
9781
9782 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9783@@ -211,7 +221,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9784
9785 static inline void native_load_tr_desc(void)
9786 {
9787+ pax_open_kernel();
9788 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9789+ pax_close_kernel();
9790 }
9791
9792 static inline void native_load_gdt(const struct desc_ptr *dtr)
9793@@ -246,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9794 unsigned int i;
9795 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9796
9797+ pax_open_kernel();
9798 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9799 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9800+ pax_close_kernel();
9801 }
9802
9803 #define _LDT_empty(info) \
9804@@ -309,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9805 desc->limit = (limit >> 16) & 0xf;
9806 }
9807
9808-static inline void _set_gate(int gate, unsigned type, void *addr,
9809+static inline void _set_gate(int gate, unsigned type, const void *addr,
9810 unsigned dpl, unsigned ist, unsigned seg)
9811 {
9812 gate_desc s;
9813@@ -327,7 +341,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9814 * Pentium F0 0F bugfix can have resulted in the mapped
9815 * IDT being write-protected.
9816 */
9817-static inline void set_intr_gate(unsigned int n, void *addr)
9818+static inline void set_intr_gate(unsigned int n, const void *addr)
9819 {
9820 BUG_ON((unsigned)n > 0xFF);
9821 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9822@@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9823 /*
9824 * This routine sets up an interrupt gate at directory privilege level 3.
9825 */
9826-static inline void set_system_intr_gate(unsigned int n, void *addr)
9827+static inline void set_system_intr_gate(unsigned int n, const void *addr)
9828 {
9829 BUG_ON((unsigned)n > 0xFF);
9830 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9831 }
9832
9833-static inline void set_system_trap_gate(unsigned int n, void *addr)
9834+static inline void set_system_trap_gate(unsigned int n, const void *addr)
9835 {
9836 BUG_ON((unsigned)n > 0xFF);
9837 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9838 }
9839
9840-static inline void set_trap_gate(unsigned int n, void *addr)
9841+static inline void set_trap_gate(unsigned int n, const void *addr)
9842 {
9843 BUG_ON((unsigned)n > 0xFF);
9844 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9845@@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9846 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9847 {
9848 BUG_ON((unsigned)n > 0xFF);
9849- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9850+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9851 }
9852
9853-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9854+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9855 {
9856 BUG_ON((unsigned)n > 0xFF);
9857 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9858 }
9859
9860-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9861+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9862 {
9863 BUG_ON((unsigned)n > 0xFF);
9864 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9865 }
9866
9867+#ifdef CONFIG_X86_32
9868+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9869+{
9870+ struct desc_struct d;
9871+
9872+ if (likely(limit))
9873+ limit = (limit - 1UL) >> PAGE_SHIFT;
9874+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
9875+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9876+}
9877+#endif
9878+
9879 #endif /* _ASM_X86_DESC_H */
9880diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9881index 9d66848..6b4a691 100644
9882--- a/arch/x86/include/asm/desc_defs.h
9883+++ b/arch/x86/include/asm/desc_defs.h
9884@@ -31,6 +31,12 @@ struct desc_struct {
9885 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9886 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9887 };
9888+ struct {
9889+ u16 offset_low;
9890+ u16 seg;
9891+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9892+ unsigned offset_high: 16;
9893+ } gate;
9894 };
9895 } __attribute__((packed));
9896
9897diff --git a/arch/x86/include/asm/device.h b/arch/x86/include/asm/device.h
9898index cee34e9..a7c3fa2 100644
9899--- a/arch/x86/include/asm/device.h
9900+++ b/arch/x86/include/asm/device.h
9901@@ -6,7 +6,7 @@ struct dev_archdata {
9902 void *acpi_handle;
9903 #endif
9904 #ifdef CONFIG_X86_64
9905-struct dma_map_ops *dma_ops;
9906+ const struct dma_map_ops *dma_ops;
9907 #endif
9908 #ifdef CONFIG_DMAR
9909 void *iommu; /* hook for IOMMU specific extension */
9910diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
9911index 6a25d5d..786b202 100644
9912--- a/arch/x86/include/asm/dma-mapping.h
9913+++ b/arch/x86/include/asm/dma-mapping.h
9914@@ -25,9 +25,9 @@ extern int iommu_merge;
9915 extern struct device x86_dma_fallback_dev;
9916 extern int panic_on_overflow;
9917
9918-extern struct dma_map_ops *dma_ops;
9919+extern const struct dma_map_ops *dma_ops;
9920
9921-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9922+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
9923 {
9924 #ifdef CONFIG_X86_32
9925 return dma_ops;
9926@@ -44,7 +44,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9927 /* Make sure we keep the same behaviour */
9928 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
9929 {
9930- struct dma_map_ops *ops = get_dma_ops(dev);
9931+ const struct dma_map_ops *ops = get_dma_ops(dev);
9932 if (ops->mapping_error)
9933 return ops->mapping_error(dev, dma_addr);
9934
9935@@ -122,7 +122,7 @@ static inline void *
9936 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9937 gfp_t gfp)
9938 {
9939- struct dma_map_ops *ops = get_dma_ops(dev);
9940+ const struct dma_map_ops *ops = get_dma_ops(dev);
9941 void *memory;
9942
9943 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
9944@@ -149,7 +149,7 @@ dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9945 static inline void dma_free_coherent(struct device *dev, size_t size,
9946 void *vaddr, dma_addr_t bus)
9947 {
9948- struct dma_map_ops *ops = get_dma_ops(dev);
9949+ const struct dma_map_ops *ops = get_dma_ops(dev);
9950
9951 WARN_ON(irqs_disabled()); /* for portability */
9952
9953diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9954index 40b4e61..40d8133 100644
9955--- a/arch/x86/include/asm/e820.h
9956+++ b/arch/x86/include/asm/e820.h
9957@@ -133,7 +133,7 @@ extern char *default_machine_specific_memory_setup(void);
9958 #define ISA_END_ADDRESS 0x100000
9959 #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
9960
9961-#define BIOS_BEGIN 0x000a0000
9962+#define BIOS_BEGIN 0x000c0000
9963 #define BIOS_END 0x00100000
9964
9965 #ifdef __KERNEL__
9966diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9967index 8ac9d9a..0a6c96e 100644
9968--- a/arch/x86/include/asm/elf.h
9969+++ b/arch/x86/include/asm/elf.h
9970@@ -257,7 +257,25 @@ extern int force_personality32;
9971 the loader. We need to make sure that it is out of the way of the program
9972 that it will "exec", and that there is sufficient room for the brk. */
9973
9974+#ifdef CONFIG_PAX_SEGMEXEC
9975+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9976+#else
9977 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9978+#endif
9979+
9980+#ifdef CONFIG_PAX_ASLR
9981+#ifdef CONFIG_X86_32
9982+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9983+
9984+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9985+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9986+#else
9987+#define PAX_ELF_ET_DYN_BASE 0x400000UL
9988+
9989+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9990+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9991+#endif
9992+#endif
9993
9994 /* This yields a mask that user programs can use to figure out what
9995 instruction set this CPU supports. This could be done in user space,
9996@@ -310,9 +328,7 @@ do { \
9997
9998 #define ARCH_DLINFO \
9999 do { \
10000- if (vdso_enabled) \
10001- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10002- (unsigned long)current->mm->context.vdso); \
10003+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10004 } while (0)
10005
10006 #define AT_SYSINFO 32
10007@@ -323,7 +339,7 @@ do { \
10008
10009 #endif /* !CONFIG_X86_32 */
10010
10011-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10012+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10013
10014 #define VDSO_ENTRY \
10015 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10016@@ -337,7 +353,4 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
10017 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10018 #define compat_arch_setup_additional_pages syscall32_setup_pages
10019
10020-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10021-#define arch_randomize_brk arch_randomize_brk
10022-
10023 #endif /* _ASM_X86_ELF_H */
10024diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10025index cc70c1c..d96d011 100644
10026--- a/arch/x86/include/asm/emergency-restart.h
10027+++ b/arch/x86/include/asm/emergency-restart.h
10028@@ -15,6 +15,6 @@ enum reboot_type {
10029
10030 extern enum reboot_type reboot_type;
10031
10032-extern void machine_emergency_restart(void);
10033+extern void machine_emergency_restart(void) __noreturn;
10034
10035 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10036diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10037index 1f11ce4..7caabd1 100644
10038--- a/arch/x86/include/asm/futex.h
10039+++ b/arch/x86/include/asm/futex.h
10040@@ -12,16 +12,18 @@
10041 #include <asm/system.h>
10042
10043 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10044+ typecheck(u32 __user *, uaddr); \
10045 asm volatile("1:\t" insn "\n" \
10046 "2:\t.section .fixup,\"ax\"\n" \
10047 "3:\tmov\t%3, %1\n" \
10048 "\tjmp\t2b\n" \
10049 "\t.previous\n" \
10050 _ASM_EXTABLE(1b, 3b) \
10051- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10052+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10053 : "i" (-EFAULT), "0" (oparg), "1" (0))
10054
10055 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10056+ typecheck(u32 __user *, uaddr); \
10057 asm volatile("1:\tmovl %2, %0\n" \
10058 "\tmovl\t%0, %3\n" \
10059 "\t" insn "\n" \
10060@@ -34,10 +36,10 @@
10061 _ASM_EXTABLE(1b, 4b) \
10062 _ASM_EXTABLE(2b, 4b) \
10063 : "=&a" (oldval), "=&r" (ret), \
10064- "+m" (*uaddr), "=&r" (tem) \
10065+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10066 : "r" (oparg), "i" (-EFAULT), "1" (0))
10067
10068-static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
10069+static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10070 {
10071 int op = (encoded_op >> 28) & 7;
10072 int cmp = (encoded_op >> 24) & 15;
10073@@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
10074
10075 switch (op) {
10076 case FUTEX_OP_SET:
10077- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10078+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10079 break;
10080 case FUTEX_OP_ADD:
10081- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10082+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10083 uaddr, oparg);
10084 break;
10085 case FUTEX_OP_OR:
10086@@ -109,7 +111,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
10087 return ret;
10088 }
10089
10090-static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
10091+static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
10092 int newval)
10093 {
10094
10095@@ -119,16 +121,16 @@ static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
10096 return -ENOSYS;
10097 #endif
10098
10099- if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
10100+ if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10101 return -EFAULT;
10102
10103- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n"
10104+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %1\n"
10105 "2:\t.section .fixup, \"ax\"\n"
10106 "3:\tmov %2, %0\n"
10107 "\tjmp 2b\n"
10108 "\t.previous\n"
10109 _ASM_EXTABLE(1b, 3b)
10110- : "=a" (oldval), "+m" (*uaddr)
10111+ : "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
10112 : "i" (-EFAULT), "r" (newval), "0" (oldval)
10113 : "memory"
10114 );
10115diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10116index ba180d9..3bad351 100644
10117--- a/arch/x86/include/asm/hw_irq.h
10118+++ b/arch/x86/include/asm/hw_irq.h
10119@@ -92,8 +92,8 @@ extern void setup_ioapic_dest(void);
10120 extern void enable_IO_APIC(void);
10121
10122 /* Statistics */
10123-extern atomic_t irq_err_count;
10124-extern atomic_t irq_mis_count;
10125+extern atomic_unchecked_t irq_err_count;
10126+extern atomic_unchecked_t irq_mis_count;
10127
10128 /* EISA */
10129 extern void eisa_set_level_irq(unsigned int irq);
10130diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10131index 0b20bbb..4cb1396 100644
10132--- a/arch/x86/include/asm/i387.h
10133+++ b/arch/x86/include/asm/i387.h
10134@@ -60,6 +60,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10135 {
10136 int err;
10137
10138+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10139+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10140+ fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
10141+#endif
10142+
10143 asm volatile("1: rex64/fxrstor (%[fx])\n\t"
10144 "2:\n"
10145 ".section .fixup,\"ax\"\n"
10146@@ -105,6 +110,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10147 {
10148 int err;
10149
10150+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10151+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10152+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10153+#endif
10154+
10155 asm volatile("1: rex64/fxsave (%[fx])\n\t"
10156 "2:\n"
10157 ".section .fixup,\"ax\"\n"
10158@@ -195,13 +205,8 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10159 }
10160
10161 /* We need a safe address that is cheap to find and that is already
10162- in L1 during context switch. The best choices are unfortunately
10163- different for UP and SMP */
10164-#ifdef CONFIG_SMP
10165-#define safe_address (__per_cpu_offset[0])
10166-#else
10167-#define safe_address (kstat_cpu(0).cpustat.user)
10168-#endif
10169+ in L1 during context switch. */
10170+#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
10171
10172 /*
10173 * These must be called with preempt disabled
10174@@ -291,7 +296,7 @@ static inline void kernel_fpu_begin(void)
10175 struct thread_info *me = current_thread_info();
10176 preempt_disable();
10177 if (me->status & TS_USEDFPU)
10178- __save_init_fpu(me->task);
10179+ __save_init_fpu(current);
10180 else
10181 clts();
10182 }
10183diff --git a/arch/x86/include/asm/io_32.h b/arch/x86/include/asm/io_32.h
10184index a299900..15c5410 100644
10185--- a/arch/x86/include/asm/io_32.h
10186+++ b/arch/x86/include/asm/io_32.h
10187@@ -3,6 +3,7 @@
10188
10189 #include <linux/string.h>
10190 #include <linux/compiler.h>
10191+#include <asm/processor.h>
10192
10193 /*
10194 * This file contains the definitions for the x86 IO instructions
10195@@ -42,6 +43,17 @@
10196
10197 #ifdef __KERNEL__
10198
10199+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10200+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10201+{
10202+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10203+}
10204+
10205+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10206+{
10207+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10208+}
10209+
10210 #include <asm-generic/iomap.h>
10211
10212 #include <linux/vmalloc.h>
10213diff --git a/arch/x86/include/asm/io_64.h b/arch/x86/include/asm/io_64.h
10214index 2440678..c158b88 100644
10215--- a/arch/x86/include/asm/io_64.h
10216+++ b/arch/x86/include/asm/io_64.h
10217@@ -140,6 +140,17 @@ __OUTS(l)
10218
10219 #include <linux/vmalloc.h>
10220
10221+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10222+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10223+{
10224+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10225+}
10226+
10227+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10228+{
10229+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10230+}
10231+
10232 #include <asm-generic/iomap.h>
10233
10234 void __memcpy_fromio(void *, unsigned long, unsigned);
10235diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
10236index fd6d21b..8b13915 100644
10237--- a/arch/x86/include/asm/iommu.h
10238+++ b/arch/x86/include/asm/iommu.h
10239@@ -3,7 +3,7 @@
10240
10241 extern void pci_iommu_shutdown(void);
10242 extern void no_iommu_init(void);
10243-extern struct dma_map_ops nommu_dma_ops;
10244+extern const struct dma_map_ops nommu_dma_ops;
10245 extern int force_iommu, no_iommu;
10246 extern int iommu_detected;
10247 extern int iommu_pass_through;
10248diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10249index 9e2b952..557206e 100644
10250--- a/arch/x86/include/asm/irqflags.h
10251+++ b/arch/x86/include/asm/irqflags.h
10252@@ -142,6 +142,11 @@ static inline unsigned long __raw_local_irq_save(void)
10253 sti; \
10254 sysexit
10255
10256+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10257+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10258+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10259+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10260+
10261 #else
10262 #define INTERRUPT_RETURN iret
10263 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10264diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10265index 4fe681d..bb6d40c 100644
10266--- a/arch/x86/include/asm/kprobes.h
10267+++ b/arch/x86/include/asm/kprobes.h
10268@@ -34,13 +34,8 @@ typedef u8 kprobe_opcode_t;
10269 #define BREAKPOINT_INSTRUCTION 0xcc
10270 #define RELATIVEJUMP_INSTRUCTION 0xe9
10271 #define MAX_INSN_SIZE 16
10272-#define MAX_STACK_SIZE 64
10273-#define MIN_STACK_SIZE(ADDR) \
10274- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10275- THREAD_SIZE - (unsigned long)(ADDR))) \
10276- ? (MAX_STACK_SIZE) \
10277- : (((unsigned long)current_thread_info()) + \
10278- THREAD_SIZE - (unsigned long)(ADDR)))
10279+#define MAX_STACK_SIZE 64UL
10280+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10281
10282 #define flush_insn_slot(p) do { } while (0)
10283
10284diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10285index 08bc2ff..2e88d1f 100644
10286--- a/arch/x86/include/asm/kvm_host.h
10287+++ b/arch/x86/include/asm/kvm_host.h
10288@@ -534,9 +534,9 @@ struct kvm_x86_ops {
10289 bool (*gb_page_enable)(void);
10290
10291 const struct trace_print_flags *exit_reasons_str;
10292-};
10293+} __do_const;
10294
10295-extern struct kvm_x86_ops *kvm_x86_ops;
10296+extern const struct kvm_x86_ops *kvm_x86_ops;
10297
10298 int kvm_mmu_module_init(void);
10299 void kvm_mmu_module_exit(void);
10300diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10301index 47b9b6f..815aaa1 100644
10302--- a/arch/x86/include/asm/local.h
10303+++ b/arch/x86/include/asm/local.h
10304@@ -18,26 +18,58 @@ typedef struct {
10305
10306 static inline void local_inc(local_t *l)
10307 {
10308- asm volatile(_ASM_INC "%0"
10309+ asm volatile(_ASM_INC "%0\n"
10310+
10311+#ifdef CONFIG_PAX_REFCOUNT
10312+ "jno 0f\n"
10313+ _ASM_DEC "%0\n"
10314+ "int $4\n0:\n"
10315+ _ASM_EXTABLE(0b, 0b)
10316+#endif
10317+
10318 : "+m" (l->a.counter));
10319 }
10320
10321 static inline void local_dec(local_t *l)
10322 {
10323- asm volatile(_ASM_DEC "%0"
10324+ asm volatile(_ASM_DEC "%0\n"
10325+
10326+#ifdef CONFIG_PAX_REFCOUNT
10327+ "jno 0f\n"
10328+ _ASM_INC "%0\n"
10329+ "int $4\n0:\n"
10330+ _ASM_EXTABLE(0b, 0b)
10331+#endif
10332+
10333 : "+m" (l->a.counter));
10334 }
10335
10336 static inline void local_add(long i, local_t *l)
10337 {
10338- asm volatile(_ASM_ADD "%1,%0"
10339+ asm volatile(_ASM_ADD "%1,%0\n"
10340+
10341+#ifdef CONFIG_PAX_REFCOUNT
10342+ "jno 0f\n"
10343+ _ASM_SUB "%1,%0\n"
10344+ "int $4\n0:\n"
10345+ _ASM_EXTABLE(0b, 0b)
10346+#endif
10347+
10348 : "+m" (l->a.counter)
10349 : "ir" (i));
10350 }
10351
10352 static inline void local_sub(long i, local_t *l)
10353 {
10354- asm volatile(_ASM_SUB "%1,%0"
10355+ asm volatile(_ASM_SUB "%1,%0\n"
10356+
10357+#ifdef CONFIG_PAX_REFCOUNT
10358+ "jno 0f\n"
10359+ _ASM_ADD "%1,%0\n"
10360+ "int $4\n0:\n"
10361+ _ASM_EXTABLE(0b, 0b)
10362+#endif
10363+
10364 : "+m" (l->a.counter)
10365 : "ir" (i));
10366 }
10367@@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10368 {
10369 unsigned char c;
10370
10371- asm volatile(_ASM_SUB "%2,%0; sete %1"
10372+ asm volatile(_ASM_SUB "%2,%0\n"
10373+
10374+#ifdef CONFIG_PAX_REFCOUNT
10375+ "jno 0f\n"
10376+ _ASM_ADD "%2,%0\n"
10377+ "int $4\n0:\n"
10378+ _ASM_EXTABLE(0b, 0b)
10379+#endif
10380+
10381+ "sete %1\n"
10382 : "+m" (l->a.counter), "=qm" (c)
10383 : "ir" (i) : "memory");
10384 return c;
10385@@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10386 {
10387 unsigned char c;
10388
10389- asm volatile(_ASM_DEC "%0; sete %1"
10390+ asm volatile(_ASM_DEC "%0\n"
10391+
10392+#ifdef CONFIG_PAX_REFCOUNT
10393+ "jno 0f\n"
10394+ _ASM_INC "%0\n"
10395+ "int $4\n0:\n"
10396+ _ASM_EXTABLE(0b, 0b)
10397+#endif
10398+
10399+ "sete %1\n"
10400 : "+m" (l->a.counter), "=qm" (c)
10401 : : "memory");
10402 return c != 0;
10403@@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10404 {
10405 unsigned char c;
10406
10407- asm volatile(_ASM_INC "%0; sete %1"
10408+ asm volatile(_ASM_INC "%0\n"
10409+
10410+#ifdef CONFIG_PAX_REFCOUNT
10411+ "jno 0f\n"
10412+ _ASM_DEC "%0\n"
10413+ "int $4\n0:\n"
10414+ _ASM_EXTABLE(0b, 0b)
10415+#endif
10416+
10417+ "sete %1\n"
10418 : "+m" (l->a.counter), "=qm" (c)
10419 : : "memory");
10420 return c != 0;
10421@@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10422 {
10423 unsigned char c;
10424
10425- asm volatile(_ASM_ADD "%2,%0; sets %1"
10426+ asm volatile(_ASM_ADD "%2,%0\n"
10427+
10428+#ifdef CONFIG_PAX_REFCOUNT
10429+ "jno 0f\n"
10430+ _ASM_SUB "%2,%0\n"
10431+ "int $4\n0:\n"
10432+ _ASM_EXTABLE(0b, 0b)
10433+#endif
10434+
10435+ "sets %1\n"
10436 : "+m" (l->a.counter), "=qm" (c)
10437 : "ir" (i) : "memory");
10438 return c;
10439@@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10440 #endif
10441 /* Modern 486+ processor */
10442 __i = i;
10443- asm volatile(_ASM_XADD "%0, %1;"
10444+ asm volatile(_ASM_XADD "%0, %1\n"
10445+
10446+#ifdef CONFIG_PAX_REFCOUNT
10447+ "jno 0f\n"
10448+ _ASM_MOV "%0,%1\n"
10449+ "int $4\n0:\n"
10450+ _ASM_EXTABLE(0b, 0b)
10451+#endif
10452+
10453 : "+r" (i), "+m" (l->a.counter)
10454 : : "memory");
10455 return i + __i;
10456diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microcode.h
10457index ef51b50..514ba37 100644
10458--- a/arch/x86/include/asm/microcode.h
10459+++ b/arch/x86/include/asm/microcode.h
10460@@ -12,13 +12,13 @@ struct device;
10461 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
10462
10463 struct microcode_ops {
10464- enum ucode_state (*request_microcode_user) (int cpu,
10465+ enum ucode_state (* const request_microcode_user) (int cpu,
10466 const void __user *buf, size_t size);
10467
10468- enum ucode_state (*request_microcode_fw) (int cpu,
10469+ enum ucode_state (* const request_microcode_fw) (int cpu,
10470 struct device *device);
10471
10472- void (*microcode_fini_cpu) (int cpu);
10473+ void (* const microcode_fini_cpu) (int cpu);
10474
10475 /*
10476 * The generic 'microcode_core' part guarantees that
10477@@ -38,18 +38,18 @@ struct ucode_cpu_info {
10478 extern struct ucode_cpu_info ucode_cpu_info[];
10479
10480 #ifdef CONFIG_MICROCODE_INTEL
10481-extern struct microcode_ops * __init init_intel_microcode(void);
10482+extern const struct microcode_ops * __init init_intel_microcode(void);
10483 #else
10484-static inline struct microcode_ops * __init init_intel_microcode(void)
10485+static inline const struct microcode_ops * __init init_intel_microcode(void)
10486 {
10487 return NULL;
10488 }
10489 #endif /* CONFIG_MICROCODE_INTEL */
10490
10491 #ifdef CONFIG_MICROCODE_AMD
10492-extern struct microcode_ops * __init init_amd_microcode(void);
10493+extern const struct microcode_ops * __init init_amd_microcode(void);
10494 #else
10495-static inline struct microcode_ops * __init init_amd_microcode(void)
10496+static inline const struct microcode_ops * __init init_amd_microcode(void)
10497 {
10498 return NULL;
10499 }
10500diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10501index 593e51d..fa69c9a 100644
10502--- a/arch/x86/include/asm/mman.h
10503+++ b/arch/x86/include/asm/mman.h
10504@@ -5,4 +5,14 @@
10505
10506 #include <asm-generic/mman.h>
10507
10508+#ifdef __KERNEL__
10509+#ifndef __ASSEMBLY__
10510+#ifdef CONFIG_X86_32
10511+#define arch_mmap_check i386_mmap_check
10512+int i386_mmap_check(unsigned long addr, unsigned long len,
10513+ unsigned long flags);
10514+#endif
10515+#endif
10516+#endif
10517+
10518 #endif /* _ASM_X86_MMAN_H */
10519diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10520index 80a1dee..239c67d 100644
10521--- a/arch/x86/include/asm/mmu.h
10522+++ b/arch/x86/include/asm/mmu.h
10523@@ -9,10 +9,23 @@
10524 * we put the segment information here.
10525 */
10526 typedef struct {
10527- void *ldt;
10528+ struct desc_struct *ldt;
10529 int size;
10530 struct mutex lock;
10531- void *vdso;
10532+ unsigned long vdso;
10533+
10534+#ifdef CONFIG_X86_32
10535+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10536+ unsigned long user_cs_base;
10537+ unsigned long user_cs_limit;
10538+
10539+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10540+ cpumask_t cpu_user_cs_mask;
10541+#endif
10542+
10543+#endif
10544+#endif
10545+
10546 } mm_context_t;
10547
10548 #ifdef CONFIG_SMP
10549diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10550index 8b5393e..8143173 100644
10551--- a/arch/x86/include/asm/mmu_context.h
10552+++ b/arch/x86/include/asm/mmu_context.h
10553@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10554
10555 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10556 {
10557+
10558+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10559+ unsigned int i;
10560+ pgd_t *pgd;
10561+
10562+ pax_open_kernel();
10563+ pgd = get_cpu_pgd(smp_processor_id());
10564+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10565+ set_pgd_batched(pgd+i, native_make_pgd(0));
10566+ pax_close_kernel();
10567+#endif
10568+
10569 #ifdef CONFIG_SMP
10570 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10571 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10572@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10573 struct task_struct *tsk)
10574 {
10575 unsigned cpu = smp_processor_id();
10576+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)) && defined(CONFIG_SMP)
10577+ int tlbstate = TLBSTATE_OK;
10578+#endif
10579
10580 if (likely(prev != next)) {
10581 #ifdef CONFIG_SMP
10582+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10583+ tlbstate = percpu_read(cpu_tlbstate.state);
10584+#endif
10585 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10586 percpu_write(cpu_tlbstate.active_mm, next);
10587 #endif
10588 cpumask_set_cpu(cpu, mm_cpumask(next));
10589
10590 /* Re-load page tables */
10591+#ifdef CONFIG_PAX_PER_CPU_PGD
10592+ pax_open_kernel();
10593+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10594+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10595+ pax_close_kernel();
10596+ load_cr3(get_cpu_pgd(cpu));
10597+#else
10598 load_cr3(next->pgd);
10599+#endif
10600
10601 /* stop flush ipis for the previous mm */
10602 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10603@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10604 */
10605 if (unlikely(prev->context.ldt != next->context.ldt))
10606 load_LDT_nolock(&next->context);
10607- }
10608+
10609+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10610+ if (!nx_enabled) {
10611+ smp_mb__before_clear_bit();
10612+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10613+ smp_mb__after_clear_bit();
10614+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10615+ }
10616+#endif
10617+
10618+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10619+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10620+ prev->context.user_cs_limit != next->context.user_cs_limit))
10621+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10622 #ifdef CONFIG_SMP
10623+ else if (unlikely(tlbstate != TLBSTATE_OK))
10624+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10625+#endif
10626+#endif
10627+
10628+ }
10629 else {
10630+
10631+#ifdef CONFIG_PAX_PER_CPU_PGD
10632+ pax_open_kernel();
10633+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10634+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10635+ pax_close_kernel();
10636+ load_cr3(get_cpu_pgd(cpu));
10637+#endif
10638+
10639+#ifdef CONFIG_SMP
10640 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10641 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10642
10643@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10644 * tlb flush IPI delivery. We must reload CR3
10645 * to make sure to use no freed page tables.
10646 */
10647+
10648+#ifndef CONFIG_PAX_PER_CPU_PGD
10649 load_cr3(next->pgd);
10650+#endif
10651+
10652 load_LDT_nolock(&next->context);
10653+
10654+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10655+ if (!nx_enabled)
10656+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10657+#endif
10658+
10659+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10660+#ifdef CONFIG_PAX_PAGEEXEC
10661+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
10662+#endif
10663+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10664+#endif
10665+
10666 }
10667+#endif
10668 }
10669-#endif
10670 }
10671
10672 #define activate_mm(prev, next) \
10673diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10674index 3e2ce58..caaf478 100644
10675--- a/arch/x86/include/asm/module.h
10676+++ b/arch/x86/include/asm/module.h
10677@@ -5,6 +5,7 @@
10678
10679 #ifdef CONFIG_X86_64
10680 /* X86_64 does not define MODULE_PROC_FAMILY */
10681+#define MODULE_PROC_FAMILY ""
10682 #elif defined CONFIG_M386
10683 #define MODULE_PROC_FAMILY "386 "
10684 #elif defined CONFIG_M486
10685@@ -59,13 +60,26 @@
10686 #error unknown processor family
10687 #endif
10688
10689-#ifdef CONFIG_X86_32
10690-# ifdef CONFIG_4KSTACKS
10691-# define MODULE_STACKSIZE "4KSTACKS "
10692-# else
10693-# define MODULE_STACKSIZE ""
10694-# endif
10695-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
10696+#if defined(CONFIG_X86_32) && defined(CONFIG_4KSTACKS)
10697+#define MODULE_STACKSIZE "4KSTACKS "
10698+#else
10699+#define MODULE_STACKSIZE ""
10700 #endif
10701
10702+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10703+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10704+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10705+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10706+#else
10707+#define MODULE_PAX_KERNEXEC ""
10708+#endif
10709+
10710+#ifdef CONFIG_PAX_MEMORY_UDEREF
10711+#define MODULE_PAX_UDEREF "UDEREF "
10712+#else
10713+#define MODULE_PAX_UDEREF ""
10714+#endif
10715+
10716+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10717+
10718 #endif /* _ASM_X86_MODULE_H */
10719diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10720index 7639dbf..e08a58c 100644
10721--- a/arch/x86/include/asm/page_64_types.h
10722+++ b/arch/x86/include/asm/page_64_types.h
10723@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10724
10725 /* duplicated to the one in bootmem.h */
10726 extern unsigned long max_pfn;
10727-extern unsigned long phys_base;
10728+extern const unsigned long phys_base;
10729
10730 extern unsigned long __phys_addr(unsigned long);
10731 #define __phys_reloc_hide(x) (x)
10732diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10733index efb3899..ef30687 100644
10734--- a/arch/x86/include/asm/paravirt.h
10735+++ b/arch/x86/include/asm/paravirt.h
10736@@ -648,6 +648,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10737 val);
10738 }
10739
10740+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10741+{
10742+ pgdval_t val = native_pgd_val(pgd);
10743+
10744+ if (sizeof(pgdval_t) > sizeof(long))
10745+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10746+ val, (u64)val >> 32);
10747+ else
10748+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10749+ val);
10750+}
10751+
10752 static inline void pgd_clear(pgd_t *pgdp)
10753 {
10754 set_pgd(pgdp, __pgd(0));
10755@@ -729,6 +741,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10756 pv_mmu_ops.set_fixmap(idx, phys, flags);
10757 }
10758
10759+#ifdef CONFIG_PAX_KERNEXEC
10760+static inline unsigned long pax_open_kernel(void)
10761+{
10762+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10763+}
10764+
10765+static inline unsigned long pax_close_kernel(void)
10766+{
10767+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10768+}
10769+#else
10770+static inline unsigned long pax_open_kernel(void) { return 0; }
10771+static inline unsigned long pax_close_kernel(void) { return 0; }
10772+#endif
10773+
10774 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10775
10776 static inline int __raw_spin_is_locked(struct raw_spinlock *lock)
10777@@ -945,7 +972,7 @@ extern void default_banner(void);
10778
10779 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10780 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10781-#define PARA_INDIRECT(addr) *%cs:addr
10782+#define PARA_INDIRECT(addr) *%ss:addr
10783 #endif
10784
10785 #define INTERRUPT_RETURN \
10786@@ -1022,6 +1049,21 @@ extern void default_banner(void);
10787 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10788 CLBR_NONE, \
10789 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10790+
10791+#define GET_CR0_INTO_RDI \
10792+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10793+ mov %rax,%rdi
10794+
10795+#define SET_RDI_INTO_CR0 \
10796+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10797+
10798+#define GET_CR3_INTO_RDI \
10799+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10800+ mov %rax,%rdi
10801+
10802+#define SET_RDI_INTO_CR3 \
10803+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10804+
10805 #endif /* CONFIG_X86_32 */
10806
10807 #endif /* __ASSEMBLY__ */
10808diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10809index 9357473..aeb2de5 100644
10810--- a/arch/x86/include/asm/paravirt_types.h
10811+++ b/arch/x86/include/asm/paravirt_types.h
10812@@ -78,19 +78,19 @@ struct pv_init_ops {
10813 */
10814 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10815 unsigned long addr, unsigned len);
10816-};
10817+} __no_const;
10818
10819
10820 struct pv_lazy_ops {
10821 /* Set deferred update mode, used for batching operations. */
10822 void (*enter)(void);
10823 void (*leave)(void);
10824-};
10825+} __no_const;
10826
10827 struct pv_time_ops {
10828 unsigned long long (*sched_clock)(void);
10829 unsigned long (*get_tsc_khz)(void);
10830-};
10831+} __no_const;
10832
10833 struct pv_cpu_ops {
10834 /* hooks for various privileged instructions */
10835@@ -186,7 +186,7 @@ struct pv_cpu_ops {
10836
10837 void (*start_context_switch)(struct task_struct *prev);
10838 void (*end_context_switch)(struct task_struct *next);
10839-};
10840+} __no_const;
10841
10842 struct pv_irq_ops {
10843 /*
10844@@ -217,7 +217,7 @@ struct pv_apic_ops {
10845 unsigned long start_eip,
10846 unsigned long start_esp);
10847 #endif
10848-};
10849+} __no_const;
10850
10851 struct pv_mmu_ops {
10852 unsigned long (*read_cr2)(void);
10853@@ -301,6 +301,7 @@ struct pv_mmu_ops {
10854 struct paravirt_callee_save make_pud;
10855
10856 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10857+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10858 #endif /* PAGETABLE_LEVELS == 4 */
10859 #endif /* PAGETABLE_LEVELS >= 3 */
10860
10861@@ -316,6 +317,12 @@ struct pv_mmu_ops {
10862 an mfn. We can tell which is which from the index. */
10863 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10864 phys_addr_t phys, pgprot_t flags);
10865+
10866+#ifdef CONFIG_PAX_KERNEXEC
10867+ unsigned long (*pax_open_kernel)(void);
10868+ unsigned long (*pax_close_kernel)(void);
10869+#endif
10870+
10871 };
10872
10873 struct raw_spinlock;
10874@@ -326,7 +333,7 @@ struct pv_lock_ops {
10875 void (*spin_lock_flags)(struct raw_spinlock *lock, unsigned long flags);
10876 int (*spin_trylock)(struct raw_spinlock *lock);
10877 void (*spin_unlock)(struct raw_spinlock *lock);
10878-};
10879+} __no_const;
10880
10881 /* This contains all the paravirt structures: we get a convenient
10882 * number for each function using the offset which we use to indicate
10883diff --git a/arch/x86/include/asm/pci_x86.h b/arch/x86/include/asm/pci_x86.h
10884index b399988..3f47c38 100644
10885--- a/arch/x86/include/asm/pci_x86.h
10886+++ b/arch/x86/include/asm/pci_x86.h
10887@@ -89,16 +89,16 @@ extern int (*pcibios_enable_irq)(struct pci_dev *dev);
10888 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
10889
10890 struct pci_raw_ops {
10891- int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10892+ int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10893 int reg, int len, u32 *val);
10894- int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10895+ int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10896 int reg, int len, u32 val);
10897 };
10898
10899-extern struct pci_raw_ops *raw_pci_ops;
10900-extern struct pci_raw_ops *raw_pci_ext_ops;
10901+extern const struct pci_raw_ops *raw_pci_ops;
10902+extern const struct pci_raw_ops *raw_pci_ext_ops;
10903
10904-extern struct pci_raw_ops pci_direct_conf1;
10905+extern const struct pci_raw_ops pci_direct_conf1;
10906 extern bool port_cf9_safe;
10907
10908 /* arch_initcall level */
10909diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
10910index b65a36d..50345a4 100644
10911--- a/arch/x86/include/asm/percpu.h
10912+++ b/arch/x86/include/asm/percpu.h
10913@@ -78,6 +78,7 @@ do { \
10914 if (0) { \
10915 T__ tmp__; \
10916 tmp__ = (val); \
10917+ (void)tmp__; \
10918 } \
10919 switch (sizeof(var)) { \
10920 case 1: \
10921diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10922index 271de94..ef944d6 100644
10923--- a/arch/x86/include/asm/pgalloc.h
10924+++ b/arch/x86/include/asm/pgalloc.h
10925@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10926 pmd_t *pmd, pte_t *pte)
10927 {
10928 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10929+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10930+}
10931+
10932+static inline void pmd_populate_user(struct mm_struct *mm,
10933+ pmd_t *pmd, pte_t *pte)
10934+{
10935+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10936 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10937 }
10938
10939diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10940index 2334982..70bc412 100644
10941--- a/arch/x86/include/asm/pgtable-2level.h
10942+++ b/arch/x86/include/asm/pgtable-2level.h
10943@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10944
10945 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10946 {
10947+ pax_open_kernel();
10948 *pmdp = pmd;
10949+ pax_close_kernel();
10950 }
10951
10952 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10953diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10954index 33927d2..ccde329 100644
10955--- a/arch/x86/include/asm/pgtable-3level.h
10956+++ b/arch/x86/include/asm/pgtable-3level.h
10957@@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10958
10959 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10960 {
10961+ pax_open_kernel();
10962 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10963+ pax_close_kernel();
10964 }
10965
10966 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10967 {
10968+ pax_open_kernel();
10969 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10970+ pax_close_kernel();
10971 }
10972
10973 /*
10974diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10975index af6fd36..867ff74 100644
10976--- a/arch/x86/include/asm/pgtable.h
10977+++ b/arch/x86/include/asm/pgtable.h
10978@@ -39,6 +39,7 @@ extern struct list_head pgd_list;
10979
10980 #ifndef __PAGETABLE_PUD_FOLDED
10981 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10982+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10983 #define pgd_clear(pgd) native_pgd_clear(pgd)
10984 #endif
10985
10986@@ -74,12 +75,51 @@ extern struct list_head pgd_list;
10987
10988 #define arch_end_context_switch(prev) do {} while(0)
10989
10990+#define pax_open_kernel() native_pax_open_kernel()
10991+#define pax_close_kernel() native_pax_close_kernel()
10992 #endif /* CONFIG_PARAVIRT */
10993
10994+#define __HAVE_ARCH_PAX_OPEN_KERNEL
10995+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10996+
10997+#ifdef CONFIG_PAX_KERNEXEC
10998+static inline unsigned long native_pax_open_kernel(void)
10999+{
11000+ unsigned long cr0;
11001+
11002+ preempt_disable();
11003+ barrier();
11004+ cr0 = read_cr0() ^ X86_CR0_WP;
11005+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11006+ write_cr0(cr0);
11007+ return cr0 ^ X86_CR0_WP;
11008+}
11009+
11010+static inline unsigned long native_pax_close_kernel(void)
11011+{
11012+ unsigned long cr0;
11013+
11014+ cr0 = read_cr0() ^ X86_CR0_WP;
11015+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11016+ write_cr0(cr0);
11017+ barrier();
11018+ preempt_enable_no_resched();
11019+ return cr0 ^ X86_CR0_WP;
11020+}
11021+#else
11022+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11023+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11024+#endif
11025+
11026 /*
11027 * The following only work if pte_present() is true.
11028 * Undefined behaviour if not..
11029 */
11030+static inline int pte_user(pte_t pte)
11031+{
11032+ return pte_val(pte) & _PAGE_USER;
11033+}
11034+
11035 static inline int pte_dirty(pte_t pte)
11036 {
11037 return pte_flags(pte) & _PAGE_DIRTY;
11038@@ -167,9 +207,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11039 return pte_clear_flags(pte, _PAGE_RW);
11040 }
11041
11042+static inline pte_t pte_mkread(pte_t pte)
11043+{
11044+ return __pte(pte_val(pte) | _PAGE_USER);
11045+}
11046+
11047 static inline pte_t pte_mkexec(pte_t pte)
11048 {
11049- return pte_clear_flags(pte, _PAGE_NX);
11050+#ifdef CONFIG_X86_PAE
11051+ if (__supported_pte_mask & _PAGE_NX)
11052+ return pte_clear_flags(pte, _PAGE_NX);
11053+ else
11054+#endif
11055+ return pte_set_flags(pte, _PAGE_USER);
11056+}
11057+
11058+static inline pte_t pte_exprotect(pte_t pte)
11059+{
11060+#ifdef CONFIG_X86_PAE
11061+ if (__supported_pte_mask & _PAGE_NX)
11062+ return pte_set_flags(pte, _PAGE_NX);
11063+ else
11064+#endif
11065+ return pte_clear_flags(pte, _PAGE_USER);
11066 }
11067
11068 static inline pte_t pte_mkdirty(pte_t pte)
11069@@ -302,6 +362,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11070 #endif
11071
11072 #ifndef __ASSEMBLY__
11073+
11074+#ifdef CONFIG_PAX_PER_CPU_PGD
11075+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11076+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11077+{
11078+ return cpu_pgd[cpu];
11079+}
11080+#endif
11081+
11082 #include <linux/mm_types.h>
11083
11084 static inline int pte_none(pte_t pte)
11085@@ -472,7 +541,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11086
11087 static inline int pgd_bad(pgd_t pgd)
11088 {
11089- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11090+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11091 }
11092
11093 static inline int pgd_none(pgd_t pgd)
11094@@ -495,7 +564,12 @@ static inline int pgd_none(pgd_t pgd)
11095 * pgd_offset() returns a (pgd_t *)
11096 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11097 */
11098-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11099+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11100+
11101+#ifdef CONFIG_PAX_PER_CPU_PGD
11102+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11103+#endif
11104+
11105 /*
11106 * a shortcut which implies the use of the kernel's pgd, instead
11107 * of a process's
11108@@ -506,6 +580,20 @@ static inline int pgd_none(pgd_t pgd)
11109 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11110 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11111
11112+#ifdef CONFIG_X86_32
11113+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11114+#else
11115+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11116+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11117+
11118+#ifdef CONFIG_PAX_MEMORY_UDEREF
11119+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11120+#else
11121+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11122+#endif
11123+
11124+#endif
11125+
11126 #ifndef __ASSEMBLY__
11127
11128 extern int direct_gbpages;
11129@@ -611,11 +699,23 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm,
11130 * dst and src can be on the same page, but the range must not overlap,
11131 * and must not cross a page boundary.
11132 */
11133-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11134+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11135 {
11136- memcpy(dst, src, count * sizeof(pgd_t));
11137+ pax_open_kernel();
11138+ while (count--)
11139+ *dst++ = *src++;
11140+ pax_close_kernel();
11141 }
11142
11143+#ifdef CONFIG_PAX_PER_CPU_PGD
11144+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11145+#endif
11146+
11147+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11148+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11149+#else
11150+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
11151+#endif
11152
11153 #include <asm-generic/pgtable.h>
11154 #endif /* __ASSEMBLY__ */
11155diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11156index 750f1bf..971e839 100644
11157--- a/arch/x86/include/asm/pgtable_32.h
11158+++ b/arch/x86/include/asm/pgtable_32.h
11159@@ -26,9 +26,6 @@
11160 struct mm_struct;
11161 struct vm_area_struct;
11162
11163-extern pgd_t swapper_pg_dir[1024];
11164-extern pgd_t trampoline_pg_dir[1024];
11165-
11166 static inline void pgtable_cache_init(void) { }
11167 static inline void check_pgt_cache(void) { }
11168 void paging_init(void);
11169@@ -49,6 +46,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11170 # include <asm/pgtable-2level.h>
11171 #endif
11172
11173+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11174+extern pgd_t trampoline_pg_dir[PTRS_PER_PGD];
11175+#ifdef CONFIG_X86_PAE
11176+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11177+#endif
11178+
11179 #if defined(CONFIG_HIGHPTE)
11180 #define __KM_PTE \
11181 (in_nmi() ? KM_NMI_PTE : \
11182@@ -73,7 +76,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11183 /* Clear a kernel PTE and flush it from the TLB */
11184 #define kpte_clear_flush(ptep, vaddr) \
11185 do { \
11186+ pax_open_kernel(); \
11187 pte_clear(&init_mm, (vaddr), (ptep)); \
11188+ pax_close_kernel(); \
11189 __flush_tlb_one((vaddr)); \
11190 } while (0)
11191
11192@@ -85,6 +90,9 @@ do { \
11193
11194 #endif /* !__ASSEMBLY__ */
11195
11196+#define HAVE_ARCH_UNMAPPED_AREA
11197+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11198+
11199 /*
11200 * kern_addr_valid() is (1) for FLATMEM and (0) for
11201 * SPARSEMEM and DISCONTIGMEM
11202diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11203index 5e67c15..12d5c47 100644
11204--- a/arch/x86/include/asm/pgtable_32_types.h
11205+++ b/arch/x86/include/asm/pgtable_32_types.h
11206@@ -8,7 +8,7 @@
11207 */
11208 #ifdef CONFIG_X86_PAE
11209 # include <asm/pgtable-3level_types.h>
11210-# define PMD_SIZE (1UL << PMD_SHIFT)
11211+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11212 # define PMD_MASK (~(PMD_SIZE - 1))
11213 #else
11214 # include <asm/pgtable-2level_types.h>
11215@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11216 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11217 #endif
11218
11219+#ifdef CONFIG_PAX_KERNEXEC
11220+#ifndef __ASSEMBLY__
11221+extern unsigned char MODULES_EXEC_VADDR[];
11222+extern unsigned char MODULES_EXEC_END[];
11223+#endif
11224+#include <asm/boot.h>
11225+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11226+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11227+#else
11228+#define ktla_ktva(addr) (addr)
11229+#define ktva_ktla(addr) (addr)
11230+#endif
11231+
11232 #define MODULES_VADDR VMALLOC_START
11233 #define MODULES_END VMALLOC_END
11234 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11235diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11236index c57a301..6b414ff 100644
11237--- a/arch/x86/include/asm/pgtable_64.h
11238+++ b/arch/x86/include/asm/pgtable_64.h
11239@@ -16,10 +16,14 @@
11240
11241 extern pud_t level3_kernel_pgt[512];
11242 extern pud_t level3_ident_pgt[512];
11243+extern pud_t level3_vmalloc_start_pgt[512];
11244+extern pud_t level3_vmalloc_end_pgt[512];
11245+extern pud_t level3_vmemmap_pgt[512];
11246+extern pud_t level2_vmemmap_pgt[512];
11247 extern pmd_t level2_kernel_pgt[512];
11248 extern pmd_t level2_fixmap_pgt[512];
11249-extern pmd_t level2_ident_pgt[512];
11250-extern pgd_t init_level4_pgt[];
11251+extern pmd_t level2_ident_pgt[512*2];
11252+extern pgd_t init_level4_pgt[512];
11253
11254 #define swapper_pg_dir init_level4_pgt
11255
11256@@ -74,7 +78,9 @@ static inline pte_t native_ptep_get_and_clear(pte_t *xp)
11257
11258 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11259 {
11260+ pax_open_kernel();
11261 *pmdp = pmd;
11262+ pax_close_kernel();
11263 }
11264
11265 static inline void native_pmd_clear(pmd_t *pmd)
11266@@ -94,6 +100,13 @@ static inline void native_pud_clear(pud_t *pud)
11267
11268 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11269 {
11270+ pax_open_kernel();
11271+ *pgdp = pgd;
11272+ pax_close_kernel();
11273+}
11274+
11275+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11276+{
11277 *pgdp = pgd;
11278 }
11279
11280diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11281index 766ea16..5b96cb3 100644
11282--- a/arch/x86/include/asm/pgtable_64_types.h
11283+++ b/arch/x86/include/asm/pgtable_64_types.h
11284@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11285 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11286 #define MODULES_END _AC(0xffffffffff000000, UL)
11287 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11288+#define MODULES_EXEC_VADDR MODULES_VADDR
11289+#define MODULES_EXEC_END MODULES_END
11290+
11291+#define ktla_ktva(addr) (addr)
11292+#define ktva_ktla(addr) (addr)
11293
11294 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11295diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11296index d1f4a76..2f46ba1 100644
11297--- a/arch/x86/include/asm/pgtable_types.h
11298+++ b/arch/x86/include/asm/pgtable_types.h
11299@@ -16,12 +16,11 @@
11300 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11301 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11302 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11303-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11304+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11305 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11306 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11307 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11308-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11309-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11310+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11311 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11312
11313 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11314@@ -39,7 +38,6 @@
11315 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11316 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11317 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11318-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11319 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11320 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11321 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11322@@ -55,8 +53,10 @@
11323
11324 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11325 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11326-#else
11327+#elif defined(CONFIG_KMEMCHECK)
11328 #define _PAGE_NX (_AT(pteval_t, 0))
11329+#else
11330+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11331 #endif
11332
11333 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11334@@ -93,6 +93,9 @@
11335 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11336 _PAGE_ACCESSED)
11337
11338+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11339+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11340+
11341 #define __PAGE_KERNEL_EXEC \
11342 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11343 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11344@@ -103,8 +106,8 @@
11345 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11346 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11347 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11348-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11349-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
11350+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11351+#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
11352 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11353 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
11354 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
11355@@ -163,8 +166,8 @@
11356 * bits are combined, this will alow user to access the high address mapped
11357 * VDSO in the presence of CONFIG_COMPAT_VDSO
11358 */
11359-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11360-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11361+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11362+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11363 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11364 #endif
11365
11366@@ -202,7 +205,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11367 {
11368 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11369 }
11370+#endif
11371
11372+#if PAGETABLE_LEVELS == 3
11373+#include <asm-generic/pgtable-nopud.h>
11374+#endif
11375+
11376+#if PAGETABLE_LEVELS == 2
11377+#include <asm-generic/pgtable-nopmd.h>
11378+#endif
11379+
11380+#ifndef __ASSEMBLY__
11381 #if PAGETABLE_LEVELS > 3
11382 typedef struct { pudval_t pud; } pud_t;
11383
11384@@ -216,8 +229,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11385 return pud.pud;
11386 }
11387 #else
11388-#include <asm-generic/pgtable-nopud.h>
11389-
11390 static inline pudval_t native_pud_val(pud_t pud)
11391 {
11392 return native_pgd_val(pud.pgd);
11393@@ -237,8 +248,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11394 return pmd.pmd;
11395 }
11396 #else
11397-#include <asm-generic/pgtable-nopmd.h>
11398-
11399 static inline pmdval_t native_pmd_val(pmd_t pmd)
11400 {
11401 return native_pgd_val(pmd.pud.pgd);
11402@@ -278,7 +287,16 @@ typedef struct page *pgtable_t;
11403
11404 extern pteval_t __supported_pte_mask;
11405 extern void set_nx(void);
11406+
11407+#ifdef CONFIG_X86_32
11408+#ifdef CONFIG_X86_PAE
11409 extern int nx_enabled;
11410+#else
11411+#define nx_enabled (0)
11412+#endif
11413+#else
11414+#define nx_enabled (1)
11415+#endif
11416
11417 #define pgprot_writecombine pgprot_writecombine
11418 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11419diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11420index fa04dea..5f823fc 100644
11421--- a/arch/x86/include/asm/processor.h
11422+++ b/arch/x86/include/asm/processor.h
11423@@ -272,7 +272,7 @@ struct tss_struct {
11424
11425 } ____cacheline_aligned;
11426
11427-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11428+extern struct tss_struct init_tss[NR_CPUS];
11429
11430 /*
11431 * Save the original ist values for checking stack pointers during debugging
11432@@ -911,11 +911,18 @@ static inline void spin_lock_prefetch(const void *x)
11433 */
11434 #define TASK_SIZE PAGE_OFFSET
11435 #define TASK_SIZE_MAX TASK_SIZE
11436+
11437+#ifdef CONFIG_PAX_SEGMEXEC
11438+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11439+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11440+#else
11441 #define STACK_TOP TASK_SIZE
11442-#define STACK_TOP_MAX STACK_TOP
11443+#endif
11444+
11445+#define STACK_TOP_MAX TASK_SIZE
11446
11447 #define INIT_THREAD { \
11448- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11449+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11450 .vm86_info = NULL, \
11451 .sysenter_cs = __KERNEL_CS, \
11452 .io_bitmap_ptr = NULL, \
11453@@ -929,7 +936,7 @@ static inline void spin_lock_prefetch(const void *x)
11454 */
11455 #define INIT_TSS { \
11456 .x86_tss = { \
11457- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11458+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11459 .ss0 = __KERNEL_DS, \
11460 .ss1 = __KERNEL_CS, \
11461 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11462@@ -940,11 +947,7 @@ static inline void spin_lock_prefetch(const void *x)
11463 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11464
11465 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11466-#define KSTK_TOP(info) \
11467-({ \
11468- unsigned long *__ptr = (unsigned long *)(info); \
11469- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11470-})
11471+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11472
11473 /*
11474 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11475@@ -959,7 +962,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11476 #define task_pt_regs(task) \
11477 ({ \
11478 struct pt_regs *__regs__; \
11479- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11480+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11481 __regs__ - 1; \
11482 })
11483
11484@@ -969,13 +972,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11485 /*
11486 * User space process size. 47bits minus one guard page.
11487 */
11488-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11489+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11490
11491 /* This decides where the kernel will search for a free chunk of vm
11492 * space during mmap's.
11493 */
11494 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11495- 0xc0000000 : 0xFFFFe000)
11496+ 0xc0000000 : 0xFFFFf000)
11497
11498 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11499 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11500@@ -986,11 +989,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11501 #define STACK_TOP_MAX TASK_SIZE_MAX
11502
11503 #define INIT_THREAD { \
11504- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11505+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11506 }
11507
11508 #define INIT_TSS { \
11509- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11510+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11511 }
11512
11513 /*
11514@@ -1012,6 +1015,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11515 */
11516 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11517
11518+#ifdef CONFIG_PAX_SEGMEXEC
11519+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11520+#endif
11521+
11522 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11523
11524 /* Get/set a process' ability to use the timestamp counter instruction */
11525diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11526index 0f0d908..f2e3da2 100644
11527--- a/arch/x86/include/asm/ptrace.h
11528+++ b/arch/x86/include/asm/ptrace.h
11529@@ -151,28 +151,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11530 }
11531
11532 /*
11533- * user_mode_vm(regs) determines whether a register set came from user mode.
11534+ * user_mode(regs) determines whether a register set came from user mode.
11535 * This is true if V8086 mode was enabled OR if the register set was from
11536 * protected mode with RPL-3 CS value. This tricky test checks that with
11537 * one comparison. Many places in the kernel can bypass this full check
11538- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11539+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11540+ * be used.
11541 */
11542-static inline int user_mode(struct pt_regs *regs)
11543+static inline int user_mode_novm(struct pt_regs *regs)
11544 {
11545 #ifdef CONFIG_X86_32
11546 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11547 #else
11548- return !!(regs->cs & 3);
11549+ return !!(regs->cs & SEGMENT_RPL_MASK);
11550 #endif
11551 }
11552
11553-static inline int user_mode_vm(struct pt_regs *regs)
11554+static inline int user_mode(struct pt_regs *regs)
11555 {
11556 #ifdef CONFIG_X86_32
11557 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11558 USER_RPL;
11559 #else
11560- return user_mode(regs);
11561+ return user_mode_novm(regs);
11562 #endif
11563 }
11564
11565diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11566index 562d4fd..6e39df1 100644
11567--- a/arch/x86/include/asm/reboot.h
11568+++ b/arch/x86/include/asm/reboot.h
11569@@ -6,19 +6,19 @@
11570 struct pt_regs;
11571
11572 struct machine_ops {
11573- void (*restart)(char *cmd);
11574- void (*halt)(void);
11575- void (*power_off)(void);
11576+ void (* __noreturn restart)(char *cmd);
11577+ void (* __noreturn halt)(void);
11578+ void (* __noreturn power_off)(void);
11579 void (*shutdown)(void);
11580 void (*crash_shutdown)(struct pt_regs *);
11581- void (*emergency_restart)(void);
11582-};
11583+ void (* __noreturn emergency_restart)(void);
11584+} __no_const;
11585
11586 extern struct machine_ops machine_ops;
11587
11588 void native_machine_crash_shutdown(struct pt_regs *regs);
11589 void native_machine_shutdown(void);
11590-void machine_real_restart(const unsigned char *code, int length);
11591+void machine_real_restart(const unsigned char *code, unsigned int length) __noreturn;
11592
11593 typedef void (*nmi_shootdown_cb)(int, struct die_args*);
11594 void nmi_shootdown_cpus(nmi_shootdown_cb callback);
11595diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11596index 606ede1..dbfff37 100644
11597--- a/arch/x86/include/asm/rwsem.h
11598+++ b/arch/x86/include/asm/rwsem.h
11599@@ -118,6 +118,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11600 {
11601 asm volatile("# beginning down_read\n\t"
11602 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11603+
11604+#ifdef CONFIG_PAX_REFCOUNT
11605+ "jno 0f\n"
11606+ LOCK_PREFIX _ASM_DEC "(%1)\n\t"
11607+ "int $4\n0:\n"
11608+ _ASM_EXTABLE(0b, 0b)
11609+#endif
11610+
11611 /* adds 0x00000001, returns the old value */
11612 " jns 1f\n"
11613 " call call_rwsem_down_read_failed\n"
11614@@ -139,6 +147,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11615 "1:\n\t"
11616 " mov %1,%2\n\t"
11617 " add %3,%2\n\t"
11618+
11619+#ifdef CONFIG_PAX_REFCOUNT
11620+ "jno 0f\n"
11621+ "sub %3,%2\n"
11622+ "int $4\n0:\n"
11623+ _ASM_EXTABLE(0b, 0b)
11624+#endif
11625+
11626 " jle 2f\n\t"
11627 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11628 " jnz 1b\n\t"
11629@@ -160,6 +176,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11630 tmp = RWSEM_ACTIVE_WRITE_BIAS;
11631 asm volatile("# beginning down_write\n\t"
11632 LOCK_PREFIX " xadd %1,(%2)\n\t"
11633+
11634+#ifdef CONFIG_PAX_REFCOUNT
11635+ "jno 0f\n"
11636+ "mov %1,(%2)\n"
11637+ "int $4\n0:\n"
11638+ _ASM_EXTABLE(0b, 0b)
11639+#endif
11640+
11641 /* subtract 0x0000ffff, returns the old value */
11642 " test %1,%1\n\t"
11643 /* was the count 0 before? */
11644@@ -198,6 +222,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11645 rwsem_count_t tmp = -RWSEM_ACTIVE_READ_BIAS;
11646 asm volatile("# beginning __up_read\n\t"
11647 LOCK_PREFIX " xadd %1,(%2)\n\t"
11648+
11649+#ifdef CONFIG_PAX_REFCOUNT
11650+ "jno 0f\n"
11651+ "mov %1,(%2)\n"
11652+ "int $4\n0:\n"
11653+ _ASM_EXTABLE(0b, 0b)
11654+#endif
11655+
11656 /* subtracts 1, returns the old value */
11657 " jns 1f\n\t"
11658 " call call_rwsem_wake\n"
11659@@ -216,6 +248,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11660 rwsem_count_t tmp;
11661 asm volatile("# beginning __up_write\n\t"
11662 LOCK_PREFIX " xadd %1,(%2)\n\t"
11663+
11664+#ifdef CONFIG_PAX_REFCOUNT
11665+ "jno 0f\n"
11666+ "mov %1,(%2)\n"
11667+ "int $4\n0:\n"
11668+ _ASM_EXTABLE(0b, 0b)
11669+#endif
11670+
11671 /* tries to transition
11672 0xffff0001 -> 0x00000000 */
11673 " jz 1f\n"
11674@@ -234,6 +274,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11675 {
11676 asm volatile("# beginning __downgrade_write\n\t"
11677 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11678+
11679+#ifdef CONFIG_PAX_REFCOUNT
11680+ "jno 0f\n"
11681+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11682+ "int $4\n0:\n"
11683+ _ASM_EXTABLE(0b, 0b)
11684+#endif
11685+
11686 /*
11687 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11688 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11689@@ -253,7 +301,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11690 static inline void rwsem_atomic_add(rwsem_count_t delta,
11691 struct rw_semaphore *sem)
11692 {
11693- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11694+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11695+
11696+#ifdef CONFIG_PAX_REFCOUNT
11697+ "jno 0f\n"
11698+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
11699+ "int $4\n0:\n"
11700+ _ASM_EXTABLE(0b, 0b)
11701+#endif
11702+
11703 : "+m" (sem->count)
11704 : "er" (delta));
11705 }
11706@@ -266,7 +322,15 @@ static inline rwsem_count_t rwsem_atomic_update(rwsem_count_t delta,
11707 {
11708 rwsem_count_t tmp = delta;
11709
11710- asm volatile(LOCK_PREFIX "xadd %0,%1"
11711+ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
11712+
11713+#ifdef CONFIG_PAX_REFCOUNT
11714+ "jno 0f\n"
11715+ "mov %0,%1\n"
11716+ "int $4\n0:\n"
11717+ _ASM_EXTABLE(0b, 0b)
11718+#endif
11719+
11720 : "+r" (tmp), "+m" (sem->count)
11721 : : "memory");
11722
11723diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11724index 14e0ed8..7f7dd5e 100644
11725--- a/arch/x86/include/asm/segment.h
11726+++ b/arch/x86/include/asm/segment.h
11727@@ -62,10 +62,15 @@
11728 * 26 - ESPFIX small SS
11729 * 27 - per-cpu [ offset to per-cpu data area ]
11730 * 28 - stack_canary-20 [ for stack protector ]
11731- * 29 - unused
11732- * 30 - unused
11733+ * 29 - PCI BIOS CS
11734+ * 30 - PCI BIOS DS
11735 * 31 - TSS for double fault handler
11736 */
11737+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11738+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11739+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11740+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11741+
11742 #define GDT_ENTRY_TLS_MIN 6
11743 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11744
11745@@ -77,6 +82,8 @@
11746
11747 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0)
11748
11749+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11750+
11751 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1)
11752
11753 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE + 4)
11754@@ -88,7 +95,7 @@
11755 #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
11756 #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
11757
11758-#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
11759+#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
11760 #ifdef CONFIG_SMP
11761 #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
11762 #else
11763@@ -102,6 +109,12 @@
11764 #define __KERNEL_STACK_CANARY 0
11765 #endif
11766
11767+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 17)
11768+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11769+
11770+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 18)
11771+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11772+
11773 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11774
11775 /*
11776@@ -139,7 +152,7 @@
11777 */
11778
11779 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11780-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11781+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11782
11783
11784 #else
11785@@ -163,6 +176,8 @@
11786 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
11787 #define __USER32_DS __USER_DS
11788
11789+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11790+
11791 #define GDT_ENTRY_TSS 8 /* needs two entries */
11792 #define GDT_ENTRY_LDT 10 /* needs two entries */
11793 #define GDT_ENTRY_TLS_MIN 12
11794@@ -183,6 +198,7 @@
11795 #endif
11796
11797 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
11798+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS * 8)
11799 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
11800 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS* 8 + 3)
11801 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS* 8 + 3)
11802diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11803index 4c2f63c..5685db2 100644
11804--- a/arch/x86/include/asm/smp.h
11805+++ b/arch/x86/include/asm/smp.h
11806@@ -24,7 +24,7 @@ extern unsigned int num_processors;
11807 DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
11808 DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11809 DECLARE_PER_CPU(u16, cpu_llc_id);
11810-DECLARE_PER_CPU(int, cpu_number);
11811+DECLARE_PER_CPU(unsigned int, cpu_number);
11812
11813 static inline struct cpumask *cpu_sibling_mask(int cpu)
11814 {
11815@@ -40,10 +40,7 @@ DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
11816 DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
11817
11818 /* Static state in head.S used to set up a CPU */
11819-extern struct {
11820- void *sp;
11821- unsigned short ss;
11822-} stack_start;
11823+extern unsigned long stack_start; /* Initial stack pointer address */
11824
11825 struct smp_ops {
11826 void (*smp_prepare_boot_cpu)(void);
11827@@ -60,7 +57,7 @@ struct smp_ops {
11828
11829 void (*send_call_func_ipi)(const struct cpumask *mask);
11830 void (*send_call_func_single_ipi)(int cpu);
11831-};
11832+} __no_const;
11833
11834 /* Globals due to paravirt */
11835 extern void set_cpu_sibling_map(int cpu);
11836@@ -175,14 +172,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11837 extern int safe_smp_processor_id(void);
11838
11839 #elif defined(CONFIG_X86_64_SMP)
11840-#define raw_smp_processor_id() (percpu_read(cpu_number))
11841-
11842-#define stack_smp_processor_id() \
11843-({ \
11844- struct thread_info *ti; \
11845- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11846- ti->cpu; \
11847-})
11848+#define raw_smp_processor_id() (percpu_read(cpu_number))
11849+#define stack_smp_processor_id() raw_smp_processor_id()
11850 #define safe_smp_processor_id() smp_processor_id()
11851
11852 #endif
11853diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11854index 4e77853..4359783 100644
11855--- a/arch/x86/include/asm/spinlock.h
11856+++ b/arch/x86/include/asm/spinlock.h
11857@@ -249,6 +249,14 @@ static inline int __raw_write_can_lock(raw_rwlock_t *lock)
11858 static inline void __raw_read_lock(raw_rwlock_t *rw)
11859 {
11860 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
11861+
11862+#ifdef CONFIG_PAX_REFCOUNT
11863+ "jno 0f\n"
11864+ LOCK_PREFIX " addl $1,(%0)\n"
11865+ "int $4\n0:\n"
11866+ _ASM_EXTABLE(0b, 0b)
11867+#endif
11868+
11869 "jns 1f\n"
11870 "call __read_lock_failed\n\t"
11871 "1:\n"
11872@@ -258,6 +266,14 @@ static inline void __raw_read_lock(raw_rwlock_t *rw)
11873 static inline void __raw_write_lock(raw_rwlock_t *rw)
11874 {
11875 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
11876+
11877+#ifdef CONFIG_PAX_REFCOUNT
11878+ "jno 0f\n"
11879+ LOCK_PREFIX " addl %1,(%0)\n"
11880+ "int $4\n0:\n"
11881+ _ASM_EXTABLE(0b, 0b)
11882+#endif
11883+
11884 "jz 1f\n"
11885 "call __write_lock_failed\n\t"
11886 "1:\n"
11887@@ -286,12 +302,29 @@ static inline int __raw_write_trylock(raw_rwlock_t *lock)
11888
11889 static inline void __raw_read_unlock(raw_rwlock_t *rw)
11890 {
11891- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
11892+ asm volatile(LOCK_PREFIX "incl %0\n"
11893+
11894+#ifdef CONFIG_PAX_REFCOUNT
11895+ "jno 0f\n"
11896+ LOCK_PREFIX "decl %0\n"
11897+ "int $4\n0:\n"
11898+ _ASM_EXTABLE(0b, 0b)
11899+#endif
11900+
11901+ :"+m" (rw->lock) : : "memory");
11902 }
11903
11904 static inline void __raw_write_unlock(raw_rwlock_t *rw)
11905 {
11906- asm volatile(LOCK_PREFIX "addl %1, %0"
11907+ asm volatile(LOCK_PREFIX "addl %1, %0\n"
11908+
11909+#ifdef CONFIG_PAX_REFCOUNT
11910+ "jno 0f\n"
11911+ LOCK_PREFIX "subl %1, %0\n"
11912+ "int $4\n0:\n"
11913+ _ASM_EXTABLE(0b, 0b)
11914+#endif
11915+
11916 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
11917 }
11918
11919diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11920index 1575177..cb23f52 100644
11921--- a/arch/x86/include/asm/stackprotector.h
11922+++ b/arch/x86/include/asm/stackprotector.h
11923@@ -48,7 +48,7 @@
11924 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11925 */
11926 #define GDT_STACK_CANARY_INIT \
11927- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11928+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11929
11930 /*
11931 * Initialize the stackprotector canary value.
11932@@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11933
11934 static inline void load_stack_canary_segment(void)
11935 {
11936-#ifdef CONFIG_X86_32
11937+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11938 asm volatile ("mov %0, %%gs" : : "r" (0));
11939 #endif
11940 }
11941diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11942index e0fbf29..858ef4a 100644
11943--- a/arch/x86/include/asm/system.h
11944+++ b/arch/x86/include/asm/system.h
11945@@ -132,7 +132,7 @@ do { \
11946 "thread_return:\n\t" \
11947 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11948 __switch_canary \
11949- "movq %P[thread_info](%%rsi),%%r8\n\t" \
11950+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11951 "movq %%rax,%%rdi\n\t" \
11952 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11953 "jnz ret_from_fork\n\t" \
11954@@ -143,7 +143,7 @@ do { \
11955 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11956 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11957 [_tif_fork] "i" (_TIF_FORK), \
11958- [thread_info] "i" (offsetof(struct task_struct, stack)), \
11959+ [thread_info] "m" (per_cpu_var(current_tinfo)), \
11960 [current_task] "m" (per_cpu_var(current_task)) \
11961 __switch_canary_iparam \
11962 : "memory", "cc" __EXTRA_CLOBBER)
11963@@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11964 {
11965 unsigned long __limit;
11966 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11967- return __limit + 1;
11968+ return __limit;
11969 }
11970
11971 static inline void native_clts(void)
11972@@ -340,12 +340,12 @@ void enable_hlt(void);
11973
11974 void cpu_idle_wait(void);
11975
11976-extern unsigned long arch_align_stack(unsigned long sp);
11977+#define arch_align_stack(x) ((x) & ~0xfUL)
11978 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11979
11980 void default_idle(void);
11981
11982-void stop_this_cpu(void *dummy);
11983+void stop_this_cpu(void *dummy) __noreturn;
11984
11985 /*
11986 * Force strict CPU ordering.
11987diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11988index 19c3ce4..8962535 100644
11989--- a/arch/x86/include/asm/thread_info.h
11990+++ b/arch/x86/include/asm/thread_info.h
11991@@ -10,6 +10,7 @@
11992 #include <linux/compiler.h>
11993 #include <asm/page.h>
11994 #include <asm/types.h>
11995+#include <asm/percpu.h>
11996
11997 /*
11998 * low level task data that entry.S needs immediate access to
11999@@ -24,7 +25,6 @@ struct exec_domain;
12000 #include <asm/atomic.h>
12001
12002 struct thread_info {
12003- struct task_struct *task; /* main task structure */
12004 struct exec_domain *exec_domain; /* execution domain */
12005 __u32 flags; /* low level flags */
12006 __u32 status; /* thread synchronous flags */
12007@@ -34,18 +34,12 @@ struct thread_info {
12008 mm_segment_t addr_limit;
12009 struct restart_block restart_block;
12010 void __user *sysenter_return;
12011-#ifdef CONFIG_X86_32
12012- unsigned long previous_esp; /* ESP of the previous stack in
12013- case of nested (IRQ) stacks
12014- */
12015- __u8 supervisor_stack[0];
12016-#endif
12017+ unsigned long lowest_stack;
12018 int uaccess_err;
12019 };
12020
12021-#define INIT_THREAD_INFO(tsk) \
12022+#define INIT_THREAD_INFO \
12023 { \
12024- .task = &tsk, \
12025 .exec_domain = &default_exec_domain, \
12026 .flags = 0, \
12027 .cpu = 0, \
12028@@ -56,7 +50,7 @@ struct thread_info {
12029 }, \
12030 }
12031
12032-#define init_thread_info (init_thread_union.thread_info)
12033+#define init_thread_info (init_thread_union.stack)
12034 #define init_stack (init_thread_union.stack)
12035
12036 #else /* !__ASSEMBLY__ */
12037@@ -163,45 +157,40 @@ struct thread_info {
12038 #define alloc_thread_info(tsk) \
12039 ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
12040
12041-#ifdef CONFIG_X86_32
12042-
12043-#define STACK_WARN (THREAD_SIZE/8)
12044-/*
12045- * macros/functions for gaining access to the thread information structure
12046- *
12047- * preempt_count needs to be 1 initially, until the scheduler is functional.
12048- */
12049-#ifndef __ASSEMBLY__
12050-
12051-
12052-/* how to get the current stack pointer from C */
12053-register unsigned long current_stack_pointer asm("esp") __used;
12054-
12055-/* how to get the thread information struct from C */
12056-static inline struct thread_info *current_thread_info(void)
12057-{
12058- return (struct thread_info *)
12059- (current_stack_pointer & ~(THREAD_SIZE - 1));
12060-}
12061-
12062-#else /* !__ASSEMBLY__ */
12063-
12064+#ifdef __ASSEMBLY__
12065 /* how to get the thread information struct from ASM */
12066 #define GET_THREAD_INFO(reg) \
12067- movl $-THREAD_SIZE, reg; \
12068- andl %esp, reg
12069+ mov PER_CPU_VAR(current_tinfo), reg
12070
12071 /* use this one if reg already contains %esp */
12072-#define GET_THREAD_INFO_WITH_ESP(reg) \
12073- andl $-THREAD_SIZE, reg
12074+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12075+#else
12076+/* how to get the thread information struct from C */
12077+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12078+
12079+static __always_inline struct thread_info *current_thread_info(void)
12080+{
12081+ return percpu_read_stable(current_tinfo);
12082+}
12083+#endif
12084+
12085+#ifdef CONFIG_X86_32
12086+
12087+#define STACK_WARN (THREAD_SIZE/8)
12088+/*
12089+ * macros/functions for gaining access to the thread information structure
12090+ *
12091+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12092+ */
12093+#ifndef __ASSEMBLY__
12094+
12095+/* how to get the current stack pointer from C */
12096+register unsigned long current_stack_pointer asm("esp") __used;
12097
12098 #endif
12099
12100 #else /* X86_32 */
12101
12102-#include <asm/percpu.h>
12103-#define KERNEL_STACK_OFFSET (5*8)
12104-
12105 /*
12106 * macros/functions for gaining access to the thread information structure
12107 * preempt_count needs to be 1 initially, until the scheduler is functional.
12108@@ -209,21 +198,8 @@ static inline struct thread_info *current_thread_info(void)
12109 #ifndef __ASSEMBLY__
12110 DECLARE_PER_CPU(unsigned long, kernel_stack);
12111
12112-static inline struct thread_info *current_thread_info(void)
12113-{
12114- struct thread_info *ti;
12115- ti = (void *)(percpu_read_stable(kernel_stack) +
12116- KERNEL_STACK_OFFSET - THREAD_SIZE);
12117- return ti;
12118-}
12119-
12120-#else /* !__ASSEMBLY__ */
12121-
12122-/* how to get the thread information struct from ASM */
12123-#define GET_THREAD_INFO(reg) \
12124- movq PER_CPU_VAR(kernel_stack),reg ; \
12125- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12126-
12127+/* how to get the current stack pointer from C */
12128+register unsigned long current_stack_pointer asm("rsp") __used;
12129 #endif
12130
12131 #endif /* !X86_32 */
12132@@ -260,5 +236,16 @@ extern void arch_task_cache_init(void);
12133 extern void free_thread_info(struct thread_info *ti);
12134 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12135 #define arch_task_cache_init arch_task_cache_init
12136+
12137+#define __HAVE_THREAD_FUNCTIONS
12138+#define task_thread_info(task) (&(task)->tinfo)
12139+#define task_stack_page(task) ((task)->stack)
12140+#define setup_thread_stack(p, org) do {} while (0)
12141+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12142+
12143+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12144+extern struct task_struct *alloc_task_struct(void);
12145+extern void free_task_struct(struct task_struct *);
12146+
12147 #endif
12148 #endif /* _ASM_X86_THREAD_INFO_H */
12149diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12150index 61c5874..8a046e9 100644
12151--- a/arch/x86/include/asm/uaccess.h
12152+++ b/arch/x86/include/asm/uaccess.h
12153@@ -8,12 +8,15 @@
12154 #include <linux/thread_info.h>
12155 #include <linux/prefetch.h>
12156 #include <linux/string.h>
12157+#include <linux/sched.h>
12158 #include <asm/asm.h>
12159 #include <asm/page.h>
12160
12161 #define VERIFY_READ 0
12162 #define VERIFY_WRITE 1
12163
12164+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12165+
12166 /*
12167 * The fs value determines whether argument validity checking should be
12168 * performed or not. If get_fs() == USER_DS, checking is performed, with
12169@@ -29,7 +32,12 @@
12170
12171 #define get_ds() (KERNEL_DS)
12172 #define get_fs() (current_thread_info()->addr_limit)
12173+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12174+void __set_fs(mm_segment_t x);
12175+void set_fs(mm_segment_t x);
12176+#else
12177 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12178+#endif
12179
12180 #define segment_eq(a, b) ((a).seg == (b).seg)
12181
12182@@ -77,7 +85,33 @@
12183 * checks that the pointer is in the user space range - after calling
12184 * this function, memory access functions may still return -EFAULT.
12185 */
12186-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12187+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12188+#define access_ok(type, addr, size) \
12189+({ \
12190+ long __size = size; \
12191+ unsigned long __addr = (unsigned long)addr; \
12192+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12193+ unsigned long __end_ao = __addr + __size - 1; \
12194+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12195+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12196+ while(__addr_ao <= __end_ao) { \
12197+ char __c_ao; \
12198+ __addr_ao += PAGE_SIZE; \
12199+ if (__size > PAGE_SIZE) \
12200+ cond_resched(); \
12201+ if (__get_user(__c_ao, (char __user *)__addr)) \
12202+ break; \
12203+ if (type != VERIFY_WRITE) { \
12204+ __addr = __addr_ao; \
12205+ continue; \
12206+ } \
12207+ if (__put_user(__c_ao, (char __user *)__addr)) \
12208+ break; \
12209+ __addr = __addr_ao; \
12210+ } \
12211+ } \
12212+ __ret_ao; \
12213+})
12214
12215 /*
12216 * The exception table consists of pairs of addresses: the first is the
12217@@ -183,12 +217,20 @@ extern int __get_user_bad(void);
12218 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12219 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12220
12221-
12222+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12223+#define __copyuser_seg "gs;"
12224+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12225+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12226+#else
12227+#define __copyuser_seg
12228+#define __COPYUSER_SET_ES
12229+#define __COPYUSER_RESTORE_ES
12230+#endif
12231
12232 #ifdef CONFIG_X86_32
12233 #define __put_user_asm_u64(x, addr, err, errret) \
12234- asm volatile("1: movl %%eax,0(%2)\n" \
12235- "2: movl %%edx,4(%2)\n" \
12236+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12237+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12238 "3:\n" \
12239 ".section .fixup,\"ax\"\n" \
12240 "4: movl %3,%0\n" \
12241@@ -200,8 +242,8 @@ extern int __get_user_bad(void);
12242 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12243
12244 #define __put_user_asm_ex_u64(x, addr) \
12245- asm volatile("1: movl %%eax,0(%1)\n" \
12246- "2: movl %%edx,4(%1)\n" \
12247+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12248+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12249 "3:\n" \
12250 _ASM_EXTABLE(1b, 2b - 1b) \
12251 _ASM_EXTABLE(2b, 3b - 2b) \
12252@@ -253,7 +295,7 @@ extern void __put_user_8(void);
12253 __typeof__(*(ptr)) __pu_val; \
12254 __chk_user_ptr(ptr); \
12255 might_fault(); \
12256- __pu_val = x; \
12257+ __pu_val = (x); \
12258 switch (sizeof(*(ptr))) { \
12259 case 1: \
12260 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12261@@ -374,7 +416,7 @@ do { \
12262 } while (0)
12263
12264 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12265- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12266+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12267 "2:\n" \
12268 ".section .fixup,\"ax\"\n" \
12269 "3: mov %3,%0\n" \
12270@@ -382,7 +424,7 @@ do { \
12271 " jmp 2b\n" \
12272 ".previous\n" \
12273 _ASM_EXTABLE(1b, 3b) \
12274- : "=r" (err), ltype(x) \
12275+ : "=r" (err), ltype (x) \
12276 : "m" (__m(addr)), "i" (errret), "0" (err))
12277
12278 #define __get_user_size_ex(x, ptr, size) \
12279@@ -407,7 +449,7 @@ do { \
12280 } while (0)
12281
12282 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12283- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12284+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12285 "2:\n" \
12286 _ASM_EXTABLE(1b, 2b - 1b) \
12287 : ltype(x) : "m" (__m(addr)))
12288@@ -424,13 +466,24 @@ do { \
12289 int __gu_err; \
12290 unsigned long __gu_val; \
12291 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12292- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12293+ (x) = (__typeof__(*(ptr)))__gu_val; \
12294 __gu_err; \
12295 })
12296
12297 /* FIXME: this hack is definitely wrong -AK */
12298 struct __large_struct { unsigned long buf[100]; };
12299-#define __m(x) (*(struct __large_struct __user *)(x))
12300+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12301+#define ____m(x) \
12302+({ \
12303+ unsigned long ____x = (unsigned long)(x); \
12304+ if (____x < PAX_USER_SHADOW_BASE) \
12305+ ____x += PAX_USER_SHADOW_BASE; \
12306+ (void __user *)____x; \
12307+})
12308+#else
12309+#define ____m(x) (x)
12310+#endif
12311+#define __m(x) (*(struct __large_struct __user *)____m(x))
12312
12313 /*
12314 * Tell gcc we read from memory instead of writing: this is because
12315@@ -438,7 +491,7 @@ struct __large_struct { unsigned long buf[100]; };
12316 * aliasing issues.
12317 */
12318 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12319- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12320+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12321 "2:\n" \
12322 ".section .fixup,\"ax\"\n" \
12323 "3: mov %3,%0\n" \
12324@@ -446,10 +499,10 @@ struct __large_struct { unsigned long buf[100]; };
12325 ".previous\n" \
12326 _ASM_EXTABLE(1b, 3b) \
12327 : "=r"(err) \
12328- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12329+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12330
12331 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12332- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12333+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12334 "2:\n" \
12335 _ASM_EXTABLE(1b, 2b - 1b) \
12336 : : ltype(x), "m" (__m(addr)))
12337@@ -488,8 +541,12 @@ struct __large_struct { unsigned long buf[100]; };
12338 * On error, the variable @x is set to zero.
12339 */
12340
12341+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12342+#define __get_user(x, ptr) get_user((x), (ptr))
12343+#else
12344 #define __get_user(x, ptr) \
12345 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12346+#endif
12347
12348 /**
12349 * __put_user: - Write a simple value into user space, with less checking.
12350@@ -511,8 +568,12 @@ struct __large_struct { unsigned long buf[100]; };
12351 * Returns zero on success, or -EFAULT on error.
12352 */
12353
12354+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12355+#define __put_user(x, ptr) put_user((x), (ptr))
12356+#else
12357 #define __put_user(x, ptr) \
12358 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12359+#endif
12360
12361 #define __get_user_unaligned __get_user
12362 #define __put_user_unaligned __put_user
12363@@ -530,7 +591,7 @@ struct __large_struct { unsigned long buf[100]; };
12364 #define get_user_ex(x, ptr) do { \
12365 unsigned long __gue_val; \
12366 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12367- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12368+ (x) = (__typeof__(*(ptr)))__gue_val; \
12369 } while (0)
12370
12371 #ifdef CONFIG_X86_WP_WORKS_OK
12372@@ -567,6 +628,7 @@ extern struct movsl_mask {
12373
12374 #define ARCH_HAS_NOCACHE_UACCESS 1
12375
12376+#define ARCH_HAS_SORT_EXTABLE
12377 #ifdef CONFIG_X86_32
12378 # include "uaccess_32.h"
12379 #else
12380diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12381index 632fb44..e30e334 100644
12382--- a/arch/x86/include/asm/uaccess_32.h
12383+++ b/arch/x86/include/asm/uaccess_32.h
12384@@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12385 static __always_inline unsigned long __must_check
12386 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12387 {
12388+ pax_track_stack();
12389+
12390+ if ((long)n < 0)
12391+ return n;
12392+
12393 if (__builtin_constant_p(n)) {
12394 unsigned long ret;
12395
12396@@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12397 return ret;
12398 }
12399 }
12400+ if (!__builtin_constant_p(n))
12401+ check_object_size(from, n, true);
12402 return __copy_to_user_ll(to, from, n);
12403 }
12404
12405@@ -83,12 +90,16 @@ static __always_inline unsigned long __must_check
12406 __copy_to_user(void __user *to, const void *from, unsigned long n)
12407 {
12408 might_fault();
12409+
12410 return __copy_to_user_inatomic(to, from, n);
12411 }
12412
12413 static __always_inline unsigned long
12414 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12415 {
12416+ if ((long)n < 0)
12417+ return n;
12418+
12419 /* Avoid zeroing the tail if the copy fails..
12420 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12421 * but as the zeroing behaviour is only significant when n is not
12422@@ -138,6 +149,12 @@ static __always_inline unsigned long
12423 __copy_from_user(void *to, const void __user *from, unsigned long n)
12424 {
12425 might_fault();
12426+
12427+ pax_track_stack();
12428+
12429+ if ((long)n < 0)
12430+ return n;
12431+
12432 if (__builtin_constant_p(n)) {
12433 unsigned long ret;
12434
12435@@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12436 return ret;
12437 }
12438 }
12439+ if (!__builtin_constant_p(n))
12440+ check_object_size(to, n, false);
12441 return __copy_from_user_ll(to, from, n);
12442 }
12443
12444@@ -160,6 +179,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12445 const void __user *from, unsigned long n)
12446 {
12447 might_fault();
12448+
12449+ if ((long)n < 0)
12450+ return n;
12451+
12452 if (__builtin_constant_p(n)) {
12453 unsigned long ret;
12454
12455@@ -182,14 +205,62 @@ static __always_inline unsigned long
12456 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12457 unsigned long n)
12458 {
12459- return __copy_from_user_ll_nocache_nozero(to, from, n);
12460+ if ((long)n < 0)
12461+ return n;
12462+
12463+ return __copy_from_user_ll_nocache_nozero(to, from, n);
12464+}
12465+
12466+/**
12467+ * copy_to_user: - Copy a block of data into user space.
12468+ * @to: Destination address, in user space.
12469+ * @from: Source address, in kernel space.
12470+ * @n: Number of bytes to copy.
12471+ *
12472+ * Context: User context only. This function may sleep.
12473+ *
12474+ * Copy data from kernel space to user space.
12475+ *
12476+ * Returns number of bytes that could not be copied.
12477+ * On success, this will be zero.
12478+ */
12479+static __always_inline unsigned long __must_check
12480+copy_to_user(void __user *to, const void *from, unsigned long n)
12481+{
12482+ if (access_ok(VERIFY_WRITE, to, n))
12483+ n = __copy_to_user(to, from, n);
12484+ return n;
12485+}
12486+
12487+/**
12488+ * copy_from_user: - Copy a block of data from user space.
12489+ * @to: Destination address, in kernel space.
12490+ * @from: Source address, in user space.
12491+ * @n: Number of bytes to copy.
12492+ *
12493+ * Context: User context only. This function may sleep.
12494+ *
12495+ * Copy data from user space to kernel space.
12496+ *
12497+ * Returns number of bytes that could not be copied.
12498+ * On success, this will be zero.
12499+ *
12500+ * If some data could not be copied, this function will pad the copied
12501+ * data to the requested size using zero bytes.
12502+ */
12503+static __always_inline unsigned long __must_check
12504+copy_from_user(void *to, const void __user *from, unsigned long n)
12505+{
12506+ if (access_ok(VERIFY_READ, from, n))
12507+ n = __copy_from_user(to, from, n);
12508+ else if ((long)n > 0) {
12509+ if (!__builtin_constant_p(n))
12510+ check_object_size(to, n, false);
12511+ memset(to, 0, n);
12512+ }
12513+ return n;
12514 }
12515
12516-unsigned long __must_check copy_to_user(void __user *to,
12517- const void *from, unsigned long n);
12518-unsigned long __must_check copy_from_user(void *to,
12519- const void __user *from,
12520- unsigned long n);
12521 long __must_check strncpy_from_user(char *dst, const char __user *src,
12522 long count);
12523 long __must_check __strncpy_from_user(char *dst,
12524diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12525index db24b21..f595ae7 100644
12526--- a/arch/x86/include/asm/uaccess_64.h
12527+++ b/arch/x86/include/asm/uaccess_64.h
12528@@ -9,6 +9,9 @@
12529 #include <linux/prefetch.h>
12530 #include <linux/lockdep.h>
12531 #include <asm/page.h>
12532+#include <asm/pgtable.h>
12533+
12534+#define set_fs(x) (current_thread_info()->addr_limit = (x))
12535
12536 /*
12537 * Copy To/From Userspace
12538@@ -16,116 +19,205 @@
12539
12540 /* Handles exceptions in both to and from, but doesn't do access_ok */
12541 __must_check unsigned long
12542-copy_user_generic(void *to, const void *from, unsigned len);
12543+copy_user_generic(void *to, const void *from, unsigned long len);
12544
12545 __must_check unsigned long
12546-copy_to_user(void __user *to, const void *from, unsigned len);
12547-__must_check unsigned long
12548-copy_from_user(void *to, const void __user *from, unsigned len);
12549-__must_check unsigned long
12550-copy_in_user(void __user *to, const void __user *from, unsigned len);
12551+copy_in_user(void __user *to, const void __user *from, unsigned long len);
12552
12553 static __always_inline __must_check
12554-int __copy_from_user(void *dst, const void __user *src, unsigned size)
12555+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12556 {
12557- int ret = 0;
12558+ unsigned ret = 0;
12559
12560 might_fault();
12561- if (!__builtin_constant_p(size))
12562- return copy_user_generic(dst, (__force void *)src, size);
12563+
12564+ if (size > INT_MAX)
12565+ return size;
12566+
12567+#ifdef CONFIG_PAX_MEMORY_UDEREF
12568+ if (!__access_ok(VERIFY_READ, src, size))
12569+ return size;
12570+#endif
12571+
12572+ if (!__builtin_constant_p(size)) {
12573+ check_object_size(dst, size, false);
12574+
12575+#ifdef CONFIG_PAX_MEMORY_UDEREF
12576+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12577+ src += PAX_USER_SHADOW_BASE;
12578+#endif
12579+
12580+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
12581+ }
12582 switch (size) {
12583- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12584+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12585 ret, "b", "b", "=q", 1);
12586 return ret;
12587- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12588+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12589 ret, "w", "w", "=r", 2);
12590 return ret;
12591- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12592+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12593 ret, "l", "k", "=r", 4);
12594 return ret;
12595- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12596+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12597 ret, "q", "", "=r", 8);
12598 return ret;
12599 case 10:
12600- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12601+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12602 ret, "q", "", "=r", 10);
12603 if (unlikely(ret))
12604 return ret;
12605 __get_user_asm(*(u16 *)(8 + (char *)dst),
12606- (u16 __user *)(8 + (char __user *)src),
12607+ (const u16 __user *)(8 + (const char __user *)src),
12608 ret, "w", "w", "=r", 2);
12609 return ret;
12610 case 16:
12611- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12612+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12613 ret, "q", "", "=r", 16);
12614 if (unlikely(ret))
12615 return ret;
12616 __get_user_asm(*(u64 *)(8 + (char *)dst),
12617- (u64 __user *)(8 + (char __user *)src),
12618+ (const u64 __user *)(8 + (const char __user *)src),
12619 ret, "q", "", "=r", 8);
12620 return ret;
12621 default:
12622- return copy_user_generic(dst, (__force void *)src, size);
12623+
12624+#ifdef CONFIG_PAX_MEMORY_UDEREF
12625+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12626+ src += PAX_USER_SHADOW_BASE;
12627+#endif
12628+
12629+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
12630 }
12631 }
12632
12633 static __always_inline __must_check
12634-int __copy_to_user(void __user *dst, const void *src, unsigned size)
12635+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12636 {
12637- int ret = 0;
12638+ unsigned ret = 0;
12639
12640 might_fault();
12641- if (!__builtin_constant_p(size))
12642- return copy_user_generic((__force void *)dst, src, size);
12643+
12644+ pax_track_stack();
12645+
12646+ if (size > INT_MAX)
12647+ return size;
12648+
12649+#ifdef CONFIG_PAX_MEMORY_UDEREF
12650+ if (!__access_ok(VERIFY_WRITE, dst, size))
12651+ return size;
12652+#endif
12653+
12654+ if (!__builtin_constant_p(size)) {
12655+ check_object_size(src, size, true);
12656+
12657+#ifdef CONFIG_PAX_MEMORY_UDEREF
12658+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12659+ dst += PAX_USER_SHADOW_BASE;
12660+#endif
12661+
12662+ return copy_user_generic((__force_kernel void *)dst, src, size);
12663+ }
12664 switch (size) {
12665- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12666+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12667 ret, "b", "b", "iq", 1);
12668 return ret;
12669- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12670+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12671 ret, "w", "w", "ir", 2);
12672 return ret;
12673- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12674+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12675 ret, "l", "k", "ir", 4);
12676 return ret;
12677- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12678+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12679 ret, "q", "", "er", 8);
12680 return ret;
12681 case 10:
12682- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12683+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12684 ret, "q", "", "er", 10);
12685 if (unlikely(ret))
12686 return ret;
12687 asm("":::"memory");
12688- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12689+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12690 ret, "w", "w", "ir", 2);
12691 return ret;
12692 case 16:
12693- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12694+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12695 ret, "q", "", "er", 16);
12696 if (unlikely(ret))
12697 return ret;
12698 asm("":::"memory");
12699- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12700+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12701 ret, "q", "", "er", 8);
12702 return ret;
12703 default:
12704- return copy_user_generic((__force void *)dst, src, size);
12705+
12706+#ifdef CONFIG_PAX_MEMORY_UDEREF
12707+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12708+ dst += PAX_USER_SHADOW_BASE;
12709+#endif
12710+
12711+ return copy_user_generic((__force_kernel void *)dst, src, size);
12712+ }
12713+}
12714+
12715+static __always_inline __must_check
12716+unsigned long copy_to_user(void __user *to, const void *from, unsigned long len)
12717+{
12718+ if (access_ok(VERIFY_WRITE, to, len))
12719+ len = __copy_to_user(to, from, len);
12720+ return len;
12721+}
12722+
12723+static __always_inline __must_check
12724+unsigned long copy_from_user(void *to, const void __user *from, unsigned long len)
12725+{
12726+ might_fault();
12727+
12728+ if (access_ok(VERIFY_READ, from, len))
12729+ len = __copy_from_user(to, from, len);
12730+ else if (len < INT_MAX) {
12731+ if (!__builtin_constant_p(len))
12732+ check_object_size(to, len, false);
12733+ memset(to, 0, len);
12734 }
12735+ return len;
12736 }
12737
12738 static __always_inline __must_check
12739-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12740+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12741 {
12742- int ret = 0;
12743+ unsigned ret = 0;
12744
12745 might_fault();
12746- if (!__builtin_constant_p(size))
12747- return copy_user_generic((__force void *)dst,
12748- (__force void *)src, size);
12749+
12750+ pax_track_stack();
12751+
12752+ if (size > INT_MAX)
12753+ return size;
12754+
12755+#ifdef CONFIG_PAX_MEMORY_UDEREF
12756+ if (!__access_ok(VERIFY_READ, src, size))
12757+ return size;
12758+ if (!__access_ok(VERIFY_WRITE, dst, size))
12759+ return size;
12760+#endif
12761+
12762+ if (!__builtin_constant_p(size)) {
12763+
12764+#ifdef CONFIG_PAX_MEMORY_UDEREF
12765+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12766+ src += PAX_USER_SHADOW_BASE;
12767+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12768+ dst += PAX_USER_SHADOW_BASE;
12769+#endif
12770+
12771+ return copy_user_generic((__force_kernel void *)dst,
12772+ (__force_kernel const void *)src, size);
12773+ }
12774 switch (size) {
12775 case 1: {
12776 u8 tmp;
12777- __get_user_asm(tmp, (u8 __user *)src,
12778+ __get_user_asm(tmp, (const u8 __user *)src,
12779 ret, "b", "b", "=q", 1);
12780 if (likely(!ret))
12781 __put_user_asm(tmp, (u8 __user *)dst,
12782@@ -134,7 +226,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12783 }
12784 case 2: {
12785 u16 tmp;
12786- __get_user_asm(tmp, (u16 __user *)src,
12787+ __get_user_asm(tmp, (const u16 __user *)src,
12788 ret, "w", "w", "=r", 2);
12789 if (likely(!ret))
12790 __put_user_asm(tmp, (u16 __user *)dst,
12791@@ -144,7 +236,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12792
12793 case 4: {
12794 u32 tmp;
12795- __get_user_asm(tmp, (u32 __user *)src,
12796+ __get_user_asm(tmp, (const u32 __user *)src,
12797 ret, "l", "k", "=r", 4);
12798 if (likely(!ret))
12799 __put_user_asm(tmp, (u32 __user *)dst,
12800@@ -153,7 +245,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12801 }
12802 case 8: {
12803 u64 tmp;
12804- __get_user_asm(tmp, (u64 __user *)src,
12805+ __get_user_asm(tmp, (const u64 __user *)src,
12806 ret, "q", "", "=r", 8);
12807 if (likely(!ret))
12808 __put_user_asm(tmp, (u64 __user *)dst,
12809@@ -161,8 +253,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12810 return ret;
12811 }
12812 default:
12813- return copy_user_generic((__force void *)dst,
12814- (__force void *)src, size);
12815+
12816+#ifdef CONFIG_PAX_MEMORY_UDEREF
12817+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12818+ src += PAX_USER_SHADOW_BASE;
12819+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12820+ dst += PAX_USER_SHADOW_BASE;
12821+#endif
12822+
12823+ return copy_user_generic((__force_kernel void *)dst,
12824+ (__force_kernel const void *)src, size);
12825 }
12826 }
12827
12828@@ -176,33 +276,75 @@ __must_check long strlen_user(const char __user *str);
12829 __must_check unsigned long clear_user(void __user *mem, unsigned long len);
12830 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12831
12832-__must_check long __copy_from_user_inatomic(void *dst, const void __user *src,
12833- unsigned size);
12834+static __must_check __always_inline unsigned long
12835+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12836+{
12837+ pax_track_stack();
12838+
12839+ if (size > INT_MAX)
12840+ return size;
12841+
12842+#ifdef CONFIG_PAX_MEMORY_UDEREF
12843+ if (!__access_ok(VERIFY_READ, src, size))
12844+ return size;
12845
12846-static __must_check __always_inline int
12847-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12848+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12849+ src += PAX_USER_SHADOW_BASE;
12850+#endif
12851+
12852+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
12853+}
12854+
12855+static __must_check __always_inline unsigned long
12856+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12857 {
12858- return copy_user_generic((__force void *)dst, src, size);
12859+ if (size > INT_MAX)
12860+ return size;
12861+
12862+#ifdef CONFIG_PAX_MEMORY_UDEREF
12863+ if (!__access_ok(VERIFY_WRITE, dst, size))
12864+ return size;
12865+
12866+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12867+ dst += PAX_USER_SHADOW_BASE;
12868+#endif
12869+
12870+ return copy_user_generic((__force_kernel void *)dst, src, size);
12871 }
12872
12873-extern long __copy_user_nocache(void *dst, const void __user *src,
12874- unsigned size, int zerorest);
12875+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12876+ unsigned long size, int zerorest);
12877
12878-static inline int
12879-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12880+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
12881 {
12882 might_sleep();
12883+
12884+ if (size > INT_MAX)
12885+ return size;
12886+
12887+#ifdef CONFIG_PAX_MEMORY_UDEREF
12888+ if (!__access_ok(VERIFY_READ, src, size))
12889+ return size;
12890+#endif
12891+
12892 return __copy_user_nocache(dst, src, size, 1);
12893 }
12894
12895-static inline int
12896-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12897- unsigned size)
12898+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12899+ unsigned long size)
12900 {
12901+ if (size > INT_MAX)
12902+ return size;
12903+
12904+#ifdef CONFIG_PAX_MEMORY_UDEREF
12905+ if (!__access_ok(VERIFY_READ, src, size))
12906+ return size;
12907+#endif
12908+
12909 return __copy_user_nocache(dst, src, size, 0);
12910 }
12911
12912-unsigned long
12913-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12914+extern unsigned long
12915+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest);
12916
12917 #endif /* _ASM_X86_UACCESS_64_H */
12918diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
12919index 9064052..786cfbc 100644
12920--- a/arch/x86/include/asm/vdso.h
12921+++ b/arch/x86/include/asm/vdso.h
12922@@ -25,7 +25,7 @@ extern const char VDSO32_PRELINK[];
12923 #define VDSO32_SYMBOL(base, name) \
12924 ({ \
12925 extern const char VDSO32_##name[]; \
12926- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12927+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12928 })
12929 #endif
12930
12931diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
12932index 3d61e20..9507180 100644
12933--- a/arch/x86/include/asm/vgtod.h
12934+++ b/arch/x86/include/asm/vgtod.h
12935@@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
12936 int sysctl_enabled;
12937 struct timezone sys_tz;
12938 struct { /* extract of a clocksource struct */
12939+ char name[8];
12940 cycle_t (*vread)(void);
12941 cycle_t cycle_last;
12942 cycle_t mask;
12943diff --git a/arch/x86/include/asm/vmi.h b/arch/x86/include/asm/vmi.h
12944index 61e08c0..b0da582 100644
12945--- a/arch/x86/include/asm/vmi.h
12946+++ b/arch/x86/include/asm/vmi.h
12947@@ -191,6 +191,7 @@ struct vrom_header {
12948 u8 reserved[96]; /* Reserved for headers */
12949 char vmi_init[8]; /* VMI_Init jump point */
12950 char get_reloc[8]; /* VMI_GetRelocationInfo jump point */
12951+ char rom_data[8048]; /* rest of the option ROM */
12952 } __attribute__((packed));
12953
12954 struct pnp_header {
12955diff --git a/arch/x86/include/asm/vmi_time.h b/arch/x86/include/asm/vmi_time.h
12956index c6e0bee..fcb9f74 100644
12957--- a/arch/x86/include/asm/vmi_time.h
12958+++ b/arch/x86/include/asm/vmi_time.h
12959@@ -43,7 +43,7 @@ extern struct vmi_timer_ops {
12960 int (*wallclock_updated)(void);
12961 void (*set_alarm)(u32 flags, u64 expiry, u64 period);
12962 void (*cancel_alarm)(u32 flags);
12963-} vmi_timer_ops;
12964+} __no_const vmi_timer_ops;
12965
12966 /* Prototypes */
12967 extern void __init vmi_time_init(void);
12968diff --git a/arch/x86/include/asm/vsyscall.h b/arch/x86/include/asm/vsyscall.h
12969index d0983d2..1f7c9e9 100644
12970--- a/arch/x86/include/asm/vsyscall.h
12971+++ b/arch/x86/include/asm/vsyscall.h
12972@@ -15,9 +15,10 @@ enum vsyscall_num {
12973
12974 #ifdef __KERNEL__
12975 #include <linux/seqlock.h>
12976+#include <linux/getcpu.h>
12977+#include <linux/time.h>
12978
12979 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
12980-#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
12981
12982 /* Definitions for CONFIG_GENERIC_TIME definitions */
12983 #define __section_vsyscall_gtod_data __attribute__ \
12984@@ -31,7 +32,6 @@ enum vsyscall_num {
12985 #define VGETCPU_LSL 2
12986
12987 extern int __vgetcpu_mode;
12988-extern volatile unsigned long __jiffies;
12989
12990 /* kernel space (writeable) */
12991 extern int vgetcpu_mode;
12992@@ -39,6 +39,9 @@ extern struct timezone sys_tz;
12993
12994 extern void map_vsyscall(void);
12995
12996+extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
12997+extern time_t vtime(time_t *t);
12998+extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
12999 #endif /* __KERNEL__ */
13000
13001 #endif /* _ASM_X86_VSYSCALL_H */
13002diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13003index 2c756fd..3377e37 100644
13004--- a/arch/x86/include/asm/x86_init.h
13005+++ b/arch/x86/include/asm/x86_init.h
13006@@ -28,7 +28,7 @@ struct x86_init_mpparse {
13007 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13008 void (*find_smp_config)(unsigned int reserve);
13009 void (*get_smp_config)(unsigned int early);
13010-};
13011+} __no_const;
13012
13013 /**
13014 * struct x86_init_resources - platform specific resource related ops
13015@@ -42,7 +42,7 @@ struct x86_init_resources {
13016 void (*probe_roms)(void);
13017 void (*reserve_resources)(void);
13018 char *(*memory_setup)(void);
13019-};
13020+} __no_const;
13021
13022 /**
13023 * struct x86_init_irqs - platform specific interrupt setup
13024@@ -55,7 +55,7 @@ struct x86_init_irqs {
13025 void (*pre_vector_init)(void);
13026 void (*intr_init)(void);
13027 void (*trap_init)(void);
13028-};
13029+} __no_const;
13030
13031 /**
13032 * struct x86_init_oem - oem platform specific customizing functions
13033@@ -65,7 +65,7 @@ struct x86_init_irqs {
13034 struct x86_init_oem {
13035 void (*arch_setup)(void);
13036 void (*banner)(void);
13037-};
13038+} __no_const;
13039
13040 /**
13041 * struct x86_init_paging - platform specific paging functions
13042@@ -75,7 +75,7 @@ struct x86_init_oem {
13043 struct x86_init_paging {
13044 void (*pagetable_setup_start)(pgd_t *base);
13045 void (*pagetable_setup_done)(pgd_t *base);
13046-};
13047+} __no_const;
13048
13049 /**
13050 * struct x86_init_timers - platform specific timer setup
13051@@ -88,7 +88,7 @@ struct x86_init_timers {
13052 void (*setup_percpu_clockev)(void);
13053 void (*tsc_pre_init)(void);
13054 void (*timer_init)(void);
13055-};
13056+} __no_const;
13057
13058 /**
13059 * struct x86_init_ops - functions for platform specific setup
13060@@ -101,7 +101,7 @@ struct x86_init_ops {
13061 struct x86_init_oem oem;
13062 struct x86_init_paging paging;
13063 struct x86_init_timers timers;
13064-};
13065+} __no_const;
13066
13067 /**
13068 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13069@@ -109,7 +109,7 @@ struct x86_init_ops {
13070 */
13071 struct x86_cpuinit_ops {
13072 void (*setup_percpu_clockev)(void);
13073-};
13074+} __no_const;
13075
13076 /**
13077 * struct x86_platform_ops - platform specific runtime functions
13078@@ -121,7 +121,7 @@ struct x86_platform_ops {
13079 unsigned long (*calibrate_tsc)(void);
13080 unsigned long (*get_wallclock)(void);
13081 int (*set_wallclock)(unsigned long nowtime);
13082-};
13083+} __no_const;
13084
13085 extern struct x86_init_ops x86_init;
13086 extern struct x86_cpuinit_ops x86_cpuinit;
13087diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13088index 727acc1..554f3eb 100644
13089--- a/arch/x86/include/asm/xsave.h
13090+++ b/arch/x86/include/asm/xsave.h
13091@@ -56,6 +56,12 @@ static inline int xrstor_checking(struct xsave_struct *fx)
13092 static inline int xsave_user(struct xsave_struct __user *buf)
13093 {
13094 int err;
13095+
13096+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13097+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13098+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13099+#endif
13100+
13101 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
13102 "2:\n"
13103 ".section .fixup,\"ax\"\n"
13104@@ -78,10 +84,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13105 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13106 {
13107 int err;
13108- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13109+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13110 u32 lmask = mask;
13111 u32 hmask = mask >> 32;
13112
13113+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13114+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13115+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13116+#endif
13117+
13118 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13119 "2:\n"
13120 ".section .fixup,\"ax\"\n"
13121diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13122index 6a564ac..9b1340c 100644
13123--- a/arch/x86/kernel/acpi/realmode/Makefile
13124+++ b/arch/x86/kernel/acpi/realmode/Makefile
13125@@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13126 $(call cc-option, -fno-stack-protector) \
13127 $(call cc-option, -mpreferred-stack-boundary=2)
13128 KBUILD_CFLAGS += $(call cc-option, -m32)
13129+ifdef CONSTIFY_PLUGIN
13130+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13131+endif
13132 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13133 GCOV_PROFILE := n
13134
13135diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13136index 580b4e2..d4129e4 100644
13137--- a/arch/x86/kernel/acpi/realmode/wakeup.S
13138+++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13139@@ -91,6 +91,9 @@ _start:
13140 /* Do any other stuff... */
13141
13142 #ifndef CONFIG_64BIT
13143+ /* Recheck NX bit overrides (64bit path does this in trampoline) */
13144+ call verify_cpu
13145+
13146 /* This could also be done in C code... */
13147 movl pmode_cr3, %eax
13148 movl %eax, %cr3
13149@@ -104,7 +107,7 @@ _start:
13150 movl %eax, %ecx
13151 orl %edx, %ecx
13152 jz 1f
13153- movl $0xc0000080, %ecx
13154+ mov $MSR_EFER, %ecx
13155 wrmsr
13156 1:
13157
13158@@ -114,6 +117,7 @@ _start:
13159 movl pmode_cr0, %eax
13160 movl %eax, %cr0
13161 jmp pmode_return
13162+# include "../../verify_cpu.S"
13163 #else
13164 pushw $0
13165 pushw trampoline_segment
13166diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13167index ca93638..7042f24 100644
13168--- a/arch/x86/kernel/acpi/sleep.c
13169+++ b/arch/x86/kernel/acpi/sleep.c
13170@@ -11,11 +11,12 @@
13171 #include <linux/cpumask.h>
13172 #include <asm/segment.h>
13173 #include <asm/desc.h>
13174+#include <asm/e820.h>
13175
13176 #include "realmode/wakeup.h"
13177 #include "sleep.h"
13178
13179-unsigned long acpi_wakeup_address;
13180+unsigned long acpi_wakeup_address = 0x2000;
13181 unsigned long acpi_realmode_flags;
13182
13183 /* address in low memory of the wakeup routine. */
13184@@ -98,9 +99,13 @@ int acpi_save_state_mem(void)
13185 #else /* CONFIG_64BIT */
13186 header->trampoline_segment = setup_trampoline() >> 4;
13187 #ifdef CONFIG_SMP
13188- stack_start.sp = temp_stack + sizeof(temp_stack);
13189+ stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13190+
13191+ pax_open_kernel();
13192 early_gdt_descr.address =
13193 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13194+ pax_close_kernel();
13195+
13196 initial_gs = per_cpu_offset(smp_processor_id());
13197 #endif
13198 initial_code = (unsigned long)wakeup_long64;
13199@@ -134,14 +139,8 @@ void __init acpi_reserve_bootmem(void)
13200 return;
13201 }
13202
13203- acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
13204-
13205- if (!acpi_realmode) {
13206- printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
13207- return;
13208- }
13209-
13210- acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
13211+ reserve_early(acpi_wakeup_address, acpi_wakeup_address + WAKEUP_SIZE, "ACPI Wakeup Code");
13212+ acpi_realmode = (unsigned long)__va(acpi_wakeup_address);;
13213 }
13214
13215
13216diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13217index 8ded418..079961e 100644
13218--- a/arch/x86/kernel/acpi/wakeup_32.S
13219+++ b/arch/x86/kernel/acpi/wakeup_32.S
13220@@ -30,13 +30,11 @@ wakeup_pmode_return:
13221 # and restore the stack ... but you need gdt for this to work
13222 movl saved_context_esp, %esp
13223
13224- movl %cs:saved_magic, %eax
13225- cmpl $0x12345678, %eax
13226+ cmpl $0x12345678, saved_magic
13227 jne bogus_magic
13228
13229 # jump to place where we left off
13230- movl saved_eip, %eax
13231- jmp *%eax
13232+ jmp *(saved_eip)
13233
13234 bogus_magic:
13235 jmp bogus_magic
13236diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13237index de7353c..075da5f 100644
13238--- a/arch/x86/kernel/alternative.c
13239+++ b/arch/x86/kernel/alternative.c
13240@@ -407,7 +407,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13241
13242 BUG_ON(p->len > MAX_PATCH_LEN);
13243 /* prep the buffer with the original instructions */
13244- memcpy(insnbuf, p->instr, p->len);
13245+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13246 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13247 (unsigned long)p->instr, p->len);
13248
13249@@ -475,7 +475,7 @@ void __init alternative_instructions(void)
13250 if (smp_alt_once)
13251 free_init_pages("SMP alternatives",
13252 (unsigned long)__smp_locks,
13253- (unsigned long)__smp_locks_end);
13254+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13255
13256 restart_nmi();
13257 }
13258@@ -492,13 +492,17 @@ void __init alternative_instructions(void)
13259 * instructions. And on the local CPU you need to be protected again NMI or MCE
13260 * handlers seeing an inconsistent instruction while you patch.
13261 */
13262-static void *__init_or_module text_poke_early(void *addr, const void *opcode,
13263+static void *__kprobes text_poke_early(void *addr, const void *opcode,
13264 size_t len)
13265 {
13266 unsigned long flags;
13267 local_irq_save(flags);
13268- memcpy(addr, opcode, len);
13269+
13270+ pax_open_kernel();
13271+ memcpy(ktla_ktva(addr), opcode, len);
13272 sync_core();
13273+ pax_close_kernel();
13274+
13275 local_irq_restore(flags);
13276 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13277 that causes hangs on some VIA CPUs. */
13278@@ -520,35 +524,21 @@ static void *__init_or_module text_poke_early(void *addr, const void *opcode,
13279 */
13280 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13281 {
13282- unsigned long flags;
13283- char *vaddr;
13284+ unsigned char *vaddr = ktla_ktva(addr);
13285 struct page *pages[2];
13286- int i;
13287+ size_t i;
13288
13289 if (!core_kernel_text((unsigned long)addr)) {
13290- pages[0] = vmalloc_to_page(addr);
13291- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13292+ pages[0] = vmalloc_to_page(vaddr);
13293+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13294 } else {
13295- pages[0] = virt_to_page(addr);
13296+ pages[0] = virt_to_page(vaddr);
13297 WARN_ON(!PageReserved(pages[0]));
13298- pages[1] = virt_to_page(addr + PAGE_SIZE);
13299+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13300 }
13301 BUG_ON(!pages[0]);
13302- local_irq_save(flags);
13303- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13304- if (pages[1])
13305- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13306- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13307- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13308- clear_fixmap(FIX_TEXT_POKE0);
13309- if (pages[1])
13310- clear_fixmap(FIX_TEXT_POKE1);
13311- local_flush_tlb();
13312- sync_core();
13313- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13314- that causes hangs on some VIA CPUs. */
13315+ text_poke_early(addr, opcode, len);
13316 for (i = 0; i < len; i++)
13317- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13318- local_irq_restore(flags);
13319+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13320 return addr;
13321 }
13322diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
13323index 3a44b75..1601800 100644
13324--- a/arch/x86/kernel/amd_iommu.c
13325+++ b/arch/x86/kernel/amd_iommu.c
13326@@ -2076,7 +2076,7 @@ static void prealloc_protection_domains(void)
13327 }
13328 }
13329
13330-static struct dma_map_ops amd_iommu_dma_ops = {
13331+static const struct dma_map_ops amd_iommu_dma_ops = {
13332 .alloc_coherent = alloc_coherent,
13333 .free_coherent = free_coherent,
13334 .map_page = map_page,
13335diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13336index 1d2d670..8e3f477 100644
13337--- a/arch/x86/kernel/apic/apic.c
13338+++ b/arch/x86/kernel/apic/apic.c
13339@@ -170,7 +170,7 @@ int first_system_vector = 0xfe;
13340 /*
13341 * Debug level, exported for io_apic.c
13342 */
13343-unsigned int apic_verbosity;
13344+int apic_verbosity;
13345
13346 int pic_mode;
13347
13348@@ -1794,7 +1794,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13349 apic_write(APIC_ESR, 0);
13350 v1 = apic_read(APIC_ESR);
13351 ack_APIC_irq();
13352- atomic_inc(&irq_err_count);
13353+ atomic_inc_unchecked(&irq_err_count);
13354
13355 /*
13356 * Here is what the APIC error bits mean:
13357@@ -2184,6 +2184,8 @@ static int __cpuinit apic_cluster_num(void)
13358 u16 *bios_cpu_apicid;
13359 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
13360
13361+ pax_track_stack();
13362+
13363 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
13364 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
13365
13366diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13367index 8928d97..f799cea 100644
13368--- a/arch/x86/kernel/apic/io_apic.c
13369+++ b/arch/x86/kernel/apic/io_apic.c
13370@@ -716,7 +716,7 @@ struct IO_APIC_route_entry **alloc_ioapic_entries(void)
13371 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
13372 GFP_ATOMIC);
13373 if (!ioapic_entries)
13374- return 0;
13375+ return NULL;
13376
13377 for (apic = 0; apic < nr_ioapics; apic++) {
13378 ioapic_entries[apic] =
13379@@ -733,7 +733,7 @@ nomem:
13380 kfree(ioapic_entries[apic]);
13381 kfree(ioapic_entries);
13382
13383- return 0;
13384+ return NULL;
13385 }
13386
13387 /*
13388@@ -1150,7 +1150,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13389 }
13390 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13391
13392-void lock_vector_lock(void)
13393+void lock_vector_lock(void) __acquires(vector_lock)
13394 {
13395 /* Used to the online set of cpus does not change
13396 * during assign_irq_vector.
13397@@ -1158,7 +1158,7 @@ void lock_vector_lock(void)
13398 spin_lock(&vector_lock);
13399 }
13400
13401-void unlock_vector_lock(void)
13402+void unlock_vector_lock(void) __releases(vector_lock)
13403 {
13404 spin_unlock(&vector_lock);
13405 }
13406@@ -2542,7 +2542,7 @@ static void ack_apic_edge(unsigned int irq)
13407 ack_APIC_irq();
13408 }
13409
13410-atomic_t irq_mis_count;
13411+atomic_unchecked_t irq_mis_count;
13412
13413 static void ack_apic_level(unsigned int irq)
13414 {
13415@@ -2626,7 +2626,7 @@ static void ack_apic_level(unsigned int irq)
13416
13417 /* Tail end of version 0x11 I/O APIC bug workaround */
13418 if (!(v & (1 << (i & 0x1f)))) {
13419- atomic_inc(&irq_mis_count);
13420+ atomic_inc_unchecked(&irq_mis_count);
13421 spin_lock(&ioapic_lock);
13422 __mask_and_edge_IO_APIC_irq(cfg);
13423 __unmask_and_level_IO_APIC_irq(cfg);
13424diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13425index 151ace6..f317474 100644
13426--- a/arch/x86/kernel/apm_32.c
13427+++ b/arch/x86/kernel/apm_32.c
13428@@ -410,7 +410,7 @@ static DEFINE_SPINLOCK(user_list_lock);
13429 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13430 * even though they are called in protected mode.
13431 */
13432-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13433+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13434 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13435
13436 static const char driver_version[] = "1.16ac"; /* no spaces */
13437@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13438 BUG_ON(cpu != 0);
13439 gdt = get_cpu_gdt_table(cpu);
13440 save_desc_40 = gdt[0x40 / 8];
13441+
13442+ pax_open_kernel();
13443 gdt[0x40 / 8] = bad_bios_desc;
13444+ pax_close_kernel();
13445
13446 apm_irq_save(flags);
13447 APM_DO_SAVE_SEGS;
13448@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13449 &call->esi);
13450 APM_DO_RESTORE_SEGS;
13451 apm_irq_restore(flags);
13452+
13453+ pax_open_kernel();
13454 gdt[0x40 / 8] = save_desc_40;
13455+ pax_close_kernel();
13456+
13457 put_cpu();
13458
13459 return call->eax & 0xff;
13460@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13461 BUG_ON(cpu != 0);
13462 gdt = get_cpu_gdt_table(cpu);
13463 save_desc_40 = gdt[0x40 / 8];
13464+
13465+ pax_open_kernel();
13466 gdt[0x40 / 8] = bad_bios_desc;
13467+ pax_close_kernel();
13468
13469 apm_irq_save(flags);
13470 APM_DO_SAVE_SEGS;
13471@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13472 &call->eax);
13473 APM_DO_RESTORE_SEGS;
13474 apm_irq_restore(flags);
13475+
13476+ pax_open_kernel();
13477 gdt[0x40 / 8] = save_desc_40;
13478+ pax_close_kernel();
13479+
13480 put_cpu();
13481 return error;
13482 }
13483@@ -975,7 +989,7 @@ recalc:
13484
13485 static void apm_power_off(void)
13486 {
13487- unsigned char po_bios_call[] = {
13488+ const unsigned char po_bios_call[] = {
13489 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
13490 0x8e, 0xd0, /* movw ax,ss */
13491 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
13492@@ -2357,12 +2371,15 @@ static int __init apm_init(void)
13493 * code to that CPU.
13494 */
13495 gdt = get_cpu_gdt_table(0);
13496+
13497+ pax_open_kernel();
13498 set_desc_base(&gdt[APM_CS >> 3],
13499 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13500 set_desc_base(&gdt[APM_CS_16 >> 3],
13501 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13502 set_desc_base(&gdt[APM_DS >> 3],
13503 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13504+ pax_close_kernel();
13505
13506 proc_create("apm", 0, NULL, &apm_file_ops);
13507
13508diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c
13509index dfdbf64..9b2b6ce 100644
13510--- a/arch/x86/kernel/asm-offsets_32.c
13511+++ b/arch/x86/kernel/asm-offsets_32.c
13512@@ -51,7 +51,6 @@ void foo(void)
13513 OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
13514 BLANK();
13515
13516- OFFSET(TI_task, thread_info, task);
13517 OFFSET(TI_exec_domain, thread_info, exec_domain);
13518 OFFSET(TI_flags, thread_info, flags);
13519 OFFSET(TI_status, thread_info, status);
13520@@ -60,6 +59,8 @@ void foo(void)
13521 OFFSET(TI_restart_block, thread_info, restart_block);
13522 OFFSET(TI_sysenter_return, thread_info, sysenter_return);
13523 OFFSET(TI_cpu, thread_info, cpu);
13524+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13525+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13526 BLANK();
13527
13528 OFFSET(GDS_size, desc_ptr, size);
13529@@ -99,6 +100,7 @@ void foo(void)
13530
13531 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13532 DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13533+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13534 DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
13535 DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
13536 DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
13537@@ -115,6 +117,11 @@ void foo(void)
13538 OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
13539 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13540 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13541+
13542+#ifdef CONFIG_PAX_KERNEXEC
13543+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13544+#endif
13545+
13546 #endif
13547
13548 #ifdef CONFIG_XEN
13549diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13550index 4a6aeed..371de20 100644
13551--- a/arch/x86/kernel/asm-offsets_64.c
13552+++ b/arch/x86/kernel/asm-offsets_64.c
13553@@ -44,6 +44,8 @@ int main(void)
13554 ENTRY(addr_limit);
13555 ENTRY(preempt_count);
13556 ENTRY(status);
13557+ ENTRY(lowest_stack);
13558+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13559 #ifdef CONFIG_IA32_EMULATION
13560 ENTRY(sysenter_return);
13561 #endif
13562@@ -63,6 +65,18 @@ int main(void)
13563 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13564 OFFSET(PV_CPU_swapgs, pv_cpu_ops, swapgs);
13565 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13566+
13567+#ifdef CONFIG_PAX_KERNEXEC
13568+ OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13569+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13570+#endif
13571+
13572+#ifdef CONFIG_PAX_MEMORY_UDEREF
13573+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13574+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13575+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13576+#endif
13577+
13578 #endif
13579
13580
13581@@ -115,6 +129,7 @@ int main(void)
13582 ENTRY(cr8);
13583 BLANK();
13584 #undef ENTRY
13585+ DEFINE(TSS_size, sizeof(struct tss_struct));
13586 DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
13587 BLANK();
13588 DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
13589@@ -130,6 +145,7 @@ int main(void)
13590
13591 BLANK();
13592 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13593+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13594 #ifdef CONFIG_XEN
13595 BLANK();
13596 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13597diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13598index ff502cc..dc5133e 100644
13599--- a/arch/x86/kernel/cpu/Makefile
13600+++ b/arch/x86/kernel/cpu/Makefile
13601@@ -7,10 +7,6 @@ ifdef CONFIG_FUNCTION_TRACER
13602 CFLAGS_REMOVE_common.o = -pg
13603 endif
13604
13605-# Make sure load_percpu_segment has no stackprotector
13606-nostackp := $(call cc-option, -fno-stack-protector)
13607-CFLAGS_common.o := $(nostackp)
13608-
13609 obj-y := intel_cacheinfo.o addon_cpuid_features.o
13610 obj-y += proc.o capflags.o powerflags.o common.o
13611 obj-y += vmware.o hypervisor.o sched.o
13612diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13613index 6e082dc..a0b5f36 100644
13614--- a/arch/x86/kernel/cpu/amd.c
13615+++ b/arch/x86/kernel/cpu/amd.c
13616@@ -602,7 +602,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13617 unsigned int size)
13618 {
13619 /* AMD errata T13 (order #21922) */
13620- if ((c->x86 == 6)) {
13621+ if (c->x86 == 6) {
13622 /* Duron Rev A0 */
13623 if (c->x86_model == 3 && c->x86_mask == 0)
13624 size = 64;
13625diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13626index 4e34d10..ba6bc97 100644
13627--- a/arch/x86/kernel/cpu/common.c
13628+++ b/arch/x86/kernel/cpu/common.c
13629@@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13630
13631 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13632
13633-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13634-#ifdef CONFIG_X86_64
13635- /*
13636- * We need valid kernel segments for data and code in long mode too
13637- * IRET will check the segment types kkeil 2000/10/28
13638- * Also sysret mandates a special GDT layout
13639- *
13640- * TLS descriptors are currently at a different place compared to i386.
13641- * Hopefully nobody expects them at a fixed place (Wine?)
13642- */
13643- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13644- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13645- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13646- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13647- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13648- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13649-#else
13650- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13651- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13652- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13653- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13654- /*
13655- * Segments used for calling PnP BIOS have byte granularity.
13656- * They code segments and data segments have fixed 64k limits,
13657- * the transfer segment sizes are set at run time.
13658- */
13659- /* 32-bit code */
13660- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13661- /* 16-bit code */
13662- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13663- /* 16-bit data */
13664- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13665- /* 16-bit data */
13666- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13667- /* 16-bit data */
13668- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13669- /*
13670- * The APM segments have byte granularity and their bases
13671- * are set at run time. All have 64k limits.
13672- */
13673- /* 32-bit code */
13674- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13675- /* 16-bit code */
13676- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13677- /* data */
13678- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13679-
13680- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13681- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13682- GDT_STACK_CANARY_INIT
13683-#endif
13684-} };
13685-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13686-
13687 static int __init x86_xsave_setup(char *s)
13688 {
13689 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13690@@ -344,7 +290,7 @@ void switch_to_new_gdt(int cpu)
13691 {
13692 struct desc_ptr gdt_descr;
13693
13694- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13695+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13696 gdt_descr.size = GDT_SIZE - 1;
13697 load_gdt(&gdt_descr);
13698 /* Reload the per-cpu base */
13699@@ -798,6 +744,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13700 /* Filter out anything that depends on CPUID levels we don't have */
13701 filter_cpuid_features(c, true);
13702
13703+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13704+ setup_clear_cpu_cap(X86_FEATURE_SEP);
13705+#endif
13706+
13707 /* If the model name is still unset, do table lookup. */
13708 if (!c->x86_model_id[0]) {
13709 const char *p;
13710@@ -980,6 +930,9 @@ static __init int setup_disablecpuid(char *arg)
13711 }
13712 __setup("clearcpuid=", setup_disablecpuid);
13713
13714+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13715+EXPORT_PER_CPU_SYMBOL(current_tinfo);
13716+
13717 #ifdef CONFIG_X86_64
13718 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13719
13720@@ -995,7 +948,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13721 EXPORT_PER_CPU_SYMBOL(current_task);
13722
13723 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13724- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13725+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13726 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13727
13728 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13729@@ -1060,7 +1013,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13730 {
13731 memset(regs, 0, sizeof(struct pt_regs));
13732 regs->fs = __KERNEL_PERCPU;
13733- regs->gs = __KERNEL_STACK_CANARY;
13734+ savesegment(gs, regs->gs);
13735
13736 return regs;
13737 }
13738@@ -1101,7 +1054,7 @@ void __cpuinit cpu_init(void)
13739 int i;
13740
13741 cpu = stack_smp_processor_id();
13742- t = &per_cpu(init_tss, cpu);
13743+ t = init_tss + cpu;
13744 orig_ist = &per_cpu(orig_ist, cpu);
13745
13746 #ifdef CONFIG_NUMA
13747@@ -1127,7 +1080,7 @@ void __cpuinit cpu_init(void)
13748 switch_to_new_gdt(cpu);
13749 loadsegment(fs, 0);
13750
13751- load_idt((const struct desc_ptr *)&idt_descr);
13752+ load_idt(&idt_descr);
13753
13754 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13755 syscall_init();
13756@@ -1136,7 +1089,6 @@ void __cpuinit cpu_init(void)
13757 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13758 barrier();
13759
13760- check_efer();
13761 if (cpu != 0)
13762 enable_x2apic();
13763
13764@@ -1199,7 +1151,7 @@ void __cpuinit cpu_init(void)
13765 {
13766 int cpu = smp_processor_id();
13767 struct task_struct *curr = current;
13768- struct tss_struct *t = &per_cpu(init_tss, cpu);
13769+ struct tss_struct *t = init_tss + cpu;
13770 struct thread_struct *thread = &curr->thread;
13771
13772 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13773diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13774index 6a77cca..4f4fca0 100644
13775--- a/arch/x86/kernel/cpu/intel.c
13776+++ b/arch/x86/kernel/cpu/intel.c
13777@@ -162,7 +162,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13778 * Update the IDT descriptor and reload the IDT so that
13779 * it uses the read-only mapped virtual address.
13780 */
13781- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13782+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13783 load_idt(&idt_descr);
13784 }
13785 #endif
13786diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
13787index 417990f..96dc36b 100644
13788--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
13789+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
13790@@ -921,7 +921,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
13791 return ret;
13792 }
13793
13794-static struct sysfs_ops sysfs_ops = {
13795+static const struct sysfs_ops sysfs_ops = {
13796 .show = show,
13797 .store = store,
13798 };
13799diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13800index 472763d..9831e11 100644
13801--- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
13802+++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13803@@ -211,7 +211,9 @@ static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13804 static int inject_init(void)
13805 {
13806 printk(KERN_INFO "Machine check injector initialized\n");
13807- mce_chrdev_ops.write = mce_write;
13808+ pax_open_kernel();
13809+ *(void **)&mce_chrdev_ops.write = mce_write;
13810+ pax_close_kernel();
13811 register_die_notifier(&mce_raise_nb);
13812 return 0;
13813 }
13814diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13815index 0f16a2b..21740f5 100644
13816--- a/arch/x86/kernel/cpu/mcheck/mce.c
13817+++ b/arch/x86/kernel/cpu/mcheck/mce.c
13818@@ -43,6 +43,7 @@
13819 #include <asm/ipi.h>
13820 #include <asm/mce.h>
13821 #include <asm/msr.h>
13822+#include <asm/local.h>
13823
13824 #include "mce-internal.h"
13825
13826@@ -187,7 +188,7 @@ static void print_mce(struct mce *m)
13827 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13828 m->cs, m->ip);
13829
13830- if (m->cs == __KERNEL_CS)
13831+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13832 print_symbol("{%s}", m->ip);
13833 pr_cont("\n");
13834 }
13835@@ -221,10 +222,10 @@ static void print_mce_tail(void)
13836
13837 #define PANIC_TIMEOUT 5 /* 5 seconds */
13838
13839-static atomic_t mce_paniced;
13840+static atomic_unchecked_t mce_paniced;
13841
13842 static int fake_panic;
13843-static atomic_t mce_fake_paniced;
13844+static atomic_unchecked_t mce_fake_paniced;
13845
13846 /* Panic in progress. Enable interrupts and wait for final IPI */
13847 static void wait_for_panic(void)
13848@@ -248,7 +249,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13849 /*
13850 * Make sure only one CPU runs in machine check panic
13851 */
13852- if (atomic_inc_return(&mce_paniced) > 1)
13853+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13854 wait_for_panic();
13855 barrier();
13856
13857@@ -256,7 +257,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13858 console_verbose();
13859 } else {
13860 /* Don't log too much for fake panic */
13861- if (atomic_inc_return(&mce_fake_paniced) > 1)
13862+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13863 return;
13864 }
13865 print_mce_head();
13866@@ -616,7 +617,7 @@ static int mce_timed_out(u64 *t)
13867 * might have been modified by someone else.
13868 */
13869 rmb();
13870- if (atomic_read(&mce_paniced))
13871+ if (atomic_read_unchecked(&mce_paniced))
13872 wait_for_panic();
13873 if (!monarch_timeout)
13874 goto out;
13875@@ -1394,7 +1395,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13876 }
13877
13878 /* Call the installed machine check handler for this CPU setup. */
13879-void (*machine_check_vector)(struct pt_regs *, long error_code) =
13880+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13881 unexpected_machine_check;
13882
13883 /*
13884@@ -1416,7 +1417,9 @@ void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
13885 return;
13886 }
13887
13888+ pax_open_kernel();
13889 machine_check_vector = do_machine_check;
13890+ pax_close_kernel();
13891
13892 mce_init();
13893 mce_cpu_features(c);
13894@@ -1429,14 +1432,14 @@ void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
13895 */
13896
13897 static DEFINE_SPINLOCK(mce_state_lock);
13898-static int open_count; /* #times opened */
13899+static local_t open_count; /* #times opened */
13900 static int open_exclu; /* already open exclusive? */
13901
13902 static int mce_open(struct inode *inode, struct file *file)
13903 {
13904 spin_lock(&mce_state_lock);
13905
13906- if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
13907+ if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
13908 spin_unlock(&mce_state_lock);
13909
13910 return -EBUSY;
13911@@ -1444,7 +1447,7 @@ static int mce_open(struct inode *inode, struct file *file)
13912
13913 if (file->f_flags & O_EXCL)
13914 open_exclu = 1;
13915- open_count++;
13916+ local_inc(&open_count);
13917
13918 spin_unlock(&mce_state_lock);
13919
13920@@ -1455,7 +1458,7 @@ static int mce_release(struct inode *inode, struct file *file)
13921 {
13922 spin_lock(&mce_state_lock);
13923
13924- open_count--;
13925+ local_dec(&open_count);
13926 open_exclu = 0;
13927
13928 spin_unlock(&mce_state_lock);
13929@@ -2082,7 +2085,7 @@ struct dentry *mce_get_debugfs_dir(void)
13930 static void mce_reset(void)
13931 {
13932 cpu_missing = 0;
13933- atomic_set(&mce_fake_paniced, 0);
13934+ atomic_set_unchecked(&mce_fake_paniced, 0);
13935 atomic_set(&mce_executing, 0);
13936 atomic_set(&mce_callin, 0);
13937 atomic_set(&global_nwo, 0);
13938diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
13939index ef3cd31..9d2f6ab 100644
13940--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
13941+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
13942@@ -385,7 +385,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
13943 return ret;
13944 }
13945
13946-static struct sysfs_ops threshold_ops = {
13947+static const struct sysfs_ops threshold_ops = {
13948 .show = show,
13949 .store = store,
13950 };
13951diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13952index 5c0e653..1e82c7c 100644
13953--- a/arch/x86/kernel/cpu/mcheck/p5.c
13954+++ b/arch/x86/kernel/cpu/mcheck/p5.c
13955@@ -50,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13956 if (!cpu_has(c, X86_FEATURE_MCE))
13957 return;
13958
13959+ pax_open_kernel();
13960 machine_check_vector = pentium_machine_check;
13961+ pax_close_kernel();
13962 /* Make sure the vector pointer is visible before we enable MCEs: */
13963 wmb();
13964
13965diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13966index 54060f5..e6ba93d 100644
13967--- a/arch/x86/kernel/cpu/mcheck/winchip.c
13968+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13969@@ -24,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13970 {
13971 u32 lo, hi;
13972
13973+ pax_open_kernel();
13974 machine_check_vector = winchip_machine_check;
13975+ pax_close_kernel();
13976 /* Make sure the vector pointer is visible before we enable MCEs: */
13977 wmb();
13978
13979diff --git a/arch/x86/kernel/cpu/mtrr/amd.c b/arch/x86/kernel/cpu/mtrr/amd.c
13980index 33af141..92ba9cd 100644
13981--- a/arch/x86/kernel/cpu/mtrr/amd.c
13982+++ b/arch/x86/kernel/cpu/mtrr/amd.c
13983@@ -108,7 +108,7 @@ amd_validate_add_page(unsigned long base, unsigned long size, unsigned int type)
13984 return 0;
13985 }
13986
13987-static struct mtrr_ops amd_mtrr_ops = {
13988+static const struct mtrr_ops amd_mtrr_ops = {
13989 .vendor = X86_VENDOR_AMD,
13990 .set = amd_set_mtrr,
13991 .get = amd_get_mtrr,
13992diff --git a/arch/x86/kernel/cpu/mtrr/centaur.c b/arch/x86/kernel/cpu/mtrr/centaur.c
13993index de89f14..316fe3e 100644
13994--- a/arch/x86/kernel/cpu/mtrr/centaur.c
13995+++ b/arch/x86/kernel/cpu/mtrr/centaur.c
13996@@ -110,7 +110,7 @@ centaur_validate_add_page(unsigned long base, unsigned long size, unsigned int t
13997 return 0;
13998 }
13999
14000-static struct mtrr_ops centaur_mtrr_ops = {
14001+static const struct mtrr_ops centaur_mtrr_ops = {
14002 .vendor = X86_VENDOR_CENTAUR,
14003 .set = centaur_set_mcr,
14004 .get = centaur_get_mcr,
14005diff --git a/arch/x86/kernel/cpu/mtrr/cyrix.c b/arch/x86/kernel/cpu/mtrr/cyrix.c
14006index 228d982..68a3343 100644
14007--- a/arch/x86/kernel/cpu/mtrr/cyrix.c
14008+++ b/arch/x86/kernel/cpu/mtrr/cyrix.c
14009@@ -265,7 +265,7 @@ static void cyrix_set_all(void)
14010 post_set();
14011 }
14012
14013-static struct mtrr_ops cyrix_mtrr_ops = {
14014+static const struct mtrr_ops cyrix_mtrr_ops = {
14015 .vendor = X86_VENDOR_CYRIX,
14016 .set_all = cyrix_set_all,
14017 .set = cyrix_set_arr,
14018diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
14019index 55da0c5..4d75584 100644
14020--- a/arch/x86/kernel/cpu/mtrr/generic.c
14021+++ b/arch/x86/kernel/cpu/mtrr/generic.c
14022@@ -752,7 +752,7 @@ int positive_have_wrcomb(void)
14023 /*
14024 * Generic structure...
14025 */
14026-struct mtrr_ops generic_mtrr_ops = {
14027+const struct mtrr_ops generic_mtrr_ops = {
14028 .use_intel_if = 1,
14029 .set_all = generic_set_all,
14030 .get = generic_get_mtrr,
14031diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14032index fd60f09..c94ef52 100644
14033--- a/arch/x86/kernel/cpu/mtrr/main.c
14034+++ b/arch/x86/kernel/cpu/mtrr/main.c
14035@@ -60,14 +60,14 @@ static DEFINE_MUTEX(mtrr_mutex);
14036 u64 size_or_mask, size_and_mask;
14037 static bool mtrr_aps_delayed_init;
14038
14039-static struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14040+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14041
14042-struct mtrr_ops *mtrr_if;
14043+const struct mtrr_ops *mtrr_if;
14044
14045 static void set_mtrr(unsigned int reg, unsigned long base,
14046 unsigned long size, mtrr_type type);
14047
14048-void set_mtrr_ops(struct mtrr_ops *ops)
14049+void set_mtrr_ops(const struct mtrr_ops *ops)
14050 {
14051 if (ops->vendor && ops->vendor < X86_VENDOR_NUM)
14052 mtrr_ops[ops->vendor] = ops;
14053diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14054index a501dee..816c719 100644
14055--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14056+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14057@@ -25,14 +25,14 @@ struct mtrr_ops {
14058 int (*validate_add_page)(unsigned long base, unsigned long size,
14059 unsigned int type);
14060 int (*have_wrcomb)(void);
14061-};
14062+} __do_const;
14063
14064 extern int generic_get_free_region(unsigned long base, unsigned long size,
14065 int replace_reg);
14066 extern int generic_validate_add_page(unsigned long base, unsigned long size,
14067 unsigned int type);
14068
14069-extern struct mtrr_ops generic_mtrr_ops;
14070+extern const struct mtrr_ops generic_mtrr_ops;
14071
14072 extern int positive_have_wrcomb(void);
14073
14074@@ -53,10 +53,10 @@ void fill_mtrr_var_range(unsigned int index,
14075 u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi);
14076 void get_mtrr_state(void);
14077
14078-extern void set_mtrr_ops(struct mtrr_ops *ops);
14079+extern void set_mtrr_ops(const struct mtrr_ops *ops);
14080
14081 extern u64 size_or_mask, size_and_mask;
14082-extern struct mtrr_ops *mtrr_if;
14083+extern const struct mtrr_ops *mtrr_if;
14084
14085 #define is_cpu(vnd) (mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
14086 #define use_intel() (mtrr_if && mtrr_if->use_intel_if == 1)
14087diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14088index 0ff02ca..fc49a60 100644
14089--- a/arch/x86/kernel/cpu/perf_event.c
14090+++ b/arch/x86/kernel/cpu/perf_event.c
14091@@ -723,10 +723,10 @@ x86_perf_event_update(struct perf_event *event,
14092 * count to the generic event atomically:
14093 */
14094 again:
14095- prev_raw_count = atomic64_read(&hwc->prev_count);
14096+ prev_raw_count = atomic64_read_unchecked(&hwc->prev_count);
14097 rdmsrl(hwc->event_base + idx, new_raw_count);
14098
14099- if (atomic64_cmpxchg(&hwc->prev_count, prev_raw_count,
14100+ if (atomic64_cmpxchg_unchecked(&hwc->prev_count, prev_raw_count,
14101 new_raw_count) != prev_raw_count)
14102 goto again;
14103
14104@@ -741,7 +741,7 @@ again:
14105 delta = (new_raw_count << shift) - (prev_raw_count << shift);
14106 delta >>= shift;
14107
14108- atomic64_add(delta, &event->count);
14109+ atomic64_add_unchecked(delta, &event->count);
14110 atomic64_sub(delta, &hwc->period_left);
14111
14112 return new_raw_count;
14113@@ -1353,7 +1353,7 @@ x86_perf_event_set_period(struct perf_event *event,
14114 * The hw event starts counting from this event offset,
14115 * mark it to be able to extra future deltas:
14116 */
14117- atomic64_set(&hwc->prev_count, (u64)-left);
14118+ atomic64_set_unchecked(&hwc->prev_count, (u64)-left);
14119
14120 err = checking_wrmsrl(hwc->event_base + idx,
14121 (u64)(-left) & x86_pmu.event_mask);
14122@@ -2357,7 +2357,7 @@ perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry)
14123 break;
14124
14125 callchain_store(entry, frame.return_address);
14126- fp = frame.next_frame;
14127+ fp = (__force const void __user *)frame.next_frame;
14128 }
14129 }
14130
14131diff --git a/arch/x86/kernel/cpu/perfctr-watchdog.c b/arch/x86/kernel/cpu/perfctr-watchdog.c
14132index 898df97..9e82503 100644
14133--- a/arch/x86/kernel/cpu/perfctr-watchdog.c
14134+++ b/arch/x86/kernel/cpu/perfctr-watchdog.c
14135@@ -30,11 +30,11 @@ struct nmi_watchdog_ctlblk {
14136
14137 /* Interface defining a CPU specific perfctr watchdog */
14138 struct wd_ops {
14139- int (*reserve)(void);
14140- void (*unreserve)(void);
14141- int (*setup)(unsigned nmi_hz);
14142- void (*rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
14143- void (*stop)(void);
14144+ int (* const reserve)(void);
14145+ void (* const unreserve)(void);
14146+ int (* const setup)(unsigned nmi_hz);
14147+ void (* const rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
14148+ void (* const stop)(void);
14149 unsigned perfctr;
14150 unsigned evntsel;
14151 u64 checkbit;
14152@@ -645,6 +645,7 @@ static const struct wd_ops p4_wd_ops = {
14153 #define ARCH_PERFMON_NMI_EVENT_SEL ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL
14154 #define ARCH_PERFMON_NMI_EVENT_UMASK ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK
14155
14156+/* cannot be const */
14157 static struct wd_ops intel_arch_wd_ops;
14158
14159 static int setup_intel_arch_watchdog(unsigned nmi_hz)
14160@@ -697,6 +698,7 @@ static int setup_intel_arch_watchdog(unsigned nmi_hz)
14161 return 1;
14162 }
14163
14164+/* cannot be const */
14165 static struct wd_ops intel_arch_wd_ops __read_mostly = {
14166 .reserve = single_msr_reserve,
14167 .unreserve = single_msr_unreserve,
14168diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14169index ff95824..2ffdcb5 100644
14170--- a/arch/x86/kernel/crash.c
14171+++ b/arch/x86/kernel/crash.c
14172@@ -41,7 +41,7 @@ static void kdump_nmi_callback(int cpu, struct die_args *args)
14173 regs = args->regs;
14174
14175 #ifdef CONFIG_X86_32
14176- if (!user_mode_vm(regs)) {
14177+ if (!user_mode(regs)) {
14178 crash_fixup_ss_esp(&fixed_regs, regs);
14179 regs = &fixed_regs;
14180 }
14181diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14182index 37250fe..bf2ec74 100644
14183--- a/arch/x86/kernel/doublefault_32.c
14184+++ b/arch/x86/kernel/doublefault_32.c
14185@@ -11,7 +11,7 @@
14186
14187 #define DOUBLEFAULT_STACKSIZE (1024)
14188 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14189-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14190+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14191
14192 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14193
14194@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14195 unsigned long gdt, tss;
14196
14197 store_gdt(&gdt_desc);
14198- gdt = gdt_desc.address;
14199+ gdt = (unsigned long)gdt_desc.address;
14200
14201 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14202
14203@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14204 /* 0x2 bit is always set */
14205 .flags = X86_EFLAGS_SF | 0x2,
14206 .sp = STACK_START,
14207- .es = __USER_DS,
14208+ .es = __KERNEL_DS,
14209 .cs = __KERNEL_CS,
14210 .ss = __KERNEL_DS,
14211- .ds = __USER_DS,
14212+ .ds = __KERNEL_DS,
14213 .fs = __KERNEL_PERCPU,
14214
14215 .__cr3 = __pa_nodebug(swapper_pg_dir),
14216diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14217index 2d8a371..4fa6ae6 100644
14218--- a/arch/x86/kernel/dumpstack.c
14219+++ b/arch/x86/kernel/dumpstack.c
14220@@ -2,6 +2,9 @@
14221 * Copyright (C) 1991, 1992 Linus Torvalds
14222 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14223 */
14224+#ifdef CONFIG_GRKERNSEC_HIDESYM
14225+#define __INCLUDED_BY_HIDESYM 1
14226+#endif
14227 #include <linux/kallsyms.h>
14228 #include <linux/kprobes.h>
14229 #include <linux/uaccess.h>
14230@@ -28,7 +31,7 @@ static int die_counter;
14231
14232 void printk_address(unsigned long address, int reliable)
14233 {
14234- printk(" [<%p>] %s%pS\n", (void *) address,
14235+ printk(" [<%p>] %s%pA\n", (void *) address,
14236 reliable ? "" : "? ", (void *) address);
14237 }
14238
14239@@ -36,9 +39,8 @@ void printk_address(unsigned long address, int reliable)
14240 static void
14241 print_ftrace_graph_addr(unsigned long addr, void *data,
14242 const struct stacktrace_ops *ops,
14243- struct thread_info *tinfo, int *graph)
14244+ struct task_struct *task, int *graph)
14245 {
14246- struct task_struct *task = tinfo->task;
14247 unsigned long ret_addr;
14248 int index = task->curr_ret_stack;
14249
14250@@ -59,7 +61,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14251 static inline void
14252 print_ftrace_graph_addr(unsigned long addr, void *data,
14253 const struct stacktrace_ops *ops,
14254- struct thread_info *tinfo, int *graph)
14255+ struct task_struct *task, int *graph)
14256 { }
14257 #endif
14258
14259@@ -70,10 +72,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14260 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14261 */
14262
14263-static inline int valid_stack_ptr(struct thread_info *tinfo,
14264- void *p, unsigned int size, void *end)
14265+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14266 {
14267- void *t = tinfo;
14268 if (end) {
14269 if (p < end && p >= (end-THREAD_SIZE))
14270 return 1;
14271@@ -84,14 +84,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14272 }
14273
14274 unsigned long
14275-print_context_stack(struct thread_info *tinfo,
14276+print_context_stack(struct task_struct *task, void *stack_start,
14277 unsigned long *stack, unsigned long bp,
14278 const struct stacktrace_ops *ops, void *data,
14279 unsigned long *end, int *graph)
14280 {
14281 struct stack_frame *frame = (struct stack_frame *)bp;
14282
14283- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14284+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14285 unsigned long addr;
14286
14287 addr = *stack;
14288@@ -103,7 +103,7 @@ print_context_stack(struct thread_info *tinfo,
14289 } else {
14290 ops->address(data, addr, 0);
14291 }
14292- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14293+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14294 }
14295 stack++;
14296 }
14297@@ -180,7 +180,7 @@ void dump_stack(void)
14298 #endif
14299
14300 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14301- current->pid, current->comm, print_tainted(),
14302+ task_pid_nr(current), current->comm, print_tainted(),
14303 init_utsname()->release,
14304 (int)strcspn(init_utsname()->version, " "),
14305 init_utsname()->version);
14306@@ -220,6 +220,8 @@ unsigned __kprobes long oops_begin(void)
14307 return flags;
14308 }
14309
14310+extern void gr_handle_kernel_exploit(void);
14311+
14312 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14313 {
14314 if (regs && kexec_should_crash(current))
14315@@ -241,7 +243,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14316 panic("Fatal exception in interrupt");
14317 if (panic_on_oops)
14318 panic("Fatal exception");
14319- do_exit(signr);
14320+
14321+ gr_handle_kernel_exploit();
14322+
14323+ do_group_exit(signr);
14324 }
14325
14326 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14327@@ -295,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14328 unsigned long flags = oops_begin();
14329 int sig = SIGSEGV;
14330
14331- if (!user_mode_vm(regs))
14332+ if (!user_mode(regs))
14333 report_bug(regs->ip, regs);
14334
14335 if (__die(str, regs, err))
14336diff --git a/arch/x86/kernel/dumpstack.h b/arch/x86/kernel/dumpstack.h
14337index 81086c2..13e8b17 100644
14338--- a/arch/x86/kernel/dumpstack.h
14339+++ b/arch/x86/kernel/dumpstack.h
14340@@ -15,7 +15,7 @@
14341 #endif
14342
14343 extern unsigned long
14344-print_context_stack(struct thread_info *tinfo,
14345+print_context_stack(struct task_struct *task, void *stack_start,
14346 unsigned long *stack, unsigned long bp,
14347 const struct stacktrace_ops *ops, void *data,
14348 unsigned long *end, int *graph);
14349diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14350index f7dd2a7..504f53b 100644
14351--- a/arch/x86/kernel/dumpstack_32.c
14352+++ b/arch/x86/kernel/dumpstack_32.c
14353@@ -53,16 +53,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14354 #endif
14355
14356 for (;;) {
14357- struct thread_info *context;
14358+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14359+ bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14360
14361- context = (struct thread_info *)
14362- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14363- bp = print_context_stack(context, stack, bp, ops,
14364- data, NULL, &graph);
14365-
14366- stack = (unsigned long *)context->previous_esp;
14367- if (!stack)
14368+ if (stack_start == task_stack_page(task))
14369 break;
14370+ stack = *(unsigned long **)stack_start;
14371 if (ops->stack(data, "IRQ") < 0)
14372 break;
14373 touch_nmi_watchdog();
14374@@ -112,11 +108,12 @@ void show_registers(struct pt_regs *regs)
14375 * When in-kernel, we also print out the stack and code at the
14376 * time of the fault..
14377 */
14378- if (!user_mode_vm(regs)) {
14379+ if (!user_mode(regs)) {
14380 unsigned int code_prologue = code_bytes * 43 / 64;
14381 unsigned int code_len = code_bytes;
14382 unsigned char c;
14383 u8 *ip;
14384+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14385
14386 printk(KERN_EMERG "Stack:\n");
14387 show_stack_log_lvl(NULL, regs, &regs->sp,
14388@@ -124,10 +121,10 @@ void show_registers(struct pt_regs *regs)
14389
14390 printk(KERN_EMERG "Code: ");
14391
14392- ip = (u8 *)regs->ip - code_prologue;
14393+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14394 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14395 /* try starting at IP */
14396- ip = (u8 *)regs->ip;
14397+ ip = (u8 *)regs->ip + cs_base;
14398 code_len = code_len - code_prologue + 1;
14399 }
14400 for (i = 0; i < code_len; i++, ip++) {
14401@@ -136,7 +133,7 @@ void show_registers(struct pt_regs *regs)
14402 printk(" Bad EIP value.");
14403 break;
14404 }
14405- if (ip == (u8 *)regs->ip)
14406+ if (ip == (u8 *)regs->ip + cs_base)
14407 printk("<%02x> ", c);
14408 else
14409 printk("%02x ", c);
14410@@ -145,10 +142,23 @@ void show_registers(struct pt_regs *regs)
14411 printk("\n");
14412 }
14413
14414+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14415+void pax_check_alloca(unsigned long size)
14416+{
14417+ unsigned long sp = (unsigned long)&sp, stack_left;
14418+
14419+ /* all kernel stacks are of the same size */
14420+ stack_left = sp & (THREAD_SIZE - 1);
14421+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14422+}
14423+EXPORT_SYMBOL(pax_check_alloca);
14424+#endif
14425+
14426 int is_valid_bugaddr(unsigned long ip)
14427 {
14428 unsigned short ud2;
14429
14430+ ip = ktla_ktva(ip);
14431 if (ip < PAGE_OFFSET)
14432 return 0;
14433 if (probe_kernel_address((unsigned short *)ip, ud2))
14434diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14435index a071e6b..36cd585 100644
14436--- a/arch/x86/kernel/dumpstack_64.c
14437+++ b/arch/x86/kernel/dumpstack_64.c
14438@@ -116,8 +116,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14439 unsigned long *irq_stack_end =
14440 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14441 unsigned used = 0;
14442- struct thread_info *tinfo;
14443 int graph = 0;
14444+ void *stack_start;
14445
14446 if (!task)
14447 task = current;
14448@@ -146,10 +146,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14449 * current stack address. If the stacks consist of nested
14450 * exceptions
14451 */
14452- tinfo = task_thread_info(task);
14453 for (;;) {
14454 char *id;
14455 unsigned long *estack_end;
14456+
14457 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14458 &used, &id);
14459
14460@@ -157,7 +157,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14461 if (ops->stack(data, id) < 0)
14462 break;
14463
14464- bp = print_context_stack(tinfo, stack, bp, ops,
14465+ bp = print_context_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14466 data, estack_end, &graph);
14467 ops->stack(data, "<EOE>");
14468 /*
14469@@ -176,7 +176,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14470 if (stack >= irq_stack && stack < irq_stack_end) {
14471 if (ops->stack(data, "IRQ") < 0)
14472 break;
14473- bp = print_context_stack(tinfo, stack, bp,
14474+ bp = print_context_stack(task, irq_stack, stack, bp,
14475 ops, data, irq_stack_end, &graph);
14476 /*
14477 * We link to the next stack (which would be
14478@@ -195,7 +195,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14479 /*
14480 * This handles the process stack:
14481 */
14482- bp = print_context_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14483+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14484+ bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14485 put_cpu();
14486 }
14487 EXPORT_SYMBOL(dump_trace);
14488@@ -304,3 +305,50 @@ int is_valid_bugaddr(unsigned long ip)
14489 return ud2 == 0x0b0f;
14490 }
14491
14492+
14493+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14494+void pax_check_alloca(unsigned long size)
14495+{
14496+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14497+ unsigned cpu, used;
14498+ char *id;
14499+
14500+ /* check the process stack first */
14501+ stack_start = (unsigned long)task_stack_page(current);
14502+ stack_end = stack_start + THREAD_SIZE;
14503+ if (likely(stack_start <= sp && sp < stack_end)) {
14504+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14505+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14506+ return;
14507+ }
14508+
14509+ cpu = get_cpu();
14510+
14511+ /* check the irq stacks */
14512+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14513+ stack_start = stack_end - IRQ_STACK_SIZE;
14514+ if (stack_start <= sp && sp < stack_end) {
14515+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14516+ put_cpu();
14517+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14518+ return;
14519+ }
14520+
14521+ /* check the exception stacks */
14522+ used = 0;
14523+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14524+ stack_start = stack_end - EXCEPTION_STKSZ;
14525+ if (stack_end && stack_start <= sp && sp < stack_end) {
14526+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14527+ put_cpu();
14528+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14529+ return;
14530+ }
14531+
14532+ put_cpu();
14533+
14534+ /* unknown stack */
14535+ BUG();
14536+}
14537+EXPORT_SYMBOL(pax_check_alloca);
14538+#endif
14539diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
14540index a89739a..95e0c48 100644
14541--- a/arch/x86/kernel/e820.c
14542+++ b/arch/x86/kernel/e820.c
14543@@ -733,7 +733,7 @@ struct early_res {
14544 };
14545 static struct early_res early_res[MAX_EARLY_RES] __initdata = {
14546 { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */
14547- {}
14548+ { 0, 0, {0}, 0 }
14549 };
14550
14551 static int __init find_overlapped_early(u64 start, u64 end)
14552diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14553index b9c830c..1e41a96 100644
14554--- a/arch/x86/kernel/early_printk.c
14555+++ b/arch/x86/kernel/early_printk.c
14556@@ -7,6 +7,7 @@
14557 #include <linux/pci_regs.h>
14558 #include <linux/pci_ids.h>
14559 #include <linux/errno.h>
14560+#include <linux/sched.h>
14561 #include <asm/io.h>
14562 #include <asm/processor.h>
14563 #include <asm/fcntl.h>
14564@@ -170,6 +171,8 @@ asmlinkage void early_printk(const char *fmt, ...)
14565 int n;
14566 va_list ap;
14567
14568+ pax_track_stack();
14569+
14570 va_start(ap, fmt);
14571 n = vscnprintf(buf, sizeof(buf), fmt, ap);
14572 early_console->write(early_console, buf, n);
14573diff --git a/arch/x86/kernel/efi_32.c b/arch/x86/kernel/efi_32.c
14574index 5cab48e..b025f9b 100644
14575--- a/arch/x86/kernel/efi_32.c
14576+++ b/arch/x86/kernel/efi_32.c
14577@@ -38,70 +38,56 @@
14578 */
14579
14580 static unsigned long efi_rt_eflags;
14581-static pgd_t efi_bak_pg_dir_pointer[2];
14582+static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
14583
14584-void efi_call_phys_prelog(void)
14585+void __init efi_call_phys_prelog(void)
14586 {
14587- unsigned long cr4;
14588- unsigned long temp;
14589 struct desc_ptr gdt_descr;
14590
14591+#ifdef CONFIG_PAX_KERNEXEC
14592+ struct desc_struct d;
14593+#endif
14594+
14595 local_irq_save(efi_rt_eflags);
14596
14597- /*
14598- * If I don't have PAE, I should just duplicate two entries in page
14599- * directory. If I have PAE, I just need to duplicate one entry in
14600- * page directory.
14601- */
14602- cr4 = read_cr4_safe();
14603-
14604- if (cr4 & X86_CR4_PAE) {
14605- efi_bak_pg_dir_pointer[0].pgd =
14606- swapper_pg_dir[pgd_index(0)].pgd;
14607- swapper_pg_dir[0].pgd =
14608- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
14609- } else {
14610- efi_bak_pg_dir_pointer[0].pgd =
14611- swapper_pg_dir[pgd_index(0)].pgd;
14612- efi_bak_pg_dir_pointer[1].pgd =
14613- swapper_pg_dir[pgd_index(0x400000)].pgd;
14614- swapper_pg_dir[pgd_index(0)].pgd =
14615- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
14616- temp = PAGE_OFFSET + 0x400000;
14617- swapper_pg_dir[pgd_index(0x400000)].pgd =
14618- swapper_pg_dir[pgd_index(temp)].pgd;
14619- }
14620+ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
14621+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
14622+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
14623
14624 /*
14625 * After the lock is released, the original page table is restored.
14626 */
14627 __flush_tlb_all();
14628
14629+#ifdef CONFIG_PAX_KERNEXEC
14630+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
14631+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
14632+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
14633+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
14634+#endif
14635+
14636 gdt_descr.address = __pa(get_cpu_gdt_table(0));
14637 gdt_descr.size = GDT_SIZE - 1;
14638 load_gdt(&gdt_descr);
14639 }
14640
14641-void efi_call_phys_epilog(void)
14642+void __init efi_call_phys_epilog(void)
14643 {
14644- unsigned long cr4;
14645 struct desc_ptr gdt_descr;
14646
14647+#ifdef CONFIG_PAX_KERNEXEC
14648+ struct desc_struct d;
14649+
14650+ memset(&d, 0, sizeof d);
14651+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
14652+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
14653+#endif
14654+
14655 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
14656 gdt_descr.size = GDT_SIZE - 1;
14657 load_gdt(&gdt_descr);
14658
14659- cr4 = read_cr4_safe();
14660-
14661- if (cr4 & X86_CR4_PAE) {
14662- swapper_pg_dir[pgd_index(0)].pgd =
14663- efi_bak_pg_dir_pointer[0].pgd;
14664- } else {
14665- swapper_pg_dir[pgd_index(0)].pgd =
14666- efi_bak_pg_dir_pointer[0].pgd;
14667- swapper_pg_dir[pgd_index(0x400000)].pgd =
14668- efi_bak_pg_dir_pointer[1].pgd;
14669- }
14670+ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
14671
14672 /*
14673 * After the lock is released, the original page table is restored.
14674diff --git a/arch/x86/kernel/efi_stub_32.S b/arch/x86/kernel/efi_stub_32.S
14675index fbe66e6..c5c0dd2 100644
14676--- a/arch/x86/kernel/efi_stub_32.S
14677+++ b/arch/x86/kernel/efi_stub_32.S
14678@@ -6,7 +6,9 @@
14679 */
14680
14681 #include <linux/linkage.h>
14682+#include <linux/init.h>
14683 #include <asm/page_types.h>
14684+#include <asm/segment.h>
14685
14686 /*
14687 * efi_call_phys(void *, ...) is a function with variable parameters.
14688@@ -20,7 +22,7 @@
14689 * service functions will comply with gcc calling convention, too.
14690 */
14691
14692-.text
14693+__INIT
14694 ENTRY(efi_call_phys)
14695 /*
14696 * 0. The function can only be called in Linux kernel. So CS has been
14697@@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
14698 * The mapping of lower virtual memory has been created in prelog and
14699 * epilog.
14700 */
14701- movl $1f, %edx
14702- subl $__PAGE_OFFSET, %edx
14703- jmp *%edx
14704+ movl $(__KERNEXEC_EFI_DS), %edx
14705+ mov %edx, %ds
14706+ mov %edx, %es
14707+ mov %edx, %ss
14708+ ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
14709 1:
14710
14711 /*
14712@@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
14713 * parameter 2, ..., param n. To make things easy, we save the return
14714 * address of efi_call_phys in a global variable.
14715 */
14716- popl %edx
14717- movl %edx, saved_return_addr
14718- /* get the function pointer into ECX*/
14719- popl %ecx
14720- movl %ecx, efi_rt_function_ptr
14721- movl $2f, %edx
14722- subl $__PAGE_OFFSET, %edx
14723- pushl %edx
14724+ popl (saved_return_addr)
14725+ popl (efi_rt_function_ptr)
14726
14727 /*
14728 * 3. Clear PG bit in %CR0.
14729@@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
14730 /*
14731 * 5. Call the physical function.
14732 */
14733- jmp *%ecx
14734+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
14735
14736-2:
14737 /*
14738 * 6. After EFI runtime service returns, control will return to
14739 * following instruction. We'd better readjust stack pointer first.
14740@@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
14741 movl %cr0, %edx
14742 orl $0x80000000, %edx
14743 movl %edx, %cr0
14744- jmp 1f
14745-1:
14746+
14747 /*
14748 * 8. Now restore the virtual mode from flat mode by
14749 * adding EIP with PAGE_OFFSET.
14750 */
14751- movl $1f, %edx
14752- jmp *%edx
14753+ ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
14754 1:
14755+ movl $(__KERNEL_DS), %edx
14756+ mov %edx, %ds
14757+ mov %edx, %es
14758+ mov %edx, %ss
14759
14760 /*
14761 * 9. Balance the stack. And because EAX contain the return value,
14762 * we'd better not clobber it.
14763 */
14764- leal efi_rt_function_ptr, %edx
14765- movl (%edx), %ecx
14766- pushl %ecx
14767+ pushl (efi_rt_function_ptr)
14768
14769 /*
14770- * 10. Push the saved return address onto the stack and return.
14771+ * 10. Return to the saved return address.
14772 */
14773- leal saved_return_addr, %edx
14774- movl (%edx), %ecx
14775- pushl %ecx
14776- ret
14777+ jmpl *(saved_return_addr)
14778 ENDPROC(efi_call_phys)
14779 .previous
14780
14781-.data
14782+__INITDATA
14783 saved_return_addr:
14784 .long 0
14785 efi_rt_function_ptr:
14786diff --git a/arch/x86/kernel/efi_stub_64.S b/arch/x86/kernel/efi_stub_64.S
14787index 4c07cca..2c8427d 100644
14788--- a/arch/x86/kernel/efi_stub_64.S
14789+++ b/arch/x86/kernel/efi_stub_64.S
14790@@ -7,6 +7,7 @@
14791 */
14792
14793 #include <linux/linkage.h>
14794+#include <asm/alternative-asm.h>
14795
14796 #define SAVE_XMM \
14797 mov %rsp, %rax; \
14798@@ -40,6 +41,7 @@ ENTRY(efi_call0)
14799 call *%rdi
14800 addq $32, %rsp
14801 RESTORE_XMM
14802+ pax_force_retaddr 0, 1
14803 ret
14804 ENDPROC(efi_call0)
14805
14806@@ -50,6 +52,7 @@ ENTRY(efi_call1)
14807 call *%rdi
14808 addq $32, %rsp
14809 RESTORE_XMM
14810+ pax_force_retaddr 0, 1
14811 ret
14812 ENDPROC(efi_call1)
14813
14814@@ -60,6 +63,7 @@ ENTRY(efi_call2)
14815 call *%rdi
14816 addq $32, %rsp
14817 RESTORE_XMM
14818+ pax_force_retaddr 0, 1
14819 ret
14820 ENDPROC(efi_call2)
14821
14822@@ -71,6 +75,7 @@ ENTRY(efi_call3)
14823 call *%rdi
14824 addq $32, %rsp
14825 RESTORE_XMM
14826+ pax_force_retaddr 0, 1
14827 ret
14828 ENDPROC(efi_call3)
14829
14830@@ -83,6 +88,7 @@ ENTRY(efi_call4)
14831 call *%rdi
14832 addq $32, %rsp
14833 RESTORE_XMM
14834+ pax_force_retaddr 0, 1
14835 ret
14836 ENDPROC(efi_call4)
14837
14838@@ -96,6 +102,7 @@ ENTRY(efi_call5)
14839 call *%rdi
14840 addq $48, %rsp
14841 RESTORE_XMM
14842+ pax_force_retaddr 0, 1
14843 ret
14844 ENDPROC(efi_call5)
14845
14846@@ -112,5 +119,6 @@ ENTRY(efi_call6)
14847 call *%rdi
14848 addq $48, %rsp
14849 RESTORE_XMM
14850+ pax_force_retaddr 0, 1
14851 ret
14852 ENDPROC(efi_call6)
14853diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14854index c097e7d..c689cf4 100644
14855--- a/arch/x86/kernel/entry_32.S
14856+++ b/arch/x86/kernel/entry_32.S
14857@@ -185,13 +185,146 @@
14858 /*CFI_REL_OFFSET gs, PT_GS*/
14859 .endm
14860 .macro SET_KERNEL_GS reg
14861+
14862+#ifdef CONFIG_CC_STACKPROTECTOR
14863 movl $(__KERNEL_STACK_CANARY), \reg
14864+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14865+ movl $(__USER_DS), \reg
14866+#else
14867+ xorl \reg, \reg
14868+#endif
14869+
14870 movl \reg, %gs
14871 .endm
14872
14873 #endif /* CONFIG_X86_32_LAZY_GS */
14874
14875-.macro SAVE_ALL
14876+.macro pax_enter_kernel
14877+#ifdef CONFIG_PAX_KERNEXEC
14878+ call pax_enter_kernel
14879+#endif
14880+.endm
14881+
14882+.macro pax_exit_kernel
14883+#ifdef CONFIG_PAX_KERNEXEC
14884+ call pax_exit_kernel
14885+#endif
14886+.endm
14887+
14888+#ifdef CONFIG_PAX_KERNEXEC
14889+ENTRY(pax_enter_kernel)
14890+#ifdef CONFIG_PARAVIRT
14891+ pushl %eax
14892+ pushl %ecx
14893+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14894+ mov %eax, %esi
14895+#else
14896+ mov %cr0, %esi
14897+#endif
14898+ bts $16, %esi
14899+ jnc 1f
14900+ mov %cs, %esi
14901+ cmp $__KERNEL_CS, %esi
14902+ jz 3f
14903+ ljmp $__KERNEL_CS, $3f
14904+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14905+2:
14906+#ifdef CONFIG_PARAVIRT
14907+ mov %esi, %eax
14908+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14909+#else
14910+ mov %esi, %cr0
14911+#endif
14912+3:
14913+#ifdef CONFIG_PARAVIRT
14914+ popl %ecx
14915+ popl %eax
14916+#endif
14917+ ret
14918+ENDPROC(pax_enter_kernel)
14919+
14920+ENTRY(pax_exit_kernel)
14921+#ifdef CONFIG_PARAVIRT
14922+ pushl %eax
14923+ pushl %ecx
14924+#endif
14925+ mov %cs, %esi
14926+ cmp $__KERNEXEC_KERNEL_CS, %esi
14927+ jnz 2f
14928+#ifdef CONFIG_PARAVIRT
14929+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14930+ mov %eax, %esi
14931+#else
14932+ mov %cr0, %esi
14933+#endif
14934+ btr $16, %esi
14935+ ljmp $__KERNEL_CS, $1f
14936+1:
14937+#ifdef CONFIG_PARAVIRT
14938+ mov %esi, %eax
14939+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14940+#else
14941+ mov %esi, %cr0
14942+#endif
14943+2:
14944+#ifdef CONFIG_PARAVIRT
14945+ popl %ecx
14946+ popl %eax
14947+#endif
14948+ ret
14949+ENDPROC(pax_exit_kernel)
14950+#endif
14951+
14952+.macro pax_erase_kstack
14953+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14954+ call pax_erase_kstack
14955+#endif
14956+.endm
14957+
14958+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14959+/*
14960+ * ebp: thread_info
14961+ * ecx, edx: can be clobbered
14962+ */
14963+ENTRY(pax_erase_kstack)
14964+ pushl %edi
14965+ pushl %eax
14966+
14967+ mov TI_lowest_stack(%ebp), %edi
14968+ mov $-0xBEEF, %eax
14969+ std
14970+
14971+1: mov %edi, %ecx
14972+ and $THREAD_SIZE_asm - 1, %ecx
14973+ shr $2, %ecx
14974+ repne scasl
14975+ jecxz 2f
14976+
14977+ cmp $2*16, %ecx
14978+ jc 2f
14979+
14980+ mov $2*16, %ecx
14981+ repe scasl
14982+ jecxz 2f
14983+ jne 1b
14984+
14985+2: cld
14986+ mov %esp, %ecx
14987+ sub %edi, %ecx
14988+ shr $2, %ecx
14989+ rep stosl
14990+
14991+ mov TI_task_thread_sp0(%ebp), %edi
14992+ sub $128, %edi
14993+ mov %edi, TI_lowest_stack(%ebp)
14994+
14995+ popl %eax
14996+ popl %edi
14997+ ret
14998+ENDPROC(pax_erase_kstack)
14999+#endif
15000+
15001+.macro __SAVE_ALL _DS
15002 cld
15003 PUSH_GS
15004 pushl %fs
15005@@ -224,7 +357,7 @@
15006 pushl %ebx
15007 CFI_ADJUST_CFA_OFFSET 4
15008 CFI_REL_OFFSET ebx, 0
15009- movl $(__USER_DS), %edx
15010+ movl $\_DS, %edx
15011 movl %edx, %ds
15012 movl %edx, %es
15013 movl $(__KERNEL_PERCPU), %edx
15014@@ -232,6 +365,15 @@
15015 SET_KERNEL_GS %edx
15016 .endm
15017
15018+.macro SAVE_ALL
15019+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15020+ __SAVE_ALL __KERNEL_DS
15021+ pax_enter_kernel
15022+#else
15023+ __SAVE_ALL __USER_DS
15024+#endif
15025+.endm
15026+
15027 .macro RESTORE_INT_REGS
15028 popl %ebx
15029 CFI_ADJUST_CFA_OFFSET -4
15030@@ -331,7 +473,7 @@ ENTRY(ret_from_fork)
15031 CFI_ADJUST_CFA_OFFSET -4
15032 jmp syscall_exit
15033 CFI_ENDPROC
15034-END(ret_from_fork)
15035+ENDPROC(ret_from_fork)
15036
15037 /*
15038 * Return to user mode is not as complex as all this looks,
15039@@ -352,7 +494,15 @@ check_userspace:
15040 movb PT_CS(%esp), %al
15041 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
15042 cmpl $USER_RPL, %eax
15043+
15044+#ifdef CONFIG_PAX_KERNEXEC
15045+ jae resume_userspace
15046+
15047+ PAX_EXIT_KERNEL
15048+ jmp resume_kernel
15049+#else
15050 jb resume_kernel # not returning to v8086 or userspace
15051+#endif
15052
15053 ENTRY(resume_userspace)
15054 LOCKDEP_SYS_EXIT
15055@@ -364,8 +514,8 @@ ENTRY(resume_userspace)
15056 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15057 # int/exception return?
15058 jne work_pending
15059- jmp restore_all
15060-END(ret_from_exception)
15061+ jmp restore_all_pax
15062+ENDPROC(ret_from_exception)
15063
15064 #ifdef CONFIG_PREEMPT
15065 ENTRY(resume_kernel)
15066@@ -380,7 +530,7 @@ need_resched:
15067 jz restore_all
15068 call preempt_schedule_irq
15069 jmp need_resched
15070-END(resume_kernel)
15071+ENDPROC(resume_kernel)
15072 #endif
15073 CFI_ENDPROC
15074
15075@@ -414,25 +564,36 @@ sysenter_past_esp:
15076 /*CFI_REL_OFFSET cs, 0*/
15077 /*
15078 * Push current_thread_info()->sysenter_return to the stack.
15079- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15080- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15081 */
15082- pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
15083+ pushl $0
15084 CFI_ADJUST_CFA_OFFSET 4
15085 CFI_REL_OFFSET eip, 0
15086
15087 pushl %eax
15088 CFI_ADJUST_CFA_OFFSET 4
15089 SAVE_ALL
15090+ GET_THREAD_INFO(%ebp)
15091+ movl TI_sysenter_return(%ebp),%ebp
15092+ movl %ebp,PT_EIP(%esp)
15093 ENABLE_INTERRUPTS(CLBR_NONE)
15094
15095 /*
15096 * Load the potential sixth argument from user stack.
15097 * Careful about security.
15098 */
15099+ movl PT_OLDESP(%esp),%ebp
15100+
15101+#ifdef CONFIG_PAX_MEMORY_UDEREF
15102+ mov PT_OLDSS(%esp),%ds
15103+1: movl %ds:(%ebp),%ebp
15104+ push %ss
15105+ pop %ds
15106+#else
15107 cmpl $__PAGE_OFFSET-3,%ebp
15108 jae syscall_fault
15109 1: movl (%ebp),%ebp
15110+#endif
15111+
15112 movl %ebp,PT_EBP(%esp)
15113 .section __ex_table,"a"
15114 .align 4
15115@@ -455,12 +616,24 @@ sysenter_do_call:
15116 testl $_TIF_ALLWORK_MASK, %ecx
15117 jne sysexit_audit
15118 sysenter_exit:
15119+
15120+#ifdef CONFIG_PAX_RANDKSTACK
15121+ pushl_cfi %eax
15122+ movl %esp, %eax
15123+ call pax_randomize_kstack
15124+ popl_cfi %eax
15125+#endif
15126+
15127+ pax_erase_kstack
15128+
15129 /* if something modifies registers it must also disable sysexit */
15130 movl PT_EIP(%esp), %edx
15131 movl PT_OLDESP(%esp), %ecx
15132 xorl %ebp,%ebp
15133 TRACE_IRQS_ON
15134 1: mov PT_FS(%esp), %fs
15135+2: mov PT_DS(%esp), %ds
15136+3: mov PT_ES(%esp), %es
15137 PTGS_TO_GS
15138 ENABLE_INTERRUPTS_SYSEXIT
15139
15140@@ -477,6 +650,9 @@ sysenter_audit:
15141 movl %eax,%edx /* 2nd arg: syscall number */
15142 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15143 call audit_syscall_entry
15144+
15145+ pax_erase_kstack
15146+
15147 pushl %ebx
15148 CFI_ADJUST_CFA_OFFSET 4
15149 movl PT_EAX(%esp),%eax /* reload syscall number */
15150@@ -504,11 +680,17 @@ sysexit_audit:
15151
15152 CFI_ENDPROC
15153 .pushsection .fixup,"ax"
15154-2: movl $0,PT_FS(%esp)
15155+4: movl $0,PT_FS(%esp)
15156+ jmp 1b
15157+5: movl $0,PT_DS(%esp)
15158+ jmp 1b
15159+6: movl $0,PT_ES(%esp)
15160 jmp 1b
15161 .section __ex_table,"a"
15162 .align 4
15163- .long 1b,2b
15164+ .long 1b,4b
15165+ .long 2b,5b
15166+ .long 3b,6b
15167 .popsection
15168 PTGS_TO_GS_EX
15169 ENDPROC(ia32_sysenter_target)
15170@@ -538,6 +720,15 @@ syscall_exit:
15171 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15172 jne syscall_exit_work
15173
15174+restore_all_pax:
15175+
15176+#ifdef CONFIG_PAX_RANDKSTACK
15177+ movl %esp, %eax
15178+ call pax_randomize_kstack
15179+#endif
15180+
15181+ pax_erase_kstack
15182+
15183 restore_all:
15184 TRACE_IRQS_IRET
15185 restore_all_notrace:
15186@@ -602,10 +793,29 @@ ldt_ss:
15187 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15188 mov %dx, %ax /* eax: new kernel esp */
15189 sub %eax, %edx /* offset (low word is 0) */
15190- PER_CPU(gdt_page, %ebx)
15191+#ifdef CONFIG_SMP
15192+ movl PER_CPU_VAR(cpu_number), %ebx
15193+ shll $PAGE_SHIFT_asm, %ebx
15194+ addl $cpu_gdt_table, %ebx
15195+#else
15196+ movl $cpu_gdt_table, %ebx
15197+#endif
15198 shr $16, %edx
15199+
15200+#ifdef CONFIG_PAX_KERNEXEC
15201+ mov %cr0, %esi
15202+ btr $16, %esi
15203+ mov %esi, %cr0
15204+#endif
15205+
15206 mov %dl, GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx) /* bits 16..23 */
15207 mov %dh, GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx) /* bits 24..31 */
15208+
15209+#ifdef CONFIG_PAX_KERNEXEC
15210+ bts $16, %esi
15211+ mov %esi, %cr0
15212+#endif
15213+
15214 pushl $__ESPFIX_SS
15215 CFI_ADJUST_CFA_OFFSET 4
15216 push %eax /* new kernel esp */
15217@@ -636,36 +846,30 @@ work_resched:
15218 movl TI_flags(%ebp), %ecx
15219 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15220 # than syscall tracing?
15221- jz restore_all
15222+ jz restore_all_pax
15223 testb $_TIF_NEED_RESCHED, %cl
15224 jnz work_resched
15225
15226 work_notifysig: # deal with pending signals and
15227 # notify-resume requests
15228+ movl %esp, %eax
15229 #ifdef CONFIG_VM86
15230 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15231- movl %esp, %eax
15232- jne work_notifysig_v86 # returning to kernel-space or
15233+ jz 1f # returning to kernel-space or
15234 # vm86-space
15235- xorl %edx, %edx
15236- call do_notify_resume
15237- jmp resume_userspace_sig
15238
15239- ALIGN
15240-work_notifysig_v86:
15241 pushl %ecx # save ti_flags for do_notify_resume
15242 CFI_ADJUST_CFA_OFFSET 4
15243 call save_v86_state # %eax contains pt_regs pointer
15244 popl %ecx
15245 CFI_ADJUST_CFA_OFFSET -4
15246 movl %eax, %esp
15247-#else
15248- movl %esp, %eax
15249+1:
15250 #endif
15251 xorl %edx, %edx
15252 call do_notify_resume
15253 jmp resume_userspace_sig
15254-END(work_pending)
15255+ENDPROC(work_pending)
15256
15257 # perform syscall exit tracing
15258 ALIGN
15259@@ -673,11 +877,14 @@ syscall_trace_entry:
15260 movl $-ENOSYS,PT_EAX(%esp)
15261 movl %esp, %eax
15262 call syscall_trace_enter
15263+
15264+ pax_erase_kstack
15265+
15266 /* What it returned is what we'll actually use. */
15267 cmpl $(nr_syscalls), %eax
15268 jnae syscall_call
15269 jmp syscall_exit
15270-END(syscall_trace_entry)
15271+ENDPROC(syscall_trace_entry)
15272
15273 # perform syscall exit tracing
15274 ALIGN
15275@@ -690,20 +897,24 @@ syscall_exit_work:
15276 movl %esp, %eax
15277 call syscall_trace_leave
15278 jmp resume_userspace
15279-END(syscall_exit_work)
15280+ENDPROC(syscall_exit_work)
15281 CFI_ENDPROC
15282
15283 RING0_INT_FRAME # can't unwind into user space anyway
15284 syscall_fault:
15285+#ifdef CONFIG_PAX_MEMORY_UDEREF
15286+ push %ss
15287+ pop %ds
15288+#endif
15289 GET_THREAD_INFO(%ebp)
15290 movl $-EFAULT,PT_EAX(%esp)
15291 jmp resume_userspace
15292-END(syscall_fault)
15293+ENDPROC(syscall_fault)
15294
15295 syscall_badsys:
15296 movl $-ENOSYS,PT_EAX(%esp)
15297 jmp resume_userspace
15298-END(syscall_badsys)
15299+ENDPROC(syscall_badsys)
15300 CFI_ENDPROC
15301
15302 /*
15303@@ -726,6 +937,33 @@ PTREGSCALL(rt_sigreturn)
15304 PTREGSCALL(vm86)
15305 PTREGSCALL(vm86old)
15306
15307+ ALIGN;
15308+ENTRY(kernel_execve)
15309+ push %ebp
15310+ sub $PT_OLDSS+4,%esp
15311+ push %edi
15312+ push %ecx
15313+ push %eax
15314+ lea 3*4(%esp),%edi
15315+ mov $PT_OLDSS/4+1,%ecx
15316+ xorl %eax,%eax
15317+ rep stosl
15318+ pop %eax
15319+ pop %ecx
15320+ pop %edi
15321+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15322+ mov %eax,PT_EBX(%esp)
15323+ mov %edx,PT_ECX(%esp)
15324+ mov %ecx,PT_EDX(%esp)
15325+ mov %esp,%eax
15326+ call sys_execve
15327+ GET_THREAD_INFO(%ebp)
15328+ test %eax,%eax
15329+ jz syscall_exit
15330+ add $PT_OLDSS+4,%esp
15331+ pop %ebp
15332+ ret
15333+
15334 .macro FIXUP_ESPFIX_STACK
15335 /*
15336 * Switch back for ESPFIX stack to the normal zerobased stack
15337@@ -735,7 +973,13 @@ PTREGSCALL(vm86old)
15338 * normal stack and adjusts ESP with the matching offset.
15339 */
15340 /* fixup the stack */
15341- PER_CPU(gdt_page, %ebx)
15342+#ifdef CONFIG_SMP
15343+ movl PER_CPU_VAR(cpu_number), %ebx
15344+ shll $PAGE_SHIFT_asm, %ebx
15345+ addl $cpu_gdt_table, %ebx
15346+#else
15347+ movl $cpu_gdt_table, %ebx
15348+#endif
15349 mov GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx), %al /* bits 16..23 */
15350 mov GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx), %ah /* bits 24..31 */
15351 shl $16, %eax
15352@@ -793,7 +1037,7 @@ vector=vector+1
15353 .endr
15354 2: jmp common_interrupt
15355 .endr
15356-END(irq_entries_start)
15357+ENDPROC(irq_entries_start)
15358
15359 .previous
15360 END(interrupt)
15361@@ -840,7 +1084,7 @@ ENTRY(coprocessor_error)
15362 CFI_ADJUST_CFA_OFFSET 4
15363 jmp error_code
15364 CFI_ENDPROC
15365-END(coprocessor_error)
15366+ENDPROC(coprocessor_error)
15367
15368 ENTRY(simd_coprocessor_error)
15369 RING0_INT_FRAME
15370@@ -850,7 +1094,7 @@ ENTRY(simd_coprocessor_error)
15371 CFI_ADJUST_CFA_OFFSET 4
15372 jmp error_code
15373 CFI_ENDPROC
15374-END(simd_coprocessor_error)
15375+ENDPROC(simd_coprocessor_error)
15376
15377 ENTRY(device_not_available)
15378 RING0_INT_FRAME
15379@@ -860,7 +1104,7 @@ ENTRY(device_not_available)
15380 CFI_ADJUST_CFA_OFFSET 4
15381 jmp error_code
15382 CFI_ENDPROC
15383-END(device_not_available)
15384+ENDPROC(device_not_available)
15385
15386 #ifdef CONFIG_PARAVIRT
15387 ENTRY(native_iret)
15388@@ -869,12 +1113,12 @@ ENTRY(native_iret)
15389 .align 4
15390 .long native_iret, iret_exc
15391 .previous
15392-END(native_iret)
15393+ENDPROC(native_iret)
15394
15395 ENTRY(native_irq_enable_sysexit)
15396 sti
15397 sysexit
15398-END(native_irq_enable_sysexit)
15399+ENDPROC(native_irq_enable_sysexit)
15400 #endif
15401
15402 ENTRY(overflow)
15403@@ -885,7 +1129,7 @@ ENTRY(overflow)
15404 CFI_ADJUST_CFA_OFFSET 4
15405 jmp error_code
15406 CFI_ENDPROC
15407-END(overflow)
15408+ENDPROC(overflow)
15409
15410 ENTRY(bounds)
15411 RING0_INT_FRAME
15412@@ -895,7 +1139,7 @@ ENTRY(bounds)
15413 CFI_ADJUST_CFA_OFFSET 4
15414 jmp error_code
15415 CFI_ENDPROC
15416-END(bounds)
15417+ENDPROC(bounds)
15418
15419 ENTRY(invalid_op)
15420 RING0_INT_FRAME
15421@@ -905,7 +1149,7 @@ ENTRY(invalid_op)
15422 CFI_ADJUST_CFA_OFFSET 4
15423 jmp error_code
15424 CFI_ENDPROC
15425-END(invalid_op)
15426+ENDPROC(invalid_op)
15427
15428 ENTRY(coprocessor_segment_overrun)
15429 RING0_INT_FRAME
15430@@ -915,7 +1159,7 @@ ENTRY(coprocessor_segment_overrun)
15431 CFI_ADJUST_CFA_OFFSET 4
15432 jmp error_code
15433 CFI_ENDPROC
15434-END(coprocessor_segment_overrun)
15435+ENDPROC(coprocessor_segment_overrun)
15436
15437 ENTRY(invalid_TSS)
15438 RING0_EC_FRAME
15439@@ -923,7 +1167,7 @@ ENTRY(invalid_TSS)
15440 CFI_ADJUST_CFA_OFFSET 4
15441 jmp error_code
15442 CFI_ENDPROC
15443-END(invalid_TSS)
15444+ENDPROC(invalid_TSS)
15445
15446 ENTRY(segment_not_present)
15447 RING0_EC_FRAME
15448@@ -931,7 +1175,7 @@ ENTRY(segment_not_present)
15449 CFI_ADJUST_CFA_OFFSET 4
15450 jmp error_code
15451 CFI_ENDPROC
15452-END(segment_not_present)
15453+ENDPROC(segment_not_present)
15454
15455 ENTRY(stack_segment)
15456 RING0_EC_FRAME
15457@@ -939,7 +1183,7 @@ ENTRY(stack_segment)
15458 CFI_ADJUST_CFA_OFFSET 4
15459 jmp error_code
15460 CFI_ENDPROC
15461-END(stack_segment)
15462+ENDPROC(stack_segment)
15463
15464 ENTRY(alignment_check)
15465 RING0_EC_FRAME
15466@@ -947,7 +1191,7 @@ ENTRY(alignment_check)
15467 CFI_ADJUST_CFA_OFFSET 4
15468 jmp error_code
15469 CFI_ENDPROC
15470-END(alignment_check)
15471+ENDPROC(alignment_check)
15472
15473 ENTRY(divide_error)
15474 RING0_INT_FRAME
15475@@ -957,7 +1201,7 @@ ENTRY(divide_error)
15476 CFI_ADJUST_CFA_OFFSET 4
15477 jmp error_code
15478 CFI_ENDPROC
15479-END(divide_error)
15480+ENDPROC(divide_error)
15481
15482 #ifdef CONFIG_X86_MCE
15483 ENTRY(machine_check)
15484@@ -968,7 +1212,7 @@ ENTRY(machine_check)
15485 CFI_ADJUST_CFA_OFFSET 4
15486 jmp error_code
15487 CFI_ENDPROC
15488-END(machine_check)
15489+ENDPROC(machine_check)
15490 #endif
15491
15492 ENTRY(spurious_interrupt_bug)
15493@@ -979,7 +1223,7 @@ ENTRY(spurious_interrupt_bug)
15494 CFI_ADJUST_CFA_OFFSET 4
15495 jmp error_code
15496 CFI_ENDPROC
15497-END(spurious_interrupt_bug)
15498+ENDPROC(spurious_interrupt_bug)
15499
15500 ENTRY(kernel_thread_helper)
15501 pushl $0 # fake return address for unwinder
15502@@ -1095,7 +1339,7 @@ ENDPROC(xen_failsafe_callback)
15503
15504 ENTRY(mcount)
15505 ret
15506-END(mcount)
15507+ENDPROC(mcount)
15508
15509 ENTRY(ftrace_caller)
15510 cmpl $0, function_trace_stop
15511@@ -1124,7 +1368,7 @@ ftrace_graph_call:
15512 .globl ftrace_stub
15513 ftrace_stub:
15514 ret
15515-END(ftrace_caller)
15516+ENDPROC(ftrace_caller)
15517
15518 #else /* ! CONFIG_DYNAMIC_FTRACE */
15519
15520@@ -1160,7 +1404,7 @@ trace:
15521 popl %ecx
15522 popl %eax
15523 jmp ftrace_stub
15524-END(mcount)
15525+ENDPROC(mcount)
15526 #endif /* CONFIG_DYNAMIC_FTRACE */
15527 #endif /* CONFIG_FUNCTION_TRACER */
15528
15529@@ -1181,7 +1425,7 @@ ENTRY(ftrace_graph_caller)
15530 popl %ecx
15531 popl %eax
15532 ret
15533-END(ftrace_graph_caller)
15534+ENDPROC(ftrace_graph_caller)
15535
15536 .globl return_to_handler
15537 return_to_handler:
15538@@ -1198,7 +1442,6 @@ return_to_handler:
15539 ret
15540 #endif
15541
15542-.section .rodata,"a"
15543 #include "syscall_table_32.S"
15544
15545 syscall_table_size=(.-sys_call_table)
15546@@ -1255,15 +1498,18 @@ error_code:
15547 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15548 REG_TO_PTGS %ecx
15549 SET_KERNEL_GS %ecx
15550- movl $(__USER_DS), %ecx
15551+ movl $(__KERNEL_DS), %ecx
15552 movl %ecx, %ds
15553 movl %ecx, %es
15554+
15555+ pax_enter_kernel
15556+
15557 TRACE_IRQS_OFF
15558 movl %esp,%eax # pt_regs pointer
15559 call *%edi
15560 jmp ret_from_exception
15561 CFI_ENDPROC
15562-END(page_fault)
15563+ENDPROC(page_fault)
15564
15565 /*
15566 * Debug traps and NMI can happen at the one SYSENTER instruction
15567@@ -1309,7 +1555,7 @@ debug_stack_correct:
15568 call do_debug
15569 jmp ret_from_exception
15570 CFI_ENDPROC
15571-END(debug)
15572+ENDPROC(debug)
15573
15574 /*
15575 * NMI is doubly nasty. It can happen _while_ we're handling
15576@@ -1351,6 +1597,9 @@ nmi_stack_correct:
15577 xorl %edx,%edx # zero error code
15578 movl %esp,%eax # pt_regs pointer
15579 call do_nmi
15580+
15581+ pax_exit_kernel
15582+
15583 jmp restore_all_notrace
15584 CFI_ENDPROC
15585
15586@@ -1391,12 +1640,15 @@ nmi_espfix_stack:
15587 FIXUP_ESPFIX_STACK # %eax == %esp
15588 xorl %edx,%edx # zero error code
15589 call do_nmi
15590+
15591+ pax_exit_kernel
15592+
15593 RESTORE_REGS
15594 lss 12+4(%esp), %esp # back to espfix stack
15595 CFI_ADJUST_CFA_OFFSET -24
15596 jmp irq_return
15597 CFI_ENDPROC
15598-END(nmi)
15599+ENDPROC(nmi)
15600
15601 ENTRY(int3)
15602 RING0_INT_FRAME
15603@@ -1409,7 +1661,7 @@ ENTRY(int3)
15604 call do_int3
15605 jmp ret_from_exception
15606 CFI_ENDPROC
15607-END(int3)
15608+ENDPROC(int3)
15609
15610 ENTRY(general_protection)
15611 RING0_EC_FRAME
15612@@ -1417,7 +1669,7 @@ ENTRY(general_protection)
15613 CFI_ADJUST_CFA_OFFSET 4
15614 jmp error_code
15615 CFI_ENDPROC
15616-END(general_protection)
15617+ENDPROC(general_protection)
15618
15619 /*
15620 * End of kprobes section
15621diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15622index 34a56a9..4aa5c8b 100644
15623--- a/arch/x86/kernel/entry_64.S
15624+++ b/arch/x86/kernel/entry_64.S
15625@@ -53,6 +53,8 @@
15626 #include <asm/paravirt.h>
15627 #include <asm/ftrace.h>
15628 #include <asm/percpu.h>
15629+#include <asm/pgtable.h>
15630+#include <asm/alternative-asm.h>
15631
15632 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15633 #include <linux/elf-em.h>
15634@@ -64,8 +66,9 @@
15635 #ifdef CONFIG_FUNCTION_TRACER
15636 #ifdef CONFIG_DYNAMIC_FTRACE
15637 ENTRY(mcount)
15638+ pax_force_retaddr
15639 retq
15640-END(mcount)
15641+ENDPROC(mcount)
15642
15643 ENTRY(ftrace_caller)
15644 cmpl $0, function_trace_stop
15645@@ -88,8 +91,9 @@ GLOBAL(ftrace_graph_call)
15646 #endif
15647
15648 GLOBAL(ftrace_stub)
15649+ pax_force_retaddr
15650 retq
15651-END(ftrace_caller)
15652+ENDPROC(ftrace_caller)
15653
15654 #else /* ! CONFIG_DYNAMIC_FTRACE */
15655 ENTRY(mcount)
15656@@ -108,6 +112,7 @@ ENTRY(mcount)
15657 #endif
15658
15659 GLOBAL(ftrace_stub)
15660+ pax_force_retaddr
15661 retq
15662
15663 trace:
15664@@ -117,12 +122,13 @@ trace:
15665 movq 8(%rbp), %rsi
15666 subq $MCOUNT_INSN_SIZE, %rdi
15667
15668+ pax_force_fptr ftrace_trace_function
15669 call *ftrace_trace_function
15670
15671 MCOUNT_RESTORE_FRAME
15672
15673 jmp ftrace_stub
15674-END(mcount)
15675+ENDPROC(mcount)
15676 #endif /* CONFIG_DYNAMIC_FTRACE */
15677 #endif /* CONFIG_FUNCTION_TRACER */
15678
15679@@ -142,8 +148,9 @@ ENTRY(ftrace_graph_caller)
15680
15681 MCOUNT_RESTORE_FRAME
15682
15683+ pax_force_retaddr
15684 retq
15685-END(ftrace_graph_caller)
15686+ENDPROC(ftrace_graph_caller)
15687
15688 GLOBAL(return_to_handler)
15689 subq $24, %rsp
15690@@ -159,6 +166,7 @@ GLOBAL(return_to_handler)
15691 movq 8(%rsp), %rdx
15692 movq (%rsp), %rax
15693 addq $16, %rsp
15694+ pax_force_retaddr
15695 retq
15696 #endif
15697
15698@@ -174,6 +182,282 @@ ENTRY(native_usergs_sysret64)
15699 ENDPROC(native_usergs_sysret64)
15700 #endif /* CONFIG_PARAVIRT */
15701
15702+ .macro ljmpq sel, off
15703+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15704+ .byte 0x48; ljmp *1234f(%rip)
15705+ .pushsection .rodata
15706+ .align 16
15707+ 1234: .quad \off; .word \sel
15708+ .popsection
15709+#else
15710+ pushq $\sel
15711+ pushq $\off
15712+ lretq
15713+#endif
15714+ .endm
15715+
15716+ .macro pax_enter_kernel
15717+ pax_set_fptr_mask
15718+#ifdef CONFIG_PAX_KERNEXEC
15719+ call pax_enter_kernel
15720+#endif
15721+ .endm
15722+
15723+ .macro pax_exit_kernel
15724+#ifdef CONFIG_PAX_KERNEXEC
15725+ call pax_exit_kernel
15726+#endif
15727+ .endm
15728+
15729+#ifdef CONFIG_PAX_KERNEXEC
15730+ENTRY(pax_enter_kernel)
15731+ pushq %rdi
15732+
15733+#ifdef CONFIG_PARAVIRT
15734+ PV_SAVE_REGS(CLBR_RDI)
15735+#endif
15736+
15737+ GET_CR0_INTO_RDI
15738+ bts $16,%rdi
15739+ jnc 3f
15740+ mov %cs,%edi
15741+ cmp $__KERNEL_CS,%edi
15742+ jnz 2f
15743+1:
15744+
15745+#ifdef CONFIG_PARAVIRT
15746+ PV_RESTORE_REGS(CLBR_RDI)
15747+#endif
15748+
15749+ popq %rdi
15750+ pax_force_retaddr
15751+ retq
15752+
15753+2: ljmpq __KERNEL_CS,1f
15754+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15755+4: SET_RDI_INTO_CR0
15756+ jmp 1b
15757+ENDPROC(pax_enter_kernel)
15758+
15759+ENTRY(pax_exit_kernel)
15760+ pushq %rdi
15761+
15762+#ifdef CONFIG_PARAVIRT
15763+ PV_SAVE_REGS(CLBR_RDI)
15764+#endif
15765+
15766+ mov %cs,%rdi
15767+ cmp $__KERNEXEC_KERNEL_CS,%edi
15768+ jz 2f
15769+1:
15770+
15771+#ifdef CONFIG_PARAVIRT
15772+ PV_RESTORE_REGS(CLBR_RDI);
15773+#endif
15774+
15775+ popq %rdi
15776+ pax_force_retaddr
15777+ retq
15778+
15779+2: GET_CR0_INTO_RDI
15780+ btr $16,%rdi
15781+ ljmpq __KERNEL_CS,3f
15782+3: SET_RDI_INTO_CR0
15783+ jmp 1b
15784+#ifdef CONFIG_PARAVIRT
15785+ PV_RESTORE_REGS(CLBR_RDI);
15786+#endif
15787+
15788+ popq %rdi
15789+ pax_force_retaddr
15790+ retq
15791+ENDPROC(pax_exit_kernel)
15792+#endif
15793+
15794+ .macro pax_enter_kernel_user
15795+ pax_set_fptr_mask
15796+#ifdef CONFIG_PAX_MEMORY_UDEREF
15797+ call pax_enter_kernel_user
15798+#endif
15799+ .endm
15800+
15801+ .macro pax_exit_kernel_user
15802+#ifdef CONFIG_PAX_MEMORY_UDEREF
15803+ call pax_exit_kernel_user
15804+#endif
15805+#ifdef CONFIG_PAX_RANDKSTACK
15806+ pushq %rax
15807+ call pax_randomize_kstack
15808+ popq %rax
15809+#endif
15810+ .endm
15811+
15812+#ifdef CONFIG_PAX_MEMORY_UDEREF
15813+ENTRY(pax_enter_kernel_user)
15814+ pushq %rdi
15815+ pushq %rbx
15816+
15817+#ifdef CONFIG_PARAVIRT
15818+ PV_SAVE_REGS(CLBR_RDI)
15819+#endif
15820+
15821+ GET_CR3_INTO_RDI
15822+ mov %rdi,%rbx
15823+ add $__START_KERNEL_map,%rbx
15824+ sub phys_base(%rip),%rbx
15825+
15826+#ifdef CONFIG_PARAVIRT
15827+ pushq %rdi
15828+ cmpl $0, pv_info+PARAVIRT_enabled
15829+ jz 1f
15830+ i = 0
15831+ .rept USER_PGD_PTRS
15832+ mov i*8(%rbx),%rsi
15833+ mov $0,%sil
15834+ lea i*8(%rbx),%rdi
15835+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15836+ i = i + 1
15837+ .endr
15838+ jmp 2f
15839+1:
15840+#endif
15841+
15842+ i = 0
15843+ .rept USER_PGD_PTRS
15844+ movb $0,i*8(%rbx)
15845+ i = i + 1
15846+ .endr
15847+
15848+#ifdef CONFIG_PARAVIRT
15849+2: popq %rdi
15850+#endif
15851+ SET_RDI_INTO_CR3
15852+
15853+#ifdef CONFIG_PAX_KERNEXEC
15854+ GET_CR0_INTO_RDI
15855+ bts $16,%rdi
15856+ SET_RDI_INTO_CR0
15857+#endif
15858+
15859+#ifdef CONFIG_PARAVIRT
15860+ PV_RESTORE_REGS(CLBR_RDI)
15861+#endif
15862+
15863+ popq %rbx
15864+ popq %rdi
15865+ pax_force_retaddr
15866+ retq
15867+ENDPROC(pax_enter_kernel_user)
15868+
15869+ENTRY(pax_exit_kernel_user)
15870+ push %rdi
15871+
15872+#ifdef CONFIG_PARAVIRT
15873+ pushq %rbx
15874+ PV_SAVE_REGS(CLBR_RDI)
15875+#endif
15876+
15877+#ifdef CONFIG_PAX_KERNEXEC
15878+ GET_CR0_INTO_RDI
15879+ btr $16,%rdi
15880+ SET_RDI_INTO_CR0
15881+#endif
15882+
15883+ GET_CR3_INTO_RDI
15884+ add $__START_KERNEL_map,%rdi
15885+ sub phys_base(%rip),%rdi
15886+
15887+#ifdef CONFIG_PARAVIRT
15888+ cmpl $0, pv_info+PARAVIRT_enabled
15889+ jz 1f
15890+ mov %rdi,%rbx
15891+ i = 0
15892+ .rept USER_PGD_PTRS
15893+ mov i*8(%rbx),%rsi
15894+ mov $0x67,%sil
15895+ lea i*8(%rbx),%rdi
15896+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15897+ i = i + 1
15898+ .endr
15899+ jmp 2f
15900+1:
15901+#endif
15902+
15903+ i = 0
15904+ .rept USER_PGD_PTRS
15905+ movb $0x67,i*8(%rdi)
15906+ i = i + 1
15907+ .endr
15908+
15909+#ifdef CONFIG_PARAVIRT
15910+2: PV_RESTORE_REGS(CLBR_RDI)
15911+ popq %rbx
15912+#endif
15913+
15914+ popq %rdi
15915+ pax_force_retaddr
15916+ retq
15917+ENDPROC(pax_exit_kernel_user)
15918+#endif
15919+
15920+.macro pax_erase_kstack
15921+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15922+ call pax_erase_kstack
15923+#endif
15924+.endm
15925+
15926+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15927+/*
15928+ * r11: thread_info
15929+ * rcx, rdx: can be clobbered
15930+ */
15931+ENTRY(pax_erase_kstack)
15932+ pushq %rdi
15933+ pushq %rax
15934+ pushq %r11
15935+
15936+ GET_THREAD_INFO(%r11)
15937+ mov TI_lowest_stack(%r11), %rdi
15938+ mov $-0xBEEF, %rax
15939+ std
15940+
15941+1: mov %edi, %ecx
15942+ and $THREAD_SIZE_asm - 1, %ecx
15943+ shr $3, %ecx
15944+ repne scasq
15945+ jecxz 2f
15946+
15947+ cmp $2*8, %ecx
15948+ jc 2f
15949+
15950+ mov $2*8, %ecx
15951+ repe scasq
15952+ jecxz 2f
15953+ jne 1b
15954+
15955+2: cld
15956+ mov %esp, %ecx
15957+ sub %edi, %ecx
15958+
15959+ cmp $THREAD_SIZE_asm, %rcx
15960+ jb 3f
15961+ ud2
15962+3:
15963+
15964+ shr $3, %ecx
15965+ rep stosq
15966+
15967+ mov TI_task_thread_sp0(%r11), %rdi
15968+ sub $256, %rdi
15969+ mov %rdi, TI_lowest_stack(%r11)
15970+
15971+ popq %r11
15972+ popq %rax
15973+ popq %rdi
15974+ pax_force_retaddr
15975+ ret
15976+ENDPROC(pax_erase_kstack)
15977+#endif
15978
15979 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15980 #ifdef CONFIG_TRACE_IRQFLAGS
15981@@ -233,8 +517,8 @@ ENDPROC(native_usergs_sysret64)
15982 .endm
15983
15984 .macro UNFAKE_STACK_FRAME
15985- addq $8*6, %rsp
15986- CFI_ADJUST_CFA_OFFSET -(6*8)
15987+ addq $8*6 + ARG_SKIP, %rsp
15988+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15989 .endm
15990
15991 /*
15992@@ -317,7 +601,7 @@ ENTRY(save_args)
15993 leaq -ARGOFFSET+16(%rsp),%rdi /* arg1 for handler */
15994 movq_cfi rbp, 8 /* push %rbp */
15995 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
15996- testl $3, CS(%rdi)
15997+ testb $3, CS(%rdi)
15998 je 1f
15999 SWAPGS
16000 /*
16001@@ -337,9 +621,10 @@ ENTRY(save_args)
16002 * We entered an interrupt context - irqs are off:
16003 */
16004 2: TRACE_IRQS_OFF
16005+ pax_force_retaddr
16006 ret
16007 CFI_ENDPROC
16008-END(save_args)
16009+ENDPROC(save_args)
16010
16011 ENTRY(save_rest)
16012 PARTIAL_FRAME 1 REST_SKIP+8
16013@@ -352,9 +637,10 @@ ENTRY(save_rest)
16014 movq_cfi r15, R15+16
16015 movq %r11, 8(%rsp) /* return address */
16016 FIXUP_TOP_OF_STACK %r11, 16
16017+ pax_force_retaddr
16018 ret
16019 CFI_ENDPROC
16020-END(save_rest)
16021+ENDPROC(save_rest)
16022
16023 /* save complete stack frame */
16024 .pushsection .kprobes.text, "ax"
16025@@ -383,9 +669,10 @@ ENTRY(save_paranoid)
16026 js 1f /* negative -> in kernel */
16027 SWAPGS
16028 xorl %ebx,%ebx
16029-1: ret
16030+1: pax_force_retaddr_bts
16031+ ret
16032 CFI_ENDPROC
16033-END(save_paranoid)
16034+ENDPROC(save_paranoid)
16035 .popsection
16036
16037 /*
16038@@ -409,7 +696,7 @@ ENTRY(ret_from_fork)
16039
16040 RESTORE_REST
16041
16042- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16043+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16044 je int_ret_from_sys_call
16045
16046 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16047@@ -419,7 +706,7 @@ ENTRY(ret_from_fork)
16048 jmp ret_from_sys_call # go to the SYSRET fastpath
16049
16050 CFI_ENDPROC
16051-END(ret_from_fork)
16052+ENDPROC(ret_from_fork)
16053
16054 /*
16055 * System call entry. Upto 6 arguments in registers are supported.
16056@@ -455,7 +742,7 @@ END(ret_from_fork)
16057 ENTRY(system_call)
16058 CFI_STARTPROC simple
16059 CFI_SIGNAL_FRAME
16060- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16061+ CFI_DEF_CFA rsp,0
16062 CFI_REGISTER rip,rcx
16063 /*CFI_REGISTER rflags,r11*/
16064 SWAPGS_UNSAFE_STACK
16065@@ -468,12 +755,13 @@ ENTRY(system_call_after_swapgs)
16066
16067 movq %rsp,PER_CPU_VAR(old_rsp)
16068 movq PER_CPU_VAR(kernel_stack),%rsp
16069+ SAVE_ARGS 8*6,1
16070+ pax_enter_kernel_user
16071 /*
16072 * No need to follow this irqs off/on section - it's straight
16073 * and short:
16074 */
16075 ENABLE_INTERRUPTS(CLBR_NONE)
16076- SAVE_ARGS 8,1
16077 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16078 movq %rcx,RIP-ARGOFFSET(%rsp)
16079 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16080@@ -483,7 +771,7 @@ ENTRY(system_call_after_swapgs)
16081 system_call_fastpath:
16082 cmpq $__NR_syscall_max,%rax
16083 ja badsys
16084- movq %r10,%rcx
16085+ movq R10-ARGOFFSET(%rsp),%rcx
16086 call *sys_call_table(,%rax,8) # XXX: rip relative
16087 movq %rax,RAX-ARGOFFSET(%rsp)
16088 /*
16089@@ -502,6 +790,8 @@ sysret_check:
16090 andl %edi,%edx
16091 jnz sysret_careful
16092 CFI_REMEMBER_STATE
16093+ pax_exit_kernel_user
16094+ pax_erase_kstack
16095 /*
16096 * sysretq will re-enable interrupts:
16097 */
16098@@ -555,14 +845,18 @@ badsys:
16099 * jump back to the normal fast path.
16100 */
16101 auditsys:
16102- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16103+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16104 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16105 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16106 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16107 movq %rax,%rsi /* 2nd arg: syscall number */
16108 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16109 call audit_syscall_entry
16110+
16111+ pax_erase_kstack
16112+
16113 LOAD_ARGS 0 /* reload call-clobbered registers */
16114+ pax_set_fptr_mask
16115 jmp system_call_fastpath
16116
16117 /*
16118@@ -592,16 +886,20 @@ tracesys:
16119 FIXUP_TOP_OF_STACK %rdi
16120 movq %rsp,%rdi
16121 call syscall_trace_enter
16122+
16123+ pax_erase_kstack
16124+
16125 /*
16126 * Reload arg registers from stack in case ptrace changed them.
16127 * We don't reload %rax because syscall_trace_enter() returned
16128 * the value it wants us to use in the table lookup.
16129 */
16130 LOAD_ARGS ARGOFFSET, 1
16131+ pax_set_fptr_mask
16132 RESTORE_REST
16133 cmpq $__NR_syscall_max,%rax
16134 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16135- movq %r10,%rcx /* fixup for C */
16136+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16137 call *sys_call_table(,%rax,8)
16138 movq %rax,RAX-ARGOFFSET(%rsp)
16139 /* Use IRET because user could have changed frame */
16140@@ -613,7 +911,7 @@ tracesys:
16141 GLOBAL(int_ret_from_sys_call)
16142 DISABLE_INTERRUPTS(CLBR_NONE)
16143 TRACE_IRQS_OFF
16144- testl $3,CS-ARGOFFSET(%rsp)
16145+ testb $3,CS-ARGOFFSET(%rsp)
16146 je retint_restore_args
16147 movl $_TIF_ALLWORK_MASK,%edi
16148 /* edi: mask to check */
16149@@ -674,7 +972,7 @@ int_restore_rest:
16150 TRACE_IRQS_OFF
16151 jmp int_with_check
16152 CFI_ENDPROC
16153-END(system_call)
16154+ENDPROC(system_call)
16155
16156 /*
16157 * Certain special system calls that need to save a complete full stack frame.
16158@@ -690,7 +988,7 @@ ENTRY(\label)
16159 call \func
16160 jmp ptregscall_common
16161 CFI_ENDPROC
16162-END(\label)
16163+ENDPROC(\label)
16164 .endm
16165
16166 PTREGSCALL stub_clone, sys_clone, %r8
16167@@ -708,9 +1006,10 @@ ENTRY(ptregscall_common)
16168 movq_cfi_restore R12+8, r12
16169 movq_cfi_restore RBP+8, rbp
16170 movq_cfi_restore RBX+8, rbx
16171+ pax_force_retaddr
16172 ret $REST_SKIP /* pop extended registers */
16173 CFI_ENDPROC
16174-END(ptregscall_common)
16175+ENDPROC(ptregscall_common)
16176
16177 ENTRY(stub_execve)
16178 CFI_STARTPROC
16179@@ -726,7 +1025,7 @@ ENTRY(stub_execve)
16180 RESTORE_REST
16181 jmp int_ret_from_sys_call
16182 CFI_ENDPROC
16183-END(stub_execve)
16184+ENDPROC(stub_execve)
16185
16186 /*
16187 * sigreturn is special because it needs to restore all registers on return.
16188@@ -744,7 +1043,7 @@ ENTRY(stub_rt_sigreturn)
16189 RESTORE_REST
16190 jmp int_ret_from_sys_call
16191 CFI_ENDPROC
16192-END(stub_rt_sigreturn)
16193+ENDPROC(stub_rt_sigreturn)
16194
16195 /*
16196 * Build the entry stubs and pointer table with some assembler magic.
16197@@ -780,7 +1079,7 @@ vector=vector+1
16198 2: jmp common_interrupt
16199 .endr
16200 CFI_ENDPROC
16201-END(irq_entries_start)
16202+ENDPROC(irq_entries_start)
16203
16204 .previous
16205 END(interrupt)
16206@@ -800,6 +1099,16 @@ END(interrupt)
16207 CFI_ADJUST_CFA_OFFSET 10*8
16208 call save_args
16209 PARTIAL_FRAME 0
16210+#ifdef CONFIG_PAX_MEMORY_UDEREF
16211+ testb $3, CS(%rdi)
16212+ jnz 1f
16213+ pax_enter_kernel
16214+ jmp 2f
16215+1: pax_enter_kernel_user
16216+2:
16217+#else
16218+ pax_enter_kernel
16219+#endif
16220 call \func
16221 .endm
16222
16223@@ -822,7 +1131,7 @@ ret_from_intr:
16224 CFI_ADJUST_CFA_OFFSET -8
16225 exit_intr:
16226 GET_THREAD_INFO(%rcx)
16227- testl $3,CS-ARGOFFSET(%rsp)
16228+ testb $3,CS-ARGOFFSET(%rsp)
16229 je retint_kernel
16230
16231 /* Interrupt came from user space */
16232@@ -844,12 +1153,16 @@ retint_swapgs: /* return to user-space */
16233 * The iretq could re-enable interrupts:
16234 */
16235 DISABLE_INTERRUPTS(CLBR_ANY)
16236+ pax_exit_kernel_user
16237+ pax_erase_kstack
16238 TRACE_IRQS_IRETQ
16239 SWAPGS
16240 jmp restore_args
16241
16242 retint_restore_args: /* return to kernel space */
16243 DISABLE_INTERRUPTS(CLBR_ANY)
16244+ pax_exit_kernel
16245+ pax_force_retaddr RIP-ARGOFFSET
16246 /*
16247 * The iretq could re-enable interrupts:
16248 */
16249@@ -940,7 +1253,7 @@ ENTRY(retint_kernel)
16250 #endif
16251
16252 CFI_ENDPROC
16253-END(common_interrupt)
16254+ENDPROC(common_interrupt)
16255
16256 /*
16257 * APIC interrupts.
16258@@ -953,7 +1266,7 @@ ENTRY(\sym)
16259 interrupt \do_sym
16260 jmp ret_from_intr
16261 CFI_ENDPROC
16262-END(\sym)
16263+ENDPROC(\sym)
16264 .endm
16265
16266 #ifdef CONFIG_SMP
16267@@ -1032,12 +1345,22 @@ ENTRY(\sym)
16268 CFI_ADJUST_CFA_OFFSET 15*8
16269 call error_entry
16270 DEFAULT_FRAME 0
16271+#ifdef CONFIG_PAX_MEMORY_UDEREF
16272+ testb $3, CS(%rsp)
16273+ jnz 1f
16274+ pax_enter_kernel
16275+ jmp 2f
16276+1: pax_enter_kernel_user
16277+2:
16278+#else
16279+ pax_enter_kernel
16280+#endif
16281 movq %rsp,%rdi /* pt_regs pointer */
16282 xorl %esi,%esi /* no error code */
16283 call \do_sym
16284 jmp error_exit /* %ebx: no swapgs flag */
16285 CFI_ENDPROC
16286-END(\sym)
16287+ENDPROC(\sym)
16288 .endm
16289
16290 .macro paranoidzeroentry sym do_sym
16291@@ -1049,12 +1372,22 @@ ENTRY(\sym)
16292 subq $15*8, %rsp
16293 call save_paranoid
16294 TRACE_IRQS_OFF
16295+#ifdef CONFIG_PAX_MEMORY_UDEREF
16296+ testb $3, CS(%rsp)
16297+ jnz 1f
16298+ pax_enter_kernel
16299+ jmp 2f
16300+1: pax_enter_kernel_user
16301+2:
16302+#else
16303+ pax_enter_kernel
16304+#endif
16305 movq %rsp,%rdi /* pt_regs pointer */
16306 xorl %esi,%esi /* no error code */
16307 call \do_sym
16308 jmp paranoid_exit /* %ebx: no swapgs flag */
16309 CFI_ENDPROC
16310-END(\sym)
16311+ENDPROC(\sym)
16312 .endm
16313
16314 .macro paranoidzeroentry_ist sym do_sym ist
16315@@ -1066,15 +1399,30 @@ ENTRY(\sym)
16316 subq $15*8, %rsp
16317 call save_paranoid
16318 TRACE_IRQS_OFF
16319+#ifdef CONFIG_PAX_MEMORY_UDEREF
16320+ testb $3, CS(%rsp)
16321+ jnz 1f
16322+ pax_enter_kernel
16323+ jmp 2f
16324+1: pax_enter_kernel_user
16325+2:
16326+#else
16327+ pax_enter_kernel
16328+#endif
16329 movq %rsp,%rdi /* pt_regs pointer */
16330 xorl %esi,%esi /* no error code */
16331- PER_CPU(init_tss, %rbp)
16332+#ifdef CONFIG_SMP
16333+ imul $TSS_size, PER_CPU_VAR(cpu_number), %ebp
16334+ lea init_tss(%rbp), %rbp
16335+#else
16336+ lea init_tss(%rip), %rbp
16337+#endif
16338 subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
16339 call \do_sym
16340 addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
16341 jmp paranoid_exit /* %ebx: no swapgs flag */
16342 CFI_ENDPROC
16343-END(\sym)
16344+ENDPROC(\sym)
16345 .endm
16346
16347 .macro errorentry sym do_sym
16348@@ -1085,13 +1433,23 @@ ENTRY(\sym)
16349 CFI_ADJUST_CFA_OFFSET 15*8
16350 call error_entry
16351 DEFAULT_FRAME 0
16352+#ifdef CONFIG_PAX_MEMORY_UDEREF
16353+ testb $3, CS(%rsp)
16354+ jnz 1f
16355+ pax_enter_kernel
16356+ jmp 2f
16357+1: pax_enter_kernel_user
16358+2:
16359+#else
16360+ pax_enter_kernel
16361+#endif
16362 movq %rsp,%rdi /* pt_regs pointer */
16363 movq ORIG_RAX(%rsp),%rsi /* get error code */
16364 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16365 call \do_sym
16366 jmp error_exit /* %ebx: no swapgs flag */
16367 CFI_ENDPROC
16368-END(\sym)
16369+ENDPROC(\sym)
16370 .endm
16371
16372 /* error code is on the stack already */
16373@@ -1104,13 +1462,23 @@ ENTRY(\sym)
16374 call save_paranoid
16375 DEFAULT_FRAME 0
16376 TRACE_IRQS_OFF
16377+#ifdef CONFIG_PAX_MEMORY_UDEREF
16378+ testb $3, CS(%rsp)
16379+ jnz 1f
16380+ pax_enter_kernel
16381+ jmp 2f
16382+1: pax_enter_kernel_user
16383+2:
16384+#else
16385+ pax_enter_kernel
16386+#endif
16387 movq %rsp,%rdi /* pt_regs pointer */
16388 movq ORIG_RAX(%rsp),%rsi /* get error code */
16389 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16390 call \do_sym
16391 jmp paranoid_exit /* %ebx: no swapgs flag */
16392 CFI_ENDPROC
16393-END(\sym)
16394+ENDPROC(\sym)
16395 .endm
16396
16397 zeroentry divide_error do_divide_error
16398@@ -1141,9 +1509,10 @@ gs_change:
16399 SWAPGS
16400 popf
16401 CFI_ADJUST_CFA_OFFSET -8
16402+ pax_force_retaddr
16403 ret
16404 CFI_ENDPROC
16405-END(native_load_gs_index)
16406+ENDPROC(native_load_gs_index)
16407
16408 .section __ex_table,"a"
16409 .align 8
16410@@ -1193,11 +1562,12 @@ ENTRY(kernel_thread)
16411 * of hacks for example to fork off the per-CPU idle tasks.
16412 * [Hopefully no generic code relies on the reschedule -AK]
16413 */
16414- RESTORE_ALL
16415+ RESTORE_REST
16416 UNFAKE_STACK_FRAME
16417+ pax_force_retaddr
16418 ret
16419 CFI_ENDPROC
16420-END(kernel_thread)
16421+ENDPROC(kernel_thread)
16422
16423 ENTRY(child_rip)
16424 pushq $0 # fake return address
16425@@ -1208,13 +1578,14 @@ ENTRY(child_rip)
16426 */
16427 movq %rdi, %rax
16428 movq %rsi, %rdi
16429+ pax_force_fptr %rax
16430 call *%rax
16431 # exit
16432 mov %eax, %edi
16433 call do_exit
16434 ud2 # padding for call trace
16435 CFI_ENDPROC
16436-END(child_rip)
16437+ENDPROC(child_rip)
16438
16439 /*
16440 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16441@@ -1241,11 +1612,11 @@ ENTRY(kernel_execve)
16442 RESTORE_REST
16443 testq %rax,%rax
16444 je int_ret_from_sys_call
16445- RESTORE_ARGS
16446 UNFAKE_STACK_FRAME
16447+ pax_force_retaddr
16448 ret
16449 CFI_ENDPROC
16450-END(kernel_execve)
16451+ENDPROC(kernel_execve)
16452
16453 /* Call softirq on interrupt stack. Interrupts are off. */
16454 ENTRY(call_softirq)
16455@@ -1263,9 +1634,10 @@ ENTRY(call_softirq)
16456 CFI_DEF_CFA_REGISTER rsp
16457 CFI_ADJUST_CFA_OFFSET -8
16458 decl PER_CPU_VAR(irq_count)
16459+ pax_force_retaddr
16460 ret
16461 CFI_ENDPROC
16462-END(call_softirq)
16463+ENDPROC(call_softirq)
16464
16465 #ifdef CONFIG_XEN
16466 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16467@@ -1303,7 +1675,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16468 decl PER_CPU_VAR(irq_count)
16469 jmp error_exit
16470 CFI_ENDPROC
16471-END(xen_do_hypervisor_callback)
16472+ENDPROC(xen_do_hypervisor_callback)
16473
16474 /*
16475 * Hypervisor uses this for application faults while it executes.
16476@@ -1362,7 +1734,7 @@ ENTRY(xen_failsafe_callback)
16477 SAVE_ALL
16478 jmp error_exit
16479 CFI_ENDPROC
16480-END(xen_failsafe_callback)
16481+ENDPROC(xen_failsafe_callback)
16482
16483 #endif /* CONFIG_XEN */
16484
16485@@ -1405,16 +1777,31 @@ ENTRY(paranoid_exit)
16486 TRACE_IRQS_OFF
16487 testl %ebx,%ebx /* swapgs needed? */
16488 jnz paranoid_restore
16489- testl $3,CS(%rsp)
16490+ testb $3,CS(%rsp)
16491 jnz paranoid_userspace
16492+#ifdef CONFIG_PAX_MEMORY_UDEREF
16493+ pax_exit_kernel
16494+ TRACE_IRQS_IRETQ 0
16495+ SWAPGS_UNSAFE_STACK
16496+ RESTORE_ALL 8
16497+ pax_force_retaddr_bts
16498+ jmp irq_return
16499+#endif
16500 paranoid_swapgs:
16501+#ifdef CONFIG_PAX_MEMORY_UDEREF
16502+ pax_exit_kernel_user
16503+#else
16504+ pax_exit_kernel
16505+#endif
16506 TRACE_IRQS_IRETQ 0
16507 SWAPGS_UNSAFE_STACK
16508 RESTORE_ALL 8
16509 jmp irq_return
16510 paranoid_restore:
16511+ pax_exit_kernel
16512 TRACE_IRQS_IRETQ 0
16513 RESTORE_ALL 8
16514+ pax_force_retaddr_bts
16515 jmp irq_return
16516 paranoid_userspace:
16517 GET_THREAD_INFO(%rcx)
16518@@ -1443,7 +1830,7 @@ paranoid_schedule:
16519 TRACE_IRQS_OFF
16520 jmp paranoid_userspace
16521 CFI_ENDPROC
16522-END(paranoid_exit)
16523+ENDPROC(paranoid_exit)
16524
16525 /*
16526 * Exception entry point. This expects an error code/orig_rax on the stack.
16527@@ -1470,12 +1857,13 @@ ENTRY(error_entry)
16528 movq_cfi r14, R14+8
16529 movq_cfi r15, R15+8
16530 xorl %ebx,%ebx
16531- testl $3,CS+8(%rsp)
16532+ testb $3,CS+8(%rsp)
16533 je error_kernelspace
16534 error_swapgs:
16535 SWAPGS
16536 error_sti:
16537 TRACE_IRQS_OFF
16538+ pax_force_retaddr_bts
16539 ret
16540 CFI_ENDPROC
16541
16542@@ -1497,7 +1885,7 @@ error_kernelspace:
16543 cmpq $gs_change,RIP+8(%rsp)
16544 je error_swapgs
16545 jmp error_sti
16546-END(error_entry)
16547+ENDPROC(error_entry)
16548
16549
16550 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16551@@ -1517,7 +1905,7 @@ ENTRY(error_exit)
16552 jnz retint_careful
16553 jmp retint_swapgs
16554 CFI_ENDPROC
16555-END(error_exit)
16556+ENDPROC(error_exit)
16557
16558
16559 /* runs on exception stack */
16560@@ -1529,6 +1917,16 @@ ENTRY(nmi)
16561 CFI_ADJUST_CFA_OFFSET 15*8
16562 call save_paranoid
16563 DEFAULT_FRAME 0
16564+#ifdef CONFIG_PAX_MEMORY_UDEREF
16565+ testb $3, CS(%rsp)
16566+ jnz 1f
16567+ pax_enter_kernel
16568+ jmp 2f
16569+1: pax_enter_kernel_user
16570+2:
16571+#else
16572+ pax_enter_kernel
16573+#endif
16574 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16575 movq %rsp,%rdi
16576 movq $-1,%rsi
16577@@ -1539,12 +1937,28 @@ ENTRY(nmi)
16578 DISABLE_INTERRUPTS(CLBR_NONE)
16579 testl %ebx,%ebx /* swapgs needed? */
16580 jnz nmi_restore
16581- testl $3,CS(%rsp)
16582+ testb $3,CS(%rsp)
16583 jnz nmi_userspace
16584+#ifdef CONFIG_PAX_MEMORY_UDEREF
16585+ pax_exit_kernel
16586+ SWAPGS_UNSAFE_STACK
16587+ RESTORE_ALL 8
16588+ pax_force_retaddr_bts
16589+ jmp irq_return
16590+#endif
16591 nmi_swapgs:
16592+#ifdef CONFIG_PAX_MEMORY_UDEREF
16593+ pax_exit_kernel_user
16594+#else
16595+ pax_exit_kernel
16596+#endif
16597 SWAPGS_UNSAFE_STACK
16598+ RESTORE_ALL 8
16599+ jmp irq_return
16600 nmi_restore:
16601+ pax_exit_kernel
16602 RESTORE_ALL 8
16603+ pax_force_retaddr_bts
16604 jmp irq_return
16605 nmi_userspace:
16606 GET_THREAD_INFO(%rcx)
16607@@ -1573,14 +1987,14 @@ nmi_schedule:
16608 jmp paranoid_exit
16609 CFI_ENDPROC
16610 #endif
16611-END(nmi)
16612+ENDPROC(nmi)
16613
16614 ENTRY(ignore_sysret)
16615 CFI_STARTPROC
16616 mov $-ENOSYS,%eax
16617 sysret
16618 CFI_ENDPROC
16619-END(ignore_sysret)
16620+ENDPROC(ignore_sysret)
16621
16622 /*
16623 * End of kprobes section
16624diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16625index 9dbb527..7b3615a 100644
16626--- a/arch/x86/kernel/ftrace.c
16627+++ b/arch/x86/kernel/ftrace.c
16628@@ -103,7 +103,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16629 static void *mod_code_newcode; /* holds the text to write to the IP */
16630
16631 static unsigned nmi_wait_count;
16632-static atomic_t nmi_update_count = ATOMIC_INIT(0);
16633+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16634
16635 int ftrace_arch_read_dyn_info(char *buf, int size)
16636 {
16637@@ -111,7 +111,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16638
16639 r = snprintf(buf, size, "%u %u",
16640 nmi_wait_count,
16641- atomic_read(&nmi_update_count));
16642+ atomic_read_unchecked(&nmi_update_count));
16643 return r;
16644 }
16645
16646@@ -149,8 +149,10 @@ void ftrace_nmi_enter(void)
16647 {
16648 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16649 smp_rmb();
16650+ pax_open_kernel();
16651 ftrace_mod_code();
16652- atomic_inc(&nmi_update_count);
16653+ pax_close_kernel();
16654+ atomic_inc_unchecked(&nmi_update_count);
16655 }
16656 /* Must have previous changes seen before executions */
16657 smp_mb();
16658@@ -215,7 +217,7 @@ do_ftrace_mod_code(unsigned long ip, void *new_code)
16659
16660
16661
16662-static unsigned char ftrace_nop[MCOUNT_INSN_SIZE];
16663+static unsigned char ftrace_nop[MCOUNT_INSN_SIZE] __read_only;
16664
16665 static unsigned char *ftrace_nop_replace(void)
16666 {
16667@@ -228,6 +230,8 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
16668 {
16669 unsigned char replaced[MCOUNT_INSN_SIZE];
16670
16671+ ip = ktla_ktva(ip);
16672+
16673 /*
16674 * Note: Due to modules and __init, code can
16675 * disappear and change, we need to protect against faulting
16676@@ -284,7 +288,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16677 unsigned char old[MCOUNT_INSN_SIZE], *new;
16678 int ret;
16679
16680- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16681+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16682 new = ftrace_call_replace(ip, (unsigned long)func);
16683 ret = ftrace_modify_code(ip, old, new);
16684
16685@@ -337,15 +341,15 @@ int __init ftrace_dyn_arch_init(void *data)
16686 switch (faulted) {
16687 case 0:
16688 pr_info("ftrace: converting mcount calls to 0f 1f 44 00 00\n");
16689- memcpy(ftrace_nop, ftrace_test_p6nop, MCOUNT_INSN_SIZE);
16690+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_p6nop), MCOUNT_INSN_SIZE);
16691 break;
16692 case 1:
16693 pr_info("ftrace: converting mcount calls to 66 66 66 66 90\n");
16694- memcpy(ftrace_nop, ftrace_test_nop5, MCOUNT_INSN_SIZE);
16695+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_nop5), MCOUNT_INSN_SIZE);
16696 break;
16697 case 2:
16698 pr_info("ftrace: converting mcount calls to jmp . + 5\n");
16699- memcpy(ftrace_nop, ftrace_test_jmp, MCOUNT_INSN_SIZE);
16700+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_jmp), MCOUNT_INSN_SIZE);
16701 break;
16702 }
16703
16704@@ -366,6 +370,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16705 {
16706 unsigned char code[MCOUNT_INSN_SIZE];
16707
16708+ ip = ktla_ktva(ip);
16709+
16710 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16711 return -EFAULT;
16712
16713diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16714index 4f8e250..df24706 100644
16715--- a/arch/x86/kernel/head32.c
16716+++ b/arch/x86/kernel/head32.c
16717@@ -16,6 +16,7 @@
16718 #include <asm/apic.h>
16719 #include <asm/io_apic.h>
16720 #include <asm/bios_ebda.h>
16721+#include <asm/boot.h>
16722
16723 static void __init i386_default_early_setup(void)
16724 {
16725@@ -31,7 +32,7 @@ void __init i386_start_kernel(void)
16726 {
16727 reserve_trampoline_memory();
16728
16729- reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
16730+ reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
16731
16732 #ifdef CONFIG_BLK_DEV_INITRD
16733 /* Reserve INITRD */
16734diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16735index 34c3308..6fc4e76 100644
16736--- a/arch/x86/kernel/head_32.S
16737+++ b/arch/x86/kernel/head_32.S
16738@@ -19,10 +19,17 @@
16739 #include <asm/setup.h>
16740 #include <asm/processor-flags.h>
16741 #include <asm/percpu.h>
16742+#include <asm/msr-index.h>
16743
16744 /* Physical address */
16745 #define pa(X) ((X) - __PAGE_OFFSET)
16746
16747+#ifdef CONFIG_PAX_KERNEXEC
16748+#define ta(X) (X)
16749+#else
16750+#define ta(X) ((X) - __PAGE_OFFSET)
16751+#endif
16752+
16753 /*
16754 * References to members of the new_cpu_data structure.
16755 */
16756@@ -52,11 +59,7 @@
16757 * and small than max_low_pfn, otherwise will waste some page table entries
16758 */
16759
16760-#if PTRS_PER_PMD > 1
16761-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16762-#else
16763-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16764-#endif
16765+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16766
16767 /* Enough space to fit pagetables for the low memory linear map */
16768 MAPPING_BEYOND_END = \
16769@@ -73,6 +76,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE_asm
16770 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16771
16772 /*
16773+ * Real beginning of normal "text" segment
16774+ */
16775+ENTRY(stext)
16776+ENTRY(_stext)
16777+
16778+/*
16779 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16780 * %esi points to the real-mode code as a 32-bit pointer.
16781 * CS and DS must be 4 GB flat segments, but we don't depend on
16782@@ -80,7 +89,16 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16783 * can.
16784 */
16785 __HEAD
16786+
16787+#ifdef CONFIG_PAX_KERNEXEC
16788+ jmp startup_32
16789+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16790+.fill PAGE_SIZE-5,1,0xcc
16791+#endif
16792+
16793 ENTRY(startup_32)
16794+ movl pa(stack_start),%ecx
16795+
16796 /* test KEEP_SEGMENTS flag to see if the bootloader is asking
16797 us to not reload segments */
16798 testb $(1<<6), BP_loadflags(%esi)
16799@@ -95,7 +113,60 @@ ENTRY(startup_32)
16800 movl %eax,%es
16801 movl %eax,%fs
16802 movl %eax,%gs
16803+ movl %eax,%ss
16804 2:
16805+ leal -__PAGE_OFFSET(%ecx),%esp
16806+
16807+#ifdef CONFIG_SMP
16808+ movl $pa(cpu_gdt_table),%edi
16809+ movl $__per_cpu_load,%eax
16810+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16811+ rorl $16,%eax
16812+ movb %al,__KERNEL_PERCPU + 4(%edi)
16813+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16814+ movl $__per_cpu_end - 1,%eax
16815+ subl $__per_cpu_start,%eax
16816+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16817+#endif
16818+
16819+#ifdef CONFIG_PAX_MEMORY_UDEREF
16820+ movl $NR_CPUS,%ecx
16821+ movl $pa(cpu_gdt_table),%edi
16822+1:
16823+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16824+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16825+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16826+ addl $PAGE_SIZE_asm,%edi
16827+ loop 1b
16828+#endif
16829+
16830+#ifdef CONFIG_PAX_KERNEXEC
16831+ movl $pa(boot_gdt),%edi
16832+ movl $__LOAD_PHYSICAL_ADDR,%eax
16833+ movw %ax,__BOOT_CS + 2(%edi)
16834+ rorl $16,%eax
16835+ movb %al,__BOOT_CS + 4(%edi)
16836+ movb %ah,__BOOT_CS + 7(%edi)
16837+ rorl $16,%eax
16838+
16839+ ljmp $(__BOOT_CS),$1f
16840+1:
16841+
16842+ movl $NR_CPUS,%ecx
16843+ movl $pa(cpu_gdt_table),%edi
16844+ addl $__PAGE_OFFSET,%eax
16845+1:
16846+ movw %ax,__KERNEL_CS + 2(%edi)
16847+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16848+ rorl $16,%eax
16849+ movb %al,__KERNEL_CS + 4(%edi)
16850+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16851+ movb %ah,__KERNEL_CS + 7(%edi)
16852+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16853+ rorl $16,%eax
16854+ addl $PAGE_SIZE_asm,%edi
16855+ loop 1b
16856+#endif
16857
16858 /*
16859 * Clear BSS first so that there are no surprises...
16860@@ -140,9 +211,7 @@ ENTRY(startup_32)
16861 cmpl $num_subarch_entries, %eax
16862 jae bad_subarch
16863
16864- movl pa(subarch_entries)(,%eax,4), %eax
16865- subl $__PAGE_OFFSET, %eax
16866- jmp *%eax
16867+ jmp *pa(subarch_entries)(,%eax,4)
16868
16869 bad_subarch:
16870 WEAK(lguest_entry)
16871@@ -154,10 +223,10 @@ WEAK(xen_entry)
16872 __INITDATA
16873
16874 subarch_entries:
16875- .long default_entry /* normal x86/PC */
16876- .long lguest_entry /* lguest hypervisor */
16877- .long xen_entry /* Xen hypervisor */
16878- .long default_entry /* Moorestown MID */
16879+ .long ta(default_entry) /* normal x86/PC */
16880+ .long ta(lguest_entry) /* lguest hypervisor */
16881+ .long ta(xen_entry) /* Xen hypervisor */
16882+ .long ta(default_entry) /* Moorestown MID */
16883 num_subarch_entries = (. - subarch_entries) / 4
16884 .previous
16885 #endif /* CONFIG_PARAVIRT */
16886@@ -218,8 +287,11 @@ default_entry:
16887 movl %eax, pa(max_pfn_mapped)
16888
16889 /* Do early initialization of the fixmap area */
16890- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
16891- movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
16892+#ifdef CONFIG_COMPAT_VDSO
16893+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_pmd+0x1000*KPMDS-8)
16894+#else
16895+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
16896+#endif
16897 #else /* Not PAE */
16898
16899 page_pde_offset = (__PAGE_OFFSET >> 20);
16900@@ -249,8 +321,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16901 movl %eax, pa(max_pfn_mapped)
16902
16903 /* Do early initialization of the fixmap area */
16904- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
16905- movl %eax,pa(swapper_pg_dir+0xffc)
16906+#ifdef CONFIG_COMPAT_VDSO
16907+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_dir+0xffc)
16908+#else
16909+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_dir+0xffc)
16910+#endif
16911 #endif
16912 jmp 3f
16913 /*
16914@@ -272,6 +347,9 @@ ENTRY(startup_32_smp)
16915 movl %eax,%es
16916 movl %eax,%fs
16917 movl %eax,%gs
16918+ movl pa(stack_start),%ecx
16919+ movl %eax,%ss
16920+ leal -__PAGE_OFFSET(%ecx),%esp
16921 #endif /* CONFIG_SMP */
16922 3:
16923
16924@@ -297,6 +375,7 @@ ENTRY(startup_32_smp)
16925 orl %edx,%eax
16926 movl %eax,%cr4
16927
16928+#ifdef CONFIG_X86_PAE
16929 btl $5, %eax # check if PAE is enabled
16930 jnc 6f
16931
16932@@ -305,6 +384,10 @@ ENTRY(startup_32_smp)
16933 cpuid
16934 cmpl $0x80000000, %eax
16935 jbe 6f
16936+
16937+ /* Clear bogus XD_DISABLE bits */
16938+ call verify_cpu
16939+
16940 mov $0x80000001, %eax
16941 cpuid
16942 /* Execute Disable bit supported? */
16943@@ -312,13 +395,17 @@ ENTRY(startup_32_smp)
16944 jnc 6f
16945
16946 /* Setup EFER (Extended Feature Enable Register) */
16947- movl $0xc0000080, %ecx
16948+ movl $MSR_EFER, %ecx
16949 rdmsr
16950
16951 btsl $11, %eax
16952 /* Make changes effective */
16953 wrmsr
16954
16955+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16956+ movl $1,pa(nx_enabled)
16957+#endif
16958+
16959 6:
16960
16961 /*
16962@@ -331,8 +418,8 @@ ENTRY(startup_32_smp)
16963 movl %eax,%cr0 /* ..and set paging (PG) bit */
16964 ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */
16965 1:
16966- /* Set up the stack pointer */
16967- lss stack_start,%esp
16968+ /* Shift the stack pointer to a virtual address */
16969+ addl $__PAGE_OFFSET, %esp
16970
16971 /*
16972 * Initialize eflags. Some BIOS's leave bits like NT set. This would
16973@@ -344,9 +431,7 @@ ENTRY(startup_32_smp)
16974
16975 #ifdef CONFIG_SMP
16976 cmpb $0, ready
16977- jz 1f /* Initial CPU cleans BSS */
16978- jmp checkCPUtype
16979-1:
16980+ jnz checkCPUtype
16981 #endif /* CONFIG_SMP */
16982
16983 /*
16984@@ -424,7 +509,7 @@ is386: movl $2,%ecx # set MP
16985 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16986 movl %eax,%ss # after changing gdt.
16987
16988- movl $(__USER_DS),%eax # DS/ES contains default USER segment
16989+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16990 movl %eax,%ds
16991 movl %eax,%es
16992
16993@@ -438,15 +523,22 @@ is386: movl $2,%ecx # set MP
16994 */
16995 cmpb $0,ready
16996 jne 1f
16997- movl $per_cpu__gdt_page,%eax
16998+ movl $cpu_gdt_table,%eax
16999 movl $per_cpu__stack_canary,%ecx
17000+#ifdef CONFIG_SMP
17001+ addl $__per_cpu_load,%ecx
17002+#endif
17003 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17004 shrl $16, %ecx
17005 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17006 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
17007 1:
17008-#endif
17009 movl $(__KERNEL_STACK_CANARY),%eax
17010+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17011+ movl $(__USER_DS),%eax
17012+#else
17013+ xorl %eax,%eax
17014+#endif
17015 movl %eax,%gs
17016
17017 xorl %eax,%eax # Clear LDT
17018@@ -454,14 +546,7 @@ is386: movl $2,%ecx # set MP
17019
17020 cld # gcc2 wants the direction flag cleared at all times
17021 pushl $0 # fake return address for unwinder
17022-#ifdef CONFIG_SMP
17023- movb ready, %cl
17024 movb $1, ready
17025- cmpb $0,%cl # the first CPU calls start_kernel
17026- je 1f
17027- movl (stack_start), %esp
17028-1:
17029-#endif /* CONFIG_SMP */
17030 jmp *(initial_code)
17031
17032 /*
17033@@ -546,22 +631,22 @@ early_page_fault:
17034 jmp early_fault
17035
17036 early_fault:
17037- cld
17038 #ifdef CONFIG_PRINTK
17039+ cmpl $1,%ss:early_recursion_flag
17040+ je hlt_loop
17041+ incl %ss:early_recursion_flag
17042+ cld
17043 pusha
17044 movl $(__KERNEL_DS),%eax
17045 movl %eax,%ds
17046 movl %eax,%es
17047- cmpl $2,early_recursion_flag
17048- je hlt_loop
17049- incl early_recursion_flag
17050 movl %cr2,%eax
17051 pushl %eax
17052 pushl %edx /* trapno */
17053 pushl $fault_msg
17054 call printk
17055+; call dump_stack
17056 #endif
17057- call dump_stack
17058 hlt_loop:
17059 hlt
17060 jmp hlt_loop
17061@@ -569,8 +654,11 @@ hlt_loop:
17062 /* This is the default interrupt "handler" :-) */
17063 ALIGN
17064 ignore_int:
17065- cld
17066 #ifdef CONFIG_PRINTK
17067+ cmpl $2,%ss:early_recursion_flag
17068+ je hlt_loop
17069+ incl %ss:early_recursion_flag
17070+ cld
17071 pushl %eax
17072 pushl %ecx
17073 pushl %edx
17074@@ -579,9 +667,6 @@ ignore_int:
17075 movl $(__KERNEL_DS),%eax
17076 movl %eax,%ds
17077 movl %eax,%es
17078- cmpl $2,early_recursion_flag
17079- je hlt_loop
17080- incl early_recursion_flag
17081 pushl 16(%esp)
17082 pushl 24(%esp)
17083 pushl 32(%esp)
17084@@ -600,6 +685,8 @@ ignore_int:
17085 #endif
17086 iret
17087
17088+#include "verify_cpu.S"
17089+
17090 __REFDATA
17091 .align 4
17092 ENTRY(initial_code)
17093@@ -610,31 +697,47 @@ ENTRY(initial_page_table)
17094 /*
17095 * BSS section
17096 */
17097-__PAGE_ALIGNED_BSS
17098- .align PAGE_SIZE_asm
17099 #ifdef CONFIG_X86_PAE
17100+.section .swapper_pg_pmd,"a",@progbits
17101 swapper_pg_pmd:
17102 .fill 1024*KPMDS,4,0
17103 #else
17104+.section .swapper_pg_dir,"a",@progbits
17105 ENTRY(swapper_pg_dir)
17106 .fill 1024,4,0
17107 #endif
17108+.section .swapper_pg_fixmap,"a",@progbits
17109 swapper_pg_fixmap:
17110 .fill 1024,4,0
17111 #ifdef CONFIG_X86_TRAMPOLINE
17112+.section .trampoline_pg_dir,"a",@progbits
17113 ENTRY(trampoline_pg_dir)
17114+#ifdef CONFIG_X86_PAE
17115+ .fill 4,8,0
17116+#else
17117 .fill 1024,4,0
17118 #endif
17119+#endif
17120+
17121+.section .empty_zero_page,"a",@progbits
17122 ENTRY(empty_zero_page)
17123 .fill 4096,1,0
17124
17125 /*
17126+ * The IDT has to be page-aligned to simplify the Pentium
17127+ * F0 0F bug workaround.. We have a special link segment
17128+ * for this.
17129+ */
17130+.section .idt,"a",@progbits
17131+ENTRY(idt_table)
17132+ .fill 256,8,0
17133+
17134+/*
17135 * This starts the data section.
17136 */
17137 #ifdef CONFIG_X86_PAE
17138-__PAGE_ALIGNED_DATA
17139- /* Page-aligned for the benefit of paravirt? */
17140- .align PAGE_SIZE_asm
17141+.section .swapper_pg_dir,"a",@progbits
17142+
17143 ENTRY(swapper_pg_dir)
17144 .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17145 # if KPMDS == 3
17146@@ -653,15 +756,24 @@ ENTRY(swapper_pg_dir)
17147 # error "Kernel PMDs should be 1, 2 or 3"
17148 # endif
17149 .align PAGE_SIZE_asm /* needs to be page-sized too */
17150+
17151+#ifdef CONFIG_PAX_PER_CPU_PGD
17152+ENTRY(cpu_pgd)
17153+ .rept NR_CPUS
17154+ .fill 4,8,0
17155+ .endr
17156+#endif
17157+
17158 #endif
17159
17160 .data
17161+.balign 4
17162 ENTRY(stack_start)
17163- .long init_thread_union+THREAD_SIZE
17164- .long __BOOT_DS
17165+ .long init_thread_union+THREAD_SIZE-8
17166
17167 ready: .byte 0
17168
17169+.section .rodata,"a",@progbits
17170 early_recursion_flag:
17171 .long 0
17172
17173@@ -697,7 +809,7 @@ fault_msg:
17174 .word 0 # 32 bit align gdt_desc.address
17175 boot_gdt_descr:
17176 .word __BOOT_DS+7
17177- .long boot_gdt - __PAGE_OFFSET
17178+ .long pa(boot_gdt)
17179
17180 .word 0 # 32-bit align idt_desc.address
17181 idt_descr:
17182@@ -708,7 +820,7 @@ idt_descr:
17183 .word 0 # 32 bit align gdt_desc.address
17184 ENTRY(early_gdt_descr)
17185 .word GDT_ENTRIES*8-1
17186- .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
17187+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17188
17189 /*
17190 * The boot_gdt must mirror the equivalent in setup.S and is
17191@@ -717,5 +829,65 @@ ENTRY(early_gdt_descr)
17192 .align L1_CACHE_BYTES
17193 ENTRY(boot_gdt)
17194 .fill GDT_ENTRY_BOOT_CS,8,0
17195- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17196- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17197+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17198+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17199+
17200+ .align PAGE_SIZE_asm
17201+ENTRY(cpu_gdt_table)
17202+ .rept NR_CPUS
17203+ .quad 0x0000000000000000 /* NULL descriptor */
17204+ .quad 0x0000000000000000 /* 0x0b reserved */
17205+ .quad 0x0000000000000000 /* 0x13 reserved */
17206+ .quad 0x0000000000000000 /* 0x1b reserved */
17207+
17208+#ifdef CONFIG_PAX_KERNEXEC
17209+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17210+#else
17211+ .quad 0x0000000000000000 /* 0x20 unused */
17212+#endif
17213+
17214+ .quad 0x0000000000000000 /* 0x28 unused */
17215+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17216+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17217+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17218+ .quad 0x0000000000000000 /* 0x4b reserved */
17219+ .quad 0x0000000000000000 /* 0x53 reserved */
17220+ .quad 0x0000000000000000 /* 0x5b reserved */
17221+
17222+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17223+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17224+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17225+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17226+
17227+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17228+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17229+
17230+ /*
17231+ * Segments used for calling PnP BIOS have byte granularity.
17232+ * The code segments and data segments have fixed 64k limits,
17233+ * the transfer segment sizes are set at run time.
17234+ */
17235+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17236+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17237+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17238+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17239+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17240+
17241+ /*
17242+ * The APM segments have byte granularity and their bases
17243+ * are set at run time. All have 64k limits.
17244+ */
17245+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17246+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17247+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17248+
17249+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17250+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17251+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17252+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17253+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17254+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17255+
17256+ /* Be sure this is zeroed to avoid false validations in Xen */
17257+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17258+ .endr
17259diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17260index 780cd92..758b2a6 100644
17261--- a/arch/x86/kernel/head_64.S
17262+++ b/arch/x86/kernel/head_64.S
17263@@ -19,6 +19,8 @@
17264 #include <asm/cache.h>
17265 #include <asm/processor-flags.h>
17266 #include <asm/percpu.h>
17267+#include <asm/cpufeature.h>
17268+#include <asm/alternative-asm.h>
17269
17270 #ifdef CONFIG_PARAVIRT
17271 #include <asm/asm-offsets.h>
17272@@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17273 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17274 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17275 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17276+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17277+L3_VMALLOC_START = pud_index(VMALLOC_START)
17278+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17279+L3_VMALLOC_END = pud_index(VMALLOC_END)
17280+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17281+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17282
17283 .text
17284 __HEAD
17285@@ -85,35 +93,23 @@ startup_64:
17286 */
17287 addq %rbp, init_level4_pgt + 0(%rip)
17288 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17289+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17290+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17291+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17292 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17293
17294 addq %rbp, level3_ident_pgt + 0(%rip)
17295+#ifndef CONFIG_XEN
17296+ addq %rbp, level3_ident_pgt + 8(%rip)
17297+#endif
17298
17299- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17300- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17301+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17302+
17303+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17304+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17305
17306 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17307-
17308- /* Add an Identity mapping if I am above 1G */
17309- leaq _text(%rip), %rdi
17310- andq $PMD_PAGE_MASK, %rdi
17311-
17312- movq %rdi, %rax
17313- shrq $PUD_SHIFT, %rax
17314- andq $(PTRS_PER_PUD - 1), %rax
17315- jz ident_complete
17316-
17317- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17318- leaq level3_ident_pgt(%rip), %rbx
17319- movq %rdx, 0(%rbx, %rax, 8)
17320-
17321- movq %rdi, %rax
17322- shrq $PMD_SHIFT, %rax
17323- andq $(PTRS_PER_PMD - 1), %rax
17324- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17325- leaq level2_spare_pgt(%rip), %rbx
17326- movq %rdx, 0(%rbx, %rax, 8)
17327-ident_complete:
17328+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17329
17330 /*
17331 * Fixup the kernel text+data virtual addresses. Note that
17332@@ -161,8 +157,8 @@ ENTRY(secondary_startup_64)
17333 * after the boot processor executes this code.
17334 */
17335
17336- /* Enable PAE mode and PGE */
17337- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17338+ /* Enable PAE mode and PSE/PGE */
17339+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17340 movq %rax, %cr4
17341
17342 /* Setup early boot stage 4 level pagetables. */
17343@@ -184,9 +180,16 @@ ENTRY(secondary_startup_64)
17344 movl $MSR_EFER, %ecx
17345 rdmsr
17346 btsl $_EFER_SCE, %eax /* Enable System Call */
17347- btl $20,%edi /* No Execute supported? */
17348+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17349 jnc 1f
17350 btsl $_EFER_NX, %eax
17351+ leaq init_level4_pgt(%rip), %rdi
17352+#ifndef CONFIG_EFI
17353+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17354+#endif
17355+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17356+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17357+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17358 1: wrmsr /* Make changes effective */
17359
17360 /* Setup cr0 */
17361@@ -249,6 +252,7 @@ ENTRY(secondary_startup_64)
17362 * jump. In addition we need to ensure %cs is set so we make this
17363 * a far return.
17364 */
17365+ pax_set_fptr_mask
17366 movq initial_code(%rip),%rax
17367 pushq $0 # fake return address to stop unwinder
17368 pushq $__KERNEL_CS # set correct cs
17369@@ -262,16 +266,16 @@ ENTRY(secondary_startup_64)
17370 .quad x86_64_start_kernel
17371 ENTRY(initial_gs)
17372 .quad INIT_PER_CPU_VAR(irq_stack_union)
17373- __FINITDATA
17374
17375 ENTRY(stack_start)
17376 .quad init_thread_union+THREAD_SIZE-8
17377 .word 0
17378+ __FINITDATA
17379
17380 bad_address:
17381 jmp bad_address
17382
17383- .section ".init.text","ax"
17384+ __INIT
17385 #ifdef CONFIG_EARLY_PRINTK
17386 .globl early_idt_handlers
17387 early_idt_handlers:
17388@@ -316,18 +320,23 @@ ENTRY(early_idt_handler)
17389 #endif /* EARLY_PRINTK */
17390 1: hlt
17391 jmp 1b
17392+ .previous
17393
17394 #ifdef CONFIG_EARLY_PRINTK
17395+ __INITDATA
17396 early_recursion_flag:
17397 .long 0
17398+ .previous
17399
17400+ .section .rodata,"a",@progbits
17401 early_idt_msg:
17402 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17403 early_idt_ripmsg:
17404 .asciz "RIP %s\n"
17405+ .previous
17406 #endif /* CONFIG_EARLY_PRINTK */
17407- .previous
17408
17409+ .section .rodata,"a",@progbits
17410 #define NEXT_PAGE(name) \
17411 .balign PAGE_SIZE; \
17412 ENTRY(name)
17413@@ -350,13 +359,41 @@ NEXT_PAGE(init_level4_pgt)
17414 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17415 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17416 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17417+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17418+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17419+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17420+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17421+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17422+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17423 .org init_level4_pgt + L4_START_KERNEL*8, 0
17424 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17425 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17426
17427+#ifdef CONFIG_PAX_PER_CPU_PGD
17428+NEXT_PAGE(cpu_pgd)
17429+ .rept NR_CPUS
17430+ .fill 512,8,0
17431+ .endr
17432+#endif
17433+
17434 NEXT_PAGE(level3_ident_pgt)
17435 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17436+#ifdef CONFIG_XEN
17437 .fill 511,8,0
17438+#else
17439+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17440+ .fill 510,8,0
17441+#endif
17442+
17443+NEXT_PAGE(level3_vmalloc_start_pgt)
17444+ .fill 512,8,0
17445+
17446+NEXT_PAGE(level3_vmalloc_end_pgt)
17447+ .fill 512,8,0
17448+
17449+NEXT_PAGE(level3_vmemmap_pgt)
17450+ .fill L3_VMEMMAP_START,8,0
17451+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17452
17453 NEXT_PAGE(level3_kernel_pgt)
17454 .fill L3_START_KERNEL,8,0
17455@@ -364,20 +401,23 @@ NEXT_PAGE(level3_kernel_pgt)
17456 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17457 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17458
17459+NEXT_PAGE(level2_vmemmap_pgt)
17460+ .fill 512,8,0
17461+
17462 NEXT_PAGE(level2_fixmap_pgt)
17463- .fill 506,8,0
17464- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17465- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17466- .fill 5,8,0
17467+ .fill 507,8,0
17468+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17469+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17470+ .fill 4,8,0
17471
17472-NEXT_PAGE(level1_fixmap_pgt)
17473+NEXT_PAGE(level1_vsyscall_pgt)
17474 .fill 512,8,0
17475
17476-NEXT_PAGE(level2_ident_pgt)
17477- /* Since I easily can, map the first 1G.
17478+ /* Since I easily can, map the first 2G.
17479 * Don't set NX because code runs from these pages.
17480 */
17481- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17482+NEXT_PAGE(level2_ident_pgt)
17483+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17484
17485 NEXT_PAGE(level2_kernel_pgt)
17486 /*
17487@@ -390,33 +430,55 @@ NEXT_PAGE(level2_kernel_pgt)
17488 * If you want to increase this then increase MODULES_VADDR
17489 * too.)
17490 */
17491- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17492- KERNEL_IMAGE_SIZE/PMD_SIZE)
17493-
17494-NEXT_PAGE(level2_spare_pgt)
17495- .fill 512, 8, 0
17496+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17497
17498 #undef PMDS
17499 #undef NEXT_PAGE
17500
17501- .data
17502+ .align PAGE_SIZE
17503+ENTRY(cpu_gdt_table)
17504+ .rept NR_CPUS
17505+ .quad 0x0000000000000000 /* NULL descriptor */
17506+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17507+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17508+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17509+ .quad 0x00cffb000000ffff /* __USER32_CS */
17510+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17511+ .quad 0x00affb000000ffff /* __USER_CS */
17512+
17513+#ifdef CONFIG_PAX_KERNEXEC
17514+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17515+#else
17516+ .quad 0x0 /* unused */
17517+#endif
17518+
17519+ .quad 0,0 /* TSS */
17520+ .quad 0,0 /* LDT */
17521+ .quad 0,0,0 /* three TLS descriptors */
17522+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17523+ /* asm/segment.h:GDT_ENTRIES must match this */
17524+
17525+ /* zero the remaining page */
17526+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17527+ .endr
17528+
17529 .align 16
17530 .globl early_gdt_descr
17531 early_gdt_descr:
17532 .word GDT_ENTRIES*8-1
17533 early_gdt_descr_base:
17534- .quad INIT_PER_CPU_VAR(gdt_page)
17535+ .quad cpu_gdt_table
17536
17537 ENTRY(phys_base)
17538 /* This must match the first entry in level2_kernel_pgt */
17539 .quad 0x0000000000000000
17540
17541 #include "../../x86/xen/xen-head.S"
17542-
17543- .section .bss, "aw", @nobits
17544+
17545+ .section .rodata,"a",@progbits
17546 .align L1_CACHE_BYTES
17547 ENTRY(idt_table)
17548- .skip IDT_ENTRIES * 16
17549+ .fill 512,8,0
17550
17551 __PAGE_ALIGNED_BSS
17552 .align PAGE_SIZE
17553diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17554index 9c3bd4a..e1d9b35 100644
17555--- a/arch/x86/kernel/i386_ksyms_32.c
17556+++ b/arch/x86/kernel/i386_ksyms_32.c
17557@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17558 EXPORT_SYMBOL(cmpxchg8b_emu);
17559 #endif
17560
17561+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17562+
17563 /* Networking helper routines. */
17564 EXPORT_SYMBOL(csum_partial_copy_generic);
17565+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17566+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17567
17568 EXPORT_SYMBOL(__get_user_1);
17569 EXPORT_SYMBOL(__get_user_2);
17570@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17571
17572 EXPORT_SYMBOL(csum_partial);
17573 EXPORT_SYMBOL(empty_zero_page);
17574+
17575+#ifdef CONFIG_PAX_KERNEXEC
17576+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17577+#endif
17578diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17579index df89102..a244320 100644
17580--- a/arch/x86/kernel/i8259.c
17581+++ b/arch/x86/kernel/i8259.c
17582@@ -208,7 +208,7 @@ spurious_8259A_irq:
17583 "spurious 8259A interrupt: IRQ%d.\n", irq);
17584 spurious_irq_mask |= irqmask;
17585 }
17586- atomic_inc(&irq_err_count);
17587+ atomic_inc_unchecked(&irq_err_count);
17588 /*
17589 * Theoretically we do not have to handle this IRQ,
17590 * but in Linux this does not cause problems and is
17591diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17592index 3a54dcb..1c22348 100644
17593--- a/arch/x86/kernel/init_task.c
17594+++ b/arch/x86/kernel/init_task.c
17595@@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17596 * way process stacks are handled. This is done by having a special
17597 * "init_task" linker map entry..
17598 */
17599-union thread_union init_thread_union __init_task_data =
17600- { INIT_THREAD_INFO(init_task) };
17601+union thread_union init_thread_union __init_task_data;
17602
17603 /*
17604 * Initial task structure.
17605@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17606 * section. Since TSS's are completely CPU-local, we want them
17607 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17608 */
17609-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17610-
17611+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17612+EXPORT_SYMBOL(init_tss);
17613diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17614index 99c4d30..74c84e9 100644
17615--- a/arch/x86/kernel/ioport.c
17616+++ b/arch/x86/kernel/ioport.c
17617@@ -6,6 +6,7 @@
17618 #include <linux/sched.h>
17619 #include <linux/kernel.h>
17620 #include <linux/capability.h>
17621+#include <linux/security.h>
17622 #include <linux/errno.h>
17623 #include <linux/types.h>
17624 #include <linux/ioport.h>
17625@@ -41,6 +42,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17626
17627 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17628 return -EINVAL;
17629+#ifdef CONFIG_GRKERNSEC_IO
17630+ if (turn_on && grsec_disable_privio) {
17631+ gr_handle_ioperm();
17632+ return -EPERM;
17633+ }
17634+#endif
17635 if (turn_on && !capable(CAP_SYS_RAWIO))
17636 return -EPERM;
17637
17638@@ -67,7 +74,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17639 * because the ->io_bitmap_max value must match the bitmap
17640 * contents:
17641 */
17642- tss = &per_cpu(init_tss, get_cpu());
17643+ tss = init_tss + get_cpu();
17644
17645 set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
17646
17647@@ -111,6 +118,12 @@ static int do_iopl(unsigned int level, struct pt_regs *regs)
17648 return -EINVAL;
17649 /* Trying to gain more privileges? */
17650 if (level > old) {
17651+#ifdef CONFIG_GRKERNSEC_IO
17652+ if (grsec_disable_privio) {
17653+ gr_handle_iopl();
17654+ return -EPERM;
17655+ }
17656+#endif
17657 if (!capable(CAP_SYS_RAWIO))
17658 return -EPERM;
17659 }
17660diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17661index 04bbd52..83a07d9 100644
17662--- a/arch/x86/kernel/irq.c
17663+++ b/arch/x86/kernel/irq.c
17664@@ -15,7 +15,7 @@
17665 #include <asm/mce.h>
17666 #include <asm/hw_irq.h>
17667
17668-atomic_t irq_err_count;
17669+atomic_unchecked_t irq_err_count;
17670
17671 /* Function pointer for generic interrupt vector handling */
17672 void (*generic_interrupt_extension)(void) = NULL;
17673@@ -114,9 +114,9 @@ static int show_other_interrupts(struct seq_file *p, int prec)
17674 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17675 seq_printf(p, " Machine check polls\n");
17676 #endif
17677- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17678+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17679 #if defined(CONFIG_X86_IO_APIC)
17680- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17681+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17682 #endif
17683 return 0;
17684 }
17685@@ -209,10 +209,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17686
17687 u64 arch_irq_stat(void)
17688 {
17689- u64 sum = atomic_read(&irq_err_count);
17690+ u64 sum = atomic_read_unchecked(&irq_err_count);
17691
17692 #ifdef CONFIG_X86_IO_APIC
17693- sum += atomic_read(&irq_mis_count);
17694+ sum += atomic_read_unchecked(&irq_mis_count);
17695 #endif
17696 return sum;
17697 }
17698diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17699index 7d35d0f..03f1d52 100644
17700--- a/arch/x86/kernel/irq_32.c
17701+++ b/arch/x86/kernel/irq_32.c
17702@@ -35,7 +35,7 @@ static int check_stack_overflow(void)
17703 __asm__ __volatile__("andl %%esp,%0" :
17704 "=r" (sp) : "0" (THREAD_SIZE - 1));
17705
17706- return sp < (sizeof(struct thread_info) + STACK_WARN);
17707+ return sp < STACK_WARN;
17708 }
17709
17710 static void print_stack_overflow(void)
17711@@ -54,9 +54,9 @@ static inline void print_stack_overflow(void) { }
17712 * per-CPU IRQ handling contexts (thread information and stack)
17713 */
17714 union irq_ctx {
17715- struct thread_info tinfo;
17716- u32 stack[THREAD_SIZE/sizeof(u32)];
17717-} __attribute__((aligned(PAGE_SIZE)));
17718+ unsigned long previous_esp;
17719+ u32 stack[THREAD_SIZE/sizeof(u32)];
17720+} __attribute__((aligned(THREAD_SIZE)));
17721
17722 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17723 static DEFINE_PER_CPU(union irq_ctx *, softirq_ctx);
17724@@ -78,10 +78,9 @@ static void call_on_stack(void *func, void *stack)
17725 static inline int
17726 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17727 {
17728- union irq_ctx *curctx, *irqctx;
17729+ union irq_ctx *irqctx;
17730 u32 *isp, arg1, arg2;
17731
17732- curctx = (union irq_ctx *) current_thread_info();
17733 irqctx = __get_cpu_var(hardirq_ctx);
17734
17735 /*
17736@@ -90,21 +89,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17737 * handler) we can't do that and just have to keep using the
17738 * current stack (which is the irq stack already after all)
17739 */
17740- if (unlikely(curctx == irqctx))
17741+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17742 return 0;
17743
17744 /* build the stack frame on the IRQ stack */
17745- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17746- irqctx->tinfo.task = curctx->tinfo.task;
17747- irqctx->tinfo.previous_esp = current_stack_pointer;
17748+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17749+ irqctx->previous_esp = current_stack_pointer;
17750
17751- /*
17752- * Copy the softirq bits in preempt_count so that the
17753- * softirq checks work in the hardirq context.
17754- */
17755- irqctx->tinfo.preempt_count =
17756- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17757- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17758+#ifdef CONFIG_PAX_MEMORY_UDEREF
17759+ __set_fs(MAKE_MM_SEG(0));
17760+#endif
17761
17762 if (unlikely(overflow))
17763 call_on_stack(print_stack_overflow, isp);
17764@@ -116,6 +110,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17765 : "0" (irq), "1" (desc), "2" (isp),
17766 "D" (desc->handle_irq)
17767 : "memory", "cc", "ecx");
17768+
17769+#ifdef CONFIG_PAX_MEMORY_UDEREF
17770+ __set_fs(current_thread_info()->addr_limit);
17771+#endif
17772+
17773 return 1;
17774 }
17775
17776@@ -124,28 +123,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17777 */
17778 void __cpuinit irq_ctx_init(int cpu)
17779 {
17780- union irq_ctx *irqctx;
17781-
17782 if (per_cpu(hardirq_ctx, cpu))
17783 return;
17784
17785- irqctx = &per_cpu(hardirq_stack, cpu);
17786- irqctx->tinfo.task = NULL;
17787- irqctx->tinfo.exec_domain = NULL;
17788- irqctx->tinfo.cpu = cpu;
17789- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17790- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17791-
17792- per_cpu(hardirq_ctx, cpu) = irqctx;
17793-
17794- irqctx = &per_cpu(softirq_stack, cpu);
17795- irqctx->tinfo.task = NULL;
17796- irqctx->tinfo.exec_domain = NULL;
17797- irqctx->tinfo.cpu = cpu;
17798- irqctx->tinfo.preempt_count = 0;
17799- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17800-
17801- per_cpu(softirq_ctx, cpu) = irqctx;
17802+ per_cpu(hardirq_ctx, cpu) = &per_cpu(hardirq_stack, cpu);
17803+ per_cpu(softirq_ctx, cpu) = &per_cpu(softirq_stack, cpu);
17804
17805 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17806 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17807@@ -159,7 +141,6 @@ void irq_ctx_exit(int cpu)
17808 asmlinkage void do_softirq(void)
17809 {
17810 unsigned long flags;
17811- struct thread_info *curctx;
17812 union irq_ctx *irqctx;
17813 u32 *isp;
17814
17815@@ -169,15 +150,22 @@ asmlinkage void do_softirq(void)
17816 local_irq_save(flags);
17817
17818 if (local_softirq_pending()) {
17819- curctx = current_thread_info();
17820 irqctx = __get_cpu_var(softirq_ctx);
17821- irqctx->tinfo.task = curctx->task;
17822- irqctx->tinfo.previous_esp = current_stack_pointer;
17823+ irqctx->previous_esp = current_stack_pointer;
17824
17825 /* build the stack frame on the softirq stack */
17826- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17827+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17828+
17829+#ifdef CONFIG_PAX_MEMORY_UDEREF
17830+ __set_fs(MAKE_MM_SEG(0));
17831+#endif
17832
17833 call_on_stack(__do_softirq, isp);
17834+
17835+#ifdef CONFIG_PAX_MEMORY_UDEREF
17836+ __set_fs(current_thread_info()->addr_limit);
17837+#endif
17838+
17839 /*
17840 * Shouldnt happen, we returned above if in_interrupt():
17841 */
17842diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17843index 8d82a77..0baf312 100644
17844--- a/arch/x86/kernel/kgdb.c
17845+++ b/arch/x86/kernel/kgdb.c
17846@@ -390,13 +390,13 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17847
17848 /* clear the trace bit */
17849 linux_regs->flags &= ~X86_EFLAGS_TF;
17850- atomic_set(&kgdb_cpu_doing_single_step, -1);
17851+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17852
17853 /* set the trace bit if we're stepping */
17854 if (remcomInBuffer[0] == 's') {
17855 linux_regs->flags |= X86_EFLAGS_TF;
17856 kgdb_single_step = 1;
17857- atomic_set(&kgdb_cpu_doing_single_step,
17858+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17859 raw_smp_processor_id());
17860 }
17861
17862@@ -476,7 +476,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17863 break;
17864
17865 case DIE_DEBUG:
17866- if (atomic_read(&kgdb_cpu_doing_single_step) ==
17867+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) ==
17868 raw_smp_processor_id()) {
17869 if (user_mode(regs))
17870 return single_step_cont(regs, args);
17871@@ -573,7 +573,7 @@ unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
17872 return instruction_pointer(regs);
17873 }
17874
17875-struct kgdb_arch arch_kgdb_ops = {
17876+const struct kgdb_arch arch_kgdb_ops = {
17877 /* Breakpoint instruction: */
17878 .gdb_bpt_instr = { 0xcc },
17879 .flags = KGDB_HW_BREAKPOINT,
17880diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17881index 7a67820..8d15b75 100644
17882--- a/arch/x86/kernel/kprobes.c
17883+++ b/arch/x86/kernel/kprobes.c
17884@@ -168,9 +168,13 @@ static void __kprobes set_jmp_op(void *from, void *to)
17885 char op;
17886 s32 raddr;
17887 } __attribute__((packed)) * jop;
17888- jop = (struct __arch_jmp_op *)from;
17889+
17890+ jop = (struct __arch_jmp_op *)(ktla_ktva(from));
17891+
17892+ pax_open_kernel();
17893 jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
17894 jop->op = RELATIVEJUMP_INSTRUCTION;
17895+ pax_close_kernel();
17896 }
17897
17898 /*
17899@@ -195,7 +199,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17900 kprobe_opcode_t opcode;
17901 kprobe_opcode_t *orig_opcodes = opcodes;
17902
17903- if (search_exception_tables((unsigned long)opcodes))
17904+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17905 return 0; /* Page fault may occur on this address. */
17906
17907 retry:
17908@@ -339,7 +343,9 @@ static void __kprobes fix_riprel(struct kprobe *p)
17909 disp = (u8 *) p->addr + *((s32 *) insn) -
17910 (u8 *) p->ainsn.insn;
17911 BUG_ON((s64) (s32) disp != disp); /* Sanity check. */
17912+ pax_open_kernel();
17913 *(s32 *)insn = (s32) disp;
17914+ pax_close_kernel();
17915 }
17916 }
17917 #endif
17918@@ -347,16 +353,18 @@ static void __kprobes fix_riprel(struct kprobe *p)
17919
17920 static void __kprobes arch_copy_kprobe(struct kprobe *p)
17921 {
17922- memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
17923+ pax_open_kernel();
17924+ memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
17925+ pax_close_kernel();
17926
17927 fix_riprel(p);
17928
17929- if (can_boost(p->addr))
17930+ if (can_boost(ktla_ktva(p->addr)))
17931 p->ainsn.boostable = 0;
17932 else
17933 p->ainsn.boostable = -1;
17934
17935- p->opcode = *p->addr;
17936+ p->opcode = *(ktla_ktva(p->addr));
17937 }
17938
17939 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17940@@ -434,7 +442,7 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
17941 if (p->opcode == BREAKPOINT_INSTRUCTION)
17942 regs->ip = (unsigned long)p->addr;
17943 else
17944- regs->ip = (unsigned long)p->ainsn.insn;
17945+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17946 }
17947
17948 void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
17949@@ -455,7 +463,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17950 if (p->ainsn.boostable == 1 && !p->post_handler) {
17951 /* Boost up -- we can execute copied instructions directly */
17952 reset_current_kprobe();
17953- regs->ip = (unsigned long)p->ainsn.insn;
17954+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17955 preempt_enable_no_resched();
17956 return;
17957 }
17958@@ -525,7 +533,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17959 struct kprobe_ctlblk *kcb;
17960
17961 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
17962- if (*addr != BREAKPOINT_INSTRUCTION) {
17963+ if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17964 /*
17965 * The breakpoint instruction was removed right
17966 * after we hit it. Another cpu has removed
17967@@ -637,6 +645,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17968 /* Skip orig_ax, ip, cs */
17969 " addq $24, %rsp\n"
17970 " popfq\n"
17971+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
17972+ " btsq $63,(%rsp)\n"
17973+#endif
17974 #else
17975 " pushf\n"
17976 /*
17977@@ -777,7 +788,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17978 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17979 {
17980 unsigned long *tos = stack_addr(regs);
17981- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17982+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17983 unsigned long orig_ip = (unsigned long)p->addr;
17984 kprobe_opcode_t *insn = p->ainsn.insn;
17985
17986@@ -960,7 +971,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17987 struct die_args *args = data;
17988 int ret = NOTIFY_DONE;
17989
17990- if (args->regs && user_mode_vm(args->regs))
17991+ if (args->regs && user_mode(args->regs))
17992 return ret;
17993
17994 switch (val) {
17995diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
17996index 63b0ec8..6d92227 100644
17997--- a/arch/x86/kernel/kvm.c
17998+++ b/arch/x86/kernel/kvm.c
17999@@ -216,6 +216,7 @@ static void __init paravirt_ops_setup(void)
18000 pv_mmu_ops.set_pud = kvm_set_pud;
18001 #if PAGETABLE_LEVELS == 4
18002 pv_mmu_ops.set_pgd = kvm_set_pgd;
18003+ pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
18004 #endif
18005 #endif
18006 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
18007diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18008index ec6ef60..ab2c824 100644
18009--- a/arch/x86/kernel/ldt.c
18010+++ b/arch/x86/kernel/ldt.c
18011@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18012 if (reload) {
18013 #ifdef CONFIG_SMP
18014 preempt_disable();
18015- load_LDT(pc);
18016+ load_LDT_nolock(pc);
18017 if (!cpumask_equal(mm_cpumask(current->mm),
18018 cpumask_of(smp_processor_id())))
18019 smp_call_function(flush_ldt, current->mm, 1);
18020 preempt_enable();
18021 #else
18022- load_LDT(pc);
18023+ load_LDT_nolock(pc);
18024 #endif
18025 }
18026 if (oldsize) {
18027@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18028 return err;
18029
18030 for (i = 0; i < old->size; i++)
18031- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18032+ write_ldt_entry(new->ldt, i, old->ldt + i);
18033 return 0;
18034 }
18035
18036@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18037 retval = copy_ldt(&mm->context, &old_mm->context);
18038 mutex_unlock(&old_mm->context.lock);
18039 }
18040+
18041+ if (tsk == current) {
18042+ mm->context.vdso = 0;
18043+
18044+#ifdef CONFIG_X86_32
18045+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18046+ mm->context.user_cs_base = 0UL;
18047+ mm->context.user_cs_limit = ~0UL;
18048+
18049+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18050+ cpus_clear(mm->context.cpu_user_cs_mask);
18051+#endif
18052+
18053+#endif
18054+#endif
18055+
18056+ }
18057+
18058 return retval;
18059 }
18060
18061@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18062 }
18063 }
18064
18065+#ifdef CONFIG_PAX_SEGMEXEC
18066+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18067+ error = -EINVAL;
18068+ goto out_unlock;
18069+ }
18070+#endif
18071+
18072 fill_ldt(&ldt, &ldt_info);
18073 if (oldmode)
18074 ldt.avl = 0;
18075diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18076index c1c429d..f02eaf9 100644
18077--- a/arch/x86/kernel/machine_kexec_32.c
18078+++ b/arch/x86/kernel/machine_kexec_32.c
18079@@ -26,7 +26,7 @@
18080 #include <asm/system.h>
18081 #include <asm/cacheflush.h>
18082
18083-static void set_idt(void *newidt, __u16 limit)
18084+static void set_idt(struct desc_struct *newidt, __u16 limit)
18085 {
18086 struct desc_ptr curidt;
18087
18088@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18089 }
18090
18091
18092-static void set_gdt(void *newgdt, __u16 limit)
18093+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18094 {
18095 struct desc_ptr curgdt;
18096
18097@@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
18098 }
18099
18100 control_page = page_address(image->control_code_page);
18101- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18102+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18103
18104 relocate_kernel_ptr = control_page;
18105 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18106diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
18107index 1e47679..e73449d 100644
18108--- a/arch/x86/kernel/microcode_amd.c
18109+++ b/arch/x86/kernel/microcode_amd.c
18110@@ -364,7 +364,7 @@ static void microcode_fini_cpu_amd(int cpu)
18111 uci->mc = NULL;
18112 }
18113
18114-static struct microcode_ops microcode_amd_ops = {
18115+static const struct microcode_ops microcode_amd_ops = {
18116 .request_microcode_user = request_microcode_user,
18117 .request_microcode_fw = request_microcode_fw,
18118 .collect_cpu_info = collect_cpu_info_amd,
18119@@ -372,7 +372,7 @@ static struct microcode_ops microcode_amd_ops = {
18120 .microcode_fini_cpu = microcode_fini_cpu_amd,
18121 };
18122
18123-struct microcode_ops * __init init_amd_microcode(void)
18124+const struct microcode_ops * __init init_amd_microcode(void)
18125 {
18126 return &microcode_amd_ops;
18127 }
18128diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
18129index 378e9a8..b5a6ea9 100644
18130--- a/arch/x86/kernel/microcode_core.c
18131+++ b/arch/x86/kernel/microcode_core.c
18132@@ -90,7 +90,7 @@ MODULE_LICENSE("GPL");
18133
18134 #define MICROCODE_VERSION "2.00"
18135
18136-static struct microcode_ops *microcode_ops;
18137+static const struct microcode_ops *microcode_ops;
18138
18139 /*
18140 * Synchronization.
18141diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18142index 0d334dd..14cedaf 100644
18143--- a/arch/x86/kernel/microcode_intel.c
18144+++ b/arch/x86/kernel/microcode_intel.c
18145@@ -443,13 +443,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18146
18147 static int get_ucode_user(void *to, const void *from, size_t n)
18148 {
18149- return copy_from_user(to, from, n);
18150+ return copy_from_user(to, (const void __force_user *)from, n);
18151 }
18152
18153 static enum ucode_state
18154 request_microcode_user(int cpu, const void __user *buf, size_t size)
18155 {
18156- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18157+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18158 }
18159
18160 static void microcode_fini_cpu(int cpu)
18161@@ -460,7 +460,7 @@ static void microcode_fini_cpu(int cpu)
18162 uci->mc = NULL;
18163 }
18164
18165-static struct microcode_ops microcode_intel_ops = {
18166+static const struct microcode_ops microcode_intel_ops = {
18167 .request_microcode_user = request_microcode_user,
18168 .request_microcode_fw = request_microcode_fw,
18169 .collect_cpu_info = collect_cpu_info,
18170@@ -468,7 +468,7 @@ static struct microcode_ops microcode_intel_ops = {
18171 .microcode_fini_cpu = microcode_fini_cpu,
18172 };
18173
18174-struct microcode_ops * __init init_intel_microcode(void)
18175+const struct microcode_ops * __init init_intel_microcode(void)
18176 {
18177 return &microcode_intel_ops;
18178 }
18179diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18180index 89f386f..9028f51 100644
18181--- a/arch/x86/kernel/module.c
18182+++ b/arch/x86/kernel/module.c
18183@@ -34,7 +34,7 @@
18184 #define DEBUGP(fmt...)
18185 #endif
18186
18187-void *module_alloc(unsigned long size)
18188+static void *__module_alloc(unsigned long size, pgprot_t prot)
18189 {
18190 struct vm_struct *area;
18191
18192@@ -48,8 +48,18 @@ void *module_alloc(unsigned long size)
18193 if (!area)
18194 return NULL;
18195
18196- return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM,
18197- PAGE_KERNEL_EXEC);
18198+ return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot);
18199+}
18200+
18201+void *module_alloc(unsigned long size)
18202+{
18203+
18204+#ifdef CONFIG_PAX_KERNEXEC
18205+ return __module_alloc(size, PAGE_KERNEL);
18206+#else
18207+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18208+#endif
18209+
18210 }
18211
18212 /* Free memory returned from module_alloc */
18213@@ -58,6 +68,40 @@ void module_free(struct module *mod, void *module_region)
18214 vfree(module_region);
18215 }
18216
18217+#ifdef CONFIG_PAX_KERNEXEC
18218+#ifdef CONFIG_X86_32
18219+void *module_alloc_exec(unsigned long size)
18220+{
18221+ struct vm_struct *area;
18222+
18223+ if (size == 0)
18224+ return NULL;
18225+
18226+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18227+ return area ? area->addr : NULL;
18228+}
18229+EXPORT_SYMBOL(module_alloc_exec);
18230+
18231+void module_free_exec(struct module *mod, void *module_region)
18232+{
18233+ vunmap(module_region);
18234+}
18235+EXPORT_SYMBOL(module_free_exec);
18236+#else
18237+void module_free_exec(struct module *mod, void *module_region)
18238+{
18239+ module_free(mod, module_region);
18240+}
18241+EXPORT_SYMBOL(module_free_exec);
18242+
18243+void *module_alloc_exec(unsigned long size)
18244+{
18245+ return __module_alloc(size, PAGE_KERNEL_RX);
18246+}
18247+EXPORT_SYMBOL(module_alloc_exec);
18248+#endif
18249+#endif
18250+
18251 /* We don't need anything special. */
18252 int module_frob_arch_sections(Elf_Ehdr *hdr,
18253 Elf_Shdr *sechdrs,
18254@@ -77,14 +121,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18255 unsigned int i;
18256 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18257 Elf32_Sym *sym;
18258- uint32_t *location;
18259+ uint32_t *plocation, location;
18260
18261 DEBUGP("Applying relocate section %u to %u\n", relsec,
18262 sechdrs[relsec].sh_info);
18263 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18264 /* This is where to make the change */
18265- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18266- + rel[i].r_offset;
18267+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18268+ location = (uint32_t)plocation;
18269+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18270+ plocation = ktla_ktva((void *)plocation);
18271 /* This is the symbol it is referring to. Note that all
18272 undefined symbols have been resolved. */
18273 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18274@@ -93,11 +139,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18275 switch (ELF32_R_TYPE(rel[i].r_info)) {
18276 case R_386_32:
18277 /* We add the value into the location given */
18278- *location += sym->st_value;
18279+ pax_open_kernel();
18280+ *plocation += sym->st_value;
18281+ pax_close_kernel();
18282 break;
18283 case R_386_PC32:
18284 /* Add the value, subtract its postition */
18285- *location += sym->st_value - (uint32_t)location;
18286+ pax_open_kernel();
18287+ *plocation += sym->st_value - location;
18288+ pax_close_kernel();
18289 break;
18290 default:
18291 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18292@@ -153,21 +203,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18293 case R_X86_64_NONE:
18294 break;
18295 case R_X86_64_64:
18296+ pax_open_kernel();
18297 *(u64 *)loc = val;
18298+ pax_close_kernel();
18299 break;
18300 case R_X86_64_32:
18301+ pax_open_kernel();
18302 *(u32 *)loc = val;
18303+ pax_close_kernel();
18304 if (val != *(u32 *)loc)
18305 goto overflow;
18306 break;
18307 case R_X86_64_32S:
18308+ pax_open_kernel();
18309 *(s32 *)loc = val;
18310+ pax_close_kernel();
18311 if ((s64)val != *(s32 *)loc)
18312 goto overflow;
18313 break;
18314 case R_X86_64_PC32:
18315 val -= (u64)loc;
18316+ pax_open_kernel();
18317 *(u32 *)loc = val;
18318+ pax_close_kernel();
18319+
18320 #if 0
18321 if ((s64)val != *(s32 *)loc)
18322 goto overflow;
18323diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18324index 3a7c5a4..9191528 100644
18325--- a/arch/x86/kernel/paravirt-spinlocks.c
18326+++ b/arch/x86/kernel/paravirt-spinlocks.c
18327@@ -13,7 +13,7 @@ default_spin_lock_flags(raw_spinlock_t *lock, unsigned long flags)
18328 __raw_spin_lock(lock);
18329 }
18330
18331-struct pv_lock_ops pv_lock_ops = {
18332+struct pv_lock_ops pv_lock_ops __read_only = {
18333 #ifdef CONFIG_SMP
18334 .spin_is_locked = __ticket_spin_is_locked,
18335 .spin_is_contended = __ticket_spin_is_contended,
18336diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18337index 1b1739d..dea6077 100644
18338--- a/arch/x86/kernel/paravirt.c
18339+++ b/arch/x86/kernel/paravirt.c
18340@@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
18341 {
18342 return x;
18343 }
18344+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18345+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18346+#endif
18347
18348 void __init default_banner(void)
18349 {
18350@@ -122,7 +125,7 @@ unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
18351 * corresponding structure. */
18352 static void *get_call_destination(u8 type)
18353 {
18354- struct paravirt_patch_template tmpl = {
18355+ const struct paravirt_patch_template tmpl = {
18356 .pv_init_ops = pv_init_ops,
18357 .pv_time_ops = pv_time_ops,
18358 .pv_cpu_ops = pv_cpu_ops,
18359@@ -133,6 +136,8 @@ static void *get_call_destination(u8 type)
18360 .pv_lock_ops = pv_lock_ops,
18361 #endif
18362 };
18363+
18364+ pax_track_stack();
18365 return *((void **)&tmpl + type);
18366 }
18367
18368@@ -145,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18369 if (opfunc == NULL)
18370 /* If there's no function, patch it with a ud2a (BUG) */
18371 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18372- else if (opfunc == _paravirt_nop)
18373+ else if (opfunc == (void *)_paravirt_nop)
18374 /* If the operation is a nop, then nop the callsite */
18375 ret = paravirt_patch_nop();
18376
18377 /* identity functions just return their single argument */
18378- else if (opfunc == _paravirt_ident_32)
18379+ else if (opfunc == (void *)_paravirt_ident_32)
18380 ret = paravirt_patch_ident_32(insnbuf, len);
18381- else if (opfunc == _paravirt_ident_64)
18382+ else if (opfunc == (void *)_paravirt_ident_64)
18383 ret = paravirt_patch_ident_64(insnbuf, len);
18384+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18385+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18386+ ret = paravirt_patch_ident_64(insnbuf, len);
18387+#endif
18388
18389 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18390 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18391@@ -178,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18392 if (insn_len > len || start == NULL)
18393 insn_len = len;
18394 else
18395- memcpy(insnbuf, start, insn_len);
18396+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18397
18398 return insn_len;
18399 }
18400@@ -294,22 +303,22 @@ void arch_flush_lazy_mmu_mode(void)
18401 preempt_enable();
18402 }
18403
18404-struct pv_info pv_info = {
18405+struct pv_info pv_info __read_only = {
18406 .name = "bare hardware",
18407 .paravirt_enabled = 0,
18408 .kernel_rpl = 0,
18409 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
18410 };
18411
18412-struct pv_init_ops pv_init_ops = {
18413+struct pv_init_ops pv_init_ops __read_only = {
18414 .patch = native_patch,
18415 };
18416
18417-struct pv_time_ops pv_time_ops = {
18418+struct pv_time_ops pv_time_ops __read_only = {
18419 .sched_clock = native_sched_clock,
18420 };
18421
18422-struct pv_irq_ops pv_irq_ops = {
18423+struct pv_irq_ops pv_irq_ops __read_only = {
18424 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18425 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18426 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18427@@ -321,7 +330,7 @@ struct pv_irq_ops pv_irq_ops = {
18428 #endif
18429 };
18430
18431-struct pv_cpu_ops pv_cpu_ops = {
18432+struct pv_cpu_ops pv_cpu_ops __read_only = {
18433 .cpuid = native_cpuid,
18434 .get_debugreg = native_get_debugreg,
18435 .set_debugreg = native_set_debugreg,
18436@@ -382,21 +391,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18437 .end_context_switch = paravirt_nop,
18438 };
18439
18440-struct pv_apic_ops pv_apic_ops = {
18441+struct pv_apic_ops pv_apic_ops __read_only = {
18442 #ifdef CONFIG_X86_LOCAL_APIC
18443 .startup_ipi_hook = paravirt_nop,
18444 #endif
18445 };
18446
18447-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18448+#ifdef CONFIG_X86_32
18449+#ifdef CONFIG_X86_PAE
18450+/* 64-bit pagetable entries */
18451+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18452+#else
18453 /* 32-bit pagetable entries */
18454 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18455+#endif
18456 #else
18457 /* 64-bit pagetable entries */
18458 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18459 #endif
18460
18461-struct pv_mmu_ops pv_mmu_ops = {
18462+struct pv_mmu_ops pv_mmu_ops __read_only = {
18463
18464 .read_cr2 = native_read_cr2,
18465 .write_cr2 = native_write_cr2,
18466@@ -448,6 +462,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18467 .make_pud = PTE_IDENT,
18468
18469 .set_pgd = native_set_pgd,
18470+ .set_pgd_batched = native_set_pgd_batched,
18471 #endif
18472 #endif /* PAGETABLE_LEVELS >= 3 */
18473
18474@@ -467,6 +482,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18475 },
18476
18477 .set_fixmap = native_set_fixmap,
18478+
18479+#ifdef CONFIG_PAX_KERNEXEC
18480+ .pax_open_kernel = native_pax_open_kernel,
18481+ .pax_close_kernel = native_pax_close_kernel,
18482+#endif
18483+
18484 };
18485
18486 EXPORT_SYMBOL_GPL(pv_time_ops);
18487diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
18488index 1a2d4b1..6a0dd55 100644
18489--- a/arch/x86/kernel/pci-calgary_64.c
18490+++ b/arch/x86/kernel/pci-calgary_64.c
18491@@ -477,7 +477,7 @@ static void calgary_free_coherent(struct device *dev, size_t size,
18492 free_pages((unsigned long)vaddr, get_order(size));
18493 }
18494
18495-static struct dma_map_ops calgary_dma_ops = {
18496+static const struct dma_map_ops calgary_dma_ops = {
18497 .alloc_coherent = calgary_alloc_coherent,
18498 .free_coherent = calgary_free_coherent,
18499 .map_sg = calgary_map_sg,
18500diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
18501index 6ac3931..42b4414 100644
18502--- a/arch/x86/kernel/pci-dma.c
18503+++ b/arch/x86/kernel/pci-dma.c
18504@@ -14,7 +14,7 @@
18505
18506 static int forbid_dac __read_mostly;
18507
18508-struct dma_map_ops *dma_ops;
18509+const struct dma_map_ops *dma_ops;
18510 EXPORT_SYMBOL(dma_ops);
18511
18512 static int iommu_sac_force __read_mostly;
18513@@ -243,7 +243,7 @@ early_param("iommu", iommu_setup);
18514
18515 int dma_supported(struct device *dev, u64 mask)
18516 {
18517- struct dma_map_ops *ops = get_dma_ops(dev);
18518+ const struct dma_map_ops *ops = get_dma_ops(dev);
18519
18520 #ifdef CONFIG_PCI
18521 if (mask > 0xffffffff && forbid_dac > 0) {
18522diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c
18523index 1c76691..e3632db 100644
18524--- a/arch/x86/kernel/pci-gart_64.c
18525+++ b/arch/x86/kernel/pci-gart_64.c
18526@@ -682,7 +682,7 @@ static __init int init_k8_gatt(struct agp_kern_info *info)
18527 return -1;
18528 }
18529
18530-static struct dma_map_ops gart_dma_ops = {
18531+static const struct dma_map_ops gart_dma_ops = {
18532 .map_sg = gart_map_sg,
18533 .unmap_sg = gart_unmap_sg,
18534 .map_page = gart_map_page,
18535diff --git a/arch/x86/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu.c
18536index a3933d4..c898869 100644
18537--- a/arch/x86/kernel/pci-nommu.c
18538+++ b/arch/x86/kernel/pci-nommu.c
18539@@ -94,7 +94,7 @@ static void nommu_sync_sg_for_device(struct device *dev,
18540 flush_write_buffers();
18541 }
18542
18543-struct dma_map_ops nommu_dma_ops = {
18544+const struct dma_map_ops nommu_dma_ops = {
18545 .alloc_coherent = dma_generic_alloc_coherent,
18546 .free_coherent = nommu_free_coherent,
18547 .map_sg = nommu_map_sg,
18548diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
18549index aaa6b78..4de1881 100644
18550--- a/arch/x86/kernel/pci-swiotlb.c
18551+++ b/arch/x86/kernel/pci-swiotlb.c
18552@@ -25,7 +25,7 @@ static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
18553 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
18554 }
18555
18556-static struct dma_map_ops swiotlb_dma_ops = {
18557+static const struct dma_map_ops swiotlb_dma_ops = {
18558 .mapping_error = swiotlb_dma_mapping_error,
18559 .alloc_coherent = x86_swiotlb_alloc_coherent,
18560 .free_coherent = swiotlb_free_coherent,
18561diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18562index fc6c84d..0312ca2 100644
18563--- a/arch/x86/kernel/process.c
18564+++ b/arch/x86/kernel/process.c
18565@@ -51,16 +51,33 @@ void free_thread_xstate(struct task_struct *tsk)
18566
18567 void free_thread_info(struct thread_info *ti)
18568 {
18569- free_thread_xstate(ti->task);
18570 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
18571 }
18572
18573+static struct kmem_cache *task_struct_cachep;
18574+
18575 void arch_task_cache_init(void)
18576 {
18577- task_xstate_cachep =
18578- kmem_cache_create("task_xstate", xstate_size,
18579+ /* create a slab on which task_structs can be allocated */
18580+ task_struct_cachep =
18581+ kmem_cache_create("task_struct", sizeof(struct task_struct),
18582+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18583+
18584+ task_xstate_cachep =
18585+ kmem_cache_create("task_xstate", xstate_size,
18586 __alignof__(union thread_xstate),
18587- SLAB_PANIC | SLAB_NOTRACK, NULL);
18588+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18589+}
18590+
18591+struct task_struct *alloc_task_struct(void)
18592+{
18593+ return kmem_cache_alloc(task_struct_cachep, GFP_KERNEL);
18594+}
18595+
18596+void free_task_struct(struct task_struct *task)
18597+{
18598+ free_thread_xstate(task);
18599+ kmem_cache_free(task_struct_cachep, task);
18600 }
18601
18602 /*
18603@@ -73,7 +90,7 @@ void exit_thread(void)
18604 unsigned long *bp = t->io_bitmap_ptr;
18605
18606 if (bp) {
18607- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18608+ struct tss_struct *tss = init_tss + get_cpu();
18609
18610 t->io_bitmap_ptr = NULL;
18611 clear_thread_flag(TIF_IO_BITMAP);
18612@@ -93,6 +110,9 @@ void flush_thread(void)
18613
18614 clear_tsk_thread_flag(tsk, TIF_DEBUG);
18615
18616+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18617+ loadsegment(gs, 0);
18618+#endif
18619 tsk->thread.debugreg0 = 0;
18620 tsk->thread.debugreg1 = 0;
18621 tsk->thread.debugreg2 = 0;
18622@@ -307,7 +327,7 @@ void default_idle(void)
18623 EXPORT_SYMBOL(default_idle);
18624 #endif
18625
18626-void stop_this_cpu(void *dummy)
18627+__noreturn void stop_this_cpu(void *dummy)
18628 {
18629 local_irq_disable();
18630 /*
18631@@ -568,16 +588,38 @@ static int __init idle_setup(char *str)
18632 }
18633 early_param("idle", idle_setup);
18634
18635-unsigned long arch_align_stack(unsigned long sp)
18636+#ifdef CONFIG_PAX_RANDKSTACK
18637+void pax_randomize_kstack(struct pt_regs *regs)
18638 {
18639- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18640- sp -= get_random_int() % 8192;
18641- return sp & ~0xf;
18642-}
18643+ struct thread_struct *thread = &current->thread;
18644+ unsigned long time;
18645
18646-unsigned long arch_randomize_brk(struct mm_struct *mm)
18647-{
18648- unsigned long range_end = mm->brk + 0x02000000;
18649- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18650+ if (!randomize_va_space)
18651+ return;
18652+
18653+ if (v8086_mode(regs))
18654+ return;
18655+
18656+ rdtscl(time);
18657+
18658+ /* P4 seems to return a 0 LSB, ignore it */
18659+#ifdef CONFIG_MPENTIUM4
18660+ time &= 0x3EUL;
18661+ time <<= 2;
18662+#elif defined(CONFIG_X86_64)
18663+ time &= 0xFUL;
18664+ time <<= 4;
18665+#else
18666+ time &= 0x1FUL;
18667+ time <<= 3;
18668+#endif
18669+
18670+ thread->sp0 ^= time;
18671+ load_sp0(init_tss + smp_processor_id(), thread);
18672+
18673+#ifdef CONFIG_X86_64
18674+ percpu_write(kernel_stack, thread->sp0);
18675+#endif
18676 }
18677+#endif
18678
18679diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18680index c40c432..6e1df72 100644
18681--- a/arch/x86/kernel/process_32.c
18682+++ b/arch/x86/kernel/process_32.c
18683@@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18684 unsigned long thread_saved_pc(struct task_struct *tsk)
18685 {
18686 return ((unsigned long *)tsk->thread.sp)[3];
18687+//XXX return tsk->thread.eip;
18688 }
18689
18690 #ifndef CONFIG_SMP
18691@@ -129,15 +130,14 @@ void __show_regs(struct pt_regs *regs, int all)
18692 unsigned short ss, gs;
18693 const char *board;
18694
18695- if (user_mode_vm(regs)) {
18696+ if (user_mode(regs)) {
18697 sp = regs->sp;
18698 ss = regs->ss & 0xffff;
18699- gs = get_user_gs(regs);
18700 } else {
18701 sp = (unsigned long) (&regs->sp);
18702 savesegment(ss, ss);
18703- savesegment(gs, gs);
18704 }
18705+ gs = get_user_gs(regs);
18706
18707 printk("\n");
18708
18709@@ -210,10 +210,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18710 regs.bx = (unsigned long) fn;
18711 regs.dx = (unsigned long) arg;
18712
18713- regs.ds = __USER_DS;
18714- regs.es = __USER_DS;
18715+ regs.ds = __KERNEL_DS;
18716+ regs.es = __KERNEL_DS;
18717 regs.fs = __KERNEL_PERCPU;
18718- regs.gs = __KERNEL_STACK_CANARY;
18719+ savesegment(gs, regs.gs);
18720 regs.orig_ax = -1;
18721 regs.ip = (unsigned long) kernel_thread_helper;
18722 regs.cs = __KERNEL_CS | get_kernel_rpl();
18723@@ -247,13 +247,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18724 struct task_struct *tsk;
18725 int err;
18726
18727- childregs = task_pt_regs(p);
18728+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18729 *childregs = *regs;
18730 childregs->ax = 0;
18731 childregs->sp = sp;
18732
18733 p->thread.sp = (unsigned long) childregs;
18734 p->thread.sp0 = (unsigned long) (childregs+1);
18735+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18736
18737 p->thread.ip = (unsigned long) ret_from_fork;
18738
18739@@ -345,7 +346,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18740 struct thread_struct *prev = &prev_p->thread,
18741 *next = &next_p->thread;
18742 int cpu = smp_processor_id();
18743- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18744+ struct tss_struct *tss = init_tss + cpu;
18745 bool preload_fpu;
18746
18747 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18748@@ -380,6 +381,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18749 */
18750 lazy_save_gs(prev->gs);
18751
18752+#ifdef CONFIG_PAX_MEMORY_UDEREF
18753+ __set_fs(task_thread_info(next_p)->addr_limit);
18754+#endif
18755+
18756 /*
18757 * Load the per-thread Thread-Local Storage descriptor.
18758 */
18759@@ -415,6 +420,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18760 */
18761 arch_end_context_switch(next_p);
18762
18763+ percpu_write(current_task, next_p);
18764+ percpu_write(current_tinfo, &next_p->tinfo);
18765+
18766 if (preload_fpu)
18767 __math_state_restore();
18768
18769@@ -424,8 +432,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18770 if (prev->gs | next->gs)
18771 lazy_load_gs(next->gs);
18772
18773- percpu_write(current_task, next_p);
18774-
18775 return prev_p;
18776 }
18777
18778@@ -495,4 +501,3 @@ unsigned long get_wchan(struct task_struct *p)
18779 } while (count++ < 16);
18780 return 0;
18781 }
18782-
18783diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18784index 39493bc..196816d 100644
18785--- a/arch/x86/kernel/process_64.c
18786+++ b/arch/x86/kernel/process_64.c
18787@@ -91,7 +91,7 @@ static void __exit_idle(void)
18788 void exit_idle(void)
18789 {
18790 /* idle loop has pid 0 */
18791- if (current->pid)
18792+ if (task_pid_nr(current))
18793 return;
18794 __exit_idle();
18795 }
18796@@ -170,7 +170,7 @@ void __show_regs(struct pt_regs *regs, int all)
18797 if (!board)
18798 board = "";
18799 printk(KERN_INFO "Pid: %d, comm: %.20s %s %s %.*s %s\n",
18800- current->pid, current->comm, print_tainted(),
18801+ task_pid_nr(current), current->comm, print_tainted(),
18802 init_utsname()->release,
18803 (int)strcspn(init_utsname()->version, " "),
18804 init_utsname()->version, board);
18805@@ -280,8 +280,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18806 struct pt_regs *childregs;
18807 struct task_struct *me = current;
18808
18809- childregs = ((struct pt_regs *)
18810- (THREAD_SIZE + task_stack_page(p))) - 1;
18811+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18812 *childregs = *regs;
18813
18814 childregs->ax = 0;
18815@@ -292,6 +291,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18816 p->thread.sp = (unsigned long) childregs;
18817 p->thread.sp0 = (unsigned long) (childregs+1);
18818 p->thread.usersp = me->thread.usersp;
18819+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18820
18821 set_tsk_thread_flag(p, TIF_FORK);
18822
18823@@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18824 struct thread_struct *prev = &prev_p->thread;
18825 struct thread_struct *next = &next_p->thread;
18826 int cpu = smp_processor_id();
18827- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18828+ struct tss_struct *tss = init_tss + cpu;
18829 unsigned fsindex, gsindex;
18830 bool preload_fpu;
18831
18832@@ -475,10 +475,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18833 prev->usersp = percpu_read(old_rsp);
18834 percpu_write(old_rsp, next->usersp);
18835 percpu_write(current_task, next_p);
18836+ percpu_write(current_tinfo, &next_p->tinfo);
18837
18838- percpu_write(kernel_stack,
18839- (unsigned long)task_stack_page(next_p) +
18840- THREAD_SIZE - KERNEL_STACK_OFFSET);
18841+ percpu_write(kernel_stack, next->sp0);
18842
18843 /*
18844 * Now maybe reload the debug registers and handle I/O bitmaps
18845@@ -559,12 +558,11 @@ unsigned long get_wchan(struct task_struct *p)
18846 if (!p || p == current || p->state == TASK_RUNNING)
18847 return 0;
18848 stack = (unsigned long)task_stack_page(p);
18849- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18850+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18851 return 0;
18852 fp = *(u64 *)(p->thread.sp);
18853 do {
18854- if (fp < (unsigned long)stack ||
18855- fp >= (unsigned long)stack+THREAD_SIZE)
18856+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18857 return 0;
18858 ip = *(u64 *)(fp+8);
18859 if (!in_sched_functions(ip))
18860diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18861index c06acdd..3f5fff5 100644
18862--- a/arch/x86/kernel/ptrace.c
18863+++ b/arch/x86/kernel/ptrace.c
18864@@ -925,7 +925,7 @@ static const struct user_regset_view user_x86_32_view; /* Initialized below. */
18865 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18866 {
18867 int ret;
18868- unsigned long __user *datap = (unsigned long __user *)data;
18869+ unsigned long __user *datap = (__force unsigned long __user *)data;
18870
18871 switch (request) {
18872 /* read the word at location addr in the USER area. */
18873@@ -1012,14 +1012,14 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18874 if (addr < 0)
18875 return -EIO;
18876 ret = do_get_thread_area(child, addr,
18877- (struct user_desc __user *) data);
18878+ (__force struct user_desc __user *) data);
18879 break;
18880
18881 case PTRACE_SET_THREAD_AREA:
18882 if (addr < 0)
18883 return -EIO;
18884 ret = do_set_thread_area(child, addr,
18885- (struct user_desc __user *) data, 0);
18886+ (__force struct user_desc __user *) data, 0);
18887 break;
18888 #endif
18889
18890@@ -1038,12 +1038,12 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18891 #ifdef CONFIG_X86_PTRACE_BTS
18892 case PTRACE_BTS_CONFIG:
18893 ret = ptrace_bts_config
18894- (child, data, (struct ptrace_bts_config __user *)addr);
18895+ (child, data, (__force struct ptrace_bts_config __user *)addr);
18896 break;
18897
18898 case PTRACE_BTS_STATUS:
18899 ret = ptrace_bts_status
18900- (child, data, (struct ptrace_bts_config __user *)addr);
18901+ (child, data, (__force struct ptrace_bts_config __user *)addr);
18902 break;
18903
18904 case PTRACE_BTS_SIZE:
18905@@ -1052,7 +1052,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18906
18907 case PTRACE_BTS_GET:
18908 ret = ptrace_bts_read_record
18909- (child, data, (struct bts_struct __user *) addr);
18910+ (child, data, (__force struct bts_struct __user *) addr);
18911 break;
18912
18913 case PTRACE_BTS_CLEAR:
18914@@ -1061,7 +1061,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18915
18916 case PTRACE_BTS_DRAIN:
18917 ret = ptrace_bts_drain
18918- (child, data, (struct bts_struct __user *) addr);
18919+ (child, data, (__force struct bts_struct __user *) addr);
18920 break;
18921 #endif /* CONFIG_X86_PTRACE_BTS */
18922
18923@@ -1450,7 +1450,7 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18924 info.si_code = si_code;
18925
18926 /* User-mode ip? */
18927- info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
18928+ info.si_addr = user_mode(regs) ? (__force void __user *) regs->ip : NULL;
18929
18930 /* Send us the fake SIGTRAP */
18931 force_sig_info(SIGTRAP, &info, tsk);
18932@@ -1469,7 +1469,7 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18933 * We must return the syscall number to actually look up in the table.
18934 * This can be -1L to skip running any syscall at all.
18935 */
18936-asmregparm long syscall_trace_enter(struct pt_regs *regs)
18937+long syscall_trace_enter(struct pt_regs *regs)
18938 {
18939 long ret = 0;
18940
18941@@ -1514,7 +1514,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
18942 return ret ?: regs->orig_ax;
18943 }
18944
18945-asmregparm void syscall_trace_leave(struct pt_regs *regs)
18946+void syscall_trace_leave(struct pt_regs *regs)
18947 {
18948 if (unlikely(current->audit_context))
18949 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
18950diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18951index cf98100..e76e03d 100644
18952--- a/arch/x86/kernel/reboot.c
18953+++ b/arch/x86/kernel/reboot.c
18954@@ -33,7 +33,7 @@ void (*pm_power_off)(void);
18955 EXPORT_SYMBOL(pm_power_off);
18956
18957 static const struct desc_ptr no_idt = {};
18958-static int reboot_mode;
18959+static unsigned short reboot_mode;
18960 enum reboot_type reboot_type = BOOT_KBD;
18961 int reboot_force;
18962
18963@@ -292,12 +292,12 @@ core_initcall(reboot_init);
18964 controller to pulse the CPU reset line, which is more thorough, but
18965 doesn't work with at least one type of 486 motherboard. It is easy
18966 to stop this code working; hence the copious comments. */
18967-static const unsigned long long
18968-real_mode_gdt_entries [3] =
18969+static struct desc_struct
18970+real_mode_gdt_entries [3] __read_only =
18971 {
18972- 0x0000000000000000ULL, /* Null descriptor */
18973- 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
18974- 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
18975+ GDT_ENTRY_INIT(0, 0, 0), /* Null descriptor */
18976+ GDT_ENTRY_INIT(0x9b, 0, 0xffff), /* 16-bit real-mode 64k code at 0x00000000 */
18977+ GDT_ENTRY_INIT(0x93, 0x100, 0xffff) /* 16-bit real-mode 64k data at 0x00000100 */
18978 };
18979
18980 static const struct desc_ptr
18981@@ -346,7 +346,7 @@ static const unsigned char jump_to_bios [] =
18982 * specified by the code and length parameters.
18983 * We assume that length will aways be less that 100!
18984 */
18985-void machine_real_restart(const unsigned char *code, int length)
18986+__noreturn void machine_real_restart(const unsigned char *code, unsigned int length)
18987 {
18988 local_irq_disable();
18989
18990@@ -366,8 +366,8 @@ void machine_real_restart(const unsigned char *code, int length)
18991 /* Remap the kernel at virtual address zero, as well as offset zero
18992 from the kernel segment. This assumes the kernel segment starts at
18993 virtual address PAGE_OFFSET. */
18994- memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18995- sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
18996+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18997+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
18998
18999 /*
19000 * Use `swapper_pg_dir' as our page directory.
19001@@ -379,16 +379,15 @@ void machine_real_restart(const unsigned char *code, int length)
19002 boot)". This seems like a fairly standard thing that gets set by
19003 REBOOT.COM programs, and the previous reset routine did this
19004 too. */
19005- *((unsigned short *)0x472) = reboot_mode;
19006+ *(unsigned short *)(__va(0x472)) = reboot_mode;
19007
19008 /* For the switch to real mode, copy some code to low memory. It has
19009 to be in the first 64k because it is running in 16-bit mode, and it
19010 has to have the same physical and virtual address, because it turns
19011 off paging. Copy it near the end of the first page, out of the way
19012 of BIOS variables. */
19013- memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
19014- real_mode_switch, sizeof (real_mode_switch));
19015- memcpy((void *)(0x1000 - 100), code, length);
19016+ memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
19017+ memcpy(__va(0x1000 - 100), code, length);
19018
19019 /* Set up the IDT for real mode. */
19020 load_idt(&real_mode_idt);
19021@@ -416,6 +415,7 @@ void machine_real_restart(const unsigned char *code, int length)
19022 __asm__ __volatile__ ("ljmp $0x0008,%0"
19023 :
19024 : "i" ((void *)(0x1000 - sizeof (real_mode_switch) - 100)));
19025+ do { } while (1);
19026 }
19027 #ifdef CONFIG_APM_MODULE
19028 EXPORT_SYMBOL(machine_real_restart);
19029@@ -544,7 +544,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
19030 {
19031 }
19032
19033-static void native_machine_emergency_restart(void)
19034+__noreturn static void native_machine_emergency_restart(void)
19035 {
19036 int i;
19037
19038@@ -659,13 +659,13 @@ void native_machine_shutdown(void)
19039 #endif
19040 }
19041
19042-static void __machine_emergency_restart(int emergency)
19043+static __noreturn void __machine_emergency_restart(int emergency)
19044 {
19045 reboot_emergency = emergency;
19046 machine_ops.emergency_restart();
19047 }
19048
19049-static void native_machine_restart(char *__unused)
19050+static __noreturn void native_machine_restart(char *__unused)
19051 {
19052 printk("machine restart\n");
19053
19054@@ -674,7 +674,7 @@ static void native_machine_restart(char *__unused)
19055 __machine_emergency_restart(0);
19056 }
19057
19058-static void native_machine_halt(void)
19059+static __noreturn void native_machine_halt(void)
19060 {
19061 /* stop other cpus and apics */
19062 machine_shutdown();
19063@@ -685,7 +685,7 @@ static void native_machine_halt(void)
19064 stop_this_cpu(NULL);
19065 }
19066
19067-static void native_machine_power_off(void)
19068+__noreturn static void native_machine_power_off(void)
19069 {
19070 if (pm_power_off) {
19071 if (!reboot_force)
19072@@ -694,6 +694,7 @@ static void native_machine_power_off(void)
19073 }
19074 /* a fallback in case there is no PM info available */
19075 tboot_shutdown(TB_SHUTDOWN_HALT);
19076+ do { } while (1);
19077 }
19078
19079 struct machine_ops machine_ops = {
19080diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19081index 7a6f3b3..976a959 100644
19082--- a/arch/x86/kernel/relocate_kernel_64.S
19083+++ b/arch/x86/kernel/relocate_kernel_64.S
19084@@ -11,6 +11,7 @@
19085 #include <asm/kexec.h>
19086 #include <asm/processor-flags.h>
19087 #include <asm/pgtable_types.h>
19088+#include <asm/alternative-asm.h>
19089
19090 /*
19091 * Must be relocatable PIC code callable as a C function
19092@@ -167,6 +168,7 @@ identity_mapped:
19093 xorq %r14, %r14
19094 xorq %r15, %r15
19095
19096+ pax_force_retaddr 0, 1
19097 ret
19098
19099 1:
19100diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19101index 5449a26..0b6c759 100644
19102--- a/arch/x86/kernel/setup.c
19103+++ b/arch/x86/kernel/setup.c
19104@@ -783,14 +783,14 @@ void __init setup_arch(char **cmdline_p)
19105
19106 if (!boot_params.hdr.root_flags)
19107 root_mountflags &= ~MS_RDONLY;
19108- init_mm.start_code = (unsigned long) _text;
19109- init_mm.end_code = (unsigned long) _etext;
19110+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19111+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19112 init_mm.end_data = (unsigned long) _edata;
19113 init_mm.brk = _brk_end;
19114
19115- code_resource.start = virt_to_phys(_text);
19116- code_resource.end = virt_to_phys(_etext)-1;
19117- data_resource.start = virt_to_phys(_etext);
19118+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19119+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19120+ data_resource.start = virt_to_phys(_sdata);
19121 data_resource.end = virt_to_phys(_edata)-1;
19122 bss_resource.start = virt_to_phys(&__bss_start);
19123 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19124diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19125index d559af9..524c6ad 100644
19126--- a/arch/x86/kernel/setup_percpu.c
19127+++ b/arch/x86/kernel/setup_percpu.c
19128@@ -25,19 +25,17 @@
19129 # define DBG(x...)
19130 #endif
19131
19132-DEFINE_PER_CPU(int, cpu_number);
19133+#ifdef CONFIG_SMP
19134+DEFINE_PER_CPU(unsigned int, cpu_number);
19135 EXPORT_PER_CPU_SYMBOL(cpu_number);
19136+#endif
19137
19138-#ifdef CONFIG_X86_64
19139 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19140-#else
19141-#define BOOT_PERCPU_OFFSET 0
19142-#endif
19143
19144 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19145 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19146
19147-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19148+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19149 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19150 };
19151 EXPORT_SYMBOL(__per_cpu_offset);
19152@@ -159,10 +157,10 @@ static inline void setup_percpu_segment(int cpu)
19153 {
19154 #ifdef CONFIG_X86_32
19155 struct desc_struct gdt;
19156+ unsigned long base = per_cpu_offset(cpu);
19157
19158- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19159- 0x2 | DESCTYPE_S, 0x8);
19160- gdt.s = 1;
19161+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19162+ 0x83 | DESCTYPE_S, 0xC);
19163 write_gdt_entry(get_cpu_gdt_table(cpu),
19164 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19165 #endif
19166@@ -212,6 +210,11 @@ void __init setup_per_cpu_areas(void)
19167 /* alrighty, percpu areas up and running */
19168 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19169 for_each_possible_cpu(cpu) {
19170+#ifdef CONFIG_CC_STACKPROTECTOR
19171+#ifdef CONFIG_X86_32
19172+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19173+#endif
19174+#endif
19175 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19176 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19177 per_cpu(cpu_number, cpu) = cpu;
19178@@ -239,6 +242,12 @@ void __init setup_per_cpu_areas(void)
19179 early_per_cpu_map(x86_cpu_to_node_map, cpu);
19180 #endif
19181 #endif
19182+#ifdef CONFIG_CC_STACKPROTECTOR
19183+#ifdef CONFIG_X86_32
19184+ if (!cpu)
19185+ per_cpu(stack_canary.canary, cpu) = canary;
19186+#endif
19187+#endif
19188 /*
19189 * Up to this point, the boot CPU has been using .data.init
19190 * area. Reload any changed state for the boot CPU.
19191diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19192index 6a44a76..a9287a1 100644
19193--- a/arch/x86/kernel/signal.c
19194+++ b/arch/x86/kernel/signal.c
19195@@ -197,7 +197,7 @@ static unsigned long align_sigframe(unsigned long sp)
19196 * Align the stack pointer according to the i386 ABI,
19197 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19198 */
19199- sp = ((sp + 4) & -16ul) - 4;
19200+ sp = ((sp - 12) & -16ul) - 4;
19201 #else /* !CONFIG_X86_32 */
19202 sp = round_down(sp, 16) - 8;
19203 #endif
19204@@ -248,11 +248,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19205 * Return an always-bogus address instead so we will die with SIGSEGV.
19206 */
19207 if (onsigstack && !likely(on_sig_stack(sp)))
19208- return (void __user *)-1L;
19209+ return (__force void __user *)-1L;
19210
19211 /* save i387 state */
19212 if (used_math() && save_i387_xstate(*fpstate) < 0)
19213- return (void __user *)-1L;
19214+ return (__force void __user *)-1L;
19215
19216 return (void __user *)sp;
19217 }
19218@@ -307,9 +307,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19219 }
19220
19221 if (current->mm->context.vdso)
19222- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19223+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19224 else
19225- restorer = &frame->retcode;
19226+ restorer = (void __user *)&frame->retcode;
19227 if (ka->sa.sa_flags & SA_RESTORER)
19228 restorer = ka->sa.sa_restorer;
19229
19230@@ -323,7 +323,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19231 * reasons and because gdb uses it as a signature to notice
19232 * signal handler stack frames.
19233 */
19234- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19235+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19236
19237 if (err)
19238 return -EFAULT;
19239@@ -377,7 +377,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19240 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19241
19242 /* Set up to return from userspace. */
19243- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19244+ if (current->mm->context.vdso)
19245+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19246+ else
19247+ restorer = (void __user *)&frame->retcode;
19248 if (ka->sa.sa_flags & SA_RESTORER)
19249 restorer = ka->sa.sa_restorer;
19250 put_user_ex(restorer, &frame->pretcode);
19251@@ -389,7 +392,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19252 * reasons and because gdb uses it as a signature to notice
19253 * signal handler stack frames.
19254 */
19255- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19256+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19257 } put_user_catch(err);
19258
19259 if (err)
19260@@ -782,6 +785,8 @@ static void do_signal(struct pt_regs *regs)
19261 int signr;
19262 sigset_t *oldset;
19263
19264+ pax_track_stack();
19265+
19266 /*
19267 * We want the common case to go fast, which is why we may in certain
19268 * cases get here from kernel mode. Just return without doing anything
19269@@ -789,7 +794,7 @@ static void do_signal(struct pt_regs *regs)
19270 * X86_32: vm86 regs switched out by assembly code before reaching
19271 * here, so testing against kernel CS suffices.
19272 */
19273- if (!user_mode(regs))
19274+ if (!user_mode_novm(regs))
19275 return;
19276
19277 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
19278diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19279index 7e8e905..64d5c32 100644
19280--- a/arch/x86/kernel/smpboot.c
19281+++ b/arch/x86/kernel/smpboot.c
19282@@ -94,14 +94,14 @@ static DEFINE_PER_CPU(struct task_struct *, idle_thread_array);
19283 */
19284 static DEFINE_MUTEX(x86_cpu_hotplug_driver_mutex);
19285
19286-void cpu_hotplug_driver_lock()
19287+void cpu_hotplug_driver_lock(void)
19288 {
19289- mutex_lock(&x86_cpu_hotplug_driver_mutex);
19290+ mutex_lock(&x86_cpu_hotplug_driver_mutex);
19291 }
19292
19293-void cpu_hotplug_driver_unlock()
19294+void cpu_hotplug_driver_unlock(void)
19295 {
19296- mutex_unlock(&x86_cpu_hotplug_driver_mutex);
19297+ mutex_unlock(&x86_cpu_hotplug_driver_mutex);
19298 }
19299
19300 ssize_t arch_cpu_probe(const char *buf, size_t count) { return -1; }
19301@@ -625,7 +625,7 @@ wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip)
19302 * target processor state.
19303 */
19304 startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
19305- (unsigned long)stack_start.sp);
19306+ stack_start);
19307
19308 /*
19309 * Run STARTUP IPI loop.
19310@@ -743,6 +743,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19311 set_idle_for_cpu(cpu, c_idle.idle);
19312 do_rest:
19313 per_cpu(current_task, cpu) = c_idle.idle;
19314+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19315 #ifdef CONFIG_X86_32
19316 /* Stack for startup_32 can be just as for start_secondary onwards */
19317 irq_ctx_init(cpu);
19318@@ -750,13 +751,15 @@ do_rest:
19319 #else
19320 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19321 initial_gs = per_cpu_offset(cpu);
19322- per_cpu(kernel_stack, cpu) =
19323- (unsigned long)task_stack_page(c_idle.idle) -
19324- KERNEL_STACK_OFFSET + THREAD_SIZE;
19325+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19326 #endif
19327+
19328+ pax_open_kernel();
19329 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19330+ pax_close_kernel();
19331+
19332 initial_code = (unsigned long)start_secondary;
19333- stack_start.sp = (void *) c_idle.idle->thread.sp;
19334+ stack_start = c_idle.idle->thread.sp;
19335
19336 /* start_ip had better be page-aligned! */
19337 start_ip = setup_trampoline();
19338@@ -891,6 +894,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19339
19340 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19341
19342+#ifdef CONFIG_PAX_PER_CPU_PGD
19343+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19344+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19345+ KERNEL_PGD_PTRS);
19346+#endif
19347+
19348 err = do_boot_cpu(apicid, cpu);
19349
19350 if (err) {
19351diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19352index 3149032..14f1053 100644
19353--- a/arch/x86/kernel/step.c
19354+++ b/arch/x86/kernel/step.c
19355@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19356 struct desc_struct *desc;
19357 unsigned long base;
19358
19359- seg &= ~7UL;
19360+ seg >>= 3;
19361
19362 mutex_lock(&child->mm->context.lock);
19363- if (unlikely((seg >> 3) >= child->mm->context.size))
19364+ if (unlikely(seg >= child->mm->context.size))
19365 addr = -1L; /* bogus selector, access would fault */
19366 else {
19367 desc = child->mm->context.ldt + seg;
19368@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19369 addr += base;
19370 }
19371 mutex_unlock(&child->mm->context.lock);
19372- }
19373+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19374+ addr = ktla_ktva(addr);
19375
19376 return addr;
19377 }
19378@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19379 unsigned char opcode[15];
19380 unsigned long addr = convert_ip_to_linear(child, regs);
19381
19382+ if (addr == -EINVAL)
19383+ return 0;
19384+
19385 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19386 for (i = 0; i < copied; i++) {
19387 switch (opcode[i]) {
19388@@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19389
19390 #ifdef CONFIG_X86_64
19391 case 0x40 ... 0x4f:
19392- if (regs->cs != __USER_CS)
19393+ if ((regs->cs & 0xffff) != __USER_CS)
19394 /* 32-bit mode: register increment */
19395 return 0;
19396 /* 64-bit mode: REX prefix */
19397diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19398index dee1ff7..a397f7f 100644
19399--- a/arch/x86/kernel/sys_i386_32.c
19400+++ b/arch/x86/kernel/sys_i386_32.c
19401@@ -24,6 +24,21 @@
19402
19403 #include <asm/syscalls.h>
19404
19405+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19406+{
19407+ unsigned long pax_task_size = TASK_SIZE;
19408+
19409+#ifdef CONFIG_PAX_SEGMEXEC
19410+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19411+ pax_task_size = SEGMEXEC_TASK_SIZE;
19412+#endif
19413+
19414+ if (len > pax_task_size || addr > pax_task_size - len)
19415+ return -EINVAL;
19416+
19417+ return 0;
19418+}
19419+
19420 /*
19421 * Perform the select(nd, in, out, ex, tv) and mmap() system
19422 * calls. Linux/i386 didn't use to be able to handle more than
19423@@ -58,6 +73,212 @@ out:
19424 return err;
19425 }
19426
19427+unsigned long
19428+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19429+ unsigned long len, unsigned long pgoff, unsigned long flags)
19430+{
19431+ struct mm_struct *mm = current->mm;
19432+ struct vm_area_struct *vma;
19433+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19434+
19435+#ifdef CONFIG_PAX_SEGMEXEC
19436+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19437+ pax_task_size = SEGMEXEC_TASK_SIZE;
19438+#endif
19439+
19440+ pax_task_size -= PAGE_SIZE;
19441+
19442+ if (len > pax_task_size)
19443+ return -ENOMEM;
19444+
19445+ if (flags & MAP_FIXED)
19446+ return addr;
19447+
19448+#ifdef CONFIG_PAX_RANDMMAP
19449+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19450+#endif
19451+
19452+ if (addr) {
19453+ addr = PAGE_ALIGN(addr);
19454+ if (pax_task_size - len >= addr) {
19455+ vma = find_vma(mm, addr);
19456+ if (check_heap_stack_gap(vma, addr, len))
19457+ return addr;
19458+ }
19459+ }
19460+ if (len > mm->cached_hole_size) {
19461+ start_addr = addr = mm->free_area_cache;
19462+ } else {
19463+ start_addr = addr = mm->mmap_base;
19464+ mm->cached_hole_size = 0;
19465+ }
19466+
19467+#ifdef CONFIG_PAX_PAGEEXEC
19468+ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19469+ start_addr = 0x00110000UL;
19470+
19471+#ifdef CONFIG_PAX_RANDMMAP
19472+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19473+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19474+#endif
19475+
19476+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19477+ start_addr = addr = mm->mmap_base;
19478+ else
19479+ addr = start_addr;
19480+ }
19481+#endif
19482+
19483+full_search:
19484+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19485+ /* At this point: (!vma || addr < vma->vm_end). */
19486+ if (pax_task_size - len < addr) {
19487+ /*
19488+ * Start a new search - just in case we missed
19489+ * some holes.
19490+ */
19491+ if (start_addr != mm->mmap_base) {
19492+ start_addr = addr = mm->mmap_base;
19493+ mm->cached_hole_size = 0;
19494+ goto full_search;
19495+ }
19496+ return -ENOMEM;
19497+ }
19498+ if (check_heap_stack_gap(vma, addr, len))
19499+ break;
19500+ if (addr + mm->cached_hole_size < vma->vm_start)
19501+ mm->cached_hole_size = vma->vm_start - addr;
19502+ addr = vma->vm_end;
19503+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19504+ start_addr = addr = mm->mmap_base;
19505+ mm->cached_hole_size = 0;
19506+ goto full_search;
19507+ }
19508+ }
19509+
19510+ /*
19511+ * Remember the place where we stopped the search:
19512+ */
19513+ mm->free_area_cache = addr + len;
19514+ return addr;
19515+}
19516+
19517+unsigned long
19518+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19519+ const unsigned long len, const unsigned long pgoff,
19520+ const unsigned long flags)
19521+{
19522+ struct vm_area_struct *vma;
19523+ struct mm_struct *mm = current->mm;
19524+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19525+
19526+#ifdef CONFIG_PAX_SEGMEXEC
19527+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19528+ pax_task_size = SEGMEXEC_TASK_SIZE;
19529+#endif
19530+
19531+ pax_task_size -= PAGE_SIZE;
19532+
19533+ /* requested length too big for entire address space */
19534+ if (len > pax_task_size)
19535+ return -ENOMEM;
19536+
19537+ if (flags & MAP_FIXED)
19538+ return addr;
19539+
19540+#ifdef CONFIG_PAX_PAGEEXEC
19541+ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19542+ goto bottomup;
19543+#endif
19544+
19545+#ifdef CONFIG_PAX_RANDMMAP
19546+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19547+#endif
19548+
19549+ /* requesting a specific address */
19550+ if (addr) {
19551+ addr = PAGE_ALIGN(addr);
19552+ if (pax_task_size - len >= addr) {
19553+ vma = find_vma(mm, addr);
19554+ if (check_heap_stack_gap(vma, addr, len))
19555+ return addr;
19556+ }
19557+ }
19558+
19559+ /* check if free_area_cache is useful for us */
19560+ if (len <= mm->cached_hole_size) {
19561+ mm->cached_hole_size = 0;
19562+ mm->free_area_cache = mm->mmap_base;
19563+ }
19564+
19565+ /* either no address requested or can't fit in requested address hole */
19566+ addr = mm->free_area_cache;
19567+
19568+ /* make sure it can fit in the remaining address space */
19569+ if (addr > len) {
19570+ vma = find_vma(mm, addr-len);
19571+ if (check_heap_stack_gap(vma, addr - len, len))
19572+ /* remember the address as a hint for next time */
19573+ return (mm->free_area_cache = addr-len);
19574+ }
19575+
19576+ if (mm->mmap_base < len)
19577+ goto bottomup;
19578+
19579+ addr = mm->mmap_base-len;
19580+
19581+ do {
19582+ /*
19583+ * Lookup failure means no vma is above this address,
19584+ * else if new region fits below vma->vm_start,
19585+ * return with success:
19586+ */
19587+ vma = find_vma(mm, addr);
19588+ if (check_heap_stack_gap(vma, addr, len))
19589+ /* remember the address as a hint for next time */
19590+ return (mm->free_area_cache = addr);
19591+
19592+ /* remember the largest hole we saw so far */
19593+ if (addr + mm->cached_hole_size < vma->vm_start)
19594+ mm->cached_hole_size = vma->vm_start - addr;
19595+
19596+ /* try just below the current vma->vm_start */
19597+ addr = skip_heap_stack_gap(vma, len);
19598+ } while (!IS_ERR_VALUE(addr));
19599+
19600+bottomup:
19601+ /*
19602+ * A failed mmap() very likely causes application failure,
19603+ * so fall back to the bottom-up function here. This scenario
19604+ * can happen with large stack limits and large mmap()
19605+ * allocations.
19606+ */
19607+
19608+#ifdef CONFIG_PAX_SEGMEXEC
19609+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19610+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19611+ else
19612+#endif
19613+
19614+ mm->mmap_base = TASK_UNMAPPED_BASE;
19615+
19616+#ifdef CONFIG_PAX_RANDMMAP
19617+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19618+ mm->mmap_base += mm->delta_mmap;
19619+#endif
19620+
19621+ mm->free_area_cache = mm->mmap_base;
19622+ mm->cached_hole_size = ~0UL;
19623+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19624+ /*
19625+ * Restore the topdown base:
19626+ */
19627+ mm->mmap_base = base;
19628+ mm->free_area_cache = base;
19629+ mm->cached_hole_size = ~0UL;
19630+
19631+ return addr;
19632+}
19633
19634 struct sel_arg_struct {
19635 unsigned long n;
19636@@ -93,7 +314,7 @@ asmlinkage int sys_ipc(uint call, int first, int second,
19637 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
19638 case SEMTIMEDOP:
19639 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
19640- (const struct timespec __user *)fifth);
19641+ (__force const struct timespec __user *)fifth);
19642
19643 case SEMGET:
19644 return sys_semget(first, second, third);
19645@@ -140,7 +361,7 @@ asmlinkage int sys_ipc(uint call, int first, int second,
19646 ret = do_shmat(first, (char __user *) ptr, second, &raddr);
19647 if (ret)
19648 return ret;
19649- return put_user(raddr, (ulong __user *) third);
19650+ return put_user(raddr, (__force ulong __user *) third);
19651 }
19652 case 1: /* iBCS2 emulator entry point */
19653 if (!segment_eq(get_fs(), get_ds()))
19654@@ -207,17 +428,3 @@ asmlinkage int sys_olduname(struct oldold_utsname __user *name)
19655
19656 return error;
19657 }
19658-
19659-
19660-/*
19661- * Do a system call from kernel instead of calling sys_execve so we
19662- * end up with proper pt_regs.
19663- */
19664-int kernel_execve(const char *filename, char *const argv[], char *const envp[])
19665-{
19666- long __res;
19667- asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
19668- : "=a" (__res)
19669- : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory");
19670- return __res;
19671-}
19672diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19673index 8aa2057..b604bc1 100644
19674--- a/arch/x86/kernel/sys_x86_64.c
19675+++ b/arch/x86/kernel/sys_x86_64.c
19676@@ -32,8 +32,8 @@ out:
19677 return error;
19678 }
19679
19680-static void find_start_end(unsigned long flags, unsigned long *begin,
19681- unsigned long *end)
19682+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19683+ unsigned long *begin, unsigned long *end)
19684 {
19685 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19686 unsigned long new_begin;
19687@@ -52,7 +52,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19688 *begin = new_begin;
19689 }
19690 } else {
19691- *begin = TASK_UNMAPPED_BASE;
19692+ *begin = mm->mmap_base;
19693 *end = TASK_SIZE;
19694 }
19695 }
19696@@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19697 if (flags & MAP_FIXED)
19698 return addr;
19699
19700- find_start_end(flags, &begin, &end);
19701+ find_start_end(mm, flags, &begin, &end);
19702
19703 if (len > end)
19704 return -ENOMEM;
19705
19706+#ifdef CONFIG_PAX_RANDMMAP
19707+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19708+#endif
19709+
19710 if (addr) {
19711 addr = PAGE_ALIGN(addr);
19712 vma = find_vma(mm, addr);
19713- if (end - len >= addr &&
19714- (!vma || addr + len <= vma->vm_start))
19715+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19716 return addr;
19717 }
19718 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19719@@ -106,7 +109,7 @@ full_search:
19720 }
19721 return -ENOMEM;
19722 }
19723- if (!vma || addr + len <= vma->vm_start) {
19724+ if (check_heap_stack_gap(vma, addr, len)) {
19725 /*
19726 * Remember the place where we stopped the search:
19727 */
19728@@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19729 {
19730 struct vm_area_struct *vma;
19731 struct mm_struct *mm = current->mm;
19732- unsigned long addr = addr0;
19733+ unsigned long base = mm->mmap_base, addr = addr0;
19734
19735 /* requested length too big for entire address space */
19736 if (len > TASK_SIZE)
19737@@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19738 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19739 goto bottomup;
19740
19741+#ifdef CONFIG_PAX_RANDMMAP
19742+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19743+#endif
19744+
19745 /* requesting a specific address */
19746 if (addr) {
19747 addr = PAGE_ALIGN(addr);
19748- vma = find_vma(mm, addr);
19749- if (TASK_SIZE - len >= addr &&
19750- (!vma || addr + len <= vma->vm_start))
19751- return addr;
19752+ if (TASK_SIZE - len >= addr) {
19753+ vma = find_vma(mm, addr);
19754+ if (check_heap_stack_gap(vma, addr, len))
19755+ return addr;
19756+ }
19757 }
19758
19759 /* check if free_area_cache is useful for us */
19760@@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19761 /* make sure it can fit in the remaining address space */
19762 if (addr > len) {
19763 vma = find_vma(mm, addr-len);
19764- if (!vma || addr <= vma->vm_start)
19765+ if (check_heap_stack_gap(vma, addr - len, len))
19766 /* remember the address as a hint for next time */
19767 return mm->free_area_cache = addr-len;
19768 }
19769@@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19770 * return with success:
19771 */
19772 vma = find_vma(mm, addr);
19773- if (!vma || addr+len <= vma->vm_start)
19774+ if (check_heap_stack_gap(vma, addr, len))
19775 /* remember the address as a hint for next time */
19776 return mm->free_area_cache = addr;
19777
19778@@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19779 mm->cached_hole_size = vma->vm_start - addr;
19780
19781 /* try just below the current vma->vm_start */
19782- addr = vma->vm_start-len;
19783- } while (len < vma->vm_start);
19784+ addr = skip_heap_stack_gap(vma, len);
19785+ } while (!IS_ERR_VALUE(addr));
19786
19787 bottomup:
19788 /*
19789@@ -198,13 +206,21 @@ bottomup:
19790 * can happen with large stack limits and large mmap()
19791 * allocations.
19792 */
19793+ mm->mmap_base = TASK_UNMAPPED_BASE;
19794+
19795+#ifdef CONFIG_PAX_RANDMMAP
19796+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19797+ mm->mmap_base += mm->delta_mmap;
19798+#endif
19799+
19800+ mm->free_area_cache = mm->mmap_base;
19801 mm->cached_hole_size = ~0UL;
19802- mm->free_area_cache = TASK_UNMAPPED_BASE;
19803 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19804 /*
19805 * Restore the topdown base:
19806 */
19807- mm->free_area_cache = mm->mmap_base;
19808+ mm->mmap_base = base;
19809+ mm->free_area_cache = base;
19810 mm->cached_hole_size = ~0UL;
19811
19812 return addr;
19813diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
19814index 76d70a4..4c94a44 100644
19815--- a/arch/x86/kernel/syscall_table_32.S
19816+++ b/arch/x86/kernel/syscall_table_32.S
19817@@ -1,3 +1,4 @@
19818+.section .rodata,"a",@progbits
19819 ENTRY(sys_call_table)
19820 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
19821 .long sys_exit
19822diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19823index 46b8277..3349d55 100644
19824--- a/arch/x86/kernel/tboot.c
19825+++ b/arch/x86/kernel/tboot.c
19826@@ -216,7 +216,7 @@ static int tboot_setup_sleep(void)
19827
19828 void tboot_shutdown(u32 shutdown_type)
19829 {
19830- void (*shutdown)(void);
19831+ void (* __noreturn shutdown)(void);
19832
19833 if (!tboot_enabled())
19834 return;
19835@@ -238,7 +238,7 @@ void tboot_shutdown(u32 shutdown_type)
19836
19837 switch_to_tboot_pt();
19838
19839- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19840+ shutdown = (void *)tboot->shutdown_entry;
19841 shutdown();
19842
19843 /* should not reach here */
19844@@ -295,7 +295,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19845 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19846 }
19847
19848-static atomic_t ap_wfs_count;
19849+static atomic_unchecked_t ap_wfs_count;
19850
19851 static int tboot_wait_for_aps(int num_aps)
19852 {
19853@@ -319,9 +319,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19854 {
19855 switch (action) {
19856 case CPU_DYING:
19857- atomic_inc(&ap_wfs_count);
19858+ atomic_inc_unchecked(&ap_wfs_count);
19859 if (num_online_cpus() == 1)
19860- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19861+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19862 return NOTIFY_BAD;
19863 break;
19864 }
19865@@ -340,7 +340,7 @@ static __init int tboot_late_init(void)
19866
19867 tboot_create_trampoline();
19868
19869- atomic_set(&ap_wfs_count, 0);
19870+ atomic_set_unchecked(&ap_wfs_count, 0);
19871 register_hotcpu_notifier(&tboot_cpu_notifier);
19872 return 0;
19873 }
19874diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19875index be25734..87fe232 100644
19876--- a/arch/x86/kernel/time.c
19877+++ b/arch/x86/kernel/time.c
19878@@ -26,17 +26,13 @@
19879 int timer_ack;
19880 #endif
19881
19882-#ifdef CONFIG_X86_64
19883-volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
19884-#endif
19885-
19886 unsigned long profile_pc(struct pt_regs *regs)
19887 {
19888 unsigned long pc = instruction_pointer(regs);
19889
19890- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19891+ if (!user_mode(regs) && in_lock_functions(pc)) {
19892 #ifdef CONFIG_FRAME_POINTER
19893- return *(unsigned long *)(regs->bp + sizeof(long));
19894+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19895 #else
19896 unsigned long *sp =
19897 (unsigned long *)kernel_stack_pointer(regs);
19898@@ -45,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19899 * or above a saved flags. Eflags has bits 22-31 zero,
19900 * kernel addresses don't.
19901 */
19902+
19903+#ifdef CONFIG_PAX_KERNEXEC
19904+ return ktla_ktva(sp[0]);
19905+#else
19906 if (sp[0] >> 22)
19907 return sp[0];
19908 if (sp[1] >> 22)
19909 return sp[1];
19910 #endif
19911+
19912+#endif
19913 }
19914 return pc;
19915 }
19916diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19917index 6bb7b85..dd853e1 100644
19918--- a/arch/x86/kernel/tls.c
19919+++ b/arch/x86/kernel/tls.c
19920@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19921 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19922 return -EINVAL;
19923
19924+#ifdef CONFIG_PAX_SEGMEXEC
19925+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19926+ return -EINVAL;
19927+#endif
19928+
19929 set_tls_desc(p, idx, &info, 1);
19930
19931 return 0;
19932diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19933index 8508237..229b664 100644
19934--- a/arch/x86/kernel/trampoline_32.S
19935+++ b/arch/x86/kernel/trampoline_32.S
19936@@ -32,6 +32,12 @@
19937 #include <asm/segment.h>
19938 #include <asm/page_types.h>
19939
19940+#ifdef CONFIG_PAX_KERNEXEC
19941+#define ta(X) (X)
19942+#else
19943+#define ta(X) ((X) - __PAGE_OFFSET)
19944+#endif
19945+
19946 /* We can free up trampoline after bootup if cpu hotplug is not supported. */
19947 __CPUINITRODATA
19948 .code16
19949@@ -60,7 +66,7 @@ r_base = .
19950 inc %ax # protected mode (PE) bit
19951 lmsw %ax # into protected mode
19952 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19953- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19954+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
19955
19956 # These need to be in the same 64K segment as the above;
19957 # hence we don't use the boot_gdt_descr defined in head.S
19958diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19959index 3af2dff..ba8aa49 100644
19960--- a/arch/x86/kernel/trampoline_64.S
19961+++ b/arch/x86/kernel/trampoline_64.S
19962@@ -91,7 +91,7 @@ startup_32:
19963 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19964 movl %eax, %ds
19965
19966- movl $X86_CR4_PAE, %eax
19967+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19968 movl %eax, %cr4 # Enable PAE mode
19969
19970 # Setup trampoline 4 level pagetables
19971@@ -127,7 +127,7 @@ startup_64:
19972 no_longmode:
19973 hlt
19974 jmp no_longmode
19975-#include "verify_cpu_64.S"
19976+#include "verify_cpu.S"
19977
19978 # Careful these need to be in the same 64K segment as the above;
19979 tidt:
19980@@ -138,7 +138,7 @@ tidt:
19981 # so the kernel can live anywhere
19982 .balign 4
19983 tgdt:
19984- .short tgdt_end - tgdt # gdt limit
19985+ .short tgdt_end - tgdt - 1 # gdt limit
19986 .long tgdt - r_base
19987 .short 0
19988 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19989diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19990index 7e37dce..ec3f8e5 100644
19991--- a/arch/x86/kernel/traps.c
19992+++ b/arch/x86/kernel/traps.c
19993@@ -69,12 +69,6 @@ asmlinkage int system_call(void);
19994
19995 /* Do we ignore FPU interrupts ? */
19996 char ignore_fpu_irq;
19997-
19998-/*
19999- * The IDT has to be page-aligned to simplify the Pentium
20000- * F0 0F bug workaround.
20001- */
20002-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
20003 #endif
20004
20005 DECLARE_BITMAP(used_vectors, NR_VECTORS);
20006@@ -112,19 +106,19 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
20007 static inline void
20008 die_if_kernel(const char *str, struct pt_regs *regs, long err)
20009 {
20010- if (!user_mode_vm(regs))
20011+ if (!user_mode(regs))
20012 die(str, regs, err);
20013 }
20014 #endif
20015
20016 static void __kprobes
20017-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20018+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
20019 long error_code, siginfo_t *info)
20020 {
20021 struct task_struct *tsk = current;
20022
20023 #ifdef CONFIG_X86_32
20024- if (regs->flags & X86_VM_MASK) {
20025+ if (v8086_mode(regs)) {
20026 /*
20027 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
20028 * On nmi (interrupt 2), do_trap should not be called.
20029@@ -135,7 +129,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20030 }
20031 #endif
20032
20033- if (!user_mode(regs))
20034+ if (!user_mode_novm(regs))
20035 goto kernel_trap;
20036
20037 #ifdef CONFIG_X86_32
20038@@ -158,7 +152,7 @@ trap_signal:
20039 printk_ratelimit()) {
20040 printk(KERN_INFO
20041 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
20042- tsk->comm, tsk->pid, str,
20043+ tsk->comm, task_pid_nr(tsk), str,
20044 regs->ip, regs->sp, error_code);
20045 print_vma_addr(" in ", regs->ip);
20046 printk("\n");
20047@@ -175,8 +169,20 @@ kernel_trap:
20048 if (!fixup_exception(regs)) {
20049 tsk->thread.error_code = error_code;
20050 tsk->thread.trap_no = trapnr;
20051+
20052+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20053+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
20054+ str = "PAX: suspicious stack segment fault";
20055+#endif
20056+
20057 die(str, regs, error_code);
20058 }
20059+
20060+#ifdef CONFIG_PAX_REFCOUNT
20061+ if (trapnr == 4)
20062+ pax_report_refcount_overflow(regs);
20063+#endif
20064+
20065 return;
20066
20067 #ifdef CONFIG_X86_32
20068@@ -265,14 +271,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
20069 conditional_sti(regs);
20070
20071 #ifdef CONFIG_X86_32
20072- if (regs->flags & X86_VM_MASK)
20073+ if (v8086_mode(regs))
20074 goto gp_in_vm86;
20075 #endif
20076
20077 tsk = current;
20078- if (!user_mode(regs))
20079+ if (!user_mode_novm(regs))
20080 goto gp_in_kernel;
20081
20082+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20083+ if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
20084+ struct mm_struct *mm = tsk->mm;
20085+ unsigned long limit;
20086+
20087+ down_write(&mm->mmap_sem);
20088+ limit = mm->context.user_cs_limit;
20089+ if (limit < TASK_SIZE) {
20090+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
20091+ up_write(&mm->mmap_sem);
20092+ return;
20093+ }
20094+ up_write(&mm->mmap_sem);
20095+ }
20096+#endif
20097+
20098 tsk->thread.error_code = error_code;
20099 tsk->thread.trap_no = 13;
20100
20101@@ -305,6 +327,13 @@ gp_in_kernel:
20102 if (notify_die(DIE_GPF, "general protection fault", regs,
20103 error_code, 13, SIGSEGV) == NOTIFY_STOP)
20104 return;
20105+
20106+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20107+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
20108+ die("PAX: suspicious general protection fault", regs, error_code);
20109+ else
20110+#endif
20111+
20112 die("general protection fault", regs, error_code);
20113 }
20114
20115@@ -435,6 +464,17 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
20116 dotraplinkage notrace __kprobes void
20117 do_nmi(struct pt_regs *regs, long error_code)
20118 {
20119+
20120+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20121+ if (!user_mode(regs)) {
20122+ unsigned long cs = regs->cs & 0xFFFF;
20123+ unsigned long ip = ktva_ktla(regs->ip);
20124+
20125+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
20126+ regs->ip = ip;
20127+ }
20128+#endif
20129+
20130 nmi_enter();
20131
20132 inc_irq_stat(__nmi_count);
20133@@ -558,7 +598,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20134 }
20135
20136 #ifdef CONFIG_X86_32
20137- if (regs->flags & X86_VM_MASK)
20138+ if (v8086_mode(regs))
20139 goto debug_vm86;
20140 #endif
20141
20142@@ -570,7 +610,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20143 * kernel space (but re-enable TF when returning to user mode).
20144 */
20145 if (condition & DR_STEP) {
20146- if (!user_mode(regs))
20147+ if (!user_mode_novm(regs))
20148 goto clear_TF_reenable;
20149 }
20150
20151@@ -757,7 +797,7 @@ do_simd_coprocessor_error(struct pt_regs *regs, long error_code)
20152 * Handle strange cache flush from user space exception
20153 * in all other cases. This is undocumented behaviour.
20154 */
20155- if (regs->flags & X86_VM_MASK) {
20156+ if (v8086_mode(regs)) {
20157 handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
20158 return;
20159 }
20160@@ -798,7 +838,7 @@ asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
20161 void __math_state_restore(void)
20162 {
20163 struct thread_info *thread = current_thread_info();
20164- struct task_struct *tsk = thread->task;
20165+ struct task_struct *tsk = current;
20166
20167 /*
20168 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
20169@@ -825,8 +865,7 @@ void __math_state_restore(void)
20170 */
20171 asmlinkage void math_state_restore(void)
20172 {
20173- struct thread_info *thread = current_thread_info();
20174- struct task_struct *tsk = thread->task;
20175+ struct task_struct *tsk = current;
20176
20177 if (!tsk_used_math(tsk)) {
20178 local_irq_enable();
20179diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
20180new file mode 100644
20181index 0000000..50c5edd
20182--- /dev/null
20183+++ b/arch/x86/kernel/verify_cpu.S
20184@@ -0,0 +1,140 @@
20185+/*
20186+ *
20187+ * verify_cpu.S - Code for cpu long mode and SSE verification. This
20188+ * code has been borrowed from boot/setup.S and was introduced by
20189+ * Andi Kleen.
20190+ *
20191+ * Copyright (c) 2007 Andi Kleen (ak@suse.de)
20192+ * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
20193+ * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
20194+ * Copyright (c) 2010 Kees Cook (kees.cook@canonical.com)
20195+ *
20196+ * This source code is licensed under the GNU General Public License,
20197+ * Version 2. See the file COPYING for more details.
20198+ *
20199+ * This is a common code for verification whether CPU supports
20200+ * long mode and SSE or not. It is not called directly instead this
20201+ * file is included at various places and compiled in that context.
20202+ * This file is expected to run in 32bit code. Currently:
20203+ *
20204+ * arch/x86/boot/compressed/head_64.S: Boot cpu verification
20205+ * arch/x86/kernel/trampoline_64.S: secondary processor verification
20206+ * arch/x86/kernel/head_32.S: processor startup
20207+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
20208+ *
20209+ * verify_cpu, returns the status of longmode and SSE in register %eax.
20210+ * 0: Success 1: Failure
20211+ *
20212+ * On Intel, the XD_DISABLE flag will be cleared as a side-effect.
20213+ *
20214+ * The caller needs to check for the error code and take the action
20215+ * appropriately. Either display a message or halt.
20216+ */
20217+
20218+#include <asm/cpufeature.h>
20219+#include <asm/msr-index.h>
20220+
20221+verify_cpu:
20222+ pushfl # Save caller passed flags
20223+ pushl $0 # Kill any dangerous flags
20224+ popfl
20225+
20226+ pushfl # standard way to check for cpuid
20227+ popl %eax
20228+ movl %eax,%ebx
20229+ xorl $0x200000,%eax
20230+ pushl %eax
20231+ popfl
20232+ pushfl
20233+ popl %eax
20234+ cmpl %eax,%ebx
20235+ jz verify_cpu_no_longmode # cpu has no cpuid
20236+
20237+ movl $0x0,%eax # See if cpuid 1 is implemented
20238+ cpuid
20239+ cmpl $0x1,%eax
20240+ jb verify_cpu_no_longmode # no cpuid 1
20241+
20242+ xor %di,%di
20243+ cmpl $0x68747541,%ebx # AuthenticAMD
20244+ jnz verify_cpu_noamd
20245+ cmpl $0x69746e65,%edx
20246+ jnz verify_cpu_noamd
20247+ cmpl $0x444d4163,%ecx
20248+ jnz verify_cpu_noamd
20249+ mov $1,%di # cpu is from AMD
20250+ jmp verify_cpu_check
20251+
20252+verify_cpu_noamd:
20253+ cmpl $0x756e6547,%ebx # GenuineIntel?
20254+ jnz verify_cpu_check
20255+ cmpl $0x49656e69,%edx
20256+ jnz verify_cpu_check
20257+ cmpl $0x6c65746e,%ecx
20258+ jnz verify_cpu_check
20259+
20260+ # only call IA32_MISC_ENABLE when:
20261+ # family > 6 || (family == 6 && model >= 0xd)
20262+ movl $0x1, %eax # check CPU family and model
20263+ cpuid
20264+ movl %eax, %ecx
20265+
20266+ andl $0x0ff00f00, %eax # mask family and extended family
20267+ shrl $8, %eax
20268+ cmpl $6, %eax
20269+ ja verify_cpu_clear_xd # family > 6, ok
20270+ jb verify_cpu_check # family < 6, skip
20271+
20272+ andl $0x000f00f0, %ecx # mask model and extended model
20273+ shrl $4, %ecx
20274+ cmpl $0xd, %ecx
20275+ jb verify_cpu_check # family == 6, model < 0xd, skip
20276+
20277+verify_cpu_clear_xd:
20278+ movl $MSR_IA32_MISC_ENABLE, %ecx
20279+ rdmsr
20280+ btrl $2, %edx # clear MSR_IA32_MISC_ENABLE_XD_DISABLE
20281+ jnc verify_cpu_check # only write MSR if bit was changed
20282+ wrmsr
20283+
20284+verify_cpu_check:
20285+ movl $0x1,%eax # Does the cpu have what it takes
20286+ cpuid
20287+ andl $REQUIRED_MASK0,%edx
20288+ xorl $REQUIRED_MASK0,%edx
20289+ jnz verify_cpu_no_longmode
20290+
20291+ movl $0x80000000,%eax # See if extended cpuid is implemented
20292+ cpuid
20293+ cmpl $0x80000001,%eax
20294+ jb verify_cpu_no_longmode # no extended cpuid
20295+
20296+ movl $0x80000001,%eax # Does the cpu have what it takes
20297+ cpuid
20298+ andl $REQUIRED_MASK1,%edx
20299+ xorl $REQUIRED_MASK1,%edx
20300+ jnz verify_cpu_no_longmode
20301+
20302+verify_cpu_sse_test:
20303+ movl $1,%eax
20304+ cpuid
20305+ andl $SSE_MASK,%edx
20306+ cmpl $SSE_MASK,%edx
20307+ je verify_cpu_sse_ok
20308+ test %di,%di
20309+ jz verify_cpu_no_longmode # only try to force SSE on AMD
20310+ movl $MSR_K7_HWCR,%ecx
20311+ rdmsr
20312+ btr $15,%eax # enable SSE
20313+ wrmsr
20314+ xor %di,%di # don't loop
20315+ jmp verify_cpu_sse_test # try again
20316+
20317+verify_cpu_no_longmode:
20318+ popfl # Restore caller passed flags
20319+ movl $1,%eax
20320+ ret
20321+verify_cpu_sse_ok:
20322+ popfl # Restore caller passed flags
20323+ xorl %eax, %eax
20324+ ret
20325diff --git a/arch/x86/kernel/verify_cpu_64.S b/arch/x86/kernel/verify_cpu_64.S
20326deleted file mode 100644
20327index 45b6f8a..0000000
20328--- a/arch/x86/kernel/verify_cpu_64.S
20329+++ /dev/null
20330@@ -1,105 +0,0 @@
20331-/*
20332- *
20333- * verify_cpu.S - Code for cpu long mode and SSE verification. This
20334- * code has been borrowed from boot/setup.S and was introduced by
20335- * Andi Kleen.
20336- *
20337- * Copyright (c) 2007 Andi Kleen (ak@suse.de)
20338- * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
20339- * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
20340- *
20341- * This source code is licensed under the GNU General Public License,
20342- * Version 2. See the file COPYING for more details.
20343- *
20344- * This is a common code for verification whether CPU supports
20345- * long mode and SSE or not. It is not called directly instead this
20346- * file is included at various places and compiled in that context.
20347- * Following are the current usage.
20348- *
20349- * This file is included by both 16bit and 32bit code.
20350- *
20351- * arch/x86_64/boot/setup.S : Boot cpu verification (16bit)
20352- * arch/x86_64/boot/compressed/head.S: Boot cpu verification (32bit)
20353- * arch/x86_64/kernel/trampoline.S: secondary processor verfication (16bit)
20354- * arch/x86_64/kernel/acpi/wakeup.S:Verfication at resume (16bit)
20355- *
20356- * verify_cpu, returns the status of cpu check in register %eax.
20357- * 0: Success 1: Failure
20358- *
20359- * The caller needs to check for the error code and take the action
20360- * appropriately. Either display a message or halt.
20361- */
20362-
20363-#include <asm/cpufeature.h>
20364-
20365-verify_cpu:
20366- pushfl # Save caller passed flags
20367- pushl $0 # Kill any dangerous flags
20368- popfl
20369-
20370- pushfl # standard way to check for cpuid
20371- popl %eax
20372- movl %eax,%ebx
20373- xorl $0x200000,%eax
20374- pushl %eax
20375- popfl
20376- pushfl
20377- popl %eax
20378- cmpl %eax,%ebx
20379- jz verify_cpu_no_longmode # cpu has no cpuid
20380-
20381- movl $0x0,%eax # See if cpuid 1 is implemented
20382- cpuid
20383- cmpl $0x1,%eax
20384- jb verify_cpu_no_longmode # no cpuid 1
20385-
20386- xor %di,%di
20387- cmpl $0x68747541,%ebx # AuthenticAMD
20388- jnz verify_cpu_noamd
20389- cmpl $0x69746e65,%edx
20390- jnz verify_cpu_noamd
20391- cmpl $0x444d4163,%ecx
20392- jnz verify_cpu_noamd
20393- mov $1,%di # cpu is from AMD
20394-
20395-verify_cpu_noamd:
20396- movl $0x1,%eax # Does the cpu have what it takes
20397- cpuid
20398- andl $REQUIRED_MASK0,%edx
20399- xorl $REQUIRED_MASK0,%edx
20400- jnz verify_cpu_no_longmode
20401-
20402- movl $0x80000000,%eax # See if extended cpuid is implemented
20403- cpuid
20404- cmpl $0x80000001,%eax
20405- jb verify_cpu_no_longmode # no extended cpuid
20406-
20407- movl $0x80000001,%eax # Does the cpu have what it takes
20408- cpuid
20409- andl $REQUIRED_MASK1,%edx
20410- xorl $REQUIRED_MASK1,%edx
20411- jnz verify_cpu_no_longmode
20412-
20413-verify_cpu_sse_test:
20414- movl $1,%eax
20415- cpuid
20416- andl $SSE_MASK,%edx
20417- cmpl $SSE_MASK,%edx
20418- je verify_cpu_sse_ok
20419- test %di,%di
20420- jz verify_cpu_no_longmode # only try to force SSE on AMD
20421- movl $0xc0010015,%ecx # HWCR
20422- rdmsr
20423- btr $15,%eax # enable SSE
20424- wrmsr
20425- xor %di,%di # don't loop
20426- jmp verify_cpu_sse_test # try again
20427-
20428-verify_cpu_no_longmode:
20429- popfl # Restore caller passed flags
20430- movl $1,%eax
20431- ret
20432-verify_cpu_sse_ok:
20433- popfl # Restore caller passed flags
20434- xorl %eax, %eax
20435- ret
20436diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
20437index 9c4e625..c992817 100644
20438--- a/arch/x86/kernel/vm86_32.c
20439+++ b/arch/x86/kernel/vm86_32.c
20440@@ -41,6 +41,7 @@
20441 #include <linux/ptrace.h>
20442 #include <linux/audit.h>
20443 #include <linux/stddef.h>
20444+#include <linux/grsecurity.h>
20445
20446 #include <asm/uaccess.h>
20447 #include <asm/io.h>
20448@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20449 do_exit(SIGSEGV);
20450 }
20451
20452- tss = &per_cpu(init_tss, get_cpu());
20453+ tss = init_tss + get_cpu();
20454 current->thread.sp0 = current->thread.saved_sp0;
20455 current->thread.sysenter_cs = __KERNEL_CS;
20456 load_sp0(tss, &current->thread);
20457@@ -208,6 +209,13 @@ int sys_vm86old(struct pt_regs *regs)
20458 struct task_struct *tsk;
20459 int tmp, ret = -EPERM;
20460
20461+#ifdef CONFIG_GRKERNSEC_VM86
20462+ if (!capable(CAP_SYS_RAWIO)) {
20463+ gr_handle_vm86();
20464+ goto out;
20465+ }
20466+#endif
20467+
20468 tsk = current;
20469 if (tsk->thread.saved_sp0)
20470 goto out;
20471@@ -238,6 +246,14 @@ int sys_vm86(struct pt_regs *regs)
20472 int tmp, ret;
20473 struct vm86plus_struct __user *v86;
20474
20475+#ifdef CONFIG_GRKERNSEC_VM86
20476+ if (!capable(CAP_SYS_RAWIO)) {
20477+ gr_handle_vm86();
20478+ ret = -EPERM;
20479+ goto out;
20480+ }
20481+#endif
20482+
20483 tsk = current;
20484 switch (regs->bx) {
20485 case VM86_REQUEST_IRQ:
20486@@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20487 tsk->thread.saved_fs = info->regs32->fs;
20488 tsk->thread.saved_gs = get_user_gs(info->regs32);
20489
20490- tss = &per_cpu(init_tss, get_cpu());
20491+ tss = init_tss + get_cpu();
20492 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20493 if (cpu_has_sep)
20494 tsk->thread.sysenter_cs = 0;
20495@@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20496 goto cannot_handle;
20497 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20498 goto cannot_handle;
20499- intr_ptr = (unsigned long __user *) (i << 2);
20500+ intr_ptr = (__force unsigned long __user *) (i << 2);
20501 if (get_user(segoffs, intr_ptr))
20502 goto cannot_handle;
20503 if ((segoffs >> 16) == BIOSSEG)
20504diff --git a/arch/x86/kernel/vmi_32.c b/arch/x86/kernel/vmi_32.c
20505index d430e4c..831f817 100644
20506--- a/arch/x86/kernel/vmi_32.c
20507+++ b/arch/x86/kernel/vmi_32.c
20508@@ -44,12 +44,17 @@ typedef u32 __attribute__((regparm(1))) (VROMFUNC)(void);
20509 typedef u64 __attribute__((regparm(2))) (VROMLONGFUNC)(int);
20510
20511 #define call_vrom_func(rom,func) \
20512- (((VROMFUNC *)(rom->func))())
20513+ (((VROMFUNC *)(ktva_ktla(rom.func)))())
20514
20515 #define call_vrom_long_func(rom,func,arg) \
20516- (((VROMLONGFUNC *)(rom->func)) (arg))
20517+({\
20518+ u64 __reloc = ((VROMLONGFUNC *)(ktva_ktla(rom.func))) (arg);\
20519+ struct vmi_relocation_info *const __rel = (struct vmi_relocation_info *)&__reloc;\
20520+ __rel->eip = (unsigned char *)ktva_ktla((unsigned long)__rel->eip);\
20521+ __reloc;\
20522+})
20523
20524-static struct vrom_header *vmi_rom;
20525+static struct vrom_header vmi_rom __attribute((__section__(".vmi.rom"), __aligned__(PAGE_SIZE)));
20526 static int disable_pge;
20527 static int disable_pse;
20528 static int disable_sep;
20529@@ -76,10 +81,10 @@ static struct {
20530 void (*set_initial_ap_state)(int, int);
20531 void (*halt)(void);
20532 void (*set_lazy_mode)(int mode);
20533-} vmi_ops;
20534+} __no_const vmi_ops __read_only;
20535
20536 /* Cached VMI operations */
20537-struct vmi_timer_ops vmi_timer_ops;
20538+struct vmi_timer_ops vmi_timer_ops __read_only;
20539
20540 /*
20541 * VMI patching routines.
20542@@ -94,7 +99,7 @@ struct vmi_timer_ops vmi_timer_ops;
20543 static inline void patch_offset(void *insnbuf,
20544 unsigned long ip, unsigned long dest)
20545 {
20546- *(unsigned long *)(insnbuf+1) = dest-ip-5;
20547+ *(unsigned long *)(insnbuf+1) = dest-ip-5;
20548 }
20549
20550 static unsigned patch_internal(int call, unsigned len, void *insnbuf,
20551@@ -102,6 +107,7 @@ static unsigned patch_internal(int call, unsigned len, void *insnbuf,
20552 {
20553 u64 reloc;
20554 struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
20555+
20556 reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
20557 switch(rel->type) {
20558 case VMI_RELOCATION_CALL_REL:
20559@@ -404,13 +410,13 @@ static void vmi_set_pud(pud_t *pudp, pud_t pudval)
20560
20561 static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
20562 {
20563- const pte_t pte = { .pte = 0 };
20564+ const pte_t pte = __pte(0ULL);
20565 vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
20566 }
20567
20568 static void vmi_pmd_clear(pmd_t *pmd)
20569 {
20570- const pte_t pte = { .pte = 0 };
20571+ const pte_t pte = __pte(0ULL);
20572 vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
20573 }
20574 #endif
20575@@ -438,10 +444,10 @@ vmi_startup_ipi_hook(int phys_apicid, unsigned long start_eip,
20576 ap.ss = __KERNEL_DS;
20577 ap.esp = (unsigned long) start_esp;
20578
20579- ap.ds = __USER_DS;
20580- ap.es = __USER_DS;
20581+ ap.ds = __KERNEL_DS;
20582+ ap.es = __KERNEL_DS;
20583 ap.fs = __KERNEL_PERCPU;
20584- ap.gs = __KERNEL_STACK_CANARY;
20585+ savesegment(gs, ap.gs);
20586
20587 ap.eflags = 0;
20588
20589@@ -486,6 +492,18 @@ static void vmi_leave_lazy_mmu(void)
20590 paravirt_leave_lazy_mmu();
20591 }
20592
20593+#ifdef CONFIG_PAX_KERNEXEC
20594+static unsigned long vmi_pax_open_kernel(void)
20595+{
20596+ return 0;
20597+}
20598+
20599+static unsigned long vmi_pax_close_kernel(void)
20600+{
20601+ return 0;
20602+}
20603+#endif
20604+
20605 static inline int __init check_vmi_rom(struct vrom_header *rom)
20606 {
20607 struct pci_header *pci;
20608@@ -498,6 +516,10 @@ static inline int __init check_vmi_rom(struct vrom_header *rom)
20609 return 0;
20610 if (rom->vrom_signature != VMI_SIGNATURE)
20611 return 0;
20612+ if (rom->rom_length * 512 > sizeof(*rom)) {
20613+ printk(KERN_WARNING "PAX: VMI: ROM size too big: %x\n", rom->rom_length * 512);
20614+ return 0;
20615+ }
20616 if (rom->api_version_maj != VMI_API_REV_MAJOR ||
20617 rom->api_version_min+1 < VMI_API_REV_MINOR+1) {
20618 printk(KERN_WARNING "VMI: Found mismatched rom version %d.%d\n",
20619@@ -562,7 +584,7 @@ static inline int __init probe_vmi_rom(void)
20620 struct vrom_header *romstart;
20621 romstart = (struct vrom_header *)isa_bus_to_virt(base);
20622 if (check_vmi_rom(romstart)) {
20623- vmi_rom = romstart;
20624+ vmi_rom = *romstart;
20625 return 1;
20626 }
20627 }
20628@@ -836,6 +858,11 @@ static inline int __init activate_vmi(void)
20629
20630 para_fill(pv_irq_ops.safe_halt, Halt);
20631
20632+#ifdef CONFIG_PAX_KERNEXEC
20633+ pv_mmu_ops.pax_open_kernel = vmi_pax_open_kernel;
20634+ pv_mmu_ops.pax_close_kernel = vmi_pax_close_kernel;
20635+#endif
20636+
20637 /*
20638 * Alternative instruction rewriting doesn't happen soon enough
20639 * to convert VMI_IRET to a call instead of a jump; so we have
20640@@ -853,16 +880,16 @@ static inline int __init activate_vmi(void)
20641
20642 void __init vmi_init(void)
20643 {
20644- if (!vmi_rom)
20645+ if (!vmi_rom.rom_signature)
20646 probe_vmi_rom();
20647 else
20648- check_vmi_rom(vmi_rom);
20649+ check_vmi_rom(&vmi_rom);
20650
20651 /* In case probing for or validating the ROM failed, basil */
20652- if (!vmi_rom)
20653+ if (!vmi_rom.rom_signature)
20654 return;
20655
20656- reserve_top_address(-vmi_rom->virtual_top);
20657+ reserve_top_address(-vmi_rom.virtual_top);
20658
20659 #ifdef CONFIG_X86_IO_APIC
20660 /* This is virtual hardware; timer routing is wired correctly */
20661@@ -874,7 +901,7 @@ void __init vmi_activate(void)
20662 {
20663 unsigned long flags;
20664
20665- if (!vmi_rom)
20666+ if (!vmi_rom.rom_signature)
20667 return;
20668
20669 local_irq_save(flags);
20670diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20671index 3c68fe2..12c8280 100644
20672--- a/arch/x86/kernel/vmlinux.lds.S
20673+++ b/arch/x86/kernel/vmlinux.lds.S
20674@@ -26,6 +26,13 @@
20675 #include <asm/page_types.h>
20676 #include <asm/cache.h>
20677 #include <asm/boot.h>
20678+#include <asm/segment.h>
20679+
20680+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20681+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20682+#else
20683+#define __KERNEL_TEXT_OFFSET 0
20684+#endif
20685
20686 #undef i386 /* in case the preprocessor is a 32bit one */
20687
20688@@ -34,40 +41,53 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT)
20689 #ifdef CONFIG_X86_32
20690 OUTPUT_ARCH(i386)
20691 ENTRY(phys_startup_32)
20692-jiffies = jiffies_64;
20693 #else
20694 OUTPUT_ARCH(i386:x86-64)
20695 ENTRY(phys_startup_64)
20696-jiffies_64 = jiffies;
20697 #endif
20698
20699 PHDRS {
20700 text PT_LOAD FLAGS(5); /* R_E */
20701- data PT_LOAD FLAGS(7); /* RWE */
20702+#ifdef CONFIG_X86_32
20703+ module PT_LOAD FLAGS(5); /* R_E */
20704+#endif
20705+#ifdef CONFIG_XEN
20706+ rodata PT_LOAD FLAGS(5); /* R_E */
20707+#else
20708+ rodata PT_LOAD FLAGS(4); /* R__ */
20709+#endif
20710+ data PT_LOAD FLAGS(6); /* RW_ */
20711 #ifdef CONFIG_X86_64
20712 user PT_LOAD FLAGS(5); /* R_E */
20713+#endif
20714+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20715 #ifdef CONFIG_SMP
20716 percpu PT_LOAD FLAGS(6); /* RW_ */
20717 #endif
20718+ text.init PT_LOAD FLAGS(5); /* R_E */
20719+ text.exit PT_LOAD FLAGS(5); /* R_E */
20720 init PT_LOAD FLAGS(7); /* RWE */
20721-#endif
20722 note PT_NOTE FLAGS(0); /* ___ */
20723 }
20724
20725 SECTIONS
20726 {
20727 #ifdef CONFIG_X86_32
20728- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20729- phys_startup_32 = startup_32 - LOAD_OFFSET;
20730+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20731 #else
20732- . = __START_KERNEL;
20733- phys_startup_64 = startup_64 - LOAD_OFFSET;
20734+ . = __START_KERNEL;
20735 #endif
20736
20737 /* Text and read-only data */
20738- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20739- _text = .;
20740+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20741 /* bootstrapping code */
20742+#ifdef CONFIG_X86_32
20743+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20744+#else
20745+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20746+#endif
20747+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20748+ _text = .;
20749 HEAD_TEXT
20750 #ifdef CONFIG_X86_32
20751 . = ALIGN(PAGE_SIZE);
20752@@ -82,28 +102,71 @@ SECTIONS
20753 IRQENTRY_TEXT
20754 *(.fixup)
20755 *(.gnu.warning)
20756- /* End of text section */
20757- _etext = .;
20758 } :text = 0x9090
20759
20760- NOTES :text :note
20761+ . += __KERNEL_TEXT_OFFSET;
20762
20763- EXCEPTION_TABLE(16) :text = 0x9090
20764+#ifdef CONFIG_X86_32
20765+ . = ALIGN(PAGE_SIZE);
20766+ .vmi.rom : AT(ADDR(.vmi.rom) - LOAD_OFFSET) {
20767+ *(.vmi.rom)
20768+ } :module
20769+
20770+ . = ALIGN(PAGE_SIZE);
20771+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20772+
20773+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20774+ MODULES_EXEC_VADDR = .;
20775+ BYTE(0)
20776+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20777+ . = ALIGN(HPAGE_SIZE);
20778+ MODULES_EXEC_END = . - 1;
20779+#endif
20780+
20781+ } :module
20782+#endif
20783+
20784+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20785+ /* End of text section */
20786+ _etext = . - __KERNEL_TEXT_OFFSET;
20787+ }
20788+
20789+#ifdef CONFIG_X86_32
20790+ . = ALIGN(PAGE_SIZE);
20791+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20792+ *(.idt)
20793+ . = ALIGN(PAGE_SIZE);
20794+ *(.empty_zero_page)
20795+ *(.swapper_pg_fixmap)
20796+ *(.swapper_pg_pmd)
20797+ *(.swapper_pg_dir)
20798+ *(.trampoline_pg_dir)
20799+ } :rodata
20800+#endif
20801+
20802+ . = ALIGN(PAGE_SIZE);
20803+ NOTES :rodata :note
20804+
20805+ EXCEPTION_TABLE(16) :rodata
20806
20807 RO_DATA(PAGE_SIZE)
20808
20809 /* Data */
20810 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20811+
20812+#ifdef CONFIG_PAX_KERNEXEC
20813+ . = ALIGN(HPAGE_SIZE);
20814+#else
20815+ . = ALIGN(PAGE_SIZE);
20816+#endif
20817+
20818 /* Start of data section */
20819 _sdata = .;
20820
20821 /* init_task */
20822 INIT_TASK_DATA(THREAD_SIZE)
20823
20824-#ifdef CONFIG_X86_32
20825- /* 32 bit has nosave before _edata */
20826 NOSAVE_DATA
20827-#endif
20828
20829 PAGE_ALIGNED_DATA(PAGE_SIZE)
20830
20831@@ -112,6 +175,8 @@ SECTIONS
20832 DATA_DATA
20833 CONSTRUCTORS
20834
20835+ jiffies = jiffies_64;
20836+
20837 /* rarely changed data like cpu maps */
20838 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
20839
20840@@ -166,12 +231,6 @@ SECTIONS
20841 }
20842 vgetcpu_mode = VVIRT(.vgetcpu_mode);
20843
20844- . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
20845- .jiffies : AT(VLOAD(.jiffies)) {
20846- *(.jiffies)
20847- }
20848- jiffies = VVIRT(.jiffies);
20849-
20850 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
20851 *(.vsyscall_3)
20852 }
20853@@ -187,12 +246,19 @@ SECTIONS
20854 #endif /* CONFIG_X86_64 */
20855
20856 /* Init code and data - will be freed after init */
20857- . = ALIGN(PAGE_SIZE);
20858 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20859+ BYTE(0)
20860+
20861+#ifdef CONFIG_PAX_KERNEXEC
20862+ . = ALIGN(HPAGE_SIZE);
20863+#else
20864+ . = ALIGN(PAGE_SIZE);
20865+#endif
20866+
20867 __init_begin = .; /* paired with __init_end */
20868- }
20869+ } :init.begin
20870
20871-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20872+#ifdef CONFIG_SMP
20873 /*
20874 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20875 * output PHDR, so the next output section - .init.text - should
20876@@ -201,12 +267,27 @@ SECTIONS
20877 PERCPU_VADDR(0, :percpu)
20878 #endif
20879
20880- INIT_TEXT_SECTION(PAGE_SIZE)
20881-#ifdef CONFIG_X86_64
20882- :init
20883-#endif
20884+ . = ALIGN(PAGE_SIZE);
20885+ init_begin = .;
20886+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20887+ VMLINUX_SYMBOL(_sinittext) = .;
20888+ INIT_TEXT
20889+ VMLINUX_SYMBOL(_einittext) = .;
20890+ . = ALIGN(PAGE_SIZE);
20891+ } :text.init
20892
20893- INIT_DATA_SECTION(16)
20894+ /*
20895+ * .exit.text is discard at runtime, not link time, to deal with
20896+ * references from .altinstructions and .eh_frame
20897+ */
20898+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20899+ EXIT_TEXT
20900+ . = ALIGN(16);
20901+ } :text.exit
20902+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20903+
20904+ . = ALIGN(PAGE_SIZE);
20905+ INIT_DATA_SECTION(16) :init
20906
20907 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20908 __x86_cpu_dev_start = .;
20909@@ -232,19 +313,11 @@ SECTIONS
20910 *(.altinstr_replacement)
20911 }
20912
20913- /*
20914- * .exit.text is discard at runtime, not link time, to deal with
20915- * references from .altinstructions and .eh_frame
20916- */
20917- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20918- EXIT_TEXT
20919- }
20920-
20921 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20922 EXIT_DATA
20923 }
20924
20925-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20926+#ifndef CONFIG_SMP
20927 PERCPU(PAGE_SIZE)
20928 #endif
20929
20930@@ -267,12 +340,6 @@ SECTIONS
20931 . = ALIGN(PAGE_SIZE);
20932 }
20933
20934-#ifdef CONFIG_X86_64
20935- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20936- NOSAVE_DATA
20937- }
20938-#endif
20939-
20940 /* BSS */
20941 . = ALIGN(PAGE_SIZE);
20942 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20943@@ -288,6 +355,7 @@ SECTIONS
20944 __brk_base = .;
20945 . += 64 * 1024; /* 64k alignment slop space */
20946 *(.brk_reservation) /* areas brk users have reserved */
20947+ . = ALIGN(HPAGE_SIZE);
20948 __brk_limit = .;
20949 }
20950
20951@@ -316,13 +384,12 @@ SECTIONS
20952 * for the boot processor.
20953 */
20954 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
20955-INIT_PER_CPU(gdt_page);
20956 INIT_PER_CPU(irq_stack_union);
20957
20958 /*
20959 * Build-time check on the image size:
20960 */
20961-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20962+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20963 "kernel image bigger than KERNEL_IMAGE_SIZE");
20964
20965 #ifdef CONFIG_SMP
20966diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20967index 62f39d7..3bc46a1 100644
20968--- a/arch/x86/kernel/vsyscall_64.c
20969+++ b/arch/x86/kernel/vsyscall_64.c
20970@@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wall_time, struct clocksource *clock,
20971
20972 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
20973 /* copy vsyscall data */
20974+ strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
20975 vsyscall_gtod_data.clock.vread = clock->vread;
20976 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
20977 vsyscall_gtod_data.clock.mask = clock->mask;
20978@@ -203,7 +204,7 @@ vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache)
20979 We do this here because otherwise user space would do it on
20980 its own in a likely inferior way (no access to jiffies).
20981 If you don't like it pass NULL. */
20982- if (tcache && tcache->blob[0] == (j = __jiffies)) {
20983+ if (tcache && tcache->blob[0] == (j = jiffies)) {
20984 p = tcache->blob[1];
20985 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
20986 /* Load per CPU data from RDTSCP */
20987diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20988index 3909e3b..5433a97 100644
20989--- a/arch/x86/kernel/x8664_ksyms_64.c
20990+++ b/arch/x86/kernel/x8664_ksyms_64.c
20991@@ -30,8 +30,6 @@ EXPORT_SYMBOL(__put_user_8);
20992
20993 EXPORT_SYMBOL(copy_user_generic);
20994 EXPORT_SYMBOL(__copy_user_nocache);
20995-EXPORT_SYMBOL(copy_from_user);
20996-EXPORT_SYMBOL(copy_to_user);
20997 EXPORT_SYMBOL(__copy_from_user_inatomic);
20998
20999 EXPORT_SYMBOL(copy_page);
21000diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21001index c5ee17e..d63218f 100644
21002--- a/arch/x86/kernel/xsave.c
21003+++ b/arch/x86/kernel/xsave.c
21004@@ -54,7 +54,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
21005 fx_sw_user->xstate_size > fx_sw_user->extended_size)
21006 return -1;
21007
21008- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
21009+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
21010 fx_sw_user->extended_size -
21011 FP_XSTATE_MAGIC2_SIZE));
21012 /*
21013@@ -196,7 +196,7 @@ fx_only:
21014 * the other extended state.
21015 */
21016 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
21017- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
21018+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
21019 }
21020
21021 /*
21022@@ -228,7 +228,7 @@ int restore_i387_xstate(void __user *buf)
21023 if (task_thread_info(tsk)->status & TS_XSAVE)
21024 err = restore_user_xstate(buf);
21025 else
21026- err = fxrstor_checking((__force struct i387_fxsave_struct *)
21027+ err = fxrstor_checking((struct i387_fxsave_struct __user *)
21028 buf);
21029 if (unlikely(err)) {
21030 /*
21031diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21032index 1350e43..a94b011 100644
21033--- a/arch/x86/kvm/emulate.c
21034+++ b/arch/x86/kvm/emulate.c
21035@@ -81,8 +81,8 @@
21036 #define Src2CL (1<<29)
21037 #define Src2ImmByte (2<<29)
21038 #define Src2One (3<<29)
21039-#define Src2Imm16 (4<<29)
21040-#define Src2Mask (7<<29)
21041+#define Src2Imm16 (4U<<29)
21042+#define Src2Mask (7U<<29)
21043
21044 enum {
21045 Group1_80, Group1_81, Group1_82, Group1_83,
21046@@ -411,6 +411,7 @@ static u32 group2_table[] = {
21047
21048 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix) \
21049 do { \
21050+ unsigned long _tmp; \
21051 __asm__ __volatile__ ( \
21052 _PRE_EFLAGS("0", "4", "2") \
21053 _op _suffix " %"_x"3,%1; " \
21054@@ -424,8 +425,6 @@ static u32 group2_table[] = {
21055 /* Raw emulation: instruction has two explicit operands. */
21056 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
21057 do { \
21058- unsigned long _tmp; \
21059- \
21060 switch ((_dst).bytes) { \
21061 case 2: \
21062 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w"); \
21063@@ -441,7 +440,6 @@ static u32 group2_table[] = {
21064
21065 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21066 do { \
21067- unsigned long _tmp; \
21068 switch ((_dst).bytes) { \
21069 case 1: \
21070 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b"); \
21071diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21072index 8dfeaaa..4daa395 100644
21073--- a/arch/x86/kvm/lapic.c
21074+++ b/arch/x86/kvm/lapic.c
21075@@ -52,7 +52,7 @@
21076 #define APIC_BUS_CYCLE_NS 1
21077
21078 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21079-#define apic_debug(fmt, arg...)
21080+#define apic_debug(fmt, arg...) do {} while (0)
21081
21082 #define APIC_LVT_NUM 6
21083 /* 14 is the version for Xeon and Pentium 8.4.8*/
21084diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21085index 3bc2707..dd157e2 100644
21086--- a/arch/x86/kvm/paging_tmpl.h
21087+++ b/arch/x86/kvm/paging_tmpl.h
21088@@ -416,6 +416,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
21089 int level = PT_PAGE_TABLE_LEVEL;
21090 unsigned long mmu_seq;
21091
21092+ pax_track_stack();
21093+
21094 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
21095 kvm_mmu_audit(vcpu, "pre page fault");
21096
21097@@ -461,6 +463,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
21098 kvm_mmu_free_some_pages(vcpu);
21099 sptep = FNAME(fetch)(vcpu, addr, &walker, user_fault, write_fault,
21100 level, &write_pt, pfn);
21101+ (void)sptep;
21102 pgprintk("%s: shadow pte %p %llx ptwrite %d\n", __func__,
21103 sptep, *sptep, write_pt);
21104
21105diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21106index 7c6e63e..c5d92c1 100644
21107--- a/arch/x86/kvm/svm.c
21108+++ b/arch/x86/kvm/svm.c
21109@@ -2486,7 +2486,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21110 int cpu = raw_smp_processor_id();
21111
21112 struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
21113+
21114+ pax_open_kernel();
21115 svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
21116+ pax_close_kernel();
21117+
21118 load_TR_desc();
21119 }
21120
21121@@ -2947,7 +2951,7 @@ static bool svm_gb_page_enable(void)
21122 return true;
21123 }
21124
21125-static struct kvm_x86_ops svm_x86_ops = {
21126+static const struct kvm_x86_ops svm_x86_ops = {
21127 .cpu_has_kvm_support = has_svm,
21128 .disabled_by_bios = is_disabled,
21129 .hardware_setup = svm_hardware_setup,
21130diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21131index e6d925f..e7a4af8 100644
21132--- a/arch/x86/kvm/vmx.c
21133+++ b/arch/x86/kvm/vmx.c
21134@@ -570,7 +570,11 @@ static void reload_tss(void)
21135
21136 kvm_get_gdt(&gdt);
21137 descs = (void *)gdt.base;
21138+
21139+ pax_open_kernel();
21140 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21141+ pax_close_kernel();
21142+
21143 load_TR_desc();
21144 }
21145
21146@@ -1410,8 +1414,11 @@ static __init int hardware_setup(void)
21147 if (!cpu_has_vmx_flexpriority())
21148 flexpriority_enabled = 0;
21149
21150- if (!cpu_has_vmx_tpr_shadow())
21151- kvm_x86_ops->update_cr8_intercept = NULL;
21152+ if (!cpu_has_vmx_tpr_shadow()) {
21153+ pax_open_kernel();
21154+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21155+ pax_close_kernel();
21156+ }
21157
21158 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21159 kvm_disable_largepages();
21160@@ -2362,7 +2369,7 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
21161 vmcs_writel(HOST_IDTR_BASE, dt.base); /* 22.2.4 */
21162
21163 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
21164- vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
21165+ vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
21166 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
21167 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
21168 vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, 0);
21169@@ -3718,6 +3725,12 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
21170 "jmp .Lkvm_vmx_return \n\t"
21171 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
21172 ".Lkvm_vmx_return: "
21173+
21174+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21175+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
21176+ ".Lkvm_vmx_return2: "
21177+#endif
21178+
21179 /* Save guest registers, load host registers, keep flags */
21180 "xchg %0, (%%"R"sp) \n\t"
21181 "mov %%"R"ax, %c[rax](%0) \n\t"
21182@@ -3764,8 +3777,13 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
21183 [r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
21184 #endif
21185 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2))
21186+
21187+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21188+ ,[cs]"i"(__KERNEL_CS)
21189+#endif
21190+
21191 : "cc", "memory"
21192- , R"bx", R"di", R"si"
21193+ , R"ax", R"bx", R"di", R"si"
21194 #ifdef CONFIG_X86_64
21195 , "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
21196 #endif
21197@@ -3782,7 +3800,16 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
21198 if (vmx->rmode.irq.pending)
21199 fixup_rmode_irq(vmx);
21200
21201- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
21202+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
21203+
21204+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21205+ loadsegment(fs, __KERNEL_PERCPU);
21206+#endif
21207+
21208+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21209+ __set_fs(current_thread_info()->addr_limit);
21210+#endif
21211+
21212 vmx->launched = 1;
21213
21214 vmx_complete_interrupts(vmx);
21215@@ -3957,7 +3984,7 @@ static bool vmx_gb_page_enable(void)
21216 return false;
21217 }
21218
21219-static struct kvm_x86_ops vmx_x86_ops = {
21220+static const struct kvm_x86_ops vmx_x86_ops = {
21221 .cpu_has_kvm_support = cpu_has_kvm_support,
21222 .disabled_by_bios = vmx_disabled_by_bios,
21223 .hardware_setup = hardware_setup,
21224diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
21225index df1cefb..5e882ad 100644
21226--- a/arch/x86/kvm/x86.c
21227+++ b/arch/x86/kvm/x86.c
21228@@ -82,7 +82,7 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu);
21229 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
21230 struct kvm_cpuid_entry2 __user *entries);
21231
21232-struct kvm_x86_ops *kvm_x86_ops;
21233+const struct kvm_x86_ops *kvm_x86_ops;
21234 EXPORT_SYMBOL_GPL(kvm_x86_ops);
21235
21236 int ignore_msrs = 0;
21237@@ -1430,15 +1430,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21238 struct kvm_cpuid2 *cpuid,
21239 struct kvm_cpuid_entry2 __user *entries)
21240 {
21241- int r;
21242+ int r, i;
21243
21244 r = -E2BIG;
21245 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21246 goto out;
21247 r = -EFAULT;
21248- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21249- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21250+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21251 goto out;
21252+ for (i = 0; i < cpuid->nent; ++i) {
21253+ struct kvm_cpuid_entry2 cpuid_entry;
21254+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21255+ goto out;
21256+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
21257+ }
21258 vcpu->arch.cpuid_nent = cpuid->nent;
21259 kvm_apic_set_version(vcpu);
21260 return 0;
21261@@ -1451,16 +1456,20 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21262 struct kvm_cpuid2 *cpuid,
21263 struct kvm_cpuid_entry2 __user *entries)
21264 {
21265- int r;
21266+ int r, i;
21267
21268 vcpu_load(vcpu);
21269 r = -E2BIG;
21270 if (cpuid->nent < vcpu->arch.cpuid_nent)
21271 goto out;
21272 r = -EFAULT;
21273- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21274- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21275+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21276 goto out;
21277+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21278+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21279+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21280+ goto out;
21281+ }
21282 return 0;
21283
21284 out:
21285@@ -1678,7 +1687,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
21286 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
21287 struct kvm_interrupt *irq)
21288 {
21289- if (irq->irq < 0 || irq->irq >= 256)
21290+ if (irq->irq >= 256)
21291 return -EINVAL;
21292 if (irqchip_in_kernel(vcpu->kvm))
21293 return -ENXIO;
21294@@ -3260,10 +3269,10 @@ static struct notifier_block kvmclock_cpufreq_notifier_block = {
21295 .notifier_call = kvmclock_cpufreq_notifier
21296 };
21297
21298-int kvm_arch_init(void *opaque)
21299+int kvm_arch_init(const void *opaque)
21300 {
21301 int r, cpu;
21302- struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
21303+ const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
21304
21305 if (kvm_x86_ops) {
21306 printk(KERN_ERR "kvm: already loaded the other module\n");
21307diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
21308index 7e59dc1..b88c98f 100644
21309--- a/arch/x86/lguest/boot.c
21310+++ b/arch/x86/lguest/boot.c
21311@@ -1172,9 +1172,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
21312 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
21313 * Launcher to reboot us.
21314 */
21315-static void lguest_restart(char *reason)
21316+static __noreturn void lguest_restart(char *reason)
21317 {
21318 kvm_hypercall2(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART);
21319+ BUG();
21320 }
21321
21322 /*G:050
21323diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
21324index 824fa0b..c619e96 100644
21325--- a/arch/x86/lib/atomic64_32.c
21326+++ b/arch/x86/lib/atomic64_32.c
21327@@ -25,6 +25,12 @@ u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val)
21328 }
21329 EXPORT_SYMBOL(atomic64_cmpxchg);
21330
21331+u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val)
21332+{
21333+ return cmpxchg8b(&ptr->counter, old_val, new_val);
21334+}
21335+EXPORT_SYMBOL(atomic64_cmpxchg_unchecked);
21336+
21337 /**
21338 * atomic64_xchg - xchg atomic64 variable
21339 * @ptr: pointer to type atomic64_t
21340@@ -56,6 +62,36 @@ u64 atomic64_xchg(atomic64_t *ptr, u64 new_val)
21341 EXPORT_SYMBOL(atomic64_xchg);
21342
21343 /**
21344+ * atomic64_xchg_unchecked - xchg atomic64 variable
21345+ * @ptr: pointer to type atomic64_unchecked_t
21346+ * @new_val: value to assign
21347+ *
21348+ * Atomically xchgs the value of @ptr to @new_val and returns
21349+ * the old value.
21350+ */
21351+u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
21352+{
21353+ /*
21354+ * Try first with a (possibly incorrect) assumption about
21355+ * what we have there. We'll do two loops most likely,
21356+ * but we'll get an ownership MESI transaction straight away
21357+ * instead of a read transaction followed by a
21358+ * flush-for-ownership transaction:
21359+ */
21360+ u64 old_val, real_val = 0;
21361+
21362+ do {
21363+ old_val = real_val;
21364+
21365+ real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
21366+
21367+ } while (real_val != old_val);
21368+
21369+ return old_val;
21370+}
21371+EXPORT_SYMBOL(atomic64_xchg_unchecked);
21372+
21373+/**
21374 * atomic64_set - set atomic64 variable
21375 * @ptr: pointer to type atomic64_t
21376 * @new_val: value to assign
21377@@ -69,7 +105,19 @@ void atomic64_set(atomic64_t *ptr, u64 new_val)
21378 EXPORT_SYMBOL(atomic64_set);
21379
21380 /**
21381-EXPORT_SYMBOL(atomic64_read);
21382+ * atomic64_unchecked_set - set atomic64 variable
21383+ * @ptr: pointer to type atomic64_unchecked_t
21384+ * @new_val: value to assign
21385+ *
21386+ * Atomically sets the value of @ptr to @new_val.
21387+ */
21388+void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
21389+{
21390+ atomic64_xchg_unchecked(ptr, new_val);
21391+}
21392+EXPORT_SYMBOL(atomic64_set_unchecked);
21393+
21394+/**
21395 * atomic64_add_return - add and return
21396 * @delta: integer value to add
21397 * @ptr: pointer to type atomic64_t
21398@@ -99,24 +147,72 @@ noinline u64 atomic64_add_return(u64 delta, atomic64_t *ptr)
21399 }
21400 EXPORT_SYMBOL(atomic64_add_return);
21401
21402+/**
21403+ * atomic64_add_return_unchecked - add and return
21404+ * @delta: integer value to add
21405+ * @ptr: pointer to type atomic64_unchecked_t
21406+ *
21407+ * Atomically adds @delta to @ptr and returns @delta + *@ptr
21408+ */
21409+noinline u64 atomic64_add_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21410+{
21411+ /*
21412+ * Try first with a (possibly incorrect) assumption about
21413+ * what we have there. We'll do two loops most likely,
21414+ * but we'll get an ownership MESI transaction straight away
21415+ * instead of a read transaction followed by a
21416+ * flush-for-ownership transaction:
21417+ */
21418+ u64 old_val, new_val, real_val = 0;
21419+
21420+ do {
21421+ old_val = real_val;
21422+ new_val = old_val + delta;
21423+
21424+ real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
21425+
21426+ } while (real_val != old_val);
21427+
21428+ return new_val;
21429+}
21430+EXPORT_SYMBOL(atomic64_add_return_unchecked);
21431+
21432 u64 atomic64_sub_return(u64 delta, atomic64_t *ptr)
21433 {
21434 return atomic64_add_return(-delta, ptr);
21435 }
21436 EXPORT_SYMBOL(atomic64_sub_return);
21437
21438+u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21439+{
21440+ return atomic64_add_return_unchecked(-delta, ptr);
21441+}
21442+EXPORT_SYMBOL(atomic64_sub_return_unchecked);
21443+
21444 u64 atomic64_inc_return(atomic64_t *ptr)
21445 {
21446 return atomic64_add_return(1, ptr);
21447 }
21448 EXPORT_SYMBOL(atomic64_inc_return);
21449
21450+u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr)
21451+{
21452+ return atomic64_add_return_unchecked(1, ptr);
21453+}
21454+EXPORT_SYMBOL(atomic64_inc_return_unchecked);
21455+
21456 u64 atomic64_dec_return(atomic64_t *ptr)
21457 {
21458 return atomic64_sub_return(1, ptr);
21459 }
21460 EXPORT_SYMBOL(atomic64_dec_return);
21461
21462+u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr)
21463+{
21464+ return atomic64_sub_return_unchecked(1, ptr);
21465+}
21466+EXPORT_SYMBOL(atomic64_dec_return_unchecked);
21467+
21468 /**
21469 * atomic64_add - add integer to atomic64 variable
21470 * @delta: integer value to add
21471@@ -131,6 +227,19 @@ void atomic64_add(u64 delta, atomic64_t *ptr)
21472 EXPORT_SYMBOL(atomic64_add);
21473
21474 /**
21475+ * atomic64_add_unchecked - add integer to atomic64 variable
21476+ * @delta: integer value to add
21477+ * @ptr: pointer to type atomic64_unchecked_t
21478+ *
21479+ * Atomically adds @delta to @ptr.
21480+ */
21481+void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21482+{
21483+ atomic64_add_return_unchecked(delta, ptr);
21484+}
21485+EXPORT_SYMBOL(atomic64_add_unchecked);
21486+
21487+/**
21488 * atomic64_sub - subtract the atomic64 variable
21489 * @delta: integer value to subtract
21490 * @ptr: pointer to type atomic64_t
21491@@ -144,6 +253,19 @@ void atomic64_sub(u64 delta, atomic64_t *ptr)
21492 EXPORT_SYMBOL(atomic64_sub);
21493
21494 /**
21495+ * atomic64_sub_unchecked - subtract the atomic64 variable
21496+ * @delta: integer value to subtract
21497+ * @ptr: pointer to type atomic64_unchecked_t
21498+ *
21499+ * Atomically subtracts @delta from @ptr.
21500+ */
21501+void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21502+{
21503+ atomic64_add_unchecked(-delta, ptr);
21504+}
21505+EXPORT_SYMBOL(atomic64_sub_unchecked);
21506+
21507+/**
21508 * atomic64_sub_and_test - subtract value from variable and test result
21509 * @delta: integer value to subtract
21510 * @ptr: pointer to type atomic64_t
21511@@ -173,6 +295,18 @@ void atomic64_inc(atomic64_t *ptr)
21512 EXPORT_SYMBOL(atomic64_inc);
21513
21514 /**
21515+ * atomic64_inc_unchecked - increment atomic64 variable
21516+ * @ptr: pointer to type atomic64_unchecked_t
21517+ *
21518+ * Atomically increments @ptr by 1.
21519+ */
21520+void atomic64_inc_unchecked(atomic64_unchecked_t *ptr)
21521+{
21522+ atomic64_add_unchecked(1, ptr);
21523+}
21524+EXPORT_SYMBOL(atomic64_inc_unchecked);
21525+
21526+/**
21527 * atomic64_dec - decrement atomic64 variable
21528 * @ptr: pointer to type atomic64_t
21529 *
21530@@ -185,6 +319,18 @@ void atomic64_dec(atomic64_t *ptr)
21531 EXPORT_SYMBOL(atomic64_dec);
21532
21533 /**
21534+ * atomic64_dec_unchecked - decrement atomic64 variable
21535+ * @ptr: pointer to type atomic64_unchecked_t
21536+ *
21537+ * Atomically decrements @ptr by 1.
21538+ */
21539+void atomic64_dec_unchecked(atomic64_unchecked_t *ptr)
21540+{
21541+ atomic64_sub_unchecked(1, ptr);
21542+}
21543+EXPORT_SYMBOL(atomic64_dec_unchecked);
21544+
21545+/**
21546 * atomic64_dec_and_test - decrement and test
21547 * @ptr: pointer to type atomic64_t
21548 *
21549diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21550index adbccd0..98f96c8 100644
21551--- a/arch/x86/lib/checksum_32.S
21552+++ b/arch/x86/lib/checksum_32.S
21553@@ -28,7 +28,8 @@
21554 #include <linux/linkage.h>
21555 #include <asm/dwarf2.h>
21556 #include <asm/errno.h>
21557-
21558+#include <asm/segment.h>
21559+
21560 /*
21561 * computes a partial checksum, e.g. for TCP/UDP fragments
21562 */
21563@@ -304,9 +305,28 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21564
21565 #define ARGBASE 16
21566 #define FP 12
21567-
21568-ENTRY(csum_partial_copy_generic)
21569+
21570+ENTRY(csum_partial_copy_generic_to_user)
21571 CFI_STARTPROC
21572+
21573+#ifdef CONFIG_PAX_MEMORY_UDEREF
21574+ pushl %gs
21575+ CFI_ADJUST_CFA_OFFSET 4
21576+ popl %es
21577+ CFI_ADJUST_CFA_OFFSET -4
21578+ jmp csum_partial_copy_generic
21579+#endif
21580+
21581+ENTRY(csum_partial_copy_generic_from_user)
21582+
21583+#ifdef CONFIG_PAX_MEMORY_UDEREF
21584+ pushl %gs
21585+ CFI_ADJUST_CFA_OFFSET 4
21586+ popl %ds
21587+ CFI_ADJUST_CFA_OFFSET -4
21588+#endif
21589+
21590+ENTRY(csum_partial_copy_generic)
21591 subl $4,%esp
21592 CFI_ADJUST_CFA_OFFSET 4
21593 pushl %edi
21594@@ -331,7 +351,7 @@ ENTRY(csum_partial_copy_generic)
21595 jmp 4f
21596 SRC(1: movw (%esi), %bx )
21597 addl $2, %esi
21598-DST( movw %bx, (%edi) )
21599+DST( movw %bx, %es:(%edi) )
21600 addl $2, %edi
21601 addw %bx, %ax
21602 adcl $0, %eax
21603@@ -343,30 +363,30 @@ DST( movw %bx, (%edi) )
21604 SRC(1: movl (%esi), %ebx )
21605 SRC( movl 4(%esi), %edx )
21606 adcl %ebx, %eax
21607-DST( movl %ebx, (%edi) )
21608+DST( movl %ebx, %es:(%edi) )
21609 adcl %edx, %eax
21610-DST( movl %edx, 4(%edi) )
21611+DST( movl %edx, %es:4(%edi) )
21612
21613 SRC( movl 8(%esi), %ebx )
21614 SRC( movl 12(%esi), %edx )
21615 adcl %ebx, %eax
21616-DST( movl %ebx, 8(%edi) )
21617+DST( movl %ebx, %es:8(%edi) )
21618 adcl %edx, %eax
21619-DST( movl %edx, 12(%edi) )
21620+DST( movl %edx, %es:12(%edi) )
21621
21622 SRC( movl 16(%esi), %ebx )
21623 SRC( movl 20(%esi), %edx )
21624 adcl %ebx, %eax
21625-DST( movl %ebx, 16(%edi) )
21626+DST( movl %ebx, %es:16(%edi) )
21627 adcl %edx, %eax
21628-DST( movl %edx, 20(%edi) )
21629+DST( movl %edx, %es:20(%edi) )
21630
21631 SRC( movl 24(%esi), %ebx )
21632 SRC( movl 28(%esi), %edx )
21633 adcl %ebx, %eax
21634-DST( movl %ebx, 24(%edi) )
21635+DST( movl %ebx, %es:24(%edi) )
21636 adcl %edx, %eax
21637-DST( movl %edx, 28(%edi) )
21638+DST( movl %edx, %es:28(%edi) )
21639
21640 lea 32(%esi), %esi
21641 lea 32(%edi), %edi
21642@@ -380,7 +400,7 @@ DST( movl %edx, 28(%edi) )
21643 shrl $2, %edx # This clears CF
21644 SRC(3: movl (%esi), %ebx )
21645 adcl %ebx, %eax
21646-DST( movl %ebx, (%edi) )
21647+DST( movl %ebx, %es:(%edi) )
21648 lea 4(%esi), %esi
21649 lea 4(%edi), %edi
21650 dec %edx
21651@@ -392,12 +412,12 @@ DST( movl %ebx, (%edi) )
21652 jb 5f
21653 SRC( movw (%esi), %cx )
21654 leal 2(%esi), %esi
21655-DST( movw %cx, (%edi) )
21656+DST( movw %cx, %es:(%edi) )
21657 leal 2(%edi), %edi
21658 je 6f
21659 shll $16,%ecx
21660 SRC(5: movb (%esi), %cl )
21661-DST( movb %cl, (%edi) )
21662+DST( movb %cl, %es:(%edi) )
21663 6: addl %ecx, %eax
21664 adcl $0, %eax
21665 7:
21666@@ -408,7 +428,7 @@ DST( movb %cl, (%edi) )
21667
21668 6001:
21669 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21670- movl $-EFAULT, (%ebx)
21671+ movl $-EFAULT, %ss:(%ebx)
21672
21673 # zero the complete destination - computing the rest
21674 # is too much work
21675@@ -421,11 +441,19 @@ DST( movb %cl, (%edi) )
21676
21677 6002:
21678 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21679- movl $-EFAULT,(%ebx)
21680+ movl $-EFAULT,%ss:(%ebx)
21681 jmp 5000b
21682
21683 .previous
21684
21685+ pushl %ss
21686+ CFI_ADJUST_CFA_OFFSET 4
21687+ popl %ds
21688+ CFI_ADJUST_CFA_OFFSET -4
21689+ pushl %ss
21690+ CFI_ADJUST_CFA_OFFSET 4
21691+ popl %es
21692+ CFI_ADJUST_CFA_OFFSET -4
21693 popl %ebx
21694 CFI_ADJUST_CFA_OFFSET -4
21695 CFI_RESTORE ebx
21696@@ -439,26 +467,47 @@ DST( movb %cl, (%edi) )
21697 CFI_ADJUST_CFA_OFFSET -4
21698 ret
21699 CFI_ENDPROC
21700-ENDPROC(csum_partial_copy_generic)
21701+ENDPROC(csum_partial_copy_generic_to_user)
21702
21703 #else
21704
21705 /* Version for PentiumII/PPro */
21706
21707 #define ROUND1(x) \
21708+ nop; nop; nop; \
21709 SRC(movl x(%esi), %ebx ) ; \
21710 addl %ebx, %eax ; \
21711- DST(movl %ebx, x(%edi) ) ;
21712+ DST(movl %ebx, %es:x(%edi)) ;
21713
21714 #define ROUND(x) \
21715+ nop; nop; nop; \
21716 SRC(movl x(%esi), %ebx ) ; \
21717 adcl %ebx, %eax ; \
21718- DST(movl %ebx, x(%edi) ) ;
21719+ DST(movl %ebx, %es:x(%edi)) ;
21720
21721 #define ARGBASE 12
21722-
21723-ENTRY(csum_partial_copy_generic)
21724+
21725+ENTRY(csum_partial_copy_generic_to_user)
21726 CFI_STARTPROC
21727+
21728+#ifdef CONFIG_PAX_MEMORY_UDEREF
21729+ pushl %gs
21730+ CFI_ADJUST_CFA_OFFSET 4
21731+ popl %es
21732+ CFI_ADJUST_CFA_OFFSET -4
21733+ jmp csum_partial_copy_generic
21734+#endif
21735+
21736+ENTRY(csum_partial_copy_generic_from_user)
21737+
21738+#ifdef CONFIG_PAX_MEMORY_UDEREF
21739+ pushl %gs
21740+ CFI_ADJUST_CFA_OFFSET 4
21741+ popl %ds
21742+ CFI_ADJUST_CFA_OFFSET -4
21743+#endif
21744+
21745+ENTRY(csum_partial_copy_generic)
21746 pushl %ebx
21747 CFI_ADJUST_CFA_OFFSET 4
21748 CFI_REL_OFFSET ebx, 0
21749@@ -482,7 +531,7 @@ ENTRY(csum_partial_copy_generic)
21750 subl %ebx, %edi
21751 lea -1(%esi),%edx
21752 andl $-32,%edx
21753- lea 3f(%ebx,%ebx), %ebx
21754+ lea 3f(%ebx,%ebx,2), %ebx
21755 testl %esi, %esi
21756 jmp *%ebx
21757 1: addl $64,%esi
21758@@ -503,19 +552,19 @@ ENTRY(csum_partial_copy_generic)
21759 jb 5f
21760 SRC( movw (%esi), %dx )
21761 leal 2(%esi), %esi
21762-DST( movw %dx, (%edi) )
21763+DST( movw %dx, %es:(%edi) )
21764 leal 2(%edi), %edi
21765 je 6f
21766 shll $16,%edx
21767 5:
21768 SRC( movb (%esi), %dl )
21769-DST( movb %dl, (%edi) )
21770+DST( movb %dl, %es:(%edi) )
21771 6: addl %edx, %eax
21772 adcl $0, %eax
21773 7:
21774 .section .fixup, "ax"
21775 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21776- movl $-EFAULT, (%ebx)
21777+ movl $-EFAULT, %ss:(%ebx)
21778 # zero the complete destination (computing the rest is too much work)
21779 movl ARGBASE+8(%esp),%edi # dst
21780 movl ARGBASE+12(%esp),%ecx # len
21781@@ -523,10 +572,21 @@ DST( movb %dl, (%edi) )
21782 rep; stosb
21783 jmp 7b
21784 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21785- movl $-EFAULT, (%ebx)
21786+ movl $-EFAULT, %ss:(%ebx)
21787 jmp 7b
21788 .previous
21789
21790+#ifdef CONFIG_PAX_MEMORY_UDEREF
21791+ pushl %ss
21792+ CFI_ADJUST_CFA_OFFSET 4
21793+ popl %ds
21794+ CFI_ADJUST_CFA_OFFSET -4
21795+ pushl %ss
21796+ CFI_ADJUST_CFA_OFFSET 4
21797+ popl %es
21798+ CFI_ADJUST_CFA_OFFSET -4
21799+#endif
21800+
21801 popl %esi
21802 CFI_ADJUST_CFA_OFFSET -4
21803 CFI_RESTORE esi
21804@@ -538,7 +598,7 @@ DST( movb %dl, (%edi) )
21805 CFI_RESTORE ebx
21806 ret
21807 CFI_ENDPROC
21808-ENDPROC(csum_partial_copy_generic)
21809+ENDPROC(csum_partial_copy_generic_to_user)
21810
21811 #undef ROUND
21812 #undef ROUND1
21813diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21814index ebeafcc..1e3a402 100644
21815--- a/arch/x86/lib/clear_page_64.S
21816+++ b/arch/x86/lib/clear_page_64.S
21817@@ -1,5 +1,6 @@
21818 #include <linux/linkage.h>
21819 #include <asm/dwarf2.h>
21820+#include <asm/alternative-asm.h>
21821
21822 /*
21823 * Zero a page.
21824@@ -10,6 +11,7 @@ ENTRY(clear_page_c)
21825 movl $4096/8,%ecx
21826 xorl %eax,%eax
21827 rep stosq
21828+ pax_force_retaddr
21829 ret
21830 CFI_ENDPROC
21831 ENDPROC(clear_page_c)
21832@@ -33,6 +35,7 @@ ENTRY(clear_page)
21833 leaq 64(%rdi),%rdi
21834 jnz .Lloop
21835 nop
21836+ pax_force_retaddr
21837 ret
21838 CFI_ENDPROC
21839 .Lclear_page_end:
21840@@ -43,7 +46,7 @@ ENDPROC(clear_page)
21841
21842 #include <asm/cpufeature.h>
21843
21844- .section .altinstr_replacement,"ax"
21845+ .section .altinstr_replacement,"a"
21846 1: .byte 0xeb /* jmp <disp8> */
21847 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21848 2:
21849diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21850index 727a5d4..333818a 100644
21851--- a/arch/x86/lib/copy_page_64.S
21852+++ b/arch/x86/lib/copy_page_64.S
21853@@ -2,12 +2,14 @@
21854
21855 #include <linux/linkage.h>
21856 #include <asm/dwarf2.h>
21857+#include <asm/alternative-asm.h>
21858
21859 ALIGN
21860 copy_page_c:
21861 CFI_STARTPROC
21862 movl $4096/8,%ecx
21863 rep movsq
21864+ pax_force_retaddr
21865 ret
21866 CFI_ENDPROC
21867 ENDPROC(copy_page_c)
21868@@ -38,7 +40,7 @@ ENTRY(copy_page)
21869 movq 16 (%rsi), %rdx
21870 movq 24 (%rsi), %r8
21871 movq 32 (%rsi), %r9
21872- movq 40 (%rsi), %r10
21873+ movq 40 (%rsi), %r13
21874 movq 48 (%rsi), %r11
21875 movq 56 (%rsi), %r12
21876
21877@@ -49,7 +51,7 @@ ENTRY(copy_page)
21878 movq %rdx, 16 (%rdi)
21879 movq %r8, 24 (%rdi)
21880 movq %r9, 32 (%rdi)
21881- movq %r10, 40 (%rdi)
21882+ movq %r13, 40 (%rdi)
21883 movq %r11, 48 (%rdi)
21884 movq %r12, 56 (%rdi)
21885
21886@@ -68,7 +70,7 @@ ENTRY(copy_page)
21887 movq 16 (%rsi), %rdx
21888 movq 24 (%rsi), %r8
21889 movq 32 (%rsi), %r9
21890- movq 40 (%rsi), %r10
21891+ movq 40 (%rsi), %r13
21892 movq 48 (%rsi), %r11
21893 movq 56 (%rsi), %r12
21894
21895@@ -77,7 +79,7 @@ ENTRY(copy_page)
21896 movq %rdx, 16 (%rdi)
21897 movq %r8, 24 (%rdi)
21898 movq %r9, 32 (%rdi)
21899- movq %r10, 40 (%rdi)
21900+ movq %r13, 40 (%rdi)
21901 movq %r11, 48 (%rdi)
21902 movq %r12, 56 (%rdi)
21903
21904@@ -94,6 +96,7 @@ ENTRY(copy_page)
21905 CFI_RESTORE r13
21906 addq $3*8,%rsp
21907 CFI_ADJUST_CFA_OFFSET -3*8
21908+ pax_force_retaddr
21909 ret
21910 .Lcopy_page_end:
21911 CFI_ENDPROC
21912@@ -104,7 +107,7 @@ ENDPROC(copy_page)
21913
21914 #include <asm/cpufeature.h>
21915
21916- .section .altinstr_replacement,"ax"
21917+ .section .altinstr_replacement,"a"
21918 1: .byte 0xeb /* jmp <disp8> */
21919 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21920 2:
21921diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21922index af8debd..40c75f3 100644
21923--- a/arch/x86/lib/copy_user_64.S
21924+++ b/arch/x86/lib/copy_user_64.S
21925@@ -15,13 +15,15 @@
21926 #include <asm/asm-offsets.h>
21927 #include <asm/thread_info.h>
21928 #include <asm/cpufeature.h>
21929+#include <asm/pgtable.h>
21930+#include <asm/alternative-asm.h>
21931
21932 .macro ALTERNATIVE_JUMP feature,orig,alt
21933 0:
21934 .byte 0xe9 /* 32bit jump */
21935 .long \orig-1f /* by default jump to orig */
21936 1:
21937- .section .altinstr_replacement,"ax"
21938+ .section .altinstr_replacement,"a"
21939 2: .byte 0xe9 /* near jump with 32bit immediate */
21940 .long \alt-1b /* offset */ /* or alternatively to alt */
21941 .previous
21942@@ -64,55 +66,26 @@
21943 #endif
21944 .endm
21945
21946-/* Standard copy_to_user with segment limit checking */
21947-ENTRY(copy_to_user)
21948- CFI_STARTPROC
21949- GET_THREAD_INFO(%rax)
21950- movq %rdi,%rcx
21951- addq %rdx,%rcx
21952- jc bad_to_user
21953- cmpq TI_addr_limit(%rax),%rcx
21954- ja bad_to_user
21955- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21956- CFI_ENDPROC
21957-ENDPROC(copy_to_user)
21958-
21959-/* Standard copy_from_user with segment limit checking */
21960-ENTRY(copy_from_user)
21961- CFI_STARTPROC
21962- GET_THREAD_INFO(%rax)
21963- movq %rsi,%rcx
21964- addq %rdx,%rcx
21965- jc bad_from_user
21966- cmpq TI_addr_limit(%rax),%rcx
21967- ja bad_from_user
21968- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21969- CFI_ENDPROC
21970-ENDPROC(copy_from_user)
21971-
21972 ENTRY(copy_user_generic)
21973 CFI_STARTPROC
21974 ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21975 CFI_ENDPROC
21976 ENDPROC(copy_user_generic)
21977
21978-ENTRY(__copy_from_user_inatomic)
21979- CFI_STARTPROC
21980- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21981- CFI_ENDPROC
21982-ENDPROC(__copy_from_user_inatomic)
21983-
21984 .section .fixup,"ax"
21985 /* must zero dest */
21986 ENTRY(bad_from_user)
21987 bad_from_user:
21988 CFI_STARTPROC
21989+ testl %edx,%edx
21990+ js bad_to_user
21991 movl %edx,%ecx
21992 xorl %eax,%eax
21993 rep
21994 stosb
21995 bad_to_user:
21996 movl %edx,%eax
21997+ pax_force_retaddr
21998 ret
21999 CFI_ENDPROC
22000 ENDPROC(bad_from_user)
22001@@ -142,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
22002 jz 17f
22003 1: movq (%rsi),%r8
22004 2: movq 1*8(%rsi),%r9
22005-3: movq 2*8(%rsi),%r10
22006+3: movq 2*8(%rsi),%rax
22007 4: movq 3*8(%rsi),%r11
22008 5: movq %r8,(%rdi)
22009 6: movq %r9,1*8(%rdi)
22010-7: movq %r10,2*8(%rdi)
22011+7: movq %rax,2*8(%rdi)
22012 8: movq %r11,3*8(%rdi)
22013 9: movq 4*8(%rsi),%r8
22014 10: movq 5*8(%rsi),%r9
22015-11: movq 6*8(%rsi),%r10
22016+11: movq 6*8(%rsi),%rax
22017 12: movq 7*8(%rsi),%r11
22018 13: movq %r8,4*8(%rdi)
22019 14: movq %r9,5*8(%rdi)
22020-15: movq %r10,6*8(%rdi)
22021+15: movq %rax,6*8(%rdi)
22022 16: movq %r11,7*8(%rdi)
22023 leaq 64(%rsi),%rsi
22024 leaq 64(%rdi),%rdi
22025@@ -180,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
22026 decl %ecx
22027 jnz 21b
22028 23: xor %eax,%eax
22029+ pax_force_retaddr
22030 ret
22031
22032 .section .fixup,"ax"
22033@@ -252,6 +226,7 @@ ENTRY(copy_user_generic_string)
22034 3: rep
22035 movsb
22036 4: xorl %eax,%eax
22037+ pax_force_retaddr
22038 ret
22039
22040 .section .fixup,"ax"
22041diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
22042index cb0c112..e3a6895 100644
22043--- a/arch/x86/lib/copy_user_nocache_64.S
22044+++ b/arch/x86/lib/copy_user_nocache_64.S
22045@@ -8,12 +8,14 @@
22046
22047 #include <linux/linkage.h>
22048 #include <asm/dwarf2.h>
22049+#include <asm/alternative-asm.h>
22050
22051 #define FIX_ALIGNMENT 1
22052
22053 #include <asm/current.h>
22054 #include <asm/asm-offsets.h>
22055 #include <asm/thread_info.h>
22056+#include <asm/pgtable.h>
22057
22058 .macro ALIGN_DESTINATION
22059 #ifdef FIX_ALIGNMENT
22060@@ -50,6 +52,15 @@
22061 */
22062 ENTRY(__copy_user_nocache)
22063 CFI_STARTPROC
22064+
22065+#ifdef CONFIG_PAX_MEMORY_UDEREF
22066+ mov $PAX_USER_SHADOW_BASE,%rcx
22067+ cmp %rcx,%rsi
22068+ jae 1f
22069+ add %rcx,%rsi
22070+1:
22071+#endif
22072+
22073 cmpl $8,%edx
22074 jb 20f /* less then 8 bytes, go to byte copy loop */
22075 ALIGN_DESTINATION
22076@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
22077 jz 17f
22078 1: movq (%rsi),%r8
22079 2: movq 1*8(%rsi),%r9
22080-3: movq 2*8(%rsi),%r10
22081+3: movq 2*8(%rsi),%rax
22082 4: movq 3*8(%rsi),%r11
22083 5: movnti %r8,(%rdi)
22084 6: movnti %r9,1*8(%rdi)
22085-7: movnti %r10,2*8(%rdi)
22086+7: movnti %rax,2*8(%rdi)
22087 8: movnti %r11,3*8(%rdi)
22088 9: movq 4*8(%rsi),%r8
22089 10: movq 5*8(%rsi),%r9
22090-11: movq 6*8(%rsi),%r10
22091+11: movq 6*8(%rsi),%rax
22092 12: movq 7*8(%rsi),%r11
22093 13: movnti %r8,4*8(%rdi)
22094 14: movnti %r9,5*8(%rdi)
22095-15: movnti %r10,6*8(%rdi)
22096+15: movnti %rax,6*8(%rdi)
22097 16: movnti %r11,7*8(%rdi)
22098 leaq 64(%rsi),%rsi
22099 leaq 64(%rdi),%rdi
22100@@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
22101 jnz 21b
22102 23: xorl %eax,%eax
22103 sfence
22104+ pax_force_retaddr
22105 ret
22106
22107 .section .fixup,"ax"
22108diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
22109index f0dba36..48cb4d6 100644
22110--- a/arch/x86/lib/csum-copy_64.S
22111+++ b/arch/x86/lib/csum-copy_64.S
22112@@ -8,6 +8,7 @@
22113 #include <linux/linkage.h>
22114 #include <asm/dwarf2.h>
22115 #include <asm/errno.h>
22116+#include <asm/alternative-asm.h>
22117
22118 /*
22119 * Checksum copy with exception handling.
22120@@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
22121 CFI_RESTORE rbp
22122 addq $7*8,%rsp
22123 CFI_ADJUST_CFA_OFFSET -7*8
22124+ pax_force_retaddr 0, 1
22125 ret
22126 CFI_RESTORE_STATE
22127
22128diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
22129index 459b58a..9570bc7 100644
22130--- a/arch/x86/lib/csum-wrappers_64.c
22131+++ b/arch/x86/lib/csum-wrappers_64.c
22132@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
22133 len -= 2;
22134 }
22135 }
22136- isum = csum_partial_copy_generic((__force const void *)src,
22137+
22138+#ifdef CONFIG_PAX_MEMORY_UDEREF
22139+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
22140+ src += PAX_USER_SHADOW_BASE;
22141+#endif
22142+
22143+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
22144 dst, len, isum, errp, NULL);
22145 if (unlikely(*errp))
22146 goto out_err;
22147@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
22148 }
22149
22150 *errp = 0;
22151- return csum_partial_copy_generic(src, (void __force *)dst,
22152+
22153+#ifdef CONFIG_PAX_MEMORY_UDEREF
22154+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
22155+ dst += PAX_USER_SHADOW_BASE;
22156+#endif
22157+
22158+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
22159 len, isum, NULL, errp);
22160 }
22161 EXPORT_SYMBOL(csum_partial_copy_to_user);
22162diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
22163index 51f1504..ddac4c1 100644
22164--- a/arch/x86/lib/getuser.S
22165+++ b/arch/x86/lib/getuser.S
22166@@ -33,15 +33,38 @@
22167 #include <asm/asm-offsets.h>
22168 #include <asm/thread_info.h>
22169 #include <asm/asm.h>
22170+#include <asm/segment.h>
22171+#include <asm/pgtable.h>
22172+#include <asm/alternative-asm.h>
22173+
22174+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22175+#define __copyuser_seg gs;
22176+#else
22177+#define __copyuser_seg
22178+#endif
22179
22180 .text
22181 ENTRY(__get_user_1)
22182 CFI_STARTPROC
22183+
22184+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22185 GET_THREAD_INFO(%_ASM_DX)
22186 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22187 jae bad_get_user
22188-1: movzb (%_ASM_AX),%edx
22189+
22190+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22191+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22192+ cmp %_ASM_DX,%_ASM_AX
22193+ jae 1234f
22194+ add %_ASM_DX,%_ASM_AX
22195+1234:
22196+#endif
22197+
22198+#endif
22199+
22200+1: __copyuser_seg movzb (%_ASM_AX),%edx
22201 xor %eax,%eax
22202+ pax_force_retaddr
22203 ret
22204 CFI_ENDPROC
22205 ENDPROC(__get_user_1)
22206@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
22207 ENTRY(__get_user_2)
22208 CFI_STARTPROC
22209 add $1,%_ASM_AX
22210+
22211+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22212 jc bad_get_user
22213 GET_THREAD_INFO(%_ASM_DX)
22214 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22215 jae bad_get_user
22216-2: movzwl -1(%_ASM_AX),%edx
22217+
22218+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22219+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22220+ cmp %_ASM_DX,%_ASM_AX
22221+ jae 1234f
22222+ add %_ASM_DX,%_ASM_AX
22223+1234:
22224+#endif
22225+
22226+#endif
22227+
22228+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
22229 xor %eax,%eax
22230+ pax_force_retaddr
22231 ret
22232 CFI_ENDPROC
22233 ENDPROC(__get_user_2)
22234@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
22235 ENTRY(__get_user_4)
22236 CFI_STARTPROC
22237 add $3,%_ASM_AX
22238+
22239+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22240 jc bad_get_user
22241 GET_THREAD_INFO(%_ASM_DX)
22242 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22243 jae bad_get_user
22244-3: mov -3(%_ASM_AX),%edx
22245+
22246+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22247+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22248+ cmp %_ASM_DX,%_ASM_AX
22249+ jae 1234f
22250+ add %_ASM_DX,%_ASM_AX
22251+1234:
22252+#endif
22253+
22254+#endif
22255+
22256+3: __copyuser_seg mov -3(%_ASM_AX),%edx
22257 xor %eax,%eax
22258+ pax_force_retaddr
22259 ret
22260 CFI_ENDPROC
22261 ENDPROC(__get_user_4)
22262@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
22263 GET_THREAD_INFO(%_ASM_DX)
22264 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22265 jae bad_get_user
22266+
22267+#ifdef CONFIG_PAX_MEMORY_UDEREF
22268+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22269+ cmp %_ASM_DX,%_ASM_AX
22270+ jae 1234f
22271+ add %_ASM_DX,%_ASM_AX
22272+1234:
22273+#endif
22274+
22275 4: movq -7(%_ASM_AX),%_ASM_DX
22276 xor %eax,%eax
22277+ pax_force_retaddr
22278 ret
22279 CFI_ENDPROC
22280 ENDPROC(__get_user_8)
22281@@ -91,6 +152,7 @@ bad_get_user:
22282 CFI_STARTPROC
22283 xor %edx,%edx
22284 mov $(-EFAULT),%_ASM_AX
22285+ pax_force_retaddr
22286 ret
22287 CFI_ENDPROC
22288 END(bad_get_user)
22289diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22290index 05a95e7..326f2fa 100644
22291--- a/arch/x86/lib/iomap_copy_64.S
22292+++ b/arch/x86/lib/iomap_copy_64.S
22293@@ -17,6 +17,7 @@
22294
22295 #include <linux/linkage.h>
22296 #include <asm/dwarf2.h>
22297+#include <asm/alternative-asm.h>
22298
22299 /*
22300 * override generic version in lib/iomap_copy.c
22301@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22302 CFI_STARTPROC
22303 movl %edx,%ecx
22304 rep movsd
22305+ pax_force_retaddr
22306 ret
22307 CFI_ENDPROC
22308 ENDPROC(__iowrite32_copy)
22309diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22310index ad5441e..610e351 100644
22311--- a/arch/x86/lib/memcpy_64.S
22312+++ b/arch/x86/lib/memcpy_64.S
22313@@ -4,6 +4,7 @@
22314
22315 #include <asm/cpufeature.h>
22316 #include <asm/dwarf2.h>
22317+#include <asm/alternative-asm.h>
22318
22319 /*
22320 * memcpy - Copy a memory block.
22321@@ -34,6 +35,7 @@ memcpy_c:
22322 rep movsq
22323 movl %edx, %ecx
22324 rep movsb
22325+ pax_force_retaddr
22326 ret
22327 CFI_ENDPROC
22328 ENDPROC(memcpy_c)
22329@@ -118,6 +120,7 @@ ENTRY(memcpy)
22330 jnz .Lloop_1
22331
22332 .Lend:
22333+ pax_force_retaddr 0, 1
22334 ret
22335 CFI_ENDPROC
22336 ENDPROC(memcpy)
22337@@ -128,7 +131,7 @@ ENDPROC(__memcpy)
22338 * It is also a lot simpler. Use this when possible:
22339 */
22340
22341- .section .altinstr_replacement, "ax"
22342+ .section .altinstr_replacement, "a"
22343 1: .byte 0xeb /* jmp <disp8> */
22344 .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
22345 2:
22346diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22347index 2c59481..7e9ba4e 100644
22348--- a/arch/x86/lib/memset_64.S
22349+++ b/arch/x86/lib/memset_64.S
22350@@ -2,6 +2,7 @@
22351
22352 #include <linux/linkage.h>
22353 #include <asm/dwarf2.h>
22354+#include <asm/alternative-asm.h>
22355
22356 /*
22357 * ISO C memset - set a memory block to a byte value.
22358@@ -28,6 +29,7 @@ memset_c:
22359 movl %r8d,%ecx
22360 rep stosb
22361 movq %r9,%rax
22362+ pax_force_retaddr
22363 ret
22364 CFI_ENDPROC
22365 ENDPROC(memset_c)
22366@@ -35,13 +37,13 @@ ENDPROC(memset_c)
22367 ENTRY(memset)
22368 ENTRY(__memset)
22369 CFI_STARTPROC
22370- movq %rdi,%r10
22371 movq %rdx,%r11
22372
22373 /* expand byte value */
22374 movzbl %sil,%ecx
22375 movabs $0x0101010101010101,%rax
22376 mul %rcx /* with rax, clobbers rdx */
22377+ movq %rdi,%rdx
22378
22379 /* align dst */
22380 movl %edi,%r9d
22381@@ -95,7 +97,8 @@ ENTRY(__memset)
22382 jnz .Lloop_1
22383
22384 .Lende:
22385- movq %r10,%rax
22386+ movq %rdx,%rax
22387+ pax_force_retaddr
22388 ret
22389
22390 CFI_RESTORE_STATE
22391@@ -118,7 +121,7 @@ ENDPROC(__memset)
22392
22393 #include <asm/cpufeature.h>
22394
22395- .section .altinstr_replacement,"ax"
22396+ .section .altinstr_replacement,"a"
22397 1: .byte 0xeb /* jmp <disp8> */
22398 .byte (memset_c - memset) - (2f - 1b) /* offset */
22399 2:
22400diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22401index c9f2d9b..e7fd2c0 100644
22402--- a/arch/x86/lib/mmx_32.c
22403+++ b/arch/x86/lib/mmx_32.c
22404@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22405 {
22406 void *p;
22407 int i;
22408+ unsigned long cr0;
22409
22410 if (unlikely(in_interrupt()))
22411 return __memcpy(to, from, len);
22412@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22413 kernel_fpu_begin();
22414
22415 __asm__ __volatile__ (
22416- "1: prefetch (%0)\n" /* This set is 28 bytes */
22417- " prefetch 64(%0)\n"
22418- " prefetch 128(%0)\n"
22419- " prefetch 192(%0)\n"
22420- " prefetch 256(%0)\n"
22421+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22422+ " prefetch 64(%1)\n"
22423+ " prefetch 128(%1)\n"
22424+ " prefetch 192(%1)\n"
22425+ " prefetch 256(%1)\n"
22426 "2: \n"
22427 ".section .fixup, \"ax\"\n"
22428- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22429+ "3: \n"
22430+
22431+#ifdef CONFIG_PAX_KERNEXEC
22432+ " movl %%cr0, %0\n"
22433+ " movl %0, %%eax\n"
22434+ " andl $0xFFFEFFFF, %%eax\n"
22435+ " movl %%eax, %%cr0\n"
22436+#endif
22437+
22438+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22439+
22440+#ifdef CONFIG_PAX_KERNEXEC
22441+ " movl %0, %%cr0\n"
22442+#endif
22443+
22444 " jmp 2b\n"
22445 ".previous\n"
22446 _ASM_EXTABLE(1b, 3b)
22447- : : "r" (from));
22448+ : "=&r" (cr0) : "r" (from) : "ax");
22449
22450 for ( ; i > 5; i--) {
22451 __asm__ __volatile__ (
22452- "1: prefetch 320(%0)\n"
22453- "2: movq (%0), %%mm0\n"
22454- " movq 8(%0), %%mm1\n"
22455- " movq 16(%0), %%mm2\n"
22456- " movq 24(%0), %%mm3\n"
22457- " movq %%mm0, (%1)\n"
22458- " movq %%mm1, 8(%1)\n"
22459- " movq %%mm2, 16(%1)\n"
22460- " movq %%mm3, 24(%1)\n"
22461- " movq 32(%0), %%mm0\n"
22462- " movq 40(%0), %%mm1\n"
22463- " movq 48(%0), %%mm2\n"
22464- " movq 56(%0), %%mm3\n"
22465- " movq %%mm0, 32(%1)\n"
22466- " movq %%mm1, 40(%1)\n"
22467- " movq %%mm2, 48(%1)\n"
22468- " movq %%mm3, 56(%1)\n"
22469+ "1: prefetch 320(%1)\n"
22470+ "2: movq (%1), %%mm0\n"
22471+ " movq 8(%1), %%mm1\n"
22472+ " movq 16(%1), %%mm2\n"
22473+ " movq 24(%1), %%mm3\n"
22474+ " movq %%mm0, (%2)\n"
22475+ " movq %%mm1, 8(%2)\n"
22476+ " movq %%mm2, 16(%2)\n"
22477+ " movq %%mm3, 24(%2)\n"
22478+ " movq 32(%1), %%mm0\n"
22479+ " movq 40(%1), %%mm1\n"
22480+ " movq 48(%1), %%mm2\n"
22481+ " movq 56(%1), %%mm3\n"
22482+ " movq %%mm0, 32(%2)\n"
22483+ " movq %%mm1, 40(%2)\n"
22484+ " movq %%mm2, 48(%2)\n"
22485+ " movq %%mm3, 56(%2)\n"
22486 ".section .fixup, \"ax\"\n"
22487- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22488+ "3:\n"
22489+
22490+#ifdef CONFIG_PAX_KERNEXEC
22491+ " movl %%cr0, %0\n"
22492+ " movl %0, %%eax\n"
22493+ " andl $0xFFFEFFFF, %%eax\n"
22494+ " movl %%eax, %%cr0\n"
22495+#endif
22496+
22497+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22498+
22499+#ifdef CONFIG_PAX_KERNEXEC
22500+ " movl %0, %%cr0\n"
22501+#endif
22502+
22503 " jmp 2b\n"
22504 ".previous\n"
22505 _ASM_EXTABLE(1b, 3b)
22506- : : "r" (from), "r" (to) : "memory");
22507+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22508
22509 from += 64;
22510 to += 64;
22511@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22512 static void fast_copy_page(void *to, void *from)
22513 {
22514 int i;
22515+ unsigned long cr0;
22516
22517 kernel_fpu_begin();
22518
22519@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22520 * but that is for later. -AV
22521 */
22522 __asm__ __volatile__(
22523- "1: prefetch (%0)\n"
22524- " prefetch 64(%0)\n"
22525- " prefetch 128(%0)\n"
22526- " prefetch 192(%0)\n"
22527- " prefetch 256(%0)\n"
22528+ "1: prefetch (%1)\n"
22529+ " prefetch 64(%1)\n"
22530+ " prefetch 128(%1)\n"
22531+ " prefetch 192(%1)\n"
22532+ " prefetch 256(%1)\n"
22533 "2: \n"
22534 ".section .fixup, \"ax\"\n"
22535- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22536+ "3: \n"
22537+
22538+#ifdef CONFIG_PAX_KERNEXEC
22539+ " movl %%cr0, %0\n"
22540+ " movl %0, %%eax\n"
22541+ " andl $0xFFFEFFFF, %%eax\n"
22542+ " movl %%eax, %%cr0\n"
22543+#endif
22544+
22545+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22546+
22547+#ifdef CONFIG_PAX_KERNEXEC
22548+ " movl %0, %%cr0\n"
22549+#endif
22550+
22551 " jmp 2b\n"
22552 ".previous\n"
22553- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22554+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22555
22556 for (i = 0; i < (4096-320)/64; i++) {
22557 __asm__ __volatile__ (
22558- "1: prefetch 320(%0)\n"
22559- "2: movq (%0), %%mm0\n"
22560- " movntq %%mm0, (%1)\n"
22561- " movq 8(%0), %%mm1\n"
22562- " movntq %%mm1, 8(%1)\n"
22563- " movq 16(%0), %%mm2\n"
22564- " movntq %%mm2, 16(%1)\n"
22565- " movq 24(%0), %%mm3\n"
22566- " movntq %%mm3, 24(%1)\n"
22567- " movq 32(%0), %%mm4\n"
22568- " movntq %%mm4, 32(%1)\n"
22569- " movq 40(%0), %%mm5\n"
22570- " movntq %%mm5, 40(%1)\n"
22571- " movq 48(%0), %%mm6\n"
22572- " movntq %%mm6, 48(%1)\n"
22573- " movq 56(%0), %%mm7\n"
22574- " movntq %%mm7, 56(%1)\n"
22575+ "1: prefetch 320(%1)\n"
22576+ "2: movq (%1), %%mm0\n"
22577+ " movntq %%mm0, (%2)\n"
22578+ " movq 8(%1), %%mm1\n"
22579+ " movntq %%mm1, 8(%2)\n"
22580+ " movq 16(%1), %%mm2\n"
22581+ " movntq %%mm2, 16(%2)\n"
22582+ " movq 24(%1), %%mm3\n"
22583+ " movntq %%mm3, 24(%2)\n"
22584+ " movq 32(%1), %%mm4\n"
22585+ " movntq %%mm4, 32(%2)\n"
22586+ " movq 40(%1), %%mm5\n"
22587+ " movntq %%mm5, 40(%2)\n"
22588+ " movq 48(%1), %%mm6\n"
22589+ " movntq %%mm6, 48(%2)\n"
22590+ " movq 56(%1), %%mm7\n"
22591+ " movntq %%mm7, 56(%2)\n"
22592 ".section .fixup, \"ax\"\n"
22593- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22594+ "3:\n"
22595+
22596+#ifdef CONFIG_PAX_KERNEXEC
22597+ " movl %%cr0, %0\n"
22598+ " movl %0, %%eax\n"
22599+ " andl $0xFFFEFFFF, %%eax\n"
22600+ " movl %%eax, %%cr0\n"
22601+#endif
22602+
22603+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22604+
22605+#ifdef CONFIG_PAX_KERNEXEC
22606+ " movl %0, %%cr0\n"
22607+#endif
22608+
22609 " jmp 2b\n"
22610 ".previous\n"
22611- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22612+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22613
22614 from += 64;
22615 to += 64;
22616@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22617 static void fast_copy_page(void *to, void *from)
22618 {
22619 int i;
22620+ unsigned long cr0;
22621
22622 kernel_fpu_begin();
22623
22624 __asm__ __volatile__ (
22625- "1: prefetch (%0)\n"
22626- " prefetch 64(%0)\n"
22627- " prefetch 128(%0)\n"
22628- " prefetch 192(%0)\n"
22629- " prefetch 256(%0)\n"
22630+ "1: prefetch (%1)\n"
22631+ " prefetch 64(%1)\n"
22632+ " prefetch 128(%1)\n"
22633+ " prefetch 192(%1)\n"
22634+ " prefetch 256(%1)\n"
22635 "2: \n"
22636 ".section .fixup, \"ax\"\n"
22637- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22638+ "3: \n"
22639+
22640+#ifdef CONFIG_PAX_KERNEXEC
22641+ " movl %%cr0, %0\n"
22642+ " movl %0, %%eax\n"
22643+ " andl $0xFFFEFFFF, %%eax\n"
22644+ " movl %%eax, %%cr0\n"
22645+#endif
22646+
22647+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22648+
22649+#ifdef CONFIG_PAX_KERNEXEC
22650+ " movl %0, %%cr0\n"
22651+#endif
22652+
22653 " jmp 2b\n"
22654 ".previous\n"
22655- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22656+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22657
22658 for (i = 0; i < 4096/64; i++) {
22659 __asm__ __volatile__ (
22660- "1: prefetch 320(%0)\n"
22661- "2: movq (%0), %%mm0\n"
22662- " movq 8(%0), %%mm1\n"
22663- " movq 16(%0), %%mm2\n"
22664- " movq 24(%0), %%mm3\n"
22665- " movq %%mm0, (%1)\n"
22666- " movq %%mm1, 8(%1)\n"
22667- " movq %%mm2, 16(%1)\n"
22668- " movq %%mm3, 24(%1)\n"
22669- " movq 32(%0), %%mm0\n"
22670- " movq 40(%0), %%mm1\n"
22671- " movq 48(%0), %%mm2\n"
22672- " movq 56(%0), %%mm3\n"
22673- " movq %%mm0, 32(%1)\n"
22674- " movq %%mm1, 40(%1)\n"
22675- " movq %%mm2, 48(%1)\n"
22676- " movq %%mm3, 56(%1)\n"
22677+ "1: prefetch 320(%1)\n"
22678+ "2: movq (%1), %%mm0\n"
22679+ " movq 8(%1), %%mm1\n"
22680+ " movq 16(%1), %%mm2\n"
22681+ " movq 24(%1), %%mm3\n"
22682+ " movq %%mm0, (%2)\n"
22683+ " movq %%mm1, 8(%2)\n"
22684+ " movq %%mm2, 16(%2)\n"
22685+ " movq %%mm3, 24(%2)\n"
22686+ " movq 32(%1), %%mm0\n"
22687+ " movq 40(%1), %%mm1\n"
22688+ " movq 48(%1), %%mm2\n"
22689+ " movq 56(%1), %%mm3\n"
22690+ " movq %%mm0, 32(%2)\n"
22691+ " movq %%mm1, 40(%2)\n"
22692+ " movq %%mm2, 48(%2)\n"
22693+ " movq %%mm3, 56(%2)\n"
22694 ".section .fixup, \"ax\"\n"
22695- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22696+ "3:\n"
22697+
22698+#ifdef CONFIG_PAX_KERNEXEC
22699+ " movl %%cr0, %0\n"
22700+ " movl %0, %%eax\n"
22701+ " andl $0xFFFEFFFF, %%eax\n"
22702+ " movl %%eax, %%cr0\n"
22703+#endif
22704+
22705+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22706+
22707+#ifdef CONFIG_PAX_KERNEXEC
22708+ " movl %0, %%cr0\n"
22709+#endif
22710+
22711 " jmp 2b\n"
22712 ".previous\n"
22713 _ASM_EXTABLE(1b, 3b)
22714- : : "r" (from), "r" (to) : "memory");
22715+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22716
22717 from += 64;
22718 to += 64;
22719diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22720index 69fa106..adda88b 100644
22721--- a/arch/x86/lib/msr-reg.S
22722+++ b/arch/x86/lib/msr-reg.S
22723@@ -3,6 +3,7 @@
22724 #include <asm/dwarf2.h>
22725 #include <asm/asm.h>
22726 #include <asm/msr.h>
22727+#include <asm/alternative-asm.h>
22728
22729 #ifdef CONFIG_X86_64
22730 /*
22731@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22732 CFI_STARTPROC
22733 pushq_cfi %rbx
22734 pushq_cfi %rbp
22735- movq %rdi, %r10 /* Save pointer */
22736+ movq %rdi, %r9 /* Save pointer */
22737 xorl %r11d, %r11d /* Return value */
22738 movl (%rdi), %eax
22739 movl 4(%rdi), %ecx
22740@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22741 movl 28(%rdi), %edi
22742 CFI_REMEMBER_STATE
22743 1: \op
22744-2: movl %eax, (%r10)
22745+2: movl %eax, (%r9)
22746 movl %r11d, %eax /* Return value */
22747- movl %ecx, 4(%r10)
22748- movl %edx, 8(%r10)
22749- movl %ebx, 12(%r10)
22750- movl %ebp, 20(%r10)
22751- movl %esi, 24(%r10)
22752- movl %edi, 28(%r10)
22753+ movl %ecx, 4(%r9)
22754+ movl %edx, 8(%r9)
22755+ movl %ebx, 12(%r9)
22756+ movl %ebp, 20(%r9)
22757+ movl %esi, 24(%r9)
22758+ movl %edi, 28(%r9)
22759 popq_cfi %rbp
22760 popq_cfi %rbx
22761+ pax_force_retaddr
22762 ret
22763 3:
22764 CFI_RESTORE_STATE
22765diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22766index 36b0d15..d381858 100644
22767--- a/arch/x86/lib/putuser.S
22768+++ b/arch/x86/lib/putuser.S
22769@@ -15,7 +15,9 @@
22770 #include <asm/thread_info.h>
22771 #include <asm/errno.h>
22772 #include <asm/asm.h>
22773-
22774+#include <asm/segment.h>
22775+#include <asm/pgtable.h>
22776+#include <asm/alternative-asm.h>
22777
22778 /*
22779 * __put_user_X
22780@@ -29,52 +31,119 @@
22781 * as they get called from within inline assembly.
22782 */
22783
22784-#define ENTER CFI_STARTPROC ; \
22785- GET_THREAD_INFO(%_ASM_BX)
22786-#define EXIT ret ; \
22787+#define ENTER CFI_STARTPROC
22788+#define EXIT pax_force_retaddr; ret ; \
22789 CFI_ENDPROC
22790
22791+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22792+#define _DEST %_ASM_CX,%_ASM_BX
22793+#else
22794+#define _DEST %_ASM_CX
22795+#endif
22796+
22797+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22798+#define __copyuser_seg gs;
22799+#else
22800+#define __copyuser_seg
22801+#endif
22802+
22803 .text
22804 ENTRY(__put_user_1)
22805 ENTER
22806+
22807+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22808+ GET_THREAD_INFO(%_ASM_BX)
22809 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22810 jae bad_put_user
22811-1: movb %al,(%_ASM_CX)
22812+
22813+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22814+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22815+ cmp %_ASM_BX,%_ASM_CX
22816+ jb 1234f
22817+ xor %ebx,%ebx
22818+1234:
22819+#endif
22820+
22821+#endif
22822+
22823+1: __copyuser_seg movb %al,(_DEST)
22824 xor %eax,%eax
22825 EXIT
22826 ENDPROC(__put_user_1)
22827
22828 ENTRY(__put_user_2)
22829 ENTER
22830+
22831+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22832+ GET_THREAD_INFO(%_ASM_BX)
22833 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22834 sub $1,%_ASM_BX
22835 cmp %_ASM_BX,%_ASM_CX
22836 jae bad_put_user
22837-2: movw %ax,(%_ASM_CX)
22838+
22839+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22840+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22841+ cmp %_ASM_BX,%_ASM_CX
22842+ jb 1234f
22843+ xor %ebx,%ebx
22844+1234:
22845+#endif
22846+
22847+#endif
22848+
22849+2: __copyuser_seg movw %ax,(_DEST)
22850 xor %eax,%eax
22851 EXIT
22852 ENDPROC(__put_user_2)
22853
22854 ENTRY(__put_user_4)
22855 ENTER
22856+
22857+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22858+ GET_THREAD_INFO(%_ASM_BX)
22859 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22860 sub $3,%_ASM_BX
22861 cmp %_ASM_BX,%_ASM_CX
22862 jae bad_put_user
22863-3: movl %eax,(%_ASM_CX)
22864+
22865+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22866+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22867+ cmp %_ASM_BX,%_ASM_CX
22868+ jb 1234f
22869+ xor %ebx,%ebx
22870+1234:
22871+#endif
22872+
22873+#endif
22874+
22875+3: __copyuser_seg movl %eax,(_DEST)
22876 xor %eax,%eax
22877 EXIT
22878 ENDPROC(__put_user_4)
22879
22880 ENTRY(__put_user_8)
22881 ENTER
22882+
22883+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22884+ GET_THREAD_INFO(%_ASM_BX)
22885 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22886 sub $7,%_ASM_BX
22887 cmp %_ASM_BX,%_ASM_CX
22888 jae bad_put_user
22889-4: mov %_ASM_AX,(%_ASM_CX)
22890+
22891+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22892+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22893+ cmp %_ASM_BX,%_ASM_CX
22894+ jb 1234f
22895+ xor %ebx,%ebx
22896+1234:
22897+#endif
22898+
22899+#endif
22900+
22901+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22902 #ifdef CONFIG_X86_32
22903-5: movl %edx,4(%_ASM_CX)
22904+5: __copyuser_seg movl %edx,4(_DEST)
22905 #endif
22906 xor %eax,%eax
22907 EXIT
22908diff --git a/arch/x86/lib/rwlock_64.S b/arch/x86/lib/rwlock_64.S
22909index 05ea55f..6345b9a 100644
22910--- a/arch/x86/lib/rwlock_64.S
22911+++ b/arch/x86/lib/rwlock_64.S
22912@@ -2,6 +2,7 @@
22913
22914 #include <linux/linkage.h>
22915 #include <asm/rwlock.h>
22916+#include <asm/asm.h>
22917 #include <asm/alternative-asm.h>
22918 #include <asm/dwarf2.h>
22919
22920@@ -10,13 +11,34 @@ ENTRY(__write_lock_failed)
22921 CFI_STARTPROC
22922 LOCK_PREFIX
22923 addl $RW_LOCK_BIAS,(%rdi)
22924+
22925+#ifdef CONFIG_PAX_REFCOUNT
22926+ jno 1234f
22927+ LOCK_PREFIX
22928+ subl $RW_LOCK_BIAS,(%rdi)
22929+ int $4
22930+1234:
22931+ _ASM_EXTABLE(1234b, 1234b)
22932+#endif
22933+
22934 1: rep
22935 nop
22936 cmpl $RW_LOCK_BIAS,(%rdi)
22937 jne 1b
22938 LOCK_PREFIX
22939 subl $RW_LOCK_BIAS,(%rdi)
22940+
22941+#ifdef CONFIG_PAX_REFCOUNT
22942+ jno 1234f
22943+ LOCK_PREFIX
22944+ addl $RW_LOCK_BIAS,(%rdi)
22945+ int $4
22946+1234:
22947+ _ASM_EXTABLE(1234b, 1234b)
22948+#endif
22949+
22950 jnz __write_lock_failed
22951+ pax_force_retaddr
22952 ret
22953 CFI_ENDPROC
22954 END(__write_lock_failed)
22955@@ -26,13 +48,34 @@ ENTRY(__read_lock_failed)
22956 CFI_STARTPROC
22957 LOCK_PREFIX
22958 incl (%rdi)
22959+
22960+#ifdef CONFIG_PAX_REFCOUNT
22961+ jno 1234f
22962+ LOCK_PREFIX
22963+ decl (%rdi)
22964+ int $4
22965+1234:
22966+ _ASM_EXTABLE(1234b, 1234b)
22967+#endif
22968+
22969 1: rep
22970 nop
22971 cmpl $1,(%rdi)
22972 js 1b
22973 LOCK_PREFIX
22974 decl (%rdi)
22975+
22976+#ifdef CONFIG_PAX_REFCOUNT
22977+ jno 1234f
22978+ LOCK_PREFIX
22979+ incl (%rdi)
22980+ int $4
22981+1234:
22982+ _ASM_EXTABLE(1234b, 1234b)
22983+#endif
22984+
22985 js __read_lock_failed
22986+ pax_force_retaddr
22987 ret
22988 CFI_ENDPROC
22989 END(__read_lock_failed)
22990diff --git a/arch/x86/lib/rwsem_64.S b/arch/x86/lib/rwsem_64.S
22991index 15acecf..f768b10 100644
22992--- a/arch/x86/lib/rwsem_64.S
22993+++ b/arch/x86/lib/rwsem_64.S
22994@@ -48,6 +48,7 @@ ENTRY(call_rwsem_down_read_failed)
22995 call rwsem_down_read_failed
22996 popq %rdx
22997 restore_common_regs
22998+ pax_force_retaddr
22999 ret
23000 ENDPROC(call_rwsem_down_read_failed)
23001
23002@@ -56,6 +57,7 @@ ENTRY(call_rwsem_down_write_failed)
23003 movq %rax,%rdi
23004 call rwsem_down_write_failed
23005 restore_common_regs
23006+ pax_force_retaddr
23007 ret
23008 ENDPROC(call_rwsem_down_write_failed)
23009
23010@@ -66,7 +68,8 @@ ENTRY(call_rwsem_wake)
23011 movq %rax,%rdi
23012 call rwsem_wake
23013 restore_common_regs
23014-1: ret
23015+1: pax_force_retaddr
23016+ ret
23017 ENDPROC(call_rwsem_wake)
23018
23019 /* Fix up special calling conventions */
23020@@ -77,5 +80,6 @@ ENTRY(call_rwsem_downgrade_wake)
23021 call rwsem_downgrade_wake
23022 popq %rdx
23023 restore_common_regs
23024+ pax_force_retaddr
23025 ret
23026 ENDPROC(call_rwsem_downgrade_wake)
23027diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
23028index bf9a7d5..fb06ab5 100644
23029--- a/arch/x86/lib/thunk_64.S
23030+++ b/arch/x86/lib/thunk_64.S
23031@@ -10,7 +10,8 @@
23032 #include <asm/dwarf2.h>
23033 #include <asm/calling.h>
23034 #include <asm/rwlock.h>
23035-
23036+ #include <asm/alternative-asm.h>
23037+
23038 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
23039 .macro thunk name,func
23040 .globl \name
23041@@ -70,6 +71,7 @@
23042 SAVE_ARGS
23043 restore:
23044 RESTORE_ARGS
23045+ pax_force_retaddr
23046 ret
23047 CFI_ENDPROC
23048
23049@@ -77,5 +79,6 @@ restore:
23050 SAVE_ARGS
23051 restore_norax:
23052 RESTORE_ARGS 1
23053+ pax_force_retaddr
23054 ret
23055 CFI_ENDPROC
23056diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
23057index 1f118d4..ec4a953 100644
23058--- a/arch/x86/lib/usercopy_32.c
23059+++ b/arch/x86/lib/usercopy_32.c
23060@@ -43,7 +43,7 @@ do { \
23061 __asm__ __volatile__( \
23062 " testl %1,%1\n" \
23063 " jz 2f\n" \
23064- "0: lodsb\n" \
23065+ "0: "__copyuser_seg"lodsb\n" \
23066 " stosb\n" \
23067 " testb %%al,%%al\n" \
23068 " jz 1f\n" \
23069@@ -128,10 +128,12 @@ do { \
23070 int __d0; \
23071 might_fault(); \
23072 __asm__ __volatile__( \
23073+ __COPYUSER_SET_ES \
23074 "0: rep; stosl\n" \
23075 " movl %2,%0\n" \
23076 "1: rep; stosb\n" \
23077 "2:\n" \
23078+ __COPYUSER_RESTORE_ES \
23079 ".section .fixup,\"ax\"\n" \
23080 "3: lea 0(%2,%0,4),%0\n" \
23081 " jmp 2b\n" \
23082@@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
23083 might_fault();
23084
23085 __asm__ __volatile__(
23086+ __COPYUSER_SET_ES
23087 " testl %0, %0\n"
23088 " jz 3f\n"
23089 " andl %0,%%ecx\n"
23090@@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
23091 " subl %%ecx,%0\n"
23092 " addl %0,%%eax\n"
23093 "1:\n"
23094+ __COPYUSER_RESTORE_ES
23095 ".section .fixup,\"ax\"\n"
23096 "2: xorl %%eax,%%eax\n"
23097 " jmp 1b\n"
23098@@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
23099
23100 #ifdef CONFIG_X86_INTEL_USERCOPY
23101 static unsigned long
23102-__copy_user_intel(void __user *to, const void *from, unsigned long size)
23103+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
23104 {
23105 int d0, d1;
23106 __asm__ __volatile__(
23107@@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23108 " .align 2,0x90\n"
23109 "3: movl 0(%4), %%eax\n"
23110 "4: movl 4(%4), %%edx\n"
23111- "5: movl %%eax, 0(%3)\n"
23112- "6: movl %%edx, 4(%3)\n"
23113+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
23114+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
23115 "7: movl 8(%4), %%eax\n"
23116 "8: movl 12(%4),%%edx\n"
23117- "9: movl %%eax, 8(%3)\n"
23118- "10: movl %%edx, 12(%3)\n"
23119+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
23120+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
23121 "11: movl 16(%4), %%eax\n"
23122 "12: movl 20(%4), %%edx\n"
23123- "13: movl %%eax, 16(%3)\n"
23124- "14: movl %%edx, 20(%3)\n"
23125+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
23126+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
23127 "15: movl 24(%4), %%eax\n"
23128 "16: movl 28(%4), %%edx\n"
23129- "17: movl %%eax, 24(%3)\n"
23130- "18: movl %%edx, 28(%3)\n"
23131+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23132+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23133 "19: movl 32(%4), %%eax\n"
23134 "20: movl 36(%4), %%edx\n"
23135- "21: movl %%eax, 32(%3)\n"
23136- "22: movl %%edx, 36(%3)\n"
23137+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23138+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23139 "23: movl 40(%4), %%eax\n"
23140 "24: movl 44(%4), %%edx\n"
23141- "25: movl %%eax, 40(%3)\n"
23142- "26: movl %%edx, 44(%3)\n"
23143+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23144+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23145 "27: movl 48(%4), %%eax\n"
23146 "28: movl 52(%4), %%edx\n"
23147- "29: movl %%eax, 48(%3)\n"
23148- "30: movl %%edx, 52(%3)\n"
23149+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23150+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23151 "31: movl 56(%4), %%eax\n"
23152 "32: movl 60(%4), %%edx\n"
23153- "33: movl %%eax, 56(%3)\n"
23154- "34: movl %%edx, 60(%3)\n"
23155+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23156+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23157 " addl $-64, %0\n"
23158 " addl $64, %4\n"
23159 " addl $64, %3\n"
23160@@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23161 " shrl $2, %0\n"
23162 " andl $3, %%eax\n"
23163 " cld\n"
23164+ __COPYUSER_SET_ES
23165 "99: rep; movsl\n"
23166 "36: movl %%eax, %0\n"
23167 "37: rep; movsb\n"
23168 "100:\n"
23169+ __COPYUSER_RESTORE_ES
23170+ ".section .fixup,\"ax\"\n"
23171+ "101: lea 0(%%eax,%0,4),%0\n"
23172+ " jmp 100b\n"
23173+ ".previous\n"
23174+ ".section __ex_table,\"a\"\n"
23175+ " .align 4\n"
23176+ " .long 1b,100b\n"
23177+ " .long 2b,100b\n"
23178+ " .long 3b,100b\n"
23179+ " .long 4b,100b\n"
23180+ " .long 5b,100b\n"
23181+ " .long 6b,100b\n"
23182+ " .long 7b,100b\n"
23183+ " .long 8b,100b\n"
23184+ " .long 9b,100b\n"
23185+ " .long 10b,100b\n"
23186+ " .long 11b,100b\n"
23187+ " .long 12b,100b\n"
23188+ " .long 13b,100b\n"
23189+ " .long 14b,100b\n"
23190+ " .long 15b,100b\n"
23191+ " .long 16b,100b\n"
23192+ " .long 17b,100b\n"
23193+ " .long 18b,100b\n"
23194+ " .long 19b,100b\n"
23195+ " .long 20b,100b\n"
23196+ " .long 21b,100b\n"
23197+ " .long 22b,100b\n"
23198+ " .long 23b,100b\n"
23199+ " .long 24b,100b\n"
23200+ " .long 25b,100b\n"
23201+ " .long 26b,100b\n"
23202+ " .long 27b,100b\n"
23203+ " .long 28b,100b\n"
23204+ " .long 29b,100b\n"
23205+ " .long 30b,100b\n"
23206+ " .long 31b,100b\n"
23207+ " .long 32b,100b\n"
23208+ " .long 33b,100b\n"
23209+ " .long 34b,100b\n"
23210+ " .long 35b,100b\n"
23211+ " .long 36b,100b\n"
23212+ " .long 37b,100b\n"
23213+ " .long 99b,101b\n"
23214+ ".previous"
23215+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23216+ : "1"(to), "2"(from), "0"(size)
23217+ : "eax", "edx", "memory");
23218+ return size;
23219+}
23220+
23221+static unsigned long
23222+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23223+{
23224+ int d0, d1;
23225+ __asm__ __volatile__(
23226+ " .align 2,0x90\n"
23227+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23228+ " cmpl $67, %0\n"
23229+ " jbe 3f\n"
23230+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23231+ " .align 2,0x90\n"
23232+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23233+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23234+ "5: movl %%eax, 0(%3)\n"
23235+ "6: movl %%edx, 4(%3)\n"
23236+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23237+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23238+ "9: movl %%eax, 8(%3)\n"
23239+ "10: movl %%edx, 12(%3)\n"
23240+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23241+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23242+ "13: movl %%eax, 16(%3)\n"
23243+ "14: movl %%edx, 20(%3)\n"
23244+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23245+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23246+ "17: movl %%eax, 24(%3)\n"
23247+ "18: movl %%edx, 28(%3)\n"
23248+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23249+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23250+ "21: movl %%eax, 32(%3)\n"
23251+ "22: movl %%edx, 36(%3)\n"
23252+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23253+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23254+ "25: movl %%eax, 40(%3)\n"
23255+ "26: movl %%edx, 44(%3)\n"
23256+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23257+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23258+ "29: movl %%eax, 48(%3)\n"
23259+ "30: movl %%edx, 52(%3)\n"
23260+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23261+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23262+ "33: movl %%eax, 56(%3)\n"
23263+ "34: movl %%edx, 60(%3)\n"
23264+ " addl $-64, %0\n"
23265+ " addl $64, %4\n"
23266+ " addl $64, %3\n"
23267+ " cmpl $63, %0\n"
23268+ " ja 1b\n"
23269+ "35: movl %0, %%eax\n"
23270+ " shrl $2, %0\n"
23271+ " andl $3, %%eax\n"
23272+ " cld\n"
23273+ "99: rep; "__copyuser_seg" movsl\n"
23274+ "36: movl %%eax, %0\n"
23275+ "37: rep; "__copyuser_seg" movsb\n"
23276+ "100:\n"
23277 ".section .fixup,\"ax\"\n"
23278 "101: lea 0(%%eax,%0,4),%0\n"
23279 " jmp 100b\n"
23280@@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23281 int d0, d1;
23282 __asm__ __volatile__(
23283 " .align 2,0x90\n"
23284- "0: movl 32(%4), %%eax\n"
23285+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23286 " cmpl $67, %0\n"
23287 " jbe 2f\n"
23288- "1: movl 64(%4), %%eax\n"
23289+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23290 " .align 2,0x90\n"
23291- "2: movl 0(%4), %%eax\n"
23292- "21: movl 4(%4), %%edx\n"
23293+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23294+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23295 " movl %%eax, 0(%3)\n"
23296 " movl %%edx, 4(%3)\n"
23297- "3: movl 8(%4), %%eax\n"
23298- "31: movl 12(%4),%%edx\n"
23299+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23300+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23301 " movl %%eax, 8(%3)\n"
23302 " movl %%edx, 12(%3)\n"
23303- "4: movl 16(%4), %%eax\n"
23304- "41: movl 20(%4), %%edx\n"
23305+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23306+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23307 " movl %%eax, 16(%3)\n"
23308 " movl %%edx, 20(%3)\n"
23309- "10: movl 24(%4), %%eax\n"
23310- "51: movl 28(%4), %%edx\n"
23311+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23312+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23313 " movl %%eax, 24(%3)\n"
23314 " movl %%edx, 28(%3)\n"
23315- "11: movl 32(%4), %%eax\n"
23316- "61: movl 36(%4), %%edx\n"
23317+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23318+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23319 " movl %%eax, 32(%3)\n"
23320 " movl %%edx, 36(%3)\n"
23321- "12: movl 40(%4), %%eax\n"
23322- "71: movl 44(%4), %%edx\n"
23323+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23324+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23325 " movl %%eax, 40(%3)\n"
23326 " movl %%edx, 44(%3)\n"
23327- "13: movl 48(%4), %%eax\n"
23328- "81: movl 52(%4), %%edx\n"
23329+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23330+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23331 " movl %%eax, 48(%3)\n"
23332 " movl %%edx, 52(%3)\n"
23333- "14: movl 56(%4), %%eax\n"
23334- "91: movl 60(%4), %%edx\n"
23335+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23336+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23337 " movl %%eax, 56(%3)\n"
23338 " movl %%edx, 60(%3)\n"
23339 " addl $-64, %0\n"
23340@@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23341 " shrl $2, %0\n"
23342 " andl $3, %%eax\n"
23343 " cld\n"
23344- "6: rep; movsl\n"
23345+ "6: rep; "__copyuser_seg" movsl\n"
23346 " movl %%eax,%0\n"
23347- "7: rep; movsb\n"
23348+ "7: rep; "__copyuser_seg" movsb\n"
23349 "8:\n"
23350 ".section .fixup,\"ax\"\n"
23351 "9: lea 0(%%eax,%0,4),%0\n"
23352@@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23353
23354 __asm__ __volatile__(
23355 " .align 2,0x90\n"
23356- "0: movl 32(%4), %%eax\n"
23357+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23358 " cmpl $67, %0\n"
23359 " jbe 2f\n"
23360- "1: movl 64(%4), %%eax\n"
23361+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23362 " .align 2,0x90\n"
23363- "2: movl 0(%4), %%eax\n"
23364- "21: movl 4(%4), %%edx\n"
23365+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23366+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23367 " movnti %%eax, 0(%3)\n"
23368 " movnti %%edx, 4(%3)\n"
23369- "3: movl 8(%4), %%eax\n"
23370- "31: movl 12(%4),%%edx\n"
23371+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23372+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23373 " movnti %%eax, 8(%3)\n"
23374 " movnti %%edx, 12(%3)\n"
23375- "4: movl 16(%4), %%eax\n"
23376- "41: movl 20(%4), %%edx\n"
23377+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23378+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23379 " movnti %%eax, 16(%3)\n"
23380 " movnti %%edx, 20(%3)\n"
23381- "10: movl 24(%4), %%eax\n"
23382- "51: movl 28(%4), %%edx\n"
23383+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23384+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23385 " movnti %%eax, 24(%3)\n"
23386 " movnti %%edx, 28(%3)\n"
23387- "11: movl 32(%4), %%eax\n"
23388- "61: movl 36(%4), %%edx\n"
23389+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23390+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23391 " movnti %%eax, 32(%3)\n"
23392 " movnti %%edx, 36(%3)\n"
23393- "12: movl 40(%4), %%eax\n"
23394- "71: movl 44(%4), %%edx\n"
23395+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23396+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23397 " movnti %%eax, 40(%3)\n"
23398 " movnti %%edx, 44(%3)\n"
23399- "13: movl 48(%4), %%eax\n"
23400- "81: movl 52(%4), %%edx\n"
23401+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23402+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23403 " movnti %%eax, 48(%3)\n"
23404 " movnti %%edx, 52(%3)\n"
23405- "14: movl 56(%4), %%eax\n"
23406- "91: movl 60(%4), %%edx\n"
23407+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23408+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23409 " movnti %%eax, 56(%3)\n"
23410 " movnti %%edx, 60(%3)\n"
23411 " addl $-64, %0\n"
23412@@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23413 " shrl $2, %0\n"
23414 " andl $3, %%eax\n"
23415 " cld\n"
23416- "6: rep; movsl\n"
23417+ "6: rep; "__copyuser_seg" movsl\n"
23418 " movl %%eax,%0\n"
23419- "7: rep; movsb\n"
23420+ "7: rep; "__copyuser_seg" movsb\n"
23421 "8:\n"
23422 ".section .fixup,\"ax\"\n"
23423 "9: lea 0(%%eax,%0,4),%0\n"
23424@@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
23425
23426 __asm__ __volatile__(
23427 " .align 2,0x90\n"
23428- "0: movl 32(%4), %%eax\n"
23429+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23430 " cmpl $67, %0\n"
23431 " jbe 2f\n"
23432- "1: movl 64(%4), %%eax\n"
23433+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23434 " .align 2,0x90\n"
23435- "2: movl 0(%4), %%eax\n"
23436- "21: movl 4(%4), %%edx\n"
23437+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23438+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23439 " movnti %%eax, 0(%3)\n"
23440 " movnti %%edx, 4(%3)\n"
23441- "3: movl 8(%4), %%eax\n"
23442- "31: movl 12(%4),%%edx\n"
23443+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23444+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23445 " movnti %%eax, 8(%3)\n"
23446 " movnti %%edx, 12(%3)\n"
23447- "4: movl 16(%4), %%eax\n"
23448- "41: movl 20(%4), %%edx\n"
23449+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23450+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23451 " movnti %%eax, 16(%3)\n"
23452 " movnti %%edx, 20(%3)\n"
23453- "10: movl 24(%4), %%eax\n"
23454- "51: movl 28(%4), %%edx\n"
23455+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23456+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23457 " movnti %%eax, 24(%3)\n"
23458 " movnti %%edx, 28(%3)\n"
23459- "11: movl 32(%4), %%eax\n"
23460- "61: movl 36(%4), %%edx\n"
23461+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23462+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23463 " movnti %%eax, 32(%3)\n"
23464 " movnti %%edx, 36(%3)\n"
23465- "12: movl 40(%4), %%eax\n"
23466- "71: movl 44(%4), %%edx\n"
23467+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23468+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23469 " movnti %%eax, 40(%3)\n"
23470 " movnti %%edx, 44(%3)\n"
23471- "13: movl 48(%4), %%eax\n"
23472- "81: movl 52(%4), %%edx\n"
23473+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23474+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23475 " movnti %%eax, 48(%3)\n"
23476 " movnti %%edx, 52(%3)\n"
23477- "14: movl 56(%4), %%eax\n"
23478- "91: movl 60(%4), %%edx\n"
23479+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23480+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23481 " movnti %%eax, 56(%3)\n"
23482 " movnti %%edx, 60(%3)\n"
23483 " addl $-64, %0\n"
23484@@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23485 " shrl $2, %0\n"
23486 " andl $3, %%eax\n"
23487 " cld\n"
23488- "6: rep; movsl\n"
23489+ "6: rep; "__copyuser_seg" movsl\n"
23490 " movl %%eax,%0\n"
23491- "7: rep; movsb\n"
23492+ "7: rep; "__copyuser_seg" movsb\n"
23493 "8:\n"
23494 ".section .fixup,\"ax\"\n"
23495 "9: lea 0(%%eax,%0,4),%0\n"
23496@@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23497 */
23498 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23499 unsigned long size);
23500-unsigned long __copy_user_intel(void __user *to, const void *from,
23501+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23502+ unsigned long size);
23503+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23504 unsigned long size);
23505 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23506 const void __user *from, unsigned long size);
23507 #endif /* CONFIG_X86_INTEL_USERCOPY */
23508
23509 /* Generic arbitrary sized copy. */
23510-#define __copy_user(to, from, size) \
23511+#define __copy_user(to, from, size, prefix, set, restore) \
23512 do { \
23513 int __d0, __d1, __d2; \
23514 __asm__ __volatile__( \
23515+ set \
23516 " cmp $7,%0\n" \
23517 " jbe 1f\n" \
23518 " movl %1,%0\n" \
23519 " negl %0\n" \
23520 " andl $7,%0\n" \
23521 " subl %0,%3\n" \
23522- "4: rep; movsb\n" \
23523+ "4: rep; "prefix"movsb\n" \
23524 " movl %3,%0\n" \
23525 " shrl $2,%0\n" \
23526 " andl $3,%3\n" \
23527 " .align 2,0x90\n" \
23528- "0: rep; movsl\n" \
23529+ "0: rep; "prefix"movsl\n" \
23530 " movl %3,%0\n" \
23531- "1: rep; movsb\n" \
23532+ "1: rep; "prefix"movsb\n" \
23533 "2:\n" \
23534+ restore \
23535 ".section .fixup,\"ax\"\n" \
23536 "5: addl %3,%0\n" \
23537 " jmp 2b\n" \
23538@@ -682,14 +799,14 @@ do { \
23539 " negl %0\n" \
23540 " andl $7,%0\n" \
23541 " subl %0,%3\n" \
23542- "4: rep; movsb\n" \
23543+ "4: rep; "__copyuser_seg"movsb\n" \
23544 " movl %3,%0\n" \
23545 " shrl $2,%0\n" \
23546 " andl $3,%3\n" \
23547 " .align 2,0x90\n" \
23548- "0: rep; movsl\n" \
23549+ "0: rep; "__copyuser_seg"movsl\n" \
23550 " movl %3,%0\n" \
23551- "1: rep; movsb\n" \
23552+ "1: rep; "__copyuser_seg"movsb\n" \
23553 "2:\n" \
23554 ".section .fixup,\"ax\"\n" \
23555 "5: addl %3,%0\n" \
23556@@ -775,9 +892,9 @@ survive:
23557 }
23558 #endif
23559 if (movsl_is_ok(to, from, n))
23560- __copy_user(to, from, n);
23561+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23562 else
23563- n = __copy_user_intel(to, from, n);
23564+ n = __generic_copy_to_user_intel(to, from, n);
23565 return n;
23566 }
23567 EXPORT_SYMBOL(__copy_to_user_ll);
23568@@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23569 unsigned long n)
23570 {
23571 if (movsl_is_ok(to, from, n))
23572- __copy_user(to, from, n);
23573+ __copy_user(to, from, n, __copyuser_seg, "", "");
23574 else
23575- n = __copy_user_intel((void __user *)to,
23576- (const void *)from, n);
23577+ n = __generic_copy_from_user_intel(to, from, n);
23578 return n;
23579 }
23580 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23581@@ -827,59 +943,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23582 if (n > 64 && cpu_has_xmm2)
23583 n = __copy_user_intel_nocache(to, from, n);
23584 else
23585- __copy_user(to, from, n);
23586+ __copy_user(to, from, n, __copyuser_seg, "", "");
23587 #else
23588- __copy_user(to, from, n);
23589+ __copy_user(to, from, n, __copyuser_seg, "", "");
23590 #endif
23591 return n;
23592 }
23593 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23594
23595-/**
23596- * copy_to_user: - Copy a block of data into user space.
23597- * @to: Destination address, in user space.
23598- * @from: Source address, in kernel space.
23599- * @n: Number of bytes to copy.
23600- *
23601- * Context: User context only. This function may sleep.
23602- *
23603- * Copy data from kernel space to user space.
23604- *
23605- * Returns number of bytes that could not be copied.
23606- * On success, this will be zero.
23607- */
23608-unsigned long
23609-copy_to_user(void __user *to, const void *from, unsigned long n)
23610+#ifdef CONFIG_PAX_MEMORY_UDEREF
23611+void __set_fs(mm_segment_t x)
23612 {
23613- if (access_ok(VERIFY_WRITE, to, n))
23614- n = __copy_to_user(to, from, n);
23615- return n;
23616+ switch (x.seg) {
23617+ case 0:
23618+ loadsegment(gs, 0);
23619+ break;
23620+ case TASK_SIZE_MAX:
23621+ loadsegment(gs, __USER_DS);
23622+ break;
23623+ case -1UL:
23624+ loadsegment(gs, __KERNEL_DS);
23625+ break;
23626+ default:
23627+ BUG();
23628+ }
23629+ return;
23630 }
23631-EXPORT_SYMBOL(copy_to_user);
23632+EXPORT_SYMBOL(__set_fs);
23633
23634-/**
23635- * copy_from_user: - Copy a block of data from user space.
23636- * @to: Destination address, in kernel space.
23637- * @from: Source address, in user space.
23638- * @n: Number of bytes to copy.
23639- *
23640- * Context: User context only. This function may sleep.
23641- *
23642- * Copy data from user space to kernel space.
23643- *
23644- * Returns number of bytes that could not be copied.
23645- * On success, this will be zero.
23646- *
23647- * If some data could not be copied, this function will pad the copied
23648- * data to the requested size using zero bytes.
23649- */
23650-unsigned long
23651-copy_from_user(void *to, const void __user *from, unsigned long n)
23652+void set_fs(mm_segment_t x)
23653 {
23654- if (access_ok(VERIFY_READ, from, n))
23655- n = __copy_from_user(to, from, n);
23656- else
23657- memset(to, 0, n);
23658- return n;
23659+ current_thread_info()->addr_limit = x;
23660+ __set_fs(x);
23661 }
23662-EXPORT_SYMBOL(copy_from_user);
23663+EXPORT_SYMBOL(set_fs);
23664+#endif
23665diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23666index b7c2849..8633ad8 100644
23667--- a/arch/x86/lib/usercopy_64.c
23668+++ b/arch/x86/lib/usercopy_64.c
23669@@ -42,6 +42,12 @@ long
23670 __strncpy_from_user(char *dst, const char __user *src, long count)
23671 {
23672 long res;
23673+
23674+#ifdef CONFIG_PAX_MEMORY_UDEREF
23675+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23676+ src += PAX_USER_SHADOW_BASE;
23677+#endif
23678+
23679 __do_strncpy_from_user(dst, src, count, res);
23680 return res;
23681 }
23682@@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23683 {
23684 long __d0;
23685 might_fault();
23686+
23687+#ifdef CONFIG_PAX_MEMORY_UDEREF
23688+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23689+ addr += PAX_USER_SHADOW_BASE;
23690+#endif
23691+
23692 /* no memory constraint because it doesn't change any memory gcc knows
23693 about */
23694 asm volatile(
23695@@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23696 }
23697 EXPORT_SYMBOL(strlen_user);
23698
23699-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23700+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23701 {
23702- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23703- return copy_user_generic((__force void *)to, (__force void *)from, len);
23704- }
23705- return len;
23706+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23707+
23708+#ifdef CONFIG_PAX_MEMORY_UDEREF
23709+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23710+ to += PAX_USER_SHADOW_BASE;
23711+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23712+ from += PAX_USER_SHADOW_BASE;
23713+#endif
23714+
23715+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23716+ }
23717+ return len;
23718 }
23719 EXPORT_SYMBOL(copy_in_user);
23720
23721@@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
23722 * it is not necessary to optimize tail handling.
23723 */
23724 unsigned long
23725-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23726+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23727 {
23728 char c;
23729 unsigned zero_len;
23730diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23731index 61b41ca..5fef66a 100644
23732--- a/arch/x86/mm/extable.c
23733+++ b/arch/x86/mm/extable.c
23734@@ -1,14 +1,71 @@
23735 #include <linux/module.h>
23736 #include <linux/spinlock.h>
23737+#include <linux/sort.h>
23738 #include <asm/uaccess.h>
23739+#include <asm/pgtable.h>
23740
23741+/*
23742+ * The exception table needs to be sorted so that the binary
23743+ * search that we use to find entries in it works properly.
23744+ * This is used both for the kernel exception table and for
23745+ * the exception tables of modules that get loaded.
23746+ */
23747+static int cmp_ex(const void *a, const void *b)
23748+{
23749+ const struct exception_table_entry *x = a, *y = b;
23750+
23751+ /* avoid overflow */
23752+ if (x->insn > y->insn)
23753+ return 1;
23754+ if (x->insn < y->insn)
23755+ return -1;
23756+ return 0;
23757+}
23758+
23759+static void swap_ex(void *a, void *b, int size)
23760+{
23761+ struct exception_table_entry t, *x = a, *y = b;
23762+
23763+ t = *x;
23764+
23765+ pax_open_kernel();
23766+ *x = *y;
23767+ *y = t;
23768+ pax_close_kernel();
23769+}
23770+
23771+void sort_extable(struct exception_table_entry *start,
23772+ struct exception_table_entry *finish)
23773+{
23774+ sort(start, finish - start, sizeof(struct exception_table_entry),
23775+ cmp_ex, swap_ex);
23776+}
23777+
23778+#ifdef CONFIG_MODULES
23779+/*
23780+ * If the exception table is sorted, any referring to the module init
23781+ * will be at the beginning or the end.
23782+ */
23783+void trim_init_extable(struct module *m)
23784+{
23785+ /*trim the beginning*/
23786+ while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
23787+ m->extable++;
23788+ m->num_exentries--;
23789+ }
23790+ /*trim the end*/
23791+ while (m->num_exentries &&
23792+ within_module_init(m->extable[m->num_exentries-1].insn, m))
23793+ m->num_exentries--;
23794+}
23795+#endif /* CONFIG_MODULES */
23796
23797 int fixup_exception(struct pt_regs *regs)
23798 {
23799 const struct exception_table_entry *fixup;
23800
23801 #ifdef CONFIG_PNPBIOS
23802- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23803+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23804 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23805 extern u32 pnp_bios_is_utter_crap;
23806 pnp_bios_is_utter_crap = 1;
23807diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23808index 8ac0d76..87899a4 100644
23809--- a/arch/x86/mm/fault.c
23810+++ b/arch/x86/mm/fault.c
23811@@ -11,10 +11,19 @@
23812 #include <linux/kprobes.h> /* __kprobes, ... */
23813 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
23814 #include <linux/perf_event.h> /* perf_sw_event */
23815+#include <linux/unistd.h>
23816+#include <linux/compiler.h>
23817
23818 #include <asm/traps.h> /* dotraplinkage, ... */
23819 #include <asm/pgalloc.h> /* pgd_*(), ... */
23820 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23821+#include <asm/vsyscall.h>
23822+#include <asm/tlbflush.h>
23823+
23824+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23825+#include <asm/stacktrace.h>
23826+#include "../kernel/dumpstack.h"
23827+#endif
23828
23829 /*
23830 * Page fault error code bits:
23831@@ -51,7 +60,7 @@ static inline int notify_page_fault(struct pt_regs *regs)
23832 int ret = 0;
23833
23834 /* kprobe_running() needs smp_processor_id() */
23835- if (kprobes_built_in() && !user_mode_vm(regs)) {
23836+ if (kprobes_built_in() && !user_mode(regs)) {
23837 preempt_disable();
23838 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23839 ret = 1;
23840@@ -112,7 +121,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23841 return !instr_lo || (instr_lo>>1) == 1;
23842 case 0x00:
23843 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23844- if (probe_kernel_address(instr, opcode))
23845+ if (user_mode(regs)) {
23846+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23847+ return 0;
23848+ } else if (probe_kernel_address(instr, opcode))
23849 return 0;
23850
23851 *prefetch = (instr_lo == 0xF) &&
23852@@ -146,7 +158,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23853 while (instr < max_instr) {
23854 unsigned char opcode;
23855
23856- if (probe_kernel_address(instr, opcode))
23857+ if (user_mode(regs)) {
23858+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23859+ break;
23860+ } else if (probe_kernel_address(instr, opcode))
23861 break;
23862
23863 instr++;
23864@@ -172,6 +187,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23865 force_sig_info(si_signo, &info, tsk);
23866 }
23867
23868+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23869+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23870+#endif
23871+
23872+#ifdef CONFIG_PAX_EMUTRAMP
23873+static int pax_handle_fetch_fault(struct pt_regs *regs);
23874+#endif
23875+
23876+#ifdef CONFIG_PAX_PAGEEXEC
23877+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23878+{
23879+ pgd_t *pgd;
23880+ pud_t *pud;
23881+ pmd_t *pmd;
23882+
23883+ pgd = pgd_offset(mm, address);
23884+ if (!pgd_present(*pgd))
23885+ return NULL;
23886+ pud = pud_offset(pgd, address);
23887+ if (!pud_present(*pud))
23888+ return NULL;
23889+ pmd = pmd_offset(pud, address);
23890+ if (!pmd_present(*pmd))
23891+ return NULL;
23892+ return pmd;
23893+}
23894+#endif
23895+
23896 DEFINE_SPINLOCK(pgd_lock);
23897 LIST_HEAD(pgd_list);
23898
23899@@ -224,11 +267,24 @@ void vmalloc_sync_all(void)
23900 address += PMD_SIZE) {
23901
23902 unsigned long flags;
23903+
23904+#ifdef CONFIG_PAX_PER_CPU_PGD
23905+ unsigned long cpu;
23906+#else
23907 struct page *page;
23908+#endif
23909
23910 spin_lock_irqsave(&pgd_lock, flags);
23911+
23912+#ifdef CONFIG_PAX_PER_CPU_PGD
23913+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
23914+ pgd_t *pgd = get_cpu_pgd(cpu);
23915+#else
23916 list_for_each_entry(page, &pgd_list, lru) {
23917- if (!vmalloc_sync_one(page_address(page), address))
23918+ pgd_t *pgd = page_address(page);
23919+#endif
23920+
23921+ if (!vmalloc_sync_one(pgd, address))
23922 break;
23923 }
23924 spin_unlock_irqrestore(&pgd_lock, flags);
23925@@ -258,6 +314,11 @@ static noinline int vmalloc_fault(unsigned long address)
23926 * an interrupt in the middle of a task switch..
23927 */
23928 pgd_paddr = read_cr3();
23929+
23930+#ifdef CONFIG_PAX_PER_CPU_PGD
23931+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23932+#endif
23933+
23934 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23935 if (!pmd_k)
23936 return -1;
23937@@ -332,15 +393,27 @@ void vmalloc_sync_all(void)
23938
23939 const pgd_t *pgd_ref = pgd_offset_k(address);
23940 unsigned long flags;
23941+
23942+#ifdef CONFIG_PAX_PER_CPU_PGD
23943+ unsigned long cpu;
23944+#else
23945 struct page *page;
23946+#endif
23947
23948 if (pgd_none(*pgd_ref))
23949 continue;
23950
23951 spin_lock_irqsave(&pgd_lock, flags);
23952+
23953+#ifdef CONFIG_PAX_PER_CPU_PGD
23954+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
23955+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
23956+#else
23957 list_for_each_entry(page, &pgd_list, lru) {
23958 pgd_t *pgd;
23959 pgd = (pgd_t *)page_address(page) + pgd_index(address);
23960+#endif
23961+
23962 if (pgd_none(*pgd))
23963 set_pgd(pgd, *pgd_ref);
23964 else
23965@@ -373,7 +446,14 @@ static noinline int vmalloc_fault(unsigned long address)
23966 * happen within a race in page table update. In the later
23967 * case just flush:
23968 */
23969+
23970+#ifdef CONFIG_PAX_PER_CPU_PGD
23971+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23972+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23973+#else
23974 pgd = pgd_offset(current->active_mm, address);
23975+#endif
23976+
23977 pgd_ref = pgd_offset_k(address);
23978 if (pgd_none(*pgd_ref))
23979 return -1;
23980@@ -535,7 +615,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23981 static int is_errata100(struct pt_regs *regs, unsigned long address)
23982 {
23983 #ifdef CONFIG_X86_64
23984- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23985+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23986 return 1;
23987 #endif
23988 return 0;
23989@@ -562,7 +642,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23990 }
23991
23992 static const char nx_warning[] = KERN_CRIT
23993-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23994+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23995
23996 static void
23997 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23998@@ -571,15 +651,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23999 if (!oops_may_print())
24000 return;
24001
24002- if (error_code & PF_INSTR) {
24003+ if (nx_enabled && (error_code & PF_INSTR)) {
24004 unsigned int level;
24005
24006 pte_t *pte = lookup_address(address, &level);
24007
24008 if (pte && pte_present(*pte) && !pte_exec(*pte))
24009- printk(nx_warning, current_uid());
24010+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
24011 }
24012
24013+#ifdef CONFIG_PAX_KERNEXEC
24014+ if (init_mm.start_code <= address && address < init_mm.end_code) {
24015+ if (current->signal->curr_ip)
24016+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
24017+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
24018+ else
24019+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
24020+ current->comm, task_pid_nr(current), current_uid(), current_euid());
24021+ }
24022+#endif
24023+
24024 printk(KERN_ALERT "BUG: unable to handle kernel ");
24025 if (address < PAGE_SIZE)
24026 printk(KERN_CONT "NULL pointer dereference");
24027@@ -705,6 +796,23 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
24028 {
24029 struct task_struct *tsk = current;
24030
24031+#ifdef CONFIG_X86_64
24032+ struct mm_struct *mm = tsk->mm;
24033+
24034+ if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
24035+ if (regs->ip == (unsigned long)vgettimeofday) {
24036+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
24037+ return;
24038+ } else if (regs->ip == (unsigned long)vtime) {
24039+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
24040+ return;
24041+ } else if (regs->ip == (unsigned long)vgetcpu) {
24042+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
24043+ return;
24044+ }
24045+ }
24046+#endif
24047+
24048 /* User mode accesses just cause a SIGSEGV */
24049 if (error_code & PF_USER) {
24050 /*
24051@@ -722,6 +830,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
24052 if (is_errata100(regs, address))
24053 return;
24054
24055+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24056+ if (pax_is_fetch_fault(regs, error_code, address)) {
24057+
24058+#ifdef CONFIG_PAX_EMUTRAMP
24059+ switch (pax_handle_fetch_fault(regs)) {
24060+ case 2:
24061+ return;
24062+ }
24063+#endif
24064+
24065+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24066+ do_group_exit(SIGKILL);
24067+ }
24068+#endif
24069+
24070 if (unlikely(show_unhandled_signals))
24071 show_signal_msg(regs, error_code, address, tsk);
24072
24073@@ -818,7 +941,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
24074 if (fault & VM_FAULT_HWPOISON) {
24075 printk(KERN_ERR
24076 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
24077- tsk->comm, tsk->pid, address);
24078+ tsk->comm, task_pid_nr(tsk), address);
24079 code = BUS_MCEERR_AR;
24080 }
24081 #endif
24082@@ -857,6 +980,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
24083 return 1;
24084 }
24085
24086+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24087+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
24088+{
24089+ pte_t *pte;
24090+ pmd_t *pmd;
24091+ spinlock_t *ptl;
24092+ unsigned char pte_mask;
24093+
24094+ if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
24095+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
24096+ return 0;
24097+
24098+ /* PaX: it's our fault, let's handle it if we can */
24099+
24100+ /* PaX: take a look at read faults before acquiring any locks */
24101+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
24102+ /* instruction fetch attempt from a protected page in user mode */
24103+ up_read(&mm->mmap_sem);
24104+
24105+#ifdef CONFIG_PAX_EMUTRAMP
24106+ switch (pax_handle_fetch_fault(regs)) {
24107+ case 2:
24108+ return 1;
24109+ }
24110+#endif
24111+
24112+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24113+ do_group_exit(SIGKILL);
24114+ }
24115+
24116+ pmd = pax_get_pmd(mm, address);
24117+ if (unlikely(!pmd))
24118+ return 0;
24119+
24120+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
24121+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
24122+ pte_unmap_unlock(pte, ptl);
24123+ return 0;
24124+ }
24125+
24126+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
24127+ /* write attempt to a protected page in user mode */
24128+ pte_unmap_unlock(pte, ptl);
24129+ return 0;
24130+ }
24131+
24132+#ifdef CONFIG_SMP
24133+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
24134+#else
24135+ if (likely(address > get_limit(regs->cs)))
24136+#endif
24137+ {
24138+ set_pte(pte, pte_mkread(*pte));
24139+ __flush_tlb_one(address);
24140+ pte_unmap_unlock(pte, ptl);
24141+ up_read(&mm->mmap_sem);
24142+ return 1;
24143+ }
24144+
24145+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
24146+
24147+ /*
24148+ * PaX: fill DTLB with user rights and retry
24149+ */
24150+ __asm__ __volatile__ (
24151+ "orb %2,(%1)\n"
24152+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
24153+/*
24154+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
24155+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
24156+ * page fault when examined during a TLB load attempt. this is true not only
24157+ * for PTEs holding a non-present entry but also present entries that will
24158+ * raise a page fault (such as those set up by PaX, or the copy-on-write
24159+ * mechanism). in effect it means that we do *not* need to flush the TLBs
24160+ * for our target pages since their PTEs are simply not in the TLBs at all.
24161+
24162+ * the best thing in omitting it is that we gain around 15-20% speed in the
24163+ * fast path of the page fault handler and can get rid of tracing since we
24164+ * can no longer flush unintended entries.
24165+ */
24166+ "invlpg (%0)\n"
24167+#endif
24168+ __copyuser_seg"testb $0,(%0)\n"
24169+ "xorb %3,(%1)\n"
24170+ :
24171+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24172+ : "memory", "cc");
24173+ pte_unmap_unlock(pte, ptl);
24174+ up_read(&mm->mmap_sem);
24175+ return 1;
24176+}
24177+#endif
24178+
24179 /*
24180 * Handle a spurious fault caused by a stale TLB entry.
24181 *
24182@@ -923,6 +1139,9 @@ int show_unhandled_signals = 1;
24183 static inline int
24184 access_error(unsigned long error_code, int write, struct vm_area_struct *vma)
24185 {
24186+ if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24187+ return 1;
24188+
24189 if (write) {
24190 /* write, present and write, not present: */
24191 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24192@@ -956,16 +1175,30 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24193 {
24194 struct vm_area_struct *vma;
24195 struct task_struct *tsk;
24196- unsigned long address;
24197 struct mm_struct *mm;
24198 int write;
24199 int fault;
24200
24201- tsk = current;
24202- mm = tsk->mm;
24203-
24204 /* Get the faulting address: */
24205- address = read_cr2();
24206+ unsigned long address = read_cr2();
24207+
24208+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24209+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24210+ if (!search_exception_tables(regs->ip)) {
24211+ bad_area_nosemaphore(regs, error_code, address);
24212+ return;
24213+ }
24214+ if (address < PAX_USER_SHADOW_BASE) {
24215+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24216+ printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
24217+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24218+ } else
24219+ address -= PAX_USER_SHADOW_BASE;
24220+ }
24221+#endif
24222+
24223+ tsk = current;
24224+ mm = tsk->mm;
24225
24226 /*
24227 * Detect and handle instructions that would cause a page fault for
24228@@ -1026,7 +1259,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24229 * User-mode registers count as a user access even for any
24230 * potential system fault or CPU buglet:
24231 */
24232- if (user_mode_vm(regs)) {
24233+ if (user_mode(regs)) {
24234 local_irq_enable();
24235 error_code |= PF_USER;
24236 } else {
24237@@ -1080,6 +1313,11 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24238 might_sleep();
24239 }
24240
24241+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24242+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24243+ return;
24244+#endif
24245+
24246 vma = find_vma(mm, address);
24247 if (unlikely(!vma)) {
24248 bad_area(regs, error_code, address);
24249@@ -1091,18 +1329,24 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24250 bad_area(regs, error_code, address);
24251 return;
24252 }
24253- if (error_code & PF_USER) {
24254- /*
24255- * Accessing the stack below %sp is always a bug.
24256- * The large cushion allows instructions like enter
24257- * and pusha to work. ("enter $65535, $31" pushes
24258- * 32 pointers and then decrements %sp by 65535.)
24259- */
24260- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24261- bad_area(regs, error_code, address);
24262- return;
24263- }
24264+ /*
24265+ * Accessing the stack below %sp is always a bug.
24266+ * The large cushion allows instructions like enter
24267+ * and pusha to work. ("enter $65535, $31" pushes
24268+ * 32 pointers and then decrements %sp by 65535.)
24269+ */
24270+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24271+ bad_area(regs, error_code, address);
24272+ return;
24273 }
24274+
24275+#ifdef CONFIG_PAX_SEGMEXEC
24276+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24277+ bad_area(regs, error_code, address);
24278+ return;
24279+ }
24280+#endif
24281+
24282 if (unlikely(expand_stack(vma, address))) {
24283 bad_area(regs, error_code, address);
24284 return;
24285@@ -1146,3 +1390,292 @@ good_area:
24286
24287 up_read(&mm->mmap_sem);
24288 }
24289+
24290+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24291+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24292+{
24293+ struct mm_struct *mm = current->mm;
24294+ unsigned long ip = regs->ip;
24295+
24296+ if (v8086_mode(regs))
24297+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24298+
24299+#ifdef CONFIG_PAX_PAGEEXEC
24300+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24301+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24302+ return true;
24303+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24304+ return true;
24305+ return false;
24306+ }
24307+#endif
24308+
24309+#ifdef CONFIG_PAX_SEGMEXEC
24310+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24311+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24312+ return true;
24313+ return false;
24314+ }
24315+#endif
24316+
24317+ return false;
24318+}
24319+#endif
24320+
24321+#ifdef CONFIG_PAX_EMUTRAMP
24322+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24323+{
24324+ int err;
24325+
24326+ do { /* PaX: libffi trampoline emulation */
24327+ unsigned char mov, jmp;
24328+ unsigned int addr1, addr2;
24329+
24330+#ifdef CONFIG_X86_64
24331+ if ((regs->ip + 9) >> 32)
24332+ break;
24333+#endif
24334+
24335+ err = get_user(mov, (unsigned char __user *)regs->ip);
24336+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24337+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24338+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24339+
24340+ if (err)
24341+ break;
24342+
24343+ if (mov == 0xB8 && jmp == 0xE9) {
24344+ regs->ax = addr1;
24345+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24346+ return 2;
24347+ }
24348+ } while (0);
24349+
24350+ do { /* PaX: gcc trampoline emulation #1 */
24351+ unsigned char mov1, mov2;
24352+ unsigned short jmp;
24353+ unsigned int addr1, addr2;
24354+
24355+#ifdef CONFIG_X86_64
24356+ if ((regs->ip + 11) >> 32)
24357+ break;
24358+#endif
24359+
24360+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24361+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24362+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24363+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24364+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24365+
24366+ if (err)
24367+ break;
24368+
24369+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24370+ regs->cx = addr1;
24371+ regs->ax = addr2;
24372+ regs->ip = addr2;
24373+ return 2;
24374+ }
24375+ } while (0);
24376+
24377+ do { /* PaX: gcc trampoline emulation #2 */
24378+ unsigned char mov, jmp;
24379+ unsigned int addr1, addr2;
24380+
24381+#ifdef CONFIG_X86_64
24382+ if ((regs->ip + 9) >> 32)
24383+ break;
24384+#endif
24385+
24386+ err = get_user(mov, (unsigned char __user *)regs->ip);
24387+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24388+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24389+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24390+
24391+ if (err)
24392+ break;
24393+
24394+ if (mov == 0xB9 && jmp == 0xE9) {
24395+ regs->cx = addr1;
24396+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24397+ return 2;
24398+ }
24399+ } while (0);
24400+
24401+ return 1; /* PaX in action */
24402+}
24403+
24404+#ifdef CONFIG_X86_64
24405+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24406+{
24407+ int err;
24408+
24409+ do { /* PaX: libffi trampoline emulation */
24410+ unsigned short mov1, mov2, jmp1;
24411+ unsigned char stcclc, jmp2;
24412+ unsigned long addr1, addr2;
24413+
24414+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24415+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24416+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24417+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24418+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24419+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24420+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24421+
24422+ if (err)
24423+ break;
24424+
24425+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24426+ regs->r11 = addr1;
24427+ regs->r10 = addr2;
24428+ if (stcclc == 0xF8)
24429+ regs->flags &= ~X86_EFLAGS_CF;
24430+ else
24431+ regs->flags |= X86_EFLAGS_CF;
24432+ regs->ip = addr1;
24433+ return 2;
24434+ }
24435+ } while (0);
24436+
24437+ do { /* PaX: gcc trampoline emulation #1 */
24438+ unsigned short mov1, mov2, jmp1;
24439+ unsigned char jmp2;
24440+ unsigned int addr1;
24441+ unsigned long addr2;
24442+
24443+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24444+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24445+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24446+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24447+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24448+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24449+
24450+ if (err)
24451+ break;
24452+
24453+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24454+ regs->r11 = addr1;
24455+ regs->r10 = addr2;
24456+ regs->ip = addr1;
24457+ return 2;
24458+ }
24459+ } while (0);
24460+
24461+ do { /* PaX: gcc trampoline emulation #2 */
24462+ unsigned short mov1, mov2, jmp1;
24463+ unsigned char jmp2;
24464+ unsigned long addr1, addr2;
24465+
24466+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24467+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24468+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24469+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24470+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24471+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24472+
24473+ if (err)
24474+ break;
24475+
24476+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24477+ regs->r11 = addr1;
24478+ regs->r10 = addr2;
24479+ regs->ip = addr1;
24480+ return 2;
24481+ }
24482+ } while (0);
24483+
24484+ return 1; /* PaX in action */
24485+}
24486+#endif
24487+
24488+/*
24489+ * PaX: decide what to do with offenders (regs->ip = fault address)
24490+ *
24491+ * returns 1 when task should be killed
24492+ * 2 when gcc trampoline was detected
24493+ */
24494+static int pax_handle_fetch_fault(struct pt_regs *regs)
24495+{
24496+ if (v8086_mode(regs))
24497+ return 1;
24498+
24499+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24500+ return 1;
24501+
24502+#ifdef CONFIG_X86_32
24503+ return pax_handle_fetch_fault_32(regs);
24504+#else
24505+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24506+ return pax_handle_fetch_fault_32(regs);
24507+ else
24508+ return pax_handle_fetch_fault_64(regs);
24509+#endif
24510+}
24511+#endif
24512+
24513+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24514+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24515+{
24516+ long i;
24517+
24518+ printk(KERN_ERR "PAX: bytes at PC: ");
24519+ for (i = 0; i < 20; i++) {
24520+ unsigned char c;
24521+ if (get_user(c, (unsigned char __force_user *)pc+i))
24522+ printk(KERN_CONT "?? ");
24523+ else
24524+ printk(KERN_CONT "%02x ", c);
24525+ }
24526+ printk("\n");
24527+
24528+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24529+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24530+ unsigned long c;
24531+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24532+#ifdef CONFIG_X86_32
24533+ printk(KERN_CONT "???????? ");
24534+#else
24535+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24536+ printk(KERN_CONT "???????? ???????? ");
24537+ else
24538+ printk(KERN_CONT "???????????????? ");
24539+#endif
24540+ } else {
24541+#ifdef CONFIG_X86_64
24542+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24543+ printk(KERN_CONT "%08x ", (unsigned int)c);
24544+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24545+ } else
24546+#endif
24547+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24548+ }
24549+ }
24550+ printk("\n");
24551+}
24552+#endif
24553+
24554+/**
24555+ * probe_kernel_write(): safely attempt to write to a location
24556+ * @dst: address to write to
24557+ * @src: pointer to the data that shall be written
24558+ * @size: size of the data chunk
24559+ *
24560+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24561+ * happens, handle that and return -EFAULT.
24562+ */
24563+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24564+{
24565+ long ret;
24566+ mm_segment_t old_fs = get_fs();
24567+
24568+ set_fs(KERNEL_DS);
24569+ pagefault_disable();
24570+ pax_open_kernel();
24571+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24572+ pax_close_kernel();
24573+ pagefault_enable();
24574+ set_fs(old_fs);
24575+
24576+ return ret ? -EFAULT : 0;
24577+}
24578diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24579index 71da1bc..7a16bf4 100644
24580--- a/arch/x86/mm/gup.c
24581+++ b/arch/x86/mm/gup.c
24582@@ -237,7 +237,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24583 addr = start;
24584 len = (unsigned long) nr_pages << PAGE_SHIFT;
24585 end = start + len;
24586- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24587+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24588 (void __user *)start, len)))
24589 return 0;
24590
24591diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24592index 63a6ba6..79abd7a 100644
24593--- a/arch/x86/mm/highmem_32.c
24594+++ b/arch/x86/mm/highmem_32.c
24595@@ -43,7 +43,10 @@ void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot)
24596 idx = type + KM_TYPE_NR*smp_processor_id();
24597 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24598 BUG_ON(!pte_none(*(kmap_pte-idx)));
24599+
24600+ pax_open_kernel();
24601 set_pte(kmap_pte-idx, mk_pte(page, prot));
24602+ pax_close_kernel();
24603
24604 return (void *)vaddr;
24605 }
24606diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24607index f46c340..6ff9a26 100644
24608--- a/arch/x86/mm/hugetlbpage.c
24609+++ b/arch/x86/mm/hugetlbpage.c
24610@@ -267,13 +267,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24611 struct hstate *h = hstate_file(file);
24612 struct mm_struct *mm = current->mm;
24613 struct vm_area_struct *vma;
24614- unsigned long start_addr;
24615+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24616+
24617+#ifdef CONFIG_PAX_SEGMEXEC
24618+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24619+ pax_task_size = SEGMEXEC_TASK_SIZE;
24620+#endif
24621+
24622+ pax_task_size -= PAGE_SIZE;
24623
24624 if (len > mm->cached_hole_size) {
24625- start_addr = mm->free_area_cache;
24626+ start_addr = mm->free_area_cache;
24627 } else {
24628- start_addr = TASK_UNMAPPED_BASE;
24629- mm->cached_hole_size = 0;
24630+ start_addr = mm->mmap_base;
24631+ mm->cached_hole_size = 0;
24632 }
24633
24634 full_search:
24635@@ -281,26 +288,27 @@ full_search:
24636
24637 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24638 /* At this point: (!vma || addr < vma->vm_end). */
24639- if (TASK_SIZE - len < addr) {
24640+ if (pax_task_size - len < addr) {
24641 /*
24642 * Start a new search - just in case we missed
24643 * some holes.
24644 */
24645- if (start_addr != TASK_UNMAPPED_BASE) {
24646- start_addr = TASK_UNMAPPED_BASE;
24647+ if (start_addr != mm->mmap_base) {
24648+ start_addr = mm->mmap_base;
24649 mm->cached_hole_size = 0;
24650 goto full_search;
24651 }
24652 return -ENOMEM;
24653 }
24654- if (!vma || addr + len <= vma->vm_start) {
24655- mm->free_area_cache = addr + len;
24656- return addr;
24657- }
24658+ if (check_heap_stack_gap(vma, addr, len))
24659+ break;
24660 if (addr + mm->cached_hole_size < vma->vm_start)
24661 mm->cached_hole_size = vma->vm_start - addr;
24662 addr = ALIGN(vma->vm_end, huge_page_size(h));
24663 }
24664+
24665+ mm->free_area_cache = addr + len;
24666+ return addr;
24667 }
24668
24669 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24670@@ -309,10 +317,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24671 {
24672 struct hstate *h = hstate_file(file);
24673 struct mm_struct *mm = current->mm;
24674- struct vm_area_struct *vma, *prev_vma;
24675- unsigned long base = mm->mmap_base, addr = addr0;
24676+ struct vm_area_struct *vma;
24677+ unsigned long base = mm->mmap_base, addr;
24678 unsigned long largest_hole = mm->cached_hole_size;
24679- int first_time = 1;
24680
24681 /* don't allow allocations above current base */
24682 if (mm->free_area_cache > base)
24683@@ -322,64 +329,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24684 largest_hole = 0;
24685 mm->free_area_cache = base;
24686 }
24687-try_again:
24688+
24689 /* make sure it can fit in the remaining address space */
24690 if (mm->free_area_cache < len)
24691 goto fail;
24692
24693 /* either no address requested or cant fit in requested address hole */
24694- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24695+ addr = (mm->free_area_cache - len);
24696 do {
24697+ addr &= huge_page_mask(h);
24698+ vma = find_vma(mm, addr);
24699 /*
24700 * Lookup failure means no vma is above this address,
24701 * i.e. return with success:
24702- */
24703- if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
24704- return addr;
24705-
24706- /*
24707 * new region fits between prev_vma->vm_end and
24708 * vma->vm_start, use it:
24709 */
24710- if (addr + len <= vma->vm_start &&
24711- (!prev_vma || (addr >= prev_vma->vm_end))) {
24712+ if (check_heap_stack_gap(vma, addr, len)) {
24713 /* remember the address as a hint for next time */
24714- mm->cached_hole_size = largest_hole;
24715- return (mm->free_area_cache = addr);
24716- } else {
24717- /* pull free_area_cache down to the first hole */
24718- if (mm->free_area_cache == vma->vm_end) {
24719- mm->free_area_cache = vma->vm_start;
24720- mm->cached_hole_size = largest_hole;
24721- }
24722+ mm->cached_hole_size = largest_hole;
24723+ return (mm->free_area_cache = addr);
24724+ }
24725+ /* pull free_area_cache down to the first hole */
24726+ if (mm->free_area_cache == vma->vm_end) {
24727+ mm->free_area_cache = vma->vm_start;
24728+ mm->cached_hole_size = largest_hole;
24729 }
24730
24731 /* remember the largest hole we saw so far */
24732 if (addr + largest_hole < vma->vm_start)
24733- largest_hole = vma->vm_start - addr;
24734+ largest_hole = vma->vm_start - addr;
24735
24736 /* try just below the current vma->vm_start */
24737- addr = (vma->vm_start - len) & huge_page_mask(h);
24738- } while (len <= vma->vm_start);
24739+ addr = skip_heap_stack_gap(vma, len);
24740+ } while (!IS_ERR_VALUE(addr));
24741
24742 fail:
24743 /*
24744- * if hint left us with no space for the requested
24745- * mapping then try again:
24746- */
24747- if (first_time) {
24748- mm->free_area_cache = base;
24749- largest_hole = 0;
24750- first_time = 0;
24751- goto try_again;
24752- }
24753- /*
24754 * A failed mmap() very likely causes application failure,
24755 * so fall back to the bottom-up function here. This scenario
24756 * can happen with large stack limits and large mmap()
24757 * allocations.
24758 */
24759- mm->free_area_cache = TASK_UNMAPPED_BASE;
24760+
24761+#ifdef CONFIG_PAX_SEGMEXEC
24762+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24763+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24764+ else
24765+#endif
24766+
24767+ mm->mmap_base = TASK_UNMAPPED_BASE;
24768+
24769+#ifdef CONFIG_PAX_RANDMMAP
24770+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24771+ mm->mmap_base += mm->delta_mmap;
24772+#endif
24773+
24774+ mm->free_area_cache = mm->mmap_base;
24775 mm->cached_hole_size = ~0UL;
24776 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24777 len, pgoff, flags);
24778@@ -387,6 +393,7 @@ fail:
24779 /*
24780 * Restore the topdown base:
24781 */
24782+ mm->mmap_base = base;
24783 mm->free_area_cache = base;
24784 mm->cached_hole_size = ~0UL;
24785
24786@@ -400,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24787 struct hstate *h = hstate_file(file);
24788 struct mm_struct *mm = current->mm;
24789 struct vm_area_struct *vma;
24790+ unsigned long pax_task_size = TASK_SIZE;
24791
24792 if (len & ~huge_page_mask(h))
24793 return -EINVAL;
24794- if (len > TASK_SIZE)
24795+
24796+#ifdef CONFIG_PAX_SEGMEXEC
24797+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24798+ pax_task_size = SEGMEXEC_TASK_SIZE;
24799+#endif
24800+
24801+ pax_task_size -= PAGE_SIZE;
24802+
24803+ if (len > pax_task_size)
24804 return -ENOMEM;
24805
24806 if (flags & MAP_FIXED) {
24807@@ -415,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24808 if (addr) {
24809 addr = ALIGN(addr, huge_page_size(h));
24810 vma = find_vma(mm, addr);
24811- if (TASK_SIZE - len >= addr &&
24812- (!vma || addr + len <= vma->vm_start))
24813+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24814 return addr;
24815 }
24816 if (mm->get_unmapped_area == arch_get_unmapped_area)
24817diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24818index 73ffd55..ad78676 100644
24819--- a/arch/x86/mm/init.c
24820+++ b/arch/x86/mm/init.c
24821@@ -69,11 +69,7 @@ static void __init find_early_table_space(unsigned long end, int use_pse,
24822 * cause a hotspot and fill up ZONE_DMA. The page tables
24823 * need roughly 0.5KB per GB.
24824 */
24825-#ifdef CONFIG_X86_32
24826- start = 0x7000;
24827-#else
24828- start = 0x8000;
24829-#endif
24830+ start = 0x100000;
24831 e820_table_start = find_e820_area(start, max_pfn_mapped<<PAGE_SHIFT,
24832 tables, PAGE_SIZE);
24833 if (e820_table_start == -1UL)
24834@@ -147,7 +143,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24835 #endif
24836
24837 set_nx();
24838- if (nx_enabled)
24839+ if (nx_enabled && cpu_has_nx)
24840 printk(KERN_INFO "NX (Execute Disable) protection: active\n");
24841
24842 /* Enable PSE if available */
24843@@ -329,10 +325,27 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24844 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24845 * mmio resources as well as potential bios/acpi data regions.
24846 */
24847+
24848 int devmem_is_allowed(unsigned long pagenr)
24849 {
24850+#ifdef CONFIG_GRKERNSEC_KMEM
24851+ /* allow BDA */
24852+ if (!pagenr)
24853+ return 1;
24854+ /* allow EBDA */
24855+ if ((0x9f000 >> PAGE_SHIFT) == pagenr)
24856+ return 1;
24857+ /* allow ISA/video mem */
24858+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24859+ return 1;
24860+ /* throw out everything else below 1MB */
24861+ if (pagenr <= 256)
24862+ return 0;
24863+#else
24864 if (pagenr <= 256)
24865 return 1;
24866+#endif
24867+
24868 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24869 return 0;
24870 if (!page_is_ram(pagenr))
24871@@ -379,6 +392,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24872
24873 void free_initmem(void)
24874 {
24875+
24876+#ifdef CONFIG_PAX_KERNEXEC
24877+#ifdef CONFIG_X86_32
24878+ /* PaX: limit KERNEL_CS to actual size */
24879+ unsigned long addr, limit;
24880+ struct desc_struct d;
24881+ int cpu;
24882+
24883+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24884+ limit = (limit - 1UL) >> PAGE_SHIFT;
24885+
24886+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24887+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
24888+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24889+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24890+ }
24891+
24892+ /* PaX: make KERNEL_CS read-only */
24893+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24894+ if (!paravirt_enabled())
24895+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24896+/*
24897+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24898+ pgd = pgd_offset_k(addr);
24899+ pud = pud_offset(pgd, addr);
24900+ pmd = pmd_offset(pud, addr);
24901+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24902+ }
24903+*/
24904+#ifdef CONFIG_X86_PAE
24905+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24906+/*
24907+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24908+ pgd = pgd_offset_k(addr);
24909+ pud = pud_offset(pgd, addr);
24910+ pmd = pmd_offset(pud, addr);
24911+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24912+ }
24913+*/
24914+#endif
24915+
24916+#ifdef CONFIG_MODULES
24917+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24918+#endif
24919+
24920+#else
24921+ pgd_t *pgd;
24922+ pud_t *pud;
24923+ pmd_t *pmd;
24924+ unsigned long addr, end;
24925+
24926+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24927+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24928+ pgd = pgd_offset_k(addr);
24929+ pud = pud_offset(pgd, addr);
24930+ pmd = pmd_offset(pud, addr);
24931+ if (!pmd_present(*pmd))
24932+ continue;
24933+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24934+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24935+ else
24936+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24937+ }
24938+
24939+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24940+ end = addr + KERNEL_IMAGE_SIZE;
24941+ for (; addr < end; addr += PMD_SIZE) {
24942+ pgd = pgd_offset_k(addr);
24943+ pud = pud_offset(pgd, addr);
24944+ pmd = pmd_offset(pud, addr);
24945+ if (!pmd_present(*pmd))
24946+ continue;
24947+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24948+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24949+ }
24950+#endif
24951+
24952+ flush_tlb_all();
24953+#endif
24954+
24955 free_init_pages("unused kernel memory",
24956 (unsigned long)(&__init_begin),
24957 (unsigned long)(&__init_end));
24958diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24959index 30938c1..bda3d5d 100644
24960--- a/arch/x86/mm/init_32.c
24961+++ b/arch/x86/mm/init_32.c
24962@@ -72,36 +72,6 @@ static __init void *alloc_low_page(void)
24963 }
24964
24965 /*
24966- * Creates a middle page table and puts a pointer to it in the
24967- * given global directory entry. This only returns the gd entry
24968- * in non-PAE compilation mode, since the middle layer is folded.
24969- */
24970-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24971-{
24972- pud_t *pud;
24973- pmd_t *pmd_table;
24974-
24975-#ifdef CONFIG_X86_PAE
24976- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24977- if (after_bootmem)
24978- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24979- else
24980- pmd_table = (pmd_t *)alloc_low_page();
24981- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24982- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24983- pud = pud_offset(pgd, 0);
24984- BUG_ON(pmd_table != pmd_offset(pud, 0));
24985-
24986- return pmd_table;
24987- }
24988-#endif
24989- pud = pud_offset(pgd, 0);
24990- pmd_table = pmd_offset(pud, 0);
24991-
24992- return pmd_table;
24993-}
24994-
24995-/*
24996 * Create a page table and place a pointer to it in a middle page
24997 * directory entry:
24998 */
24999@@ -121,13 +91,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
25000 page_table = (pte_t *)alloc_low_page();
25001
25002 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
25003+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25004+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
25005+#else
25006 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
25007+#endif
25008 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
25009 }
25010
25011 return pte_offset_kernel(pmd, 0);
25012 }
25013
25014+static pmd_t * __init one_md_table_init(pgd_t *pgd)
25015+{
25016+ pud_t *pud;
25017+ pmd_t *pmd_table;
25018+
25019+ pud = pud_offset(pgd, 0);
25020+ pmd_table = pmd_offset(pud, 0);
25021+
25022+ return pmd_table;
25023+}
25024+
25025 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
25026 {
25027 int pgd_idx = pgd_index(vaddr);
25028@@ -201,6 +186,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25029 int pgd_idx, pmd_idx;
25030 unsigned long vaddr;
25031 pgd_t *pgd;
25032+ pud_t *pud;
25033 pmd_t *pmd;
25034 pte_t *pte = NULL;
25035
25036@@ -210,8 +196,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25037 pgd = pgd_base + pgd_idx;
25038
25039 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
25040- pmd = one_md_table_init(pgd);
25041- pmd = pmd + pmd_index(vaddr);
25042+ pud = pud_offset(pgd, vaddr);
25043+ pmd = pmd_offset(pud, vaddr);
25044+
25045+#ifdef CONFIG_X86_PAE
25046+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25047+#endif
25048+
25049 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
25050 pmd++, pmd_idx++) {
25051 pte = page_table_kmap_check(one_page_table_init(pmd),
25052@@ -223,11 +214,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25053 }
25054 }
25055
25056-static inline int is_kernel_text(unsigned long addr)
25057+static inline int is_kernel_text(unsigned long start, unsigned long end)
25058 {
25059- if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
25060- return 1;
25061- return 0;
25062+ if ((start > ktla_ktva((unsigned long)_etext) ||
25063+ end <= ktla_ktva((unsigned long)_stext)) &&
25064+ (start > ktla_ktva((unsigned long)_einittext) ||
25065+ end <= ktla_ktva((unsigned long)_sinittext)) &&
25066+
25067+#ifdef CONFIG_ACPI_SLEEP
25068+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
25069+#endif
25070+
25071+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
25072+ return 0;
25073+ return 1;
25074 }
25075
25076 /*
25077@@ -243,9 +243,10 @@ kernel_physical_mapping_init(unsigned long start,
25078 int use_pse = page_size_mask == (1<<PG_LEVEL_2M);
25079 unsigned long start_pfn, end_pfn;
25080 pgd_t *pgd_base = swapper_pg_dir;
25081- int pgd_idx, pmd_idx, pte_ofs;
25082+ unsigned int pgd_idx, pmd_idx, pte_ofs;
25083 unsigned long pfn;
25084 pgd_t *pgd;
25085+ pud_t *pud;
25086 pmd_t *pmd;
25087 pte_t *pte;
25088 unsigned pages_2m, pages_4k;
25089@@ -278,8 +279,13 @@ repeat:
25090 pfn = start_pfn;
25091 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25092 pgd = pgd_base + pgd_idx;
25093- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
25094- pmd = one_md_table_init(pgd);
25095+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
25096+ pud = pud_offset(pgd, 0);
25097+ pmd = pmd_offset(pud, 0);
25098+
25099+#ifdef CONFIG_X86_PAE
25100+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25101+#endif
25102
25103 if (pfn >= end_pfn)
25104 continue;
25105@@ -291,14 +297,13 @@ repeat:
25106 #endif
25107 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
25108 pmd++, pmd_idx++) {
25109- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
25110+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
25111
25112 /*
25113 * Map with big pages if possible, otherwise
25114 * create normal page tables:
25115 */
25116 if (use_pse) {
25117- unsigned int addr2;
25118 pgprot_t prot = PAGE_KERNEL_LARGE;
25119 /*
25120 * first pass will use the same initial
25121@@ -308,11 +313,7 @@ repeat:
25122 __pgprot(PTE_IDENT_ATTR |
25123 _PAGE_PSE);
25124
25125- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
25126- PAGE_OFFSET + PAGE_SIZE-1;
25127-
25128- if (is_kernel_text(addr) ||
25129- is_kernel_text(addr2))
25130+ if (is_kernel_text(address, address + PMD_SIZE))
25131 prot = PAGE_KERNEL_LARGE_EXEC;
25132
25133 pages_2m++;
25134@@ -329,7 +330,7 @@ repeat:
25135 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25136 pte += pte_ofs;
25137 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25138- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25139+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25140 pgprot_t prot = PAGE_KERNEL;
25141 /*
25142 * first pass will use the same initial
25143@@ -337,7 +338,7 @@ repeat:
25144 */
25145 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25146
25147- if (is_kernel_text(addr))
25148+ if (is_kernel_text(address, address + PAGE_SIZE))
25149 prot = PAGE_KERNEL_EXEC;
25150
25151 pages_4k++;
25152@@ -489,7 +490,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25153
25154 pud = pud_offset(pgd, va);
25155 pmd = pmd_offset(pud, va);
25156- if (!pmd_present(*pmd))
25157+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
25158 break;
25159
25160 pte = pte_offset_kernel(pmd, va);
25161@@ -541,9 +542,7 @@ void __init early_ioremap_page_table_range_init(void)
25162
25163 static void __init pagetable_init(void)
25164 {
25165- pgd_t *pgd_base = swapper_pg_dir;
25166-
25167- permanent_kmaps_init(pgd_base);
25168+ permanent_kmaps_init(swapper_pg_dir);
25169 }
25170
25171 #ifdef CONFIG_ACPI_SLEEP
25172@@ -551,12 +550,12 @@ static void __init pagetable_init(void)
25173 * ACPI suspend needs this for resume, because things like the intel-agp
25174 * driver might have split up a kernel 4MB mapping.
25175 */
25176-char swsusp_pg_dir[PAGE_SIZE]
25177+pgd_t swsusp_pg_dir[PTRS_PER_PGD]
25178 __attribute__ ((aligned(PAGE_SIZE)));
25179
25180 static inline void save_pg_dir(void)
25181 {
25182- memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
25183+ clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
25184 }
25185 #else /* !CONFIG_ACPI_SLEEP */
25186 static inline void save_pg_dir(void)
25187@@ -588,7 +587,7 @@ void zap_low_mappings(bool early)
25188 flush_tlb_all();
25189 }
25190
25191-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25192+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25193 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25194
25195 /* user-defined highmem size */
25196@@ -777,7 +776,7 @@ void __init setup_bootmem_allocator(void)
25197 * Initialize the boot-time allocator (with low memory only):
25198 */
25199 bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
25200- bootmap = find_e820_area(0, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
25201+ bootmap = find_e820_area(0x100000, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
25202 PAGE_SIZE);
25203 if (bootmap == -1L)
25204 panic("Cannot find bootmem map of size %ld\n", bootmap_size);
25205@@ -864,6 +863,12 @@ void __init mem_init(void)
25206
25207 pci_iommu_alloc();
25208
25209+#ifdef CONFIG_PAX_PER_CPU_PGD
25210+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25211+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25212+ KERNEL_PGD_PTRS);
25213+#endif
25214+
25215 #ifdef CONFIG_FLATMEM
25216 BUG_ON(!mem_map);
25217 #endif
25218@@ -881,7 +886,7 @@ void __init mem_init(void)
25219 set_highmem_pages_init();
25220
25221 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25222- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25223+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25224 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25225
25226 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25227@@ -923,10 +928,10 @@ void __init mem_init(void)
25228 ((unsigned long)&__init_end -
25229 (unsigned long)&__init_begin) >> 10,
25230
25231- (unsigned long)&_etext, (unsigned long)&_edata,
25232- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25233+ (unsigned long)&_sdata, (unsigned long)&_edata,
25234+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25235
25236- (unsigned long)&_text, (unsigned long)&_etext,
25237+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25238 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25239
25240 /*
25241@@ -1007,6 +1012,7 @@ void set_kernel_text_rw(void)
25242 if (!kernel_set_to_readonly)
25243 return;
25244
25245+ start = ktla_ktva(start);
25246 pr_debug("Set kernel text: %lx - %lx for read write\n",
25247 start, start+size);
25248
25249@@ -1021,6 +1027,7 @@ void set_kernel_text_ro(void)
25250 if (!kernel_set_to_readonly)
25251 return;
25252
25253+ start = ktla_ktva(start);
25254 pr_debug("Set kernel text: %lx - %lx for read only\n",
25255 start, start+size);
25256
25257@@ -1032,6 +1039,7 @@ void mark_rodata_ro(void)
25258 unsigned long start = PFN_ALIGN(_text);
25259 unsigned long size = PFN_ALIGN(_etext) - start;
25260
25261+ start = ktla_ktva(start);
25262 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25263 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25264 size >> 10);
25265diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25266index 7d095ad..25d2549 100644
25267--- a/arch/x86/mm/init_64.c
25268+++ b/arch/x86/mm/init_64.c
25269@@ -164,7 +164,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25270 pmd = fill_pmd(pud, vaddr);
25271 pte = fill_pte(pmd, vaddr);
25272
25273+ pax_open_kernel();
25274 set_pte(pte, new_pte);
25275+ pax_close_kernel();
25276
25277 /*
25278 * It's enough to flush this one mapping.
25279@@ -223,14 +225,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25280 pgd = pgd_offset_k((unsigned long)__va(phys));
25281 if (pgd_none(*pgd)) {
25282 pud = (pud_t *) spp_getpage();
25283- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25284- _PAGE_USER));
25285+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25286 }
25287 pud = pud_offset(pgd, (unsigned long)__va(phys));
25288 if (pud_none(*pud)) {
25289 pmd = (pmd_t *) spp_getpage();
25290- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25291- _PAGE_USER));
25292+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25293 }
25294 pmd = pmd_offset(pud, phys);
25295 BUG_ON(!pmd_none(*pmd));
25296@@ -675,6 +675,12 @@ void __init mem_init(void)
25297
25298 pci_iommu_alloc();
25299
25300+#ifdef CONFIG_PAX_PER_CPU_PGD
25301+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25302+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25303+ KERNEL_PGD_PTRS);
25304+#endif
25305+
25306 /* clear_bss() already clear the empty_zero_page */
25307
25308 reservedpages = 0;
25309@@ -861,8 +867,8 @@ int kern_addr_valid(unsigned long addr)
25310 static struct vm_area_struct gate_vma = {
25311 .vm_start = VSYSCALL_START,
25312 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25313- .vm_page_prot = PAGE_READONLY_EXEC,
25314- .vm_flags = VM_READ | VM_EXEC
25315+ .vm_page_prot = PAGE_READONLY,
25316+ .vm_flags = VM_READ
25317 };
25318
25319 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
25320@@ -896,7 +902,7 @@ int in_gate_area_no_task(unsigned long addr)
25321
25322 const char *arch_vma_name(struct vm_area_struct *vma)
25323 {
25324- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25325+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25326 return "[vdso]";
25327 if (vma == &gate_vma)
25328 return "[vsyscall]";
25329diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25330index 84e236c..69bd3f6 100644
25331--- a/arch/x86/mm/iomap_32.c
25332+++ b/arch/x86/mm/iomap_32.c
25333@@ -65,7 +65,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot)
25334 debug_kmap_atomic(type);
25335 idx = type + KM_TYPE_NR * smp_processor_id();
25336 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25337+
25338+ pax_open_kernel();
25339 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25340+ pax_close_kernel();
25341+
25342 arch_flush_lazy_mmu_mode();
25343
25344 return (void *)vaddr;
25345diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25346index 2feb9bd..3646202 100644
25347--- a/arch/x86/mm/ioremap.c
25348+++ b/arch/x86/mm/ioremap.c
25349@@ -41,8 +41,8 @@ int page_is_ram(unsigned long pagenr)
25350 * Second special case: Some BIOSen report the PC BIOS
25351 * area (640->1Mb) as ram even though it is not.
25352 */
25353- if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
25354- pagenr < (BIOS_END >> PAGE_SHIFT))
25355+ if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
25356+ pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
25357 return 0;
25358
25359 for (i = 0; i < e820.nr_map; i++) {
25360@@ -137,13 +137,10 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25361 /*
25362 * Don't allow anybody to remap normal RAM that we're using..
25363 */
25364- for (pfn = phys_addr >> PAGE_SHIFT;
25365- (pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK);
25366- pfn++) {
25367-
25368+ for (pfn = phys_addr >> PAGE_SHIFT; ((resource_size_t)pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK); pfn++) {
25369 int is_ram = page_is_ram(pfn);
25370
25371- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25372+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25373 return NULL;
25374 WARN_ON_ONCE(is_ram);
25375 }
25376@@ -407,7 +404,7 @@ static int __init early_ioremap_debug_setup(char *str)
25377 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25378
25379 static __initdata int after_paging_init;
25380-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25381+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25382
25383 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25384 {
25385@@ -439,8 +436,7 @@ void __init early_ioremap_init(void)
25386 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25387
25388 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25389- memset(bm_pte, 0, sizeof(bm_pte));
25390- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25391+ pmd_populate_user(&init_mm, pmd, bm_pte);
25392
25393 /*
25394 * The boot-ioremap range spans multiple pmds, for which
25395diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25396index 8cc1833..1abbc5b 100644
25397--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25398+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25399@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25400 * memory (e.g. tracked pages)? For now, we need this to avoid
25401 * invoking kmemcheck for PnP BIOS calls.
25402 */
25403- if (regs->flags & X86_VM_MASK)
25404+ if (v8086_mode(regs))
25405 return false;
25406- if (regs->cs != __KERNEL_CS)
25407+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25408 return false;
25409
25410 pte = kmemcheck_pte_lookup(address);
25411diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25412index c9e57af..07a321b 100644
25413--- a/arch/x86/mm/mmap.c
25414+++ b/arch/x86/mm/mmap.c
25415@@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size(void)
25416 * Leave an at least ~128 MB hole with possible stack randomization.
25417 */
25418 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25419-#define MAX_GAP (TASK_SIZE/6*5)
25420+#define MAX_GAP (pax_task_size/6*5)
25421
25422 /*
25423 * True on X86_32 or when emulating IA32 on X86_64
25424@@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
25425 return rnd << PAGE_SHIFT;
25426 }
25427
25428-static unsigned long mmap_base(void)
25429+static unsigned long mmap_base(struct mm_struct *mm)
25430 {
25431 unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
25432+ unsigned long pax_task_size = TASK_SIZE;
25433+
25434+#ifdef CONFIG_PAX_SEGMEXEC
25435+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25436+ pax_task_size = SEGMEXEC_TASK_SIZE;
25437+#endif
25438
25439 if (gap < MIN_GAP)
25440 gap = MIN_GAP;
25441 else if (gap > MAX_GAP)
25442 gap = MAX_GAP;
25443
25444- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25445+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25446 }
25447
25448 /*
25449 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25450 * does, but not when emulating X86_32
25451 */
25452-static unsigned long mmap_legacy_base(void)
25453+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25454 {
25455- if (mmap_is_ia32())
25456+ if (mmap_is_ia32()) {
25457+
25458+#ifdef CONFIG_PAX_SEGMEXEC
25459+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25460+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25461+ else
25462+#endif
25463+
25464 return TASK_UNMAPPED_BASE;
25465- else
25466+ } else
25467 return TASK_UNMAPPED_BASE + mmap_rnd();
25468 }
25469
25470@@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(void)
25471 void arch_pick_mmap_layout(struct mm_struct *mm)
25472 {
25473 if (mmap_is_legacy()) {
25474- mm->mmap_base = mmap_legacy_base();
25475+ mm->mmap_base = mmap_legacy_base(mm);
25476+
25477+#ifdef CONFIG_PAX_RANDMMAP
25478+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25479+ mm->mmap_base += mm->delta_mmap;
25480+#endif
25481+
25482 mm->get_unmapped_area = arch_get_unmapped_area;
25483 mm->unmap_area = arch_unmap_area;
25484 } else {
25485- mm->mmap_base = mmap_base();
25486+ mm->mmap_base = mmap_base(mm);
25487+
25488+#ifdef CONFIG_PAX_RANDMMAP
25489+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25490+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25491+#endif
25492+
25493 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25494 mm->unmap_area = arch_unmap_area_topdown;
25495 }
25496diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25497index 132772a..b961f11 100644
25498--- a/arch/x86/mm/mmio-mod.c
25499+++ b/arch/x86/mm/mmio-mod.c
25500@@ -193,7 +193,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25501 break;
25502 default:
25503 {
25504- unsigned char *ip = (unsigned char *)instptr;
25505+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25506 my_trace->opcode = MMIO_UNKNOWN_OP;
25507 my_trace->width = 0;
25508 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25509@@ -233,7 +233,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25510 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25511 void __iomem *addr)
25512 {
25513- static atomic_t next_id;
25514+ static atomic_unchecked_t next_id;
25515 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25516 /* These are page-unaligned. */
25517 struct mmiotrace_map map = {
25518@@ -257,7 +257,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25519 .private = trace
25520 },
25521 .phys = offset,
25522- .id = atomic_inc_return(&next_id)
25523+ .id = atomic_inc_return_unchecked(&next_id)
25524 };
25525 map.map_id = trace->id;
25526
25527diff --git a/arch/x86/mm/numa_32.c b/arch/x86/mm/numa_32.c
25528index d253006..e56dd6a 100644
25529--- a/arch/x86/mm/numa_32.c
25530+++ b/arch/x86/mm/numa_32.c
25531@@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int nid, unsigned long start_pfn,
25532 }
25533 #endif
25534
25535-extern unsigned long find_max_low_pfn(void);
25536 extern unsigned long highend_pfn, highstart_pfn;
25537
25538 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
25539diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25540index e1d1069..2251ff3 100644
25541--- a/arch/x86/mm/pageattr-test.c
25542+++ b/arch/x86/mm/pageattr-test.c
25543@@ -36,7 +36,7 @@ enum {
25544
25545 static int pte_testbit(pte_t pte)
25546 {
25547- return pte_flags(pte) & _PAGE_UNUSED1;
25548+ return pte_flags(pte) & _PAGE_CPA_TEST;
25549 }
25550
25551 struct split_state {
25552diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25553index dd38bfb..8c12306 100644
25554--- a/arch/x86/mm/pageattr.c
25555+++ b/arch/x86/mm/pageattr.c
25556@@ -261,16 +261,17 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25557 * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support.
25558 */
25559 if (within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25560- pgprot_val(forbidden) |= _PAGE_NX;
25561+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25562
25563 /*
25564 * The kernel text needs to be executable for obvious reasons
25565 * Does not cover __inittext since that is gone later on. On
25566 * 64bit we do not enforce !NX on the low mapping
25567 */
25568- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25569- pgprot_val(forbidden) |= _PAGE_NX;
25570+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25571+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25572
25573+#ifdef CONFIG_DEBUG_RODATA
25574 /*
25575 * The .rodata section needs to be read-only. Using the pfn
25576 * catches all aliases.
25577@@ -278,6 +279,14 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25578 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25579 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25580 pgprot_val(forbidden) |= _PAGE_RW;
25581+#endif
25582+
25583+#ifdef CONFIG_PAX_KERNEXEC
25584+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25585+ pgprot_val(forbidden) |= _PAGE_RW;
25586+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25587+ }
25588+#endif
25589
25590 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25591
25592@@ -331,23 +340,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25593 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25594 {
25595 /* change init_mm */
25596+ pax_open_kernel();
25597 set_pte_atomic(kpte, pte);
25598+
25599 #ifdef CONFIG_X86_32
25600 if (!SHARED_KERNEL_PMD) {
25601+
25602+#ifdef CONFIG_PAX_PER_CPU_PGD
25603+ unsigned long cpu;
25604+#else
25605 struct page *page;
25606+#endif
25607
25608+#ifdef CONFIG_PAX_PER_CPU_PGD
25609+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
25610+ pgd_t *pgd = get_cpu_pgd(cpu);
25611+#else
25612 list_for_each_entry(page, &pgd_list, lru) {
25613- pgd_t *pgd;
25614+ pgd_t *pgd = (pgd_t *)page_address(page);
25615+#endif
25616+
25617 pud_t *pud;
25618 pmd_t *pmd;
25619
25620- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25621+ pgd += pgd_index(address);
25622 pud = pud_offset(pgd, address);
25623 pmd = pmd_offset(pud, address);
25624 set_pte_atomic((pte_t *)pmd, pte);
25625 }
25626 }
25627 #endif
25628+ pax_close_kernel();
25629 }
25630
25631 static int
25632diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25633index e78cd0e..de0a817 100644
25634--- a/arch/x86/mm/pat.c
25635+++ b/arch/x86/mm/pat.c
25636@@ -258,7 +258,7 @@ chk_conflict(struct memtype *new, struct memtype *entry, unsigned long *type)
25637
25638 conflict:
25639 printk(KERN_INFO "%s:%d conflicting memory types "
25640- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, new->start,
25641+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), new->start,
25642 new->end, cattr_name(new->type), cattr_name(entry->type));
25643 return -EBUSY;
25644 }
25645@@ -559,7 +559,7 @@ unlock_ret:
25646
25647 if (err) {
25648 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25649- current->comm, current->pid, start, end);
25650+ current->comm, task_pid_nr(current), start, end);
25651 }
25652
25653 dprintk("free_memtype request 0x%Lx-0x%Lx\n", start, end);
25654@@ -689,8 +689,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25655 while (cursor < to) {
25656 if (!devmem_is_allowed(pfn)) {
25657 printk(KERN_INFO
25658- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25659- current->comm, from, to);
25660+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25661+ current->comm, from, to, cursor);
25662 return 0;
25663 }
25664 cursor += PAGE_SIZE;
25665@@ -755,7 +755,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25666 printk(KERN_INFO
25667 "%s:%d ioremap_change_attr failed %s "
25668 "for %Lx-%Lx\n",
25669- current->comm, current->pid,
25670+ current->comm, task_pid_nr(current),
25671 cattr_name(flags),
25672 base, (unsigned long long)(base + size));
25673 return -EINVAL;
25674@@ -813,7 +813,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25675 free_memtype(paddr, paddr + size);
25676 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25677 " for %Lx-%Lx, got %s\n",
25678- current->comm, current->pid,
25679+ current->comm, task_pid_nr(current),
25680 cattr_name(want_flags),
25681 (unsigned long long)paddr,
25682 (unsigned long long)(paddr + size),
25683diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25684index df3d5c8..c2223e1 100644
25685--- a/arch/x86/mm/pf_in.c
25686+++ b/arch/x86/mm/pf_in.c
25687@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25688 int i;
25689 enum reason_type rv = OTHERS;
25690
25691- p = (unsigned char *)ins_addr;
25692+ p = (unsigned char *)ktla_ktva(ins_addr);
25693 p += skip_prefix(p, &prf);
25694 p += get_opcode(p, &opcode);
25695
25696@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25697 struct prefix_bits prf;
25698 int i;
25699
25700- p = (unsigned char *)ins_addr;
25701+ p = (unsigned char *)ktla_ktva(ins_addr);
25702 p += skip_prefix(p, &prf);
25703 p += get_opcode(p, &opcode);
25704
25705@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25706 struct prefix_bits prf;
25707 int i;
25708
25709- p = (unsigned char *)ins_addr;
25710+ p = (unsigned char *)ktla_ktva(ins_addr);
25711 p += skip_prefix(p, &prf);
25712 p += get_opcode(p, &opcode);
25713
25714@@ -417,7 +417,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25715 int i;
25716 unsigned long rv;
25717
25718- p = (unsigned char *)ins_addr;
25719+ p = (unsigned char *)ktla_ktva(ins_addr);
25720 p += skip_prefix(p, &prf);
25721 p += get_opcode(p, &opcode);
25722 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25723@@ -472,7 +472,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25724 int i;
25725 unsigned long rv;
25726
25727- p = (unsigned char *)ins_addr;
25728+ p = (unsigned char *)ktla_ktva(ins_addr);
25729 p += skip_prefix(p, &prf);
25730 p += get_opcode(p, &opcode);
25731 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25732diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25733index e0e6fad..6b90017 100644
25734--- a/arch/x86/mm/pgtable.c
25735+++ b/arch/x86/mm/pgtable.c
25736@@ -83,9 +83,52 @@ static inline void pgd_list_del(pgd_t *pgd)
25737 list_del(&page->lru);
25738 }
25739
25740-#define UNSHARED_PTRS_PER_PGD \
25741- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25742+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25743+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25744
25745+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25746+{
25747+ while (count--)
25748+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25749+}
25750+#endif
25751+
25752+#ifdef CONFIG_PAX_PER_CPU_PGD
25753+void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25754+{
25755+ while (count--)
25756+
25757+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25758+ *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
25759+#else
25760+ *dst++ = *src++;
25761+#endif
25762+
25763+}
25764+#endif
25765+
25766+#ifdef CONFIG_X86_64
25767+#define pxd_t pud_t
25768+#define pyd_t pgd_t
25769+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25770+#define pxd_free(mm, pud) pud_free((mm), (pud))
25771+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25772+#define pyd_offset(mm ,address) pgd_offset((mm), (address))
25773+#define PYD_SIZE PGDIR_SIZE
25774+#else
25775+#define pxd_t pmd_t
25776+#define pyd_t pud_t
25777+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25778+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25779+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25780+#define pyd_offset(mm ,address) pud_offset((mm), (address))
25781+#define PYD_SIZE PUD_SIZE
25782+#endif
25783+
25784+#ifdef CONFIG_PAX_PER_CPU_PGD
25785+static inline void pgd_ctor(pgd_t *pgd) {}
25786+static inline void pgd_dtor(pgd_t *pgd) {}
25787+#else
25788 static void pgd_ctor(pgd_t *pgd)
25789 {
25790 /* If the pgd points to a shared pagetable level (either the
25791@@ -119,6 +162,7 @@ static void pgd_dtor(pgd_t *pgd)
25792 pgd_list_del(pgd);
25793 spin_unlock_irqrestore(&pgd_lock, flags);
25794 }
25795+#endif
25796
25797 /*
25798 * List of all pgd's needed for non-PAE so it can invalidate entries
25799@@ -131,7 +175,7 @@ static void pgd_dtor(pgd_t *pgd)
25800 * -- wli
25801 */
25802
25803-#ifdef CONFIG_X86_PAE
25804+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25805 /*
25806 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25807 * updating the top-level pagetable entries to guarantee the
25808@@ -143,7 +187,7 @@ static void pgd_dtor(pgd_t *pgd)
25809 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25810 * and initialize the kernel pmds here.
25811 */
25812-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25813+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25814
25815 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25816 {
25817@@ -161,36 +205,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25818 */
25819 flush_tlb_mm(mm);
25820 }
25821+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25822+#define PREALLOCATED_PXDS USER_PGD_PTRS
25823 #else /* !CONFIG_X86_PAE */
25824
25825 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25826-#define PREALLOCATED_PMDS 0
25827+#define PREALLOCATED_PXDS 0
25828
25829 #endif /* CONFIG_X86_PAE */
25830
25831-static void free_pmds(pmd_t *pmds[])
25832+static void free_pxds(pxd_t *pxds[])
25833 {
25834 int i;
25835
25836- for(i = 0; i < PREALLOCATED_PMDS; i++)
25837- if (pmds[i])
25838- free_page((unsigned long)pmds[i]);
25839+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25840+ if (pxds[i])
25841+ free_page((unsigned long)pxds[i]);
25842 }
25843
25844-static int preallocate_pmds(pmd_t *pmds[])
25845+static int preallocate_pxds(pxd_t *pxds[])
25846 {
25847 int i;
25848 bool failed = false;
25849
25850- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25851- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25852- if (pmd == NULL)
25853+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25854+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25855+ if (pxd == NULL)
25856 failed = true;
25857- pmds[i] = pmd;
25858+ pxds[i] = pxd;
25859 }
25860
25861 if (failed) {
25862- free_pmds(pmds);
25863+ free_pxds(pxds);
25864 return -ENOMEM;
25865 }
25866
25867@@ -203,51 +249,56 @@ static int preallocate_pmds(pmd_t *pmds[])
25868 * preallocate which never got a corresponding vma will need to be
25869 * freed manually.
25870 */
25871-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25872+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25873 {
25874 int i;
25875
25876- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25877+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25878 pgd_t pgd = pgdp[i];
25879
25880 if (pgd_val(pgd) != 0) {
25881- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25882+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25883
25884- pgdp[i] = native_make_pgd(0);
25885+ set_pgd(pgdp + i, native_make_pgd(0));
25886
25887- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25888- pmd_free(mm, pmd);
25889+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25890+ pxd_free(mm, pxd);
25891 }
25892 }
25893 }
25894
25895-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25896+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25897 {
25898- pud_t *pud;
25899+ pyd_t *pyd;
25900 unsigned long addr;
25901 int i;
25902
25903- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25904+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25905 return;
25906
25907- pud = pud_offset(pgd, 0);
25908+#ifdef CONFIG_X86_64
25909+ pyd = pyd_offset(mm, 0L);
25910+#else
25911+ pyd = pyd_offset(pgd, 0L);
25912+#endif
25913
25914- for (addr = i = 0; i < PREALLOCATED_PMDS;
25915- i++, pud++, addr += PUD_SIZE) {
25916- pmd_t *pmd = pmds[i];
25917+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25918+ i++, pyd++, addr += PYD_SIZE) {
25919+ pxd_t *pxd = pxds[i];
25920
25921 if (i >= KERNEL_PGD_BOUNDARY)
25922- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25923- sizeof(pmd_t) * PTRS_PER_PMD);
25924+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25925+ sizeof(pxd_t) * PTRS_PER_PMD);
25926
25927- pud_populate(mm, pud, pmd);
25928+ pyd_populate(mm, pyd, pxd);
25929 }
25930 }
25931
25932 pgd_t *pgd_alloc(struct mm_struct *mm)
25933 {
25934 pgd_t *pgd;
25935- pmd_t *pmds[PREALLOCATED_PMDS];
25936+ pxd_t *pxds[PREALLOCATED_PXDS];
25937+
25938 unsigned long flags;
25939
25940 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25941@@ -257,11 +308,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25942
25943 mm->pgd = pgd;
25944
25945- if (preallocate_pmds(pmds) != 0)
25946+ if (preallocate_pxds(pxds) != 0)
25947 goto out_free_pgd;
25948
25949 if (paravirt_pgd_alloc(mm) != 0)
25950- goto out_free_pmds;
25951+ goto out_free_pxds;
25952
25953 /*
25954 * Make sure that pre-populating the pmds is atomic with
25955@@ -271,14 +322,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25956 spin_lock_irqsave(&pgd_lock, flags);
25957
25958 pgd_ctor(pgd);
25959- pgd_prepopulate_pmd(mm, pgd, pmds);
25960+ pgd_prepopulate_pxd(mm, pgd, pxds);
25961
25962 spin_unlock_irqrestore(&pgd_lock, flags);
25963
25964 return pgd;
25965
25966-out_free_pmds:
25967- free_pmds(pmds);
25968+out_free_pxds:
25969+ free_pxds(pxds);
25970 out_free_pgd:
25971 free_page((unsigned long)pgd);
25972 out:
25973@@ -287,7 +338,7 @@ out:
25974
25975 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25976 {
25977- pgd_mop_up_pmds(mm, pgd);
25978+ pgd_mop_up_pxds(mm, pgd);
25979 pgd_dtor(pgd);
25980 paravirt_pgd_free(mm, pgd);
25981 free_page((unsigned long)pgd);
25982diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25983index 46c8834..fcab43d 100644
25984--- a/arch/x86/mm/pgtable_32.c
25985+++ b/arch/x86/mm/pgtable_32.c
25986@@ -49,10 +49,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25987 return;
25988 }
25989 pte = pte_offset_kernel(pmd, vaddr);
25990+
25991+ pax_open_kernel();
25992 if (pte_val(pteval))
25993 set_pte_at(&init_mm, vaddr, pte, pteval);
25994 else
25995 pte_clear(&init_mm, vaddr, pte);
25996+ pax_close_kernel();
25997
25998 /*
25999 * It's enough to flush this one mapping.
26000diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
26001index 513d8ed..978c161 100644
26002--- a/arch/x86/mm/setup_nx.c
26003+++ b/arch/x86/mm/setup_nx.c
26004@@ -4,11 +4,10 @@
26005
26006 #include <asm/pgtable.h>
26007
26008+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26009 int nx_enabled;
26010
26011-#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26012-static int disable_nx __cpuinitdata;
26013-
26014+#ifndef CONFIG_PAX_PAGEEXEC
26015 /*
26016 * noexec = on|off
26017 *
26018@@ -22,32 +21,26 @@ static int __init noexec_setup(char *str)
26019 if (!str)
26020 return -EINVAL;
26021 if (!strncmp(str, "on", 2)) {
26022- __supported_pte_mask |= _PAGE_NX;
26023- disable_nx = 0;
26024+ nx_enabled = 1;
26025 } else if (!strncmp(str, "off", 3)) {
26026- disable_nx = 1;
26027- __supported_pte_mask &= ~_PAGE_NX;
26028+ nx_enabled = 0;
26029 }
26030 return 0;
26031 }
26032 early_param("noexec", noexec_setup);
26033 #endif
26034+#endif
26035
26036 #ifdef CONFIG_X86_PAE
26037 void __init set_nx(void)
26038 {
26039- unsigned int v[4], l, h;
26040+ if (!nx_enabled && cpu_has_nx) {
26041+ unsigned l, h;
26042
26043- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
26044- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
26045-
26046- if ((v[3] & (1 << 20)) && !disable_nx) {
26047- rdmsr(MSR_EFER, l, h);
26048- l |= EFER_NX;
26049- wrmsr(MSR_EFER, l, h);
26050- nx_enabled = 1;
26051- __supported_pte_mask |= _PAGE_NX;
26052- }
26053+ __supported_pte_mask &= ~_PAGE_NX;
26054+ rdmsr(MSR_EFER, l, h);
26055+ l &= ~EFER_NX;
26056+ wrmsr(MSR_EFER, l, h);
26057 }
26058 }
26059 #else
26060@@ -62,7 +55,7 @@ void __cpuinit check_efer(void)
26061 unsigned long efer;
26062
26063 rdmsrl(MSR_EFER, efer);
26064- if (!(efer & EFER_NX) || disable_nx)
26065+ if (!(efer & EFER_NX) || !nx_enabled)
26066 __supported_pte_mask &= ~_PAGE_NX;
26067 }
26068 #endif
26069diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
26070index 36fe08e..b123d3a 100644
26071--- a/arch/x86/mm/tlb.c
26072+++ b/arch/x86/mm/tlb.c
26073@@ -61,7 +61,11 @@ void leave_mm(int cpu)
26074 BUG();
26075 cpumask_clear_cpu(cpu,
26076 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
26077+
26078+#ifndef CONFIG_PAX_PER_CPU_PGD
26079 load_cr3(swapper_pg_dir);
26080+#endif
26081+
26082 }
26083 EXPORT_SYMBOL_GPL(leave_mm);
26084
26085diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26086index 829edf0..672adb3 100644
26087--- a/arch/x86/oprofile/backtrace.c
26088+++ b/arch/x86/oprofile/backtrace.c
26089@@ -115,7 +115,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26090 {
26091 struct frame_head *head = (struct frame_head *)frame_pointer(regs);
26092
26093- if (!user_mode_vm(regs)) {
26094+ if (!user_mode(regs)) {
26095 unsigned long stack = kernel_stack_pointer(regs);
26096 if (depth)
26097 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26098diff --git a/arch/x86/oprofile/op_model_p4.c b/arch/x86/oprofile/op_model_p4.c
26099index e6a160a..36deff6 100644
26100--- a/arch/x86/oprofile/op_model_p4.c
26101+++ b/arch/x86/oprofile/op_model_p4.c
26102@@ -50,7 +50,7 @@ static inline void setup_num_counters(void)
26103 #endif
26104 }
26105
26106-static int inline addr_increment(void)
26107+static inline int addr_increment(void)
26108 {
26109 #ifdef CONFIG_SMP
26110 return smp_num_siblings == 2 ? 2 : 1;
26111diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
26112index 1331fcf..03901b2 100644
26113--- a/arch/x86/pci/common.c
26114+++ b/arch/x86/pci/common.c
26115@@ -31,8 +31,8 @@ int noioapicreroute = 1;
26116 int pcibios_last_bus = -1;
26117 unsigned long pirq_table_addr;
26118 struct pci_bus *pci_root_bus;
26119-struct pci_raw_ops *raw_pci_ops;
26120-struct pci_raw_ops *raw_pci_ext_ops;
26121+const struct pci_raw_ops *raw_pci_ops;
26122+const struct pci_raw_ops *raw_pci_ext_ops;
26123
26124 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
26125 int reg, int len, u32 *val)
26126diff --git a/arch/x86/pci/direct.c b/arch/x86/pci/direct.c
26127index 347d882..4baf6b6 100644
26128--- a/arch/x86/pci/direct.c
26129+++ b/arch/x86/pci/direct.c
26130@@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int seg, unsigned int bus,
26131
26132 #undef PCI_CONF1_ADDRESS
26133
26134-struct pci_raw_ops pci_direct_conf1 = {
26135+const struct pci_raw_ops pci_direct_conf1 = {
26136 .read = pci_conf1_read,
26137 .write = pci_conf1_write,
26138 };
26139@@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int seg, unsigned int bus,
26140
26141 #undef PCI_CONF2_ADDRESS
26142
26143-struct pci_raw_ops pci_direct_conf2 = {
26144+const struct pci_raw_ops pci_direct_conf2 = {
26145 .read = pci_conf2_read,
26146 .write = pci_conf2_write,
26147 };
26148@@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
26149 * This should be close to trivial, but it isn't, because there are buggy
26150 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
26151 */
26152-static int __init pci_sanity_check(struct pci_raw_ops *o)
26153+static int __init pci_sanity_check(const struct pci_raw_ops *o)
26154 {
26155 u32 x = 0;
26156 int year, devfn;
26157diff --git a/arch/x86/pci/mmconfig_32.c b/arch/x86/pci/mmconfig_32.c
26158index f10a7e9..0425342 100644
26159--- a/arch/x86/pci/mmconfig_32.c
26160+++ b/arch/x86/pci/mmconfig_32.c
26161@@ -125,7 +125,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
26162 return 0;
26163 }
26164
26165-static struct pci_raw_ops pci_mmcfg = {
26166+static const struct pci_raw_ops pci_mmcfg = {
26167 .read = pci_mmcfg_read,
26168 .write = pci_mmcfg_write,
26169 };
26170diff --git a/arch/x86/pci/mmconfig_64.c b/arch/x86/pci/mmconfig_64.c
26171index 94349f8..41600a7 100644
26172--- a/arch/x86/pci/mmconfig_64.c
26173+++ b/arch/x86/pci/mmconfig_64.c
26174@@ -104,7 +104,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
26175 return 0;
26176 }
26177
26178-static struct pci_raw_ops pci_mmcfg = {
26179+static const struct pci_raw_ops pci_mmcfg = {
26180 .read = pci_mmcfg_read,
26181 .write = pci_mmcfg_write,
26182 };
26183diff --git a/arch/x86/pci/numaq_32.c b/arch/x86/pci/numaq_32.c
26184index 8eb295e..86bd657 100644
26185--- a/arch/x86/pci/numaq_32.c
26186+++ b/arch/x86/pci/numaq_32.c
26187@@ -112,7 +112,7 @@ static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
26188
26189 #undef PCI_CONF1_MQ_ADDRESS
26190
26191-static struct pci_raw_ops pci_direct_conf1_mq = {
26192+static const struct pci_raw_ops pci_direct_conf1_mq = {
26193 .read = pci_conf1_mq_read,
26194 .write = pci_conf1_mq_write
26195 };
26196diff --git a/arch/x86/pci/olpc.c b/arch/x86/pci/olpc.c
26197index b889d82..5a58a0a 100644
26198--- a/arch/x86/pci/olpc.c
26199+++ b/arch/x86/pci/olpc.c
26200@@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int seg, unsigned int bus,
26201 return 0;
26202 }
26203
26204-static struct pci_raw_ops pci_olpc_conf = {
26205+static const struct pci_raw_ops pci_olpc_conf = {
26206 .read = pci_olpc_read,
26207 .write = pci_olpc_write,
26208 };
26209diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26210index 1c975cc..ffd0536 100644
26211--- a/arch/x86/pci/pcbios.c
26212+++ b/arch/x86/pci/pcbios.c
26213@@ -56,50 +56,93 @@ union bios32 {
26214 static struct {
26215 unsigned long address;
26216 unsigned short segment;
26217-} bios32_indirect = { 0, __KERNEL_CS };
26218+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26219
26220 /*
26221 * Returns the entry point for the given service, NULL on error
26222 */
26223
26224-static unsigned long bios32_service(unsigned long service)
26225+static unsigned long __devinit bios32_service(unsigned long service)
26226 {
26227 unsigned char return_code; /* %al */
26228 unsigned long address; /* %ebx */
26229 unsigned long length; /* %ecx */
26230 unsigned long entry; /* %edx */
26231 unsigned long flags;
26232+ struct desc_struct d, *gdt;
26233
26234 local_irq_save(flags);
26235- __asm__("lcall *(%%edi); cld"
26236+
26237+ gdt = get_cpu_gdt_table(smp_processor_id());
26238+
26239+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26240+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26241+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26242+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26243+
26244+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26245 : "=a" (return_code),
26246 "=b" (address),
26247 "=c" (length),
26248 "=d" (entry)
26249 : "0" (service),
26250 "1" (0),
26251- "D" (&bios32_indirect));
26252+ "D" (&bios32_indirect),
26253+ "r"(__PCIBIOS_DS)
26254+ : "memory");
26255+
26256+ pax_open_kernel();
26257+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26258+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26259+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26260+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26261+ pax_close_kernel();
26262+
26263 local_irq_restore(flags);
26264
26265 switch (return_code) {
26266- case 0:
26267- return address + entry;
26268- case 0x80: /* Not present */
26269- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26270- return 0;
26271- default: /* Shouldn't happen */
26272- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26273- service, return_code);
26274+ case 0: {
26275+ int cpu;
26276+ unsigned char flags;
26277+
26278+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26279+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26280+ printk(KERN_WARNING "bios32_service: not valid\n");
26281 return 0;
26282+ }
26283+ address = address + PAGE_OFFSET;
26284+ length += 16UL; /* some BIOSs underreport this... */
26285+ flags = 4;
26286+ if (length >= 64*1024*1024) {
26287+ length >>= PAGE_SHIFT;
26288+ flags |= 8;
26289+ }
26290+
26291+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
26292+ gdt = get_cpu_gdt_table(cpu);
26293+ pack_descriptor(&d, address, length, 0x9b, flags);
26294+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26295+ pack_descriptor(&d, address, length, 0x93, flags);
26296+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26297+ }
26298+ return entry;
26299+ }
26300+ case 0x80: /* Not present */
26301+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26302+ return 0;
26303+ default: /* Shouldn't happen */
26304+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26305+ service, return_code);
26306+ return 0;
26307 }
26308 }
26309
26310 static struct {
26311 unsigned long address;
26312 unsigned short segment;
26313-} pci_indirect = { 0, __KERNEL_CS };
26314+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26315
26316-static int pci_bios_present;
26317+static int pci_bios_present __read_only;
26318
26319 static int __devinit check_pcibios(void)
26320 {
26321@@ -108,11 +151,13 @@ static int __devinit check_pcibios(void)
26322 unsigned long flags, pcibios_entry;
26323
26324 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26325- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26326+ pci_indirect.address = pcibios_entry;
26327
26328 local_irq_save(flags);
26329- __asm__(
26330- "lcall *(%%edi); cld\n\t"
26331+ __asm__("movw %w6, %%ds\n\t"
26332+ "lcall *%%ss:(%%edi); cld\n\t"
26333+ "push %%ss\n\t"
26334+ "pop %%ds\n\t"
26335 "jc 1f\n\t"
26336 "xor %%ah, %%ah\n"
26337 "1:"
26338@@ -121,7 +166,8 @@ static int __devinit check_pcibios(void)
26339 "=b" (ebx),
26340 "=c" (ecx)
26341 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26342- "D" (&pci_indirect)
26343+ "D" (&pci_indirect),
26344+ "r" (__PCIBIOS_DS)
26345 : "memory");
26346 local_irq_restore(flags);
26347
26348@@ -165,7 +211,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26349
26350 switch (len) {
26351 case 1:
26352- __asm__("lcall *(%%esi); cld\n\t"
26353+ __asm__("movw %w6, %%ds\n\t"
26354+ "lcall *%%ss:(%%esi); cld\n\t"
26355+ "push %%ss\n\t"
26356+ "pop %%ds\n\t"
26357 "jc 1f\n\t"
26358 "xor %%ah, %%ah\n"
26359 "1:"
26360@@ -174,7 +223,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26361 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26362 "b" (bx),
26363 "D" ((long)reg),
26364- "S" (&pci_indirect));
26365+ "S" (&pci_indirect),
26366+ "r" (__PCIBIOS_DS));
26367 /*
26368 * Zero-extend the result beyond 8 bits, do not trust the
26369 * BIOS having done it:
26370@@ -182,7 +232,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26371 *value &= 0xff;
26372 break;
26373 case 2:
26374- __asm__("lcall *(%%esi); cld\n\t"
26375+ __asm__("movw %w6, %%ds\n\t"
26376+ "lcall *%%ss:(%%esi); cld\n\t"
26377+ "push %%ss\n\t"
26378+ "pop %%ds\n\t"
26379 "jc 1f\n\t"
26380 "xor %%ah, %%ah\n"
26381 "1:"
26382@@ -191,7 +244,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26383 : "1" (PCIBIOS_READ_CONFIG_WORD),
26384 "b" (bx),
26385 "D" ((long)reg),
26386- "S" (&pci_indirect));
26387+ "S" (&pci_indirect),
26388+ "r" (__PCIBIOS_DS));
26389 /*
26390 * Zero-extend the result beyond 16 bits, do not trust the
26391 * BIOS having done it:
26392@@ -199,7 +253,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26393 *value &= 0xffff;
26394 break;
26395 case 4:
26396- __asm__("lcall *(%%esi); cld\n\t"
26397+ __asm__("movw %w6, %%ds\n\t"
26398+ "lcall *%%ss:(%%esi); cld\n\t"
26399+ "push %%ss\n\t"
26400+ "pop %%ds\n\t"
26401 "jc 1f\n\t"
26402 "xor %%ah, %%ah\n"
26403 "1:"
26404@@ -208,7 +265,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26405 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26406 "b" (bx),
26407 "D" ((long)reg),
26408- "S" (&pci_indirect));
26409+ "S" (&pci_indirect),
26410+ "r" (__PCIBIOS_DS));
26411 break;
26412 }
26413
26414@@ -231,7 +289,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26415
26416 switch (len) {
26417 case 1:
26418- __asm__("lcall *(%%esi); cld\n\t"
26419+ __asm__("movw %w6, %%ds\n\t"
26420+ "lcall *%%ss:(%%esi); cld\n\t"
26421+ "push %%ss\n\t"
26422+ "pop %%ds\n\t"
26423 "jc 1f\n\t"
26424 "xor %%ah, %%ah\n"
26425 "1:"
26426@@ -240,10 +301,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26427 "c" (value),
26428 "b" (bx),
26429 "D" ((long)reg),
26430- "S" (&pci_indirect));
26431+ "S" (&pci_indirect),
26432+ "r" (__PCIBIOS_DS));
26433 break;
26434 case 2:
26435- __asm__("lcall *(%%esi); cld\n\t"
26436+ __asm__("movw %w6, %%ds\n\t"
26437+ "lcall *%%ss:(%%esi); cld\n\t"
26438+ "push %%ss\n\t"
26439+ "pop %%ds\n\t"
26440 "jc 1f\n\t"
26441 "xor %%ah, %%ah\n"
26442 "1:"
26443@@ -252,10 +317,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26444 "c" (value),
26445 "b" (bx),
26446 "D" ((long)reg),
26447- "S" (&pci_indirect));
26448+ "S" (&pci_indirect),
26449+ "r" (__PCIBIOS_DS));
26450 break;
26451 case 4:
26452- __asm__("lcall *(%%esi); cld\n\t"
26453+ __asm__("movw %w6, %%ds\n\t"
26454+ "lcall *%%ss:(%%esi); cld\n\t"
26455+ "push %%ss\n\t"
26456+ "pop %%ds\n\t"
26457 "jc 1f\n\t"
26458 "xor %%ah, %%ah\n"
26459 "1:"
26460@@ -264,7 +333,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26461 "c" (value),
26462 "b" (bx),
26463 "D" ((long)reg),
26464- "S" (&pci_indirect));
26465+ "S" (&pci_indirect),
26466+ "r" (__PCIBIOS_DS));
26467 break;
26468 }
26469
26470@@ -278,7 +348,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26471 * Function table for BIOS32 access
26472 */
26473
26474-static struct pci_raw_ops pci_bios_access = {
26475+static const struct pci_raw_ops pci_bios_access = {
26476 .read = pci_bios_read,
26477 .write = pci_bios_write
26478 };
26479@@ -287,7 +357,7 @@ static struct pci_raw_ops pci_bios_access = {
26480 * Try to find PCI BIOS.
26481 */
26482
26483-static struct pci_raw_ops * __devinit pci_find_bios(void)
26484+static const struct pci_raw_ops * __devinit pci_find_bios(void)
26485 {
26486 union bios32 *check;
26487 unsigned char sum;
26488@@ -368,10 +438,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26489
26490 DBG("PCI: Fetching IRQ routing table... ");
26491 __asm__("push %%es\n\t"
26492+ "movw %w8, %%ds\n\t"
26493 "push %%ds\n\t"
26494 "pop %%es\n\t"
26495- "lcall *(%%esi); cld\n\t"
26496+ "lcall *%%ss:(%%esi); cld\n\t"
26497 "pop %%es\n\t"
26498+ "push %%ss\n\t"
26499+ "pop %%ds\n"
26500 "jc 1f\n\t"
26501 "xor %%ah, %%ah\n"
26502 "1:"
26503@@ -382,7 +455,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26504 "1" (0),
26505 "D" ((long) &opt),
26506 "S" (&pci_indirect),
26507- "m" (opt)
26508+ "m" (opt),
26509+ "r" (__PCIBIOS_DS)
26510 : "memory");
26511 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26512 if (ret & 0xff00)
26513@@ -406,7 +480,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26514 {
26515 int ret;
26516
26517- __asm__("lcall *(%%esi); cld\n\t"
26518+ __asm__("movw %w5, %%ds\n\t"
26519+ "lcall *%%ss:(%%esi); cld\n\t"
26520+ "push %%ss\n\t"
26521+ "pop %%ds\n"
26522 "jc 1f\n\t"
26523 "xor %%ah, %%ah\n"
26524 "1:"
26525@@ -414,7 +491,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26526 : "0" (PCIBIOS_SET_PCI_HW_INT),
26527 "b" ((dev->bus->number << 8) | dev->devfn),
26528 "c" ((irq << 8) | (pin + 10)),
26529- "S" (&pci_indirect));
26530+ "S" (&pci_indirect),
26531+ "r" (__PCIBIOS_DS));
26532 return !(ret & 0xff00);
26533 }
26534 EXPORT_SYMBOL(pcibios_set_irq_routing);
26535diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26536index fa0f651..9d8f3d9 100644
26537--- a/arch/x86/power/cpu.c
26538+++ b/arch/x86/power/cpu.c
26539@@ -129,7 +129,7 @@ static void do_fpu_end(void)
26540 static void fix_processor_context(void)
26541 {
26542 int cpu = smp_processor_id();
26543- struct tss_struct *t = &per_cpu(init_tss, cpu);
26544+ struct tss_struct *t = init_tss + cpu;
26545
26546 set_tss_desc(cpu, t); /*
26547 * This just modifies memory; should not be
26548@@ -139,7 +139,9 @@ static void fix_processor_context(void)
26549 */
26550
26551 #ifdef CONFIG_X86_64
26552+ pax_open_kernel();
26553 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26554+ pax_close_kernel();
26555
26556 syscall_init(); /* This sets MSR_*STAR and related */
26557 #endif
26558diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26559index dd78ef6..f9d928d 100644
26560--- a/arch/x86/vdso/Makefile
26561+++ b/arch/x86/vdso/Makefile
26562@@ -122,7 +122,7 @@ quiet_cmd_vdso = VDSO $@
26563 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
26564 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^)
26565
26566-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26567+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26568 GCOV_PROFILE := n
26569
26570 #
26571diff --git a/arch/x86/vdso/vclock_gettime.c b/arch/x86/vdso/vclock_gettime.c
26572index ee55754..0013b2e 100644
26573--- a/arch/x86/vdso/vclock_gettime.c
26574+++ b/arch/x86/vdso/vclock_gettime.c
26575@@ -22,24 +22,48 @@
26576 #include <asm/hpet.h>
26577 #include <asm/unistd.h>
26578 #include <asm/io.h>
26579+#include <asm/fixmap.h>
26580 #include "vextern.h"
26581
26582 #define gtod vdso_vsyscall_gtod_data
26583
26584+notrace noinline long __vdso_fallback_time(long *t)
26585+{
26586+ long secs;
26587+ asm volatile("syscall"
26588+ : "=a" (secs)
26589+ : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
26590+ return secs;
26591+}
26592+
26593 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
26594 {
26595 long ret;
26596 asm("syscall" : "=a" (ret) :
26597- "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
26598+ "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
26599 return ret;
26600 }
26601
26602+notrace static inline cycle_t __vdso_vread_hpet(void)
26603+{
26604+ return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
26605+}
26606+
26607+notrace static inline cycle_t __vdso_vread_tsc(void)
26608+{
26609+ cycle_t ret = (cycle_t)vget_cycles();
26610+
26611+ return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
26612+}
26613+
26614 notrace static inline long vgetns(void)
26615 {
26616 long v;
26617- cycles_t (*vread)(void);
26618- vread = gtod->clock.vread;
26619- v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
26620+ if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
26621+ v = __vdso_vread_tsc();
26622+ else
26623+ v = __vdso_vread_hpet();
26624+ v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
26625 return (v * gtod->clock.mult) >> gtod->clock.shift;
26626 }
26627
26628@@ -113,7 +137,9 @@ notrace static noinline int do_monotonic_coarse(struct timespec *ts)
26629
26630 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
26631 {
26632- if (likely(gtod->sysctl_enabled))
26633+ if (likely(gtod->sysctl_enabled &&
26634+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
26635+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
26636 switch (clock) {
26637 case CLOCK_REALTIME:
26638 if (likely(gtod->clock.vread))
26639@@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
26640 int clock_gettime(clockid_t, struct timespec *)
26641 __attribute__((weak, alias("__vdso_clock_gettime")));
26642
26643+notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
26644+{
26645+ long ret;
26646+ asm("syscall" : "=a" (ret) :
26647+ "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
26648+ return ret;
26649+}
26650+
26651 notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
26652 {
26653- long ret;
26654- if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
26655+ if (likely(gtod->sysctl_enabled &&
26656+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
26657+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
26658+ {
26659 if (likely(tv != NULL)) {
26660 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
26661 offsetof(struct timespec, tv_nsec) ||
26662@@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
26663 }
26664 return 0;
26665 }
26666- asm("syscall" : "=a" (ret) :
26667- "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
26668- return ret;
26669+ return __vdso_fallback_gettimeofday(tv, tz);
26670 }
26671 int gettimeofday(struct timeval *, struct timezone *)
26672 __attribute__((weak, alias("__vdso_gettimeofday")));
26673diff --git a/arch/x86/vdso/vdso.lds.S b/arch/x86/vdso/vdso.lds.S
26674index 4e5dd3b..00ba15e 100644
26675--- a/arch/x86/vdso/vdso.lds.S
26676+++ b/arch/x86/vdso/vdso.lds.S
26677@@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
26678 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
26679 #include "vextern.h"
26680 #undef VEXTERN
26681+
26682+#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
26683+VEXTERN(fallback_gettimeofday)
26684+VEXTERN(fallback_time)
26685+VEXTERN(getcpu)
26686+#undef VEXTERN
26687diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26688index 58bc00f..d53fb48 100644
26689--- a/arch/x86/vdso/vdso32-setup.c
26690+++ b/arch/x86/vdso/vdso32-setup.c
26691@@ -25,6 +25,7 @@
26692 #include <asm/tlbflush.h>
26693 #include <asm/vdso.h>
26694 #include <asm/proto.h>
26695+#include <asm/mman.h>
26696
26697 enum {
26698 VDSO_DISABLED = 0,
26699@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26700 void enable_sep_cpu(void)
26701 {
26702 int cpu = get_cpu();
26703- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26704+ struct tss_struct *tss = init_tss + cpu;
26705
26706 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26707 put_cpu();
26708@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26709 gate_vma.vm_start = FIXADDR_USER_START;
26710 gate_vma.vm_end = FIXADDR_USER_END;
26711 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26712- gate_vma.vm_page_prot = __P101;
26713+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26714 /*
26715 * Make sure the vDSO gets into every core dump.
26716 * Dumping its contents makes post-mortem fully interpretable later
26717@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26718 if (compat)
26719 addr = VDSO_HIGH_BASE;
26720 else {
26721- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26722+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26723 if (IS_ERR_VALUE(addr)) {
26724 ret = addr;
26725 goto up_fail;
26726 }
26727 }
26728
26729- current->mm->context.vdso = (void *)addr;
26730+ current->mm->context.vdso = addr;
26731
26732 if (compat_uses_vma || !compat) {
26733 /*
26734@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26735 }
26736
26737 current_thread_info()->sysenter_return =
26738- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26739+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26740
26741 up_fail:
26742 if (ret)
26743- current->mm->context.vdso = NULL;
26744+ current->mm->context.vdso = 0;
26745
26746 up_write(&mm->mmap_sem);
26747
26748@@ -413,8 +414,14 @@ __initcall(ia32_binfmt_init);
26749
26750 const char *arch_vma_name(struct vm_area_struct *vma)
26751 {
26752- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26753+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26754 return "[vdso]";
26755+
26756+#ifdef CONFIG_PAX_SEGMEXEC
26757+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26758+ return "[vdso]";
26759+#endif
26760+
26761 return NULL;
26762 }
26763
26764@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
26765 struct mm_struct *mm = tsk->mm;
26766
26767 /* Check to see if this task was created in compat vdso mode */
26768- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26769+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26770 return &gate_vma;
26771 return NULL;
26772 }
26773diff --git a/arch/x86/vdso/vextern.h b/arch/x86/vdso/vextern.h
26774index 1683ba2..48d07f3 100644
26775--- a/arch/x86/vdso/vextern.h
26776+++ b/arch/x86/vdso/vextern.h
26777@@ -11,6 +11,5 @@
26778 put into vextern.h and be referenced as a pointer with vdso prefix.
26779 The main kernel later fills in the values. */
26780
26781-VEXTERN(jiffies)
26782 VEXTERN(vgetcpu_mode)
26783 VEXTERN(vsyscall_gtod_data)
26784diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26785index 21e1aeb..2c0b3c4 100644
26786--- a/arch/x86/vdso/vma.c
26787+++ b/arch/x86/vdso/vma.c
26788@@ -17,8 +17,6 @@
26789 #include "vextern.h" /* Just for VMAGIC. */
26790 #undef VEXTERN
26791
26792-unsigned int __read_mostly vdso_enabled = 1;
26793-
26794 extern char vdso_start[], vdso_end[];
26795 extern unsigned short vdso_sync_cpuid;
26796
26797@@ -27,10 +25,8 @@ static unsigned vdso_size;
26798
26799 static inline void *var_ref(void *p, char *name)
26800 {
26801- if (*(void **)p != (void *)VMAGIC) {
26802- printk("VDSO: variable %s broken\n", name);
26803- vdso_enabled = 0;
26804- }
26805+ if (*(void **)p != (void *)VMAGIC)
26806+ panic("VDSO: variable %s broken\n", name);
26807 return p;
26808 }
26809
26810@@ -57,21 +53,18 @@ static int __init init_vdso_vars(void)
26811 if (!vbase)
26812 goto oom;
26813
26814- if (memcmp(vbase, "\177ELF", 4)) {
26815- printk("VDSO: I'm broken; not ELF\n");
26816- vdso_enabled = 0;
26817- }
26818+ if (memcmp(vbase, ELFMAG, SELFMAG))
26819+ panic("VDSO: I'm broken; not ELF\n");
26820
26821 #define VEXTERN(x) \
26822 *(typeof(__ ## x) **) var_ref(VDSO64_SYMBOL(vbase, x), #x) = &__ ## x;
26823 #include "vextern.h"
26824 #undef VEXTERN
26825+ vunmap(vbase);
26826 return 0;
26827
26828 oom:
26829- printk("Cannot allocate vdso\n");
26830- vdso_enabled = 0;
26831- return -ENOMEM;
26832+ panic("Cannot allocate vdso\n");
26833 }
26834 __initcall(init_vdso_vars);
26835
26836@@ -102,13 +95,15 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26837 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26838 {
26839 struct mm_struct *mm = current->mm;
26840- unsigned long addr;
26841+ unsigned long addr = 0;
26842 int ret;
26843
26844- if (!vdso_enabled)
26845- return 0;
26846-
26847 down_write(&mm->mmap_sem);
26848+
26849+#ifdef CONFIG_PAX_RANDMMAP
26850+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26851+#endif
26852+
26853 addr = vdso_addr(mm->start_stack, vdso_size);
26854 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26855 if (IS_ERR_VALUE(addr)) {
26856@@ -116,7 +111,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26857 goto up_fail;
26858 }
26859
26860- current->mm->context.vdso = (void *)addr;
26861+ current->mm->context.vdso = addr;
26862
26863 ret = install_special_mapping(mm, addr, vdso_size,
26864 VM_READ|VM_EXEC|
26865@@ -124,7 +119,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26866 VM_ALWAYSDUMP,
26867 vdso_pages);
26868 if (ret) {
26869- current->mm->context.vdso = NULL;
26870+ current->mm->context.vdso = 0;
26871 goto up_fail;
26872 }
26873
26874@@ -132,10 +127,3 @@ up_fail:
26875 up_write(&mm->mmap_sem);
26876 return ret;
26877 }
26878-
26879-static __init int vdso_setup(char *s)
26880-{
26881- vdso_enabled = simple_strtoul(s, NULL, 0);
26882- return 0;
26883-}
26884-__setup("vdso=", vdso_setup);
26885diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26886index 0087b00..eecb34f 100644
26887--- a/arch/x86/xen/enlighten.c
26888+++ b/arch/x86/xen/enlighten.c
26889@@ -71,8 +71,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26890
26891 struct shared_info xen_dummy_shared_info;
26892
26893-void *xen_initial_gdt;
26894-
26895 /*
26896 * Point at some empty memory to start with. We map the real shared_info
26897 * page as soon as fixmap is up and running.
26898@@ -548,7 +546,7 @@ static void xen_write_idt_entry(gate_desc *dt, int entrynum, const gate_desc *g)
26899
26900 preempt_disable();
26901
26902- start = __get_cpu_var(idt_desc).address;
26903+ start = (unsigned long)__get_cpu_var(idt_desc).address;
26904 end = start + __get_cpu_var(idt_desc).size + 1;
26905
26906 xen_mc_flush();
26907@@ -993,7 +991,7 @@ static const struct pv_apic_ops xen_apic_ops __initdata = {
26908 #endif
26909 };
26910
26911-static void xen_reboot(int reason)
26912+static __noreturn void xen_reboot(int reason)
26913 {
26914 struct sched_shutdown r = { .reason = reason };
26915
26916@@ -1001,17 +999,17 @@ static void xen_reboot(int reason)
26917 BUG();
26918 }
26919
26920-static void xen_restart(char *msg)
26921+static __noreturn void xen_restart(char *msg)
26922 {
26923 xen_reboot(SHUTDOWN_reboot);
26924 }
26925
26926-static void xen_emergency_restart(void)
26927+static __noreturn void xen_emergency_restart(void)
26928 {
26929 xen_reboot(SHUTDOWN_reboot);
26930 }
26931
26932-static void xen_machine_halt(void)
26933+static __noreturn void xen_machine_halt(void)
26934 {
26935 xen_reboot(SHUTDOWN_poweroff);
26936 }
26937@@ -1095,9 +1093,20 @@ asmlinkage void __init xen_start_kernel(void)
26938 */
26939 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26940
26941-#ifdef CONFIG_X86_64
26942 /* Work out if we support NX */
26943- check_efer();
26944+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26945+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26946+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26947+ unsigned l, h;
26948+
26949+#ifdef CONFIG_X86_PAE
26950+ nx_enabled = 1;
26951+#endif
26952+ __supported_pte_mask |= _PAGE_NX;
26953+ rdmsr(MSR_EFER, l, h);
26954+ l |= EFER_NX;
26955+ wrmsr(MSR_EFER, l, h);
26956+ }
26957 #endif
26958
26959 xen_setup_features();
26960@@ -1129,13 +1138,6 @@ asmlinkage void __init xen_start_kernel(void)
26961
26962 machine_ops = xen_machine_ops;
26963
26964- /*
26965- * The only reliable way to retain the initial address of the
26966- * percpu gdt_page is to remember it here, so we can go and
26967- * mark it RW later, when the initial percpu area is freed.
26968- */
26969- xen_initial_gdt = &per_cpu(gdt_page, 0);
26970-
26971 xen_smp_init();
26972
26973 pgd = (pgd_t *)xen_start_info->pt_base;
26974diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26975index 3f90a2c..2c2ad84 100644
26976--- a/arch/x86/xen/mmu.c
26977+++ b/arch/x86/xen/mmu.c
26978@@ -1719,6 +1719,9 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
26979 convert_pfn_mfn(init_level4_pgt);
26980 convert_pfn_mfn(level3_ident_pgt);
26981 convert_pfn_mfn(level3_kernel_pgt);
26982+ convert_pfn_mfn(level3_vmalloc_start_pgt);
26983+ convert_pfn_mfn(level3_vmalloc_end_pgt);
26984+ convert_pfn_mfn(level3_vmemmap_pgt);
26985
26986 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26987 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26988@@ -1737,7 +1740,11 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
26989 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26990 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26991 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26992+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26993+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26994+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26995 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26996+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26997 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26998 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26999
27000@@ -1860,6 +1867,7 @@ static __init void xen_post_allocator_init(void)
27001 pv_mmu_ops.set_pud = xen_set_pud;
27002 #if PAGETABLE_LEVELS == 4
27003 pv_mmu_ops.set_pgd = xen_set_pgd;
27004+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27005 #endif
27006
27007 /* This will work as long as patching hasn't happened yet
27008@@ -1946,6 +1954,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initdata = {
27009 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27010 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27011 .set_pgd = xen_set_pgd_hyper,
27012+ .set_pgd_batched = xen_set_pgd_hyper,
27013
27014 .alloc_pud = xen_alloc_pmd_init,
27015 .release_pud = xen_release_pmd_init,
27016diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27017index a96204a..fca9b8e 100644
27018--- a/arch/x86/xen/smp.c
27019+++ b/arch/x86/xen/smp.c
27020@@ -168,11 +168,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27021 {
27022 BUG_ON(smp_processor_id() != 0);
27023 native_smp_prepare_boot_cpu();
27024-
27025- /* We've switched to the "real" per-cpu gdt, so make sure the
27026- old memory can be recycled */
27027- make_lowmem_page_readwrite(xen_initial_gdt);
27028-
27029 xen_setup_vcpu_info_placement();
27030 }
27031
27032@@ -241,12 +236,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27033 gdt = get_cpu_gdt_table(cpu);
27034
27035 ctxt->flags = VGCF_IN_KERNEL;
27036- ctxt->user_regs.ds = __USER_DS;
27037- ctxt->user_regs.es = __USER_DS;
27038+ ctxt->user_regs.ds = __KERNEL_DS;
27039+ ctxt->user_regs.es = __KERNEL_DS;
27040 ctxt->user_regs.ss = __KERNEL_DS;
27041 #ifdef CONFIG_X86_32
27042 ctxt->user_regs.fs = __KERNEL_PERCPU;
27043- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27044+ savesegment(gs, ctxt->user_regs.gs);
27045 #else
27046 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27047 #endif
27048@@ -297,13 +292,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27049 int rc;
27050
27051 per_cpu(current_task, cpu) = idle;
27052+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27053 #ifdef CONFIG_X86_32
27054 irq_ctx_init(cpu);
27055 #else
27056 clear_tsk_thread_flag(idle, TIF_FORK);
27057- per_cpu(kernel_stack, cpu) =
27058- (unsigned long)task_stack_page(idle) -
27059- KERNEL_STACK_OFFSET + THREAD_SIZE;
27060+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27061 #endif
27062 xen_setup_runstate_info(cpu);
27063 xen_setup_timer(cpu);
27064diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27065index 9a95a9c..4f39e774 100644
27066--- a/arch/x86/xen/xen-asm_32.S
27067+++ b/arch/x86/xen/xen-asm_32.S
27068@@ -83,14 +83,14 @@ ENTRY(xen_iret)
27069 ESP_OFFSET=4 # bytes pushed onto stack
27070
27071 /*
27072- * Store vcpu_info pointer for easy access. Do it this way to
27073- * avoid having to reload %fs
27074+ * Store vcpu_info pointer for easy access.
27075 */
27076 #ifdef CONFIG_SMP
27077- GET_THREAD_INFO(%eax)
27078- movl TI_cpu(%eax), %eax
27079- movl __per_cpu_offset(,%eax,4), %eax
27080- mov per_cpu__xen_vcpu(%eax), %eax
27081+ push %fs
27082+ mov $(__KERNEL_PERCPU), %eax
27083+ mov %eax, %fs
27084+ mov PER_CPU_VAR(xen_vcpu), %eax
27085+ pop %fs
27086 #else
27087 movl per_cpu__xen_vcpu, %eax
27088 #endif
27089diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27090index 1a5ff24..a187d40 100644
27091--- a/arch/x86/xen/xen-head.S
27092+++ b/arch/x86/xen/xen-head.S
27093@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27094 #ifdef CONFIG_X86_32
27095 mov %esi,xen_start_info
27096 mov $init_thread_union+THREAD_SIZE,%esp
27097+#ifdef CONFIG_SMP
27098+ movl $cpu_gdt_table,%edi
27099+ movl $__per_cpu_load,%eax
27100+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27101+ rorl $16,%eax
27102+ movb %al,__KERNEL_PERCPU + 4(%edi)
27103+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27104+ movl $__per_cpu_end - 1,%eax
27105+ subl $__per_cpu_start,%eax
27106+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27107+#endif
27108 #else
27109 mov %rsi,xen_start_info
27110 mov $init_thread_union+THREAD_SIZE,%rsp
27111diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27112index f9153a3..51eab3d 100644
27113--- a/arch/x86/xen/xen-ops.h
27114+++ b/arch/x86/xen/xen-ops.h
27115@@ -10,8 +10,6 @@
27116 extern const char xen_hypervisor_callback[];
27117 extern const char xen_failsafe_callback[];
27118
27119-extern void *xen_initial_gdt;
27120-
27121 struct trap_info;
27122 void xen_copy_trap_info(struct trap_info *traps);
27123
27124diff --git a/block/blk-integrity.c b/block/blk-integrity.c
27125index 15c6308..96e83c2 100644
27126--- a/block/blk-integrity.c
27127+++ b/block/blk-integrity.c
27128@@ -278,7 +278,7 @@ static struct attribute *integrity_attrs[] = {
27129 NULL,
27130 };
27131
27132-static struct sysfs_ops integrity_ops = {
27133+static const struct sysfs_ops integrity_ops = {
27134 .show = &integrity_attr_show,
27135 .store = &integrity_attr_store,
27136 };
27137diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27138index ca56420..f2fc409 100644
27139--- a/block/blk-iopoll.c
27140+++ b/block/blk-iopoll.c
27141@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27142 }
27143 EXPORT_SYMBOL(blk_iopoll_complete);
27144
27145-static void blk_iopoll_softirq(struct softirq_action *h)
27146+static void blk_iopoll_softirq(void)
27147 {
27148 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27149 int rearm = 0, budget = blk_iopoll_budget;
27150diff --git a/block/blk-map.c b/block/blk-map.c
27151index 30a7e51..0aeec6a 100644
27152--- a/block/blk-map.c
27153+++ b/block/blk-map.c
27154@@ -54,7 +54,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
27155 * direct dma. else, set up kernel bounce buffers
27156 */
27157 uaddr = (unsigned long) ubuf;
27158- if (blk_rq_aligned(q, ubuf, len) && !map_data)
27159+ if (blk_rq_aligned(q, (__force void *)ubuf, len) && !map_data)
27160 bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
27161 else
27162 bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask);
27163@@ -201,12 +201,13 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
27164 for (i = 0; i < iov_count; i++) {
27165 unsigned long uaddr = (unsigned long)iov[i].iov_base;
27166
27167+ if (!iov[i].iov_len)
27168+ return -EINVAL;
27169+
27170 if (uaddr & queue_dma_alignment(q)) {
27171 unaligned = 1;
27172 break;
27173 }
27174- if (!iov[i].iov_len)
27175- return -EINVAL;
27176 }
27177
27178 if (unaligned || (q->dma_pad_mask & len) || map_data)
27179@@ -299,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27180 if (!len || !kbuf)
27181 return -EINVAL;
27182
27183- do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
27184+ do_copy = !blk_rq_aligned(q, kbuf, len) || object_starts_on_stack(kbuf);
27185 if (do_copy)
27186 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27187 else
27188diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27189index ee9c216..58d410a 100644
27190--- a/block/blk-softirq.c
27191+++ b/block/blk-softirq.c
27192@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27193 * Softirq action handler - move entries to local list and loop over them
27194 * while passing them to the queue registered handler.
27195 */
27196-static void blk_done_softirq(struct softirq_action *h)
27197+static void blk_done_softirq(void)
27198 {
27199 struct list_head *cpu_list, local_list;
27200
27201diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
27202index bb9c5ea..5330d48 100644
27203--- a/block/blk-sysfs.c
27204+++ b/block/blk-sysfs.c
27205@@ -414,7 +414,7 @@ static void blk_release_queue(struct kobject *kobj)
27206 kmem_cache_free(blk_requestq_cachep, q);
27207 }
27208
27209-static struct sysfs_ops queue_sysfs_ops = {
27210+static const struct sysfs_ops queue_sysfs_ops = {
27211 .show = queue_attr_show,
27212 .store = queue_attr_store,
27213 };
27214diff --git a/block/bsg.c b/block/bsg.c
27215index 7154a7a..08ac2f0 100644
27216--- a/block/bsg.c
27217+++ b/block/bsg.c
27218@@ -175,16 +175,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27219 struct sg_io_v4 *hdr, struct bsg_device *bd,
27220 fmode_t has_write_perm)
27221 {
27222+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27223+ unsigned char *cmdptr;
27224+
27225 if (hdr->request_len > BLK_MAX_CDB) {
27226 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27227 if (!rq->cmd)
27228 return -ENOMEM;
27229- }
27230+ cmdptr = rq->cmd;
27231+ } else
27232+ cmdptr = tmpcmd;
27233
27234- if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
27235+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27236 hdr->request_len))
27237 return -EFAULT;
27238
27239+ if (cmdptr != rq->cmd)
27240+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27241+
27242 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27243 if (blk_verify_command(rq->cmd, has_write_perm))
27244 return -EPERM;
27245@@ -282,7 +290,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
27246 rq->next_rq = next_rq;
27247 next_rq->cmd_type = rq->cmd_type;
27248
27249- dxferp = (void*)(unsigned long)hdr->din_xferp;
27250+ dxferp = (void __user *)(unsigned long)hdr->din_xferp;
27251 ret = blk_rq_map_user(q, next_rq, NULL, dxferp,
27252 hdr->din_xfer_len, GFP_KERNEL);
27253 if (ret)
27254@@ -291,10 +299,10 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
27255
27256 if (hdr->dout_xfer_len) {
27257 dxfer_len = hdr->dout_xfer_len;
27258- dxferp = (void*)(unsigned long)hdr->dout_xferp;
27259+ dxferp = (void __user *)(unsigned long)hdr->dout_xferp;
27260 } else if (hdr->din_xfer_len) {
27261 dxfer_len = hdr->din_xfer_len;
27262- dxferp = (void*)(unsigned long)hdr->din_xferp;
27263+ dxferp = (void __user *)(unsigned long)hdr->din_xferp;
27264 } else
27265 dxfer_len = 0;
27266
27267@@ -436,7 +444,7 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
27268 int len = min_t(unsigned int, hdr->max_response_len,
27269 rq->sense_len);
27270
27271- ret = copy_to_user((void*)(unsigned long)hdr->response,
27272+ ret = copy_to_user((void __user *)(unsigned long)hdr->response,
27273 rq->sense, len);
27274 if (!ret)
27275 hdr->response_len = len;
27276diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27277index 9bd086c..ca1fc22 100644
27278--- a/block/compat_ioctl.c
27279+++ b/block/compat_ioctl.c
27280@@ -354,7 +354,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27281 err |= __get_user(f->spec1, &uf->spec1);
27282 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27283 err |= __get_user(name, &uf->name);
27284- f->name = compat_ptr(name);
27285+ f->name = (void __force_kernel *)compat_ptr(name);
27286 if (err) {
27287 err = -EFAULT;
27288 goto out;
27289diff --git a/block/elevator.c b/block/elevator.c
27290index a847046..75a1746 100644
27291--- a/block/elevator.c
27292+++ b/block/elevator.c
27293@@ -889,7 +889,7 @@ elv_attr_store(struct kobject *kobj, struct attribute *attr,
27294 return error;
27295 }
27296
27297-static struct sysfs_ops elv_sysfs_ops = {
27298+static const struct sysfs_ops elv_sysfs_ops = {
27299 .show = elv_attr_show,
27300 .store = elv_attr_store,
27301 };
27302diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27303index 114ee29..d0efa50 100644
27304--- a/block/scsi_ioctl.c
27305+++ b/block/scsi_ioctl.c
27306@@ -24,6 +24,7 @@
27307 #include <linux/capability.h>
27308 #include <linux/completion.h>
27309 #include <linux/cdrom.h>
27310+#include <linux/ratelimit.h>
27311 #include <linux/slab.h>
27312 #include <linux/times.h>
27313 #include <asm/uaccess.h>
27314@@ -220,8 +221,20 @@ EXPORT_SYMBOL(blk_verify_command);
27315 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27316 struct sg_io_hdr *hdr, fmode_t mode)
27317 {
27318- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27319+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27320+ unsigned char *cmdptr;
27321+
27322+ if (rq->cmd != rq->__cmd)
27323+ cmdptr = rq->cmd;
27324+ else
27325+ cmdptr = tmpcmd;
27326+
27327+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27328 return -EFAULT;
27329+
27330+ if (cmdptr != rq->cmd)
27331+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27332+
27333 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27334 return -EPERM;
27335
27336@@ -430,6 +443,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27337 int err;
27338 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27339 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27340+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27341+ unsigned char *cmdptr;
27342
27343 if (!sic)
27344 return -EINVAL;
27345@@ -463,9 +478,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27346 */
27347 err = -EFAULT;
27348 rq->cmd_len = cmdlen;
27349- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27350+
27351+ if (rq->cmd != rq->__cmd)
27352+ cmdptr = rq->cmd;
27353+ else
27354+ cmdptr = tmpcmd;
27355+
27356+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27357 goto error;
27358
27359+ if (rq->cmd != cmdptr)
27360+ memcpy(rq->cmd, cmdptr, cmdlen);
27361+
27362 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27363 goto error;
27364
27365@@ -689,9 +713,54 @@ int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mod
27366 }
27367 EXPORT_SYMBOL(scsi_cmd_ioctl);
27368
27369+int scsi_verify_blk_ioctl(struct block_device *bd, unsigned int cmd)
27370+{
27371+ if (bd && bd == bd->bd_contains)
27372+ return 0;
27373+
27374+ /* Actually none of these is particularly useful on a partition,
27375+ * but they are safe.
27376+ */
27377+ switch (cmd) {
27378+ case SCSI_IOCTL_GET_IDLUN:
27379+ case SCSI_IOCTL_GET_BUS_NUMBER:
27380+ case SCSI_IOCTL_GET_PCI:
27381+ case SCSI_IOCTL_PROBE_HOST:
27382+ case SG_GET_VERSION_NUM:
27383+ case SG_SET_TIMEOUT:
27384+ case SG_GET_TIMEOUT:
27385+ case SG_GET_RESERVED_SIZE:
27386+ case SG_SET_RESERVED_SIZE:
27387+ case SG_EMULATED_HOST:
27388+ return 0;
27389+ case CDROM_GET_CAPABILITY:
27390+ /* Keep this until we remove the printk below. udev sends it
27391+ * and we do not want to spam dmesg about it. CD-ROMs do
27392+ * not have partitions, so we get here only for disks.
27393+ */
27394+ return -ENOIOCTLCMD;
27395+ default:
27396+ break;
27397+ }
27398+
27399+ /* In particular, rule out all resets and host-specific ioctls. */
27400+ if (printk_ratelimit())
27401+ printk(KERN_WARNING "%s: sending ioctl %x to a partition!\n",
27402+ current->comm, cmd);
27403+
27404+ return capable(CAP_SYS_RAWIO) ? 0 : -ENOIOCTLCMD;
27405+}
27406+EXPORT_SYMBOL(scsi_verify_blk_ioctl);
27407+
27408 int scsi_cmd_blk_ioctl(struct block_device *bd, fmode_t mode,
27409 unsigned int cmd, void __user *arg)
27410 {
27411+ int ret;
27412+
27413+ ret = scsi_verify_blk_ioctl(bd, cmd);
27414+ if (ret < 0)
27415+ return ret;
27416+
27417 return scsi_cmd_ioctl(bd->bd_disk->queue, bd->bd_disk, mode, cmd, arg);
27418 }
27419 EXPORT_SYMBOL(scsi_cmd_blk_ioctl);
27420diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27421index 3533582..f143117 100644
27422--- a/crypto/cryptd.c
27423+++ b/crypto/cryptd.c
27424@@ -50,7 +50,7 @@ struct cryptd_blkcipher_ctx {
27425
27426 struct cryptd_blkcipher_request_ctx {
27427 crypto_completion_t complete;
27428-};
27429+} __no_const;
27430
27431 struct cryptd_hash_ctx {
27432 struct crypto_shash *child;
27433diff --git a/crypto/gf128mul.c b/crypto/gf128mul.c
27434index a90d260..7a9765e 100644
27435--- a/crypto/gf128mul.c
27436+++ b/crypto/gf128mul.c
27437@@ -182,7 +182,7 @@ void gf128mul_lle(be128 *r, const be128 *b)
27438 for (i = 0; i < 7; ++i)
27439 gf128mul_x_lle(&p[i + 1], &p[i]);
27440
27441- memset(r, 0, sizeof(r));
27442+ memset(r, 0, sizeof(*r));
27443 for (i = 0;;) {
27444 u8 ch = ((u8 *)b)[15 - i];
27445
27446@@ -220,7 +220,7 @@ void gf128mul_bbe(be128 *r, const be128 *b)
27447 for (i = 0; i < 7; ++i)
27448 gf128mul_x_bbe(&p[i + 1], &p[i]);
27449
27450- memset(r, 0, sizeof(r));
27451+ memset(r, 0, sizeof(*r));
27452 for (i = 0;;) {
27453 u8 ch = ((u8 *)b)[i];
27454
27455diff --git a/crypto/serpent.c b/crypto/serpent.c
27456index b651a55..023297d 100644
27457--- a/crypto/serpent.c
27458+++ b/crypto/serpent.c
27459@@ -21,6 +21,7 @@
27460 #include <asm/byteorder.h>
27461 #include <linux/crypto.h>
27462 #include <linux/types.h>
27463+#include <linux/sched.h>
27464
27465 /* Key is padded to the maximum of 256 bits before round key generation.
27466 * Any key length <= 256 bits (32 bytes) is allowed by the algorithm.
27467@@ -224,6 +225,8 @@ static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key,
27468 u32 r0,r1,r2,r3,r4;
27469 int i;
27470
27471+ pax_track_stack();
27472+
27473 /* Copy key, add padding */
27474
27475 for (i = 0; i < keylen; ++i)
27476diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
27477index 0d2cdb8..d8de48d 100644
27478--- a/drivers/acpi/acpi_pad.c
27479+++ b/drivers/acpi/acpi_pad.c
27480@@ -30,7 +30,7 @@
27481 #include <acpi/acpi_bus.h>
27482 #include <acpi/acpi_drivers.h>
27483
27484-#define ACPI_PROCESSOR_AGGREGATOR_CLASS "processor_aggregator"
27485+#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
27486 #define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
27487 #define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
27488 static DEFINE_MUTEX(isolated_cpus_lock);
27489diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
27490index 3f4602b..2e41d36 100644
27491--- a/drivers/acpi/battery.c
27492+++ b/drivers/acpi/battery.c
27493@@ -763,7 +763,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
27494 }
27495
27496 static struct battery_file {
27497- struct file_operations ops;
27498+ const struct file_operations ops;
27499 mode_t mode;
27500 const char *name;
27501 } acpi_battery_file[] = {
27502diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
27503index 7338b6a..82f0257 100644
27504--- a/drivers/acpi/dock.c
27505+++ b/drivers/acpi/dock.c
27506@@ -77,7 +77,7 @@ struct dock_dependent_device {
27507 struct list_head list;
27508 struct list_head hotplug_list;
27509 acpi_handle handle;
27510- struct acpi_dock_ops *ops;
27511+ const struct acpi_dock_ops *ops;
27512 void *context;
27513 };
27514
27515@@ -605,7 +605,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifier);
27516 * the dock driver after _DCK is executed.
27517 */
27518 int
27519-register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
27520+register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
27521 void *context)
27522 {
27523 struct dock_dependent_device *dd;
27524diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
27525index 7c1c59e..2993595 100644
27526--- a/drivers/acpi/osl.c
27527+++ b/drivers/acpi/osl.c
27528@@ -523,6 +523,8 @@ acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
27529 void __iomem *virt_addr;
27530
27531 virt_addr = ioremap(phys_addr, width);
27532+ if (!virt_addr)
27533+ return AE_NO_MEMORY;
27534 if (!value)
27535 value = &dummy;
27536
27537@@ -551,6 +553,8 @@ acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
27538 void __iomem *virt_addr;
27539
27540 virt_addr = ioremap(phys_addr, width);
27541+ if (!virt_addr)
27542+ return AE_NO_MEMORY;
27543
27544 switch (width) {
27545 case 8:
27546diff --git a/drivers/acpi/power_meter.c b/drivers/acpi/power_meter.c
27547index c216062..eec10d2 100644
27548--- a/drivers/acpi/power_meter.c
27549+++ b/drivers/acpi/power_meter.c
27550@@ -315,8 +315,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
27551 return res;
27552
27553 temp /= 1000;
27554- if (temp < 0)
27555- return -EINVAL;
27556
27557 mutex_lock(&resource->lock);
27558 resource->trip[attr->index - 7] = temp;
27559diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27560index d0d25e2..961643d 100644
27561--- a/drivers/acpi/proc.c
27562+++ b/drivers/acpi/proc.c
27563@@ -391,20 +391,15 @@ acpi_system_write_wakeup_device(struct file *file,
27564 size_t count, loff_t * ppos)
27565 {
27566 struct list_head *node, *next;
27567- char strbuf[5];
27568- char str[5] = "";
27569- unsigned int len = count;
27570+ char strbuf[5] = {0};
27571 struct acpi_device *found_dev = NULL;
27572
27573- if (len > 4)
27574- len = 4;
27575- if (len < 0)
27576- return -EFAULT;
27577+ if (count > 4)
27578+ count = 4;
27579
27580- if (copy_from_user(strbuf, buffer, len))
27581+ if (copy_from_user(strbuf, buffer, count))
27582 return -EFAULT;
27583- strbuf[len] = '\0';
27584- sscanf(strbuf, "%s", str);
27585+ strbuf[count] = '\0';
27586
27587 mutex_lock(&acpi_device_lock);
27588 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27589@@ -413,7 +408,7 @@ acpi_system_write_wakeup_device(struct file *file,
27590 if (!dev->wakeup.flags.valid)
27591 continue;
27592
27593- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27594+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27595 dev->wakeup.state.enabled =
27596 dev->wakeup.state.enabled ? 0 : 1;
27597 found_dev = dev;
27598diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
27599index 7102474..de8ad22 100644
27600--- a/drivers/acpi/processor_core.c
27601+++ b/drivers/acpi/processor_core.c
27602@@ -790,7 +790,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27603 return 0;
27604 }
27605
27606- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27607+ BUG_ON(pr->id >= nr_cpu_ids);
27608
27609 /*
27610 * Buggy BIOS check
27611diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c
27612index d933980..5761f13 100644
27613--- a/drivers/acpi/sbshc.c
27614+++ b/drivers/acpi/sbshc.c
27615@@ -17,7 +17,7 @@
27616
27617 #define PREFIX "ACPI: "
27618
27619-#define ACPI_SMB_HC_CLASS "smbus_host_controller"
27620+#define ACPI_SMB_HC_CLASS "smbus_host_ctl"
27621 #define ACPI_SMB_HC_DEVICE_NAME "ACPI SMBus HC"
27622
27623 struct acpi_smb_hc {
27624diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
27625index 0458094..6978e7b 100644
27626--- a/drivers/acpi/sleep.c
27627+++ b/drivers/acpi/sleep.c
27628@@ -283,7 +283,7 @@ static int acpi_suspend_state_valid(suspend_state_t pm_state)
27629 }
27630 }
27631
27632-static struct platform_suspend_ops acpi_suspend_ops = {
27633+static const struct platform_suspend_ops acpi_suspend_ops = {
27634 .valid = acpi_suspend_state_valid,
27635 .begin = acpi_suspend_begin,
27636 .prepare_late = acpi_pm_prepare,
27637@@ -311,7 +311,7 @@ static int acpi_suspend_begin_old(suspend_state_t pm_state)
27638 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
27639 * been requested.
27640 */
27641-static struct platform_suspend_ops acpi_suspend_ops_old = {
27642+static const struct platform_suspend_ops acpi_suspend_ops_old = {
27643 .valid = acpi_suspend_state_valid,
27644 .begin = acpi_suspend_begin_old,
27645 .prepare_late = acpi_pm_disable_gpes,
27646@@ -460,7 +460,7 @@ static void acpi_pm_enable_gpes(void)
27647 acpi_enable_all_runtime_gpes();
27648 }
27649
27650-static struct platform_hibernation_ops acpi_hibernation_ops = {
27651+static const struct platform_hibernation_ops acpi_hibernation_ops = {
27652 .begin = acpi_hibernation_begin,
27653 .end = acpi_pm_end,
27654 .pre_snapshot = acpi_hibernation_pre_snapshot,
27655@@ -513,7 +513,7 @@ static int acpi_hibernation_pre_snapshot_old(void)
27656 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
27657 * been requested.
27658 */
27659-static struct platform_hibernation_ops acpi_hibernation_ops_old = {
27660+static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
27661 .begin = acpi_hibernation_begin_old,
27662 .end = acpi_pm_end,
27663 .pre_snapshot = acpi_hibernation_pre_snapshot_old,
27664diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
27665index 05dff63..b662ab7 100644
27666--- a/drivers/acpi/video.c
27667+++ b/drivers/acpi/video.c
27668@@ -359,7 +359,7 @@ static int acpi_video_set_brightness(struct backlight_device *bd)
27669 vd->brightness->levels[request_level]);
27670 }
27671
27672-static struct backlight_ops acpi_backlight_ops = {
27673+static const struct backlight_ops acpi_backlight_ops = {
27674 .get_brightness = acpi_video_get_brightness,
27675 .update_status = acpi_video_set_brightness,
27676 };
27677diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
27678index 6787aab..23ffb0e 100644
27679--- a/drivers/ata/ahci.c
27680+++ b/drivers/ata/ahci.c
27681@@ -387,7 +387,7 @@ static struct scsi_host_template ahci_sht = {
27682 .sdev_attrs = ahci_sdev_attrs,
27683 };
27684
27685-static struct ata_port_operations ahci_ops = {
27686+static const struct ata_port_operations ahci_ops = {
27687 .inherits = &sata_pmp_port_ops,
27688
27689 .qc_defer = sata_pmp_qc_defer_cmd_switch,
27690@@ -424,17 +424,17 @@ static struct ata_port_operations ahci_ops = {
27691 .port_stop = ahci_port_stop,
27692 };
27693
27694-static struct ata_port_operations ahci_vt8251_ops = {
27695+static const struct ata_port_operations ahci_vt8251_ops = {
27696 .inherits = &ahci_ops,
27697 .hardreset = ahci_vt8251_hardreset,
27698 };
27699
27700-static struct ata_port_operations ahci_p5wdh_ops = {
27701+static const struct ata_port_operations ahci_p5wdh_ops = {
27702 .inherits = &ahci_ops,
27703 .hardreset = ahci_p5wdh_hardreset,
27704 };
27705
27706-static struct ata_port_operations ahci_sb600_ops = {
27707+static const struct ata_port_operations ahci_sb600_ops = {
27708 .inherits = &ahci_ops,
27709 .softreset = ahci_sb600_softreset,
27710 .pmp_softreset = ahci_sb600_softreset,
27711diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
27712index 99e7196..4968c77 100644
27713--- a/drivers/ata/ata_generic.c
27714+++ b/drivers/ata/ata_generic.c
27715@@ -104,7 +104,7 @@ static struct scsi_host_template generic_sht = {
27716 ATA_BMDMA_SHT(DRV_NAME),
27717 };
27718
27719-static struct ata_port_operations generic_port_ops = {
27720+static const struct ata_port_operations generic_port_ops = {
27721 .inherits = &ata_bmdma_port_ops,
27722 .cable_detect = ata_cable_unknown,
27723 .set_mode = generic_set_mode,
27724diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
27725index c33591d..000c121 100644
27726--- a/drivers/ata/ata_piix.c
27727+++ b/drivers/ata/ata_piix.c
27728@@ -318,7 +318,7 @@ static struct scsi_host_template piix_sht = {
27729 ATA_BMDMA_SHT(DRV_NAME),
27730 };
27731
27732-static struct ata_port_operations piix_pata_ops = {
27733+static const struct ata_port_operations piix_pata_ops = {
27734 .inherits = &ata_bmdma32_port_ops,
27735 .cable_detect = ata_cable_40wire,
27736 .set_piomode = piix_set_piomode,
27737@@ -326,22 +326,22 @@ static struct ata_port_operations piix_pata_ops = {
27738 .prereset = piix_pata_prereset,
27739 };
27740
27741-static struct ata_port_operations piix_vmw_ops = {
27742+static const struct ata_port_operations piix_vmw_ops = {
27743 .inherits = &piix_pata_ops,
27744 .bmdma_status = piix_vmw_bmdma_status,
27745 };
27746
27747-static struct ata_port_operations ich_pata_ops = {
27748+static const struct ata_port_operations ich_pata_ops = {
27749 .inherits = &piix_pata_ops,
27750 .cable_detect = ich_pata_cable_detect,
27751 .set_dmamode = ich_set_dmamode,
27752 };
27753
27754-static struct ata_port_operations piix_sata_ops = {
27755+static const struct ata_port_operations piix_sata_ops = {
27756 .inherits = &ata_bmdma_port_ops,
27757 };
27758
27759-static struct ata_port_operations piix_sidpr_sata_ops = {
27760+static const struct ata_port_operations piix_sidpr_sata_ops = {
27761 .inherits = &piix_sata_ops,
27762 .hardreset = sata_std_hardreset,
27763 .scr_read = piix_sidpr_scr_read,
27764diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
27765index b0882cd..c295d65 100644
27766--- a/drivers/ata/libata-acpi.c
27767+++ b/drivers/ata/libata-acpi.c
27768@@ -223,12 +223,12 @@ static void ata_acpi_dev_uevent(acpi_handle handle, u32 event, void *data)
27769 ata_acpi_uevent(dev->link->ap, dev, event);
27770 }
27771
27772-static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
27773+static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
27774 .handler = ata_acpi_dev_notify_dock,
27775 .uevent = ata_acpi_dev_uevent,
27776 };
27777
27778-static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
27779+static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
27780 .handler = ata_acpi_ap_notify_dock,
27781 .uevent = ata_acpi_ap_uevent,
27782 };
27783diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27784index d4f7f99..94f603e 100644
27785--- a/drivers/ata/libata-core.c
27786+++ b/drivers/ata/libata-core.c
27787@@ -4954,7 +4954,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27788 struct ata_port *ap;
27789 unsigned int tag;
27790
27791- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27792+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27793 ap = qc->ap;
27794
27795 qc->flags = 0;
27796@@ -4970,7 +4970,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27797 struct ata_port *ap;
27798 struct ata_link *link;
27799
27800- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27801+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27802 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27803 ap = qc->ap;
27804 link = qc->dev->link;
27805@@ -5987,7 +5987,7 @@ static void ata_host_stop(struct device *gendev, void *res)
27806 * LOCKING:
27807 * None.
27808 */
27809-static void ata_finalize_port_ops(struct ata_port_operations *ops)
27810+static void ata_finalize_port_ops(const struct ata_port_operations *ops)
27811 {
27812 static DEFINE_SPINLOCK(lock);
27813 const struct ata_port_operations *cur;
27814@@ -5999,6 +5999,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27815 return;
27816
27817 spin_lock(&lock);
27818+ pax_open_kernel();
27819
27820 for (cur = ops->inherits; cur; cur = cur->inherits) {
27821 void **inherit = (void **)cur;
27822@@ -6012,8 +6013,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27823 if (IS_ERR(*pp))
27824 *pp = NULL;
27825
27826- ops->inherits = NULL;
27827+ *(struct ata_port_operations **)&ops->inherits = NULL;
27828
27829+ pax_close_kernel();
27830 spin_unlock(&lock);
27831 }
27832
27833@@ -6110,7 +6112,7 @@ int ata_host_start(struct ata_host *host)
27834 */
27835 /* KILLME - the only user left is ipr */
27836 void ata_host_init(struct ata_host *host, struct device *dev,
27837- unsigned long flags, struct ata_port_operations *ops)
27838+ unsigned long flags, const struct ata_port_operations *ops)
27839 {
27840 spin_lock_init(&host->lock);
27841 host->dev = dev;
27842@@ -6773,7 +6775,7 @@ static void ata_dummy_error_handler(struct ata_port *ap)
27843 /* truly dummy */
27844 }
27845
27846-struct ata_port_operations ata_dummy_port_ops = {
27847+const struct ata_port_operations ata_dummy_port_ops = {
27848 .qc_prep = ata_noop_qc_prep,
27849 .qc_issue = ata_dummy_qc_issue,
27850 .error_handler = ata_dummy_error_handler,
27851diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
27852index e5bdb9b..45a8e72 100644
27853--- a/drivers/ata/libata-eh.c
27854+++ b/drivers/ata/libata-eh.c
27855@@ -2423,6 +2423,8 @@ void ata_eh_report(struct ata_port *ap)
27856 {
27857 struct ata_link *link;
27858
27859+ pax_track_stack();
27860+
27861 ata_for_each_link(link, ap, HOST_FIRST)
27862 ata_eh_link_report(link);
27863 }
27864@@ -3594,7 +3596,7 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
27865 */
27866 void ata_std_error_handler(struct ata_port *ap)
27867 {
27868- struct ata_port_operations *ops = ap->ops;
27869+ const struct ata_port_operations *ops = ap->ops;
27870 ata_reset_fn_t hardreset = ops->hardreset;
27871
27872 /* ignore built-in hardreset if SCR access is not available */
27873diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
27874index 51f0ffb..19ce3e3 100644
27875--- a/drivers/ata/libata-pmp.c
27876+++ b/drivers/ata/libata-pmp.c
27877@@ -841,7 +841,7 @@ static int sata_pmp_handle_link_fail(struct ata_link *link, int *link_tries)
27878 */
27879 static int sata_pmp_eh_recover(struct ata_port *ap)
27880 {
27881- struct ata_port_operations *ops = ap->ops;
27882+ const struct ata_port_operations *ops = ap->ops;
27883 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
27884 struct ata_link *pmp_link = &ap->link;
27885 struct ata_device *pmp_dev = pmp_link->device;
27886diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
27887index d8f35fe..288180a 100644
27888--- a/drivers/ata/pata_acpi.c
27889+++ b/drivers/ata/pata_acpi.c
27890@@ -215,7 +215,7 @@ static struct scsi_host_template pacpi_sht = {
27891 ATA_BMDMA_SHT(DRV_NAME),
27892 };
27893
27894-static struct ata_port_operations pacpi_ops = {
27895+static const struct ata_port_operations pacpi_ops = {
27896 .inherits = &ata_bmdma_port_ops,
27897 .qc_issue = pacpi_qc_issue,
27898 .cable_detect = pacpi_cable_detect,
27899diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
27900index 9434114..1f2f364 100644
27901--- a/drivers/ata/pata_ali.c
27902+++ b/drivers/ata/pata_ali.c
27903@@ -365,7 +365,7 @@ static struct scsi_host_template ali_sht = {
27904 * Port operations for PIO only ALi
27905 */
27906
27907-static struct ata_port_operations ali_early_port_ops = {
27908+static const struct ata_port_operations ali_early_port_ops = {
27909 .inherits = &ata_sff_port_ops,
27910 .cable_detect = ata_cable_40wire,
27911 .set_piomode = ali_set_piomode,
27912@@ -382,7 +382,7 @@ static const struct ata_port_operations ali_dma_base_ops = {
27913 * Port operations for DMA capable ALi without cable
27914 * detect
27915 */
27916-static struct ata_port_operations ali_20_port_ops = {
27917+static const struct ata_port_operations ali_20_port_ops = {
27918 .inherits = &ali_dma_base_ops,
27919 .cable_detect = ata_cable_40wire,
27920 .mode_filter = ali_20_filter,
27921@@ -393,7 +393,7 @@ static struct ata_port_operations ali_20_port_ops = {
27922 /*
27923 * Port operations for DMA capable ALi with cable detect
27924 */
27925-static struct ata_port_operations ali_c2_port_ops = {
27926+static const struct ata_port_operations ali_c2_port_ops = {
27927 .inherits = &ali_dma_base_ops,
27928 .check_atapi_dma = ali_check_atapi_dma,
27929 .cable_detect = ali_c2_cable_detect,
27930@@ -404,7 +404,7 @@ static struct ata_port_operations ali_c2_port_ops = {
27931 /*
27932 * Port operations for DMA capable ALi with cable detect
27933 */
27934-static struct ata_port_operations ali_c4_port_ops = {
27935+static const struct ata_port_operations ali_c4_port_ops = {
27936 .inherits = &ali_dma_base_ops,
27937 .check_atapi_dma = ali_check_atapi_dma,
27938 .cable_detect = ali_c2_cable_detect,
27939@@ -414,7 +414,7 @@ static struct ata_port_operations ali_c4_port_ops = {
27940 /*
27941 * Port operations for DMA capable ALi with cable detect and LBA48
27942 */
27943-static struct ata_port_operations ali_c5_port_ops = {
27944+static const struct ata_port_operations ali_c5_port_ops = {
27945 .inherits = &ali_dma_base_ops,
27946 .check_atapi_dma = ali_check_atapi_dma,
27947 .dev_config = ali_warn_atapi_dma,
27948diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
27949index 567f3f7..c8ee0da 100644
27950--- a/drivers/ata/pata_amd.c
27951+++ b/drivers/ata/pata_amd.c
27952@@ -397,28 +397,28 @@ static const struct ata_port_operations amd_base_port_ops = {
27953 .prereset = amd_pre_reset,
27954 };
27955
27956-static struct ata_port_operations amd33_port_ops = {
27957+static const struct ata_port_operations amd33_port_ops = {
27958 .inherits = &amd_base_port_ops,
27959 .cable_detect = ata_cable_40wire,
27960 .set_piomode = amd33_set_piomode,
27961 .set_dmamode = amd33_set_dmamode,
27962 };
27963
27964-static struct ata_port_operations amd66_port_ops = {
27965+static const struct ata_port_operations amd66_port_ops = {
27966 .inherits = &amd_base_port_ops,
27967 .cable_detect = ata_cable_unknown,
27968 .set_piomode = amd66_set_piomode,
27969 .set_dmamode = amd66_set_dmamode,
27970 };
27971
27972-static struct ata_port_operations amd100_port_ops = {
27973+static const struct ata_port_operations amd100_port_ops = {
27974 .inherits = &amd_base_port_ops,
27975 .cable_detect = ata_cable_unknown,
27976 .set_piomode = amd100_set_piomode,
27977 .set_dmamode = amd100_set_dmamode,
27978 };
27979
27980-static struct ata_port_operations amd133_port_ops = {
27981+static const struct ata_port_operations amd133_port_ops = {
27982 .inherits = &amd_base_port_ops,
27983 .cable_detect = amd_cable_detect,
27984 .set_piomode = amd133_set_piomode,
27985@@ -433,13 +433,13 @@ static const struct ata_port_operations nv_base_port_ops = {
27986 .host_stop = nv_host_stop,
27987 };
27988
27989-static struct ata_port_operations nv100_port_ops = {
27990+static const struct ata_port_operations nv100_port_ops = {
27991 .inherits = &nv_base_port_ops,
27992 .set_piomode = nv100_set_piomode,
27993 .set_dmamode = nv100_set_dmamode,
27994 };
27995
27996-static struct ata_port_operations nv133_port_ops = {
27997+static const struct ata_port_operations nv133_port_ops = {
27998 .inherits = &nv_base_port_ops,
27999 .set_piomode = nv133_set_piomode,
28000 .set_dmamode = nv133_set_dmamode,
28001diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
28002index d332cfd..4b7eaae 100644
28003--- a/drivers/ata/pata_artop.c
28004+++ b/drivers/ata/pata_artop.c
28005@@ -311,7 +311,7 @@ static struct scsi_host_template artop_sht = {
28006 ATA_BMDMA_SHT(DRV_NAME),
28007 };
28008
28009-static struct ata_port_operations artop6210_ops = {
28010+static const struct ata_port_operations artop6210_ops = {
28011 .inherits = &ata_bmdma_port_ops,
28012 .cable_detect = ata_cable_40wire,
28013 .set_piomode = artop6210_set_piomode,
28014@@ -320,7 +320,7 @@ static struct ata_port_operations artop6210_ops = {
28015 .qc_defer = artop6210_qc_defer,
28016 };
28017
28018-static struct ata_port_operations artop6260_ops = {
28019+static const struct ata_port_operations artop6260_ops = {
28020 .inherits = &ata_bmdma_port_ops,
28021 .cable_detect = artop6260_cable_detect,
28022 .set_piomode = artop6260_set_piomode,
28023diff --git a/drivers/ata/pata_at32.c b/drivers/ata/pata_at32.c
28024index 5c129f9..7bb7ccb 100644
28025--- a/drivers/ata/pata_at32.c
28026+++ b/drivers/ata/pata_at32.c
28027@@ -172,7 +172,7 @@ static struct scsi_host_template at32_sht = {
28028 ATA_PIO_SHT(DRV_NAME),
28029 };
28030
28031-static struct ata_port_operations at32_port_ops = {
28032+static const struct ata_port_operations at32_port_ops = {
28033 .inherits = &ata_sff_port_ops,
28034 .cable_detect = ata_cable_40wire,
28035 .set_piomode = pata_at32_set_piomode,
28036diff --git a/drivers/ata/pata_at91.c b/drivers/ata/pata_at91.c
28037index 41c94b1..829006d 100644
28038--- a/drivers/ata/pata_at91.c
28039+++ b/drivers/ata/pata_at91.c
28040@@ -195,7 +195,7 @@ static struct scsi_host_template pata_at91_sht = {
28041 ATA_PIO_SHT(DRV_NAME),
28042 };
28043
28044-static struct ata_port_operations pata_at91_port_ops = {
28045+static const struct ata_port_operations pata_at91_port_ops = {
28046 .inherits = &ata_sff_port_ops,
28047
28048 .sff_data_xfer = pata_at91_data_xfer_noirq,
28049diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
28050index ae4454d..d391eb4 100644
28051--- a/drivers/ata/pata_atiixp.c
28052+++ b/drivers/ata/pata_atiixp.c
28053@@ -205,7 +205,7 @@ static struct scsi_host_template atiixp_sht = {
28054 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28055 };
28056
28057-static struct ata_port_operations atiixp_port_ops = {
28058+static const struct ata_port_operations atiixp_port_ops = {
28059 .inherits = &ata_bmdma_port_ops,
28060
28061 .qc_prep = ata_sff_dumb_qc_prep,
28062diff --git a/drivers/ata/pata_atp867x.c b/drivers/ata/pata_atp867x.c
28063index 6fe7ded..2a425dc 100644
28064--- a/drivers/ata/pata_atp867x.c
28065+++ b/drivers/ata/pata_atp867x.c
28066@@ -274,7 +274,7 @@ static struct scsi_host_template atp867x_sht = {
28067 ATA_BMDMA_SHT(DRV_NAME),
28068 };
28069
28070-static struct ata_port_operations atp867x_ops = {
28071+static const struct ata_port_operations atp867x_ops = {
28072 .inherits = &ata_bmdma_port_ops,
28073 .cable_detect = atp867x_cable_detect,
28074 .set_piomode = atp867x_set_piomode,
28075diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
28076index c4b47a3..b27a367 100644
28077--- a/drivers/ata/pata_bf54x.c
28078+++ b/drivers/ata/pata_bf54x.c
28079@@ -1464,7 +1464,7 @@ static struct scsi_host_template bfin_sht = {
28080 .dma_boundary = ATA_DMA_BOUNDARY,
28081 };
28082
28083-static struct ata_port_operations bfin_pata_ops = {
28084+static const struct ata_port_operations bfin_pata_ops = {
28085 .inherits = &ata_sff_port_ops,
28086
28087 .set_piomode = bfin_set_piomode,
28088diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c
28089index 5acf9fa..84248be 100644
28090--- a/drivers/ata/pata_cmd640.c
28091+++ b/drivers/ata/pata_cmd640.c
28092@@ -168,7 +168,7 @@ static struct scsi_host_template cmd640_sht = {
28093 ATA_BMDMA_SHT(DRV_NAME),
28094 };
28095
28096-static struct ata_port_operations cmd640_port_ops = {
28097+static const struct ata_port_operations cmd640_port_ops = {
28098 .inherits = &ata_bmdma_port_ops,
28099 /* In theory xfer_noirq is not needed once we kill the prefetcher */
28100 .sff_data_xfer = ata_sff_data_xfer_noirq,
28101diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
28102index ccd2694..c869c3d 100644
28103--- a/drivers/ata/pata_cmd64x.c
28104+++ b/drivers/ata/pata_cmd64x.c
28105@@ -271,18 +271,18 @@ static const struct ata_port_operations cmd64x_base_ops = {
28106 .set_dmamode = cmd64x_set_dmamode,
28107 };
28108
28109-static struct ata_port_operations cmd64x_port_ops = {
28110+static const struct ata_port_operations cmd64x_port_ops = {
28111 .inherits = &cmd64x_base_ops,
28112 .cable_detect = ata_cable_40wire,
28113 };
28114
28115-static struct ata_port_operations cmd646r1_port_ops = {
28116+static const struct ata_port_operations cmd646r1_port_ops = {
28117 .inherits = &cmd64x_base_ops,
28118 .bmdma_stop = cmd646r1_bmdma_stop,
28119 .cable_detect = ata_cable_40wire,
28120 };
28121
28122-static struct ata_port_operations cmd648_port_ops = {
28123+static const struct ata_port_operations cmd648_port_ops = {
28124 .inherits = &cmd64x_base_ops,
28125 .bmdma_stop = cmd648_bmdma_stop,
28126 .cable_detect = cmd648_cable_detect,
28127diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
28128index 0df83cf..d7595b0 100644
28129--- a/drivers/ata/pata_cs5520.c
28130+++ b/drivers/ata/pata_cs5520.c
28131@@ -144,7 +144,7 @@ static struct scsi_host_template cs5520_sht = {
28132 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28133 };
28134
28135-static struct ata_port_operations cs5520_port_ops = {
28136+static const struct ata_port_operations cs5520_port_ops = {
28137 .inherits = &ata_bmdma_port_ops,
28138 .qc_prep = ata_sff_dumb_qc_prep,
28139 .cable_detect = ata_cable_40wire,
28140diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
28141index c974b05..6d26b11 100644
28142--- a/drivers/ata/pata_cs5530.c
28143+++ b/drivers/ata/pata_cs5530.c
28144@@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_sht = {
28145 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28146 };
28147
28148-static struct ata_port_operations cs5530_port_ops = {
28149+static const struct ata_port_operations cs5530_port_ops = {
28150 .inherits = &ata_bmdma_port_ops,
28151
28152 .qc_prep = ata_sff_dumb_qc_prep,
28153diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
28154index 403f561..aacd26b 100644
28155--- a/drivers/ata/pata_cs5535.c
28156+++ b/drivers/ata/pata_cs5535.c
28157@@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_sht = {
28158 ATA_BMDMA_SHT(DRV_NAME),
28159 };
28160
28161-static struct ata_port_operations cs5535_port_ops = {
28162+static const struct ata_port_operations cs5535_port_ops = {
28163 .inherits = &ata_bmdma_port_ops,
28164 .cable_detect = cs5535_cable_detect,
28165 .set_piomode = cs5535_set_piomode,
28166diff --git a/drivers/ata/pata_cs5536.c b/drivers/ata/pata_cs5536.c
28167index 6da4cb4..de24a25 100644
28168--- a/drivers/ata/pata_cs5536.c
28169+++ b/drivers/ata/pata_cs5536.c
28170@@ -223,7 +223,7 @@ static struct scsi_host_template cs5536_sht = {
28171 ATA_BMDMA_SHT(DRV_NAME),
28172 };
28173
28174-static struct ata_port_operations cs5536_port_ops = {
28175+static const struct ata_port_operations cs5536_port_ops = {
28176 .inherits = &ata_bmdma_port_ops,
28177 .cable_detect = cs5536_cable_detect,
28178 .set_piomode = cs5536_set_piomode,
28179diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
28180index 8fb040b..b16a9c9 100644
28181--- a/drivers/ata/pata_cypress.c
28182+++ b/drivers/ata/pata_cypress.c
28183@@ -113,7 +113,7 @@ static struct scsi_host_template cy82c693_sht = {
28184 ATA_BMDMA_SHT(DRV_NAME),
28185 };
28186
28187-static struct ata_port_operations cy82c693_port_ops = {
28188+static const struct ata_port_operations cy82c693_port_ops = {
28189 .inherits = &ata_bmdma_port_ops,
28190 .cable_detect = ata_cable_40wire,
28191 .set_piomode = cy82c693_set_piomode,
28192diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
28193index 2a6412f..555ee11 100644
28194--- a/drivers/ata/pata_efar.c
28195+++ b/drivers/ata/pata_efar.c
28196@@ -222,7 +222,7 @@ static struct scsi_host_template efar_sht = {
28197 ATA_BMDMA_SHT(DRV_NAME),
28198 };
28199
28200-static struct ata_port_operations efar_ops = {
28201+static const struct ata_port_operations efar_ops = {
28202 .inherits = &ata_bmdma_port_ops,
28203 .cable_detect = efar_cable_detect,
28204 .set_piomode = efar_set_piomode,
28205diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
28206index b9d8836..0b92030 100644
28207--- a/drivers/ata/pata_hpt366.c
28208+++ b/drivers/ata/pata_hpt366.c
28209@@ -282,7 +282,7 @@ static struct scsi_host_template hpt36x_sht = {
28210 * Configuration for HPT366/68
28211 */
28212
28213-static struct ata_port_operations hpt366_port_ops = {
28214+static const struct ata_port_operations hpt366_port_ops = {
28215 .inherits = &ata_bmdma_port_ops,
28216 .cable_detect = hpt36x_cable_detect,
28217 .mode_filter = hpt366_filter,
28218diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
28219index 5af7f19..00c4980 100644
28220--- a/drivers/ata/pata_hpt37x.c
28221+++ b/drivers/ata/pata_hpt37x.c
28222@@ -576,7 +576,7 @@ static struct scsi_host_template hpt37x_sht = {
28223 * Configuration for HPT370
28224 */
28225
28226-static struct ata_port_operations hpt370_port_ops = {
28227+static const struct ata_port_operations hpt370_port_ops = {
28228 .inherits = &ata_bmdma_port_ops,
28229
28230 .bmdma_stop = hpt370_bmdma_stop,
28231@@ -591,7 +591,7 @@ static struct ata_port_operations hpt370_port_ops = {
28232 * Configuration for HPT370A. Close to 370 but less filters
28233 */
28234
28235-static struct ata_port_operations hpt370a_port_ops = {
28236+static const struct ata_port_operations hpt370a_port_ops = {
28237 .inherits = &hpt370_port_ops,
28238 .mode_filter = hpt370a_filter,
28239 };
28240@@ -601,7 +601,7 @@ static struct ata_port_operations hpt370a_port_ops = {
28241 * and DMA mode setting functionality.
28242 */
28243
28244-static struct ata_port_operations hpt372_port_ops = {
28245+static const struct ata_port_operations hpt372_port_ops = {
28246 .inherits = &ata_bmdma_port_ops,
28247
28248 .bmdma_stop = hpt37x_bmdma_stop,
28249@@ -616,7 +616,7 @@ static struct ata_port_operations hpt372_port_ops = {
28250 * but we have a different cable detection procedure for function 1.
28251 */
28252
28253-static struct ata_port_operations hpt374_fn1_port_ops = {
28254+static const struct ata_port_operations hpt374_fn1_port_ops = {
28255 .inherits = &hpt372_port_ops,
28256 .prereset = hpt374_fn1_pre_reset,
28257 };
28258diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
28259index 100f227..2e39382 100644
28260--- a/drivers/ata/pata_hpt3x2n.c
28261+++ b/drivers/ata/pata_hpt3x2n.c
28262@@ -337,7 +337,7 @@ static struct scsi_host_template hpt3x2n_sht = {
28263 * Configuration for HPT3x2n.
28264 */
28265
28266-static struct ata_port_operations hpt3x2n_port_ops = {
28267+static const struct ata_port_operations hpt3x2n_port_ops = {
28268 .inherits = &ata_bmdma_port_ops,
28269
28270 .bmdma_stop = hpt3x2n_bmdma_stop,
28271diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
28272index 7e31025..6fca8f4 100644
28273--- a/drivers/ata/pata_hpt3x3.c
28274+++ b/drivers/ata/pata_hpt3x3.c
28275@@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_sht = {
28276 ATA_BMDMA_SHT(DRV_NAME),
28277 };
28278
28279-static struct ata_port_operations hpt3x3_port_ops = {
28280+static const struct ata_port_operations hpt3x3_port_ops = {
28281 .inherits = &ata_bmdma_port_ops,
28282 .cable_detect = ata_cable_40wire,
28283 .set_piomode = hpt3x3_set_piomode,
28284diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c
28285index b663b7f..9a26c2a 100644
28286--- a/drivers/ata/pata_icside.c
28287+++ b/drivers/ata/pata_icside.c
28288@@ -319,7 +319,7 @@ static void pata_icside_postreset(struct ata_link *link, unsigned int *classes)
28289 }
28290 }
28291
28292-static struct ata_port_operations pata_icside_port_ops = {
28293+static const struct ata_port_operations pata_icside_port_ops = {
28294 .inherits = &ata_sff_port_ops,
28295 /* no need to build any PRD tables for DMA */
28296 .qc_prep = ata_noop_qc_prep,
28297diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
28298index 4bceb88..457dfb6 100644
28299--- a/drivers/ata/pata_isapnp.c
28300+++ b/drivers/ata/pata_isapnp.c
28301@@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_sht = {
28302 ATA_PIO_SHT(DRV_NAME),
28303 };
28304
28305-static struct ata_port_operations isapnp_port_ops = {
28306+static const struct ata_port_operations isapnp_port_ops = {
28307 .inherits = &ata_sff_port_ops,
28308 .cable_detect = ata_cable_40wire,
28309 };
28310
28311-static struct ata_port_operations isapnp_noalt_port_ops = {
28312+static const struct ata_port_operations isapnp_noalt_port_ops = {
28313 .inherits = &ata_sff_port_ops,
28314 .cable_detect = ata_cable_40wire,
28315 /* No altstatus so we don't want to use the lost interrupt poll */
28316diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
28317index f156da8..24976e2 100644
28318--- a/drivers/ata/pata_it8213.c
28319+++ b/drivers/ata/pata_it8213.c
28320@@ -234,7 +234,7 @@ static struct scsi_host_template it8213_sht = {
28321 };
28322
28323
28324-static struct ata_port_operations it8213_ops = {
28325+static const struct ata_port_operations it8213_ops = {
28326 .inherits = &ata_bmdma_port_ops,
28327 .cable_detect = it8213_cable_detect,
28328 .set_piomode = it8213_set_piomode,
28329diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
28330index 188bc2f..ca9e785 100644
28331--- a/drivers/ata/pata_it821x.c
28332+++ b/drivers/ata/pata_it821x.c
28333@@ -800,7 +800,7 @@ static struct scsi_host_template it821x_sht = {
28334 ATA_BMDMA_SHT(DRV_NAME),
28335 };
28336
28337-static struct ata_port_operations it821x_smart_port_ops = {
28338+static const struct ata_port_operations it821x_smart_port_ops = {
28339 .inherits = &ata_bmdma_port_ops,
28340
28341 .check_atapi_dma= it821x_check_atapi_dma,
28342@@ -814,7 +814,7 @@ static struct ata_port_operations it821x_smart_port_ops = {
28343 .port_start = it821x_port_start,
28344 };
28345
28346-static struct ata_port_operations it821x_passthru_port_ops = {
28347+static const struct ata_port_operations it821x_passthru_port_ops = {
28348 .inherits = &ata_bmdma_port_ops,
28349
28350 .check_atapi_dma= it821x_check_atapi_dma,
28351@@ -830,7 +830,7 @@ static struct ata_port_operations it821x_passthru_port_ops = {
28352 .port_start = it821x_port_start,
28353 };
28354
28355-static struct ata_port_operations it821x_rdc_port_ops = {
28356+static const struct ata_port_operations it821x_rdc_port_ops = {
28357 .inherits = &ata_bmdma_port_ops,
28358
28359 .check_atapi_dma= it821x_check_atapi_dma,
28360diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
28361index ba54b08..4b952b7 100644
28362--- a/drivers/ata/pata_ixp4xx_cf.c
28363+++ b/drivers/ata/pata_ixp4xx_cf.c
28364@@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_sht = {
28365 ATA_PIO_SHT(DRV_NAME),
28366 };
28367
28368-static struct ata_port_operations ixp4xx_port_ops = {
28369+static const struct ata_port_operations ixp4xx_port_ops = {
28370 .inherits = &ata_sff_port_ops,
28371 .sff_data_xfer = ixp4xx_mmio_data_xfer,
28372 .cable_detect = ata_cable_40wire,
28373diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
28374index 3a1474a..434b0ff 100644
28375--- a/drivers/ata/pata_jmicron.c
28376+++ b/drivers/ata/pata_jmicron.c
28377@@ -111,7 +111,7 @@ static struct scsi_host_template jmicron_sht = {
28378 ATA_BMDMA_SHT(DRV_NAME),
28379 };
28380
28381-static struct ata_port_operations jmicron_ops = {
28382+static const struct ata_port_operations jmicron_ops = {
28383 .inherits = &ata_bmdma_port_ops,
28384 .prereset = jmicron_pre_reset,
28385 };
28386diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
28387index 6932e56..220e71d 100644
28388--- a/drivers/ata/pata_legacy.c
28389+++ b/drivers/ata/pata_legacy.c
28390@@ -106,7 +106,7 @@ struct legacy_probe {
28391
28392 struct legacy_controller {
28393 const char *name;
28394- struct ata_port_operations *ops;
28395+ const struct ata_port_operations *ops;
28396 unsigned int pio_mask;
28397 unsigned int flags;
28398 unsigned int pflags;
28399@@ -223,12 +223,12 @@ static const struct ata_port_operations legacy_base_port_ops = {
28400 * pio_mask as well.
28401 */
28402
28403-static struct ata_port_operations simple_port_ops = {
28404+static const struct ata_port_operations simple_port_ops = {
28405 .inherits = &legacy_base_port_ops,
28406 .sff_data_xfer = ata_sff_data_xfer_noirq,
28407 };
28408
28409-static struct ata_port_operations legacy_port_ops = {
28410+static const struct ata_port_operations legacy_port_ops = {
28411 .inherits = &legacy_base_port_ops,
28412 .sff_data_xfer = ata_sff_data_xfer_noirq,
28413 .set_mode = legacy_set_mode,
28414@@ -324,7 +324,7 @@ static unsigned int pdc_data_xfer_vlb(struct ata_device *dev,
28415 return buflen;
28416 }
28417
28418-static struct ata_port_operations pdc20230_port_ops = {
28419+static const struct ata_port_operations pdc20230_port_ops = {
28420 .inherits = &legacy_base_port_ops,
28421 .set_piomode = pdc20230_set_piomode,
28422 .sff_data_xfer = pdc_data_xfer_vlb,
28423@@ -357,7 +357,7 @@ static void ht6560a_set_piomode(struct ata_port *ap, struct ata_device *adev)
28424 ioread8(ap->ioaddr.status_addr);
28425 }
28426
28427-static struct ata_port_operations ht6560a_port_ops = {
28428+static const struct ata_port_operations ht6560a_port_ops = {
28429 .inherits = &legacy_base_port_ops,
28430 .set_piomode = ht6560a_set_piomode,
28431 };
28432@@ -400,7 +400,7 @@ static void ht6560b_set_piomode(struct ata_port *ap, struct ata_device *adev)
28433 ioread8(ap->ioaddr.status_addr);
28434 }
28435
28436-static struct ata_port_operations ht6560b_port_ops = {
28437+static const struct ata_port_operations ht6560b_port_ops = {
28438 .inherits = &legacy_base_port_ops,
28439 .set_piomode = ht6560b_set_piomode,
28440 };
28441@@ -499,7 +499,7 @@ static void opti82c611a_set_piomode(struct ata_port *ap,
28442 }
28443
28444
28445-static struct ata_port_operations opti82c611a_port_ops = {
28446+static const struct ata_port_operations opti82c611a_port_ops = {
28447 .inherits = &legacy_base_port_ops,
28448 .set_piomode = opti82c611a_set_piomode,
28449 };
28450@@ -609,7 +609,7 @@ static unsigned int opti82c46x_qc_issue(struct ata_queued_cmd *qc)
28451 return ata_sff_qc_issue(qc);
28452 }
28453
28454-static struct ata_port_operations opti82c46x_port_ops = {
28455+static const struct ata_port_operations opti82c46x_port_ops = {
28456 .inherits = &legacy_base_port_ops,
28457 .set_piomode = opti82c46x_set_piomode,
28458 .qc_issue = opti82c46x_qc_issue,
28459@@ -771,20 +771,20 @@ static int qdi_port(struct platform_device *dev,
28460 return 0;
28461 }
28462
28463-static struct ata_port_operations qdi6500_port_ops = {
28464+static const struct ata_port_operations qdi6500_port_ops = {
28465 .inherits = &legacy_base_port_ops,
28466 .set_piomode = qdi6500_set_piomode,
28467 .qc_issue = qdi_qc_issue,
28468 .sff_data_xfer = vlb32_data_xfer,
28469 };
28470
28471-static struct ata_port_operations qdi6580_port_ops = {
28472+static const struct ata_port_operations qdi6580_port_ops = {
28473 .inherits = &legacy_base_port_ops,
28474 .set_piomode = qdi6580_set_piomode,
28475 .sff_data_xfer = vlb32_data_xfer,
28476 };
28477
28478-static struct ata_port_operations qdi6580dp_port_ops = {
28479+static const struct ata_port_operations qdi6580dp_port_ops = {
28480 .inherits = &legacy_base_port_ops,
28481 .set_piomode = qdi6580dp_set_piomode,
28482 .sff_data_xfer = vlb32_data_xfer,
28483@@ -855,7 +855,7 @@ static int winbond_port(struct platform_device *dev,
28484 return 0;
28485 }
28486
28487-static struct ata_port_operations winbond_port_ops = {
28488+static const struct ata_port_operations winbond_port_ops = {
28489 .inherits = &legacy_base_port_ops,
28490 .set_piomode = winbond_set_piomode,
28491 .sff_data_xfer = vlb32_data_xfer,
28492@@ -978,7 +978,7 @@ static __init int legacy_init_one(struct legacy_probe *probe)
28493 int pio_modes = controller->pio_mask;
28494 unsigned long io = probe->port;
28495 u32 mask = (1 << probe->slot);
28496- struct ata_port_operations *ops = controller->ops;
28497+ const struct ata_port_operations *ops = controller->ops;
28498 struct legacy_data *ld = &legacy_data[probe->slot];
28499 struct ata_host *host = NULL;
28500 struct ata_port *ap;
28501diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
28502index 2096fb7..4d090fc 100644
28503--- a/drivers/ata/pata_marvell.c
28504+++ b/drivers/ata/pata_marvell.c
28505@@ -100,7 +100,7 @@ static struct scsi_host_template marvell_sht = {
28506 ATA_BMDMA_SHT(DRV_NAME),
28507 };
28508
28509-static struct ata_port_operations marvell_ops = {
28510+static const struct ata_port_operations marvell_ops = {
28511 .inherits = &ata_bmdma_port_ops,
28512 .cable_detect = marvell_cable_detect,
28513 .prereset = marvell_pre_reset,
28514diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
28515index 99d41be..7d56aa8 100644
28516--- a/drivers/ata/pata_mpc52xx.c
28517+++ b/drivers/ata/pata_mpc52xx.c
28518@@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx_ata_sht = {
28519 ATA_PIO_SHT(DRV_NAME),
28520 };
28521
28522-static struct ata_port_operations mpc52xx_ata_port_ops = {
28523+static const struct ata_port_operations mpc52xx_ata_port_ops = {
28524 .inherits = &ata_bmdma_port_ops,
28525 .sff_dev_select = mpc52xx_ata_dev_select,
28526 .set_piomode = mpc52xx_ata_set_piomode,
28527diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
28528index b21f002..0a27e7f 100644
28529--- a/drivers/ata/pata_mpiix.c
28530+++ b/drivers/ata/pata_mpiix.c
28531@@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_sht = {
28532 ATA_PIO_SHT(DRV_NAME),
28533 };
28534
28535-static struct ata_port_operations mpiix_port_ops = {
28536+static const struct ata_port_operations mpiix_port_ops = {
28537 .inherits = &ata_sff_port_ops,
28538 .qc_issue = mpiix_qc_issue,
28539 .cable_detect = ata_cable_40wire,
28540diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
28541index f0d52f7..89c3be3 100644
28542--- a/drivers/ata/pata_netcell.c
28543+++ b/drivers/ata/pata_netcell.c
28544@@ -34,7 +34,7 @@ static struct scsi_host_template netcell_sht = {
28545 ATA_BMDMA_SHT(DRV_NAME),
28546 };
28547
28548-static struct ata_port_operations netcell_ops = {
28549+static const struct ata_port_operations netcell_ops = {
28550 .inherits = &ata_bmdma_port_ops,
28551 .cable_detect = ata_cable_80wire,
28552 .read_id = netcell_read_id,
28553diff --git a/drivers/ata/pata_ninja32.c b/drivers/ata/pata_ninja32.c
28554index dd53a66..a3f4317 100644
28555--- a/drivers/ata/pata_ninja32.c
28556+++ b/drivers/ata/pata_ninja32.c
28557@@ -81,7 +81,7 @@ static struct scsi_host_template ninja32_sht = {
28558 ATA_BMDMA_SHT(DRV_NAME),
28559 };
28560
28561-static struct ata_port_operations ninja32_port_ops = {
28562+static const struct ata_port_operations ninja32_port_ops = {
28563 .inherits = &ata_bmdma_port_ops,
28564 .sff_dev_select = ninja32_dev_select,
28565 .cable_detect = ata_cable_40wire,
28566diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
28567index ca53fac..9aa93ef 100644
28568--- a/drivers/ata/pata_ns87410.c
28569+++ b/drivers/ata/pata_ns87410.c
28570@@ -132,7 +132,7 @@ static struct scsi_host_template ns87410_sht = {
28571 ATA_PIO_SHT(DRV_NAME),
28572 };
28573
28574-static struct ata_port_operations ns87410_port_ops = {
28575+static const struct ata_port_operations ns87410_port_ops = {
28576 .inherits = &ata_sff_port_ops,
28577 .qc_issue = ns87410_qc_issue,
28578 .cable_detect = ata_cable_40wire,
28579diff --git a/drivers/ata/pata_ns87415.c b/drivers/ata/pata_ns87415.c
28580index 773b159..55f454e 100644
28581--- a/drivers/ata/pata_ns87415.c
28582+++ b/drivers/ata/pata_ns87415.c
28583@@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct ata_port *ap)
28584 }
28585 #endif /* 87560 SuperIO Support */
28586
28587-static struct ata_port_operations ns87415_pata_ops = {
28588+static const struct ata_port_operations ns87415_pata_ops = {
28589 .inherits = &ata_bmdma_port_ops,
28590
28591 .check_atapi_dma = ns87415_check_atapi_dma,
28592@@ -313,7 +313,7 @@ static struct ata_port_operations ns87415_pata_ops = {
28593 };
28594
28595 #if defined(CONFIG_SUPERIO)
28596-static struct ata_port_operations ns87560_pata_ops = {
28597+static const struct ata_port_operations ns87560_pata_ops = {
28598 .inherits = &ns87415_pata_ops,
28599 .sff_tf_read = ns87560_tf_read,
28600 .sff_check_status = ns87560_check_status,
28601diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
28602index d6f6956..639295b 100644
28603--- a/drivers/ata/pata_octeon_cf.c
28604+++ b/drivers/ata/pata_octeon_cf.c
28605@@ -801,6 +801,7 @@ static unsigned int octeon_cf_qc_issue(struct ata_queued_cmd *qc)
28606 return 0;
28607 }
28608
28609+/* cannot be const */
28610 static struct ata_port_operations octeon_cf_ops = {
28611 .inherits = &ata_sff_port_ops,
28612 .check_atapi_dma = octeon_cf_check_atapi_dma,
28613diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
28614index 84ac503..adee1cd 100644
28615--- a/drivers/ata/pata_oldpiix.c
28616+++ b/drivers/ata/pata_oldpiix.c
28617@@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix_sht = {
28618 ATA_BMDMA_SHT(DRV_NAME),
28619 };
28620
28621-static struct ata_port_operations oldpiix_pata_ops = {
28622+static const struct ata_port_operations oldpiix_pata_ops = {
28623 .inherits = &ata_bmdma_port_ops,
28624 .qc_issue = oldpiix_qc_issue,
28625 .cable_detect = ata_cable_40wire,
28626diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
28627index 99eddda..3a4c0aa 100644
28628--- a/drivers/ata/pata_opti.c
28629+++ b/drivers/ata/pata_opti.c
28630@@ -152,7 +152,7 @@ static struct scsi_host_template opti_sht = {
28631 ATA_PIO_SHT(DRV_NAME),
28632 };
28633
28634-static struct ata_port_operations opti_port_ops = {
28635+static const struct ata_port_operations opti_port_ops = {
28636 .inherits = &ata_sff_port_ops,
28637 .cable_detect = ata_cable_40wire,
28638 .set_piomode = opti_set_piomode,
28639diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
28640index 86885a4..8e9968d 100644
28641--- a/drivers/ata/pata_optidma.c
28642+++ b/drivers/ata/pata_optidma.c
28643@@ -337,7 +337,7 @@ static struct scsi_host_template optidma_sht = {
28644 ATA_BMDMA_SHT(DRV_NAME),
28645 };
28646
28647-static struct ata_port_operations optidma_port_ops = {
28648+static const struct ata_port_operations optidma_port_ops = {
28649 .inherits = &ata_bmdma_port_ops,
28650 .cable_detect = ata_cable_40wire,
28651 .set_piomode = optidma_set_pio_mode,
28652@@ -346,7 +346,7 @@ static struct ata_port_operations optidma_port_ops = {
28653 .prereset = optidma_pre_reset,
28654 };
28655
28656-static struct ata_port_operations optiplus_port_ops = {
28657+static const struct ata_port_operations optiplus_port_ops = {
28658 .inherits = &optidma_port_ops,
28659 .set_piomode = optiplus_set_pio_mode,
28660 .set_dmamode = optiplus_set_dma_mode,
28661diff --git a/drivers/ata/pata_palmld.c b/drivers/ata/pata_palmld.c
28662index 11fb4cc..1a14022 100644
28663--- a/drivers/ata/pata_palmld.c
28664+++ b/drivers/ata/pata_palmld.c
28665@@ -37,7 +37,7 @@ static struct scsi_host_template palmld_sht = {
28666 ATA_PIO_SHT(DRV_NAME),
28667 };
28668
28669-static struct ata_port_operations palmld_port_ops = {
28670+static const struct ata_port_operations palmld_port_ops = {
28671 .inherits = &ata_sff_port_ops,
28672 .sff_data_xfer = ata_sff_data_xfer_noirq,
28673 .cable_detect = ata_cable_40wire,
28674diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
28675index dc99e26..7f4b1e4 100644
28676--- a/drivers/ata/pata_pcmcia.c
28677+++ b/drivers/ata/pata_pcmcia.c
28678@@ -162,14 +162,14 @@ static struct scsi_host_template pcmcia_sht = {
28679 ATA_PIO_SHT(DRV_NAME),
28680 };
28681
28682-static struct ata_port_operations pcmcia_port_ops = {
28683+static const struct ata_port_operations pcmcia_port_ops = {
28684 .inherits = &ata_sff_port_ops,
28685 .sff_data_xfer = ata_sff_data_xfer_noirq,
28686 .cable_detect = ata_cable_40wire,
28687 .set_mode = pcmcia_set_mode,
28688 };
28689
28690-static struct ata_port_operations pcmcia_8bit_port_ops = {
28691+static const struct ata_port_operations pcmcia_8bit_port_ops = {
28692 .inherits = &ata_sff_port_ops,
28693 .sff_data_xfer = ata_data_xfer_8bit,
28694 .cable_detect = ata_cable_40wire,
28695@@ -256,7 +256,7 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
28696 unsigned long io_base, ctl_base;
28697 void __iomem *io_addr, *ctl_addr;
28698 int n_ports = 1;
28699- struct ata_port_operations *ops = &pcmcia_port_ops;
28700+ const struct ata_port_operations *ops = &pcmcia_port_ops;
28701
28702 info = kzalloc(sizeof(*info), GFP_KERNEL);
28703 if (info == NULL)
28704diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
28705index ca5cad0..3a1f125 100644
28706--- a/drivers/ata/pata_pdc2027x.c
28707+++ b/drivers/ata/pata_pdc2027x.c
28708@@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027x_sht = {
28709 ATA_BMDMA_SHT(DRV_NAME),
28710 };
28711
28712-static struct ata_port_operations pdc2027x_pata100_ops = {
28713+static const struct ata_port_operations pdc2027x_pata100_ops = {
28714 .inherits = &ata_bmdma_port_ops,
28715 .check_atapi_dma = pdc2027x_check_atapi_dma,
28716 .cable_detect = pdc2027x_cable_detect,
28717 .prereset = pdc2027x_prereset,
28718 };
28719
28720-static struct ata_port_operations pdc2027x_pata133_ops = {
28721+static const struct ata_port_operations pdc2027x_pata133_ops = {
28722 .inherits = &pdc2027x_pata100_ops,
28723 .mode_filter = pdc2027x_mode_filter,
28724 .set_piomode = pdc2027x_set_piomode,
28725diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
28726index 2911120..4bf62aa 100644
28727--- a/drivers/ata/pata_pdc202xx_old.c
28728+++ b/drivers/ata/pata_pdc202xx_old.c
28729@@ -274,7 +274,7 @@ static struct scsi_host_template pdc202xx_sht = {
28730 ATA_BMDMA_SHT(DRV_NAME),
28731 };
28732
28733-static struct ata_port_operations pdc2024x_port_ops = {
28734+static const struct ata_port_operations pdc2024x_port_ops = {
28735 .inherits = &ata_bmdma_port_ops,
28736
28737 .cable_detect = ata_cable_40wire,
28738@@ -284,7 +284,7 @@ static struct ata_port_operations pdc2024x_port_ops = {
28739 .sff_exec_command = pdc202xx_exec_command,
28740 };
28741
28742-static struct ata_port_operations pdc2026x_port_ops = {
28743+static const struct ata_port_operations pdc2026x_port_ops = {
28744 .inherits = &pdc2024x_port_ops,
28745
28746 .check_atapi_dma = pdc2026x_check_atapi_dma,
28747diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
28748index 3f6ebc6..a18c358 100644
28749--- a/drivers/ata/pata_platform.c
28750+++ b/drivers/ata/pata_platform.c
28751@@ -48,7 +48,7 @@ static struct scsi_host_template pata_platform_sht = {
28752 ATA_PIO_SHT(DRV_NAME),
28753 };
28754
28755-static struct ata_port_operations pata_platform_port_ops = {
28756+static const struct ata_port_operations pata_platform_port_ops = {
28757 .inherits = &ata_sff_port_ops,
28758 .sff_data_xfer = ata_sff_data_xfer_noirq,
28759 .cable_detect = ata_cable_unknown,
28760diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
28761index 45879dc..165a9f9 100644
28762--- a/drivers/ata/pata_qdi.c
28763+++ b/drivers/ata/pata_qdi.c
28764@@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht = {
28765 ATA_PIO_SHT(DRV_NAME),
28766 };
28767
28768-static struct ata_port_operations qdi6500_port_ops = {
28769+static const struct ata_port_operations qdi6500_port_ops = {
28770 .inherits = &ata_sff_port_ops,
28771 .qc_issue = qdi_qc_issue,
28772 .sff_data_xfer = qdi_data_xfer,
28773@@ -165,7 +165,7 @@ static struct ata_port_operations qdi6500_port_ops = {
28774 .set_piomode = qdi6500_set_piomode,
28775 };
28776
28777-static struct ata_port_operations qdi6580_port_ops = {
28778+static const struct ata_port_operations qdi6580_port_ops = {
28779 .inherits = &qdi6500_port_ops,
28780 .set_piomode = qdi6580_set_piomode,
28781 };
28782diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
28783index 4401b33..716c5cc 100644
28784--- a/drivers/ata/pata_radisys.c
28785+++ b/drivers/ata/pata_radisys.c
28786@@ -187,7 +187,7 @@ static struct scsi_host_template radisys_sht = {
28787 ATA_BMDMA_SHT(DRV_NAME),
28788 };
28789
28790-static struct ata_port_operations radisys_pata_ops = {
28791+static const struct ata_port_operations radisys_pata_ops = {
28792 .inherits = &ata_bmdma_port_ops,
28793 .qc_issue = radisys_qc_issue,
28794 .cable_detect = ata_cable_unknown,
28795diff --git a/drivers/ata/pata_rb532_cf.c b/drivers/ata/pata_rb532_cf.c
28796index 45f1e10..fab6bca 100644
28797--- a/drivers/ata/pata_rb532_cf.c
28798+++ b/drivers/ata/pata_rb532_cf.c
28799@@ -68,7 +68,7 @@ static irqreturn_t rb532_pata_irq_handler(int irq, void *dev_instance)
28800 return IRQ_HANDLED;
28801 }
28802
28803-static struct ata_port_operations rb532_pata_port_ops = {
28804+static const struct ata_port_operations rb532_pata_port_ops = {
28805 .inherits = &ata_sff_port_ops,
28806 .sff_data_xfer = ata_sff_data_xfer32,
28807 };
28808diff --git a/drivers/ata/pata_rdc.c b/drivers/ata/pata_rdc.c
28809index c843a1e..b5853c3 100644
28810--- a/drivers/ata/pata_rdc.c
28811+++ b/drivers/ata/pata_rdc.c
28812@@ -272,7 +272,7 @@ static void rdc_set_dmamode(struct ata_port *ap, struct ata_device *adev)
28813 pci_write_config_byte(dev, 0x48, udma_enable);
28814 }
28815
28816-static struct ata_port_operations rdc_pata_ops = {
28817+static const struct ata_port_operations rdc_pata_ops = {
28818 .inherits = &ata_bmdma32_port_ops,
28819 .cable_detect = rdc_pata_cable_detect,
28820 .set_piomode = rdc_set_piomode,
28821diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
28822index a5e4dfe..080c8c9 100644
28823--- a/drivers/ata/pata_rz1000.c
28824+++ b/drivers/ata/pata_rz1000.c
28825@@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_sht = {
28826 ATA_PIO_SHT(DRV_NAME),
28827 };
28828
28829-static struct ata_port_operations rz1000_port_ops = {
28830+static const struct ata_port_operations rz1000_port_ops = {
28831 .inherits = &ata_sff_port_ops,
28832 .cable_detect = ata_cable_40wire,
28833 .set_mode = rz1000_set_mode,
28834diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
28835index 3bbed83..e309daf 100644
28836--- a/drivers/ata/pata_sc1200.c
28837+++ b/drivers/ata/pata_sc1200.c
28838@@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_sht = {
28839 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28840 };
28841
28842-static struct ata_port_operations sc1200_port_ops = {
28843+static const struct ata_port_operations sc1200_port_ops = {
28844 .inherits = &ata_bmdma_port_ops,
28845 .qc_prep = ata_sff_dumb_qc_prep,
28846 .qc_issue = sc1200_qc_issue,
28847diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
28848index 4257d6b..4c1d9d5 100644
28849--- a/drivers/ata/pata_scc.c
28850+++ b/drivers/ata/pata_scc.c
28851@@ -965,7 +965,7 @@ static struct scsi_host_template scc_sht = {
28852 ATA_BMDMA_SHT(DRV_NAME),
28853 };
28854
28855-static struct ata_port_operations scc_pata_ops = {
28856+static const struct ata_port_operations scc_pata_ops = {
28857 .inherits = &ata_bmdma_port_ops,
28858
28859 .set_piomode = scc_set_piomode,
28860diff --git a/drivers/ata/pata_sch.c b/drivers/ata/pata_sch.c
28861index 99cceb4..e2e0a87 100644
28862--- a/drivers/ata/pata_sch.c
28863+++ b/drivers/ata/pata_sch.c
28864@@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht = {
28865 ATA_BMDMA_SHT(DRV_NAME),
28866 };
28867
28868-static struct ata_port_operations sch_pata_ops = {
28869+static const struct ata_port_operations sch_pata_ops = {
28870 .inherits = &ata_bmdma_port_ops,
28871 .cable_detect = ata_cable_unknown,
28872 .set_piomode = sch_set_piomode,
28873diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
28874index beaed12..39969f1 100644
28875--- a/drivers/ata/pata_serverworks.c
28876+++ b/drivers/ata/pata_serverworks.c
28877@@ -299,7 +299,7 @@ static struct scsi_host_template serverworks_sht = {
28878 ATA_BMDMA_SHT(DRV_NAME),
28879 };
28880
28881-static struct ata_port_operations serverworks_osb4_port_ops = {
28882+static const struct ata_port_operations serverworks_osb4_port_ops = {
28883 .inherits = &ata_bmdma_port_ops,
28884 .cable_detect = serverworks_cable_detect,
28885 .mode_filter = serverworks_osb4_filter,
28886@@ -307,7 +307,7 @@ static struct ata_port_operations serverworks_osb4_port_ops = {
28887 .set_dmamode = serverworks_set_dmamode,
28888 };
28889
28890-static struct ata_port_operations serverworks_csb_port_ops = {
28891+static const struct ata_port_operations serverworks_csb_port_ops = {
28892 .inherits = &serverworks_osb4_port_ops,
28893 .mode_filter = serverworks_csb_filter,
28894 };
28895diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
28896index a2ace48..0463b44 100644
28897--- a/drivers/ata/pata_sil680.c
28898+++ b/drivers/ata/pata_sil680.c
28899@@ -194,7 +194,7 @@ static struct scsi_host_template sil680_sht = {
28900 ATA_BMDMA_SHT(DRV_NAME),
28901 };
28902
28903-static struct ata_port_operations sil680_port_ops = {
28904+static const struct ata_port_operations sil680_port_ops = {
28905 .inherits = &ata_bmdma32_port_ops,
28906 .cable_detect = sil680_cable_detect,
28907 .set_piomode = sil680_set_piomode,
28908diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
28909index 488e77b..b3724d5 100644
28910--- a/drivers/ata/pata_sis.c
28911+++ b/drivers/ata/pata_sis.c
28912@@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht = {
28913 ATA_BMDMA_SHT(DRV_NAME),
28914 };
28915
28916-static struct ata_port_operations sis_133_for_sata_ops = {
28917+static const struct ata_port_operations sis_133_for_sata_ops = {
28918 .inherits = &ata_bmdma_port_ops,
28919 .set_piomode = sis_133_set_piomode,
28920 .set_dmamode = sis_133_set_dmamode,
28921 .cable_detect = sis_133_cable_detect,
28922 };
28923
28924-static struct ata_port_operations sis_base_ops = {
28925+static const struct ata_port_operations sis_base_ops = {
28926 .inherits = &ata_bmdma_port_ops,
28927 .prereset = sis_pre_reset,
28928 };
28929
28930-static struct ata_port_operations sis_133_ops = {
28931+static const struct ata_port_operations sis_133_ops = {
28932 .inherits = &sis_base_ops,
28933 .set_piomode = sis_133_set_piomode,
28934 .set_dmamode = sis_133_set_dmamode,
28935 .cable_detect = sis_133_cable_detect,
28936 };
28937
28938-static struct ata_port_operations sis_133_early_ops = {
28939+static const struct ata_port_operations sis_133_early_ops = {
28940 .inherits = &sis_base_ops,
28941 .set_piomode = sis_100_set_piomode,
28942 .set_dmamode = sis_133_early_set_dmamode,
28943 .cable_detect = sis_66_cable_detect,
28944 };
28945
28946-static struct ata_port_operations sis_100_ops = {
28947+static const struct ata_port_operations sis_100_ops = {
28948 .inherits = &sis_base_ops,
28949 .set_piomode = sis_100_set_piomode,
28950 .set_dmamode = sis_100_set_dmamode,
28951 .cable_detect = sis_66_cable_detect,
28952 };
28953
28954-static struct ata_port_operations sis_66_ops = {
28955+static const struct ata_port_operations sis_66_ops = {
28956 .inherits = &sis_base_ops,
28957 .set_piomode = sis_old_set_piomode,
28958 .set_dmamode = sis_66_set_dmamode,
28959 .cable_detect = sis_66_cable_detect,
28960 };
28961
28962-static struct ata_port_operations sis_old_ops = {
28963+static const struct ata_port_operations sis_old_ops = {
28964 .inherits = &sis_base_ops,
28965 .set_piomode = sis_old_set_piomode,
28966 .set_dmamode = sis_old_set_dmamode,
28967diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
28968index 29f733c..43e9ca0 100644
28969--- a/drivers/ata/pata_sl82c105.c
28970+++ b/drivers/ata/pata_sl82c105.c
28971@@ -231,7 +231,7 @@ static struct scsi_host_template sl82c105_sht = {
28972 ATA_BMDMA_SHT(DRV_NAME),
28973 };
28974
28975-static struct ata_port_operations sl82c105_port_ops = {
28976+static const struct ata_port_operations sl82c105_port_ops = {
28977 .inherits = &ata_bmdma_port_ops,
28978 .qc_defer = sl82c105_qc_defer,
28979 .bmdma_start = sl82c105_bmdma_start,
28980diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
28981index f1f13ff..df39e99 100644
28982--- a/drivers/ata/pata_triflex.c
28983+++ b/drivers/ata/pata_triflex.c
28984@@ -178,7 +178,7 @@ static struct scsi_host_template triflex_sht = {
28985 ATA_BMDMA_SHT(DRV_NAME),
28986 };
28987
28988-static struct ata_port_operations triflex_port_ops = {
28989+static const struct ata_port_operations triflex_port_ops = {
28990 .inherits = &ata_bmdma_port_ops,
28991 .bmdma_start = triflex_bmdma_start,
28992 .bmdma_stop = triflex_bmdma_stop,
28993diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
28994index 1d73b8d..98a4b29 100644
28995--- a/drivers/ata/pata_via.c
28996+++ b/drivers/ata/pata_via.c
28997@@ -419,7 +419,7 @@ static struct scsi_host_template via_sht = {
28998 ATA_BMDMA_SHT(DRV_NAME),
28999 };
29000
29001-static struct ata_port_operations via_port_ops = {
29002+static const struct ata_port_operations via_port_ops = {
29003 .inherits = &ata_bmdma_port_ops,
29004 .cable_detect = via_cable_detect,
29005 .set_piomode = via_set_piomode,
29006@@ -429,7 +429,7 @@ static struct ata_port_operations via_port_ops = {
29007 .port_start = via_port_start,
29008 };
29009
29010-static struct ata_port_operations via_port_ops_noirq = {
29011+static const struct ata_port_operations via_port_ops_noirq = {
29012 .inherits = &via_port_ops,
29013 .sff_data_xfer = ata_sff_data_xfer_noirq,
29014 };
29015diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
29016index 6d8619b..ad511c4 100644
29017--- a/drivers/ata/pata_winbond.c
29018+++ b/drivers/ata/pata_winbond.c
29019@@ -125,7 +125,7 @@ static struct scsi_host_template winbond_sht = {
29020 ATA_PIO_SHT(DRV_NAME),
29021 };
29022
29023-static struct ata_port_operations winbond_port_ops = {
29024+static const struct ata_port_operations winbond_port_ops = {
29025 .inherits = &ata_sff_port_ops,
29026 .sff_data_xfer = winbond_data_xfer,
29027 .cable_detect = ata_cable_40wire,
29028diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
29029index 6c65b07..f996ec7 100644
29030--- a/drivers/ata/pdc_adma.c
29031+++ b/drivers/ata/pdc_adma.c
29032@@ -145,7 +145,7 @@ static struct scsi_host_template adma_ata_sht = {
29033 .dma_boundary = ADMA_DMA_BOUNDARY,
29034 };
29035
29036-static struct ata_port_operations adma_ata_ops = {
29037+static const struct ata_port_operations adma_ata_ops = {
29038 .inherits = &ata_sff_port_ops,
29039
29040 .lost_interrupt = ATA_OP_NULL,
29041diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
29042index 172b57e..c49bc1e 100644
29043--- a/drivers/ata/sata_fsl.c
29044+++ b/drivers/ata/sata_fsl.c
29045@@ -1258,7 +1258,7 @@ static struct scsi_host_template sata_fsl_sht = {
29046 .dma_boundary = ATA_DMA_BOUNDARY,
29047 };
29048
29049-static struct ata_port_operations sata_fsl_ops = {
29050+static const struct ata_port_operations sata_fsl_ops = {
29051 .inherits = &sata_pmp_port_ops,
29052
29053 .qc_defer = ata_std_qc_defer,
29054diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
29055index 4406902..60603ef 100644
29056--- a/drivers/ata/sata_inic162x.c
29057+++ b/drivers/ata/sata_inic162x.c
29058@@ -721,7 +721,7 @@ static int inic_port_start(struct ata_port *ap)
29059 return 0;
29060 }
29061
29062-static struct ata_port_operations inic_port_ops = {
29063+static const struct ata_port_operations inic_port_ops = {
29064 .inherits = &sata_port_ops,
29065
29066 .check_atapi_dma = inic_check_atapi_dma,
29067diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
29068index cf41126..8107be6 100644
29069--- a/drivers/ata/sata_mv.c
29070+++ b/drivers/ata/sata_mv.c
29071@@ -656,7 +656,7 @@ static struct scsi_host_template mv6_sht = {
29072 .dma_boundary = MV_DMA_BOUNDARY,
29073 };
29074
29075-static struct ata_port_operations mv5_ops = {
29076+static const struct ata_port_operations mv5_ops = {
29077 .inherits = &ata_sff_port_ops,
29078
29079 .lost_interrupt = ATA_OP_NULL,
29080@@ -678,7 +678,7 @@ static struct ata_port_operations mv5_ops = {
29081 .port_stop = mv_port_stop,
29082 };
29083
29084-static struct ata_port_operations mv6_ops = {
29085+static const struct ata_port_operations mv6_ops = {
29086 .inherits = &mv5_ops,
29087 .dev_config = mv6_dev_config,
29088 .scr_read = mv_scr_read,
29089@@ -698,7 +698,7 @@ static struct ata_port_operations mv6_ops = {
29090 .bmdma_status = mv_bmdma_status,
29091 };
29092
29093-static struct ata_port_operations mv_iie_ops = {
29094+static const struct ata_port_operations mv_iie_ops = {
29095 .inherits = &mv6_ops,
29096 .dev_config = ATA_OP_NULL,
29097 .qc_prep = mv_qc_prep_iie,
29098diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
29099index ae2297c..d5c9c33 100644
29100--- a/drivers/ata/sata_nv.c
29101+++ b/drivers/ata/sata_nv.c
29102@@ -464,7 +464,7 @@ static struct scsi_host_template nv_swncq_sht = {
29103 * cases. Define nv_hardreset() which only kicks in for post-boot
29104 * probing and use it for all variants.
29105 */
29106-static struct ata_port_operations nv_generic_ops = {
29107+static const struct ata_port_operations nv_generic_ops = {
29108 .inherits = &ata_bmdma_port_ops,
29109 .lost_interrupt = ATA_OP_NULL,
29110 .scr_read = nv_scr_read,
29111@@ -472,20 +472,20 @@ static struct ata_port_operations nv_generic_ops = {
29112 .hardreset = nv_hardreset,
29113 };
29114
29115-static struct ata_port_operations nv_nf2_ops = {
29116+static const struct ata_port_operations nv_nf2_ops = {
29117 .inherits = &nv_generic_ops,
29118 .freeze = nv_nf2_freeze,
29119 .thaw = nv_nf2_thaw,
29120 };
29121
29122-static struct ata_port_operations nv_ck804_ops = {
29123+static const struct ata_port_operations nv_ck804_ops = {
29124 .inherits = &nv_generic_ops,
29125 .freeze = nv_ck804_freeze,
29126 .thaw = nv_ck804_thaw,
29127 .host_stop = nv_ck804_host_stop,
29128 };
29129
29130-static struct ata_port_operations nv_adma_ops = {
29131+static const struct ata_port_operations nv_adma_ops = {
29132 .inherits = &nv_ck804_ops,
29133
29134 .check_atapi_dma = nv_adma_check_atapi_dma,
29135@@ -509,7 +509,7 @@ static struct ata_port_operations nv_adma_ops = {
29136 .host_stop = nv_adma_host_stop,
29137 };
29138
29139-static struct ata_port_operations nv_swncq_ops = {
29140+static const struct ata_port_operations nv_swncq_ops = {
29141 .inherits = &nv_generic_ops,
29142
29143 .qc_defer = ata_std_qc_defer,
29144diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
29145index 07d8d00..6cc70bb 100644
29146--- a/drivers/ata/sata_promise.c
29147+++ b/drivers/ata/sata_promise.c
29148@@ -195,7 +195,7 @@ static const struct ata_port_operations pdc_common_ops = {
29149 .error_handler = pdc_error_handler,
29150 };
29151
29152-static struct ata_port_operations pdc_sata_ops = {
29153+static const struct ata_port_operations pdc_sata_ops = {
29154 .inherits = &pdc_common_ops,
29155 .cable_detect = pdc_sata_cable_detect,
29156 .freeze = pdc_sata_freeze,
29157@@ -208,14 +208,14 @@ static struct ata_port_operations pdc_sata_ops = {
29158
29159 /* First-generation chips need a more restrictive ->check_atapi_dma op,
29160 and ->freeze/thaw that ignore the hotplug controls. */
29161-static struct ata_port_operations pdc_old_sata_ops = {
29162+static const struct ata_port_operations pdc_old_sata_ops = {
29163 .inherits = &pdc_sata_ops,
29164 .freeze = pdc_freeze,
29165 .thaw = pdc_thaw,
29166 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
29167 };
29168
29169-static struct ata_port_operations pdc_pata_ops = {
29170+static const struct ata_port_operations pdc_pata_ops = {
29171 .inherits = &pdc_common_ops,
29172 .cable_detect = pdc_pata_cable_detect,
29173 .freeze = pdc_freeze,
29174diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
29175index 326c0cf..36ecebe 100644
29176--- a/drivers/ata/sata_qstor.c
29177+++ b/drivers/ata/sata_qstor.c
29178@@ -132,7 +132,7 @@ static struct scsi_host_template qs_ata_sht = {
29179 .dma_boundary = QS_DMA_BOUNDARY,
29180 };
29181
29182-static struct ata_port_operations qs_ata_ops = {
29183+static const struct ata_port_operations qs_ata_ops = {
29184 .inherits = &ata_sff_port_ops,
29185
29186 .check_atapi_dma = qs_check_atapi_dma,
29187diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
29188index 3cb69d5..0871d3c 100644
29189--- a/drivers/ata/sata_sil.c
29190+++ b/drivers/ata/sata_sil.c
29191@@ -182,7 +182,7 @@ static struct scsi_host_template sil_sht = {
29192 .sg_tablesize = ATA_MAX_PRD
29193 };
29194
29195-static struct ata_port_operations sil_ops = {
29196+static const struct ata_port_operations sil_ops = {
29197 .inherits = &ata_bmdma32_port_ops,
29198 .dev_config = sil_dev_config,
29199 .set_mode = sil_set_mode,
29200diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
29201index e6946fc..eddb794 100644
29202--- a/drivers/ata/sata_sil24.c
29203+++ b/drivers/ata/sata_sil24.c
29204@@ -388,7 +388,7 @@ static struct scsi_host_template sil24_sht = {
29205 .dma_boundary = ATA_DMA_BOUNDARY,
29206 };
29207
29208-static struct ata_port_operations sil24_ops = {
29209+static const struct ata_port_operations sil24_ops = {
29210 .inherits = &sata_pmp_port_ops,
29211
29212 .qc_defer = sil24_qc_defer,
29213diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
29214index f8a91bf..9cb06b6 100644
29215--- a/drivers/ata/sata_sis.c
29216+++ b/drivers/ata/sata_sis.c
29217@@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht = {
29218 ATA_BMDMA_SHT(DRV_NAME),
29219 };
29220
29221-static struct ata_port_operations sis_ops = {
29222+static const struct ata_port_operations sis_ops = {
29223 .inherits = &ata_bmdma_port_ops,
29224 .scr_read = sis_scr_read,
29225 .scr_write = sis_scr_write,
29226diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
29227index 7257f2d..d04c6f5 100644
29228--- a/drivers/ata/sata_svw.c
29229+++ b/drivers/ata/sata_svw.c
29230@@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata_sht = {
29231 };
29232
29233
29234-static struct ata_port_operations k2_sata_ops = {
29235+static const struct ata_port_operations k2_sata_ops = {
29236 .inherits = &ata_bmdma_port_ops,
29237 .sff_tf_load = k2_sata_tf_load,
29238 .sff_tf_read = k2_sata_tf_read,
29239diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
29240index bbcf970..cd0df0d 100644
29241--- a/drivers/ata/sata_sx4.c
29242+++ b/drivers/ata/sata_sx4.c
29243@@ -248,7 +248,7 @@ static struct scsi_host_template pdc_sata_sht = {
29244 };
29245
29246 /* TODO: inherit from base port_ops after converting to new EH */
29247-static struct ata_port_operations pdc_20621_ops = {
29248+static const struct ata_port_operations pdc_20621_ops = {
29249 .inherits = &ata_sff_port_ops,
29250
29251 .check_atapi_dma = pdc_check_atapi_dma,
29252diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
29253index e5bff47..089d859 100644
29254--- a/drivers/ata/sata_uli.c
29255+++ b/drivers/ata/sata_uli.c
29256@@ -79,7 +79,7 @@ static struct scsi_host_template uli_sht = {
29257 ATA_BMDMA_SHT(DRV_NAME),
29258 };
29259
29260-static struct ata_port_operations uli_ops = {
29261+static const struct ata_port_operations uli_ops = {
29262 .inherits = &ata_bmdma_port_ops,
29263 .scr_read = uli_scr_read,
29264 .scr_write = uli_scr_write,
29265diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
29266index f5dcca7..77b94eb 100644
29267--- a/drivers/ata/sata_via.c
29268+++ b/drivers/ata/sata_via.c
29269@@ -115,32 +115,32 @@ static struct scsi_host_template svia_sht = {
29270 ATA_BMDMA_SHT(DRV_NAME),
29271 };
29272
29273-static struct ata_port_operations svia_base_ops = {
29274+static const struct ata_port_operations svia_base_ops = {
29275 .inherits = &ata_bmdma_port_ops,
29276 .sff_tf_load = svia_tf_load,
29277 };
29278
29279-static struct ata_port_operations vt6420_sata_ops = {
29280+static const struct ata_port_operations vt6420_sata_ops = {
29281 .inherits = &svia_base_ops,
29282 .freeze = svia_noop_freeze,
29283 .prereset = vt6420_prereset,
29284 .bmdma_start = vt6420_bmdma_start,
29285 };
29286
29287-static struct ata_port_operations vt6421_pata_ops = {
29288+static const struct ata_port_operations vt6421_pata_ops = {
29289 .inherits = &svia_base_ops,
29290 .cable_detect = vt6421_pata_cable_detect,
29291 .set_piomode = vt6421_set_pio_mode,
29292 .set_dmamode = vt6421_set_dma_mode,
29293 };
29294
29295-static struct ata_port_operations vt6421_sata_ops = {
29296+static const struct ata_port_operations vt6421_sata_ops = {
29297 .inherits = &svia_base_ops,
29298 .scr_read = svia_scr_read,
29299 .scr_write = svia_scr_write,
29300 };
29301
29302-static struct ata_port_operations vt8251_ops = {
29303+static const struct ata_port_operations vt8251_ops = {
29304 .inherits = &svia_base_ops,
29305 .hardreset = sata_std_hardreset,
29306 .scr_read = vt8251_scr_read,
29307diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
29308index 8b2a278..51e65d3 100644
29309--- a/drivers/ata/sata_vsc.c
29310+++ b/drivers/ata/sata_vsc.c
29311@@ -306,7 +306,7 @@ static struct scsi_host_template vsc_sata_sht = {
29312 };
29313
29314
29315-static struct ata_port_operations vsc_sata_ops = {
29316+static const struct ata_port_operations vsc_sata_ops = {
29317 .inherits = &ata_bmdma_port_ops,
29318 /* The IRQ handling is not quite standard SFF behaviour so we
29319 cannot use the default lost interrupt handler */
29320diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
29321index 5effec6..7e4019a 100644
29322--- a/drivers/atm/adummy.c
29323+++ b/drivers/atm/adummy.c
29324@@ -77,7 +77,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
29325 vcc->pop(vcc, skb);
29326 else
29327 dev_kfree_skb_any(skb);
29328- atomic_inc(&vcc->stats->tx);
29329+ atomic_inc_unchecked(&vcc->stats->tx);
29330
29331 return 0;
29332 }
29333diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
29334index 66e1813..26a27c6 100644
29335--- a/drivers/atm/ambassador.c
29336+++ b/drivers/atm/ambassador.c
29337@@ -453,7 +453,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
29338 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
29339
29340 // VC layer stats
29341- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29342+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29343
29344 // free the descriptor
29345 kfree (tx_descr);
29346@@ -494,7 +494,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29347 dump_skb ("<<<", vc, skb);
29348
29349 // VC layer stats
29350- atomic_inc(&atm_vcc->stats->rx);
29351+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29352 __net_timestamp(skb);
29353 // end of our responsability
29354 atm_vcc->push (atm_vcc, skb);
29355@@ -509,7 +509,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29356 } else {
29357 PRINTK (KERN_INFO, "dropped over-size frame");
29358 // should we count this?
29359- atomic_inc(&atm_vcc->stats->rx_drop);
29360+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29361 }
29362
29363 } else {
29364@@ -1341,7 +1341,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
29365 }
29366
29367 if (check_area (skb->data, skb->len)) {
29368- atomic_inc(&atm_vcc->stats->tx_err);
29369+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
29370 return -ENOMEM; // ?
29371 }
29372
29373diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
29374index 02ad83d..6daffeb 100644
29375--- a/drivers/atm/atmtcp.c
29376+++ b/drivers/atm/atmtcp.c
29377@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29378 if (vcc->pop) vcc->pop(vcc,skb);
29379 else dev_kfree_skb(skb);
29380 if (dev_data) return 0;
29381- atomic_inc(&vcc->stats->tx_err);
29382+ atomic_inc_unchecked(&vcc->stats->tx_err);
29383 return -ENOLINK;
29384 }
29385 size = skb->len+sizeof(struct atmtcp_hdr);
29386@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29387 if (!new_skb) {
29388 if (vcc->pop) vcc->pop(vcc,skb);
29389 else dev_kfree_skb(skb);
29390- atomic_inc(&vcc->stats->tx_err);
29391+ atomic_inc_unchecked(&vcc->stats->tx_err);
29392 return -ENOBUFS;
29393 }
29394 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
29395@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29396 if (vcc->pop) vcc->pop(vcc,skb);
29397 else dev_kfree_skb(skb);
29398 out_vcc->push(out_vcc,new_skb);
29399- atomic_inc(&vcc->stats->tx);
29400- atomic_inc(&out_vcc->stats->rx);
29401+ atomic_inc_unchecked(&vcc->stats->tx);
29402+ atomic_inc_unchecked(&out_vcc->stats->rx);
29403 return 0;
29404 }
29405
29406@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29407 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
29408 read_unlock(&vcc_sklist_lock);
29409 if (!out_vcc) {
29410- atomic_inc(&vcc->stats->tx_err);
29411+ atomic_inc_unchecked(&vcc->stats->tx_err);
29412 goto done;
29413 }
29414 skb_pull(skb,sizeof(struct atmtcp_hdr));
29415@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29416 __net_timestamp(new_skb);
29417 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
29418 out_vcc->push(out_vcc,new_skb);
29419- atomic_inc(&vcc->stats->tx);
29420- atomic_inc(&out_vcc->stats->rx);
29421+ atomic_inc_unchecked(&vcc->stats->tx);
29422+ atomic_inc_unchecked(&out_vcc->stats->rx);
29423 done:
29424 if (vcc->pop) vcc->pop(vcc,skb);
29425 else dev_kfree_skb(skb);
29426diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
29427index 0c30261..3da356e 100644
29428--- a/drivers/atm/eni.c
29429+++ b/drivers/atm/eni.c
29430@@ -525,7 +525,7 @@ static int rx_aal0(struct atm_vcc *vcc)
29431 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
29432 vcc->dev->number);
29433 length = 0;
29434- atomic_inc(&vcc->stats->rx_err);
29435+ atomic_inc_unchecked(&vcc->stats->rx_err);
29436 }
29437 else {
29438 length = ATM_CELL_SIZE-1; /* no HEC */
29439@@ -580,7 +580,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29440 size);
29441 }
29442 eff = length = 0;
29443- atomic_inc(&vcc->stats->rx_err);
29444+ atomic_inc_unchecked(&vcc->stats->rx_err);
29445 }
29446 else {
29447 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
29448@@ -597,7 +597,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29449 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
29450 vcc->dev->number,vcc->vci,length,size << 2,descr);
29451 length = eff = 0;
29452- atomic_inc(&vcc->stats->rx_err);
29453+ atomic_inc_unchecked(&vcc->stats->rx_err);
29454 }
29455 }
29456 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
29457@@ -770,7 +770,7 @@ rx_dequeued++;
29458 vcc->push(vcc,skb);
29459 pushed++;
29460 }
29461- atomic_inc(&vcc->stats->rx);
29462+ atomic_inc_unchecked(&vcc->stats->rx);
29463 }
29464 wake_up(&eni_dev->rx_wait);
29465 }
29466@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
29467 PCI_DMA_TODEVICE);
29468 if (vcc->pop) vcc->pop(vcc,skb);
29469 else dev_kfree_skb_irq(skb);
29470- atomic_inc(&vcc->stats->tx);
29471+ atomic_inc_unchecked(&vcc->stats->tx);
29472 wake_up(&eni_dev->tx_wait);
29473 dma_complete++;
29474 }
29475@@ -1570,7 +1570,7 @@ tx_complete++;
29476 /*--------------------------------- entries ---------------------------------*/
29477
29478
29479-static const char *media_name[] __devinitdata = {
29480+static const char *media_name[] __devinitconst = {
29481 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
29482 "UTP", "05?", "06?", "07?", /* 4- 7 */
29483 "TAXI","09?", "10?", "11?", /* 8-11 */
29484diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
29485index cd5049a..a51209f 100644
29486--- a/drivers/atm/firestream.c
29487+++ b/drivers/atm/firestream.c
29488@@ -748,7 +748,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
29489 }
29490 }
29491
29492- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29493+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29494
29495 fs_dprintk (FS_DEBUG_TXMEM, "i");
29496 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
29497@@ -815,7 +815,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29498 #endif
29499 skb_put (skb, qe->p1 & 0xffff);
29500 ATM_SKB(skb)->vcc = atm_vcc;
29501- atomic_inc(&atm_vcc->stats->rx);
29502+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29503 __net_timestamp(skb);
29504 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
29505 atm_vcc->push (atm_vcc, skb);
29506@@ -836,12 +836,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29507 kfree (pe);
29508 }
29509 if (atm_vcc)
29510- atomic_inc(&atm_vcc->stats->rx_drop);
29511+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29512 break;
29513 case 0x1f: /* Reassembly abort: no buffers. */
29514 /* Silently increment error counter. */
29515 if (atm_vcc)
29516- atomic_inc(&atm_vcc->stats->rx_drop);
29517+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29518 break;
29519 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
29520 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
29521diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
29522index f766cc4..a34002e 100644
29523--- a/drivers/atm/fore200e.c
29524+++ b/drivers/atm/fore200e.c
29525@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
29526 #endif
29527 /* check error condition */
29528 if (*entry->status & STATUS_ERROR)
29529- atomic_inc(&vcc->stats->tx_err);
29530+ atomic_inc_unchecked(&vcc->stats->tx_err);
29531 else
29532- atomic_inc(&vcc->stats->tx);
29533+ atomic_inc_unchecked(&vcc->stats->tx);
29534 }
29535 }
29536
29537@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29538 if (skb == NULL) {
29539 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
29540
29541- atomic_inc(&vcc->stats->rx_drop);
29542+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29543 return -ENOMEM;
29544 }
29545
29546@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29547
29548 dev_kfree_skb_any(skb);
29549
29550- atomic_inc(&vcc->stats->rx_drop);
29551+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29552 return -ENOMEM;
29553 }
29554
29555 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29556
29557 vcc->push(vcc, skb);
29558- atomic_inc(&vcc->stats->rx);
29559+ atomic_inc_unchecked(&vcc->stats->rx);
29560
29561 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29562
29563@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
29564 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
29565 fore200e->atm_dev->number,
29566 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
29567- atomic_inc(&vcc->stats->rx_err);
29568+ atomic_inc_unchecked(&vcc->stats->rx_err);
29569 }
29570 }
29571
29572@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
29573 goto retry_here;
29574 }
29575
29576- atomic_inc(&vcc->stats->tx_err);
29577+ atomic_inc_unchecked(&vcc->stats->tx_err);
29578
29579 fore200e->tx_sat++;
29580 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
29581diff --git a/drivers/atm/he.c b/drivers/atm/he.c
29582index 7066703..2b130de 100644
29583--- a/drivers/atm/he.c
29584+++ b/drivers/atm/he.c
29585@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29586
29587 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
29588 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
29589- atomic_inc(&vcc->stats->rx_drop);
29590+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29591 goto return_host_buffers;
29592 }
29593
29594@@ -1802,7 +1802,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29595 RBRQ_LEN_ERR(he_dev->rbrq_head)
29596 ? "LEN_ERR" : "",
29597 vcc->vpi, vcc->vci);
29598- atomic_inc(&vcc->stats->rx_err);
29599+ atomic_inc_unchecked(&vcc->stats->rx_err);
29600 goto return_host_buffers;
29601 }
29602
29603@@ -1861,7 +1861,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29604 vcc->push(vcc, skb);
29605 spin_lock(&he_dev->global_lock);
29606
29607- atomic_inc(&vcc->stats->rx);
29608+ atomic_inc_unchecked(&vcc->stats->rx);
29609
29610 return_host_buffers:
29611 ++pdus_assembled;
29612@@ -2206,7 +2206,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
29613 tpd->vcc->pop(tpd->vcc, tpd->skb);
29614 else
29615 dev_kfree_skb_any(tpd->skb);
29616- atomic_inc(&tpd->vcc->stats->tx_err);
29617+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
29618 }
29619 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
29620 return;
29621@@ -2618,7 +2618,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29622 vcc->pop(vcc, skb);
29623 else
29624 dev_kfree_skb_any(skb);
29625- atomic_inc(&vcc->stats->tx_err);
29626+ atomic_inc_unchecked(&vcc->stats->tx_err);
29627 return -EINVAL;
29628 }
29629
29630@@ -2629,7 +2629,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29631 vcc->pop(vcc, skb);
29632 else
29633 dev_kfree_skb_any(skb);
29634- atomic_inc(&vcc->stats->tx_err);
29635+ atomic_inc_unchecked(&vcc->stats->tx_err);
29636 return -EINVAL;
29637 }
29638 #endif
29639@@ -2641,7 +2641,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29640 vcc->pop(vcc, skb);
29641 else
29642 dev_kfree_skb_any(skb);
29643- atomic_inc(&vcc->stats->tx_err);
29644+ atomic_inc_unchecked(&vcc->stats->tx_err);
29645 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29646 return -ENOMEM;
29647 }
29648@@ -2683,7 +2683,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29649 vcc->pop(vcc, skb);
29650 else
29651 dev_kfree_skb_any(skb);
29652- atomic_inc(&vcc->stats->tx_err);
29653+ atomic_inc_unchecked(&vcc->stats->tx_err);
29654 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29655 return -ENOMEM;
29656 }
29657@@ -2714,7 +2714,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29658 __enqueue_tpd(he_dev, tpd, cid);
29659 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29660
29661- atomic_inc(&vcc->stats->tx);
29662+ atomic_inc_unchecked(&vcc->stats->tx);
29663
29664 return 0;
29665 }
29666diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
29667index 4e49021..01b1512 100644
29668--- a/drivers/atm/horizon.c
29669+++ b/drivers/atm/horizon.c
29670@@ -1033,7 +1033,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
29671 {
29672 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
29673 // VC layer stats
29674- atomic_inc(&vcc->stats->rx);
29675+ atomic_inc_unchecked(&vcc->stats->rx);
29676 __net_timestamp(skb);
29677 // end of our responsability
29678 vcc->push (vcc, skb);
29679@@ -1185,7 +1185,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
29680 dev->tx_iovec = NULL;
29681
29682 // VC layer stats
29683- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29684+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29685
29686 // free the skb
29687 hrz_kfree_skb (skb);
29688diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
29689index e33ae00..9deb4ab 100644
29690--- a/drivers/atm/idt77252.c
29691+++ b/drivers/atm/idt77252.c
29692@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
29693 else
29694 dev_kfree_skb(skb);
29695
29696- atomic_inc(&vcc->stats->tx);
29697+ atomic_inc_unchecked(&vcc->stats->tx);
29698 }
29699
29700 atomic_dec(&scq->used);
29701@@ -1073,13 +1073,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29702 if ((sb = dev_alloc_skb(64)) == NULL) {
29703 printk("%s: Can't allocate buffers for aal0.\n",
29704 card->name);
29705- atomic_add(i, &vcc->stats->rx_drop);
29706+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
29707 break;
29708 }
29709 if (!atm_charge(vcc, sb->truesize)) {
29710 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
29711 card->name);
29712- atomic_add(i - 1, &vcc->stats->rx_drop);
29713+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
29714 dev_kfree_skb(sb);
29715 break;
29716 }
29717@@ -1096,7 +1096,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29718 ATM_SKB(sb)->vcc = vcc;
29719 __net_timestamp(sb);
29720 vcc->push(vcc, sb);
29721- atomic_inc(&vcc->stats->rx);
29722+ atomic_inc_unchecked(&vcc->stats->rx);
29723
29724 cell += ATM_CELL_PAYLOAD;
29725 }
29726@@ -1133,13 +1133,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29727 "(CDC: %08x)\n",
29728 card->name, len, rpp->len, readl(SAR_REG_CDC));
29729 recycle_rx_pool_skb(card, rpp);
29730- atomic_inc(&vcc->stats->rx_err);
29731+ atomic_inc_unchecked(&vcc->stats->rx_err);
29732 return;
29733 }
29734 if (stat & SAR_RSQE_CRC) {
29735 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
29736 recycle_rx_pool_skb(card, rpp);
29737- atomic_inc(&vcc->stats->rx_err);
29738+ atomic_inc_unchecked(&vcc->stats->rx_err);
29739 return;
29740 }
29741 if (skb_queue_len(&rpp->queue) > 1) {
29742@@ -1150,7 +1150,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29743 RXPRINTK("%s: Can't alloc RX skb.\n",
29744 card->name);
29745 recycle_rx_pool_skb(card, rpp);
29746- atomic_inc(&vcc->stats->rx_err);
29747+ atomic_inc_unchecked(&vcc->stats->rx_err);
29748 return;
29749 }
29750 if (!atm_charge(vcc, skb->truesize)) {
29751@@ -1169,7 +1169,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29752 __net_timestamp(skb);
29753
29754 vcc->push(vcc, skb);
29755- atomic_inc(&vcc->stats->rx);
29756+ atomic_inc_unchecked(&vcc->stats->rx);
29757
29758 return;
29759 }
29760@@ -1191,7 +1191,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29761 __net_timestamp(skb);
29762
29763 vcc->push(vcc, skb);
29764- atomic_inc(&vcc->stats->rx);
29765+ atomic_inc_unchecked(&vcc->stats->rx);
29766
29767 if (skb->truesize > SAR_FB_SIZE_3)
29768 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
29769@@ -1303,14 +1303,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
29770 if (vcc->qos.aal != ATM_AAL0) {
29771 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
29772 card->name, vpi, vci);
29773- atomic_inc(&vcc->stats->rx_drop);
29774+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29775 goto drop;
29776 }
29777
29778 if ((sb = dev_alloc_skb(64)) == NULL) {
29779 printk("%s: Can't allocate buffers for AAL0.\n",
29780 card->name);
29781- atomic_inc(&vcc->stats->rx_err);
29782+ atomic_inc_unchecked(&vcc->stats->rx_err);
29783 goto drop;
29784 }
29785
29786@@ -1329,7 +1329,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
29787 ATM_SKB(sb)->vcc = vcc;
29788 __net_timestamp(sb);
29789 vcc->push(vcc, sb);
29790- atomic_inc(&vcc->stats->rx);
29791+ atomic_inc_unchecked(&vcc->stats->rx);
29792
29793 drop:
29794 skb_pull(queue, 64);
29795@@ -1954,13 +1954,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29796
29797 if (vc == NULL) {
29798 printk("%s: NULL connection in send().\n", card->name);
29799- atomic_inc(&vcc->stats->tx_err);
29800+ atomic_inc_unchecked(&vcc->stats->tx_err);
29801 dev_kfree_skb(skb);
29802 return -EINVAL;
29803 }
29804 if (!test_bit(VCF_TX, &vc->flags)) {
29805 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
29806- atomic_inc(&vcc->stats->tx_err);
29807+ atomic_inc_unchecked(&vcc->stats->tx_err);
29808 dev_kfree_skb(skb);
29809 return -EINVAL;
29810 }
29811@@ -1972,14 +1972,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29812 break;
29813 default:
29814 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
29815- atomic_inc(&vcc->stats->tx_err);
29816+ atomic_inc_unchecked(&vcc->stats->tx_err);
29817 dev_kfree_skb(skb);
29818 return -EINVAL;
29819 }
29820
29821 if (skb_shinfo(skb)->nr_frags != 0) {
29822 printk("%s: No scatter-gather yet.\n", card->name);
29823- atomic_inc(&vcc->stats->tx_err);
29824+ atomic_inc_unchecked(&vcc->stats->tx_err);
29825 dev_kfree_skb(skb);
29826 return -EINVAL;
29827 }
29828@@ -1987,7 +1987,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29829
29830 err = queue_skb(card, vc, skb, oam);
29831 if (err) {
29832- atomic_inc(&vcc->stats->tx_err);
29833+ atomic_inc_unchecked(&vcc->stats->tx_err);
29834 dev_kfree_skb(skb);
29835 return err;
29836 }
29837@@ -2010,7 +2010,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
29838 skb = dev_alloc_skb(64);
29839 if (!skb) {
29840 printk("%s: Out of memory in send_oam().\n", card->name);
29841- atomic_inc(&vcc->stats->tx_err);
29842+ atomic_inc_unchecked(&vcc->stats->tx_err);
29843 return -ENOMEM;
29844 }
29845 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
29846diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
29847index b2c1b37..faa672b 100644
29848--- a/drivers/atm/iphase.c
29849+++ b/drivers/atm/iphase.c
29850@@ -1123,7 +1123,7 @@ static int rx_pkt(struct atm_dev *dev)
29851 status = (u_short) (buf_desc_ptr->desc_mode);
29852 if (status & (RX_CER | RX_PTE | RX_OFL))
29853 {
29854- atomic_inc(&vcc->stats->rx_err);
29855+ atomic_inc_unchecked(&vcc->stats->rx_err);
29856 IF_ERR(printk("IA: bad packet, dropping it");)
29857 if (status & RX_CER) {
29858 IF_ERR(printk(" cause: packet CRC error\n");)
29859@@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
29860 len = dma_addr - buf_addr;
29861 if (len > iadev->rx_buf_sz) {
29862 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
29863- atomic_inc(&vcc->stats->rx_err);
29864+ atomic_inc_unchecked(&vcc->stats->rx_err);
29865 goto out_free_desc;
29866 }
29867
29868@@ -1296,7 +1296,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29869 ia_vcc = INPH_IA_VCC(vcc);
29870 if (ia_vcc == NULL)
29871 {
29872- atomic_inc(&vcc->stats->rx_err);
29873+ atomic_inc_unchecked(&vcc->stats->rx_err);
29874 dev_kfree_skb_any(skb);
29875 atm_return(vcc, atm_guess_pdu2truesize(len));
29876 goto INCR_DLE;
29877@@ -1308,7 +1308,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29878 if ((length > iadev->rx_buf_sz) || (length >
29879 (skb->len - sizeof(struct cpcs_trailer))))
29880 {
29881- atomic_inc(&vcc->stats->rx_err);
29882+ atomic_inc_unchecked(&vcc->stats->rx_err);
29883 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
29884 length, skb->len);)
29885 dev_kfree_skb_any(skb);
29886@@ -1324,7 +1324,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29887
29888 IF_RX(printk("rx_dle_intr: skb push");)
29889 vcc->push(vcc,skb);
29890- atomic_inc(&vcc->stats->rx);
29891+ atomic_inc_unchecked(&vcc->stats->rx);
29892 iadev->rx_pkt_cnt++;
29893 }
29894 INCR_DLE:
29895@@ -2806,15 +2806,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
29896 {
29897 struct k_sonet_stats *stats;
29898 stats = &PRIV(_ia_dev[board])->sonet_stats;
29899- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
29900- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
29901- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
29902- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
29903- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
29904- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
29905- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
29906- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
29907- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
29908+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
29909+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
29910+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
29911+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
29912+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
29913+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
29914+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
29915+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
29916+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
29917 }
29918 ia_cmds.status = 0;
29919 break;
29920@@ -2919,7 +2919,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29921 if ((desc == 0) || (desc > iadev->num_tx_desc))
29922 {
29923 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
29924- atomic_inc(&vcc->stats->tx);
29925+ atomic_inc_unchecked(&vcc->stats->tx);
29926 if (vcc->pop)
29927 vcc->pop(vcc, skb);
29928 else
29929@@ -3024,14 +3024,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29930 ATM_DESC(skb) = vcc->vci;
29931 skb_queue_tail(&iadev->tx_dma_q, skb);
29932
29933- atomic_inc(&vcc->stats->tx);
29934+ atomic_inc_unchecked(&vcc->stats->tx);
29935 iadev->tx_pkt_cnt++;
29936 /* Increment transaction counter */
29937 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
29938
29939 #if 0
29940 /* add flow control logic */
29941- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
29942+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
29943 if (iavcc->vc_desc_cnt > 10) {
29944 vcc->tx_quota = vcc->tx_quota * 3 / 4;
29945 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
29946diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
29947index cf97c34..8d30655 100644
29948--- a/drivers/atm/lanai.c
29949+++ b/drivers/atm/lanai.c
29950@@ -1305,7 +1305,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
29951 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
29952 lanai_endtx(lanai, lvcc);
29953 lanai_free_skb(lvcc->tx.atmvcc, skb);
29954- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
29955+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
29956 }
29957
29958 /* Try to fill the buffer - don't call unless there is backlog */
29959@@ -1428,7 +1428,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
29960 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
29961 __net_timestamp(skb);
29962 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
29963- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
29964+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
29965 out:
29966 lvcc->rx.buf.ptr = end;
29967 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
29968@@ -1670,7 +1670,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29969 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
29970 "vcc %d\n", lanai->number, (unsigned int) s, vci);
29971 lanai->stats.service_rxnotaal5++;
29972- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29973+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29974 return 0;
29975 }
29976 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
29977@@ -1682,7 +1682,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29978 int bytes;
29979 read_unlock(&vcc_sklist_lock);
29980 DPRINTK("got trashed rx pdu on vci %d\n", vci);
29981- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29982+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29983 lvcc->stats.x.aal5.service_trash++;
29984 bytes = (SERVICE_GET_END(s) * 16) -
29985 (((unsigned long) lvcc->rx.buf.ptr) -
29986@@ -1694,7 +1694,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29987 }
29988 if (s & SERVICE_STREAM) {
29989 read_unlock(&vcc_sklist_lock);
29990- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29991+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29992 lvcc->stats.x.aal5.service_stream++;
29993 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
29994 "PDU on VCI %d!\n", lanai->number, vci);
29995@@ -1702,7 +1702,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29996 return 0;
29997 }
29998 DPRINTK("got rx crc error on vci %d\n", vci);
29999- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30000+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30001 lvcc->stats.x.aal5.service_rxcrc++;
30002 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30003 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30004diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30005index 3da804b..d3b0eed 100644
30006--- a/drivers/atm/nicstar.c
30007+++ b/drivers/atm/nicstar.c
30008@@ -1723,7 +1723,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30009 if ((vc = (vc_map *) vcc->dev_data) == NULL)
30010 {
30011 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", card->index);
30012- atomic_inc(&vcc->stats->tx_err);
30013+ atomic_inc_unchecked(&vcc->stats->tx_err);
30014 dev_kfree_skb_any(skb);
30015 return -EINVAL;
30016 }
30017@@ -1731,7 +1731,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30018 if (!vc->tx)
30019 {
30020 printk("nicstar%d: Trying to transmit on a non-tx VC.\n", card->index);
30021- atomic_inc(&vcc->stats->tx_err);
30022+ atomic_inc_unchecked(&vcc->stats->tx_err);
30023 dev_kfree_skb_any(skb);
30024 return -EINVAL;
30025 }
30026@@ -1739,7 +1739,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30027 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0)
30028 {
30029 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", card->index);
30030- atomic_inc(&vcc->stats->tx_err);
30031+ atomic_inc_unchecked(&vcc->stats->tx_err);
30032 dev_kfree_skb_any(skb);
30033 return -EINVAL;
30034 }
30035@@ -1747,7 +1747,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30036 if (skb_shinfo(skb)->nr_frags != 0)
30037 {
30038 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30039- atomic_inc(&vcc->stats->tx_err);
30040+ atomic_inc_unchecked(&vcc->stats->tx_err);
30041 dev_kfree_skb_any(skb);
30042 return -EINVAL;
30043 }
30044@@ -1792,11 +1792,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30045
30046 if (push_scqe(card, vc, scq, &scqe, skb) != 0)
30047 {
30048- atomic_inc(&vcc->stats->tx_err);
30049+ atomic_inc_unchecked(&vcc->stats->tx_err);
30050 dev_kfree_skb_any(skb);
30051 return -EIO;
30052 }
30053- atomic_inc(&vcc->stats->tx);
30054+ atomic_inc_unchecked(&vcc->stats->tx);
30055
30056 return 0;
30057 }
30058@@ -2111,14 +2111,14 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30059 {
30060 printk("nicstar%d: Can't allocate buffers for aal0.\n",
30061 card->index);
30062- atomic_add(i,&vcc->stats->rx_drop);
30063+ atomic_add_unchecked(i,&vcc->stats->rx_drop);
30064 break;
30065 }
30066 if (!atm_charge(vcc, sb->truesize))
30067 {
30068 RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n",
30069 card->index);
30070- atomic_add(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
30071+ atomic_add_unchecked(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
30072 dev_kfree_skb_any(sb);
30073 break;
30074 }
30075@@ -2133,7 +2133,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30076 ATM_SKB(sb)->vcc = vcc;
30077 __net_timestamp(sb);
30078 vcc->push(vcc, sb);
30079- atomic_inc(&vcc->stats->rx);
30080+ atomic_inc_unchecked(&vcc->stats->rx);
30081 cell += ATM_CELL_PAYLOAD;
30082 }
30083
30084@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30085 if (iovb == NULL)
30086 {
30087 printk("nicstar%d: Out of iovec buffers.\n", card->index);
30088- atomic_inc(&vcc->stats->rx_drop);
30089+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30090 recycle_rx_buf(card, skb);
30091 return;
30092 }
30093@@ -2182,7 +2182,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30094 else if (NS_SKB(iovb)->iovcnt >= NS_MAX_IOVECS)
30095 {
30096 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30097- atomic_inc(&vcc->stats->rx_err);
30098+ atomic_inc_unchecked(&vcc->stats->rx_err);
30099 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, NS_MAX_IOVECS);
30100 NS_SKB(iovb)->iovcnt = 0;
30101 iovb->len = 0;
30102@@ -2202,7 +2202,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30103 printk("nicstar%d: Expected a small buffer, and this is not one.\n",
30104 card->index);
30105 which_list(card, skb);
30106- atomic_inc(&vcc->stats->rx_err);
30107+ atomic_inc_unchecked(&vcc->stats->rx_err);
30108 recycle_rx_buf(card, skb);
30109 vc->rx_iov = NULL;
30110 recycle_iov_buf(card, iovb);
30111@@ -2216,7 +2216,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30112 printk("nicstar%d: Expected a large buffer, and this is not one.\n",
30113 card->index);
30114 which_list(card, skb);
30115- atomic_inc(&vcc->stats->rx_err);
30116+ atomic_inc_unchecked(&vcc->stats->rx_err);
30117 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
30118 NS_SKB(iovb)->iovcnt);
30119 vc->rx_iov = NULL;
30120@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30121 printk(" - PDU size mismatch.\n");
30122 else
30123 printk(".\n");
30124- atomic_inc(&vcc->stats->rx_err);
30125+ atomic_inc_unchecked(&vcc->stats->rx_err);
30126 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
30127 NS_SKB(iovb)->iovcnt);
30128 vc->rx_iov = NULL;
30129@@ -2256,7 +2256,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30130 if (!atm_charge(vcc, skb->truesize))
30131 {
30132 push_rxbufs(card, skb);
30133- atomic_inc(&vcc->stats->rx_drop);
30134+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30135 }
30136 else
30137 {
30138@@ -2268,7 +2268,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30139 ATM_SKB(skb)->vcc = vcc;
30140 __net_timestamp(skb);
30141 vcc->push(vcc, skb);
30142- atomic_inc(&vcc->stats->rx);
30143+ atomic_inc_unchecked(&vcc->stats->rx);
30144 }
30145 }
30146 else if (NS_SKB(iovb)->iovcnt == 2) /* One small plus one large buffer */
30147@@ -2283,7 +2283,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30148 if (!atm_charge(vcc, sb->truesize))
30149 {
30150 push_rxbufs(card, sb);
30151- atomic_inc(&vcc->stats->rx_drop);
30152+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30153 }
30154 else
30155 {
30156@@ -2295,7 +2295,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30157 ATM_SKB(sb)->vcc = vcc;
30158 __net_timestamp(sb);
30159 vcc->push(vcc, sb);
30160- atomic_inc(&vcc->stats->rx);
30161+ atomic_inc_unchecked(&vcc->stats->rx);
30162 }
30163
30164 push_rxbufs(card, skb);
30165@@ -2306,7 +2306,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30166 if (!atm_charge(vcc, skb->truesize))
30167 {
30168 push_rxbufs(card, skb);
30169- atomic_inc(&vcc->stats->rx_drop);
30170+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30171 }
30172 else
30173 {
30174@@ -2320,7 +2320,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30175 ATM_SKB(skb)->vcc = vcc;
30176 __net_timestamp(skb);
30177 vcc->push(vcc, skb);
30178- atomic_inc(&vcc->stats->rx);
30179+ atomic_inc_unchecked(&vcc->stats->rx);
30180 }
30181
30182 push_rxbufs(card, sb);
30183@@ -2342,7 +2342,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30184 if (hb == NULL)
30185 {
30186 printk("nicstar%d: Out of huge buffers.\n", card->index);
30187- atomic_inc(&vcc->stats->rx_drop);
30188+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30189 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
30190 NS_SKB(iovb)->iovcnt);
30191 vc->rx_iov = NULL;
30192@@ -2393,7 +2393,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30193 }
30194 else
30195 dev_kfree_skb_any(hb);
30196- atomic_inc(&vcc->stats->rx_drop);
30197+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30198 }
30199 else
30200 {
30201@@ -2427,7 +2427,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30202 #endif /* NS_USE_DESTRUCTORS */
30203 __net_timestamp(hb);
30204 vcc->push(vcc, hb);
30205- atomic_inc(&vcc->stats->rx);
30206+ atomic_inc_unchecked(&vcc->stats->rx);
30207 }
30208 }
30209
30210diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30211index 84c93ff..e6ed269 100644
30212--- a/drivers/atm/solos-pci.c
30213+++ b/drivers/atm/solos-pci.c
30214@@ -708,7 +708,7 @@ void solos_bh(unsigned long card_arg)
30215 }
30216 atm_charge(vcc, skb->truesize);
30217 vcc->push(vcc, skb);
30218- atomic_inc(&vcc->stats->rx);
30219+ atomic_inc_unchecked(&vcc->stats->rx);
30220 break;
30221
30222 case PKT_STATUS:
30223@@ -914,6 +914,8 @@ static int print_buffer(struct sk_buff *buf)
30224 char msg[500];
30225 char item[10];
30226
30227+ pax_track_stack();
30228+
30229 len = buf->len;
30230 for (i = 0; i < len; i++){
30231 if(i % 8 == 0)
30232@@ -1023,7 +1025,7 @@ static uint32_t fpga_tx(struct solos_card *card)
30233 vcc = SKB_CB(oldskb)->vcc;
30234
30235 if (vcc) {
30236- atomic_inc(&vcc->stats->tx);
30237+ atomic_inc_unchecked(&vcc->stats->tx);
30238 solos_pop(vcc, oldskb);
30239 } else
30240 dev_kfree_skb_irq(oldskb);
30241diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
30242index 6dd3f59..ee377f3 100644
30243--- a/drivers/atm/suni.c
30244+++ b/drivers/atm/suni.c
30245@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
30246
30247
30248 #define ADD_LIMITED(s,v) \
30249- atomic_add((v),&stats->s); \
30250- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
30251+ atomic_add_unchecked((v),&stats->s); \
30252+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
30253
30254
30255 static void suni_hz(unsigned long from_timer)
30256diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
30257index fc8cb07..4a80e53 100644
30258--- a/drivers/atm/uPD98402.c
30259+++ b/drivers/atm/uPD98402.c
30260@@ -41,7 +41,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
30261 struct sonet_stats tmp;
30262 int error = 0;
30263
30264- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30265+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30266 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
30267 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
30268 if (zero && !error) {
30269@@ -160,9 +160,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
30270
30271
30272 #define ADD_LIMITED(s,v) \
30273- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
30274- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
30275- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30276+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
30277+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
30278+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30279
30280
30281 static void stat_event(struct atm_dev *dev)
30282@@ -193,7 +193,7 @@ static void uPD98402_int(struct atm_dev *dev)
30283 if (reason & uPD98402_INT_PFM) stat_event(dev);
30284 if (reason & uPD98402_INT_PCO) {
30285 (void) GET(PCOCR); /* clear interrupt cause */
30286- atomic_add(GET(HECCT),
30287+ atomic_add_unchecked(GET(HECCT),
30288 &PRIV(dev)->sonet_stats.uncorr_hcs);
30289 }
30290 if ((reason & uPD98402_INT_RFO) &&
30291@@ -221,9 +221,9 @@ static int uPD98402_start(struct atm_dev *dev)
30292 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
30293 uPD98402_INT_LOS),PIMR); /* enable them */
30294 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
30295- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30296- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
30297- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
30298+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30299+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
30300+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
30301 return 0;
30302 }
30303
30304diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
30305index 2e9635b..32927b4 100644
30306--- a/drivers/atm/zatm.c
30307+++ b/drivers/atm/zatm.c
30308@@ -458,7 +458,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30309 }
30310 if (!size) {
30311 dev_kfree_skb_irq(skb);
30312- if (vcc) atomic_inc(&vcc->stats->rx_err);
30313+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
30314 continue;
30315 }
30316 if (!atm_charge(vcc,skb->truesize)) {
30317@@ -468,7 +468,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30318 skb->len = size;
30319 ATM_SKB(skb)->vcc = vcc;
30320 vcc->push(vcc,skb);
30321- atomic_inc(&vcc->stats->rx);
30322+ atomic_inc_unchecked(&vcc->stats->rx);
30323 }
30324 zout(pos & 0xffff,MTA(mbx));
30325 #if 0 /* probably a stupid idea */
30326@@ -732,7 +732,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
30327 skb_queue_head(&zatm_vcc->backlog,skb);
30328 break;
30329 }
30330- atomic_inc(&vcc->stats->tx);
30331+ atomic_inc_unchecked(&vcc->stats->tx);
30332 wake_up(&zatm_vcc->tx_wait);
30333 }
30334
30335diff --git a/drivers/base/bus.c b/drivers/base/bus.c
30336index 63c143e..fece183 100644
30337--- a/drivers/base/bus.c
30338+++ b/drivers/base/bus.c
30339@@ -70,7 +70,7 @@ static ssize_t drv_attr_store(struct kobject *kobj, struct attribute *attr,
30340 return ret;
30341 }
30342
30343-static struct sysfs_ops driver_sysfs_ops = {
30344+static const struct sysfs_ops driver_sysfs_ops = {
30345 .show = drv_attr_show,
30346 .store = drv_attr_store,
30347 };
30348@@ -115,7 +115,7 @@ static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr,
30349 return ret;
30350 }
30351
30352-static struct sysfs_ops bus_sysfs_ops = {
30353+static const struct sysfs_ops bus_sysfs_ops = {
30354 .show = bus_attr_show,
30355 .store = bus_attr_store,
30356 };
30357@@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
30358 return 0;
30359 }
30360
30361-static struct kset_uevent_ops bus_uevent_ops = {
30362+static const struct kset_uevent_ops bus_uevent_ops = {
30363 .filter = bus_uevent_filter,
30364 };
30365
30366diff --git a/drivers/base/class.c b/drivers/base/class.c
30367index 6e2c3b0..cb61871 100644
30368--- a/drivers/base/class.c
30369+++ b/drivers/base/class.c
30370@@ -63,7 +63,7 @@ static void class_release(struct kobject *kobj)
30371 kfree(cp);
30372 }
30373
30374-static struct sysfs_ops class_sysfs_ops = {
30375+static const struct sysfs_ops class_sysfs_ops = {
30376 .show = class_attr_show,
30377 .store = class_attr_store,
30378 };
30379diff --git a/drivers/base/core.c b/drivers/base/core.c
30380index f33d768..a9358d0 100644
30381--- a/drivers/base/core.c
30382+++ b/drivers/base/core.c
30383@@ -100,7 +100,7 @@ static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
30384 return ret;
30385 }
30386
30387-static struct sysfs_ops dev_sysfs_ops = {
30388+static const struct sysfs_ops dev_sysfs_ops = {
30389 .show = dev_attr_show,
30390 .store = dev_attr_store,
30391 };
30392@@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
30393 return retval;
30394 }
30395
30396-static struct kset_uevent_ops device_uevent_ops = {
30397+static const struct kset_uevent_ops device_uevent_ops = {
30398 .filter = dev_uevent_filter,
30399 .name = dev_uevent_name,
30400 .uevent = dev_uevent,
30401diff --git a/drivers/base/memory.c b/drivers/base/memory.c
30402index 989429c..2272b00 100644
30403--- a/drivers/base/memory.c
30404+++ b/drivers/base/memory.c
30405@@ -44,7 +44,7 @@ static int memory_uevent(struct kset *kset, struct kobject *obj, struct kobj_uev
30406 return retval;
30407 }
30408
30409-static struct kset_uevent_ops memory_uevent_ops = {
30410+static const struct kset_uevent_ops memory_uevent_ops = {
30411 .name = memory_uevent_name,
30412 .uevent = memory_uevent,
30413 };
30414diff --git a/drivers/base/sys.c b/drivers/base/sys.c
30415index 3f202f7..61c4a6f 100644
30416--- a/drivers/base/sys.c
30417+++ b/drivers/base/sys.c
30418@@ -54,7 +54,7 @@ sysdev_store(struct kobject *kobj, struct attribute *attr,
30419 return -EIO;
30420 }
30421
30422-static struct sysfs_ops sysfs_ops = {
30423+static const struct sysfs_ops sysfs_ops = {
30424 .show = sysdev_show,
30425 .store = sysdev_store,
30426 };
30427@@ -104,7 +104,7 @@ static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr,
30428 return -EIO;
30429 }
30430
30431-static struct sysfs_ops sysfs_class_ops = {
30432+static const struct sysfs_ops sysfs_class_ops = {
30433 .show = sysdev_class_show,
30434 .store = sysdev_class_store,
30435 };
30436diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
30437index eb4fa19..1954777 100644
30438--- a/drivers/block/DAC960.c
30439+++ b/drivers/block/DAC960.c
30440@@ -1973,6 +1973,8 @@ static bool DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
30441 unsigned long flags;
30442 int Channel, TargetID;
30443
30444+ pax_track_stack();
30445+
30446 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
30447 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
30448 sizeof(DAC960_SCSI_Inquiry_T) +
30449diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
30450index 68b90d9..7e2e3f3 100644
30451--- a/drivers/block/cciss.c
30452+++ b/drivers/block/cciss.c
30453@@ -1011,6 +1011,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
30454 int err;
30455 u32 cp;
30456
30457+ memset(&arg64, 0, sizeof(arg64));
30458+
30459 err = 0;
30460 err |=
30461 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
30462@@ -2852,7 +2854,7 @@ static unsigned long pollcomplete(int ctlr)
30463 /* Wait (up to 20 seconds) for a command to complete */
30464
30465 for (i = 20 * HZ; i > 0; i--) {
30466- done = hba[ctlr]->access.command_completed(hba[ctlr]);
30467+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
30468 if (done == FIFO_EMPTY)
30469 schedule_timeout_uninterruptible(1);
30470 else
30471@@ -2876,7 +2878,7 @@ static int sendcmd_core(ctlr_info_t *h, CommandList_struct *c)
30472 resend_cmd1:
30473
30474 /* Disable interrupt on the board. */
30475- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30476+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30477
30478 /* Make sure there is room in the command FIFO */
30479 /* Actually it should be completely empty at this time */
30480@@ -2884,13 +2886,13 @@ resend_cmd1:
30481 /* tape side of the driver. */
30482 for (i = 200000; i > 0; i--) {
30483 /* if fifo isn't full go */
30484- if (!(h->access.fifo_full(h)))
30485+ if (!(h->access->fifo_full(h)))
30486 break;
30487 udelay(10);
30488 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
30489 " waiting!\n", h->ctlr);
30490 }
30491- h->access.submit_command(h, c); /* Send the cmd */
30492+ h->access->submit_command(h, c); /* Send the cmd */
30493 do {
30494 complete = pollcomplete(h->ctlr);
30495
30496@@ -3023,7 +3025,7 @@ static void start_io(ctlr_info_t *h)
30497 while (!hlist_empty(&h->reqQ)) {
30498 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
30499 /* can't do anything if fifo is full */
30500- if ((h->access.fifo_full(h))) {
30501+ if ((h->access->fifo_full(h))) {
30502 printk(KERN_WARNING "cciss: fifo full\n");
30503 break;
30504 }
30505@@ -3033,7 +3035,7 @@ static void start_io(ctlr_info_t *h)
30506 h->Qdepth--;
30507
30508 /* Tell the controller execute command */
30509- h->access.submit_command(h, c);
30510+ h->access->submit_command(h, c);
30511
30512 /* Put job onto the completed Q */
30513 addQ(&h->cmpQ, c);
30514@@ -3393,17 +3395,17 @@ startio:
30515
30516 static inline unsigned long get_next_completion(ctlr_info_t *h)
30517 {
30518- return h->access.command_completed(h);
30519+ return h->access->command_completed(h);
30520 }
30521
30522 static inline int interrupt_pending(ctlr_info_t *h)
30523 {
30524- return h->access.intr_pending(h);
30525+ return h->access->intr_pending(h);
30526 }
30527
30528 static inline long interrupt_not_for_us(ctlr_info_t *h)
30529 {
30530- return (((h->access.intr_pending(h) == 0) ||
30531+ return (((h->access->intr_pending(h) == 0) ||
30532 (h->interrupts_enabled == 0)));
30533 }
30534
30535@@ -3892,7 +3894,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
30536 */
30537 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
30538 c->product_name = products[prod_index].product_name;
30539- c->access = *(products[prod_index].access);
30540+ c->access = products[prod_index].access;
30541 c->nr_cmds = c->max_commands - 4;
30542 if ((readb(&c->cfgtable->Signature[0]) != 'C') ||
30543 (readb(&c->cfgtable->Signature[1]) != 'I') ||
30544@@ -4291,7 +4293,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
30545 }
30546
30547 /* make sure the board interrupts are off */
30548- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
30549+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_OFF);
30550 if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
30551 IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) {
30552 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
30553@@ -4341,7 +4343,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
30554 cciss_scsi_setup(i);
30555
30556 /* Turn the interrupts on so we can service requests */
30557- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
30558+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_ON);
30559
30560 /* Get the firmware version */
30561 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
30562diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
30563index 04d6bf8..36e712d 100644
30564--- a/drivers/block/cciss.h
30565+++ b/drivers/block/cciss.h
30566@@ -90,7 +90,7 @@ struct ctlr_info
30567 // information about each logical volume
30568 drive_info_struct *drv[CISS_MAX_LUN];
30569
30570- struct access_method access;
30571+ struct access_method *access;
30572
30573 /* queue and queue Info */
30574 struct hlist_head reqQ;
30575diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
30576index 6422651..bb1bdef 100644
30577--- a/drivers/block/cpqarray.c
30578+++ b/drivers/block/cpqarray.c
30579@@ -402,7 +402,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30580 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
30581 goto Enomem4;
30582 }
30583- hba[i]->access.set_intr_mask(hba[i], 0);
30584+ hba[i]->access->set_intr_mask(hba[i], 0);
30585 if (request_irq(hba[i]->intr, do_ida_intr,
30586 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
30587 {
30588@@ -460,7 +460,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30589 add_timer(&hba[i]->timer);
30590
30591 /* Enable IRQ now that spinlock and rate limit timer are set up */
30592- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30593+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30594
30595 for(j=0; j<NWD; j++) {
30596 struct gendisk *disk = ida_gendisk[i][j];
30597@@ -695,7 +695,7 @@ DBGINFO(
30598 for(i=0; i<NR_PRODUCTS; i++) {
30599 if (board_id == products[i].board_id) {
30600 c->product_name = products[i].product_name;
30601- c->access = *(products[i].access);
30602+ c->access = products[i].access;
30603 break;
30604 }
30605 }
30606@@ -793,7 +793,7 @@ static int __init cpqarray_eisa_detect(void)
30607 hba[ctlr]->intr = intr;
30608 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
30609 hba[ctlr]->product_name = products[j].product_name;
30610- hba[ctlr]->access = *(products[j].access);
30611+ hba[ctlr]->access = products[j].access;
30612 hba[ctlr]->ctlr = ctlr;
30613 hba[ctlr]->board_id = board_id;
30614 hba[ctlr]->pci_dev = NULL; /* not PCI */
30615@@ -896,6 +896,8 @@ static void do_ida_request(struct request_queue *q)
30616 struct scatterlist tmp_sg[SG_MAX];
30617 int i, dir, seg;
30618
30619+ pax_track_stack();
30620+
30621 if (blk_queue_plugged(q))
30622 goto startio;
30623
30624@@ -968,7 +970,7 @@ static void start_io(ctlr_info_t *h)
30625
30626 while((c = h->reqQ) != NULL) {
30627 /* Can't do anything if we're busy */
30628- if (h->access.fifo_full(h) == 0)
30629+ if (h->access->fifo_full(h) == 0)
30630 return;
30631
30632 /* Get the first entry from the request Q */
30633@@ -976,7 +978,7 @@ static void start_io(ctlr_info_t *h)
30634 h->Qdepth--;
30635
30636 /* Tell the controller to do our bidding */
30637- h->access.submit_command(h, c);
30638+ h->access->submit_command(h, c);
30639
30640 /* Get onto the completion Q */
30641 addQ(&h->cmpQ, c);
30642@@ -1038,7 +1040,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30643 unsigned long flags;
30644 __u32 a,a1;
30645
30646- istat = h->access.intr_pending(h);
30647+ istat = h->access->intr_pending(h);
30648 /* Is this interrupt for us? */
30649 if (istat == 0)
30650 return IRQ_NONE;
30651@@ -1049,7 +1051,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30652 */
30653 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
30654 if (istat & FIFO_NOT_EMPTY) {
30655- while((a = h->access.command_completed(h))) {
30656+ while((a = h->access->command_completed(h))) {
30657 a1 = a; a &= ~3;
30658 if ((c = h->cmpQ) == NULL)
30659 {
30660@@ -1434,11 +1436,11 @@ static int sendcmd(
30661 /*
30662 * Disable interrupt
30663 */
30664- info_p->access.set_intr_mask(info_p, 0);
30665+ info_p->access->set_intr_mask(info_p, 0);
30666 /* Make sure there is room in the command FIFO */
30667 /* Actually it should be completely empty at this time. */
30668 for (i = 200000; i > 0; i--) {
30669- temp = info_p->access.fifo_full(info_p);
30670+ temp = info_p->access->fifo_full(info_p);
30671 if (temp != 0) {
30672 break;
30673 }
30674@@ -1451,7 +1453,7 @@ DBG(
30675 /*
30676 * Send the cmd
30677 */
30678- info_p->access.submit_command(info_p, c);
30679+ info_p->access->submit_command(info_p, c);
30680 complete = pollcomplete(ctlr);
30681
30682 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
30683@@ -1534,9 +1536,9 @@ static int revalidate_allvol(ctlr_info_t *host)
30684 * we check the new geometry. Then turn interrupts back on when
30685 * we're done.
30686 */
30687- host->access.set_intr_mask(host, 0);
30688+ host->access->set_intr_mask(host, 0);
30689 getgeometry(ctlr);
30690- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
30691+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
30692
30693 for(i=0; i<NWD; i++) {
30694 struct gendisk *disk = ida_gendisk[ctlr][i];
30695@@ -1576,7 +1578,7 @@ static int pollcomplete(int ctlr)
30696 /* Wait (up to 2 seconds) for a command to complete */
30697
30698 for (i = 200000; i > 0; i--) {
30699- done = hba[ctlr]->access.command_completed(hba[ctlr]);
30700+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
30701 if (done == 0) {
30702 udelay(10); /* a short fixed delay */
30703 } else
30704diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
30705index be73e9d..7fbf140 100644
30706--- a/drivers/block/cpqarray.h
30707+++ b/drivers/block/cpqarray.h
30708@@ -99,7 +99,7 @@ struct ctlr_info {
30709 drv_info_t drv[NWD];
30710 struct proc_dir_entry *proc;
30711
30712- struct access_method access;
30713+ struct access_method *access;
30714
30715 cmdlist_t *reqQ;
30716 cmdlist_t *cmpQ;
30717diff --git a/drivers/block/loop.c b/drivers/block/loop.c
30718index 8ec2d70..2804b30 100644
30719--- a/drivers/block/loop.c
30720+++ b/drivers/block/loop.c
30721@@ -282,7 +282,7 @@ static int __do_lo_send_write(struct file *file,
30722 mm_segment_t old_fs = get_fs();
30723
30724 set_fs(get_ds());
30725- bw = file->f_op->write(file, buf, len, &pos);
30726+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
30727 set_fs(old_fs);
30728 if (likely(bw == len))
30729 return 0;
30730diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
30731index 26ada47..083c480 100644
30732--- a/drivers/block/nbd.c
30733+++ b/drivers/block/nbd.c
30734@@ -155,6 +155,8 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size,
30735 struct kvec iov;
30736 sigset_t blocked, oldset;
30737
30738+ pax_track_stack();
30739+
30740 if (unlikely(!sock)) {
30741 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
30742 lo->disk->disk_name, (send ? "send" : "recv"));
30743@@ -569,6 +571,8 @@ static void do_nbd_request(struct request_queue *q)
30744 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
30745 unsigned int cmd, unsigned long arg)
30746 {
30747+ pax_track_stack();
30748+
30749 switch (cmd) {
30750 case NBD_DISCONNECT: {
30751 struct request sreq;
30752diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
30753index a5d585d..d087be3 100644
30754--- a/drivers/block/pktcdvd.c
30755+++ b/drivers/block/pktcdvd.c
30756@@ -284,7 +284,7 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
30757 return len;
30758 }
30759
30760-static struct sysfs_ops kobj_pkt_ops = {
30761+static const struct sysfs_ops kobj_pkt_ops = {
30762 .show = kobj_pkt_show,
30763 .store = kobj_pkt_store
30764 };
30765diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
30766index 6aad99e..89cd142 100644
30767--- a/drivers/char/Kconfig
30768+++ b/drivers/char/Kconfig
30769@@ -90,7 +90,8 @@ config VT_HW_CONSOLE_BINDING
30770
30771 config DEVKMEM
30772 bool "/dev/kmem virtual device support"
30773- default y
30774+ default n
30775+ depends on !GRKERNSEC_KMEM
30776 help
30777 Say Y here if you want to support the /dev/kmem device. The
30778 /dev/kmem device is rarely used, but can be used for certain
30779@@ -1114,6 +1115,7 @@ config DEVPORT
30780 bool
30781 depends on !M68K
30782 depends on ISA || PCI
30783+ depends on !GRKERNSEC_KMEM
30784 default y
30785
30786 source "drivers/s390/char/Kconfig"
30787diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
30788index a96f319..a778a5b 100644
30789--- a/drivers/char/agp/frontend.c
30790+++ b/drivers/char/agp/frontend.c
30791@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
30792 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
30793 return -EFAULT;
30794
30795- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
30796+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
30797 return -EFAULT;
30798
30799 client = agp_find_client_by_pid(reserve.pid);
30800diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
30801index d8cff90..9628e70 100644
30802--- a/drivers/char/briq_panel.c
30803+++ b/drivers/char/briq_panel.c
30804@@ -10,6 +10,7 @@
30805 #include <linux/types.h>
30806 #include <linux/errno.h>
30807 #include <linux/tty.h>
30808+#include <linux/mutex.h>
30809 #include <linux/timer.h>
30810 #include <linux/kernel.h>
30811 #include <linux/wait.h>
30812@@ -36,6 +37,7 @@ static int vfd_is_open;
30813 static unsigned char vfd[40];
30814 static int vfd_cursor;
30815 static unsigned char ledpb, led;
30816+static DEFINE_MUTEX(vfd_mutex);
30817
30818 static void update_vfd(void)
30819 {
30820@@ -142,12 +144,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
30821 if (!vfd_is_open)
30822 return -EBUSY;
30823
30824+ mutex_lock(&vfd_mutex);
30825 for (;;) {
30826 char c;
30827 if (!indx)
30828 break;
30829- if (get_user(c, buf))
30830+ if (get_user(c, buf)) {
30831+ mutex_unlock(&vfd_mutex);
30832 return -EFAULT;
30833+ }
30834 if (esc) {
30835 set_led(c);
30836 esc = 0;
30837@@ -177,6 +182,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
30838 buf++;
30839 }
30840 update_vfd();
30841+ mutex_unlock(&vfd_mutex);
30842
30843 return len;
30844 }
30845diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
30846index 31e7c91..161afc0 100644
30847--- a/drivers/char/genrtc.c
30848+++ b/drivers/char/genrtc.c
30849@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct inode *inode, struct file *file,
30850 switch (cmd) {
30851
30852 case RTC_PLL_GET:
30853+ memset(&pll, 0, sizeof(pll));
30854 if (get_rtc_pll(&pll))
30855 return -EINVAL;
30856 else
30857diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
30858index 006466d..a2bb21c 100644
30859--- a/drivers/char/hpet.c
30860+++ b/drivers/char/hpet.c
30861@@ -430,7 +430,7 @@ static int hpet_release(struct inode *inode, struct file *file)
30862 return 0;
30863 }
30864
30865-static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);
30866+static int hpet_ioctl_common(struct hpet_dev *, unsigned int, unsigned long, int);
30867
30868 static int
30869 hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
30870@@ -565,7 +565,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
30871 }
30872
30873 static int
30874-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
30875+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg, int kernel)
30876 {
30877 struct hpet_timer __iomem *timer;
30878 struct hpet __iomem *hpet;
30879@@ -608,11 +608,11 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
30880 {
30881 struct hpet_info info;
30882
30883+ memset(&info, 0, sizeof(info));
30884+
30885 if (devp->hd_ireqfreq)
30886 info.hi_ireqfreq =
30887 hpet_time_div(hpetp, devp->hd_ireqfreq);
30888- else
30889- info.hi_ireqfreq = 0;
30890 info.hi_flags =
30891 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
30892 info.hi_hpet = hpetp->hp_which;
30893diff --git a/drivers/char/hvc_beat.c b/drivers/char/hvc_beat.c
30894index 0afc8b8..6913fc3 100644
30895--- a/drivers/char/hvc_beat.c
30896+++ b/drivers/char/hvc_beat.c
30897@@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t vtermno, const char *buf, int cnt)
30898 return cnt;
30899 }
30900
30901-static struct hv_ops hvc_beat_get_put_ops = {
30902+static const struct hv_ops hvc_beat_get_put_ops = {
30903 .get_chars = hvc_beat_get_chars,
30904 .put_chars = hvc_beat_put_chars,
30905 };
30906diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
30907index 98097f2..407dddc 100644
30908--- a/drivers/char/hvc_console.c
30909+++ b/drivers/char/hvc_console.c
30910@@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_index(int index)
30911 * console interfaces but can still be used as a tty device. This has to be
30912 * static because kmalloc will not work during early console init.
30913 */
30914-static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
30915+static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
30916 static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
30917 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
30918
30919@@ -249,7 +249,7 @@ static void destroy_hvc_struct(struct kref *kref)
30920 * vty adapters do NOT get an hvc_instantiate() callback since they
30921 * appear after early console init.
30922 */
30923-int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
30924+int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
30925 {
30926 struct hvc_struct *hp;
30927
30928@@ -758,7 +758,7 @@ static const struct tty_operations hvc_ops = {
30929 };
30930
30931 struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data,
30932- struct hv_ops *ops, int outbuf_size)
30933+ const struct hv_ops *ops, int outbuf_size)
30934 {
30935 struct hvc_struct *hp;
30936 int i;
30937diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h
30938index 10950ca..ed176c3 100644
30939--- a/drivers/char/hvc_console.h
30940+++ b/drivers/char/hvc_console.h
30941@@ -55,7 +55,7 @@ struct hvc_struct {
30942 int outbuf_size;
30943 int n_outbuf;
30944 uint32_t vtermno;
30945- struct hv_ops *ops;
30946+ const struct hv_ops *ops;
30947 int irq_requested;
30948 int data;
30949 struct winsize ws;
30950@@ -76,11 +76,11 @@ struct hv_ops {
30951 };
30952
30953 /* Register a vterm and a slot index for use as a console (console_init) */
30954-extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
30955+extern int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops);
30956
30957 /* register a vterm for hvc tty operation (module_init or hotplug add) */
30958 extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data,
30959- struct hv_ops *ops, int outbuf_size);
30960+ const struct hv_ops *ops, int outbuf_size);
30961 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
30962 extern int hvc_remove(struct hvc_struct *hp);
30963
30964diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
30965index 936d05b..fd02426 100644
30966--- a/drivers/char/hvc_iseries.c
30967+++ b/drivers/char/hvc_iseries.c
30968@@ -197,7 +197,7 @@ done:
30969 return sent;
30970 }
30971
30972-static struct hv_ops hvc_get_put_ops = {
30973+static const struct hv_ops hvc_get_put_ops = {
30974 .get_chars = get_chars,
30975 .put_chars = put_chars,
30976 .notifier_add = notifier_add_irq,
30977diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
30978index b0e168f..69cda2a 100644
30979--- a/drivers/char/hvc_iucv.c
30980+++ b/drivers/char/hvc_iucv.c
30981@@ -924,7 +924,7 @@ static int hvc_iucv_pm_restore_thaw(struct device *dev)
30982
30983
30984 /* HVC operations */
30985-static struct hv_ops hvc_iucv_ops = {
30986+static const struct hv_ops hvc_iucv_ops = {
30987 .get_chars = hvc_iucv_get_chars,
30988 .put_chars = hvc_iucv_put_chars,
30989 .notifier_add = hvc_iucv_notifier_add,
30990diff --git a/drivers/char/hvc_rtas.c b/drivers/char/hvc_rtas.c
30991index 88590d0..61c4a61 100644
30992--- a/drivers/char/hvc_rtas.c
30993+++ b/drivers/char/hvc_rtas.c
30994@@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count)
30995 return i;
30996 }
30997
30998-static struct hv_ops hvc_rtas_get_put_ops = {
30999+static const struct hv_ops hvc_rtas_get_put_ops = {
31000 .get_chars = hvc_rtas_read_console,
31001 .put_chars = hvc_rtas_write_console,
31002 };
31003diff --git a/drivers/char/hvc_udbg.c b/drivers/char/hvc_udbg.c
31004index bd63ba8..b0957e6 100644
31005--- a/drivers/char/hvc_udbg.c
31006+++ b/drivers/char/hvc_udbg.c
31007@@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno, char *buf, int count)
31008 return i;
31009 }
31010
31011-static struct hv_ops hvc_udbg_ops = {
31012+static const struct hv_ops hvc_udbg_ops = {
31013 .get_chars = hvc_udbg_get,
31014 .put_chars = hvc_udbg_put,
31015 };
31016diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
31017index 10be343..27370e9 100644
31018--- a/drivers/char/hvc_vio.c
31019+++ b/drivers/char/hvc_vio.c
31020@@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
31021 return got;
31022 }
31023
31024-static struct hv_ops hvc_get_put_ops = {
31025+static const struct hv_ops hvc_get_put_ops = {
31026 .get_chars = filtered_get_chars,
31027 .put_chars = hvc_put_chars,
31028 .notifier_add = notifier_add_irq,
31029diff --git a/drivers/char/hvc_xen.c b/drivers/char/hvc_xen.c
31030index a6ee32b..94f8c26 100644
31031--- a/drivers/char/hvc_xen.c
31032+++ b/drivers/char/hvc_xen.c
31033@@ -120,7 +120,7 @@ static int read_console(uint32_t vtermno, char *buf, int len)
31034 return recv;
31035 }
31036
31037-static struct hv_ops hvc_ops = {
31038+static const struct hv_ops hvc_ops = {
31039 .get_chars = read_console,
31040 .put_chars = write_console,
31041 .notifier_add = notifier_add_irq,
31042diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
31043index 266b858..f3ee0bb 100644
31044--- a/drivers/char/hvcs.c
31045+++ b/drivers/char/hvcs.c
31046@@ -82,6 +82,7 @@
31047 #include <asm/hvcserver.h>
31048 #include <asm/uaccess.h>
31049 #include <asm/vio.h>
31050+#include <asm/local.h>
31051
31052 /*
31053 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
31054@@ -269,7 +270,7 @@ struct hvcs_struct {
31055 unsigned int index;
31056
31057 struct tty_struct *tty;
31058- int open_count;
31059+ local_t open_count;
31060
31061 /*
31062 * Used to tell the driver kernel_thread what operations need to take
31063@@ -419,7 +420,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
31064
31065 spin_lock_irqsave(&hvcsd->lock, flags);
31066
31067- if (hvcsd->open_count > 0) {
31068+ if (local_read(&hvcsd->open_count) > 0) {
31069 spin_unlock_irqrestore(&hvcsd->lock, flags);
31070 printk(KERN_INFO "HVCS: vterm state unchanged. "
31071 "The hvcs device node is still in use.\n");
31072@@ -1135,7 +1136,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
31073 if ((retval = hvcs_partner_connect(hvcsd)))
31074 goto error_release;
31075
31076- hvcsd->open_count = 1;
31077+ local_set(&hvcsd->open_count, 1);
31078 hvcsd->tty = tty;
31079 tty->driver_data = hvcsd;
31080
31081@@ -1169,7 +1170,7 @@ fast_open:
31082
31083 spin_lock_irqsave(&hvcsd->lock, flags);
31084 kref_get(&hvcsd->kref);
31085- hvcsd->open_count++;
31086+ local_inc(&hvcsd->open_count);
31087 hvcsd->todo_mask |= HVCS_SCHED_READ;
31088 spin_unlock_irqrestore(&hvcsd->lock, flags);
31089
31090@@ -1213,7 +1214,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
31091 hvcsd = tty->driver_data;
31092
31093 spin_lock_irqsave(&hvcsd->lock, flags);
31094- if (--hvcsd->open_count == 0) {
31095+ if (local_dec_and_test(&hvcsd->open_count)) {
31096
31097 vio_disable_interrupts(hvcsd->vdev);
31098
31099@@ -1239,10 +1240,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
31100 free_irq(irq, hvcsd);
31101 kref_put(&hvcsd->kref, destroy_hvcs_struct);
31102 return;
31103- } else if (hvcsd->open_count < 0) {
31104+ } else if (local_read(&hvcsd->open_count) < 0) {
31105 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
31106 " is missmanaged.\n",
31107- hvcsd->vdev->unit_address, hvcsd->open_count);
31108+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
31109 }
31110
31111 spin_unlock_irqrestore(&hvcsd->lock, flags);
31112@@ -1258,7 +1259,7 @@ static void hvcs_hangup(struct tty_struct * tty)
31113
31114 spin_lock_irqsave(&hvcsd->lock, flags);
31115 /* Preserve this so that we know how many kref refs to put */
31116- temp_open_count = hvcsd->open_count;
31117+ temp_open_count = local_read(&hvcsd->open_count);
31118
31119 /*
31120 * Don't kref put inside the spinlock because the destruction
31121@@ -1273,7 +1274,7 @@ static void hvcs_hangup(struct tty_struct * tty)
31122 hvcsd->tty->driver_data = NULL;
31123 hvcsd->tty = NULL;
31124
31125- hvcsd->open_count = 0;
31126+ local_set(&hvcsd->open_count, 0);
31127
31128 /* This will drop any buffered data on the floor which is OK in a hangup
31129 * scenario. */
31130@@ -1344,7 +1345,7 @@ static int hvcs_write(struct tty_struct *tty,
31131 * the middle of a write operation? This is a crummy place to do this
31132 * but we want to keep it all in the spinlock.
31133 */
31134- if (hvcsd->open_count <= 0) {
31135+ if (local_read(&hvcsd->open_count) <= 0) {
31136 spin_unlock_irqrestore(&hvcsd->lock, flags);
31137 return -ENODEV;
31138 }
31139@@ -1418,7 +1419,7 @@ static int hvcs_write_room(struct tty_struct *tty)
31140 {
31141 struct hvcs_struct *hvcsd = tty->driver_data;
31142
31143- if (!hvcsd || hvcsd->open_count <= 0)
31144+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
31145 return 0;
31146
31147 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
31148diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31149index ec5e3f8..02455ba 100644
31150--- a/drivers/char/ipmi/ipmi_msghandler.c
31151+++ b/drivers/char/ipmi/ipmi_msghandler.c
31152@@ -414,7 +414,7 @@ struct ipmi_smi {
31153 struct proc_dir_entry *proc_dir;
31154 char proc_dir_name[10];
31155
31156- atomic_t stats[IPMI_NUM_STATS];
31157+ atomic_unchecked_t stats[IPMI_NUM_STATS];
31158
31159 /*
31160 * run_to_completion duplicate of smb_info, smi_info
31161@@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31162
31163
31164 #define ipmi_inc_stat(intf, stat) \
31165- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31166+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31167 #define ipmi_get_stat(intf, stat) \
31168- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31169+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31170
31171 static int is_lan_addr(struct ipmi_addr *addr)
31172 {
31173@@ -2808,7 +2808,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31174 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31175 init_waitqueue_head(&intf->waitq);
31176 for (i = 0; i < IPMI_NUM_STATS; i++)
31177- atomic_set(&intf->stats[i], 0);
31178+ atomic_set_unchecked(&intf->stats[i], 0);
31179
31180 intf->proc_dir = NULL;
31181
31182@@ -4160,6 +4160,8 @@ static void send_panic_events(char *str)
31183 struct ipmi_smi_msg smi_msg;
31184 struct ipmi_recv_msg recv_msg;
31185
31186+ pax_track_stack();
31187+
31188 si = (struct ipmi_system_interface_addr *) &addr;
31189 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
31190 si->channel = IPMI_BMC_CHANNEL;
31191diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31192index abae8c9..8021979 100644
31193--- a/drivers/char/ipmi/ipmi_si_intf.c
31194+++ b/drivers/char/ipmi/ipmi_si_intf.c
31195@@ -277,7 +277,7 @@ struct smi_info {
31196 unsigned char slave_addr;
31197
31198 /* Counters and things for the proc filesystem. */
31199- atomic_t stats[SI_NUM_STATS];
31200+ atomic_unchecked_t stats[SI_NUM_STATS];
31201
31202 struct task_struct *thread;
31203
31204@@ -285,9 +285,9 @@ struct smi_info {
31205 };
31206
31207 #define smi_inc_stat(smi, stat) \
31208- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31209+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31210 #define smi_get_stat(smi, stat) \
31211- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31212+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31213
31214 #define SI_MAX_PARMS 4
31215
31216@@ -2931,7 +2931,7 @@ static int try_smi_init(struct smi_info *new_smi)
31217 atomic_set(&new_smi->req_events, 0);
31218 new_smi->run_to_completion = 0;
31219 for (i = 0; i < SI_NUM_STATS; i++)
31220- atomic_set(&new_smi->stats[i], 0);
31221+ atomic_set_unchecked(&new_smi->stats[i], 0);
31222
31223 new_smi->interrupt_disabled = 0;
31224 atomic_set(&new_smi->stop_operation, 0);
31225diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
31226index 402838f..55e2200 100644
31227--- a/drivers/char/istallion.c
31228+++ b/drivers/char/istallion.c
31229@@ -187,7 +187,6 @@ static struct ktermios stli_deftermios = {
31230 * re-used for each stats call.
31231 */
31232 static comstats_t stli_comstats;
31233-static combrd_t stli_brdstats;
31234 static struct asystats stli_cdkstats;
31235
31236 /*****************************************************************************/
31237@@ -4058,6 +4057,7 @@ static int stli_getbrdstats(combrd_t __user *bp)
31238 {
31239 struct stlibrd *brdp;
31240 unsigned int i;
31241+ combrd_t stli_brdstats;
31242
31243 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
31244 return -EFAULT;
31245@@ -4269,6 +4269,8 @@ static int stli_getportstruct(struct stliport __user *arg)
31246 struct stliport stli_dummyport;
31247 struct stliport *portp;
31248
31249+ pax_track_stack();
31250+
31251 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
31252 return -EFAULT;
31253 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
31254@@ -4291,6 +4293,8 @@ static int stli_getbrdstruct(struct stlibrd __user *arg)
31255 struct stlibrd stli_dummybrd;
31256 struct stlibrd *brdp;
31257
31258+ pax_track_stack();
31259+
31260 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
31261 return -EFAULT;
31262 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
31263diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
31264index 950837c..e55a288 100644
31265--- a/drivers/char/keyboard.c
31266+++ b/drivers/char/keyboard.c
31267@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
31268 kbd->kbdmode == VC_MEDIUMRAW) &&
31269 value != KVAL(K_SAK))
31270 return; /* SAK is allowed even in raw mode */
31271+
31272+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
31273+ {
31274+ void *func = fn_handler[value];
31275+ if (func == fn_show_state || func == fn_show_ptregs ||
31276+ func == fn_show_mem)
31277+ return;
31278+ }
31279+#endif
31280+
31281 fn_handler[value](vc);
31282 }
31283
31284@@ -1386,7 +1396,7 @@ static const struct input_device_id kbd_ids[] = {
31285 .evbit = { BIT_MASK(EV_SND) },
31286 },
31287
31288- { }, /* Terminating entry */
31289+ { 0 }, /* Terminating entry */
31290 };
31291
31292 MODULE_DEVICE_TABLE(input, kbd_ids);
31293diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
31294index 87c67b4..230527a 100644
31295--- a/drivers/char/mbcs.c
31296+++ b/drivers/char/mbcs.c
31297@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
31298 return 0;
31299 }
31300
31301-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
31302+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
31303 {
31304 .part_num = MBCS_PART_NUM,
31305 .mfg_num = MBCS_MFG_NUM,
31306diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31307index 1270f64..8495f49 100644
31308--- a/drivers/char/mem.c
31309+++ b/drivers/char/mem.c
31310@@ -18,6 +18,7 @@
31311 #include <linux/raw.h>
31312 #include <linux/tty.h>
31313 #include <linux/capability.h>
31314+#include <linux/security.h>
31315 #include <linux/ptrace.h>
31316 #include <linux/device.h>
31317 #include <linux/highmem.h>
31318@@ -35,6 +36,10 @@
31319 # include <linux/efi.h>
31320 #endif
31321
31322+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31323+extern struct file_operations grsec_fops;
31324+#endif
31325+
31326 static inline unsigned long size_inside_page(unsigned long start,
31327 unsigned long size)
31328 {
31329@@ -102,9 +107,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31330
31331 while (cursor < to) {
31332 if (!devmem_is_allowed(pfn)) {
31333+#ifdef CONFIG_GRKERNSEC_KMEM
31334+ gr_handle_mem_readwrite(from, to);
31335+#else
31336 printk(KERN_INFO
31337 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31338 current->comm, from, to);
31339+#endif
31340 return 0;
31341 }
31342 cursor += PAGE_SIZE;
31343@@ -112,6 +121,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31344 }
31345 return 1;
31346 }
31347+#elif defined(CONFIG_GRKERNSEC_KMEM)
31348+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31349+{
31350+ return 0;
31351+}
31352 #else
31353 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31354 {
31355@@ -155,6 +169,8 @@ static ssize_t read_mem(struct file * file, char __user * buf,
31356 #endif
31357
31358 while (count > 0) {
31359+ char *temp;
31360+
31361 /*
31362 * Handle first page in case it's not aligned
31363 */
31364@@ -177,11 +193,31 @@ static ssize_t read_mem(struct file * file, char __user * buf,
31365 if (!ptr)
31366 return -EFAULT;
31367
31368- if (copy_to_user(buf, ptr, sz)) {
31369+#ifdef CONFIG_PAX_USERCOPY
31370+ temp = kmalloc(sz, GFP_KERNEL);
31371+ if (!temp) {
31372+ unxlate_dev_mem_ptr(p, ptr);
31373+ return -ENOMEM;
31374+ }
31375+ memcpy(temp, ptr, sz);
31376+#else
31377+ temp = ptr;
31378+#endif
31379+
31380+ if (copy_to_user(buf, temp, sz)) {
31381+
31382+#ifdef CONFIG_PAX_USERCOPY
31383+ kfree(temp);
31384+#endif
31385+
31386 unxlate_dev_mem_ptr(p, ptr);
31387 return -EFAULT;
31388 }
31389
31390+#ifdef CONFIG_PAX_USERCOPY
31391+ kfree(temp);
31392+#endif
31393+
31394 unxlate_dev_mem_ptr(p, ptr);
31395
31396 buf += sz;
31397@@ -419,9 +455,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31398 size_t count, loff_t *ppos)
31399 {
31400 unsigned long p = *ppos;
31401- ssize_t low_count, read, sz;
31402+ ssize_t low_count, read, sz, err = 0;
31403 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31404- int err = 0;
31405
31406 read = 0;
31407 if (p < (unsigned long) high_memory) {
31408@@ -444,6 +479,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31409 }
31410 #endif
31411 while (low_count > 0) {
31412+ char *temp;
31413+
31414 sz = size_inside_page(p, low_count);
31415
31416 /*
31417@@ -453,7 +490,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31418 */
31419 kbuf = xlate_dev_kmem_ptr((char *)p);
31420
31421- if (copy_to_user(buf, kbuf, sz))
31422+#ifdef CONFIG_PAX_USERCOPY
31423+ temp = kmalloc(sz, GFP_KERNEL);
31424+ if (!temp)
31425+ return -ENOMEM;
31426+ memcpy(temp, kbuf, sz);
31427+#else
31428+ temp = kbuf;
31429+#endif
31430+
31431+ err = copy_to_user(buf, temp, sz);
31432+
31433+#ifdef CONFIG_PAX_USERCOPY
31434+ kfree(temp);
31435+#endif
31436+
31437+ if (err)
31438 return -EFAULT;
31439 buf += sz;
31440 p += sz;
31441@@ -889,6 +941,9 @@ static const struct memdev {
31442 #ifdef CONFIG_CRASH_DUMP
31443 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31444 #endif
31445+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31446+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31447+#endif
31448 };
31449
31450 static int memory_open(struct inode *inode, struct file *filp)
31451diff --git a/drivers/char/pcmcia/ipwireless/tty.c b/drivers/char/pcmcia/ipwireless/tty.c
31452index 674b3ab..a8d1970 100644
31453--- a/drivers/char/pcmcia/ipwireless/tty.c
31454+++ b/drivers/char/pcmcia/ipwireless/tty.c
31455@@ -29,6 +29,7 @@
31456 #include <linux/tty_driver.h>
31457 #include <linux/tty_flip.h>
31458 #include <linux/uaccess.h>
31459+#include <asm/local.h>
31460
31461 #include "tty.h"
31462 #include "network.h"
31463@@ -51,7 +52,7 @@ struct ipw_tty {
31464 int tty_type;
31465 struct ipw_network *network;
31466 struct tty_struct *linux_tty;
31467- int open_count;
31468+ local_t open_count;
31469 unsigned int control_lines;
31470 struct mutex ipw_tty_mutex;
31471 int tx_bytes_queued;
31472@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
31473 mutex_unlock(&tty->ipw_tty_mutex);
31474 return -ENODEV;
31475 }
31476- if (tty->open_count == 0)
31477+ if (local_read(&tty->open_count) == 0)
31478 tty->tx_bytes_queued = 0;
31479
31480- tty->open_count++;
31481+ local_inc(&tty->open_count);
31482
31483 tty->linux_tty = linux_tty;
31484 linux_tty->driver_data = tty;
31485@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
31486
31487 static void do_ipw_close(struct ipw_tty *tty)
31488 {
31489- tty->open_count--;
31490-
31491- if (tty->open_count == 0) {
31492+ if (local_dec_return(&tty->open_count) == 0) {
31493 struct tty_struct *linux_tty = tty->linux_tty;
31494
31495 if (linux_tty != NULL) {
31496@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
31497 return;
31498
31499 mutex_lock(&tty->ipw_tty_mutex);
31500- if (tty->open_count == 0) {
31501+ if (local_read(&tty->open_count) == 0) {
31502 mutex_unlock(&tty->ipw_tty_mutex);
31503 return;
31504 }
31505@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
31506 return;
31507 }
31508
31509- if (!tty->open_count) {
31510+ if (!local_read(&tty->open_count)) {
31511 mutex_unlock(&tty->ipw_tty_mutex);
31512 return;
31513 }
31514@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
31515 return -ENODEV;
31516
31517 mutex_lock(&tty->ipw_tty_mutex);
31518- if (!tty->open_count) {
31519+ if (!local_read(&tty->open_count)) {
31520 mutex_unlock(&tty->ipw_tty_mutex);
31521 return -EINVAL;
31522 }
31523@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
31524 if (!tty)
31525 return -ENODEV;
31526
31527- if (!tty->open_count)
31528+ if (!local_read(&tty->open_count))
31529 return -EINVAL;
31530
31531 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
31532@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
31533 if (!tty)
31534 return 0;
31535
31536- if (!tty->open_count)
31537+ if (!local_read(&tty->open_count))
31538 return 0;
31539
31540 return tty->tx_bytes_queued;
31541@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty, struct file *file)
31542 if (!tty)
31543 return -ENODEV;
31544
31545- if (!tty->open_count)
31546+ if (!local_read(&tty->open_count))
31547 return -EINVAL;
31548
31549 return get_control_lines(tty);
31550@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty, struct file *file,
31551 if (!tty)
31552 return -ENODEV;
31553
31554- if (!tty->open_count)
31555+ if (!local_read(&tty->open_count))
31556 return -EINVAL;
31557
31558 return set_control_lines(tty, set, clear);
31559@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
31560 if (!tty)
31561 return -ENODEV;
31562
31563- if (!tty->open_count)
31564+ if (!local_read(&tty->open_count))
31565 return -EINVAL;
31566
31567 /* FIXME: Exactly how is the tty object locked here .. */
31568@@ -591,7 +590,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
31569 against a parallel ioctl etc */
31570 mutex_lock(&ttyj->ipw_tty_mutex);
31571 }
31572- while (ttyj->open_count)
31573+ while (local_read(&ttyj->open_count))
31574 do_ipw_close(ttyj);
31575 ipwireless_disassociate_network_ttys(network,
31576 ttyj->channel_idx);
31577diff --git a/drivers/char/pty.c b/drivers/char/pty.c
31578index 62f282e..e45c45c 100644
31579--- a/drivers/char/pty.c
31580+++ b/drivers/char/pty.c
31581@@ -736,8 +736,10 @@ static void __init unix98_pty_init(void)
31582 register_sysctl_table(pty_root_table);
31583
31584 /* Now create the /dev/ptmx special device */
31585+ pax_open_kernel();
31586 tty_default_fops(&ptmx_fops);
31587- ptmx_fops.open = ptmx_open;
31588+ *(void **)&ptmx_fops.open = ptmx_open;
31589+ pax_close_kernel();
31590
31591 cdev_init(&ptmx_cdev, &ptmx_fops);
31592 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
31593diff --git a/drivers/char/random.c b/drivers/char/random.c
31594index 3a19e2d..6ed09d3 100644
31595--- a/drivers/char/random.c
31596+++ b/drivers/char/random.c
31597@@ -254,8 +254,13 @@
31598 /*
31599 * Configuration information
31600 */
31601+#ifdef CONFIG_GRKERNSEC_RANDNET
31602+#define INPUT_POOL_WORDS 512
31603+#define OUTPUT_POOL_WORDS 128
31604+#else
31605 #define INPUT_POOL_WORDS 128
31606 #define OUTPUT_POOL_WORDS 32
31607+#endif
31608 #define SEC_XFER_SIZE 512
31609
31610 /*
31611@@ -292,10 +297,17 @@ static struct poolinfo {
31612 int poolwords;
31613 int tap1, tap2, tap3, tap4, tap5;
31614 } poolinfo_table[] = {
31615+#ifdef CONFIG_GRKERNSEC_RANDNET
31616+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
31617+ { 512, 411, 308, 208, 104, 1 },
31618+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
31619+ { 128, 103, 76, 51, 25, 1 },
31620+#else
31621 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
31622 { 128, 103, 76, 51, 25, 1 },
31623 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
31624 { 32, 26, 20, 14, 7, 1 },
31625+#endif
31626 #if 0
31627 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
31628 { 2048, 1638, 1231, 819, 411, 1 },
31629@@ -1209,7 +1221,7 @@ EXPORT_SYMBOL(generate_random_uuid);
31630 #include <linux/sysctl.h>
31631
31632 static int min_read_thresh = 8, min_write_thresh;
31633-static int max_read_thresh = INPUT_POOL_WORDS * 32;
31634+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
31635 static int max_write_thresh = INPUT_POOL_WORDS * 32;
31636 static char sysctl_bootid[16];
31637
31638diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
31639index 0e29a23..0efc2c2 100644
31640--- a/drivers/char/rocket.c
31641+++ b/drivers/char/rocket.c
31642@@ -1266,6 +1266,8 @@ static int get_ports(struct r_port *info, struct rocket_ports __user *retports)
31643 struct rocket_ports tmp;
31644 int board;
31645
31646+ pax_track_stack();
31647+
31648 if (!retports)
31649 return -EFAULT;
31650 memset(&tmp, 0, sizeof (tmp));
31651diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
31652index 8c262aa..4d3b058 100644
31653--- a/drivers/char/sonypi.c
31654+++ b/drivers/char/sonypi.c
31655@@ -55,6 +55,7 @@
31656 #include <asm/uaccess.h>
31657 #include <asm/io.h>
31658 #include <asm/system.h>
31659+#include <asm/local.h>
31660
31661 #include <linux/sonypi.h>
31662
31663@@ -491,7 +492,7 @@ static struct sonypi_device {
31664 spinlock_t fifo_lock;
31665 wait_queue_head_t fifo_proc_list;
31666 struct fasync_struct *fifo_async;
31667- int open_count;
31668+ local_t open_count;
31669 int model;
31670 struct input_dev *input_jog_dev;
31671 struct input_dev *input_key_dev;
31672@@ -895,7 +896,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
31673 static int sonypi_misc_release(struct inode *inode, struct file *file)
31674 {
31675 mutex_lock(&sonypi_device.lock);
31676- sonypi_device.open_count--;
31677+ local_dec(&sonypi_device.open_count);
31678 mutex_unlock(&sonypi_device.lock);
31679 return 0;
31680 }
31681@@ -905,9 +906,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
31682 lock_kernel();
31683 mutex_lock(&sonypi_device.lock);
31684 /* Flush input queue on first open */
31685- if (!sonypi_device.open_count)
31686+ if (!local_read(&sonypi_device.open_count))
31687 kfifo_reset(sonypi_device.fifo);
31688- sonypi_device.open_count++;
31689+ local_inc(&sonypi_device.open_count);
31690 mutex_unlock(&sonypi_device.lock);
31691 unlock_kernel();
31692 return 0;
31693diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
31694index db6dcfa..13834cb 100644
31695--- a/drivers/char/stallion.c
31696+++ b/drivers/char/stallion.c
31697@@ -2448,6 +2448,8 @@ static int stl_getportstruct(struct stlport __user *arg)
31698 struct stlport stl_dummyport;
31699 struct stlport *portp;
31700
31701+ pax_track_stack();
31702+
31703 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
31704 return -EFAULT;
31705 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
31706diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
31707index a0789f6..cea3902 100644
31708--- a/drivers/char/tpm/tpm.c
31709+++ b/drivers/char/tpm/tpm.c
31710@@ -405,7 +405,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
31711 chip->vendor.req_complete_val)
31712 goto out_recv;
31713
31714- if ((status == chip->vendor.req_canceled)) {
31715+ if (status == chip->vendor.req_canceled) {
31716 dev_err(chip->dev, "Operation Canceled\n");
31717 rc = -ECANCELED;
31718 goto out;
31719@@ -824,6 +824,8 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
31720
31721 struct tpm_chip *chip = dev_get_drvdata(dev);
31722
31723+ pax_track_stack();
31724+
31725 tpm_cmd.header.in = tpm_readpubek_header;
31726 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
31727 "attempting to read the PUBEK");
31728diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
31729index bf2170f..ce8cab9 100644
31730--- a/drivers/char/tpm/tpm_bios.c
31731+++ b/drivers/char/tpm/tpm_bios.c
31732@@ -172,7 +172,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
31733 event = addr;
31734
31735 if ((event->event_type == 0 && event->event_size == 0) ||
31736- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
31737+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
31738 return NULL;
31739
31740 return addr;
31741@@ -197,7 +197,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
31742 return NULL;
31743
31744 if ((event->event_type == 0 && event->event_size == 0) ||
31745- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
31746+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
31747 return NULL;
31748
31749 (*pos)++;
31750@@ -290,7 +290,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
31751 int i;
31752
31753 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
31754- seq_putc(m, data[i]);
31755+ if (!seq_putc(m, data[i]))
31756+ return -EFAULT;
31757
31758 return 0;
31759 }
31760@@ -409,8 +410,13 @@ static int read_log(struct tpm_bios_log *log)
31761 log->bios_event_log_end = log->bios_event_log + len;
31762
31763 virt = acpi_os_map_memory(start, len);
31764+ if (!virt) {
31765+ kfree(log->bios_event_log);
31766+ log->bios_event_log = NULL;
31767+ return -EFAULT;
31768+ }
31769
31770- memcpy(log->bios_event_log, virt, len);
31771+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
31772
31773 acpi_os_unmap_memory(virt, len);
31774 return 0;
31775diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
31776index 123cedf..137edef 100644
31777--- a/drivers/char/tty_io.c
31778+++ b/drivers/char/tty_io.c
31779@@ -1774,6 +1774,7 @@ got_driver:
31780
31781 if (IS_ERR(tty)) {
31782 mutex_unlock(&tty_mutex);
31783+ tty_driver_kref_put(driver);
31784 return PTR_ERR(tty);
31785 }
31786 }
31787@@ -2603,8 +2604,10 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31788 return retval;
31789 }
31790
31791+EXPORT_SYMBOL(tty_ioctl);
31792+
31793 #ifdef CONFIG_COMPAT
31794-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
31795+long tty_compat_ioctl(struct file *file, unsigned int cmd,
31796 unsigned long arg)
31797 {
31798 struct inode *inode = file->f_dentry->d_inode;
31799@@ -2628,6 +2631,8 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
31800
31801 return retval;
31802 }
31803+
31804+EXPORT_SYMBOL(tty_compat_ioctl);
31805 #endif
31806
31807 /*
31808@@ -3073,7 +3078,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
31809
31810 void tty_default_fops(struct file_operations *fops)
31811 {
31812- *fops = tty_fops;
31813+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
31814 }
31815
31816 /*
31817diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
31818index d814a3d..b55b9c9 100644
31819--- a/drivers/char/tty_ldisc.c
31820+++ b/drivers/char/tty_ldisc.c
31821@@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *ld)
31822 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
31823 struct tty_ldisc_ops *ldo = ld->ops;
31824
31825- ldo->refcount--;
31826+ atomic_dec(&ldo->refcount);
31827 module_put(ldo->owner);
31828 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31829
31830@@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
31831 spin_lock_irqsave(&tty_ldisc_lock, flags);
31832 tty_ldiscs[disc] = new_ldisc;
31833 new_ldisc->num = disc;
31834- new_ldisc->refcount = 0;
31835+ atomic_set(&new_ldisc->refcount, 0);
31836 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31837
31838 return ret;
31839@@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
31840 return -EINVAL;
31841
31842 spin_lock_irqsave(&tty_ldisc_lock, flags);
31843- if (tty_ldiscs[disc]->refcount)
31844+ if (atomic_read(&tty_ldiscs[disc]->refcount))
31845 ret = -EBUSY;
31846 else
31847 tty_ldiscs[disc] = NULL;
31848@@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
31849 if (ldops) {
31850 ret = ERR_PTR(-EAGAIN);
31851 if (try_module_get(ldops->owner)) {
31852- ldops->refcount++;
31853+ atomic_inc(&ldops->refcount);
31854 ret = ldops;
31855 }
31856 }
31857@@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
31858 unsigned long flags;
31859
31860 spin_lock_irqsave(&tty_ldisc_lock, flags);
31861- ldops->refcount--;
31862+ atomic_dec(&ldops->refcount);
31863 module_put(ldops->owner);
31864 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31865 }
31866diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
31867index a035ae3..c27fe2c 100644
31868--- a/drivers/char/virtio_console.c
31869+++ b/drivers/char/virtio_console.c
31870@@ -133,7 +133,9 @@ static int get_chars(u32 vtermno, char *buf, int count)
31871 * virtqueue, so we let the drivers do some boutique early-output thing. */
31872 int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
31873 {
31874- virtio_cons.put_chars = put_chars;
31875+ pax_open_kernel();
31876+ *(void **)&virtio_cons.put_chars = put_chars;
31877+ pax_close_kernel();
31878 return hvc_instantiate(0, 0, &virtio_cons);
31879 }
31880
31881@@ -213,11 +215,13 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
31882 out_vq = vqs[1];
31883
31884 /* Start using the new console output. */
31885- virtio_cons.get_chars = get_chars;
31886- virtio_cons.put_chars = put_chars;
31887- virtio_cons.notifier_add = notifier_add_vio;
31888- virtio_cons.notifier_del = notifier_del_vio;
31889- virtio_cons.notifier_hangup = notifier_del_vio;
31890+ pax_open_kernel();
31891+ *(void **)&virtio_cons.get_chars = get_chars;
31892+ *(void **)&virtio_cons.put_chars = put_chars;
31893+ *(void **)&virtio_cons.notifier_add = notifier_add_vio;
31894+ *(void **)&virtio_cons.notifier_del = notifier_del_vio;
31895+ *(void **)&virtio_cons.notifier_hangup = notifier_del_vio;
31896+ pax_close_kernel();
31897
31898 /* The first argument of hvc_alloc() is the virtual console number, so
31899 * we use zero. The second argument is the parameter for the
31900diff --git a/drivers/char/vt.c b/drivers/char/vt.c
31901index 0c80c68..53d59c1 100644
31902--- a/drivers/char/vt.c
31903+++ b/drivers/char/vt.c
31904@@ -243,7 +243,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier);
31905
31906 static void notify_write(struct vc_data *vc, unsigned int unicode)
31907 {
31908- struct vt_notifier_param param = { .vc = vc, unicode = unicode };
31909+ struct vt_notifier_param param = { .vc = vc, .c = unicode };
31910 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
31911 }
31912
31913diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
31914index 6351a26..999af95 100644
31915--- a/drivers/char/vt_ioctl.c
31916+++ b/drivers/char/vt_ioctl.c
31917@@ -210,9 +210,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
31918 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
31919 return -EFAULT;
31920
31921- if (!capable(CAP_SYS_TTY_CONFIG))
31922- perm = 0;
31923-
31924 switch (cmd) {
31925 case KDGKBENT:
31926 key_map = key_maps[s];
31927@@ -224,8 +221,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
31928 val = (i ? K_HOLE : K_NOSUCHMAP);
31929 return put_user(val, &user_kbe->kb_value);
31930 case KDSKBENT:
31931+ if (!capable(CAP_SYS_TTY_CONFIG))
31932+ perm = 0;
31933+
31934 if (!perm)
31935 return -EPERM;
31936+
31937 if (!i && v == K_NOSUCHMAP) {
31938 /* deallocate map */
31939 key_map = key_maps[s];
31940@@ -325,9 +326,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
31941 int i, j, k;
31942 int ret;
31943
31944- if (!capable(CAP_SYS_TTY_CONFIG))
31945- perm = 0;
31946-
31947 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
31948 if (!kbs) {
31949 ret = -ENOMEM;
31950@@ -361,6 +359,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
31951 kfree(kbs);
31952 return ((p && *p) ? -EOVERFLOW : 0);
31953 case KDSKBSENT:
31954+ if (!capable(CAP_SYS_TTY_CONFIG))
31955+ perm = 0;
31956+
31957 if (!perm) {
31958 ret = -EPERM;
31959 goto reterr;
31960diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
31961index c7ae026..1769c1d 100644
31962--- a/drivers/cpufreq/cpufreq.c
31963+++ b/drivers/cpufreq/cpufreq.c
31964@@ -750,7 +750,7 @@ static void cpufreq_sysfs_release(struct kobject *kobj)
31965 complete(&policy->kobj_unregister);
31966 }
31967
31968-static struct sysfs_ops sysfs_ops = {
31969+static const struct sysfs_ops sysfs_ops = {
31970 .show = show,
31971 .store = store,
31972 };
31973diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
31974index 97b0038..2056670 100644
31975--- a/drivers/cpuidle/sysfs.c
31976+++ b/drivers/cpuidle/sysfs.c
31977@@ -191,7 +191,7 @@ static ssize_t cpuidle_store(struct kobject * kobj, struct attribute * attr,
31978 return ret;
31979 }
31980
31981-static struct sysfs_ops cpuidle_sysfs_ops = {
31982+static const struct sysfs_ops cpuidle_sysfs_ops = {
31983 .show = cpuidle_show,
31984 .store = cpuidle_store,
31985 };
31986@@ -277,7 +277,7 @@ static ssize_t cpuidle_state_show(struct kobject * kobj,
31987 return ret;
31988 }
31989
31990-static struct sysfs_ops cpuidle_state_sysfs_ops = {
31991+static const struct sysfs_ops cpuidle_state_sysfs_ops = {
31992 .show = cpuidle_state_show,
31993 };
31994
31995@@ -294,7 +294,7 @@ static struct kobj_type ktype_state_cpuidle = {
31996 .release = cpuidle_state_sysfs_release,
31997 };
31998
31999-static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
32000+static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
32001 {
32002 kobject_put(&device->kobjs[i]->kobj);
32003 wait_for_completion(&device->kobjs[i]->kobj_unregister);
32004diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
32005index 5f753fc..0377ae9 100644
32006--- a/drivers/crypto/hifn_795x.c
32007+++ b/drivers/crypto/hifn_795x.c
32008@@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device *dev, int encdec, u8 snum)
32009 0xCA, 0x34, 0x2B, 0x2E};
32010 struct scatterlist sg;
32011
32012+ pax_track_stack();
32013+
32014 memset(src, 0, sizeof(src));
32015 memset(ctx.key, 0, sizeof(ctx.key));
32016
32017diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
32018index 71e6482..de8d96c 100644
32019--- a/drivers/crypto/padlock-aes.c
32020+++ b/drivers/crypto/padlock-aes.c
32021@@ -108,6 +108,8 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
32022 struct crypto_aes_ctx gen_aes;
32023 int cpu;
32024
32025+ pax_track_stack();
32026+
32027 if (key_len % 8) {
32028 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
32029 return -EINVAL;
32030diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
32031index dcc4ab7..cc834bb 100644
32032--- a/drivers/dma/ioat/dma.c
32033+++ b/drivers/dma/ioat/dma.c
32034@@ -1146,7 +1146,7 @@ ioat_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
32035 return entry->show(&chan->common, page);
32036 }
32037
32038-struct sysfs_ops ioat_sysfs_ops = {
32039+const struct sysfs_ops ioat_sysfs_ops = {
32040 .show = ioat_attr_show,
32041 };
32042
32043diff --git a/drivers/dma/ioat/dma.h b/drivers/dma/ioat/dma.h
32044index bbc3e78..f2db62c 100644
32045--- a/drivers/dma/ioat/dma.h
32046+++ b/drivers/dma/ioat/dma.h
32047@@ -347,7 +347,7 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
32048 unsigned long *phys_complete);
32049 void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
32050 void ioat_kobject_del(struct ioatdma_device *device);
32051-extern struct sysfs_ops ioat_sysfs_ops;
32052+extern const struct sysfs_ops ioat_sysfs_ops;
32053 extern struct ioat_sysfs_entry ioat_version_attr;
32054 extern struct ioat_sysfs_entry ioat_cap_attr;
32055 #endif /* IOATDMA_H */
32056diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
32057index 9908c9e..3ceb0e5 100644
32058--- a/drivers/dma/ioat/dma_v3.c
32059+++ b/drivers/dma/ioat/dma_v3.c
32060@@ -71,10 +71,10 @@
32061 /* provide a lookup table for setting the source address in the base or
32062 * extended descriptor of an xor or pq descriptor
32063 */
32064-static const u8 xor_idx_to_desc __read_mostly = 0xd0;
32065-static const u8 xor_idx_to_field[] __read_mostly = { 1, 4, 5, 6, 7, 0, 1, 2 };
32066-static const u8 pq_idx_to_desc __read_mostly = 0xf8;
32067-static const u8 pq_idx_to_field[] __read_mostly = { 1, 4, 5, 0, 1, 2, 4, 5 };
32068+static const u8 xor_idx_to_desc = 0xd0;
32069+static const u8 xor_idx_to_field[] = { 1, 4, 5, 6, 7, 0, 1, 2 };
32070+static const u8 pq_idx_to_desc = 0xf8;
32071+static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 };
32072
32073 static dma_addr_t xor_get_src(struct ioat_raw_descriptor *descs[2], int idx)
32074 {
32075diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
32076index 85c464a..afd1e73 100644
32077--- a/drivers/edac/amd64_edac.c
32078+++ b/drivers/edac/amd64_edac.c
32079@@ -3099,7 +3099,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
32080 * PCI core identifies what devices are on a system during boot, and then
32081 * inquiry this table to see if this driver is for a given device found.
32082 */
32083-static const struct pci_device_id amd64_pci_table[] __devinitdata = {
32084+static const struct pci_device_id amd64_pci_table[] __devinitconst = {
32085 {
32086 .vendor = PCI_VENDOR_ID_AMD,
32087 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
32088diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
32089index 2b95f1a..4f52793 100644
32090--- a/drivers/edac/amd76x_edac.c
32091+++ b/drivers/edac/amd76x_edac.c
32092@@ -322,7 +322,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
32093 edac_mc_free(mci);
32094 }
32095
32096-static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
32097+static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
32098 {
32099 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32100 AMD762},
32101diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
32102index d205d49..74c9672 100644
32103--- a/drivers/edac/e752x_edac.c
32104+++ b/drivers/edac/e752x_edac.c
32105@@ -1282,7 +1282,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
32106 edac_mc_free(mci);
32107 }
32108
32109-static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
32110+static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
32111 {
32112 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32113 E7520},
32114diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
32115index c7d11cc..c59c1ca 100644
32116--- a/drivers/edac/e7xxx_edac.c
32117+++ b/drivers/edac/e7xxx_edac.c
32118@@ -526,7 +526,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
32119 edac_mc_free(mci);
32120 }
32121
32122-static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
32123+static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
32124 {
32125 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32126 E7205},
32127diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
32128index 5376457..5fdedbc 100644
32129--- a/drivers/edac/edac_device_sysfs.c
32130+++ b/drivers/edac/edac_device_sysfs.c
32131@@ -137,7 +137,7 @@ static ssize_t edac_dev_ctl_info_store(struct kobject *kobj,
32132 }
32133
32134 /* edac_dev file operations for an 'ctl_info' */
32135-static struct sysfs_ops device_ctl_info_ops = {
32136+static const struct sysfs_ops device_ctl_info_ops = {
32137 .show = edac_dev_ctl_info_show,
32138 .store = edac_dev_ctl_info_store
32139 };
32140@@ -373,7 +373,7 @@ static ssize_t edac_dev_instance_store(struct kobject *kobj,
32141 }
32142
32143 /* edac_dev file operations for an 'instance' */
32144-static struct sysfs_ops device_instance_ops = {
32145+static const struct sysfs_ops device_instance_ops = {
32146 .show = edac_dev_instance_show,
32147 .store = edac_dev_instance_store
32148 };
32149@@ -476,7 +476,7 @@ static ssize_t edac_dev_block_store(struct kobject *kobj,
32150 }
32151
32152 /* edac_dev file operations for a 'block' */
32153-static struct sysfs_ops device_block_ops = {
32154+static const struct sysfs_ops device_block_ops = {
32155 .show = edac_dev_block_show,
32156 .store = edac_dev_block_store
32157 };
32158diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
32159index e1d4ce0..88840e9 100644
32160--- a/drivers/edac/edac_mc_sysfs.c
32161+++ b/drivers/edac/edac_mc_sysfs.c
32162@@ -245,7 +245,7 @@ static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
32163 return -EIO;
32164 }
32165
32166-static struct sysfs_ops csrowfs_ops = {
32167+static const struct sysfs_ops csrowfs_ops = {
32168 .show = csrowdev_show,
32169 .store = csrowdev_store
32170 };
32171@@ -575,7 +575,7 @@ static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr,
32172 }
32173
32174 /* Intermediate show/store table */
32175-static struct sysfs_ops mci_ops = {
32176+static const struct sysfs_ops mci_ops = {
32177 .show = mcidev_show,
32178 .store = mcidev_store
32179 };
32180diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32181index 422728c..d8d9c88 100644
32182--- a/drivers/edac/edac_pci_sysfs.c
32183+++ b/drivers/edac/edac_pci_sysfs.c
32184@@ -25,8 +25,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32185 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32186 static int edac_pci_poll_msec = 1000; /* one second workq period */
32187
32188-static atomic_t pci_parity_count = ATOMIC_INIT(0);
32189-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32190+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32191+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32192
32193 static struct kobject *edac_pci_top_main_kobj;
32194 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32195@@ -121,7 +121,7 @@ static ssize_t edac_pci_instance_store(struct kobject *kobj,
32196 }
32197
32198 /* fs_ops table */
32199-static struct sysfs_ops pci_instance_ops = {
32200+static const struct sysfs_ops pci_instance_ops = {
32201 .show = edac_pci_instance_show,
32202 .store = edac_pci_instance_store
32203 };
32204@@ -261,7 +261,7 @@ static ssize_t edac_pci_dev_store(struct kobject *kobj,
32205 return -EIO;
32206 }
32207
32208-static struct sysfs_ops edac_pci_sysfs_ops = {
32209+static const struct sysfs_ops edac_pci_sysfs_ops = {
32210 .show = edac_pci_dev_show,
32211 .store = edac_pci_dev_store
32212 };
32213@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32214 edac_printk(KERN_CRIT, EDAC_PCI,
32215 "Signaled System Error on %s\n",
32216 pci_name(dev));
32217- atomic_inc(&pci_nonparity_count);
32218+ atomic_inc_unchecked(&pci_nonparity_count);
32219 }
32220
32221 if (status & (PCI_STATUS_PARITY)) {
32222@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32223 "Master Data Parity Error on %s\n",
32224 pci_name(dev));
32225
32226- atomic_inc(&pci_parity_count);
32227+ atomic_inc_unchecked(&pci_parity_count);
32228 }
32229
32230 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32231@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32232 "Detected Parity Error on %s\n",
32233 pci_name(dev));
32234
32235- atomic_inc(&pci_parity_count);
32236+ atomic_inc_unchecked(&pci_parity_count);
32237 }
32238 }
32239
32240@@ -616,7 +616,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32241 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32242 "Signaled System Error on %s\n",
32243 pci_name(dev));
32244- atomic_inc(&pci_nonparity_count);
32245+ atomic_inc_unchecked(&pci_nonparity_count);
32246 }
32247
32248 if (status & (PCI_STATUS_PARITY)) {
32249@@ -624,7 +624,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32250 "Master Data Parity Error on "
32251 "%s\n", pci_name(dev));
32252
32253- atomic_inc(&pci_parity_count);
32254+ atomic_inc_unchecked(&pci_parity_count);
32255 }
32256
32257 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32258@@ -632,7 +632,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32259 "Detected Parity Error on %s\n",
32260 pci_name(dev));
32261
32262- atomic_inc(&pci_parity_count);
32263+ atomic_inc_unchecked(&pci_parity_count);
32264 }
32265 }
32266 }
32267@@ -674,7 +674,7 @@ void edac_pci_do_parity_check(void)
32268 if (!check_pci_errors)
32269 return;
32270
32271- before_count = atomic_read(&pci_parity_count);
32272+ before_count = atomic_read_unchecked(&pci_parity_count);
32273
32274 /* scan all PCI devices looking for a Parity Error on devices and
32275 * bridges.
32276@@ -686,7 +686,7 @@ void edac_pci_do_parity_check(void)
32277 /* Only if operator has selected panic on PCI Error */
32278 if (edac_pci_get_panic_on_pe()) {
32279 /* If the count is different 'after' from 'before' */
32280- if (before_count != atomic_read(&pci_parity_count))
32281+ if (before_count != atomic_read_unchecked(&pci_parity_count))
32282 panic("EDAC: PCI Parity Error");
32283 }
32284 }
32285diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
32286index 6c9a0f2..9c1cf7e 100644
32287--- a/drivers/edac/i3000_edac.c
32288+++ b/drivers/edac/i3000_edac.c
32289@@ -471,7 +471,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
32290 edac_mc_free(mci);
32291 }
32292
32293-static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
32294+static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
32295 {
32296 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32297 I3000},
32298diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
32299index fde4db9..fe108f9 100644
32300--- a/drivers/edac/i3200_edac.c
32301+++ b/drivers/edac/i3200_edac.c
32302@@ -444,7 +444,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
32303 edac_mc_free(mci);
32304 }
32305
32306-static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
32307+static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
32308 {
32309 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32310 I3200},
32311diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
32312index adc10a2..57d4ccf 100644
32313--- a/drivers/edac/i5000_edac.c
32314+++ b/drivers/edac/i5000_edac.c
32315@@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
32316 *
32317 * The "E500P" device is the first device supported.
32318 */
32319-static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
32320+static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
32321 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
32322 .driver_data = I5000P},
32323
32324diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
32325index 22db05a..b2b5503 100644
32326--- a/drivers/edac/i5100_edac.c
32327+++ b/drivers/edac/i5100_edac.c
32328@@ -944,7 +944,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
32329 edac_mc_free(mci);
32330 }
32331
32332-static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
32333+static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
32334 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
32335 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
32336 { 0, }
32337diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
32338index f99d106..f050710 100644
32339--- a/drivers/edac/i5400_edac.c
32340+++ b/drivers/edac/i5400_edac.c
32341@@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
32342 *
32343 * The "E500P" device is the first device supported.
32344 */
32345-static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
32346+static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
32347 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
32348 {0,} /* 0 terminated list. */
32349 };
32350diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
32351index 577760a..9ce16ce 100644
32352--- a/drivers/edac/i82443bxgx_edac.c
32353+++ b/drivers/edac/i82443bxgx_edac.c
32354@@ -381,7 +381,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
32355
32356 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
32357
32358-static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
32359+static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
32360 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
32361 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
32362 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
32363diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
32364index c0088ba..64a7b98 100644
32365--- a/drivers/edac/i82860_edac.c
32366+++ b/drivers/edac/i82860_edac.c
32367@@ -271,7 +271,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
32368 edac_mc_free(mci);
32369 }
32370
32371-static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
32372+static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
32373 {
32374 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32375 I82860},
32376diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
32377index b2d83b9..a34357b 100644
32378--- a/drivers/edac/i82875p_edac.c
32379+++ b/drivers/edac/i82875p_edac.c
32380@@ -512,7 +512,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
32381 edac_mc_free(mci);
32382 }
32383
32384-static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
32385+static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
32386 {
32387 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32388 I82875P},
32389diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
32390index 2eed3ea..87bbbd1 100644
32391--- a/drivers/edac/i82975x_edac.c
32392+++ b/drivers/edac/i82975x_edac.c
32393@@ -586,7 +586,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
32394 edac_mc_free(mci);
32395 }
32396
32397-static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
32398+static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
32399 {
32400 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32401 I82975X
32402diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
32403index 9900675..78ac2b6 100644
32404--- a/drivers/edac/r82600_edac.c
32405+++ b/drivers/edac/r82600_edac.c
32406@@ -374,7 +374,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
32407 edac_mc_free(mci);
32408 }
32409
32410-static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
32411+static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
32412 {
32413 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
32414 },
32415diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
32416index d4ec605..4cfec4e 100644
32417--- a/drivers/edac/x38_edac.c
32418+++ b/drivers/edac/x38_edac.c
32419@@ -441,7 +441,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
32420 edac_mc_free(mci);
32421 }
32422
32423-static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
32424+static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
32425 {
32426 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32427 X38},
32428diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32429index 3fc2ceb..daf098f 100644
32430--- a/drivers/firewire/core-card.c
32431+++ b/drivers/firewire/core-card.c
32432@@ -558,7 +558,7 @@ void fw_card_release(struct kref *kref)
32433
32434 void fw_core_remove_card(struct fw_card *card)
32435 {
32436- struct fw_card_driver dummy_driver = dummy_driver_template;
32437+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
32438
32439 card->driver->update_phy_reg(card, 4,
32440 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32441diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32442index 4560d8f..36db24a 100644
32443--- a/drivers/firewire/core-cdev.c
32444+++ b/drivers/firewire/core-cdev.c
32445@@ -1141,8 +1141,7 @@ static int init_iso_resource(struct client *client,
32446 int ret;
32447
32448 if ((request->channels == 0 && request->bandwidth == 0) ||
32449- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32450- request->bandwidth < 0)
32451+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32452 return -EINVAL;
32453
32454 r = kmalloc(sizeof(*r), GFP_KERNEL);
32455diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32456index da628c7..cf54a2c 100644
32457--- a/drivers/firewire/core-transaction.c
32458+++ b/drivers/firewire/core-transaction.c
32459@@ -36,6 +36,7 @@
32460 #include <linux/string.h>
32461 #include <linux/timer.h>
32462 #include <linux/types.h>
32463+#include <linux/sched.h>
32464
32465 #include <asm/byteorder.h>
32466
32467@@ -344,6 +345,8 @@ int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
32468 struct transaction_callback_data d;
32469 struct fw_transaction t;
32470
32471+ pax_track_stack();
32472+
32473 init_completion(&d.done);
32474 d.payload = payload;
32475 fw_send_request(card, &t, tcode, destination_id, generation, speed,
32476diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32477index 7ff6e75..a2965d9 100644
32478--- a/drivers/firewire/core.h
32479+++ b/drivers/firewire/core.h
32480@@ -86,6 +86,7 @@ struct fw_card_driver {
32481
32482 int (*stop_iso)(struct fw_iso_context *ctx);
32483 };
32484+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32485
32486 void fw_card_initialize(struct fw_card *card,
32487 const struct fw_card_driver *driver, struct device *device);
32488diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32489index 3a2ccb0..82fd7c4 100644
32490--- a/drivers/firmware/dmi_scan.c
32491+++ b/drivers/firmware/dmi_scan.c
32492@@ -391,11 +391,6 @@ void __init dmi_scan_machine(void)
32493 }
32494 }
32495 else {
32496- /*
32497- * no iounmap() for that ioremap(); it would be a no-op, but
32498- * it's so early in setup that sucker gets confused into doing
32499- * what it shouldn't if we actually call it.
32500- */
32501 p = dmi_ioremap(0xF0000, 0x10000);
32502 if (p == NULL)
32503 goto error;
32504@@ -667,7 +662,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32505 if (buf == NULL)
32506 return -1;
32507
32508- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32509+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32510
32511 iounmap(buf);
32512 return 0;
32513diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
32514index 9e4f59d..110e24e 100644
32515--- a/drivers/firmware/edd.c
32516+++ b/drivers/firmware/edd.c
32517@@ -122,7 +122,7 @@ edd_attr_show(struct kobject * kobj, struct attribute *attr, char *buf)
32518 return ret;
32519 }
32520
32521-static struct sysfs_ops edd_attr_ops = {
32522+static const struct sysfs_ops edd_attr_ops = {
32523 .show = edd_attr_show,
32524 };
32525
32526diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32527index f4f709d..082f06e 100644
32528--- a/drivers/firmware/efivars.c
32529+++ b/drivers/firmware/efivars.c
32530@@ -362,7 +362,7 @@ static ssize_t efivar_attr_store(struct kobject *kobj, struct attribute *attr,
32531 return ret;
32532 }
32533
32534-static struct sysfs_ops efivar_attr_ops = {
32535+static const struct sysfs_ops efivar_attr_ops = {
32536 .show = efivar_attr_show,
32537 .store = efivar_attr_store,
32538 };
32539diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c
32540index 051d1eb..0a5d4e7 100644
32541--- a/drivers/firmware/iscsi_ibft.c
32542+++ b/drivers/firmware/iscsi_ibft.c
32543@@ -525,7 +525,7 @@ static ssize_t ibft_show_attribute(struct kobject *kobj,
32544 return ret;
32545 }
32546
32547-static struct sysfs_ops ibft_attr_ops = {
32548+static const struct sysfs_ops ibft_attr_ops = {
32549 .show = ibft_show_attribute,
32550 };
32551
32552diff --git a/drivers/firmware/memmap.c b/drivers/firmware/memmap.c
32553index 56f9234..8c58c7b 100644
32554--- a/drivers/firmware/memmap.c
32555+++ b/drivers/firmware/memmap.c
32556@@ -74,7 +74,7 @@ static struct attribute *def_attrs[] = {
32557 NULL
32558 };
32559
32560-static struct sysfs_ops memmap_attr_ops = {
32561+static const struct sysfs_ops memmap_attr_ops = {
32562 .show = memmap_attr_show,
32563 };
32564
32565diff --git a/drivers/gpio/vr41xx_giu.c b/drivers/gpio/vr41xx_giu.c
32566index b16c9a8..2af7d3f 100644
32567--- a/drivers/gpio/vr41xx_giu.c
32568+++ b/drivers/gpio/vr41xx_giu.c
32569@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32570 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32571 maskl, pendl, maskh, pendh);
32572
32573- atomic_inc(&irq_err_count);
32574+ atomic_inc_unchecked(&irq_err_count);
32575
32576 return -EINVAL;
32577 }
32578diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
32579index bea6efc..3dc0f42 100644
32580--- a/drivers/gpu/drm/drm_crtc.c
32581+++ b/drivers/gpu/drm/drm_crtc.c
32582@@ -1323,7 +1323,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32583 */
32584 if ((out_resp->count_modes >= mode_count) && mode_count) {
32585 copied = 0;
32586- mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
32587+ mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
32588 list_for_each_entry(mode, &connector->modes, head) {
32589 drm_crtc_convert_to_umode(&u_mode, mode);
32590 if (copy_to_user(mode_ptr + copied,
32591@@ -1338,8 +1338,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32592
32593 if ((out_resp->count_props >= props_count) && props_count) {
32594 copied = 0;
32595- prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
32596- prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
32597+ prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
32598+ prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
32599 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
32600 if (connector->property_ids[i] != 0) {
32601 if (put_user(connector->property_ids[i],
32602@@ -1361,7 +1361,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32603
32604 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
32605 copied = 0;
32606- encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
32607+ encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
32608 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
32609 if (connector->encoder_ids[i] != 0) {
32610 if (put_user(connector->encoder_ids[i],
32611@@ -1513,7 +1513,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
32612 }
32613
32614 for (i = 0; i < crtc_req->count_connectors; i++) {
32615- set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
32616+ set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
32617 if (get_user(out_id, &set_connectors_ptr[i])) {
32618 ret = -EFAULT;
32619 goto out;
32620@@ -2118,7 +2118,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32621 out_resp->flags = property->flags;
32622
32623 if ((out_resp->count_values >= value_count) && value_count) {
32624- values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
32625+ values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
32626 for (i = 0; i < value_count; i++) {
32627 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
32628 ret = -EFAULT;
32629@@ -2131,7 +2131,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32630 if (property->flags & DRM_MODE_PROP_ENUM) {
32631 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
32632 copied = 0;
32633- enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
32634+ enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
32635 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
32636
32637 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
32638@@ -2154,7 +2154,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32639 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
32640 copied = 0;
32641 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
32642- blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
32643+ blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
32644
32645 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
32646 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
32647@@ -2226,7 +2226,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
32648 blob = obj_to_blob(obj);
32649
32650 if (out_resp->length == blob->length) {
32651- blob_ptr = (void *)(unsigned long)out_resp->data;
32652+ blob_ptr = (void __user *)(unsigned long)out_resp->data;
32653 if (copy_to_user(blob_ptr, blob->data, blob->length)){
32654 ret = -EFAULT;
32655 goto done;
32656diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32657index 1b8745d..92fdbf6 100644
32658--- a/drivers/gpu/drm/drm_crtc_helper.c
32659+++ b/drivers/gpu/drm/drm_crtc_helper.c
32660@@ -573,7 +573,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32661 struct drm_crtc *tmp;
32662 int crtc_mask = 1;
32663
32664- WARN(!crtc, "checking null crtc?");
32665+ BUG_ON(!crtc);
32666
32667 dev = crtc->dev;
32668
32669@@ -642,6 +642,8 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
32670
32671 adjusted_mode = drm_mode_duplicate(dev, mode);
32672
32673+ pax_track_stack();
32674+
32675 crtc->enabled = drm_helper_crtc_in_use(crtc);
32676
32677 if (!crtc->enabled)
32678diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32679index 0e27d98..dec8768 100644
32680--- a/drivers/gpu/drm/drm_drv.c
32681+++ b/drivers/gpu/drm/drm_drv.c
32682@@ -417,7 +417,7 @@ int drm_ioctl(struct inode *inode, struct file *filp,
32683 char *kdata = NULL;
32684
32685 atomic_inc(&dev->ioctl_count);
32686- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32687+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32688 ++file_priv->ioctl_count;
32689
32690 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32691diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32692index ba14553..182d0bb 100644
32693--- a/drivers/gpu/drm/drm_fops.c
32694+++ b/drivers/gpu/drm/drm_fops.c
32695@@ -66,7 +66,7 @@ static int drm_setup(struct drm_device * dev)
32696 }
32697
32698 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32699- atomic_set(&dev->counts[i], 0);
32700+ atomic_set_unchecked(&dev->counts[i], 0);
32701
32702 dev->sigdata.lock = NULL;
32703
32704@@ -130,9 +130,9 @@ int drm_open(struct inode *inode, struct file *filp)
32705
32706 retcode = drm_open_helper(inode, filp, dev);
32707 if (!retcode) {
32708- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32709+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32710 spin_lock(&dev->count_lock);
32711- if (!dev->open_count++) {
32712+ if (local_inc_return(&dev->open_count) == 1) {
32713 spin_unlock(&dev->count_lock);
32714 retcode = drm_setup(dev);
32715 goto out;
32716@@ -435,7 +435,7 @@ int drm_release(struct inode *inode, struct file *filp)
32717
32718 lock_kernel();
32719
32720- DRM_DEBUG("open_count = %d\n", dev->open_count);
32721+ DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
32722
32723 if (dev->driver->preclose)
32724 dev->driver->preclose(dev, file_priv);
32725@@ -447,7 +447,7 @@ int drm_release(struct inode *inode, struct file *filp)
32726 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32727 task_pid_nr(current),
32728 (long)old_encode_dev(file_priv->minor->device),
32729- dev->open_count);
32730+ local_read(&dev->open_count));
32731
32732 /* if the master has gone away we can't do anything with the lock */
32733 if (file_priv->minor->master)
32734@@ -524,9 +524,9 @@ int drm_release(struct inode *inode, struct file *filp)
32735 * End inline drm_release
32736 */
32737
32738- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32739+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32740 spin_lock(&dev->count_lock);
32741- if (!--dev->open_count) {
32742+ if (local_dec_and_test(&dev->open_count)) {
32743 if (atomic_read(&dev->ioctl_count)) {
32744 DRM_ERROR("Device busy: %d\n",
32745 atomic_read(&dev->ioctl_count));
32746diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
32747index 8bf3770..79422805 100644
32748--- a/drivers/gpu/drm/drm_gem.c
32749+++ b/drivers/gpu/drm/drm_gem.c
32750@@ -83,11 +83,11 @@ drm_gem_init(struct drm_device *dev)
32751 spin_lock_init(&dev->object_name_lock);
32752 idr_init(&dev->object_name_idr);
32753 atomic_set(&dev->object_count, 0);
32754- atomic_set(&dev->object_memory, 0);
32755+ atomic_set_unchecked(&dev->object_memory, 0);
32756 atomic_set(&dev->pin_count, 0);
32757- atomic_set(&dev->pin_memory, 0);
32758+ atomic_set_unchecked(&dev->pin_memory, 0);
32759 atomic_set(&dev->gtt_count, 0);
32760- atomic_set(&dev->gtt_memory, 0);
32761+ atomic_set_unchecked(&dev->gtt_memory, 0);
32762
32763 mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL);
32764 if (!mm) {
32765@@ -150,7 +150,7 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size)
32766 goto fput;
32767 }
32768 atomic_inc(&dev->object_count);
32769- atomic_add(obj->size, &dev->object_memory);
32770+ atomic_add_unchecked(obj->size, &dev->object_memory);
32771 return obj;
32772 fput:
32773 fput(obj->filp);
32774@@ -429,7 +429,7 @@ drm_gem_object_free(struct kref *kref)
32775
32776 fput(obj->filp);
32777 atomic_dec(&dev->object_count);
32778- atomic_sub(obj->size, &dev->object_memory);
32779+ atomic_sub_unchecked(obj->size, &dev->object_memory);
32780 kfree(obj);
32781 }
32782 EXPORT_SYMBOL(drm_gem_object_free);
32783diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32784index f0f6c6b..34af322 100644
32785--- a/drivers/gpu/drm/drm_info.c
32786+++ b/drivers/gpu/drm/drm_info.c
32787@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32788 struct drm_local_map *map;
32789 struct drm_map_list *r_list;
32790
32791- /* Hardcoded from _DRM_FRAME_BUFFER,
32792- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32793- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32794- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32795+ static const char * const types[] = {
32796+ [_DRM_FRAME_BUFFER] = "FB",
32797+ [_DRM_REGISTERS] = "REG",
32798+ [_DRM_SHM] = "SHM",
32799+ [_DRM_AGP] = "AGP",
32800+ [_DRM_SCATTER_GATHER] = "SG",
32801+ [_DRM_CONSISTENT] = "PCI",
32802+ [_DRM_GEM] = "GEM" };
32803 const char *type;
32804 int i;
32805
32806@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32807 map = r_list->map;
32808 if (!map)
32809 continue;
32810- if (map->type < 0 || map->type > 5)
32811+ if (map->type >= ARRAY_SIZE(types))
32812 type = "??";
32813 else
32814 type = types[map->type];
32815@@ -265,10 +269,10 @@ int drm_gem_object_info(struct seq_file *m, void* data)
32816 struct drm_device *dev = node->minor->dev;
32817
32818 seq_printf(m, "%d objects\n", atomic_read(&dev->object_count));
32819- seq_printf(m, "%d object bytes\n", atomic_read(&dev->object_memory));
32820+ seq_printf(m, "%d object bytes\n", atomic_read_unchecked(&dev->object_memory));
32821 seq_printf(m, "%d pinned\n", atomic_read(&dev->pin_count));
32822- seq_printf(m, "%d pin bytes\n", atomic_read(&dev->pin_memory));
32823- seq_printf(m, "%d gtt bytes\n", atomic_read(&dev->gtt_memory));
32824+ seq_printf(m, "%d pin bytes\n", atomic_read_unchecked(&dev->pin_memory));
32825+ seq_printf(m, "%d gtt bytes\n", atomic_read_unchecked(&dev->gtt_memory));
32826 seq_printf(m, "%d gtt total\n", dev->gtt_total);
32827 return 0;
32828 }
32829@@ -288,7 +292,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32830 mutex_lock(&dev->struct_mutex);
32831 seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
32832 atomic_read(&dev->vma_count),
32833+#ifdef CONFIG_GRKERNSEC_HIDESYM
32834+ NULL, 0);
32835+#else
32836 high_memory, (u64)virt_to_phys(high_memory));
32837+#endif
32838
32839 list_for_each_entry(pt, &dev->vmalist, head) {
32840 vma = pt->vma;
32841@@ -296,14 +304,23 @@ int drm_vma_info(struct seq_file *m, void *data)
32842 continue;
32843 seq_printf(m,
32844 "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
32845- pt->pid, vma->vm_start, vma->vm_end,
32846+ pt->pid,
32847+#ifdef CONFIG_GRKERNSEC_HIDESYM
32848+ 0, 0,
32849+#else
32850+ vma->vm_start, vma->vm_end,
32851+#endif
32852 vma->vm_flags & VM_READ ? 'r' : '-',
32853 vma->vm_flags & VM_WRITE ? 'w' : '-',
32854 vma->vm_flags & VM_EXEC ? 'x' : '-',
32855 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32856 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32857 vma->vm_flags & VM_IO ? 'i' : '-',
32858+#ifdef CONFIG_GRKERNSEC_HIDESYM
32859+ 0);
32860+#else
32861 vma->vm_pgoff);
32862+#endif
32863
32864 #if defined(__i386__)
32865 pgprot = pgprot_val(vma->vm_page_prot);
32866diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32867index 282d9fd..71e5f11 100644
32868--- a/drivers/gpu/drm/drm_ioc32.c
32869+++ b/drivers/gpu/drm/drm_ioc32.c
32870@@ -463,7 +463,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32871 request = compat_alloc_user_space(nbytes);
32872 if (!access_ok(VERIFY_WRITE, request, nbytes))
32873 return -EFAULT;
32874- list = (struct drm_buf_desc *) (request + 1);
32875+ list = (struct drm_buf_desc __user *) (request + 1);
32876
32877 if (__put_user(count, &request->count)
32878 || __put_user(list, &request->list))
32879@@ -525,7 +525,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32880 request = compat_alloc_user_space(nbytes);
32881 if (!access_ok(VERIFY_WRITE, request, nbytes))
32882 return -EFAULT;
32883- list = (struct drm_buf_pub *) (request + 1);
32884+ list = (struct drm_buf_pub __user *) (request + 1);
32885
32886 if (__put_user(count, &request->count)
32887 || __put_user(list, &request->list))
32888diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32889index 9b9ff46..4ea724c 100644
32890--- a/drivers/gpu/drm/drm_ioctl.c
32891+++ b/drivers/gpu/drm/drm_ioctl.c
32892@@ -283,7 +283,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32893 stats->data[i].value =
32894 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32895 else
32896- stats->data[i].value = atomic_read(&dev->counts[i]);
32897+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32898 stats->data[i].type = dev->types[i];
32899 }
32900
32901diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32902index e2f70a5..c703e86 100644
32903--- a/drivers/gpu/drm/drm_lock.c
32904+++ b/drivers/gpu/drm/drm_lock.c
32905@@ -87,7 +87,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32906 if (drm_lock_take(&master->lock, lock->context)) {
32907 master->lock.file_priv = file_priv;
32908 master->lock.lock_time = jiffies;
32909- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32910+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32911 break; /* Got lock */
32912 }
32913
32914@@ -165,7 +165,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32915 return -EINVAL;
32916 }
32917
32918- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32919+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32920
32921 /* kernel_context_switch isn't used by any of the x86 drm
32922 * modules but is required by the Sparc driver.
32923diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32924index 7d1d88c..b9131b2 100644
32925--- a/drivers/gpu/drm/i810/i810_dma.c
32926+++ b/drivers/gpu/drm/i810/i810_dma.c
32927@@ -952,8 +952,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32928 dma->buflist[vertex->idx],
32929 vertex->discard, vertex->used);
32930
32931- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32932- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32933+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32934+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32935 sarea_priv->last_enqueue = dev_priv->counter - 1;
32936 sarea_priv->last_dispatch = (int)hw_status[5];
32937
32938@@ -1115,8 +1115,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32939 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32940 mc->last_render);
32941
32942- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32943- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32944+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32945+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32946 sarea_priv->last_enqueue = dev_priv->counter - 1;
32947 sarea_priv->last_dispatch = (int)hw_status[5];
32948
32949diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32950index 21e2691..7321edd 100644
32951--- a/drivers/gpu/drm/i810/i810_drv.h
32952+++ b/drivers/gpu/drm/i810/i810_drv.h
32953@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32954 int page_flipping;
32955
32956 wait_queue_head_t irq_queue;
32957- atomic_t irq_received;
32958- atomic_t irq_emitted;
32959+ atomic_unchecked_t irq_received;
32960+ atomic_unchecked_t irq_emitted;
32961
32962 int front_offset;
32963 } drm_i810_private_t;
32964diff --git a/drivers/gpu/drm/i830/i830_drv.h b/drivers/gpu/drm/i830/i830_drv.h
32965index da82afe..48a45de 100644
32966--- a/drivers/gpu/drm/i830/i830_drv.h
32967+++ b/drivers/gpu/drm/i830/i830_drv.h
32968@@ -115,8 +115,8 @@ typedef struct drm_i830_private {
32969 int page_flipping;
32970
32971 wait_queue_head_t irq_queue;
32972- atomic_t irq_received;
32973- atomic_t irq_emitted;
32974+ atomic_unchecked_t irq_received;
32975+ atomic_unchecked_t irq_emitted;
32976
32977 int use_mi_batchbuffer_start;
32978
32979diff --git a/drivers/gpu/drm/i830/i830_irq.c b/drivers/gpu/drm/i830/i830_irq.c
32980index 91ec2bb..6f21fab 100644
32981--- a/drivers/gpu/drm/i830/i830_irq.c
32982+++ b/drivers/gpu/drm/i830/i830_irq.c
32983@@ -47,7 +47,7 @@ irqreturn_t i830_driver_irq_handler(DRM_IRQ_ARGS)
32984
32985 I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
32986
32987- atomic_inc(&dev_priv->irq_received);
32988+ atomic_inc_unchecked(&dev_priv->irq_received);
32989 wake_up_interruptible(&dev_priv->irq_queue);
32990
32991 return IRQ_HANDLED;
32992@@ -60,14 +60,14 @@ static int i830_emit_irq(struct drm_device * dev)
32993
32994 DRM_DEBUG("%s\n", __func__);
32995
32996- atomic_inc(&dev_priv->irq_emitted);
32997+ atomic_inc_unchecked(&dev_priv->irq_emitted);
32998
32999 BEGIN_LP_RING(2);
33000 OUT_RING(0);
33001 OUT_RING(GFX_OP_USER_INTERRUPT);
33002 ADVANCE_LP_RING();
33003
33004- return atomic_read(&dev_priv->irq_emitted);
33005+ return atomic_read_unchecked(&dev_priv->irq_emitted);
33006 }
33007
33008 static int i830_wait_irq(struct drm_device * dev, int irq_nr)
33009@@ -79,7 +79,7 @@ static int i830_wait_irq(struct drm_device * dev, int irq_nr)
33010
33011 DRM_DEBUG("%s\n", __func__);
33012
33013- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
33014+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
33015 return 0;
33016
33017 dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
33018@@ -88,7 +88,7 @@ static int i830_wait_irq(struct drm_device * dev, int irq_nr)
33019
33020 for (;;) {
33021 __set_current_state(TASK_INTERRUPTIBLE);
33022- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
33023+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
33024 break;
33025 if ((signed)(end - jiffies) <= 0) {
33026 DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
33027@@ -163,8 +163,8 @@ void i830_driver_irq_preinstall(struct drm_device * dev)
33028 I830_WRITE16(I830REG_HWSTAM, 0xffff);
33029 I830_WRITE16(I830REG_INT_MASK_R, 0x0);
33030 I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
33031- atomic_set(&dev_priv->irq_received, 0);
33032- atomic_set(&dev_priv->irq_emitted, 0);
33033+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33034+ atomic_set_unchecked(&dev_priv->irq_emitted, 0);
33035 init_waitqueue_head(&dev_priv->irq_queue);
33036 }
33037
33038diff --git a/drivers/gpu/drm/i915/dvo.h b/drivers/gpu/drm/i915/dvo.h
33039index 288fc50..c6092055 100644
33040--- a/drivers/gpu/drm/i915/dvo.h
33041+++ b/drivers/gpu/drm/i915/dvo.h
33042@@ -135,23 +135,23 @@ struct intel_dvo_dev_ops {
33043 *
33044 * \return singly-linked list of modes or NULL if no modes found.
33045 */
33046- struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
33047+ struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
33048
33049 /**
33050 * Clean up driver-specific bits of the output
33051 */
33052- void (*destroy) (struct intel_dvo_device *dvo);
33053+ void (* const destroy) (struct intel_dvo_device *dvo);
33054
33055 /**
33056 * Debugging hook to dump device registers to log file
33057 */
33058- void (*dump_regs)(struct intel_dvo_device *dvo);
33059+ void (* const dump_regs)(struct intel_dvo_device *dvo);
33060 };
33061
33062-extern struct intel_dvo_dev_ops sil164_ops;
33063-extern struct intel_dvo_dev_ops ch7xxx_ops;
33064-extern struct intel_dvo_dev_ops ivch_ops;
33065-extern struct intel_dvo_dev_ops tfp410_ops;
33066-extern struct intel_dvo_dev_ops ch7017_ops;
33067+extern const struct intel_dvo_dev_ops sil164_ops;
33068+extern const struct intel_dvo_dev_ops ch7xxx_ops;
33069+extern const struct intel_dvo_dev_ops ivch_ops;
33070+extern const struct intel_dvo_dev_ops tfp410_ops;
33071+extern const struct intel_dvo_dev_ops ch7017_ops;
33072
33073 #endif /* _INTEL_DVO_H */
33074diff --git a/drivers/gpu/drm/i915/dvo_ch7017.c b/drivers/gpu/drm/i915/dvo_ch7017.c
33075index 621815b..499d82e 100644
33076--- a/drivers/gpu/drm/i915/dvo_ch7017.c
33077+++ b/drivers/gpu/drm/i915/dvo_ch7017.c
33078@@ -443,7 +443,7 @@ static void ch7017_destroy(struct intel_dvo_device *dvo)
33079 }
33080 }
33081
33082-struct intel_dvo_dev_ops ch7017_ops = {
33083+const struct intel_dvo_dev_ops ch7017_ops = {
33084 .init = ch7017_init,
33085 .detect = ch7017_detect,
33086 .mode_valid = ch7017_mode_valid,
33087diff --git a/drivers/gpu/drm/i915/dvo_ch7xxx.c b/drivers/gpu/drm/i915/dvo_ch7xxx.c
33088index a9b8962..ac769ba 100644
33089--- a/drivers/gpu/drm/i915/dvo_ch7xxx.c
33090+++ b/drivers/gpu/drm/i915/dvo_ch7xxx.c
33091@@ -356,7 +356,7 @@ static void ch7xxx_destroy(struct intel_dvo_device *dvo)
33092 }
33093 }
33094
33095-struct intel_dvo_dev_ops ch7xxx_ops = {
33096+const struct intel_dvo_dev_ops ch7xxx_ops = {
33097 .init = ch7xxx_init,
33098 .detect = ch7xxx_detect,
33099 .mode_valid = ch7xxx_mode_valid,
33100diff --git a/drivers/gpu/drm/i915/dvo_ivch.c b/drivers/gpu/drm/i915/dvo_ivch.c
33101index aa176f9..ed2930c 100644
33102--- a/drivers/gpu/drm/i915/dvo_ivch.c
33103+++ b/drivers/gpu/drm/i915/dvo_ivch.c
33104@@ -430,7 +430,7 @@ static void ivch_destroy(struct intel_dvo_device *dvo)
33105 }
33106 }
33107
33108-struct intel_dvo_dev_ops ivch_ops= {
33109+const struct intel_dvo_dev_ops ivch_ops= {
33110 .init = ivch_init,
33111 .dpms = ivch_dpms,
33112 .save = ivch_save,
33113diff --git a/drivers/gpu/drm/i915/dvo_sil164.c b/drivers/gpu/drm/i915/dvo_sil164.c
33114index e1c1f73..7dbebcf 100644
33115--- a/drivers/gpu/drm/i915/dvo_sil164.c
33116+++ b/drivers/gpu/drm/i915/dvo_sil164.c
33117@@ -290,7 +290,7 @@ static void sil164_destroy(struct intel_dvo_device *dvo)
33118 }
33119 }
33120
33121-struct intel_dvo_dev_ops sil164_ops = {
33122+const struct intel_dvo_dev_ops sil164_ops = {
33123 .init = sil164_init,
33124 .detect = sil164_detect,
33125 .mode_valid = sil164_mode_valid,
33126diff --git a/drivers/gpu/drm/i915/dvo_tfp410.c b/drivers/gpu/drm/i915/dvo_tfp410.c
33127index 16dce84..7e1b6f8 100644
33128--- a/drivers/gpu/drm/i915/dvo_tfp410.c
33129+++ b/drivers/gpu/drm/i915/dvo_tfp410.c
33130@@ -323,7 +323,7 @@ static void tfp410_destroy(struct intel_dvo_device *dvo)
33131 }
33132 }
33133
33134-struct intel_dvo_dev_ops tfp410_ops = {
33135+const struct intel_dvo_dev_ops tfp410_ops = {
33136 .init = tfp410_init,
33137 .detect = tfp410_detect,
33138 .mode_valid = tfp410_mode_valid,
33139diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
33140index 7e859d6..7d1cf2b 100644
33141--- a/drivers/gpu/drm/i915/i915_debugfs.c
33142+++ b/drivers/gpu/drm/i915/i915_debugfs.c
33143@@ -192,7 +192,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
33144 I915_READ(GTIMR));
33145 }
33146 seq_printf(m, "Interrupts received: %d\n",
33147- atomic_read(&dev_priv->irq_received));
33148+ atomic_read_unchecked(&dev_priv->irq_received));
33149 if (dev_priv->hw_status_page != NULL) {
33150 seq_printf(m, "Current sequence: %d\n",
33151 i915_get_gem_seqno(dev));
33152diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
33153index 5449239..7e4f68d 100644
33154--- a/drivers/gpu/drm/i915/i915_drv.c
33155+++ b/drivers/gpu/drm/i915/i915_drv.c
33156@@ -285,7 +285,7 @@ i915_pci_resume(struct pci_dev *pdev)
33157 return i915_resume(dev);
33158 }
33159
33160-static struct vm_operations_struct i915_gem_vm_ops = {
33161+static const struct vm_operations_struct i915_gem_vm_ops = {
33162 .fault = i915_gem_fault,
33163 .open = drm_gem_vm_open,
33164 .close = drm_gem_vm_close,
33165diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
33166index 97163f7..c24c7c7 100644
33167--- a/drivers/gpu/drm/i915/i915_drv.h
33168+++ b/drivers/gpu/drm/i915/i915_drv.h
33169@@ -168,7 +168,7 @@ struct drm_i915_display_funcs {
33170 /* display clock increase/decrease */
33171 /* pll clock increase/decrease */
33172 /* clock gating init */
33173-};
33174+} __no_const;
33175
33176 typedef struct drm_i915_private {
33177 struct drm_device *dev;
33178@@ -197,7 +197,7 @@ typedef struct drm_i915_private {
33179 int page_flipping;
33180
33181 wait_queue_head_t irq_queue;
33182- atomic_t irq_received;
33183+ atomic_unchecked_t irq_received;
33184 /** Protects user_irq_refcount and irq_mask_reg */
33185 spinlock_t user_irq_lock;
33186 /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
33187diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
33188index 27a3074..eb3f959 100644
33189--- a/drivers/gpu/drm/i915/i915_gem.c
33190+++ b/drivers/gpu/drm/i915/i915_gem.c
33191@@ -102,7 +102,7 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
33192
33193 args->aper_size = dev->gtt_total;
33194 args->aper_available_size = (args->aper_size -
33195- atomic_read(&dev->pin_memory));
33196+ atomic_read_unchecked(&dev->pin_memory));
33197
33198 return 0;
33199 }
33200@@ -2058,7 +2058,7 @@ i915_gem_object_unbind(struct drm_gem_object *obj)
33201
33202 if (obj_priv->gtt_space) {
33203 atomic_dec(&dev->gtt_count);
33204- atomic_sub(obj->size, &dev->gtt_memory);
33205+ atomic_sub_unchecked(obj->size, &dev->gtt_memory);
33206
33207 drm_mm_put_block(obj_priv->gtt_space);
33208 obj_priv->gtt_space = NULL;
33209@@ -2701,7 +2701,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
33210 goto search_free;
33211 }
33212 atomic_inc(&dev->gtt_count);
33213- atomic_add(obj->size, &dev->gtt_memory);
33214+ atomic_add_unchecked(obj->size, &dev->gtt_memory);
33215
33216 /* Assert that the object is not currently in any GPU domain. As it
33217 * wasn't in the GTT, there shouldn't be any way it could have been in
33218@@ -3755,9 +3755,9 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
33219 "%d/%d gtt bytes\n",
33220 atomic_read(&dev->object_count),
33221 atomic_read(&dev->pin_count),
33222- atomic_read(&dev->object_memory),
33223- atomic_read(&dev->pin_memory),
33224- atomic_read(&dev->gtt_memory),
33225+ atomic_read_unchecked(&dev->object_memory),
33226+ atomic_read_unchecked(&dev->pin_memory),
33227+ atomic_read_unchecked(&dev->gtt_memory),
33228 dev->gtt_total);
33229 }
33230 goto err;
33231@@ -3989,7 +3989,7 @@ i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment)
33232 */
33233 if (obj_priv->pin_count == 1) {
33234 atomic_inc(&dev->pin_count);
33235- atomic_add(obj->size, &dev->pin_memory);
33236+ atomic_add_unchecked(obj->size, &dev->pin_memory);
33237 if (!obj_priv->active &&
33238 (obj->write_domain & I915_GEM_GPU_DOMAINS) == 0 &&
33239 !list_empty(&obj_priv->list))
33240@@ -4022,7 +4022,7 @@ i915_gem_object_unpin(struct drm_gem_object *obj)
33241 list_move_tail(&obj_priv->list,
33242 &dev_priv->mm.inactive_list);
33243 atomic_dec(&dev->pin_count);
33244- atomic_sub(obj->size, &dev->pin_memory);
33245+ atomic_sub_unchecked(obj->size, &dev->pin_memory);
33246 }
33247 i915_verify_inactive(dev, __FILE__, __LINE__);
33248 }
33249diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
33250index 63f28ad..f5469da 100644
33251--- a/drivers/gpu/drm/i915/i915_irq.c
33252+++ b/drivers/gpu/drm/i915/i915_irq.c
33253@@ -528,7 +528,7 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
33254 int irq_received;
33255 int ret = IRQ_NONE;
33256
33257- atomic_inc(&dev_priv->irq_received);
33258+ atomic_inc_unchecked(&dev_priv->irq_received);
33259
33260 if (IS_IGDNG(dev))
33261 return igdng_irq_handler(dev);
33262@@ -1021,7 +1021,7 @@ void i915_driver_irq_preinstall(struct drm_device * dev)
33263 {
33264 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33265
33266- atomic_set(&dev_priv->irq_received, 0);
33267+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33268
33269 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
33270 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
33271diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
33272index 5d9c6a7..d1b0e29 100644
33273--- a/drivers/gpu/drm/i915/intel_sdvo.c
33274+++ b/drivers/gpu/drm/i915/intel_sdvo.c
33275@@ -2795,7 +2795,9 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
33276 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
33277
33278 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
33279- intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
33280+ pax_open_kernel();
33281+ *(void **)&intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
33282+ pax_close_kernel();
33283
33284 /* Read the regs to test if we can talk to the device */
33285 for (i = 0; i < 0x40; i++) {
33286diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33287index be6c6b9..8615d9c 100644
33288--- a/drivers/gpu/drm/mga/mga_drv.h
33289+++ b/drivers/gpu/drm/mga/mga_drv.h
33290@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33291 u32 clear_cmd;
33292 u32 maccess;
33293
33294- atomic_t vbl_received; /**< Number of vblanks received. */
33295+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33296 wait_queue_head_t fence_queue;
33297- atomic_t last_fence_retired;
33298+ atomic_unchecked_t last_fence_retired;
33299 u32 next_fence_to_post;
33300
33301 unsigned int fb_cpp;
33302diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33303index daa6041..a28a5da 100644
33304--- a/drivers/gpu/drm/mga/mga_irq.c
33305+++ b/drivers/gpu/drm/mga/mga_irq.c
33306@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33307 if (crtc != 0)
33308 return 0;
33309
33310- return atomic_read(&dev_priv->vbl_received);
33311+ return atomic_read_unchecked(&dev_priv->vbl_received);
33312 }
33313
33314
33315@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33316 /* VBLANK interrupt */
33317 if (status & MGA_VLINEPEN) {
33318 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33319- atomic_inc(&dev_priv->vbl_received);
33320+ atomic_inc_unchecked(&dev_priv->vbl_received);
33321 drm_handle_vblank(dev, 0);
33322 handled = 1;
33323 }
33324@@ -80,7 +80,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33325 MGA_WRITE(MGA_PRIMEND, prim_end);
33326 }
33327
33328- atomic_inc(&dev_priv->last_fence_retired);
33329+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
33330 DRM_WAKEUP(&dev_priv->fence_queue);
33331 handled = 1;
33332 }
33333@@ -131,7 +131,7 @@ int mga_driver_fence_wait(struct drm_device * dev, unsigned int *sequence)
33334 * using fences.
33335 */
33336 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33337- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33338+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33339 - *sequence) <= (1 << 23)));
33340
33341 *sequence = cur_fence;
33342diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33343index 4c39a40..b22a9ea 100644
33344--- a/drivers/gpu/drm/r128/r128_cce.c
33345+++ b/drivers/gpu/drm/r128/r128_cce.c
33346@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
33347
33348 /* GH: Simple idle check.
33349 */
33350- atomic_set(&dev_priv->idle_count, 0);
33351+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33352
33353 /* We don't support anything other than bus-mastering ring mode,
33354 * but the ring can be in either AGP or PCI space for the ring
33355diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33356index 3c60829..4faf484 100644
33357--- a/drivers/gpu/drm/r128/r128_drv.h
33358+++ b/drivers/gpu/drm/r128/r128_drv.h
33359@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33360 int is_pci;
33361 unsigned long cce_buffers_offset;
33362
33363- atomic_t idle_count;
33364+ atomic_unchecked_t idle_count;
33365
33366 int page_flipping;
33367 int current_page;
33368 u32 crtc_offset;
33369 u32 crtc_offset_cntl;
33370
33371- atomic_t vbl_received;
33372+ atomic_unchecked_t vbl_received;
33373
33374 u32 color_fmt;
33375 unsigned int front_offset;
33376diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33377index 69810fb..97bf17a 100644
33378--- a/drivers/gpu/drm/r128/r128_irq.c
33379+++ b/drivers/gpu/drm/r128/r128_irq.c
33380@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33381 if (crtc != 0)
33382 return 0;
33383
33384- return atomic_read(&dev_priv->vbl_received);
33385+ return atomic_read_unchecked(&dev_priv->vbl_received);
33386 }
33387
33388 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33389@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33390 /* VBLANK interrupt */
33391 if (status & R128_CRTC_VBLANK_INT) {
33392 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33393- atomic_inc(&dev_priv->vbl_received);
33394+ atomic_inc_unchecked(&dev_priv->vbl_received);
33395 drm_handle_vblank(dev, 0);
33396 return IRQ_HANDLED;
33397 }
33398diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33399index af2665c..51922d2 100644
33400--- a/drivers/gpu/drm/r128/r128_state.c
33401+++ b/drivers/gpu/drm/r128/r128_state.c
33402@@ -323,10 +323,10 @@ static void r128_clear_box(drm_r128_private_t * dev_priv,
33403
33404 static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
33405 {
33406- if (atomic_read(&dev_priv->idle_count) == 0) {
33407+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0) {
33408 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33409 } else {
33410- atomic_set(&dev_priv->idle_count, 0);
33411+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33412 }
33413 }
33414
33415diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
33416index dd72b91..8644b3c 100644
33417--- a/drivers/gpu/drm/radeon/atom.c
33418+++ b/drivers/gpu/drm/radeon/atom.c
33419@@ -1115,6 +1115,8 @@ struct atom_context *atom_parse(struct card_info *card, void *bios)
33420 char name[512];
33421 int i;
33422
33423+ pax_track_stack();
33424+
33425 ctx->card = card;
33426 ctx->bios = bios;
33427
33428diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33429index 0d79577..efaa7a5 100644
33430--- a/drivers/gpu/drm/radeon/mkregtable.c
33431+++ b/drivers/gpu/drm/radeon/mkregtable.c
33432@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33433 regex_t mask_rex;
33434 regmatch_t match[4];
33435 char buf[1024];
33436- size_t end;
33437+ long end;
33438 int len;
33439 int done = 0;
33440 int r;
33441 unsigned o;
33442 struct offset *offset;
33443 char last_reg_s[10];
33444- int last_reg;
33445+ unsigned long last_reg;
33446
33447 if (regcomp
33448 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33449diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
33450index 6735213..38c2c67 100644
33451--- a/drivers/gpu/drm/radeon/radeon.h
33452+++ b/drivers/gpu/drm/radeon/radeon.h
33453@@ -149,7 +149,7 @@ int radeon_pm_init(struct radeon_device *rdev);
33454 */
33455 struct radeon_fence_driver {
33456 uint32_t scratch_reg;
33457- atomic_t seq;
33458+ atomic_unchecked_t seq;
33459 uint32_t last_seq;
33460 unsigned long count_timeout;
33461 wait_queue_head_t queue;
33462@@ -640,7 +640,7 @@ struct radeon_asic {
33463 uint32_t offset, uint32_t obj_size);
33464 int (*clear_surface_reg)(struct radeon_device *rdev, int reg);
33465 void (*bandwidth_update)(struct radeon_device *rdev);
33466-};
33467+} __no_const;
33468
33469 /*
33470 * Asic structures
33471diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
33472index 4e928b9..d8b6008 100644
33473--- a/drivers/gpu/drm/radeon/radeon_atombios.c
33474+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
33475@@ -275,6 +275,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
33476 bool linkb;
33477 struct radeon_i2c_bus_rec ddc_bus;
33478
33479+ pax_track_stack();
33480+
33481 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
33482
33483 if (data_offset == 0)
33484@@ -520,13 +522,13 @@ static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
33485 }
33486 }
33487
33488-struct bios_connector {
33489+static struct bios_connector {
33490 bool valid;
33491 uint16_t line_mux;
33492 uint16_t devices;
33493 int connector_type;
33494 struct radeon_i2c_bus_rec ddc_bus;
33495-};
33496+} bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
33497
33498 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
33499 drm_device
33500@@ -542,7 +544,6 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
33501 uint8_t dac;
33502 union atom_supported_devices *supported_devices;
33503 int i, j;
33504- struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
33505
33506 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
33507
33508diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
33509index 083a181..ccccae0 100644
33510--- a/drivers/gpu/drm/radeon/radeon_display.c
33511+++ b/drivers/gpu/drm/radeon/radeon_display.c
33512@@ -482,7 +482,7 @@ void radeon_compute_pll(struct radeon_pll *pll,
33513
33514 if (flags & RADEON_PLL_PREFER_CLOSEST_LOWER) {
33515 error = freq - current_freq;
33516- error = error < 0 ? 0xffffffff : error;
33517+ error = (int32_t)error < 0 ? 0xffffffff : error;
33518 } else
33519 error = abs(current_freq - freq);
33520 vco_diff = abs(vco - best_vco);
33521diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33522index 76e4070..193fa7f 100644
33523--- a/drivers/gpu/drm/radeon/radeon_drv.h
33524+++ b/drivers/gpu/drm/radeon/radeon_drv.h
33525@@ -253,7 +253,7 @@ typedef struct drm_radeon_private {
33526
33527 /* SW interrupt */
33528 wait_queue_head_t swi_queue;
33529- atomic_t swi_emitted;
33530+ atomic_unchecked_t swi_emitted;
33531 int vblank_crtc;
33532 uint32_t irq_enable_reg;
33533 uint32_t r500_disp_irq_reg;
33534diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
33535index 3beb26d..6ce9c4a 100644
33536--- a/drivers/gpu/drm/radeon/radeon_fence.c
33537+++ b/drivers/gpu/drm/radeon/radeon_fence.c
33538@@ -47,7 +47,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
33539 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
33540 return 0;
33541 }
33542- fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
33543+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
33544 if (!rdev->cp.ready) {
33545 /* FIXME: cp is not running assume everythings is done right
33546 * away
33547@@ -364,7 +364,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
33548 return r;
33549 }
33550 WREG32(rdev->fence_drv.scratch_reg, 0);
33551- atomic_set(&rdev->fence_drv.seq, 0);
33552+ atomic_set_unchecked(&rdev->fence_drv.seq, 0);
33553 INIT_LIST_HEAD(&rdev->fence_drv.created);
33554 INIT_LIST_HEAD(&rdev->fence_drv.emited);
33555 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
33556diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33557index a1bf11d..4a123c0 100644
33558--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33559+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33560@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33561 request = compat_alloc_user_space(sizeof(*request));
33562 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33563 || __put_user(req32.param, &request->param)
33564- || __put_user((void __user *)(unsigned long)req32.value,
33565+ || __put_user((unsigned long)req32.value,
33566 &request->value))
33567 return -EFAULT;
33568
33569diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33570index b79ecc4..8dab92d 100644
33571--- a/drivers/gpu/drm/radeon/radeon_irq.c
33572+++ b/drivers/gpu/drm/radeon/radeon_irq.c
33573@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33574 unsigned int ret;
33575 RING_LOCALS;
33576
33577- atomic_inc(&dev_priv->swi_emitted);
33578- ret = atomic_read(&dev_priv->swi_emitted);
33579+ atomic_inc_unchecked(&dev_priv->swi_emitted);
33580+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33581
33582 BEGIN_RING(4);
33583 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33584@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33585 drm_radeon_private_t *dev_priv =
33586 (drm_radeon_private_t *) dev->dev_private;
33587
33588- atomic_set(&dev_priv->swi_emitted, 0);
33589+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33590 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33591
33592 dev->max_vblank_count = 0x001fffff;
33593diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33594index 4747910..48ca4b3 100644
33595--- a/drivers/gpu/drm/radeon/radeon_state.c
33596+++ b/drivers/gpu/drm/radeon/radeon_state.c
33597@@ -3021,7 +3021,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33598 {
33599 drm_radeon_private_t *dev_priv = dev->dev_private;
33600 drm_radeon_getparam_t *param = data;
33601- int value;
33602+ int value = 0;
33603
33604 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33605
33606diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33607index 1381e06..0e53b17 100644
33608--- a/drivers/gpu/drm/radeon/radeon_ttm.c
33609+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33610@@ -535,27 +535,10 @@ void radeon_ttm_fini(struct radeon_device *rdev)
33611 DRM_INFO("radeon: ttm finalized\n");
33612 }
33613
33614-static struct vm_operations_struct radeon_ttm_vm_ops;
33615-static const struct vm_operations_struct *ttm_vm_ops = NULL;
33616-
33617-static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33618-{
33619- struct ttm_buffer_object *bo;
33620- int r;
33621-
33622- bo = (struct ttm_buffer_object *)vma->vm_private_data;
33623- if (bo == NULL) {
33624- return VM_FAULT_NOPAGE;
33625- }
33626- r = ttm_vm_ops->fault(vma, vmf);
33627- return r;
33628-}
33629-
33630 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33631 {
33632 struct drm_file *file_priv;
33633 struct radeon_device *rdev;
33634- int r;
33635
33636 if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET)) {
33637 return drm_mmap(filp, vma);
33638@@ -563,20 +546,9 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33639
33640 file_priv = (struct drm_file *)filp->private_data;
33641 rdev = file_priv->minor->dev->dev_private;
33642- if (rdev == NULL) {
33643+ if (!rdev)
33644 return -EINVAL;
33645- }
33646- r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
33647- if (unlikely(r != 0)) {
33648- return r;
33649- }
33650- if (unlikely(ttm_vm_ops == NULL)) {
33651- ttm_vm_ops = vma->vm_ops;
33652- radeon_ttm_vm_ops = *ttm_vm_ops;
33653- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33654- }
33655- vma->vm_ops = &radeon_ttm_vm_ops;
33656- return 0;
33657+ return ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
33658 }
33659
33660
33661diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33662index b12ff76..0bd0c6e 100644
33663--- a/drivers/gpu/drm/radeon/rs690.c
33664+++ b/drivers/gpu/drm/radeon/rs690.c
33665@@ -302,9 +302,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33666 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33667 rdev->pm.sideport_bandwidth.full)
33668 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33669- read_delay_latency.full = rfixed_const(370 * 800 * 1000);
33670+ read_delay_latency.full = rfixed_const(800 * 1000);
33671 read_delay_latency.full = rfixed_div(read_delay_latency,
33672 rdev->pm.igp_sideport_mclk);
33673+ a.full = rfixed_const(370);
33674+ read_delay_latency.full = rfixed_mul(read_delay_latency, a);
33675 } else {
33676 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33677 rdev->pm.k8_bandwidth.full)
33678diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
33679index 0ed436e..e6e7ce3 100644
33680--- a/drivers/gpu/drm/ttm/ttm_bo.c
33681+++ b/drivers/gpu/drm/ttm/ttm_bo.c
33682@@ -67,7 +67,7 @@ static struct attribute *ttm_bo_global_attrs[] = {
33683 NULL
33684 };
33685
33686-static struct sysfs_ops ttm_bo_global_ops = {
33687+static const struct sysfs_ops ttm_bo_global_ops = {
33688 .show = &ttm_bo_global_show
33689 };
33690
33691diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
33692index 1c040d0..f9e4af8 100644
33693--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
33694+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
33695@@ -73,7 +73,7 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33696 {
33697 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
33698 vma->vm_private_data;
33699- struct ttm_bo_device *bdev = bo->bdev;
33700+ struct ttm_bo_device *bdev;
33701 unsigned long bus_base;
33702 unsigned long bus_offset;
33703 unsigned long bus_size;
33704@@ -88,6 +88,10 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33705 unsigned long address = (unsigned long)vmf->virtual_address;
33706 int retval = VM_FAULT_NOPAGE;
33707
33708+ if (!bo)
33709+ return VM_FAULT_NOPAGE;
33710+ bdev = bo->bdev;
33711+
33712 /*
33713 * Work around locking order reversal in fault / nopfn
33714 * between mmap_sem and bo_reserve: Perform a trylock operation
33715diff --git a/drivers/gpu/drm/ttm/ttm_global.c b/drivers/gpu/drm/ttm/ttm_global.c
33716index b170071..28ae90e 100644
33717--- a/drivers/gpu/drm/ttm/ttm_global.c
33718+++ b/drivers/gpu/drm/ttm/ttm_global.c
33719@@ -36,7 +36,7 @@
33720 struct ttm_global_item {
33721 struct mutex mutex;
33722 void *object;
33723- int refcount;
33724+ atomic_t refcount;
33725 };
33726
33727 static struct ttm_global_item glob[TTM_GLOBAL_NUM];
33728@@ -49,7 +49,7 @@ void ttm_global_init(void)
33729 struct ttm_global_item *item = &glob[i];
33730 mutex_init(&item->mutex);
33731 item->object = NULL;
33732- item->refcount = 0;
33733+ atomic_set(&item->refcount, 0);
33734 }
33735 }
33736
33737@@ -59,7 +59,7 @@ void ttm_global_release(void)
33738 for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
33739 struct ttm_global_item *item = &glob[i];
33740 BUG_ON(item->object != NULL);
33741- BUG_ON(item->refcount != 0);
33742+ BUG_ON(atomic_read(&item->refcount) != 0);
33743 }
33744 }
33745
33746@@ -70,7 +70,7 @@ int ttm_global_item_ref(struct ttm_global_reference *ref)
33747 void *object;
33748
33749 mutex_lock(&item->mutex);
33750- if (item->refcount == 0) {
33751+ if (atomic_read(&item->refcount) == 0) {
33752 item->object = kzalloc(ref->size, GFP_KERNEL);
33753 if (unlikely(item->object == NULL)) {
33754 ret = -ENOMEM;
33755@@ -83,7 +83,7 @@ int ttm_global_item_ref(struct ttm_global_reference *ref)
33756 goto out_err;
33757
33758 }
33759- ++item->refcount;
33760+ atomic_inc(&item->refcount);
33761 ref->object = item->object;
33762 object = item->object;
33763 mutex_unlock(&item->mutex);
33764@@ -100,9 +100,9 @@ void ttm_global_item_unref(struct ttm_global_reference *ref)
33765 struct ttm_global_item *item = &glob[ref->global_type];
33766
33767 mutex_lock(&item->mutex);
33768- BUG_ON(item->refcount == 0);
33769+ BUG_ON(atomic_read(&item->refcount) == 0);
33770 BUG_ON(ref->object != item->object);
33771- if (--item->refcount == 0) {
33772+ if (atomic_dec_and_test(&item->refcount)) {
33773 ref->release(ref);
33774 item->object = NULL;
33775 }
33776diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
33777index 072c281..d8ef483 100644
33778--- a/drivers/gpu/drm/ttm/ttm_memory.c
33779+++ b/drivers/gpu/drm/ttm/ttm_memory.c
33780@@ -152,7 +152,7 @@ static struct attribute *ttm_mem_zone_attrs[] = {
33781 NULL
33782 };
33783
33784-static struct sysfs_ops ttm_mem_zone_ops = {
33785+static const struct sysfs_ops ttm_mem_zone_ops = {
33786 .show = &ttm_mem_zone_show,
33787 .store = &ttm_mem_zone_store
33788 };
33789diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33790index cafcb84..b8e66cc 100644
33791--- a/drivers/gpu/drm/via/via_drv.h
33792+++ b/drivers/gpu/drm/via/via_drv.h
33793@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33794 typedef uint32_t maskarray_t[5];
33795
33796 typedef struct drm_via_irq {
33797- atomic_t irq_received;
33798+ atomic_unchecked_t irq_received;
33799 uint32_t pending_mask;
33800 uint32_t enable_mask;
33801 wait_queue_head_t irq_queue;
33802@@ -75,7 +75,7 @@ typedef struct drm_via_private {
33803 struct timeval last_vblank;
33804 int last_vblank_valid;
33805 unsigned usec_per_vblank;
33806- atomic_t vbl_received;
33807+ atomic_unchecked_t vbl_received;
33808 drm_via_state_t hc_state;
33809 char pci_buf[VIA_PCI_BUF_SIZE];
33810 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33811diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33812index 5935b88..127a8a6 100644
33813--- a/drivers/gpu/drm/via/via_irq.c
33814+++ b/drivers/gpu/drm/via/via_irq.c
33815@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33816 if (crtc != 0)
33817 return 0;
33818
33819- return atomic_read(&dev_priv->vbl_received);
33820+ return atomic_read_unchecked(&dev_priv->vbl_received);
33821 }
33822
33823 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33824@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33825
33826 status = VIA_READ(VIA_REG_INTERRUPT);
33827 if (status & VIA_IRQ_VBLANK_PENDING) {
33828- atomic_inc(&dev_priv->vbl_received);
33829- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33830+ atomic_inc_unchecked(&dev_priv->vbl_received);
33831+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33832 do_gettimeofday(&cur_vblank);
33833 if (dev_priv->last_vblank_valid) {
33834 dev_priv->usec_per_vblank =
33835@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33836 dev_priv->last_vblank = cur_vblank;
33837 dev_priv->last_vblank_valid = 1;
33838 }
33839- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33840+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33841 DRM_DEBUG("US per vblank is: %u\n",
33842 dev_priv->usec_per_vblank);
33843 }
33844@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33845
33846 for (i = 0; i < dev_priv->num_irqs; ++i) {
33847 if (status & cur_irq->pending_mask) {
33848- atomic_inc(&cur_irq->irq_received);
33849+ atomic_inc_unchecked(&cur_irq->irq_received);
33850 DRM_WAKEUP(&cur_irq->irq_queue);
33851 handled = 1;
33852 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
33853@@ -244,11 +244,11 @@ via_driver_irq_wait(struct drm_device * dev, unsigned int irq, int force_sequenc
33854 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33855 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33856 masks[irq][4]));
33857- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33858+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33859 } else {
33860 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33861 (((cur_irq_sequence =
33862- atomic_read(&cur_irq->irq_received)) -
33863+ atomic_read_unchecked(&cur_irq->irq_received)) -
33864 *sequence) <= (1 << 23)));
33865 }
33866 *sequence = cur_irq_sequence;
33867@@ -286,7 +286,7 @@ void via_driver_irq_preinstall(struct drm_device * dev)
33868 }
33869
33870 for (i = 0; i < dev_priv->num_irqs; ++i) {
33871- atomic_set(&cur_irq->irq_received, 0);
33872+ atomic_set_unchecked(&cur_irq->irq_received, 0);
33873 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33874 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33875 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33876@@ -368,7 +368,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33877 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33878 case VIA_IRQ_RELATIVE:
33879 irqwait->request.sequence +=
33880- atomic_read(&cur_irq->irq_received);
33881+ atomic_read_unchecked(&cur_irq->irq_received);
33882 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33883 case VIA_IRQ_ABSOLUTE:
33884 break;
33885diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
33886index aa8688d..6a0140c 100644
33887--- a/drivers/gpu/vga/vgaarb.c
33888+++ b/drivers/gpu/vga/vgaarb.c
33889@@ -894,14 +894,20 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
33890 uc = &priv->cards[i];
33891 }
33892
33893- if (!uc)
33894- return -EINVAL;
33895+ if (!uc) {
33896+ ret_val = -EINVAL;
33897+ goto done;
33898+ }
33899
33900- if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0)
33901- return -EINVAL;
33902+ if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0) {
33903+ ret_val = -EINVAL;
33904+ goto done;
33905+ }
33906
33907- if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0)
33908- return -EINVAL;
33909+ if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0) {
33910+ ret_val = -EINVAL;
33911+ goto done;
33912+ }
33913
33914 vga_put(pdev, io_state);
33915
33916diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33917index 11f8069..4783396 100644
33918--- a/drivers/hid/hid-core.c
33919+++ b/drivers/hid/hid-core.c
33920@@ -1752,7 +1752,7 @@ static bool hid_ignore(struct hid_device *hdev)
33921
33922 int hid_add_device(struct hid_device *hdev)
33923 {
33924- static atomic_t id = ATOMIC_INIT(0);
33925+ static atomic_unchecked_t id = ATOMIC_INIT(0);
33926 int ret;
33927
33928 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33929@@ -1766,7 +1766,7 @@ int hid_add_device(struct hid_device *hdev)
33930 /* XXX hack, any other cleaner solution after the driver core
33931 * is converted to allow more than 20 bytes as the device name? */
33932 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33933- hdev->vendor, hdev->product, atomic_inc_return(&id));
33934+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33935
33936 ret = device_add(&hdev->dev);
33937 if (!ret)
33938diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33939index 8b6ee24..70f657d 100644
33940--- a/drivers/hid/usbhid/hiddev.c
33941+++ b/drivers/hid/usbhid/hiddev.c
33942@@ -617,7 +617,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33943 return put_user(HID_VERSION, (int __user *)arg);
33944
33945 case HIDIOCAPPLICATION:
33946- if (arg < 0 || arg >= hid->maxapplication)
33947+ if (arg >= hid->maxapplication)
33948 return -EINVAL;
33949
33950 for (i = 0; i < hid->maxcollection; i++)
33951diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
33952index 5d5ed69..f40533e 100644
33953--- a/drivers/hwmon/lis3lv02d.c
33954+++ b/drivers/hwmon/lis3lv02d.c
33955@@ -146,7 +146,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
33956 * the lid is closed. This leads to interrupts as soon as a little move
33957 * is done.
33958 */
33959- atomic_inc(&lis3_dev.count);
33960+ atomic_inc_unchecked(&lis3_dev.count);
33961
33962 wake_up_interruptible(&lis3_dev.misc_wait);
33963 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
33964@@ -160,7 +160,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
33965 if (test_and_set_bit(0, &lis3_dev.misc_opened))
33966 return -EBUSY; /* already open */
33967
33968- atomic_set(&lis3_dev.count, 0);
33969+ atomic_set_unchecked(&lis3_dev.count, 0);
33970
33971 /*
33972 * The sensor can generate interrupts for free-fall and direction
33973@@ -206,7 +206,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
33974 add_wait_queue(&lis3_dev.misc_wait, &wait);
33975 while (true) {
33976 set_current_state(TASK_INTERRUPTIBLE);
33977- data = atomic_xchg(&lis3_dev.count, 0);
33978+ data = atomic_xchg_unchecked(&lis3_dev.count, 0);
33979 if (data)
33980 break;
33981
33982@@ -244,7 +244,7 @@ out:
33983 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33984 {
33985 poll_wait(file, &lis3_dev.misc_wait, wait);
33986- if (atomic_read(&lis3_dev.count))
33987+ if (atomic_read_unchecked(&lis3_dev.count))
33988 return POLLIN | POLLRDNORM;
33989 return 0;
33990 }
33991diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h
33992index 7cdd76f..fe0efdf 100644
33993--- a/drivers/hwmon/lis3lv02d.h
33994+++ b/drivers/hwmon/lis3lv02d.h
33995@@ -201,7 +201,7 @@ struct lis3lv02d {
33996
33997 struct input_polled_dev *idev; /* input device */
33998 struct platform_device *pdev; /* platform device */
33999- atomic_t count; /* interrupt count after last read */
34000+ atomic_unchecked_t count; /* interrupt count after last read */
34001 int xcalib; /* calibrated null value for x */
34002 int ycalib; /* calibrated null value for y */
34003 int zcalib; /* calibrated null value for z */
34004diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
34005index 2040507..706ec1e 100644
34006--- a/drivers/hwmon/sht15.c
34007+++ b/drivers/hwmon/sht15.c
34008@@ -112,7 +112,7 @@ struct sht15_data {
34009 int supply_uV;
34010 int supply_uV_valid;
34011 struct work_struct update_supply_work;
34012- atomic_t interrupt_handled;
34013+ atomic_unchecked_t interrupt_handled;
34014 };
34015
34016 /**
34017@@ -245,13 +245,13 @@ static inline int sht15_update_single_val(struct sht15_data *data,
34018 return ret;
34019
34020 gpio_direction_input(data->pdata->gpio_data);
34021- atomic_set(&data->interrupt_handled, 0);
34022+ atomic_set_unchecked(&data->interrupt_handled, 0);
34023
34024 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34025 if (gpio_get_value(data->pdata->gpio_data) == 0) {
34026 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
34027 /* Only relevant if the interrupt hasn't occured. */
34028- if (!atomic_read(&data->interrupt_handled))
34029+ if (!atomic_read_unchecked(&data->interrupt_handled))
34030 schedule_work(&data->read_work);
34031 }
34032 ret = wait_event_timeout(data->wait_queue,
34033@@ -398,7 +398,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
34034 struct sht15_data *data = d;
34035 /* First disable the interrupt */
34036 disable_irq_nosync(irq);
34037- atomic_inc(&data->interrupt_handled);
34038+ atomic_inc_unchecked(&data->interrupt_handled);
34039 /* Then schedule a reading work struct */
34040 if (data->flag != SHT15_READING_NOTHING)
34041 schedule_work(&data->read_work);
34042@@ -449,11 +449,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
34043 here as could have gone low in meantime so verify
34044 it hasn't!
34045 */
34046- atomic_set(&data->interrupt_handled, 0);
34047+ atomic_set_unchecked(&data->interrupt_handled, 0);
34048 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34049 /* If still not occured or another handler has been scheduled */
34050 if (gpio_get_value(data->pdata->gpio_data)
34051- || atomic_read(&data->interrupt_handled))
34052+ || atomic_read_unchecked(&data->interrupt_handled))
34053 return;
34054 }
34055 /* Read the data back from the device */
34056diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
34057index 97851c5..cb40626 100644
34058--- a/drivers/hwmon/w83791d.c
34059+++ b/drivers/hwmon/w83791d.c
34060@@ -330,8 +330,8 @@ static int w83791d_detect(struct i2c_client *client, int kind,
34061 struct i2c_board_info *info);
34062 static int w83791d_remove(struct i2c_client *client);
34063
34064-static int w83791d_read(struct i2c_client *client, u8 register);
34065-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
34066+static int w83791d_read(struct i2c_client *client, u8 reg);
34067+static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
34068 static struct w83791d_data *w83791d_update_device(struct device *dev);
34069
34070 #ifdef DEBUG
34071diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
34072index 378fcb5..5e91fa8 100644
34073--- a/drivers/i2c/busses/i2c-amd756-s4882.c
34074+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
34075@@ -43,7 +43,7 @@
34076 extern struct i2c_adapter amd756_smbus;
34077
34078 static struct i2c_adapter *s4882_adapter;
34079-static struct i2c_algorithm *s4882_algo;
34080+static i2c_algorithm_no_const *s4882_algo;
34081
34082 /* Wrapper access functions for multiplexed SMBus */
34083 static DEFINE_MUTEX(amd756_lock);
34084diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
34085index 29015eb..af2d8e9 100644
34086--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
34087+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
34088@@ -41,7 +41,7 @@
34089 extern struct i2c_adapter *nforce2_smbus;
34090
34091 static struct i2c_adapter *s4985_adapter;
34092-static struct i2c_algorithm *s4985_algo;
34093+static i2c_algorithm_no_const *s4985_algo;
34094
34095 /* Wrapper access functions for multiplexed SMBus */
34096 static DEFINE_MUTEX(nforce2_lock);
34097diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
34098index 878f8ec..12376fc 100644
34099--- a/drivers/ide/aec62xx.c
34100+++ b/drivers/ide/aec62xx.c
34101@@ -180,7 +180,7 @@ static const struct ide_port_ops atp86x_port_ops = {
34102 .cable_detect = atp86x_cable_detect,
34103 };
34104
34105-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
34106+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
34107 { /* 0: AEC6210 */
34108 .name = DRV_NAME,
34109 .init_chipset = init_chipset_aec62xx,
34110diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
34111index e59b6de..4b4fc65 100644
34112--- a/drivers/ide/alim15x3.c
34113+++ b/drivers/ide/alim15x3.c
34114@@ -509,7 +509,7 @@ static const struct ide_dma_ops ali_dma_ops = {
34115 .dma_sff_read_status = ide_dma_sff_read_status,
34116 };
34117
34118-static const struct ide_port_info ali15x3_chipset __devinitdata = {
34119+static const struct ide_port_info ali15x3_chipset __devinitconst = {
34120 .name = DRV_NAME,
34121 .init_chipset = init_chipset_ali15x3,
34122 .init_hwif = init_hwif_ali15x3,
34123diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
34124index 628cd2e..087a414 100644
34125--- a/drivers/ide/amd74xx.c
34126+++ b/drivers/ide/amd74xx.c
34127@@ -221,7 +221,7 @@ static const struct ide_port_ops amd_port_ops = {
34128 .udma_mask = udma, \
34129 }
34130
34131-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
34132+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
34133 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
34134 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
34135 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
34136diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
34137index 837322b..837fd71 100644
34138--- a/drivers/ide/atiixp.c
34139+++ b/drivers/ide/atiixp.c
34140@@ -137,7 +137,7 @@ static const struct ide_port_ops atiixp_port_ops = {
34141 .cable_detect = atiixp_cable_detect,
34142 };
34143
34144-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
34145+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
34146 { /* 0: IXP200/300/400/700 */
34147 .name = DRV_NAME,
34148 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
34149diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
34150index ca0c46f..d55318a 100644
34151--- a/drivers/ide/cmd64x.c
34152+++ b/drivers/ide/cmd64x.c
34153@@ -372,7 +372,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
34154 .dma_sff_read_status = ide_dma_sff_read_status,
34155 };
34156
34157-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
34158+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
34159 { /* 0: CMD643 */
34160 .name = DRV_NAME,
34161 .init_chipset = init_chipset_cmd64x,
34162diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
34163index 09f98ed..cebc5bc 100644
34164--- a/drivers/ide/cs5520.c
34165+++ b/drivers/ide/cs5520.c
34166@@ -93,7 +93,7 @@ static const struct ide_port_ops cs5520_port_ops = {
34167 .set_dma_mode = cs5520_set_dma_mode,
34168 };
34169
34170-static const struct ide_port_info cyrix_chipset __devinitdata = {
34171+static const struct ide_port_info cyrix_chipset __devinitconst = {
34172 .name = DRV_NAME,
34173 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
34174 .port_ops = &cs5520_port_ops,
34175diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
34176index 40bf05e..7d58ca0 100644
34177--- a/drivers/ide/cs5530.c
34178+++ b/drivers/ide/cs5530.c
34179@@ -244,7 +244,7 @@ static const struct ide_port_ops cs5530_port_ops = {
34180 .udma_filter = cs5530_udma_filter,
34181 };
34182
34183-static const struct ide_port_info cs5530_chipset __devinitdata = {
34184+static const struct ide_port_info cs5530_chipset __devinitconst = {
34185 .name = DRV_NAME,
34186 .init_chipset = init_chipset_cs5530,
34187 .init_hwif = init_hwif_cs5530,
34188diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
34189index 983d957..53e6172 100644
34190--- a/drivers/ide/cs5535.c
34191+++ b/drivers/ide/cs5535.c
34192@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
34193 .cable_detect = cs5535_cable_detect,
34194 };
34195
34196-static const struct ide_port_info cs5535_chipset __devinitdata = {
34197+static const struct ide_port_info cs5535_chipset __devinitconst = {
34198 .name = DRV_NAME,
34199 .port_ops = &cs5535_port_ops,
34200 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
34201diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
34202index 74fc540..8e933d8 100644
34203--- a/drivers/ide/cy82c693.c
34204+++ b/drivers/ide/cy82c693.c
34205@@ -288,7 +288,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
34206 .set_dma_mode = cy82c693_set_dma_mode,
34207 };
34208
34209-static const struct ide_port_info cy82c693_chipset __devinitdata = {
34210+static const struct ide_port_info cy82c693_chipset __devinitconst = {
34211 .name = DRV_NAME,
34212 .init_iops = init_iops_cy82c693,
34213 .port_ops = &cy82c693_port_ops,
34214diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
34215index 7ce68ef..e78197d 100644
34216--- a/drivers/ide/hpt366.c
34217+++ b/drivers/ide/hpt366.c
34218@@ -507,7 +507,7 @@ static struct hpt_timings hpt37x_timings = {
34219 }
34220 };
34221
34222-static const struct hpt_info hpt36x __devinitdata = {
34223+static const struct hpt_info hpt36x __devinitconst = {
34224 .chip_name = "HPT36x",
34225 .chip_type = HPT36x,
34226 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
34227@@ -515,7 +515,7 @@ static const struct hpt_info hpt36x __devinitdata = {
34228 .timings = &hpt36x_timings
34229 };
34230
34231-static const struct hpt_info hpt370 __devinitdata = {
34232+static const struct hpt_info hpt370 __devinitconst = {
34233 .chip_name = "HPT370",
34234 .chip_type = HPT370,
34235 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
34236@@ -523,7 +523,7 @@ static const struct hpt_info hpt370 __devinitdata = {
34237 .timings = &hpt37x_timings
34238 };
34239
34240-static const struct hpt_info hpt370a __devinitdata = {
34241+static const struct hpt_info hpt370a __devinitconst = {
34242 .chip_name = "HPT370A",
34243 .chip_type = HPT370A,
34244 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
34245@@ -531,7 +531,7 @@ static const struct hpt_info hpt370a __devinitdata = {
34246 .timings = &hpt37x_timings
34247 };
34248
34249-static const struct hpt_info hpt374 __devinitdata = {
34250+static const struct hpt_info hpt374 __devinitconst = {
34251 .chip_name = "HPT374",
34252 .chip_type = HPT374,
34253 .udma_mask = ATA_UDMA5,
34254@@ -539,7 +539,7 @@ static const struct hpt_info hpt374 __devinitdata = {
34255 .timings = &hpt37x_timings
34256 };
34257
34258-static const struct hpt_info hpt372 __devinitdata = {
34259+static const struct hpt_info hpt372 __devinitconst = {
34260 .chip_name = "HPT372",
34261 .chip_type = HPT372,
34262 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34263@@ -547,7 +547,7 @@ static const struct hpt_info hpt372 __devinitdata = {
34264 .timings = &hpt37x_timings
34265 };
34266
34267-static const struct hpt_info hpt372a __devinitdata = {
34268+static const struct hpt_info hpt372a __devinitconst = {
34269 .chip_name = "HPT372A",
34270 .chip_type = HPT372A,
34271 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34272@@ -555,7 +555,7 @@ static const struct hpt_info hpt372a __devinitdata = {
34273 .timings = &hpt37x_timings
34274 };
34275
34276-static const struct hpt_info hpt302 __devinitdata = {
34277+static const struct hpt_info hpt302 __devinitconst = {
34278 .chip_name = "HPT302",
34279 .chip_type = HPT302,
34280 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34281@@ -563,7 +563,7 @@ static const struct hpt_info hpt302 __devinitdata = {
34282 .timings = &hpt37x_timings
34283 };
34284
34285-static const struct hpt_info hpt371 __devinitdata = {
34286+static const struct hpt_info hpt371 __devinitconst = {
34287 .chip_name = "HPT371",
34288 .chip_type = HPT371,
34289 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34290@@ -571,7 +571,7 @@ static const struct hpt_info hpt371 __devinitdata = {
34291 .timings = &hpt37x_timings
34292 };
34293
34294-static const struct hpt_info hpt372n __devinitdata = {
34295+static const struct hpt_info hpt372n __devinitconst = {
34296 .chip_name = "HPT372N",
34297 .chip_type = HPT372N,
34298 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34299@@ -579,7 +579,7 @@ static const struct hpt_info hpt372n __devinitdata = {
34300 .timings = &hpt37x_timings
34301 };
34302
34303-static const struct hpt_info hpt302n __devinitdata = {
34304+static const struct hpt_info hpt302n __devinitconst = {
34305 .chip_name = "HPT302N",
34306 .chip_type = HPT302N,
34307 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34308@@ -587,7 +587,7 @@ static const struct hpt_info hpt302n __devinitdata = {
34309 .timings = &hpt37x_timings
34310 };
34311
34312-static const struct hpt_info hpt371n __devinitdata = {
34313+static const struct hpt_info hpt371n __devinitconst = {
34314 .chip_name = "HPT371N",
34315 .chip_type = HPT371N,
34316 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34317@@ -1422,7 +1422,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
34318 .dma_sff_read_status = ide_dma_sff_read_status,
34319 };
34320
34321-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
34322+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
34323 { /* 0: HPT36x */
34324 .name = DRV_NAME,
34325 .init_chipset = init_chipset_hpt366,
34326diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
34327index 2de76cc..74186a1 100644
34328--- a/drivers/ide/ide-cd.c
34329+++ b/drivers/ide/ide-cd.c
34330@@ -774,7 +774,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
34331 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
34332 if ((unsigned long)buf & alignment
34333 || blk_rq_bytes(rq) & q->dma_pad_mask
34334- || object_is_on_stack(buf))
34335+ || object_starts_on_stack(buf))
34336 drive->dma = 0;
34337 }
34338 }
34339diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
34340index fefbdfc..62ff465 100644
34341--- a/drivers/ide/ide-floppy.c
34342+++ b/drivers/ide/ide-floppy.c
34343@@ -373,6 +373,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
34344 u8 pc_buf[256], header_len, desc_cnt;
34345 int i, rc = 1, blocks, length;
34346
34347+ pax_track_stack();
34348+
34349 ide_debug_log(IDE_DBG_FUNC, "enter");
34350
34351 drive->bios_cyl = 0;
34352diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
34353index 39d4e01..11538ce 100644
34354--- a/drivers/ide/ide-pci-generic.c
34355+++ b/drivers/ide/ide-pci-generic.c
34356@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
34357 .udma_mask = ATA_UDMA6, \
34358 }
34359
34360-static const struct ide_port_info generic_chipsets[] __devinitdata = {
34361+static const struct ide_port_info generic_chipsets[] __devinitconst = {
34362 /* 0: Unknown */
34363 DECLARE_GENERIC_PCI_DEV(0),
34364
34365diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
34366index 0d266a5..aaca790 100644
34367--- a/drivers/ide/it8172.c
34368+++ b/drivers/ide/it8172.c
34369@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
34370 .set_dma_mode = it8172_set_dma_mode,
34371 };
34372
34373-static const struct ide_port_info it8172_port_info __devinitdata = {
34374+static const struct ide_port_info it8172_port_info __devinitconst = {
34375 .name = DRV_NAME,
34376 .port_ops = &it8172_port_ops,
34377 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
34378diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
34379index 4797616..4be488a 100644
34380--- a/drivers/ide/it8213.c
34381+++ b/drivers/ide/it8213.c
34382@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
34383 .cable_detect = it8213_cable_detect,
34384 };
34385
34386-static const struct ide_port_info it8213_chipset __devinitdata = {
34387+static const struct ide_port_info it8213_chipset __devinitconst = {
34388 .name = DRV_NAME,
34389 .enablebits = { {0x41, 0x80, 0x80} },
34390 .port_ops = &it8213_port_ops,
34391diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
34392index 51aa745..146ee60 100644
34393--- a/drivers/ide/it821x.c
34394+++ b/drivers/ide/it821x.c
34395@@ -627,7 +627,7 @@ static const struct ide_port_ops it821x_port_ops = {
34396 .cable_detect = it821x_cable_detect,
34397 };
34398
34399-static const struct ide_port_info it821x_chipset __devinitdata = {
34400+static const struct ide_port_info it821x_chipset __devinitconst = {
34401 .name = DRV_NAME,
34402 .init_chipset = init_chipset_it821x,
34403 .init_hwif = init_hwif_it821x,
34404diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
34405index bf2be64..9270098 100644
34406--- a/drivers/ide/jmicron.c
34407+++ b/drivers/ide/jmicron.c
34408@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
34409 .cable_detect = jmicron_cable_detect,
34410 };
34411
34412-static const struct ide_port_info jmicron_chipset __devinitdata = {
34413+static const struct ide_port_info jmicron_chipset __devinitconst = {
34414 .name = DRV_NAME,
34415 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
34416 .port_ops = &jmicron_port_ops,
34417diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
34418index 95327a2..73f78d8 100644
34419--- a/drivers/ide/ns87415.c
34420+++ b/drivers/ide/ns87415.c
34421@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
34422 .dma_sff_read_status = superio_dma_sff_read_status,
34423 };
34424
34425-static const struct ide_port_info ns87415_chipset __devinitdata = {
34426+static const struct ide_port_info ns87415_chipset __devinitconst = {
34427 .name = DRV_NAME,
34428 .init_hwif = init_hwif_ns87415,
34429 .tp_ops = &ns87415_tp_ops,
34430diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
34431index f1d70d6..e1de05b 100644
34432--- a/drivers/ide/opti621.c
34433+++ b/drivers/ide/opti621.c
34434@@ -202,7 +202,7 @@ static const struct ide_port_ops opti621_port_ops = {
34435 .set_pio_mode = opti621_set_pio_mode,
34436 };
34437
34438-static const struct ide_port_info opti621_chipset __devinitdata = {
34439+static const struct ide_port_info opti621_chipset __devinitconst = {
34440 .name = DRV_NAME,
34441 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
34442 .port_ops = &opti621_port_ops,
34443diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
34444index 65ba823..7311f4d 100644
34445--- a/drivers/ide/pdc202xx_new.c
34446+++ b/drivers/ide/pdc202xx_new.c
34447@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
34448 .udma_mask = udma, \
34449 }
34450
34451-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
34452+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
34453 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
34454 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
34455 };
34456diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
34457index cb812f3..af816ef 100644
34458--- a/drivers/ide/pdc202xx_old.c
34459+++ b/drivers/ide/pdc202xx_old.c
34460@@ -285,7 +285,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
34461 .max_sectors = sectors, \
34462 }
34463
34464-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
34465+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
34466 { /* 0: PDC20246 */
34467 .name = DRV_NAME,
34468 .init_chipset = init_chipset_pdc202xx,
34469diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
34470index bf14f39..15c4b98 100644
34471--- a/drivers/ide/piix.c
34472+++ b/drivers/ide/piix.c
34473@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
34474 .udma_mask = udma, \
34475 }
34476
34477-static const struct ide_port_info piix_pci_info[] __devinitdata = {
34478+static const struct ide_port_info piix_pci_info[] __devinitconst = {
34479 /* 0: MPIIX */
34480 { /*
34481 * MPIIX actually has only a single IDE channel mapped to
34482diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
34483index a6414a8..c04173e 100644
34484--- a/drivers/ide/rz1000.c
34485+++ b/drivers/ide/rz1000.c
34486@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
34487 }
34488 }
34489
34490-static const struct ide_port_info rz1000_chipset __devinitdata = {
34491+static const struct ide_port_info rz1000_chipset __devinitconst = {
34492 .name = DRV_NAME,
34493 .host_flags = IDE_HFLAG_NO_DMA,
34494 };
34495diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
34496index d467478..9203942 100644
34497--- a/drivers/ide/sc1200.c
34498+++ b/drivers/ide/sc1200.c
34499@@ -290,7 +290,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
34500 .dma_sff_read_status = ide_dma_sff_read_status,
34501 };
34502
34503-static const struct ide_port_info sc1200_chipset __devinitdata = {
34504+static const struct ide_port_info sc1200_chipset __devinitconst = {
34505 .name = DRV_NAME,
34506 .port_ops = &sc1200_port_ops,
34507 .dma_ops = &sc1200_dma_ops,
34508diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
34509index 1104bb3..59c5194 100644
34510--- a/drivers/ide/scc_pata.c
34511+++ b/drivers/ide/scc_pata.c
34512@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
34513 .dma_sff_read_status = scc_dma_sff_read_status,
34514 };
34515
34516-static const struct ide_port_info scc_chipset __devinitdata = {
34517+static const struct ide_port_info scc_chipset __devinitconst = {
34518 .name = "sccIDE",
34519 .init_iops = init_iops_scc,
34520 .init_dma = scc_init_dma,
34521diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
34522index b6554ef..6cc2cc3 100644
34523--- a/drivers/ide/serverworks.c
34524+++ b/drivers/ide/serverworks.c
34525@@ -353,7 +353,7 @@ static const struct ide_port_ops svwks_port_ops = {
34526 .cable_detect = svwks_cable_detect,
34527 };
34528
34529-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
34530+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
34531 { /* 0: OSB4 */
34532 .name = DRV_NAME,
34533 .init_chipset = init_chipset_svwks,
34534diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
34535index ab3db61..afed580 100644
34536--- a/drivers/ide/setup-pci.c
34537+++ b/drivers/ide/setup-pci.c
34538@@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
34539 int ret, i, n_ports = dev2 ? 4 : 2;
34540 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
34541
34542+ pax_track_stack();
34543+
34544 for (i = 0; i < n_ports / 2; i++) {
34545 ret = ide_setup_pci_controller(pdev[i], d, !i);
34546 if (ret < 0)
34547diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
34548index d95df52..0b03a39 100644
34549--- a/drivers/ide/siimage.c
34550+++ b/drivers/ide/siimage.c
34551@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
34552 .udma_mask = ATA_UDMA6, \
34553 }
34554
34555-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
34556+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
34557 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
34558 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
34559 };
34560diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
34561index 3b88eba..ca8699d 100644
34562--- a/drivers/ide/sis5513.c
34563+++ b/drivers/ide/sis5513.c
34564@@ -561,7 +561,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
34565 .cable_detect = sis_cable_detect,
34566 };
34567
34568-static const struct ide_port_info sis5513_chipset __devinitdata = {
34569+static const struct ide_port_info sis5513_chipset __devinitconst = {
34570 .name = DRV_NAME,
34571 .init_chipset = init_chipset_sis5513,
34572 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
34573diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
34574index d698da4..fca42a4 100644
34575--- a/drivers/ide/sl82c105.c
34576+++ b/drivers/ide/sl82c105.c
34577@@ -319,7 +319,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
34578 .dma_sff_read_status = ide_dma_sff_read_status,
34579 };
34580
34581-static const struct ide_port_info sl82c105_chipset __devinitdata = {
34582+static const struct ide_port_info sl82c105_chipset __devinitconst = {
34583 .name = DRV_NAME,
34584 .init_chipset = init_chipset_sl82c105,
34585 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
34586diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
34587index 1ccfb40..83d5779 100644
34588--- a/drivers/ide/slc90e66.c
34589+++ b/drivers/ide/slc90e66.c
34590@@ -131,7 +131,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
34591 .cable_detect = slc90e66_cable_detect,
34592 };
34593
34594-static const struct ide_port_info slc90e66_chipset __devinitdata = {
34595+static const struct ide_port_info slc90e66_chipset __devinitconst = {
34596 .name = DRV_NAME,
34597 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
34598 .port_ops = &slc90e66_port_ops,
34599diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
34600index 05a93d6..5f9e325 100644
34601--- a/drivers/ide/tc86c001.c
34602+++ b/drivers/ide/tc86c001.c
34603@@ -190,7 +190,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
34604 .dma_sff_read_status = ide_dma_sff_read_status,
34605 };
34606
34607-static const struct ide_port_info tc86c001_chipset __devinitdata = {
34608+static const struct ide_port_info tc86c001_chipset __devinitconst = {
34609 .name = DRV_NAME,
34610 .init_hwif = init_hwif_tc86c001,
34611 .port_ops = &tc86c001_port_ops,
34612diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
34613index 8773c3b..7907d6c 100644
34614--- a/drivers/ide/triflex.c
34615+++ b/drivers/ide/triflex.c
34616@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
34617 .set_dma_mode = triflex_set_mode,
34618 };
34619
34620-static const struct ide_port_info triflex_device __devinitdata = {
34621+static const struct ide_port_info triflex_device __devinitconst = {
34622 .name = DRV_NAME,
34623 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
34624 .port_ops = &triflex_port_ops,
34625diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
34626index 4b42ca0..e494a98 100644
34627--- a/drivers/ide/trm290.c
34628+++ b/drivers/ide/trm290.c
34629@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
34630 .dma_check = trm290_dma_check,
34631 };
34632
34633-static const struct ide_port_info trm290_chipset __devinitdata = {
34634+static const struct ide_port_info trm290_chipset __devinitconst = {
34635 .name = DRV_NAME,
34636 .init_hwif = init_hwif_trm290,
34637 .tp_ops = &trm290_tp_ops,
34638diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
34639index 028de26..520d5d5 100644
34640--- a/drivers/ide/via82cxxx.c
34641+++ b/drivers/ide/via82cxxx.c
34642@@ -374,7 +374,7 @@ static const struct ide_port_ops via_port_ops = {
34643 .cable_detect = via82cxxx_cable_detect,
34644 };
34645
34646-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
34647+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
34648 .name = DRV_NAME,
34649 .init_chipset = init_chipset_via82cxxx,
34650 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
34651diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
34652index 2cd00b5..14de699 100644
34653--- a/drivers/ieee1394/dv1394.c
34654+++ b/drivers/ieee1394/dv1394.c
34655@@ -739,7 +739,7 @@ static void frame_prepare(struct video_card *video, unsigned int this_frame)
34656 based upon DIF section and sequence
34657 */
34658
34659-static void inline
34660+static inline void
34661 frame_put_packet (struct frame *f, struct packet *p)
34662 {
34663 int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
34664diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c
34665index e947d8f..6a966b9 100644
34666--- a/drivers/ieee1394/hosts.c
34667+++ b/drivers/ieee1394/hosts.c
34668@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso *iso, enum isoctl_cmd command,
34669 }
34670
34671 static struct hpsb_host_driver dummy_driver = {
34672+ .name = "dummy",
34673 .transmit_packet = dummy_transmit_packet,
34674 .devctl = dummy_devctl,
34675 .isoctl = dummy_isoctl
34676diff --git a/drivers/ieee1394/init_ohci1394_dma.c b/drivers/ieee1394/init_ohci1394_dma.c
34677index ddaab6e..8d37435 100644
34678--- a/drivers/ieee1394/init_ohci1394_dma.c
34679+++ b/drivers/ieee1394/init_ohci1394_dma.c
34680@@ -257,7 +257,7 @@ void __init init_ohci1394_dma_on_all_controllers(void)
34681 for (func = 0; func < 8; func++) {
34682 u32 class = read_pci_config(num,slot,func,
34683 PCI_CLASS_REVISION);
34684- if ((class == 0xffffffff))
34685+ if (class == 0xffffffff)
34686 continue; /* No device at this func */
34687
34688 if (class>>8 != PCI_CLASS_SERIAL_FIREWIRE_OHCI)
34689diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
34690index 65c1429..5d8c11f 100644
34691--- a/drivers/ieee1394/ohci1394.c
34692+++ b/drivers/ieee1394/ohci1394.c
34693@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_DRIVER_NAME , ## args)
34694 printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
34695
34696 /* Module Parameters */
34697-static int phys_dma = 1;
34698+static int phys_dma;
34699 module_param(phys_dma, int, 0444);
34700-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
34701+MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
34702
34703 static void dma_trm_tasklet(unsigned long data);
34704 static void dma_trm_reset(struct dma_trm_ctx *d);
34705diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
34706index f199896..78c9fc8 100644
34707--- a/drivers/ieee1394/sbp2.c
34708+++ b/drivers/ieee1394/sbp2.c
34709@@ -2111,7 +2111,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver");
34710 MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
34711 MODULE_LICENSE("GPL");
34712
34713-static int sbp2_module_init(void)
34714+static int __init sbp2_module_init(void)
34715 {
34716 int ret;
34717
34718diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
34719index a5dea6b..0cefe8f 100644
34720--- a/drivers/infiniband/core/cm.c
34721+++ b/drivers/infiniband/core/cm.c
34722@@ -112,7 +112,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
34723
34724 struct cm_counter_group {
34725 struct kobject obj;
34726- atomic_long_t counter[CM_ATTR_COUNT];
34727+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
34728 };
34729
34730 struct cm_counter_attribute {
34731@@ -1386,7 +1386,7 @@ static void cm_dup_req_handler(struct cm_work *work,
34732 struct ib_mad_send_buf *msg = NULL;
34733 int ret;
34734
34735- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34736+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34737 counter[CM_REQ_COUNTER]);
34738
34739 /* Quick state check to discard duplicate REQs. */
34740@@ -1764,7 +1764,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
34741 if (!cm_id_priv)
34742 return;
34743
34744- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34745+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34746 counter[CM_REP_COUNTER]);
34747 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
34748 if (ret)
34749@@ -1931,7 +1931,7 @@ static int cm_rtu_handler(struct cm_work *work)
34750 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
34751 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
34752 spin_unlock_irq(&cm_id_priv->lock);
34753- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34754+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34755 counter[CM_RTU_COUNTER]);
34756 goto out;
34757 }
34758@@ -2110,7 +2110,7 @@ static int cm_dreq_handler(struct cm_work *work)
34759 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
34760 dreq_msg->local_comm_id);
34761 if (!cm_id_priv) {
34762- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34763+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34764 counter[CM_DREQ_COUNTER]);
34765 cm_issue_drep(work->port, work->mad_recv_wc);
34766 return -EINVAL;
34767@@ -2131,7 +2131,7 @@ static int cm_dreq_handler(struct cm_work *work)
34768 case IB_CM_MRA_REP_RCVD:
34769 break;
34770 case IB_CM_TIMEWAIT:
34771- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34772+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34773 counter[CM_DREQ_COUNTER]);
34774 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34775 goto unlock;
34776@@ -2145,7 +2145,7 @@ static int cm_dreq_handler(struct cm_work *work)
34777 cm_free_msg(msg);
34778 goto deref;
34779 case IB_CM_DREQ_RCVD:
34780- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34781+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34782 counter[CM_DREQ_COUNTER]);
34783 goto unlock;
34784 default:
34785@@ -2501,7 +2501,7 @@ static int cm_mra_handler(struct cm_work *work)
34786 ib_modify_mad(cm_id_priv->av.port->mad_agent,
34787 cm_id_priv->msg, timeout)) {
34788 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
34789- atomic_long_inc(&work->port->
34790+ atomic_long_inc_unchecked(&work->port->
34791 counter_group[CM_RECV_DUPLICATES].
34792 counter[CM_MRA_COUNTER]);
34793 goto out;
34794@@ -2510,7 +2510,7 @@ static int cm_mra_handler(struct cm_work *work)
34795 break;
34796 case IB_CM_MRA_REQ_RCVD:
34797 case IB_CM_MRA_REP_RCVD:
34798- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34799+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34800 counter[CM_MRA_COUNTER]);
34801 /* fall through */
34802 default:
34803@@ -2672,7 +2672,7 @@ static int cm_lap_handler(struct cm_work *work)
34804 case IB_CM_LAP_IDLE:
34805 break;
34806 case IB_CM_MRA_LAP_SENT:
34807- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34808+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34809 counter[CM_LAP_COUNTER]);
34810 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34811 goto unlock;
34812@@ -2688,7 +2688,7 @@ static int cm_lap_handler(struct cm_work *work)
34813 cm_free_msg(msg);
34814 goto deref;
34815 case IB_CM_LAP_RCVD:
34816- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34817+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34818 counter[CM_LAP_COUNTER]);
34819 goto unlock;
34820 default:
34821@@ -2972,7 +2972,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
34822 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34823 if (cur_cm_id_priv) {
34824 spin_unlock_irq(&cm.lock);
34825- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34826+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34827 counter[CM_SIDR_REQ_COUNTER]);
34828 goto out; /* Duplicate message. */
34829 }
34830@@ -3184,10 +3184,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34831 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34832 msg->retries = 1;
34833
34834- atomic_long_add(1 + msg->retries,
34835+ atomic_long_add_unchecked(1 + msg->retries,
34836 &port->counter_group[CM_XMIT].counter[attr_index]);
34837 if (msg->retries)
34838- atomic_long_add(msg->retries,
34839+ atomic_long_add_unchecked(msg->retries,
34840 &port->counter_group[CM_XMIT_RETRIES].
34841 counter[attr_index]);
34842
34843@@ -3397,7 +3397,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34844 }
34845
34846 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34847- atomic_long_inc(&port->counter_group[CM_RECV].
34848+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34849 counter[attr_id - CM_ATTR_ID_OFFSET]);
34850
34851 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34852@@ -3595,10 +3595,10 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34853 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34854
34855 return sprintf(buf, "%ld\n",
34856- atomic_long_read(&group->counter[cm_attr->index]));
34857+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34858 }
34859
34860-static struct sysfs_ops cm_counter_ops = {
34861+static const struct sysfs_ops cm_counter_ops = {
34862 .show = cm_show_counter
34863 };
34864
34865diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
34866index 8fd3a6f..61d8075 100644
34867--- a/drivers/infiniband/core/cma.c
34868+++ b/drivers/infiniband/core/cma.c
34869@@ -2267,6 +2267,9 @@ static int cma_resolve_ib_udp(struct rdma_id_private *id_priv,
34870
34871 req.private_data_len = sizeof(struct cma_hdr) +
34872 conn_param->private_data_len;
34873+ if (req.private_data_len < conn_param->private_data_len)
34874+ return -EINVAL;
34875+
34876 req.private_data = kzalloc(req.private_data_len, GFP_ATOMIC);
34877 if (!req.private_data)
34878 return -ENOMEM;
34879@@ -2314,6 +2317,9 @@ static int cma_connect_ib(struct rdma_id_private *id_priv,
34880 memset(&req, 0, sizeof req);
34881 offset = cma_user_data_offset(id_priv->id.ps);
34882 req.private_data_len = offset + conn_param->private_data_len;
34883+ if (req.private_data_len < conn_param->private_data_len)
34884+ return -EINVAL;
34885+
34886 private_data = kzalloc(req.private_data_len, GFP_ATOMIC);
34887 if (!private_data)
34888 return -ENOMEM;
34889diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34890index 4507043..14ad522 100644
34891--- a/drivers/infiniband/core/fmr_pool.c
34892+++ b/drivers/infiniband/core/fmr_pool.c
34893@@ -97,8 +97,8 @@ struct ib_fmr_pool {
34894
34895 struct task_struct *thread;
34896
34897- atomic_t req_ser;
34898- atomic_t flush_ser;
34899+ atomic_unchecked_t req_ser;
34900+ atomic_unchecked_t flush_ser;
34901
34902 wait_queue_head_t force_wait;
34903 };
34904@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34905 struct ib_fmr_pool *pool = pool_ptr;
34906
34907 do {
34908- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34909+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34910 ib_fmr_batch_release(pool);
34911
34912- atomic_inc(&pool->flush_ser);
34913+ atomic_inc_unchecked(&pool->flush_ser);
34914 wake_up_interruptible(&pool->force_wait);
34915
34916 if (pool->flush_function)
34917@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34918 }
34919
34920 set_current_state(TASK_INTERRUPTIBLE);
34921- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34922+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34923 !kthread_should_stop())
34924 schedule();
34925 __set_current_state(TASK_RUNNING);
34926@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34927 pool->dirty_watermark = params->dirty_watermark;
34928 pool->dirty_len = 0;
34929 spin_lock_init(&pool->pool_lock);
34930- atomic_set(&pool->req_ser, 0);
34931- atomic_set(&pool->flush_ser, 0);
34932+ atomic_set_unchecked(&pool->req_ser, 0);
34933+ atomic_set_unchecked(&pool->flush_ser, 0);
34934 init_waitqueue_head(&pool->force_wait);
34935
34936 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34937@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34938 }
34939 spin_unlock_irq(&pool->pool_lock);
34940
34941- serial = atomic_inc_return(&pool->req_ser);
34942+ serial = atomic_inc_return_unchecked(&pool->req_ser);
34943 wake_up_process(pool->thread);
34944
34945 if (wait_event_interruptible(pool->force_wait,
34946- atomic_read(&pool->flush_ser) - serial >= 0))
34947+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34948 return -EINTR;
34949
34950 return 0;
34951@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34952 } else {
34953 list_add_tail(&fmr->list, &pool->dirty_list);
34954 if (++pool->dirty_len >= pool->dirty_watermark) {
34955- atomic_inc(&pool->req_ser);
34956+ atomic_inc_unchecked(&pool->req_ser);
34957 wake_up_process(pool->thread);
34958 }
34959 }
34960diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
34961index 158a214..1558bb7 100644
34962--- a/drivers/infiniband/core/sysfs.c
34963+++ b/drivers/infiniband/core/sysfs.c
34964@@ -79,7 +79,7 @@ static ssize_t port_attr_show(struct kobject *kobj,
34965 return port_attr->show(p, port_attr, buf);
34966 }
34967
34968-static struct sysfs_ops port_sysfs_ops = {
34969+static const struct sysfs_ops port_sysfs_ops = {
34970 .show = port_attr_show
34971 };
34972
34973diff --git a/drivers/infiniband/core/uverbs_marshall.c b/drivers/infiniband/core/uverbs_marshall.c
34974index 5440da0..1194ecb 100644
34975--- a/drivers/infiniband/core/uverbs_marshall.c
34976+++ b/drivers/infiniband/core/uverbs_marshall.c
34977@@ -40,18 +40,21 @@ void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
34978 dst->grh.sgid_index = src->grh.sgid_index;
34979 dst->grh.hop_limit = src->grh.hop_limit;
34980 dst->grh.traffic_class = src->grh.traffic_class;
34981+ memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
34982 dst->dlid = src->dlid;
34983 dst->sl = src->sl;
34984 dst->src_path_bits = src->src_path_bits;
34985 dst->static_rate = src->static_rate;
34986 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0;
34987 dst->port_num = src->port_num;
34988+ dst->reserved = 0;
34989 }
34990 EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
34991
34992 void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
34993 struct ib_qp_attr *src)
34994 {
34995+ dst->qp_state = src->qp_state;
34996 dst->cur_qp_state = src->cur_qp_state;
34997 dst->path_mtu = src->path_mtu;
34998 dst->path_mig_state = src->path_mig_state;
34999@@ -83,6 +86,7 @@ void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
35000 dst->rnr_retry = src->rnr_retry;
35001 dst->alt_port_num = src->alt_port_num;
35002 dst->alt_timeout = src->alt_timeout;
35003+ memset(dst->reserved, 0, sizeof(dst->reserved));
35004 }
35005 EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
35006
35007diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
35008index 100da85..62e6b88 100644
35009--- a/drivers/infiniband/hw/ipath/ipath_fs.c
35010+++ b/drivers/infiniband/hw/ipath/ipath_fs.c
35011@@ -110,6 +110,8 @@ static ssize_t atomic_counters_read(struct file *file, char __user *buf,
35012 struct infinipath_counters counters;
35013 struct ipath_devdata *dd;
35014
35015+ pax_track_stack();
35016+
35017 dd = file->f_path.dentry->d_inode->i_private;
35018 dd->ipath_f_read_counters(dd, &counters);
35019
35020diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
35021index cbde0cf..afaf55c 100644
35022--- a/drivers/infiniband/hw/nes/nes.c
35023+++ b/drivers/infiniband/hw/nes/nes.c
35024@@ -102,7 +102,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
35025 LIST_HEAD(nes_adapter_list);
35026 static LIST_HEAD(nes_dev_list);
35027
35028-atomic_t qps_destroyed;
35029+atomic_unchecked_t qps_destroyed;
35030
35031 static unsigned int ee_flsh_adapter;
35032 static unsigned int sysfs_nonidx_addr;
35033@@ -259,7 +259,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
35034 struct nes_adapter *nesadapter = nesdev->nesadapter;
35035 u32 qp_id;
35036
35037- atomic_inc(&qps_destroyed);
35038+ atomic_inc_unchecked(&qps_destroyed);
35039
35040 /* Free the control structures */
35041
35042diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
35043index bcc6abc..9c76b2f 100644
35044--- a/drivers/infiniband/hw/nes/nes.h
35045+++ b/drivers/infiniband/hw/nes/nes.h
35046@@ -174,17 +174,17 @@ extern unsigned int nes_debug_level;
35047 extern unsigned int wqm_quanta;
35048 extern struct list_head nes_adapter_list;
35049
35050-extern atomic_t cm_connects;
35051-extern atomic_t cm_accepts;
35052-extern atomic_t cm_disconnects;
35053-extern atomic_t cm_closes;
35054-extern atomic_t cm_connecteds;
35055-extern atomic_t cm_connect_reqs;
35056-extern atomic_t cm_rejects;
35057-extern atomic_t mod_qp_timouts;
35058-extern atomic_t qps_created;
35059-extern atomic_t qps_destroyed;
35060-extern atomic_t sw_qps_destroyed;
35061+extern atomic_unchecked_t cm_connects;
35062+extern atomic_unchecked_t cm_accepts;
35063+extern atomic_unchecked_t cm_disconnects;
35064+extern atomic_unchecked_t cm_closes;
35065+extern atomic_unchecked_t cm_connecteds;
35066+extern atomic_unchecked_t cm_connect_reqs;
35067+extern atomic_unchecked_t cm_rejects;
35068+extern atomic_unchecked_t mod_qp_timouts;
35069+extern atomic_unchecked_t qps_created;
35070+extern atomic_unchecked_t qps_destroyed;
35071+extern atomic_unchecked_t sw_qps_destroyed;
35072 extern u32 mh_detected;
35073 extern u32 mh_pauses_sent;
35074 extern u32 cm_packets_sent;
35075@@ -196,11 +196,11 @@ extern u32 cm_packets_retrans;
35076 extern u32 cm_listens_created;
35077 extern u32 cm_listens_destroyed;
35078 extern u32 cm_backlog_drops;
35079-extern atomic_t cm_loopbacks;
35080-extern atomic_t cm_nodes_created;
35081-extern atomic_t cm_nodes_destroyed;
35082-extern atomic_t cm_accel_dropped_pkts;
35083-extern atomic_t cm_resets_recvd;
35084+extern atomic_unchecked_t cm_loopbacks;
35085+extern atomic_unchecked_t cm_nodes_created;
35086+extern atomic_unchecked_t cm_nodes_destroyed;
35087+extern atomic_unchecked_t cm_accel_dropped_pkts;
35088+extern atomic_unchecked_t cm_resets_recvd;
35089
35090 extern u32 int_mod_timer_init;
35091 extern u32 int_mod_cq_depth_256;
35092diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
35093index 73473db..5ed06e8 100644
35094--- a/drivers/infiniband/hw/nes/nes_cm.c
35095+++ b/drivers/infiniband/hw/nes/nes_cm.c
35096@@ -69,11 +69,11 @@ u32 cm_packets_received;
35097 u32 cm_listens_created;
35098 u32 cm_listens_destroyed;
35099 u32 cm_backlog_drops;
35100-atomic_t cm_loopbacks;
35101-atomic_t cm_nodes_created;
35102-atomic_t cm_nodes_destroyed;
35103-atomic_t cm_accel_dropped_pkts;
35104-atomic_t cm_resets_recvd;
35105+atomic_unchecked_t cm_loopbacks;
35106+atomic_unchecked_t cm_nodes_created;
35107+atomic_unchecked_t cm_nodes_destroyed;
35108+atomic_unchecked_t cm_accel_dropped_pkts;
35109+atomic_unchecked_t cm_resets_recvd;
35110
35111 static inline int mini_cm_accelerated(struct nes_cm_core *,
35112 struct nes_cm_node *);
35113@@ -149,13 +149,13 @@ static struct nes_cm_ops nes_cm_api = {
35114
35115 static struct nes_cm_core *g_cm_core;
35116
35117-atomic_t cm_connects;
35118-atomic_t cm_accepts;
35119-atomic_t cm_disconnects;
35120-atomic_t cm_closes;
35121-atomic_t cm_connecteds;
35122-atomic_t cm_connect_reqs;
35123-atomic_t cm_rejects;
35124+atomic_unchecked_t cm_connects;
35125+atomic_unchecked_t cm_accepts;
35126+atomic_unchecked_t cm_disconnects;
35127+atomic_unchecked_t cm_closes;
35128+atomic_unchecked_t cm_connecteds;
35129+atomic_unchecked_t cm_connect_reqs;
35130+atomic_unchecked_t cm_rejects;
35131
35132
35133 /**
35134@@ -1195,7 +1195,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
35135 cm_node->rem_mac);
35136
35137 add_hte_node(cm_core, cm_node);
35138- atomic_inc(&cm_nodes_created);
35139+ atomic_inc_unchecked(&cm_nodes_created);
35140
35141 return cm_node;
35142 }
35143@@ -1253,7 +1253,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
35144 }
35145
35146 atomic_dec(&cm_core->node_cnt);
35147- atomic_inc(&cm_nodes_destroyed);
35148+ atomic_inc_unchecked(&cm_nodes_destroyed);
35149 nesqp = cm_node->nesqp;
35150 if (nesqp) {
35151 nesqp->cm_node = NULL;
35152@@ -1320,7 +1320,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
35153
35154 static void drop_packet(struct sk_buff *skb)
35155 {
35156- atomic_inc(&cm_accel_dropped_pkts);
35157+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35158 dev_kfree_skb_any(skb);
35159 }
35160
35161@@ -1377,7 +1377,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
35162
35163 int reset = 0; /* whether to send reset in case of err.. */
35164 int passive_state;
35165- atomic_inc(&cm_resets_recvd);
35166+ atomic_inc_unchecked(&cm_resets_recvd);
35167 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
35168 " refcnt=%d\n", cm_node, cm_node->state,
35169 atomic_read(&cm_node->ref_count));
35170@@ -2000,7 +2000,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
35171 rem_ref_cm_node(cm_node->cm_core, cm_node);
35172 return NULL;
35173 }
35174- atomic_inc(&cm_loopbacks);
35175+ atomic_inc_unchecked(&cm_loopbacks);
35176 loopbackremotenode->loopbackpartner = cm_node;
35177 loopbackremotenode->tcp_cntxt.rcv_wscale =
35178 NES_CM_DEFAULT_RCV_WND_SCALE;
35179@@ -2262,7 +2262,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
35180 add_ref_cm_node(cm_node);
35181 } else if (cm_node->state == NES_CM_STATE_TSA) {
35182 rem_ref_cm_node(cm_core, cm_node);
35183- atomic_inc(&cm_accel_dropped_pkts);
35184+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35185 dev_kfree_skb_any(skb);
35186 break;
35187 }
35188@@ -2568,7 +2568,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35189
35190 if ((cm_id) && (cm_id->event_handler)) {
35191 if (issue_disconn) {
35192- atomic_inc(&cm_disconnects);
35193+ atomic_inc_unchecked(&cm_disconnects);
35194 cm_event.event = IW_CM_EVENT_DISCONNECT;
35195 cm_event.status = disconn_status;
35196 cm_event.local_addr = cm_id->local_addr;
35197@@ -2590,7 +2590,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35198 }
35199
35200 if (issue_close) {
35201- atomic_inc(&cm_closes);
35202+ atomic_inc_unchecked(&cm_closes);
35203 nes_disconnect(nesqp, 1);
35204
35205 cm_id->provider_data = nesqp;
35206@@ -2710,7 +2710,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35207
35208 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
35209 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
35210- atomic_inc(&cm_accepts);
35211+ atomic_inc_unchecked(&cm_accepts);
35212
35213 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
35214 atomic_read(&nesvnic->netdev->refcnt));
35215@@ -2919,7 +2919,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
35216
35217 struct nes_cm_core *cm_core;
35218
35219- atomic_inc(&cm_rejects);
35220+ atomic_inc_unchecked(&cm_rejects);
35221 cm_node = (struct nes_cm_node *) cm_id->provider_data;
35222 loopback = cm_node->loopbackpartner;
35223 cm_core = cm_node->cm_core;
35224@@ -2982,7 +2982,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35225 ntohl(cm_id->local_addr.sin_addr.s_addr),
35226 ntohs(cm_id->local_addr.sin_port));
35227
35228- atomic_inc(&cm_connects);
35229+ atomic_inc_unchecked(&cm_connects);
35230 nesqp->active_conn = 1;
35231
35232 /* cache the cm_id in the qp */
35233@@ -3195,7 +3195,7 @@ static void cm_event_connected(struct nes_cm_event *event)
35234 if (nesqp->destroyed) {
35235 return;
35236 }
35237- atomic_inc(&cm_connecteds);
35238+ atomic_inc_unchecked(&cm_connecteds);
35239 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
35240 " local port 0x%04X. jiffies = %lu.\n",
35241 nesqp->hwqp.qp_id,
35242@@ -3403,7 +3403,7 @@ static void cm_event_reset(struct nes_cm_event *event)
35243
35244 ret = cm_id->event_handler(cm_id, &cm_event);
35245 cm_id->add_ref(cm_id);
35246- atomic_inc(&cm_closes);
35247+ atomic_inc_unchecked(&cm_closes);
35248 cm_event.event = IW_CM_EVENT_CLOSE;
35249 cm_event.status = IW_CM_EVENT_STATUS_OK;
35250 cm_event.provider_data = cm_id->provider_data;
35251@@ -3439,7 +3439,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
35252 return;
35253 cm_id = cm_node->cm_id;
35254
35255- atomic_inc(&cm_connect_reqs);
35256+ atomic_inc_unchecked(&cm_connect_reqs);
35257 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35258 cm_node, cm_id, jiffies);
35259
35260@@ -3477,7 +3477,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
35261 return;
35262 cm_id = cm_node->cm_id;
35263
35264- atomic_inc(&cm_connect_reqs);
35265+ atomic_inc_unchecked(&cm_connect_reqs);
35266 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35267 cm_node, cm_id, jiffies);
35268
35269diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
35270index e593af3..870694a 100644
35271--- a/drivers/infiniband/hw/nes/nes_nic.c
35272+++ b/drivers/infiniband/hw/nes/nes_nic.c
35273@@ -1210,17 +1210,17 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35274 target_stat_values[++index] = mh_detected;
35275 target_stat_values[++index] = mh_pauses_sent;
35276 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
35277- target_stat_values[++index] = atomic_read(&cm_connects);
35278- target_stat_values[++index] = atomic_read(&cm_accepts);
35279- target_stat_values[++index] = atomic_read(&cm_disconnects);
35280- target_stat_values[++index] = atomic_read(&cm_connecteds);
35281- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
35282- target_stat_values[++index] = atomic_read(&cm_rejects);
35283- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
35284- target_stat_values[++index] = atomic_read(&qps_created);
35285- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
35286- target_stat_values[++index] = atomic_read(&qps_destroyed);
35287- target_stat_values[++index] = atomic_read(&cm_closes);
35288+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
35289+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
35290+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
35291+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
35292+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
35293+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
35294+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
35295+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
35296+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
35297+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
35298+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
35299 target_stat_values[++index] = cm_packets_sent;
35300 target_stat_values[++index] = cm_packets_bounced;
35301 target_stat_values[++index] = cm_packets_created;
35302@@ -1230,11 +1230,11 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35303 target_stat_values[++index] = cm_listens_created;
35304 target_stat_values[++index] = cm_listens_destroyed;
35305 target_stat_values[++index] = cm_backlog_drops;
35306- target_stat_values[++index] = atomic_read(&cm_loopbacks);
35307- target_stat_values[++index] = atomic_read(&cm_nodes_created);
35308- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
35309- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
35310- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
35311+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
35312+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
35313+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
35314+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
35315+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
35316 target_stat_values[++index] = int_mod_timer_init;
35317 target_stat_values[++index] = int_mod_cq_depth_1;
35318 target_stat_values[++index] = int_mod_cq_depth_4;
35319diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
35320index a680c42..f914deb 100644
35321--- a/drivers/infiniband/hw/nes/nes_verbs.c
35322+++ b/drivers/infiniband/hw/nes/nes_verbs.c
35323@@ -45,9 +45,9 @@
35324
35325 #include <rdma/ib_umem.h>
35326
35327-atomic_t mod_qp_timouts;
35328-atomic_t qps_created;
35329-atomic_t sw_qps_destroyed;
35330+atomic_unchecked_t mod_qp_timouts;
35331+atomic_unchecked_t qps_created;
35332+atomic_unchecked_t sw_qps_destroyed;
35333
35334 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
35335
35336@@ -1240,7 +1240,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
35337 if (init_attr->create_flags)
35338 return ERR_PTR(-EINVAL);
35339
35340- atomic_inc(&qps_created);
35341+ atomic_inc_unchecked(&qps_created);
35342 switch (init_attr->qp_type) {
35343 case IB_QPT_RC:
35344 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
35345@@ -1568,7 +1568,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
35346 struct iw_cm_event cm_event;
35347 int ret;
35348
35349- atomic_inc(&sw_qps_destroyed);
35350+ atomic_inc_unchecked(&sw_qps_destroyed);
35351 nesqp->destroyed = 1;
35352
35353 /* Blow away the connection if it exists. */
35354diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
35355index ac11be0..3883c04 100644
35356--- a/drivers/input/gameport/gameport.c
35357+++ b/drivers/input/gameport/gameport.c
35358@@ -515,13 +515,13 @@ EXPORT_SYMBOL(gameport_set_phys);
35359 */
35360 static void gameport_init_port(struct gameport *gameport)
35361 {
35362- static atomic_t gameport_no = ATOMIC_INIT(0);
35363+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
35364
35365 __module_get(THIS_MODULE);
35366
35367 mutex_init(&gameport->drv_mutex);
35368 device_initialize(&gameport->dev);
35369- dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1);
35370+ dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
35371 gameport->dev.bus = &gameport_bus;
35372 gameport->dev.release = gameport_release_port;
35373 if (gameport->parent)
35374diff --git a/drivers/input/input.c b/drivers/input/input.c
35375index c82ae82..8cfb9cb 100644
35376--- a/drivers/input/input.c
35377+++ b/drivers/input/input.c
35378@@ -1558,7 +1558,7 @@ EXPORT_SYMBOL(input_set_capability);
35379 */
35380 int input_register_device(struct input_dev *dev)
35381 {
35382- static atomic_t input_no = ATOMIC_INIT(0);
35383+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
35384 struct input_handler *handler;
35385 const char *path;
35386 int error;
35387@@ -1585,7 +1585,7 @@ int input_register_device(struct input_dev *dev)
35388 dev->setkeycode = input_default_setkeycode;
35389
35390 dev_set_name(&dev->dev, "input%ld",
35391- (unsigned long) atomic_inc_return(&input_no) - 1);
35392+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
35393
35394 error = device_add(&dev->dev);
35395 if (error)
35396diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
35397index ca13a6b..b032b0c 100644
35398--- a/drivers/input/joystick/sidewinder.c
35399+++ b/drivers/input/joystick/sidewinder.c
35400@@ -30,6 +30,7 @@
35401 #include <linux/kernel.h>
35402 #include <linux/module.h>
35403 #include <linux/slab.h>
35404+#include <linux/sched.h>
35405 #include <linux/init.h>
35406 #include <linux/input.h>
35407 #include <linux/gameport.h>
35408@@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
35409 unsigned char buf[SW_LENGTH];
35410 int i;
35411
35412+ pax_track_stack();
35413+
35414 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
35415
35416 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
35417diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
35418index 79e3edc..01412b9 100644
35419--- a/drivers/input/joystick/xpad.c
35420+++ b/drivers/input/joystick/xpad.c
35421@@ -621,7 +621,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
35422
35423 static int xpad_led_probe(struct usb_xpad *xpad)
35424 {
35425- static atomic_t led_seq = ATOMIC_INIT(0);
35426+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
35427 long led_no;
35428 struct xpad_led *led;
35429 struct led_classdev *led_cdev;
35430@@ -634,7 +634,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
35431 if (!led)
35432 return -ENOMEM;
35433
35434- led_no = (long)atomic_inc_return(&led_seq) - 1;
35435+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
35436
35437 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
35438 led->xpad = xpad;
35439diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
35440index 0236f0d..c7327f1 100644
35441--- a/drivers/input/serio/serio.c
35442+++ b/drivers/input/serio/serio.c
35443@@ -527,7 +527,7 @@ static void serio_release_port(struct device *dev)
35444 */
35445 static void serio_init_port(struct serio *serio)
35446 {
35447- static atomic_t serio_no = ATOMIC_INIT(0);
35448+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
35449
35450 __module_get(THIS_MODULE);
35451
35452@@ -536,7 +536,7 @@ static void serio_init_port(struct serio *serio)
35453 mutex_init(&serio->drv_mutex);
35454 device_initialize(&serio->dev);
35455 dev_set_name(&serio->dev, "serio%ld",
35456- (long)atomic_inc_return(&serio_no) - 1);
35457+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
35458 serio->dev.bus = &serio_bus;
35459 serio->dev.release = serio_release_port;
35460 if (serio->parent) {
35461diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
35462index 33dcd8d..2783d25 100644
35463--- a/drivers/isdn/gigaset/common.c
35464+++ b/drivers/isdn/gigaset/common.c
35465@@ -712,7 +712,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
35466 cs->commands_pending = 0;
35467 cs->cur_at_seq = 0;
35468 cs->gotfwver = -1;
35469- cs->open_count = 0;
35470+ local_set(&cs->open_count, 0);
35471 cs->dev = NULL;
35472 cs->tty = NULL;
35473 cs->tty_dev = NULL;
35474diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
35475index a2f6125..6a70677 100644
35476--- a/drivers/isdn/gigaset/gigaset.h
35477+++ b/drivers/isdn/gigaset/gigaset.h
35478@@ -34,6 +34,7 @@
35479 #include <linux/tty_driver.h>
35480 #include <linux/list.h>
35481 #include <asm/atomic.h>
35482+#include <asm/local.h>
35483
35484 #define GIG_VERSION {0,5,0,0}
35485 #define GIG_COMPAT {0,4,0,0}
35486@@ -446,7 +447,7 @@ struct cardstate {
35487 spinlock_t cmdlock;
35488 unsigned curlen, cmdbytes;
35489
35490- unsigned open_count;
35491+ local_t open_count;
35492 struct tty_struct *tty;
35493 struct tasklet_struct if_wake_tasklet;
35494 unsigned control_state;
35495diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
35496index b3065b8..c7e8cc9 100644
35497--- a/drivers/isdn/gigaset/interface.c
35498+++ b/drivers/isdn/gigaset/interface.c
35499@@ -165,9 +165,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
35500 return -ERESTARTSYS; // FIXME -EINTR?
35501 tty->driver_data = cs;
35502
35503- ++cs->open_count;
35504-
35505- if (cs->open_count == 1) {
35506+ if (local_inc_return(&cs->open_count) == 1) {
35507 spin_lock_irqsave(&cs->lock, flags);
35508 cs->tty = tty;
35509 spin_unlock_irqrestore(&cs->lock, flags);
35510@@ -195,10 +193,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
35511
35512 if (!cs->connected)
35513 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35514- else if (!cs->open_count)
35515+ else if (!local_read(&cs->open_count))
35516 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35517 else {
35518- if (!--cs->open_count) {
35519+ if (!local_dec_return(&cs->open_count)) {
35520 spin_lock_irqsave(&cs->lock, flags);
35521 cs->tty = NULL;
35522 spin_unlock_irqrestore(&cs->lock, flags);
35523@@ -233,7 +231,7 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
35524 if (!cs->connected) {
35525 gig_dbg(DEBUG_IF, "not connected");
35526 retval = -ENODEV;
35527- } else if (!cs->open_count)
35528+ } else if (!local_read(&cs->open_count))
35529 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35530 else {
35531 retval = 0;
35532@@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
35533 if (!cs->connected) {
35534 gig_dbg(DEBUG_IF, "not connected");
35535 retval = -ENODEV;
35536- } else if (!cs->open_count)
35537+ } else if (!local_read(&cs->open_count))
35538 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35539 else if (cs->mstate != MS_LOCKED) {
35540 dev_warn(cs->dev, "can't write to unlocked device\n");
35541@@ -395,7 +393,7 @@ static int if_write_room(struct tty_struct *tty)
35542 if (!cs->connected) {
35543 gig_dbg(DEBUG_IF, "not connected");
35544 retval = -ENODEV;
35545- } else if (!cs->open_count)
35546+ } else if (!local_read(&cs->open_count))
35547 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35548 else if (cs->mstate != MS_LOCKED) {
35549 dev_warn(cs->dev, "can't write to unlocked device\n");
35550@@ -425,7 +423,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
35551
35552 if (!cs->connected)
35553 gig_dbg(DEBUG_IF, "not connected");
35554- else if (!cs->open_count)
35555+ else if (!local_read(&cs->open_count))
35556 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35557 else if (cs->mstate != MS_LOCKED)
35558 dev_warn(cs->dev, "can't write to unlocked device\n");
35559@@ -453,7 +451,7 @@ static void if_throttle(struct tty_struct *tty)
35560
35561 if (!cs->connected)
35562 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35563- else if (!cs->open_count)
35564+ else if (!local_read(&cs->open_count))
35565 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35566 else {
35567 //FIXME
35568@@ -478,7 +476,7 @@ static void if_unthrottle(struct tty_struct *tty)
35569
35570 if (!cs->connected)
35571 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35572- else if (!cs->open_count)
35573+ else if (!local_read(&cs->open_count))
35574 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35575 else {
35576 //FIXME
35577@@ -510,7 +508,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
35578 goto out;
35579 }
35580
35581- if (!cs->open_count) {
35582+ if (!local_read(&cs->open_count)) {
35583 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35584 goto out;
35585 }
35586diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
35587index a7c0083..62a7cb6 100644
35588--- a/drivers/isdn/hardware/avm/b1.c
35589+++ b/drivers/isdn/hardware/avm/b1.c
35590@@ -173,7 +173,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
35591 }
35592 if (left) {
35593 if (t4file->user) {
35594- if (copy_from_user(buf, dp, left))
35595+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35596 return -EFAULT;
35597 } else {
35598 memcpy(buf, dp, left);
35599@@ -221,7 +221,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
35600 }
35601 if (left) {
35602 if (config->user) {
35603- if (copy_from_user(buf, dp, left))
35604+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35605 return -EFAULT;
35606 } else {
35607 memcpy(buf, dp, left);
35608diff --git a/drivers/isdn/hardware/eicon/capidtmf.c b/drivers/isdn/hardware/eicon/capidtmf.c
35609index f130724..c373c68 100644
35610--- a/drivers/isdn/hardware/eicon/capidtmf.c
35611+++ b/drivers/isdn/hardware/eicon/capidtmf.c
35612@@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_state *p_state, byte *buffer, word leng
35613 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
35614 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
35615
35616+ pax_track_stack();
35617
35618 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
35619 {
35620diff --git a/drivers/isdn/hardware/eicon/capifunc.c b/drivers/isdn/hardware/eicon/capifunc.c
35621index 4d425c6..a9be6c4 100644
35622--- a/drivers/isdn/hardware/eicon/capifunc.c
35623+++ b/drivers/isdn/hardware/eicon/capifunc.c
35624@@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
35625 IDI_SYNC_REQ req;
35626 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35627
35628+ pax_track_stack();
35629+
35630 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35631
35632 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35633diff --git a/drivers/isdn/hardware/eicon/diddfunc.c b/drivers/isdn/hardware/eicon/diddfunc.c
35634index 3029234..ef0d9e2 100644
35635--- a/drivers/isdn/hardware/eicon/diddfunc.c
35636+++ b/drivers/isdn/hardware/eicon/diddfunc.c
35637@@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35638 IDI_SYNC_REQ req;
35639 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35640
35641+ pax_track_stack();
35642+
35643 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35644
35645 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35646diff --git a/drivers/isdn/hardware/eicon/divasfunc.c b/drivers/isdn/hardware/eicon/divasfunc.c
35647index d36a4c0..11e7d1a 100644
35648--- a/drivers/isdn/hardware/eicon/divasfunc.c
35649+++ b/drivers/isdn/hardware/eicon/divasfunc.c
35650@@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35651 IDI_SYNC_REQ req;
35652 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35653
35654+ pax_track_stack();
35655+
35656 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35657
35658 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35659diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
35660index 85784a7..a19ca98 100644
35661--- a/drivers/isdn/hardware/eicon/divasync.h
35662+++ b/drivers/isdn/hardware/eicon/divasync.h
35663@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
35664 } diva_didd_add_adapter_t;
35665 typedef struct _diva_didd_remove_adapter {
35666 IDI_CALL p_request;
35667-} diva_didd_remove_adapter_t;
35668+} __no_const diva_didd_remove_adapter_t;
35669 typedef struct _diva_didd_read_adapter_array {
35670 void * buffer;
35671 dword length;
35672diff --git a/drivers/isdn/hardware/eicon/idifunc.c b/drivers/isdn/hardware/eicon/idifunc.c
35673index db87d51..7d09acf 100644
35674--- a/drivers/isdn/hardware/eicon/idifunc.c
35675+++ b/drivers/isdn/hardware/eicon/idifunc.c
35676@@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35677 IDI_SYNC_REQ req;
35678 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35679
35680+ pax_track_stack();
35681+
35682 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35683
35684 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35685diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
35686index ae89fb8..0fab299 100644
35687--- a/drivers/isdn/hardware/eicon/message.c
35688+++ b/drivers/isdn/hardware/eicon/message.c
35689@@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
35690 dword d;
35691 word w;
35692
35693+ pax_track_stack();
35694+
35695 a = plci->adapter;
35696 Id = ((word)plci->Id<<8)|a->Id;
35697 PUT_WORD(&SS_Ind[4],0x0000);
35698@@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
35699 word j, n, w;
35700 dword d;
35701
35702+ pax_track_stack();
35703+
35704
35705 for(i=0;i<8;i++) bp_parms[i].length = 0;
35706 for(i=0;i<2;i++) global_config[i].length = 0;
35707@@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARSE *bp)
35708 const byte llc3[] = {4,3,2,2,6,6,0};
35709 const byte header[] = {0,2,3,3,0,0,0};
35710
35711+ pax_track_stack();
35712+
35713 for(i=0;i<8;i++) bp_parms[i].length = 0;
35714 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
35715 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
35716@@ -14761,6 +14767,8 @@ static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
35717 word appl_number_group_type[MAX_APPL];
35718 PLCI *auxplci;
35719
35720+ pax_track_stack();
35721+
35722 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
35723
35724 if(!a->group_optimization_enabled)
35725diff --git a/drivers/isdn/hardware/eicon/mntfunc.c b/drivers/isdn/hardware/eicon/mntfunc.c
35726index a564b75..f3cf8b5 100644
35727--- a/drivers/isdn/hardware/eicon/mntfunc.c
35728+++ b/drivers/isdn/hardware/eicon/mntfunc.c
35729@@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35730 IDI_SYNC_REQ req;
35731 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35732
35733+ pax_track_stack();
35734+
35735 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35736
35737 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35738diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
35739index a3bd163..8956575 100644
35740--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
35741+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
35742@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
35743 typedef struct _diva_os_idi_adapter_interface {
35744 diva_init_card_proc_t cleanup_adapter_proc;
35745 diva_cmd_card_proc_t cmd_proc;
35746-} diva_os_idi_adapter_interface_t;
35747+} __no_const diva_os_idi_adapter_interface_t;
35748
35749 typedef struct _diva_os_xdi_adapter {
35750 struct list_head link;
35751diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
35752index adb1e8c..21b590b 100644
35753--- a/drivers/isdn/i4l/isdn_common.c
35754+++ b/drivers/isdn/i4l/isdn_common.c
35755@@ -1290,6 +1290,8 @@ isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
35756 } iocpar;
35757 void __user *argp = (void __user *)arg;
35758
35759+ pax_track_stack();
35760+
35761 #define name iocpar.name
35762 #define bname iocpar.bname
35763 #define iocts iocpar.iocts
35764diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
35765index bf7997a..cf091db 100644
35766--- a/drivers/isdn/icn/icn.c
35767+++ b/drivers/isdn/icn/icn.c
35768@@ -1044,7 +1044,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
35769 if (count > len)
35770 count = len;
35771 if (user) {
35772- if (copy_from_user(msg, buf, count))
35773+ if (count > sizeof msg || copy_from_user(msg, buf, count))
35774 return -EFAULT;
35775 } else
35776 memcpy(msg, buf, count);
35777diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c
35778index feb0fa4..f76f830 100644
35779--- a/drivers/isdn/mISDN/socket.c
35780+++ b/drivers/isdn/mISDN/socket.c
35781@@ -391,6 +391,7 @@ data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
35782 if (dev) {
35783 struct mISDN_devinfo di;
35784
35785+ memset(&di, 0, sizeof(di));
35786 di.id = dev->id;
35787 di.Dprotocols = dev->Dprotocols;
35788 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
35789@@ -671,6 +672,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
35790 if (dev) {
35791 struct mISDN_devinfo di;
35792
35793+ memset(&di, 0, sizeof(di));
35794 di.id = dev->id;
35795 di.Dprotocols = dev->Dprotocols;
35796 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
35797diff --git a/drivers/isdn/sc/interrupt.c b/drivers/isdn/sc/interrupt.c
35798index 485be8b..f0225bc 100644
35799--- a/drivers/isdn/sc/interrupt.c
35800+++ b/drivers/isdn/sc/interrupt.c
35801@@ -112,11 +112,19 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
35802 }
35803 else if(callid>=0x0000 && callid<=0x7FFF)
35804 {
35805+ int len;
35806+
35807 pr_debug("%s: Got Incoming Call\n",
35808 sc_adapter[card]->devicename);
35809- strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4]));
35810- strcpy(setup.eazmsn,
35811- sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
35812+ len = strlcpy(setup.phone, &(rcvmsg.msg_data.byte_array[4]),
35813+ sizeof(setup.phone));
35814+ if (len >= sizeof(setup.phone))
35815+ continue;
35816+ len = strlcpy(setup.eazmsn,
35817+ sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
35818+ sizeof(setup.eazmsn));
35819+ if (len >= sizeof(setup.eazmsn))
35820+ continue;
35821 setup.si1 = 7;
35822 setup.si2 = 0;
35823 setup.plan = 0;
35824@@ -176,7 +184,9 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
35825 * Handle a GetMyNumber Rsp
35826 */
35827 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
35828- strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array);
35829+ strlcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
35830+ rcvmsg.msg_data.byte_array,
35831+ sizeof(rcvmsg.msg_data.byte_array));
35832 continue;
35833 }
35834
35835diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
35836index 8744d24..d1f9a9a 100644
35837--- a/drivers/lguest/core.c
35838+++ b/drivers/lguest/core.c
35839@@ -91,9 +91,17 @@ static __init int map_switcher(void)
35840 * it's worked so far. The end address needs +1 because __get_vm_area
35841 * allocates an extra guard page, so we need space for that.
35842 */
35843+
35844+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35845+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35846+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
35847+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35848+#else
35849 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35850 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
35851 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35852+#endif
35853+
35854 if (!switcher_vma) {
35855 err = -ENOMEM;
35856 printk("lguest: could not map switcher pages high\n");
35857@@ -118,7 +126,7 @@ static __init int map_switcher(void)
35858 * Now the Switcher is mapped at the right address, we can't fail!
35859 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
35860 */
35861- memcpy(switcher_vma->addr, start_switcher_text,
35862+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
35863 end_switcher_text - start_switcher_text);
35864
35865 printk(KERN_INFO "lguest: mapped switcher at %p\n",
35866diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
35867index 6ae3888..8b38145 100644
35868--- a/drivers/lguest/x86/core.c
35869+++ b/drivers/lguest/x86/core.c
35870@@ -59,7 +59,7 @@ static struct {
35871 /* Offset from where switcher.S was compiled to where we've copied it */
35872 static unsigned long switcher_offset(void)
35873 {
35874- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
35875+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
35876 }
35877
35878 /* This cpu's struct lguest_pages. */
35879@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
35880 * These copies are pretty cheap, so we do them unconditionally: */
35881 /* Save the current Host top-level page directory.
35882 */
35883+
35884+#ifdef CONFIG_PAX_PER_CPU_PGD
35885+ pages->state.host_cr3 = read_cr3();
35886+#else
35887 pages->state.host_cr3 = __pa(current->mm->pgd);
35888+#endif
35889+
35890 /*
35891 * Set up the Guest's page tables to see this CPU's pages (and no
35892 * other CPU's pages).
35893@@ -535,7 +541,7 @@ void __init lguest_arch_host_init(void)
35894 * compiled-in switcher code and the high-mapped copy we just made.
35895 */
35896 for (i = 0; i < IDT_ENTRIES; i++)
35897- default_idt_entries[i] += switcher_offset();
35898+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
35899
35900 /*
35901 * Set up the Switcher's per-cpu areas.
35902@@ -618,7 +624,7 @@ void __init lguest_arch_host_init(void)
35903 * it will be undisturbed when we switch. To change %cs and jump we
35904 * need this structure to feed to Intel's "lcall" instruction.
35905 */
35906- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
35907+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
35908 lguest_entry.segment = LGUEST_CS;
35909
35910 /*
35911diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35912index 40634b0..4f5855e 100644
35913--- a/drivers/lguest/x86/switcher_32.S
35914+++ b/drivers/lguest/x86/switcher_32.S
35915@@ -87,6 +87,7 @@
35916 #include <asm/page.h>
35917 #include <asm/segment.h>
35918 #include <asm/lguest.h>
35919+#include <asm/processor-flags.h>
35920
35921 // We mark the start of the code to copy
35922 // It's placed in .text tho it's never run here
35923@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35924 // Changes type when we load it: damn Intel!
35925 // For after we switch over our page tables
35926 // That entry will be read-only: we'd crash.
35927+
35928+#ifdef CONFIG_PAX_KERNEXEC
35929+ mov %cr0, %edx
35930+ xor $X86_CR0_WP, %edx
35931+ mov %edx, %cr0
35932+#endif
35933+
35934 movl $(GDT_ENTRY_TSS*8), %edx
35935 ltr %dx
35936
35937@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35938 // Let's clear it again for our return.
35939 // The GDT descriptor of the Host
35940 // Points to the table after two "size" bytes
35941- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35942+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35943 // Clear "used" from type field (byte 5, bit 2)
35944- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35945+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35946+
35947+#ifdef CONFIG_PAX_KERNEXEC
35948+ mov %cr0, %eax
35949+ xor $X86_CR0_WP, %eax
35950+ mov %eax, %cr0
35951+#endif
35952
35953 // Once our page table's switched, the Guest is live!
35954 // The Host fades as we run this final step.
35955@@ -295,13 +309,12 @@ deliver_to_host:
35956 // I consulted gcc, and it gave
35957 // These instructions, which I gladly credit:
35958 leal (%edx,%ebx,8), %eax
35959- movzwl (%eax),%edx
35960- movl 4(%eax), %eax
35961- xorw %ax, %ax
35962- orl %eax, %edx
35963+ movl 4(%eax), %edx
35964+ movw (%eax), %dx
35965 // Now the address of the handler's in %edx
35966 // We call it now: its "iret" drops us home.
35967- jmp *%edx
35968+ ljmp $__KERNEL_CS, $1f
35969+1: jmp *%edx
35970
35971 // Every interrupt can come to us here
35972 // But we must truly tell each apart.
35973diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
35974index 588a5b0..b71db89 100644
35975--- a/drivers/macintosh/macio_asic.c
35976+++ b/drivers/macintosh/macio_asic.c
35977@@ -701,7 +701,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
35978 * MacIO is matched against any Apple ID, it's probe() function
35979 * will then decide wether it applies or not
35980 */
35981-static const struct pci_device_id __devinitdata pci_ids [] = { {
35982+static const struct pci_device_id __devinitconst pci_ids [] = { {
35983 .vendor = PCI_VENDOR_ID_APPLE,
35984 .device = PCI_ANY_ID,
35985 .subvendor = PCI_ANY_ID,
35986diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
35987index a348bb0..ecd9b3f 100644
35988--- a/drivers/macintosh/via-pmu-backlight.c
35989+++ b/drivers/macintosh/via-pmu-backlight.c
35990@@ -15,7 +15,7 @@
35991
35992 #define MAX_PMU_LEVEL 0xFF
35993
35994-static struct backlight_ops pmu_backlight_data;
35995+static const struct backlight_ops pmu_backlight_data;
35996 static DEFINE_SPINLOCK(pmu_backlight_lock);
35997 static int sleeping, uses_pmu_bl;
35998 static u8 bl_curve[FB_BACKLIGHT_LEVELS];
35999@@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(struct backlight_device *bd)
36000 return bd->props.brightness;
36001 }
36002
36003-static struct backlight_ops pmu_backlight_data = {
36004+static const struct backlight_ops pmu_backlight_data = {
36005 .get_brightness = pmu_backlight_get_brightness,
36006 .update_status = pmu_backlight_update_status,
36007
36008diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
36009index 6f308a4..b5f7ff7 100644
36010--- a/drivers/macintosh/via-pmu.c
36011+++ b/drivers/macintosh/via-pmu.c
36012@@ -2232,7 +2232,7 @@ static int pmu_sleep_valid(suspend_state_t state)
36013 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
36014 }
36015
36016-static struct platform_suspend_ops pmu_pm_ops = {
36017+static const struct platform_suspend_ops pmu_pm_ops = {
36018 .enter = powerbook_sleep,
36019 .valid = pmu_sleep_valid,
36020 };
36021diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
36022index 818b617..4656e38 100644
36023--- a/drivers/md/dm-ioctl.c
36024+++ b/drivers/md/dm-ioctl.c
36025@@ -1437,7 +1437,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
36026 cmd == DM_LIST_VERSIONS_CMD)
36027 return 0;
36028
36029- if ((cmd == DM_DEV_CREATE_CMD)) {
36030+ if (cmd == DM_DEV_CREATE_CMD) {
36031 if (!*param->name) {
36032 DMWARN("name not supplied when creating device");
36033 return -EINVAL;
36034diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
36035index 6021d0a..a878643 100644
36036--- a/drivers/md/dm-raid1.c
36037+++ b/drivers/md/dm-raid1.c
36038@@ -41,7 +41,7 @@ enum dm_raid1_error {
36039
36040 struct mirror {
36041 struct mirror_set *ms;
36042- atomic_t error_count;
36043+ atomic_unchecked_t error_count;
36044 unsigned long error_type;
36045 struct dm_dev *dev;
36046 sector_t offset;
36047@@ -203,7 +203,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
36048 * simple way to tell if a device has encountered
36049 * errors.
36050 */
36051- atomic_inc(&m->error_count);
36052+ atomic_inc_unchecked(&m->error_count);
36053
36054 if (test_and_set_bit(error_type, &m->error_type))
36055 return;
36056@@ -225,7 +225,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
36057 }
36058
36059 for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++)
36060- if (!atomic_read(&new->error_count)) {
36061+ if (!atomic_read_unchecked(&new->error_count)) {
36062 set_default_mirror(new);
36063 break;
36064 }
36065@@ -363,7 +363,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
36066 struct mirror *m = get_default_mirror(ms);
36067
36068 do {
36069- if (likely(!atomic_read(&m->error_count)))
36070+ if (likely(!atomic_read_unchecked(&m->error_count)))
36071 return m;
36072
36073 if (m-- == ms->mirror)
36074@@ -377,7 +377,7 @@ static int default_ok(struct mirror *m)
36075 {
36076 struct mirror *default_mirror = get_default_mirror(m->ms);
36077
36078- return !atomic_read(&default_mirror->error_count);
36079+ return !atomic_read_unchecked(&default_mirror->error_count);
36080 }
36081
36082 static int mirror_available(struct mirror_set *ms, struct bio *bio)
36083@@ -484,7 +484,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
36084 */
36085 if (likely(region_in_sync(ms, region, 1)))
36086 m = choose_mirror(ms, bio->bi_sector);
36087- else if (m && atomic_read(&m->error_count))
36088+ else if (m && atomic_read_unchecked(&m->error_count))
36089 m = NULL;
36090
36091 if (likely(m))
36092@@ -855,7 +855,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
36093 }
36094
36095 ms->mirror[mirror].ms = ms;
36096- atomic_set(&(ms->mirror[mirror].error_count), 0);
36097+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
36098 ms->mirror[mirror].error_type = 0;
36099 ms->mirror[mirror].offset = offset;
36100
36101@@ -1241,7 +1241,7 @@ static void mirror_resume(struct dm_target *ti)
36102 */
36103 static char device_status_char(struct mirror *m)
36104 {
36105- if (!atomic_read(&(m->error_count)))
36106+ if (!atomic_read_unchecked(&(m->error_count)))
36107 return 'A';
36108
36109 return (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
36110diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
36111index bd58703..9f26571 100644
36112--- a/drivers/md/dm-stripe.c
36113+++ b/drivers/md/dm-stripe.c
36114@@ -20,7 +20,7 @@ struct stripe {
36115 struct dm_dev *dev;
36116 sector_t physical_start;
36117
36118- atomic_t error_count;
36119+ atomic_unchecked_t error_count;
36120 };
36121
36122 struct stripe_c {
36123@@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
36124 kfree(sc);
36125 return r;
36126 }
36127- atomic_set(&(sc->stripe[i].error_count), 0);
36128+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
36129 }
36130
36131 ti->private = sc;
36132@@ -257,7 +257,7 @@ static int stripe_status(struct dm_target *ti,
36133 DMEMIT("%d ", sc->stripes);
36134 for (i = 0; i < sc->stripes; i++) {
36135 DMEMIT("%s ", sc->stripe[i].dev->name);
36136- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
36137+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
36138 'D' : 'A';
36139 }
36140 buffer[i] = '\0';
36141@@ -304,8 +304,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
36142 */
36143 for (i = 0; i < sc->stripes; i++)
36144 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
36145- atomic_inc(&(sc->stripe[i].error_count));
36146- if (atomic_read(&(sc->stripe[i].error_count)) <
36147+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
36148+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
36149 DM_IO_ERROR_THRESHOLD)
36150 queue_work(kstriped, &sc->kstriped_ws);
36151 }
36152diff --git a/drivers/md/dm-sysfs.c b/drivers/md/dm-sysfs.c
36153index 4b04590..13a77b2 100644
36154--- a/drivers/md/dm-sysfs.c
36155+++ b/drivers/md/dm-sysfs.c
36156@@ -75,7 +75,7 @@ static struct attribute *dm_attrs[] = {
36157 NULL,
36158 };
36159
36160-static struct sysfs_ops dm_sysfs_ops = {
36161+static const struct sysfs_ops dm_sysfs_ops = {
36162 .show = dm_attr_show,
36163 };
36164
36165diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
36166index 03345bb..332250d 100644
36167--- a/drivers/md/dm-table.c
36168+++ b/drivers/md/dm-table.c
36169@@ -376,7 +376,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
36170 if (!dev_size)
36171 return 0;
36172
36173- if ((start >= dev_size) || (start + len > dev_size)) {
36174+ if ((start >= dev_size) || (len > dev_size - start)) {
36175 DMWARN("%s: %s too small for target: "
36176 "start=%llu, len=%llu, dev_size=%llu",
36177 dm_device_name(ti->table->md), bdevname(bdev, b),
36178diff --git a/drivers/md/dm.c b/drivers/md/dm.c
36179index c988ac2..c418141 100644
36180--- a/drivers/md/dm.c
36181+++ b/drivers/md/dm.c
36182@@ -165,9 +165,9 @@ struct mapped_device {
36183 /*
36184 * Event handling.
36185 */
36186- atomic_t event_nr;
36187+ atomic_unchecked_t event_nr;
36188 wait_queue_head_t eventq;
36189- atomic_t uevent_seq;
36190+ atomic_unchecked_t uevent_seq;
36191 struct list_head uevent_list;
36192 spinlock_t uevent_lock; /* Protect access to uevent_list */
36193
36194@@ -1776,8 +1776,8 @@ static struct mapped_device *alloc_dev(int minor)
36195 rwlock_init(&md->map_lock);
36196 atomic_set(&md->holders, 1);
36197 atomic_set(&md->open_count, 0);
36198- atomic_set(&md->event_nr, 0);
36199- atomic_set(&md->uevent_seq, 0);
36200+ atomic_set_unchecked(&md->event_nr, 0);
36201+ atomic_set_unchecked(&md->uevent_seq, 0);
36202 INIT_LIST_HEAD(&md->uevent_list);
36203 spin_lock_init(&md->uevent_lock);
36204
36205@@ -1927,7 +1927,7 @@ static void event_callback(void *context)
36206
36207 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
36208
36209- atomic_inc(&md->event_nr);
36210+ atomic_inc_unchecked(&md->event_nr);
36211 wake_up(&md->eventq);
36212 }
36213
36214@@ -2562,18 +2562,18 @@ void dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
36215
36216 uint32_t dm_next_uevent_seq(struct mapped_device *md)
36217 {
36218- return atomic_add_return(1, &md->uevent_seq);
36219+ return atomic_add_return_unchecked(1, &md->uevent_seq);
36220 }
36221
36222 uint32_t dm_get_event_nr(struct mapped_device *md)
36223 {
36224- return atomic_read(&md->event_nr);
36225+ return atomic_read_unchecked(&md->event_nr);
36226 }
36227
36228 int dm_wait_event(struct mapped_device *md, int event_nr)
36229 {
36230 return wait_event_interruptible(md->eventq,
36231- (event_nr != atomic_read(&md->event_nr)));
36232+ (event_nr != atomic_read_unchecked(&md->event_nr)));
36233 }
36234
36235 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
36236diff --git a/drivers/md/md.c b/drivers/md/md.c
36237index 4ce6e2f..7a9530a 100644
36238--- a/drivers/md/md.c
36239+++ b/drivers/md/md.c
36240@@ -153,10 +153,10 @@ static int start_readonly;
36241 * start build, activate spare
36242 */
36243 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
36244-static atomic_t md_event_count;
36245+static atomic_unchecked_t md_event_count;
36246 void md_new_event(mddev_t *mddev)
36247 {
36248- atomic_inc(&md_event_count);
36249+ atomic_inc_unchecked(&md_event_count);
36250 wake_up(&md_event_waiters);
36251 }
36252 EXPORT_SYMBOL_GPL(md_new_event);
36253@@ -166,7 +166,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
36254 */
36255 static void md_new_event_inintr(mddev_t *mddev)
36256 {
36257- atomic_inc(&md_event_count);
36258+ atomic_inc_unchecked(&md_event_count);
36259 wake_up(&md_event_waiters);
36260 }
36261
36262@@ -1226,7 +1226,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
36263
36264 rdev->preferred_minor = 0xffff;
36265 rdev->data_offset = le64_to_cpu(sb->data_offset);
36266- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36267+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36268
36269 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
36270 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
36271@@ -1400,7 +1400,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
36272 else
36273 sb->resync_offset = cpu_to_le64(0);
36274
36275- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
36276+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
36277
36278 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
36279 sb->size = cpu_to_le64(mddev->dev_sectors);
36280@@ -2222,7 +2222,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
36281 static ssize_t
36282 errors_show(mdk_rdev_t *rdev, char *page)
36283 {
36284- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
36285+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
36286 }
36287
36288 static ssize_t
36289@@ -2231,7 +2231,7 @@ errors_store(mdk_rdev_t *rdev, const char *buf, size_t len)
36290 char *e;
36291 unsigned long n = simple_strtoul(buf, &e, 10);
36292 if (*buf && (*e == 0 || *e == '\n')) {
36293- atomic_set(&rdev->corrected_errors, n);
36294+ atomic_set_unchecked(&rdev->corrected_errors, n);
36295 return len;
36296 }
36297 return -EINVAL;
36298@@ -2525,7 +2525,7 @@ static void rdev_free(struct kobject *ko)
36299 mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj);
36300 kfree(rdev);
36301 }
36302-static struct sysfs_ops rdev_sysfs_ops = {
36303+static const struct sysfs_ops rdev_sysfs_ops = {
36304 .show = rdev_attr_show,
36305 .store = rdev_attr_store,
36306 };
36307@@ -2574,8 +2574,8 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
36308 rdev->data_offset = 0;
36309 rdev->sb_events = 0;
36310 atomic_set(&rdev->nr_pending, 0);
36311- atomic_set(&rdev->read_errors, 0);
36312- atomic_set(&rdev->corrected_errors, 0);
36313+ atomic_set_unchecked(&rdev->read_errors, 0);
36314+ atomic_set_unchecked(&rdev->corrected_errors, 0);
36315
36316 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
36317 if (!size) {
36318@@ -3895,7 +3895,7 @@ static void md_free(struct kobject *ko)
36319 kfree(mddev);
36320 }
36321
36322-static struct sysfs_ops md_sysfs_ops = {
36323+static const struct sysfs_ops md_sysfs_ops = {
36324 .show = md_attr_show,
36325 .store = md_attr_store,
36326 };
36327@@ -4482,7 +4482,8 @@ out:
36328 err = 0;
36329 blk_integrity_unregister(disk);
36330 md_new_event(mddev);
36331- sysfs_notify_dirent(mddev->sysfs_state);
36332+ if (mddev->sysfs_state)
36333+ sysfs_notify_dirent(mddev->sysfs_state);
36334 return err;
36335 }
36336
36337@@ -5962,7 +5963,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36338
36339 spin_unlock(&pers_lock);
36340 seq_printf(seq, "\n");
36341- mi->event = atomic_read(&md_event_count);
36342+ mi->event = atomic_read_unchecked(&md_event_count);
36343 return 0;
36344 }
36345 if (v == (void*)2) {
36346@@ -6051,7 +6052,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36347 chunk_kb ? "KB" : "B");
36348 if (bitmap->file) {
36349 seq_printf(seq, ", file: ");
36350- seq_path(seq, &bitmap->file->f_path, " \t\n");
36351+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
36352 }
36353
36354 seq_printf(seq, "\n");
36355@@ -6085,7 +6086,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
36356 else {
36357 struct seq_file *p = file->private_data;
36358 p->private = mi;
36359- mi->event = atomic_read(&md_event_count);
36360+ mi->event = atomic_read_unchecked(&md_event_count);
36361 }
36362 return error;
36363 }
36364@@ -6101,7 +6102,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
36365 /* always allow read */
36366 mask = POLLIN | POLLRDNORM;
36367
36368- if (mi->event != atomic_read(&md_event_count))
36369+ if (mi->event != atomic_read_unchecked(&md_event_count))
36370 mask |= POLLERR | POLLPRI;
36371 return mask;
36372 }
36373@@ -6145,7 +6146,7 @@ static int is_mddev_idle(mddev_t *mddev, int init)
36374 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
36375 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
36376 (int)part_stat_read(&disk->part0, sectors[1]) -
36377- atomic_read(&disk->sync_io);
36378+ atomic_read_unchecked(&disk->sync_io);
36379 /* sync IO will cause sync_io to increase before the disk_stats
36380 * as sync_io is counted when a request starts, and
36381 * disk_stats is counted when it completes.
36382diff --git a/drivers/md/md.h b/drivers/md/md.h
36383index 87430fe..0024a4c 100644
36384--- a/drivers/md/md.h
36385+++ b/drivers/md/md.h
36386@@ -94,10 +94,10 @@ struct mdk_rdev_s
36387 * only maintained for arrays that
36388 * support hot removal
36389 */
36390- atomic_t read_errors; /* number of consecutive read errors that
36391+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
36392 * we have tried to ignore.
36393 */
36394- atomic_t corrected_errors; /* number of corrected read errors,
36395+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
36396 * for reporting to userspace and storing
36397 * in superblock.
36398 */
36399@@ -304,7 +304,7 @@ static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
36400
36401 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
36402 {
36403- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36404+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36405 }
36406
36407 struct mdk_personality
36408diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
36409index 968cb14..f0ad2e4 100644
36410--- a/drivers/md/raid1.c
36411+++ b/drivers/md/raid1.c
36412@@ -1415,7 +1415,7 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
36413 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
36414 continue;
36415 rdev = conf->mirrors[d].rdev;
36416- atomic_add(s, &rdev->corrected_errors);
36417+ atomic_add_unchecked(s, &rdev->corrected_errors);
36418 if (sync_page_io(rdev->bdev,
36419 sect + rdev->data_offset,
36420 s<<9,
36421@@ -1564,7 +1564,7 @@ static void fix_read_error(conf_t *conf, int read_disk,
36422 /* Well, this device is dead */
36423 md_error(mddev, rdev);
36424 else {
36425- atomic_add(s, &rdev->corrected_errors);
36426+ atomic_add_unchecked(s, &rdev->corrected_errors);
36427 printk(KERN_INFO
36428 "raid1:%s: read error corrected "
36429 "(%d sectors at %llu on %s)\n",
36430diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
36431index 1b4e232..cf0f534 100644
36432--- a/drivers/md/raid10.c
36433+++ b/drivers/md/raid10.c
36434@@ -1255,7 +1255,7 @@ static void end_sync_read(struct bio *bio, int error)
36435 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
36436 set_bit(R10BIO_Uptodate, &r10_bio->state);
36437 else {
36438- atomic_add(r10_bio->sectors,
36439+ atomic_add_unchecked(r10_bio->sectors,
36440 &conf->mirrors[d].rdev->corrected_errors);
36441 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
36442 md_error(r10_bio->mddev,
36443@@ -1520,7 +1520,7 @@ static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
36444 test_bit(In_sync, &rdev->flags)) {
36445 atomic_inc(&rdev->nr_pending);
36446 rcu_read_unlock();
36447- atomic_add(s, &rdev->corrected_errors);
36448+ atomic_add_unchecked(s, &rdev->corrected_errors);
36449 if (sync_page_io(rdev->bdev,
36450 r10_bio->devs[sl].addr +
36451 sect + rdev->data_offset,
36452diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
36453index 883215d..675bf47 100644
36454--- a/drivers/md/raid5.c
36455+++ b/drivers/md/raid5.c
36456@@ -482,7 +482,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
36457 bi->bi_next = NULL;
36458 if ((rw & WRITE) &&
36459 test_bit(R5_ReWrite, &sh->dev[i].flags))
36460- atomic_add(STRIPE_SECTORS,
36461+ atomic_add_unchecked(STRIPE_SECTORS,
36462 &rdev->corrected_errors);
36463 generic_make_request(bi);
36464 } else {
36465@@ -1517,15 +1517,15 @@ static void raid5_end_read_request(struct bio * bi, int error)
36466 clear_bit(R5_ReadError, &sh->dev[i].flags);
36467 clear_bit(R5_ReWrite, &sh->dev[i].flags);
36468 }
36469- if (atomic_read(&conf->disks[i].rdev->read_errors))
36470- atomic_set(&conf->disks[i].rdev->read_errors, 0);
36471+ if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
36472+ atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
36473 } else {
36474 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
36475 int retry = 0;
36476 rdev = conf->disks[i].rdev;
36477
36478 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
36479- atomic_inc(&rdev->read_errors);
36480+ atomic_inc_unchecked(&rdev->read_errors);
36481 if (conf->mddev->degraded >= conf->max_degraded)
36482 printk_rl(KERN_WARNING
36483 "raid5:%s: read error not correctable "
36484@@ -1543,7 +1543,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
36485 (unsigned long long)(sh->sector
36486 + rdev->data_offset),
36487 bdn);
36488- else if (atomic_read(&rdev->read_errors)
36489+ else if (atomic_read_unchecked(&rdev->read_errors)
36490 > conf->max_nr_stripes)
36491 printk(KERN_WARNING
36492 "raid5:%s: Too many read errors, failing device %s.\n",
36493@@ -1870,6 +1870,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
36494 sector_t r_sector;
36495 struct stripe_head sh2;
36496
36497+ pax_track_stack();
36498
36499 chunk_offset = sector_div(new_sector, sectors_per_chunk);
36500 stripe = new_sector;
36501diff --git a/drivers/media/common/saa7146_hlp.c b/drivers/media/common/saa7146_hlp.c
36502index 05bde9c..2f31d40 100644
36503--- a/drivers/media/common/saa7146_hlp.c
36504+++ b/drivers/media/common/saa7146_hlp.c
36505@@ -353,6 +353,8 @@ static void calculate_clipping_registers_rect(struct saa7146_dev *dev, struct sa
36506
36507 int x[32], y[32], w[32], h[32];
36508
36509+ pax_track_stack();
36510+
36511 /* clear out memory */
36512 memset(&line_list[0], 0x00, sizeof(u32)*32);
36513 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
36514diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36515index cb22da5..82b686e 100644
36516--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36517+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36518@@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, u8 * eb
36519 u8 buf[HOST_LINK_BUF_SIZE];
36520 int i;
36521
36522+ pax_track_stack();
36523+
36524 dprintk("%s\n", __func__);
36525
36526 /* check if we have space for a link buf in the rx_buffer */
36527@@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
36528 unsigned long timeout;
36529 int written;
36530
36531+ pax_track_stack();
36532+
36533 dprintk("%s\n", __func__);
36534
36535 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
36536diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
36537index 2fe05d0..a3289c4 100644
36538--- a/drivers/media/dvb/dvb-core/dvb_demux.h
36539+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
36540@@ -71,7 +71,7 @@ struct dvb_demux_feed {
36541 union {
36542 dmx_ts_cb ts;
36543 dmx_section_cb sec;
36544- } cb;
36545+ } __no_const cb;
36546
36547 struct dvb_demux *demux;
36548 void *priv;
36549diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
36550index 94159b9..376bd8e 100644
36551--- a/drivers/media/dvb/dvb-core/dvbdev.c
36552+++ b/drivers/media/dvb/dvb-core/dvbdev.c
36553@@ -191,7 +191,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
36554 const struct dvb_device *template, void *priv, int type)
36555 {
36556 struct dvb_device *dvbdev;
36557- struct file_operations *dvbdevfops;
36558+ file_operations_no_const *dvbdevfops;
36559 struct device *clsdev;
36560 int minor;
36561 int id;
36562diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
36563index 2a53dd0..db8c07a 100644
36564--- a/drivers/media/dvb/dvb-usb/cxusb.c
36565+++ b/drivers/media/dvb/dvb-usb/cxusb.c
36566@@ -1040,7 +1040,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
36567 struct dib0700_adapter_state {
36568 int (*set_param_save) (struct dvb_frontend *,
36569 struct dvb_frontend_parameters *);
36570-};
36571+} __no_const;
36572
36573 static int dib7070_set_param_override(struct dvb_frontend *fe,
36574 struct dvb_frontend_parameters *fep)
36575diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
36576index db7f7f7..f55e96f 100644
36577--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
36578+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
36579@@ -332,6 +332,8 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
36580
36581 u8 buf[260];
36582
36583+ pax_track_stack();
36584+
36585 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
36586 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",hx.addr, hx.len, hx.chk);
36587
36588diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
36589index 524acf5..5ffc403 100644
36590--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
36591+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
36592@@ -28,7 +28,7 @@ MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplif
36593
36594 struct dib0700_adapter_state {
36595 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *);
36596-};
36597+} __no_const;
36598
36599 /* Hauppauge Nova-T 500 (aka Bristol)
36600 * has a LNA on GPIO0 which is enabled by setting 1 */
36601diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
36602index ba91735..4261d84 100644
36603--- a/drivers/media/dvb/frontends/dib3000.h
36604+++ b/drivers/media/dvb/frontends/dib3000.h
36605@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
36606 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
36607 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
36608 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
36609-};
36610+} __no_const;
36611
36612 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
36613 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
36614diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
36615index c709ce6..b3fe620 100644
36616--- a/drivers/media/dvb/frontends/or51211.c
36617+++ b/drivers/media/dvb/frontends/or51211.c
36618@@ -113,6 +113,8 @@ static int or51211_load_firmware (struct dvb_frontend* fe,
36619 u8 tudata[585];
36620 int i;
36621
36622+ pax_track_stack();
36623+
36624 dprintk("Firmware is %zd bytes\n",fw->size);
36625
36626 /* Get eprom data */
36627diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
36628index 482d0f3..ee1e202 100644
36629--- a/drivers/media/radio/radio-cadet.c
36630+++ b/drivers/media/radio/radio-cadet.c
36631@@ -347,7 +347,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36632 while (i < count && dev->rdsin != dev->rdsout)
36633 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
36634
36635- if (copy_to_user(data, readbuf, i))
36636+ if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
36637 return -EFAULT;
36638 return i;
36639 }
36640diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
36641index 6dd51e2..0359b92 100644
36642--- a/drivers/media/video/cx18/cx18-driver.c
36643+++ b/drivers/media/video/cx18/cx18-driver.c
36644@@ -56,7 +56,7 @@ static struct pci_device_id cx18_pci_tbl[] __devinitdata = {
36645
36646 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
36647
36648-static atomic_t cx18_instance = ATOMIC_INIT(0);
36649+static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
36650
36651 /* Parameter declarations */
36652 static int cardtype[CX18_MAX_CARDS];
36653@@ -288,6 +288,8 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
36654 struct i2c_client c;
36655 u8 eedata[256];
36656
36657+ pax_track_stack();
36658+
36659 memset(&c, 0, sizeof(c));
36660 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
36661 c.adapter = &cx->i2c_adap[0];
36662@@ -800,7 +802,7 @@ static int __devinit cx18_probe(struct pci_dev *pci_dev,
36663 struct cx18 *cx;
36664
36665 /* FIXME - module parameter arrays constrain max instances */
36666- i = atomic_inc_return(&cx18_instance) - 1;
36667+ i = atomic_inc_return_unchecked(&cx18_instance) - 1;
36668 if (i >= CX18_MAX_CARDS) {
36669 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
36670 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
36671diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
36672index 463ec34..2f4625a 100644
36673--- a/drivers/media/video/ivtv/ivtv-driver.c
36674+++ b/drivers/media/video/ivtv/ivtv-driver.c
36675@@ -79,7 +79,7 @@ static struct pci_device_id ivtv_pci_tbl[] __devinitdata = {
36676 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
36677
36678 /* ivtv instance counter */
36679-static atomic_t ivtv_instance = ATOMIC_INIT(0);
36680+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
36681
36682 /* Parameter declarations */
36683 static int cardtype[IVTV_MAX_CARDS];
36684diff --git a/drivers/media/video/omap24xxcam.c b/drivers/media/video/omap24xxcam.c
36685index 5fc4ac0..652a54a 100644
36686--- a/drivers/media/video/omap24xxcam.c
36687+++ b/drivers/media/video/omap24xxcam.c
36688@@ -401,7 +401,7 @@ static void omap24xxcam_vbq_complete(struct omap24xxcam_sgdma *sgdma,
36689 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
36690
36691 do_gettimeofday(&vb->ts);
36692- vb->field_count = atomic_add_return(2, &fh->field_count);
36693+ vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
36694 if (csr & csr_error) {
36695 vb->state = VIDEOBUF_ERROR;
36696 if (!atomic_read(&fh->cam->in_reset)) {
36697diff --git a/drivers/media/video/omap24xxcam.h b/drivers/media/video/omap24xxcam.h
36698index 2ce67f5..cf26a5b 100644
36699--- a/drivers/media/video/omap24xxcam.h
36700+++ b/drivers/media/video/omap24xxcam.h
36701@@ -533,7 +533,7 @@ struct omap24xxcam_fh {
36702 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
36703 struct videobuf_queue vbq;
36704 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
36705- atomic_t field_count; /* field counter for videobuf_buffer */
36706+ atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
36707 /* accessing cam here doesn't need serialisation: it's constant */
36708 struct omap24xxcam_device *cam;
36709 };
36710diff --git a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36711index 299afa4..eb47459 100644
36712--- a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36713+++ b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36714@@ -119,6 +119,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw *hdw)
36715 u8 *eeprom;
36716 struct tveeprom tvdata;
36717
36718+ pax_track_stack();
36719+
36720 memset(&tvdata,0,sizeof(tvdata));
36721
36722 eeprom = pvr2_eeprom_fetch(hdw);
36723diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36724index 5b152ff..3320638 100644
36725--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36726+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36727@@ -195,7 +195,7 @@ struct pvr2_hdw {
36728
36729 /* I2C stuff */
36730 struct i2c_adapter i2c_adap;
36731- struct i2c_algorithm i2c_algo;
36732+ i2c_algorithm_no_const i2c_algo;
36733 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
36734 int i2c_cx25840_hack_state;
36735 int i2c_linked;
36736diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
36737index 1eabff6..8e2313a 100644
36738--- a/drivers/media/video/saa7134/saa6752hs.c
36739+++ b/drivers/media/video/saa7134/saa6752hs.c
36740@@ -683,6 +683,8 @@ static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
36741 unsigned char localPAT[256];
36742 unsigned char localPMT[256];
36743
36744+ pax_track_stack();
36745+
36746 /* Set video format - must be done first as it resets other settings */
36747 set_reg8(client, 0x41, h->video_format);
36748
36749diff --git a/drivers/media/video/saa7164/saa7164-cmd.c b/drivers/media/video/saa7164/saa7164-cmd.c
36750index 9c1d3ac..b1b49e9 100644
36751--- a/drivers/media/video/saa7164/saa7164-cmd.c
36752+++ b/drivers/media/video/saa7164/saa7164-cmd.c
36753@@ -87,6 +87,8 @@ int saa7164_irq_dequeue(struct saa7164_dev *dev)
36754 wait_queue_head_t *q = 0;
36755 dprintk(DBGLVL_CMD, "%s()\n", __func__);
36756
36757+ pax_track_stack();
36758+
36759 /* While any outstand message on the bus exists... */
36760 do {
36761
36762@@ -126,6 +128,8 @@ int saa7164_cmd_dequeue(struct saa7164_dev *dev)
36763 u8 tmp[512];
36764 dprintk(DBGLVL_CMD, "%s()\n", __func__);
36765
36766+ pax_track_stack();
36767+
36768 while (loop) {
36769
36770 tmComResInfo_t tRsp = { 0, 0, 0, 0, 0, 0 };
36771diff --git a/drivers/media/video/usbvideo/ibmcam.c b/drivers/media/video/usbvideo/ibmcam.c
36772index b085496..cde0270 100644
36773--- a/drivers/media/video/usbvideo/ibmcam.c
36774+++ b/drivers/media/video/usbvideo/ibmcam.c
36775@@ -3947,15 +3947,15 @@ static struct usb_device_id id_table[] = {
36776 static int __init ibmcam_init(void)
36777 {
36778 struct usbvideo_cb cbTbl;
36779- memset(&cbTbl, 0, sizeof(cbTbl));
36780- cbTbl.probe = ibmcam_probe;
36781- cbTbl.setupOnOpen = ibmcam_setup_on_open;
36782- cbTbl.videoStart = ibmcam_video_start;
36783- cbTbl.videoStop = ibmcam_video_stop;
36784- cbTbl.processData = ibmcam_ProcessIsocData;
36785- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36786- cbTbl.adjustPicture = ibmcam_adjust_picture;
36787- cbTbl.getFPS = ibmcam_calculate_fps;
36788+ memset((void *)&cbTbl, 0, sizeof(cbTbl));
36789+ *(void **)&cbTbl.probe = ibmcam_probe;
36790+ *(void **)&cbTbl.setupOnOpen = ibmcam_setup_on_open;
36791+ *(void **)&cbTbl.videoStart = ibmcam_video_start;
36792+ *(void **)&cbTbl.videoStop = ibmcam_video_stop;
36793+ *(void **)&cbTbl.processData = ibmcam_ProcessIsocData;
36794+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36795+ *(void **)&cbTbl.adjustPicture = ibmcam_adjust_picture;
36796+ *(void **)&cbTbl.getFPS = ibmcam_calculate_fps;
36797 return usbvideo_register(
36798 &cams,
36799 MAX_IBMCAM,
36800diff --git a/drivers/media/video/usbvideo/konicawc.c b/drivers/media/video/usbvideo/konicawc.c
36801index 31d57f2..600b735 100644
36802--- a/drivers/media/video/usbvideo/konicawc.c
36803+++ b/drivers/media/video/usbvideo/konicawc.c
36804@@ -225,7 +225,7 @@ static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev
36805 int error;
36806
36807 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
36808- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36809+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36810
36811 cam->input = input_dev = input_allocate_device();
36812 if (!input_dev) {
36813@@ -935,16 +935,16 @@ static int __init konicawc_init(void)
36814 struct usbvideo_cb cbTbl;
36815 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
36816 DRIVER_DESC "\n");
36817- memset(&cbTbl, 0, sizeof(cbTbl));
36818- cbTbl.probe = konicawc_probe;
36819- cbTbl.setupOnOpen = konicawc_setup_on_open;
36820- cbTbl.processData = konicawc_process_isoc;
36821- cbTbl.getFPS = konicawc_calculate_fps;
36822- cbTbl.setVideoMode = konicawc_set_video_mode;
36823- cbTbl.startDataPump = konicawc_start_data;
36824- cbTbl.stopDataPump = konicawc_stop_data;
36825- cbTbl.adjustPicture = konicawc_adjust_picture;
36826- cbTbl.userFree = konicawc_free_uvd;
36827+ memset((void * )&cbTbl, 0, sizeof(cbTbl));
36828+ *(void **)&cbTbl.probe = konicawc_probe;
36829+ *(void **)&cbTbl.setupOnOpen = konicawc_setup_on_open;
36830+ *(void **)&cbTbl.processData = konicawc_process_isoc;
36831+ *(void **)&cbTbl.getFPS = konicawc_calculate_fps;
36832+ *(void **)&cbTbl.setVideoMode = konicawc_set_video_mode;
36833+ *(void **)&cbTbl.startDataPump = konicawc_start_data;
36834+ *(void **)&cbTbl.stopDataPump = konicawc_stop_data;
36835+ *(void **)&cbTbl.adjustPicture = konicawc_adjust_picture;
36836+ *(void **)&cbTbl.userFree = konicawc_free_uvd;
36837 return usbvideo_register(
36838 &cams,
36839 MAX_CAMERAS,
36840diff --git a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
36841index 803d3e4..c4d1b96 100644
36842--- a/drivers/media/video/usbvideo/quickcam_messenger.c
36843+++ b/drivers/media/video/usbvideo/quickcam_messenger.c
36844@@ -89,7 +89,7 @@ static void qcm_register_input(struct qcm *cam, struct usb_device *dev)
36845 int error;
36846
36847 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
36848- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36849+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36850
36851 cam->input = input_dev = input_allocate_device();
36852 if (!input_dev) {
36853diff --git a/drivers/media/video/usbvideo/ultracam.c b/drivers/media/video/usbvideo/ultracam.c
36854index fbd1b63..292f9f0 100644
36855--- a/drivers/media/video/usbvideo/ultracam.c
36856+++ b/drivers/media/video/usbvideo/ultracam.c
36857@@ -655,14 +655,14 @@ static int __init ultracam_init(void)
36858 {
36859 struct usbvideo_cb cbTbl;
36860 memset(&cbTbl, 0, sizeof(cbTbl));
36861- cbTbl.probe = ultracam_probe;
36862- cbTbl.setupOnOpen = ultracam_setup_on_open;
36863- cbTbl.videoStart = ultracam_video_start;
36864- cbTbl.videoStop = ultracam_video_stop;
36865- cbTbl.processData = ultracam_ProcessIsocData;
36866- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36867- cbTbl.adjustPicture = ultracam_adjust_picture;
36868- cbTbl.getFPS = ultracam_calculate_fps;
36869+ *(void **)&cbTbl.probe = ultracam_probe;
36870+ *(void **)&cbTbl.setupOnOpen = ultracam_setup_on_open;
36871+ *(void **)&cbTbl.videoStart = ultracam_video_start;
36872+ *(void **)&cbTbl.videoStop = ultracam_video_stop;
36873+ *(void **)&cbTbl.processData = ultracam_ProcessIsocData;
36874+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36875+ *(void **)&cbTbl.adjustPicture = ultracam_adjust_picture;
36876+ *(void **)&cbTbl.getFPS = ultracam_calculate_fps;
36877 return usbvideo_register(
36878 &cams,
36879 MAX_CAMERAS,
36880diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
36881index dea8b32..34f6878 100644
36882--- a/drivers/media/video/usbvideo/usbvideo.c
36883+++ b/drivers/media/video/usbvideo/usbvideo.c
36884@@ -697,15 +697,15 @@ int usbvideo_register(
36885 __func__, cams, base_size, num_cams);
36886
36887 /* Copy callbacks, apply defaults for those that are not set */
36888- memmove(&cams->cb, cbTbl, sizeof(cams->cb));
36889+ memmove((void *)&cams->cb, cbTbl, sizeof(cams->cb));
36890 if (cams->cb.getFrame == NULL)
36891- cams->cb.getFrame = usbvideo_GetFrame;
36892+ *(void **)&cams->cb.getFrame = usbvideo_GetFrame;
36893 if (cams->cb.disconnect == NULL)
36894- cams->cb.disconnect = usbvideo_Disconnect;
36895+ *(void **)&cams->cb.disconnect = usbvideo_Disconnect;
36896 if (cams->cb.startDataPump == NULL)
36897- cams->cb.startDataPump = usbvideo_StartDataPump;
36898+ *(void **)&cams->cb.startDataPump = usbvideo_StartDataPump;
36899 if (cams->cb.stopDataPump == NULL)
36900- cams->cb.stopDataPump = usbvideo_StopDataPump;
36901+ *(void **)&cams->cb.stopDataPump = usbvideo_StopDataPump;
36902
36903 cams->num_cameras = num_cams;
36904 cams->cam = (struct uvd *) &cams[1];
36905diff --git a/drivers/media/video/usbvideo/usbvideo.h b/drivers/media/video/usbvideo/usbvideo.h
36906index c66985b..7fa143a 100644
36907--- a/drivers/media/video/usbvideo/usbvideo.h
36908+++ b/drivers/media/video/usbvideo/usbvideo.h
36909@@ -268,7 +268,7 @@ struct usbvideo_cb {
36910 int (*startDataPump)(struct uvd *uvd);
36911 void (*stopDataPump)(struct uvd *uvd);
36912 int (*setVideoMode)(struct uvd *uvd, struct video_window *vw);
36913-};
36914+} __no_const;
36915
36916 struct usbvideo {
36917 int num_cameras; /* As allocated */
36918diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
36919index e0f91e4..37554ea 100644
36920--- a/drivers/media/video/usbvision/usbvision-core.c
36921+++ b/drivers/media/video/usbvision/usbvision-core.c
36922@@ -820,6 +820,8 @@ static enum ParseState usbvision_parse_compress(struct usb_usbvision *usbvision,
36923 unsigned char rv, gv, bv;
36924 static unsigned char *Y, *U, *V;
36925
36926+ pax_track_stack();
36927+
36928 frame = usbvision->curFrame;
36929 imageSize = frame->frmwidth * frame->frmheight;
36930 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
36931diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
36932index 0d06e7c..3d17d24 100644
36933--- a/drivers/media/video/v4l2-device.c
36934+++ b/drivers/media/video/v4l2-device.c
36935@@ -50,9 +50,9 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
36936 EXPORT_SYMBOL_GPL(v4l2_device_register);
36937
36938 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
36939- atomic_t *instance)
36940+ atomic_unchecked_t *instance)
36941 {
36942- int num = atomic_inc_return(instance) - 1;
36943+ int num = atomic_inc_return_unchecked(instance) - 1;
36944 int len = strlen(basename);
36945
36946 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
36947diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
36948index 032ebae..6a3532c 100644
36949--- a/drivers/media/video/videobuf-dma-sg.c
36950+++ b/drivers/media/video/videobuf-dma-sg.c
36951@@ -693,6 +693,8 @@ void *videobuf_sg_alloc(size_t size)
36952 {
36953 struct videobuf_queue q;
36954
36955+ pax_track_stack();
36956+
36957 /* Required to make generic handler to call __videobuf_alloc */
36958 q.int_ops = &sg_ops;
36959
36960diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
36961index b6992b7..9fa7547 100644
36962--- a/drivers/message/fusion/mptbase.c
36963+++ b/drivers/message/fusion/mptbase.c
36964@@ -6709,8 +6709,14 @@ procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eo
36965 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
36966 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
36967
36968+#ifdef CONFIG_GRKERNSEC_HIDESYM
36969+ len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36970+ NULL, NULL);
36971+#else
36972 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36973 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
36974+#endif
36975+
36976 /*
36977 * Rounding UP to nearest 4-kB boundary here...
36978 */
36979diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
36980index 83873e3..e360e9a 100644
36981--- a/drivers/message/fusion/mptsas.c
36982+++ b/drivers/message/fusion/mptsas.c
36983@@ -436,6 +436,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
36984 return 0;
36985 }
36986
36987+static inline void
36988+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36989+{
36990+ if (phy_info->port_details) {
36991+ phy_info->port_details->rphy = rphy;
36992+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36993+ ioc->name, rphy));
36994+ }
36995+
36996+ if (rphy) {
36997+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36998+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36999+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
37000+ ioc->name, rphy, rphy->dev.release));
37001+ }
37002+}
37003+
37004 /* no mutex */
37005 static void
37006 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
37007@@ -474,23 +491,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
37008 return NULL;
37009 }
37010
37011-static inline void
37012-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
37013-{
37014- if (phy_info->port_details) {
37015- phy_info->port_details->rphy = rphy;
37016- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
37017- ioc->name, rphy));
37018- }
37019-
37020- if (rphy) {
37021- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
37022- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
37023- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
37024- ioc->name, rphy, rphy->dev.release));
37025- }
37026-}
37027-
37028 static inline struct sas_port *
37029 mptsas_get_port(struct mptsas_phyinfo *phy_info)
37030 {
37031diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
37032index bd096ca..332cf76 100644
37033--- a/drivers/message/fusion/mptscsih.c
37034+++ b/drivers/message/fusion/mptscsih.c
37035@@ -1248,15 +1248,16 @@ mptscsih_info(struct Scsi_Host *SChost)
37036
37037 h = shost_priv(SChost);
37038
37039- if (h) {
37040- if (h->info_kbuf == NULL)
37041- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
37042- return h->info_kbuf;
37043- h->info_kbuf[0] = '\0';
37044+ if (!h)
37045+ return NULL;
37046
37047- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
37048- h->info_kbuf[size-1] = '\0';
37049- }
37050+ if (h->info_kbuf == NULL)
37051+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
37052+ return h->info_kbuf;
37053+ h->info_kbuf[0] = '\0';
37054+
37055+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
37056+ h->info_kbuf[size-1] = '\0';
37057
37058 return h->info_kbuf;
37059 }
37060diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
37061index efba702..59b2c0f 100644
37062--- a/drivers/message/i2o/i2o_config.c
37063+++ b/drivers/message/i2o/i2o_config.c
37064@@ -787,6 +787,8 @@ static int i2o_cfg_passthru(unsigned long arg)
37065 struct i2o_message *msg;
37066 unsigned int iop;
37067
37068+ pax_track_stack();
37069+
37070 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
37071 return -EFAULT;
37072
37073diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
37074index 7045c45..c07b170 100644
37075--- a/drivers/message/i2o/i2o_proc.c
37076+++ b/drivers/message/i2o/i2o_proc.c
37077@@ -259,13 +259,6 @@ static char *scsi_devices[] = {
37078 "Array Controller Device"
37079 };
37080
37081-static char *chtostr(u8 * chars, int n)
37082-{
37083- char tmp[256];
37084- tmp[0] = 0;
37085- return strncat(tmp, (char *)chars, n);
37086-}
37087-
37088 static int i2o_report_query_status(struct seq_file *seq, int block_status,
37089 char *group)
37090 {
37091@@ -842,8 +835,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
37092
37093 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
37094 seq_printf(seq, "%-#8x", ddm_table.module_id);
37095- seq_printf(seq, "%-29s",
37096- chtostr(ddm_table.module_name_version, 28));
37097+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
37098 seq_printf(seq, "%9d ", ddm_table.data_size);
37099 seq_printf(seq, "%8d", ddm_table.code_size);
37100
37101@@ -944,8 +936,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
37102
37103 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
37104 seq_printf(seq, "%-#8x", dst->module_id);
37105- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
37106- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
37107+ seq_printf(seq, "%-.28s", dst->module_name_version);
37108+ seq_printf(seq, "%-.8s", dst->date);
37109 seq_printf(seq, "%8d ", dst->module_size);
37110 seq_printf(seq, "%8d ", dst->mpb_size);
37111 seq_printf(seq, "0x%04x", dst->module_flags);
37112@@ -1276,14 +1268,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
37113 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
37114 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
37115 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
37116- seq_printf(seq, "Vendor info : %s\n",
37117- chtostr((u8 *) (work32 + 2), 16));
37118- seq_printf(seq, "Product info : %s\n",
37119- chtostr((u8 *) (work32 + 6), 16));
37120- seq_printf(seq, "Description : %s\n",
37121- chtostr((u8 *) (work32 + 10), 16));
37122- seq_printf(seq, "Product rev. : %s\n",
37123- chtostr((u8 *) (work32 + 14), 8));
37124+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
37125+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
37126+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
37127+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
37128
37129 seq_printf(seq, "Serial number : ");
37130 print_serial_number(seq, (u8 *) (work32 + 16),
37131@@ -1328,10 +1316,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
37132 }
37133
37134 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
37135- seq_printf(seq, "Module name : %s\n",
37136- chtostr(result.module_name, 24));
37137- seq_printf(seq, "Module revision : %s\n",
37138- chtostr(result.module_rev, 8));
37139+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
37140+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
37141
37142 seq_printf(seq, "Serial number : ");
37143 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
37144@@ -1362,14 +1348,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
37145 return 0;
37146 }
37147
37148- seq_printf(seq, "Device name : %s\n",
37149- chtostr(result.device_name, 64));
37150- seq_printf(seq, "Service name : %s\n",
37151- chtostr(result.service_name, 64));
37152- seq_printf(seq, "Physical name : %s\n",
37153- chtostr(result.physical_location, 64));
37154- seq_printf(seq, "Instance number : %s\n",
37155- chtostr(result.instance_number, 4));
37156+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
37157+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
37158+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
37159+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
37160
37161 return 0;
37162 }
37163diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
37164index 27cf4af..b1205b8 100644
37165--- a/drivers/message/i2o/iop.c
37166+++ b/drivers/message/i2o/iop.c
37167@@ -110,10 +110,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
37168
37169 spin_lock_irqsave(&c->context_list_lock, flags);
37170
37171- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
37172- atomic_inc(&c->context_list_counter);
37173+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
37174+ atomic_inc_unchecked(&c->context_list_counter);
37175
37176- entry->context = atomic_read(&c->context_list_counter);
37177+ entry->context = atomic_read_unchecked(&c->context_list_counter);
37178
37179 list_add(&entry->list, &c->context_list);
37180
37181@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
37182
37183 #if BITS_PER_LONG == 64
37184 spin_lock_init(&c->context_list_lock);
37185- atomic_set(&c->context_list_counter, 0);
37186+ atomic_set_unchecked(&c->context_list_counter, 0);
37187 INIT_LIST_HEAD(&c->context_list);
37188 #endif
37189
37190diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
37191index 78e3e85..66c9a0d 100644
37192--- a/drivers/mfd/ab3100-core.c
37193+++ b/drivers/mfd/ab3100-core.c
37194@@ -777,7 +777,7 @@ struct ab_family_id {
37195 char *name;
37196 };
37197
37198-static const struct ab_family_id ids[] __initdata = {
37199+static const struct ab_family_id ids[] __initconst = {
37200 /* AB3100 */
37201 {
37202 .id = 0xc0,
37203diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
37204index 8d8c932..8104515 100644
37205--- a/drivers/mfd/wm8350-i2c.c
37206+++ b/drivers/mfd/wm8350-i2c.c
37207@@ -43,6 +43,8 @@ static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg,
37208 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
37209 int ret;
37210
37211+ pax_track_stack();
37212+
37213 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
37214 return -EINVAL;
37215
37216diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
37217index e4ff50b..4cc3f04 100644
37218--- a/drivers/misc/kgdbts.c
37219+++ b/drivers/misc/kgdbts.c
37220@@ -118,7 +118,7 @@
37221 } while (0)
37222 #define MAX_CONFIG_LEN 40
37223
37224-static struct kgdb_io kgdbts_io_ops;
37225+static const struct kgdb_io kgdbts_io_ops;
37226 static char get_buf[BUFMAX];
37227 static int get_buf_cnt;
37228 static char put_buf[BUFMAX];
37229@@ -1102,7 +1102,7 @@ static void kgdbts_post_exp_handler(void)
37230 module_put(THIS_MODULE);
37231 }
37232
37233-static struct kgdb_io kgdbts_io_ops = {
37234+static const struct kgdb_io kgdbts_io_ops = {
37235 .name = "kgdbts",
37236 .read_char = kgdbts_get_char,
37237 .write_char = kgdbts_put_char,
37238diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
37239index 37e7cfc..67cfb76 100644
37240--- a/drivers/misc/sgi-gru/gruhandles.c
37241+++ b/drivers/misc/sgi-gru/gruhandles.c
37242@@ -39,8 +39,8 @@ struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37243
37244 static void update_mcs_stats(enum mcs_op op, unsigned long clks)
37245 {
37246- atomic_long_inc(&mcs_op_statistics[op].count);
37247- atomic_long_add(clks, &mcs_op_statistics[op].total);
37248+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
37249+ atomic_long_add_unchecked(clks, &mcs_op_statistics[op].total);
37250 if (mcs_op_statistics[op].max < clks)
37251 mcs_op_statistics[op].max = clks;
37252 }
37253diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
37254index 3f2375c..467c6e6 100644
37255--- a/drivers/misc/sgi-gru/gruprocfs.c
37256+++ b/drivers/misc/sgi-gru/gruprocfs.c
37257@@ -32,9 +32,9 @@
37258
37259 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
37260
37261-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
37262+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
37263 {
37264- unsigned long val = atomic_long_read(v);
37265+ unsigned long val = atomic_long_read_unchecked(v);
37266
37267 if (val)
37268 seq_printf(s, "%16lu %s\n", val, id);
37269@@ -136,8 +136,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
37270 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
37271
37272 for (op = 0; op < mcsop_last; op++) {
37273- count = atomic_long_read(&mcs_op_statistics[op].count);
37274- total = atomic_long_read(&mcs_op_statistics[op].total);
37275+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
37276+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
37277 max = mcs_op_statistics[op].max;
37278 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
37279 count ? total / count : 0, max);
37280diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
37281index 46990bc..4a251b5 100644
37282--- a/drivers/misc/sgi-gru/grutables.h
37283+++ b/drivers/misc/sgi-gru/grutables.h
37284@@ -167,84 +167,84 @@ extern unsigned int gru_max_gids;
37285 * GRU statistics.
37286 */
37287 struct gru_stats_s {
37288- atomic_long_t vdata_alloc;
37289- atomic_long_t vdata_free;
37290- atomic_long_t gts_alloc;
37291- atomic_long_t gts_free;
37292- atomic_long_t vdata_double_alloc;
37293- atomic_long_t gts_double_allocate;
37294- atomic_long_t assign_context;
37295- atomic_long_t assign_context_failed;
37296- atomic_long_t free_context;
37297- atomic_long_t load_user_context;
37298- atomic_long_t load_kernel_context;
37299- atomic_long_t lock_kernel_context;
37300- atomic_long_t unlock_kernel_context;
37301- atomic_long_t steal_user_context;
37302- atomic_long_t steal_kernel_context;
37303- atomic_long_t steal_context_failed;
37304- atomic_long_t nopfn;
37305- atomic_long_t break_cow;
37306- atomic_long_t asid_new;
37307- atomic_long_t asid_next;
37308- atomic_long_t asid_wrap;
37309- atomic_long_t asid_reuse;
37310- atomic_long_t intr;
37311- atomic_long_t intr_mm_lock_failed;
37312- atomic_long_t call_os;
37313- atomic_long_t call_os_offnode_reference;
37314- atomic_long_t call_os_check_for_bug;
37315- atomic_long_t call_os_wait_queue;
37316- atomic_long_t user_flush_tlb;
37317- atomic_long_t user_unload_context;
37318- atomic_long_t user_exception;
37319- atomic_long_t set_context_option;
37320- atomic_long_t migrate_check;
37321- atomic_long_t migrated_retarget;
37322- atomic_long_t migrated_unload;
37323- atomic_long_t migrated_unload_delay;
37324- atomic_long_t migrated_nopfn_retarget;
37325- atomic_long_t migrated_nopfn_unload;
37326- atomic_long_t tlb_dropin;
37327- atomic_long_t tlb_dropin_fail_no_asid;
37328- atomic_long_t tlb_dropin_fail_upm;
37329- atomic_long_t tlb_dropin_fail_invalid;
37330- atomic_long_t tlb_dropin_fail_range_active;
37331- atomic_long_t tlb_dropin_fail_idle;
37332- atomic_long_t tlb_dropin_fail_fmm;
37333- atomic_long_t tlb_dropin_fail_no_exception;
37334- atomic_long_t tlb_dropin_fail_no_exception_war;
37335- atomic_long_t tfh_stale_on_fault;
37336- atomic_long_t mmu_invalidate_range;
37337- atomic_long_t mmu_invalidate_page;
37338- atomic_long_t mmu_clear_flush_young;
37339- atomic_long_t flush_tlb;
37340- atomic_long_t flush_tlb_gru;
37341- atomic_long_t flush_tlb_gru_tgh;
37342- atomic_long_t flush_tlb_gru_zero_asid;
37343+ atomic_long_unchecked_t vdata_alloc;
37344+ atomic_long_unchecked_t vdata_free;
37345+ atomic_long_unchecked_t gts_alloc;
37346+ atomic_long_unchecked_t gts_free;
37347+ atomic_long_unchecked_t vdata_double_alloc;
37348+ atomic_long_unchecked_t gts_double_allocate;
37349+ atomic_long_unchecked_t assign_context;
37350+ atomic_long_unchecked_t assign_context_failed;
37351+ atomic_long_unchecked_t free_context;
37352+ atomic_long_unchecked_t load_user_context;
37353+ atomic_long_unchecked_t load_kernel_context;
37354+ atomic_long_unchecked_t lock_kernel_context;
37355+ atomic_long_unchecked_t unlock_kernel_context;
37356+ atomic_long_unchecked_t steal_user_context;
37357+ atomic_long_unchecked_t steal_kernel_context;
37358+ atomic_long_unchecked_t steal_context_failed;
37359+ atomic_long_unchecked_t nopfn;
37360+ atomic_long_unchecked_t break_cow;
37361+ atomic_long_unchecked_t asid_new;
37362+ atomic_long_unchecked_t asid_next;
37363+ atomic_long_unchecked_t asid_wrap;
37364+ atomic_long_unchecked_t asid_reuse;
37365+ atomic_long_unchecked_t intr;
37366+ atomic_long_unchecked_t intr_mm_lock_failed;
37367+ atomic_long_unchecked_t call_os;
37368+ atomic_long_unchecked_t call_os_offnode_reference;
37369+ atomic_long_unchecked_t call_os_check_for_bug;
37370+ atomic_long_unchecked_t call_os_wait_queue;
37371+ atomic_long_unchecked_t user_flush_tlb;
37372+ atomic_long_unchecked_t user_unload_context;
37373+ atomic_long_unchecked_t user_exception;
37374+ atomic_long_unchecked_t set_context_option;
37375+ atomic_long_unchecked_t migrate_check;
37376+ atomic_long_unchecked_t migrated_retarget;
37377+ atomic_long_unchecked_t migrated_unload;
37378+ atomic_long_unchecked_t migrated_unload_delay;
37379+ atomic_long_unchecked_t migrated_nopfn_retarget;
37380+ atomic_long_unchecked_t migrated_nopfn_unload;
37381+ atomic_long_unchecked_t tlb_dropin;
37382+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
37383+ atomic_long_unchecked_t tlb_dropin_fail_upm;
37384+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
37385+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
37386+ atomic_long_unchecked_t tlb_dropin_fail_idle;
37387+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
37388+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
37389+ atomic_long_unchecked_t tlb_dropin_fail_no_exception_war;
37390+ atomic_long_unchecked_t tfh_stale_on_fault;
37391+ atomic_long_unchecked_t mmu_invalidate_range;
37392+ atomic_long_unchecked_t mmu_invalidate_page;
37393+ atomic_long_unchecked_t mmu_clear_flush_young;
37394+ atomic_long_unchecked_t flush_tlb;
37395+ atomic_long_unchecked_t flush_tlb_gru;
37396+ atomic_long_unchecked_t flush_tlb_gru_tgh;
37397+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
37398
37399- atomic_long_t copy_gpa;
37400+ atomic_long_unchecked_t copy_gpa;
37401
37402- atomic_long_t mesq_receive;
37403- atomic_long_t mesq_receive_none;
37404- atomic_long_t mesq_send;
37405- atomic_long_t mesq_send_failed;
37406- atomic_long_t mesq_noop;
37407- atomic_long_t mesq_send_unexpected_error;
37408- atomic_long_t mesq_send_lb_overflow;
37409- atomic_long_t mesq_send_qlimit_reached;
37410- atomic_long_t mesq_send_amo_nacked;
37411- atomic_long_t mesq_send_put_nacked;
37412- atomic_long_t mesq_qf_not_full;
37413- atomic_long_t mesq_qf_locked;
37414- atomic_long_t mesq_qf_noop_not_full;
37415- atomic_long_t mesq_qf_switch_head_failed;
37416- atomic_long_t mesq_qf_unexpected_error;
37417- atomic_long_t mesq_noop_unexpected_error;
37418- atomic_long_t mesq_noop_lb_overflow;
37419- atomic_long_t mesq_noop_qlimit_reached;
37420- atomic_long_t mesq_noop_amo_nacked;
37421- atomic_long_t mesq_noop_put_nacked;
37422+ atomic_long_unchecked_t mesq_receive;
37423+ atomic_long_unchecked_t mesq_receive_none;
37424+ atomic_long_unchecked_t mesq_send;
37425+ atomic_long_unchecked_t mesq_send_failed;
37426+ atomic_long_unchecked_t mesq_noop;
37427+ atomic_long_unchecked_t mesq_send_unexpected_error;
37428+ atomic_long_unchecked_t mesq_send_lb_overflow;
37429+ atomic_long_unchecked_t mesq_send_qlimit_reached;
37430+ atomic_long_unchecked_t mesq_send_amo_nacked;
37431+ atomic_long_unchecked_t mesq_send_put_nacked;
37432+ atomic_long_unchecked_t mesq_qf_not_full;
37433+ atomic_long_unchecked_t mesq_qf_locked;
37434+ atomic_long_unchecked_t mesq_qf_noop_not_full;
37435+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
37436+ atomic_long_unchecked_t mesq_qf_unexpected_error;
37437+ atomic_long_unchecked_t mesq_noop_unexpected_error;
37438+ atomic_long_unchecked_t mesq_noop_lb_overflow;
37439+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
37440+ atomic_long_unchecked_t mesq_noop_amo_nacked;
37441+ atomic_long_unchecked_t mesq_noop_put_nacked;
37442
37443 };
37444
37445@@ -252,8 +252,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
37446 cchop_deallocate, tghop_invalidate, mcsop_last};
37447
37448 struct mcs_op_statistic {
37449- atomic_long_t count;
37450- atomic_long_t total;
37451+ atomic_long_unchecked_t count;
37452+ atomic_long_unchecked_t total;
37453 unsigned long max;
37454 };
37455
37456@@ -276,7 +276,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37457
37458 #define STAT(id) do { \
37459 if (gru_options & OPT_STATS) \
37460- atomic_long_inc(&gru_stats.id); \
37461+ atomic_long_inc_unchecked(&gru_stats.id); \
37462 } while (0)
37463
37464 #ifdef CONFIG_SGI_GRU_DEBUG
37465diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
37466index 2275126..12a9dbfb 100644
37467--- a/drivers/misc/sgi-xp/xp.h
37468+++ b/drivers/misc/sgi-xp/xp.h
37469@@ -289,7 +289,7 @@ struct xpc_interface {
37470 xpc_notify_func, void *);
37471 void (*received) (short, int, void *);
37472 enum xp_retval (*partid_to_nasids) (short, void *);
37473-};
37474+} __no_const;
37475
37476 extern struct xpc_interface xpc_interface;
37477
37478diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
37479index b94d5f7..7f494c5 100644
37480--- a/drivers/misc/sgi-xp/xpc.h
37481+++ b/drivers/misc/sgi-xp/xpc.h
37482@@ -835,6 +835,7 @@ struct xpc_arch_operations {
37483 void (*received_payload) (struct xpc_channel *, void *);
37484 void (*notify_senders_of_disconnect) (struct xpc_channel *);
37485 };
37486+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
37487
37488 /* struct xpc_partition act_state values (for XPC HB) */
37489
37490@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
37491 /* found in xpc_main.c */
37492 extern struct device *xpc_part;
37493 extern struct device *xpc_chan;
37494-extern struct xpc_arch_operations xpc_arch_ops;
37495+extern xpc_arch_operations_no_const xpc_arch_ops;
37496 extern int xpc_disengage_timelimit;
37497 extern int xpc_disengage_timedout;
37498 extern int xpc_activate_IRQ_rcvd;
37499diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
37500index fd3688a..7e211a4 100644
37501--- a/drivers/misc/sgi-xp/xpc_main.c
37502+++ b/drivers/misc/sgi-xp/xpc_main.c
37503@@ -169,7 +169,7 @@ static struct notifier_block xpc_die_notifier = {
37504 .notifier_call = xpc_system_die,
37505 };
37506
37507-struct xpc_arch_operations xpc_arch_ops;
37508+xpc_arch_operations_no_const xpc_arch_ops;
37509
37510 /*
37511 * Timer function to enforce the timelimit on the partition disengage.
37512diff --git a/drivers/misc/sgi-xp/xpc_sn2.c b/drivers/misc/sgi-xp/xpc_sn2.c
37513index 8b70e03..700bda6 100644
37514--- a/drivers/misc/sgi-xp/xpc_sn2.c
37515+++ b/drivers/misc/sgi-xp/xpc_sn2.c
37516@@ -2350,7 +2350,7 @@ xpc_received_payload_sn2(struct xpc_channel *ch, void *payload)
37517 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
37518 }
37519
37520-static struct xpc_arch_operations xpc_arch_ops_sn2 = {
37521+static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
37522 .setup_partitions = xpc_setup_partitions_sn2,
37523 .teardown_partitions = xpc_teardown_partitions_sn2,
37524 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
37525@@ -2413,7 +2413,9 @@ xpc_init_sn2(void)
37526 int ret;
37527 size_t buf_size;
37528
37529- xpc_arch_ops = xpc_arch_ops_sn2;
37530+ pax_open_kernel();
37531+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_sn2, sizeof(xpc_arch_ops_sn2));
37532+ pax_close_kernel();
37533
37534 if (offsetof(struct xpc_msg_sn2, payload) > XPC_MSG_HDR_MAX_SIZE) {
37535 dev_err(xpc_part, "header portion of struct xpc_msg_sn2 is "
37536diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
37537index 8e08d71..7cb8c9b 100644
37538--- a/drivers/misc/sgi-xp/xpc_uv.c
37539+++ b/drivers/misc/sgi-xp/xpc_uv.c
37540@@ -1669,7 +1669,7 @@ xpc_received_payload_uv(struct xpc_channel *ch, void *payload)
37541 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
37542 }
37543
37544-static struct xpc_arch_operations xpc_arch_ops_uv = {
37545+static const struct xpc_arch_operations xpc_arch_ops_uv = {
37546 .setup_partitions = xpc_setup_partitions_uv,
37547 .teardown_partitions = xpc_teardown_partitions_uv,
37548 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
37549@@ -1729,7 +1729,9 @@ static struct xpc_arch_operations xpc_arch_ops_uv = {
37550 int
37551 xpc_init_uv(void)
37552 {
37553- xpc_arch_ops = xpc_arch_ops_uv;
37554+ pax_open_kernel();
37555+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_uv, sizeof(xpc_arch_ops_uv));
37556+ pax_close_kernel();
37557
37558 if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
37559 dev_err(xpc_part, "xpc_notify_mq_msghdr_uv is larger than %d\n",
37560diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
37561index 6fd20b42..650efe3 100644
37562--- a/drivers/mmc/host/sdhci-pci.c
37563+++ b/drivers/mmc/host/sdhci-pci.c
37564@@ -297,7 +297,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
37565 .probe = via_probe,
37566 };
37567
37568-static const struct pci_device_id pci_ids[] __devinitdata = {
37569+static const struct pci_device_id pci_ids[] __devinitconst = {
37570 {
37571 .vendor = PCI_VENDOR_ID_RICOH,
37572 .device = PCI_DEVICE_ID_RICOH_R5C822,
37573diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
37574index e7563a9..5f90ce5 100644
37575--- a/drivers/mtd/chips/cfi_cmdset_0001.c
37576+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
37577@@ -743,6 +743,8 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
37578 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
37579 unsigned long timeo = jiffies + HZ;
37580
37581+ pax_track_stack();
37582+
37583 /* Prevent setting state FL_SYNCING for chip in suspended state. */
37584 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
37585 goto sleep;
37586@@ -1642,6 +1644,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
37587 unsigned long initial_adr;
37588 int initial_len = len;
37589
37590+ pax_track_stack();
37591+
37592 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
37593 adr += chip->start;
37594 initial_adr = adr;
37595@@ -1860,6 +1864,8 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
37596 int retries = 3;
37597 int ret;
37598
37599+ pax_track_stack();
37600+
37601 adr += chip->start;
37602
37603 retry:
37604diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
37605index 0667a67..3ab97ed 100644
37606--- a/drivers/mtd/chips/cfi_cmdset_0020.c
37607+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
37608@@ -255,6 +255,8 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
37609 unsigned long cmd_addr;
37610 struct cfi_private *cfi = map->fldrv_priv;
37611
37612+ pax_track_stack();
37613+
37614 adr += chip->start;
37615
37616 /* Ensure cmd read/writes are aligned. */
37617@@ -428,6 +430,8 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
37618 DECLARE_WAITQUEUE(wait, current);
37619 int wbufsize, z;
37620
37621+ pax_track_stack();
37622+
37623 /* M58LW064A requires bus alignment for buffer wriets -- saw */
37624 if (adr & (map_bankwidth(map)-1))
37625 return -EINVAL;
37626@@ -742,6 +746,8 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
37627 DECLARE_WAITQUEUE(wait, current);
37628 int ret = 0;
37629
37630+ pax_track_stack();
37631+
37632 adr += chip->start;
37633
37634 /* Let's determine this according to the interleave only once */
37635@@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struct map_info *map, struct flchip *chip, un
37636 unsigned long timeo = jiffies + HZ;
37637 DECLARE_WAITQUEUE(wait, current);
37638
37639+ pax_track_stack();
37640+
37641 adr += chip->start;
37642
37643 /* Let's determine this according to the interleave only once */
37644@@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(struct map_info *map, struct flchip *chip,
37645 unsigned long timeo = jiffies + HZ;
37646 DECLARE_WAITQUEUE(wait, current);
37647
37648+ pax_track_stack();
37649+
37650 adr += chip->start;
37651
37652 /* Let's determine this according to the interleave only once */
37653diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
37654index 5bf5f46..c5de373 100644
37655--- a/drivers/mtd/devices/doc2000.c
37656+++ b/drivers/mtd/devices/doc2000.c
37657@@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
37658
37659 /* The ECC will not be calculated correctly if less than 512 is written */
37660 /* DBB-
37661- if (len != 0x200 && eccbuf)
37662+ if (len != 0x200)
37663 printk(KERN_WARNING
37664 "ECC needs a full sector write (adr: %lx size %lx)\n",
37665 (long) to, (long) len);
37666diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
37667index 0990f78..bb4e8a4 100644
37668--- a/drivers/mtd/devices/doc2001.c
37669+++ b/drivers/mtd/devices/doc2001.c
37670@@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
37671 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
37672
37673 /* Don't allow read past end of device */
37674- if (from >= this->totlen)
37675+ if (from >= this->totlen || !len)
37676 return -EINVAL;
37677
37678 /* Don't allow a single read to cross a 512-byte block boundary */
37679diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
37680index e56d6b4..f07e6cf 100644
37681--- a/drivers/mtd/ftl.c
37682+++ b/drivers/mtd/ftl.c
37683@@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit,
37684 loff_t offset;
37685 uint16_t srcunitswap = cpu_to_le16(srcunit);
37686
37687+ pax_track_stack();
37688+
37689 eun = &part->EUNInfo[srcunit];
37690 xfer = &part->XferInfo[xferunit];
37691 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
37692diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
37693index 8aca552..146446e 100755
37694--- a/drivers/mtd/inftlcore.c
37695+++ b/drivers/mtd/inftlcore.c
37696@@ -260,6 +260,8 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
37697 struct inftl_oob oob;
37698 size_t retlen;
37699
37700+ pax_track_stack();
37701+
37702 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
37703 "pending=%d)\n", inftl, thisVUC, pendingblock);
37704
37705diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
37706index 32e82ae..ed50953 100644
37707--- a/drivers/mtd/inftlmount.c
37708+++ b/drivers/mtd/inftlmount.c
37709@@ -54,6 +54,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
37710 struct INFTLPartition *ip;
37711 size_t retlen;
37712
37713+ pax_track_stack();
37714+
37715 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
37716
37717 /*
37718diff --git a/drivers/mtd/lpddr/qinfo_probe.c b/drivers/mtd/lpddr/qinfo_probe.c
37719index 79bf40f..fe5f8fd 100644
37720--- a/drivers/mtd/lpddr/qinfo_probe.c
37721+++ b/drivers/mtd/lpddr/qinfo_probe.c
37722@@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map_info *map, struct lpddr_private *lpddr)
37723 {
37724 map_word pfow_val[4];
37725
37726+ pax_track_stack();
37727+
37728 /* Check identification string */
37729 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
37730 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
37731diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
37732index 726a1b8..f46b460 100644
37733--- a/drivers/mtd/mtdchar.c
37734+++ b/drivers/mtd/mtdchar.c
37735@@ -461,6 +461,8 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
37736 u_long size;
37737 struct mtd_info_user info;
37738
37739+ pax_track_stack();
37740+
37741 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
37742
37743 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
37744diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
37745index 1002e18..26d82d5 100644
37746--- a/drivers/mtd/nftlcore.c
37747+++ b/drivers/mtd/nftlcore.c
37748@@ -254,6 +254,8 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
37749 int inplace = 1;
37750 size_t retlen;
37751
37752+ pax_track_stack();
37753+
37754 memset(BlockMap, 0xff, sizeof(BlockMap));
37755 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
37756
37757diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
37758index 8b22b18..6fada85 100644
37759--- a/drivers/mtd/nftlmount.c
37760+++ b/drivers/mtd/nftlmount.c
37761@@ -23,6 +23,7 @@
37762 #include <asm/errno.h>
37763 #include <linux/delay.h>
37764 #include <linux/slab.h>
37765+#include <linux/sched.h>
37766 #include <linux/mtd/mtd.h>
37767 #include <linux/mtd/nand.h>
37768 #include <linux/mtd/nftl.h>
37769@@ -44,6 +45,8 @@ static int find_boot_record(struct NFTLrecord *nftl)
37770 struct mtd_info *mtd = nftl->mbd.mtd;
37771 unsigned int i;
37772
37773+ pax_track_stack();
37774+
37775 /* Assume logical EraseSize == physical erasesize for starting the scan.
37776 We'll sort it out later if we find a MediaHeader which says otherwise */
37777 /* Actually, we won't. The new DiskOnChip driver has already scanned
37778diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
37779index 14cec04..d775b87 100644
37780--- a/drivers/mtd/ubi/build.c
37781+++ b/drivers/mtd/ubi/build.c
37782@@ -1255,7 +1255,7 @@ module_exit(ubi_exit);
37783 static int __init bytes_str_to_int(const char *str)
37784 {
37785 char *endp;
37786- unsigned long result;
37787+ unsigned long result, scale = 1;
37788
37789 result = simple_strtoul(str, &endp, 0);
37790 if (str == endp || result >= INT_MAX) {
37791@@ -1266,11 +1266,11 @@ static int __init bytes_str_to_int(const char *str)
37792
37793 switch (*endp) {
37794 case 'G':
37795- result *= 1024;
37796+ scale *= 1024;
37797 case 'M':
37798- result *= 1024;
37799+ scale *= 1024;
37800 case 'K':
37801- result *= 1024;
37802+ scale *= 1024;
37803 if (endp[1] == 'i' && endp[2] == 'B')
37804 endp += 2;
37805 case '\0':
37806@@ -1281,7 +1281,13 @@ static int __init bytes_str_to_int(const char *str)
37807 return -EINVAL;
37808 }
37809
37810- return result;
37811+ if ((intoverflow_t)result*scale >= INT_MAX) {
37812+ printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
37813+ str);
37814+ return -EINVAL;
37815+ }
37816+
37817+ return result*scale;
37818 }
37819
37820 /**
37821diff --git a/drivers/net/atlx/atl2.c b/drivers/net/atlx/atl2.c
37822index ab68886..ca405e8 100644
37823--- a/drivers/net/atlx/atl2.c
37824+++ b/drivers/net/atlx/atl2.c
37825@@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
37826 */
37827
37828 #define ATL2_PARAM(X, desc) \
37829- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
37830+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
37831 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
37832 MODULE_PARM_DESC(X, desc);
37833 #else
37834diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
37835index 4874b2b..67f8526 100644
37836--- a/drivers/net/bnx2.c
37837+++ b/drivers/net/bnx2.c
37838@@ -5809,6 +5809,8 @@ bnx2_test_nvram(struct bnx2 *bp)
37839 int rc = 0;
37840 u32 magic, csum;
37841
37842+ pax_track_stack();
37843+
37844 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
37845 goto test_nvram_done;
37846
37847diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h
37848index fd3eb07..8a6978d 100644
37849--- a/drivers/net/cxgb3/l2t.h
37850+++ b/drivers/net/cxgb3/l2t.h
37851@@ -86,7 +86,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
37852 */
37853 struct l2t_skb_cb {
37854 arp_failure_handler_func arp_failure_handler;
37855-};
37856+} __no_const;
37857
37858 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
37859
37860diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c
37861index 032cfe0..411af379 100644
37862--- a/drivers/net/cxgb3/t3_hw.c
37863+++ b/drivers/net/cxgb3/t3_hw.c
37864@@ -699,6 +699,8 @@ static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
37865 int i, addr, ret;
37866 struct t3_vpd vpd;
37867
37868+ pax_track_stack();
37869+
37870 /*
37871 * Card information is normally at VPD_BASE but some early cards had
37872 * it at 0.
37873diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
37874index d1e0563..b9e129c 100644
37875--- a/drivers/net/e1000e/82571.c
37876+++ b/drivers/net/e1000e/82571.c
37877@@ -212,7 +212,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
37878 {
37879 struct e1000_hw *hw = &adapter->hw;
37880 struct e1000_mac_info *mac = &hw->mac;
37881- struct e1000_mac_operations *func = &mac->ops;
37882+ e1000_mac_operations_no_const *func = &mac->ops;
37883 u32 swsm = 0;
37884 u32 swsm2 = 0;
37885 bool force_clear_smbi = false;
37886@@ -1656,7 +1656,7 @@ static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
37887 temp = er32(ICRXDMTC);
37888 }
37889
37890-static struct e1000_mac_operations e82571_mac_ops = {
37891+static const struct e1000_mac_operations e82571_mac_ops = {
37892 /* .check_mng_mode: mac type dependent */
37893 /* .check_for_link: media type dependent */
37894 .id_led_init = e1000e_id_led_init,
37895@@ -1674,7 +1674,7 @@ static struct e1000_mac_operations e82571_mac_ops = {
37896 .setup_led = e1000e_setup_led_generic,
37897 };
37898
37899-static struct e1000_phy_operations e82_phy_ops_igp = {
37900+static const struct e1000_phy_operations e82_phy_ops_igp = {
37901 .acquire_phy = e1000_get_hw_semaphore_82571,
37902 .check_reset_block = e1000e_check_reset_block_generic,
37903 .commit_phy = NULL,
37904@@ -1691,7 +1691,7 @@ static struct e1000_phy_operations e82_phy_ops_igp = {
37905 .cfg_on_link_up = NULL,
37906 };
37907
37908-static struct e1000_phy_operations e82_phy_ops_m88 = {
37909+static const struct e1000_phy_operations e82_phy_ops_m88 = {
37910 .acquire_phy = e1000_get_hw_semaphore_82571,
37911 .check_reset_block = e1000e_check_reset_block_generic,
37912 .commit_phy = e1000e_phy_sw_reset,
37913@@ -1708,7 +1708,7 @@ static struct e1000_phy_operations e82_phy_ops_m88 = {
37914 .cfg_on_link_up = NULL,
37915 };
37916
37917-static struct e1000_phy_operations e82_phy_ops_bm = {
37918+static const struct e1000_phy_operations e82_phy_ops_bm = {
37919 .acquire_phy = e1000_get_hw_semaphore_82571,
37920 .check_reset_block = e1000e_check_reset_block_generic,
37921 .commit_phy = e1000e_phy_sw_reset,
37922@@ -1725,7 +1725,7 @@ static struct e1000_phy_operations e82_phy_ops_bm = {
37923 .cfg_on_link_up = NULL,
37924 };
37925
37926-static struct e1000_nvm_operations e82571_nvm_ops = {
37927+static const struct e1000_nvm_operations e82571_nvm_ops = {
37928 .acquire_nvm = e1000_acquire_nvm_82571,
37929 .read_nvm = e1000e_read_nvm_eerd,
37930 .release_nvm = e1000_release_nvm_82571,
37931diff --git a/drivers/net/e1000e/e1000.h b/drivers/net/e1000e/e1000.h
37932index 47db9bd..fa58ccd 100644
37933--- a/drivers/net/e1000e/e1000.h
37934+++ b/drivers/net/e1000e/e1000.h
37935@@ -375,9 +375,9 @@ struct e1000_info {
37936 u32 pba;
37937 u32 max_hw_frame_size;
37938 s32 (*get_variants)(struct e1000_adapter *);
37939- struct e1000_mac_operations *mac_ops;
37940- struct e1000_phy_operations *phy_ops;
37941- struct e1000_nvm_operations *nvm_ops;
37942+ const struct e1000_mac_operations *mac_ops;
37943+ const struct e1000_phy_operations *phy_ops;
37944+ const struct e1000_nvm_operations *nvm_ops;
37945 };
37946
37947 /* hardware capability, feature, and workaround flags */
37948diff --git a/drivers/net/e1000e/es2lan.c b/drivers/net/e1000e/es2lan.c
37949index ae5d736..e9a93a1 100644
37950--- a/drivers/net/e1000e/es2lan.c
37951+++ b/drivers/net/e1000e/es2lan.c
37952@@ -207,7 +207,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
37953 {
37954 struct e1000_hw *hw = &adapter->hw;
37955 struct e1000_mac_info *mac = &hw->mac;
37956- struct e1000_mac_operations *func = &mac->ops;
37957+ e1000_mac_operations_no_const *func = &mac->ops;
37958
37959 /* Set media type */
37960 switch (adapter->pdev->device) {
37961@@ -1365,7 +1365,7 @@ static void e1000_clear_hw_cntrs_80003es2lan(struct e1000_hw *hw)
37962 temp = er32(ICRXDMTC);
37963 }
37964
37965-static struct e1000_mac_operations es2_mac_ops = {
37966+static const struct e1000_mac_operations es2_mac_ops = {
37967 .id_led_init = e1000e_id_led_init,
37968 .check_mng_mode = e1000e_check_mng_mode_generic,
37969 /* check_for_link dependent on media type */
37970@@ -1383,7 +1383,7 @@ static struct e1000_mac_operations es2_mac_ops = {
37971 .setup_led = e1000e_setup_led_generic,
37972 };
37973
37974-static struct e1000_phy_operations es2_phy_ops = {
37975+static const struct e1000_phy_operations es2_phy_ops = {
37976 .acquire_phy = e1000_acquire_phy_80003es2lan,
37977 .check_reset_block = e1000e_check_reset_block_generic,
37978 .commit_phy = e1000e_phy_sw_reset,
37979@@ -1400,7 +1400,7 @@ static struct e1000_phy_operations es2_phy_ops = {
37980 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
37981 };
37982
37983-static struct e1000_nvm_operations es2_nvm_ops = {
37984+static const struct e1000_nvm_operations es2_nvm_ops = {
37985 .acquire_nvm = e1000_acquire_nvm_80003es2lan,
37986 .read_nvm = e1000e_read_nvm_eerd,
37987 .release_nvm = e1000_release_nvm_80003es2lan,
37988diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
37989index 11f3b7c..6381887 100644
37990--- a/drivers/net/e1000e/hw.h
37991+++ b/drivers/net/e1000e/hw.h
37992@@ -753,6 +753,7 @@ struct e1000_mac_operations {
37993 s32 (*setup_physical_interface)(struct e1000_hw *);
37994 s32 (*setup_led)(struct e1000_hw *);
37995 };
37996+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
37997
37998 /* Function pointers for the PHY. */
37999 struct e1000_phy_operations {
38000@@ -774,6 +775,7 @@ struct e1000_phy_operations {
38001 s32 (*write_phy_reg_locked)(struct e1000_hw *, u32, u16);
38002 s32 (*cfg_on_link_up)(struct e1000_hw *);
38003 };
38004+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
38005
38006 /* Function pointers for the NVM. */
38007 struct e1000_nvm_operations {
38008@@ -785,9 +787,10 @@ struct e1000_nvm_operations {
38009 s32 (*validate_nvm)(struct e1000_hw *);
38010 s32 (*write_nvm)(struct e1000_hw *, u16, u16, u16 *);
38011 };
38012+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
38013
38014 struct e1000_mac_info {
38015- struct e1000_mac_operations ops;
38016+ e1000_mac_operations_no_const ops;
38017
38018 u8 addr[6];
38019 u8 perm_addr[6];
38020@@ -823,7 +826,7 @@ struct e1000_mac_info {
38021 };
38022
38023 struct e1000_phy_info {
38024- struct e1000_phy_operations ops;
38025+ e1000_phy_operations_no_const ops;
38026
38027 enum e1000_phy_type type;
38028
38029@@ -857,7 +860,7 @@ struct e1000_phy_info {
38030 };
38031
38032 struct e1000_nvm_info {
38033- struct e1000_nvm_operations ops;
38034+ e1000_nvm_operations_no_const ops;
38035
38036 enum e1000_nvm_type type;
38037 enum e1000_nvm_override override;
38038diff --git a/drivers/net/e1000e/ich8lan.c b/drivers/net/e1000e/ich8lan.c
38039index de39f9a..e28d3e0 100644
38040--- a/drivers/net/e1000e/ich8lan.c
38041+++ b/drivers/net/e1000e/ich8lan.c
38042@@ -3463,7 +3463,7 @@ static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
38043 }
38044 }
38045
38046-static struct e1000_mac_operations ich8_mac_ops = {
38047+static const struct e1000_mac_operations ich8_mac_ops = {
38048 .id_led_init = e1000e_id_led_init,
38049 .check_mng_mode = e1000_check_mng_mode_ich8lan,
38050 .check_for_link = e1000_check_for_copper_link_ich8lan,
38051@@ -3481,7 +3481,7 @@ static struct e1000_mac_operations ich8_mac_ops = {
38052 /* id_led_init dependent on mac type */
38053 };
38054
38055-static struct e1000_phy_operations ich8_phy_ops = {
38056+static const struct e1000_phy_operations ich8_phy_ops = {
38057 .acquire_phy = e1000_acquire_swflag_ich8lan,
38058 .check_reset_block = e1000_check_reset_block_ich8lan,
38059 .commit_phy = NULL,
38060@@ -3497,7 +3497,7 @@ static struct e1000_phy_operations ich8_phy_ops = {
38061 .write_phy_reg = e1000e_write_phy_reg_igp,
38062 };
38063
38064-static struct e1000_nvm_operations ich8_nvm_ops = {
38065+static const struct e1000_nvm_operations ich8_nvm_ops = {
38066 .acquire_nvm = e1000_acquire_nvm_ich8lan,
38067 .read_nvm = e1000_read_nvm_ich8lan,
38068 .release_nvm = e1000_release_nvm_ich8lan,
38069diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
38070index 18d5fbb..542d96d 100644
38071--- a/drivers/net/fealnx.c
38072+++ b/drivers/net/fealnx.c
38073@@ -151,7 +151,7 @@ struct chip_info {
38074 int flags;
38075 };
38076
38077-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
38078+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
38079 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
38080 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
38081 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
38082diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
38083index 0e5b54b..b503f82 100644
38084--- a/drivers/net/hamradio/6pack.c
38085+++ b/drivers/net/hamradio/6pack.c
38086@@ -461,6 +461,8 @@ static void sixpack_receive_buf(struct tty_struct *tty,
38087 unsigned char buf[512];
38088 int count1;
38089
38090+ pax_track_stack();
38091+
38092 if (!count)
38093 return;
38094
38095diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
38096index 5862282..7cce8cb 100644
38097--- a/drivers/net/ibmveth.c
38098+++ b/drivers/net/ibmveth.c
38099@@ -1577,7 +1577,7 @@ static struct attribute * veth_pool_attrs[] = {
38100 NULL,
38101 };
38102
38103-static struct sysfs_ops veth_pool_ops = {
38104+static const struct sysfs_ops veth_pool_ops = {
38105 .show = veth_pool_show,
38106 .store = veth_pool_store,
38107 };
38108diff --git a/drivers/net/igb/e1000_82575.c b/drivers/net/igb/e1000_82575.c
38109index d617f2d..57b5309 100644
38110--- a/drivers/net/igb/e1000_82575.c
38111+++ b/drivers/net/igb/e1000_82575.c
38112@@ -1411,7 +1411,7 @@ void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
38113 wr32(E1000_VT_CTL, vt_ctl);
38114 }
38115
38116-static struct e1000_mac_operations e1000_mac_ops_82575 = {
38117+static const struct e1000_mac_operations e1000_mac_ops_82575 = {
38118 .reset_hw = igb_reset_hw_82575,
38119 .init_hw = igb_init_hw_82575,
38120 .check_for_link = igb_check_for_link_82575,
38121@@ -1420,13 +1420,13 @@ static struct e1000_mac_operations e1000_mac_ops_82575 = {
38122 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
38123 };
38124
38125-static struct e1000_phy_operations e1000_phy_ops_82575 = {
38126+static const struct e1000_phy_operations e1000_phy_ops_82575 = {
38127 .acquire = igb_acquire_phy_82575,
38128 .get_cfg_done = igb_get_cfg_done_82575,
38129 .release = igb_release_phy_82575,
38130 };
38131
38132-static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
38133+static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
38134 .acquire = igb_acquire_nvm_82575,
38135 .read = igb_read_nvm_eerd,
38136 .release = igb_release_nvm_82575,
38137diff --git a/drivers/net/igb/e1000_hw.h b/drivers/net/igb/e1000_hw.h
38138index 72081df..d855cf5 100644
38139--- a/drivers/net/igb/e1000_hw.h
38140+++ b/drivers/net/igb/e1000_hw.h
38141@@ -288,6 +288,7 @@ struct e1000_mac_operations {
38142 s32 (*read_mac_addr)(struct e1000_hw *);
38143 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
38144 };
38145+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
38146
38147 struct e1000_phy_operations {
38148 s32 (*acquire)(struct e1000_hw *);
38149@@ -303,6 +304,7 @@ struct e1000_phy_operations {
38150 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
38151 s32 (*write_reg)(struct e1000_hw *, u32, u16);
38152 };
38153+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
38154
38155 struct e1000_nvm_operations {
38156 s32 (*acquire)(struct e1000_hw *);
38157@@ -310,6 +312,7 @@ struct e1000_nvm_operations {
38158 void (*release)(struct e1000_hw *);
38159 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
38160 };
38161+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
38162
38163 struct e1000_info {
38164 s32 (*get_invariants)(struct e1000_hw *);
38165@@ -321,7 +324,7 @@ struct e1000_info {
38166 extern const struct e1000_info e1000_82575_info;
38167
38168 struct e1000_mac_info {
38169- struct e1000_mac_operations ops;
38170+ e1000_mac_operations_no_const ops;
38171
38172 u8 addr[6];
38173 u8 perm_addr[6];
38174@@ -365,7 +368,7 @@ struct e1000_mac_info {
38175 };
38176
38177 struct e1000_phy_info {
38178- struct e1000_phy_operations ops;
38179+ e1000_phy_operations_no_const ops;
38180
38181 enum e1000_phy_type type;
38182
38183@@ -400,7 +403,7 @@ struct e1000_phy_info {
38184 };
38185
38186 struct e1000_nvm_info {
38187- struct e1000_nvm_operations ops;
38188+ e1000_nvm_operations_no_const ops;
38189
38190 enum e1000_nvm_type type;
38191 enum e1000_nvm_override override;
38192@@ -446,6 +449,7 @@ struct e1000_mbx_operations {
38193 s32 (*check_for_ack)(struct e1000_hw *, u16);
38194 s32 (*check_for_rst)(struct e1000_hw *, u16);
38195 };
38196+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
38197
38198 struct e1000_mbx_stats {
38199 u32 msgs_tx;
38200@@ -457,7 +461,7 @@ struct e1000_mbx_stats {
38201 };
38202
38203 struct e1000_mbx_info {
38204- struct e1000_mbx_operations ops;
38205+ e1000_mbx_operations_no_const ops;
38206 struct e1000_mbx_stats stats;
38207 u32 timeout;
38208 u32 usec_delay;
38209diff --git a/drivers/net/igbvf/vf.h b/drivers/net/igbvf/vf.h
38210index 1e8ce37..549c453 100644
38211--- a/drivers/net/igbvf/vf.h
38212+++ b/drivers/net/igbvf/vf.h
38213@@ -187,9 +187,10 @@ struct e1000_mac_operations {
38214 s32 (*read_mac_addr)(struct e1000_hw *);
38215 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
38216 };
38217+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
38218
38219 struct e1000_mac_info {
38220- struct e1000_mac_operations ops;
38221+ e1000_mac_operations_no_const ops;
38222 u8 addr[6];
38223 u8 perm_addr[6];
38224
38225@@ -211,6 +212,7 @@ struct e1000_mbx_operations {
38226 s32 (*check_for_ack)(struct e1000_hw *);
38227 s32 (*check_for_rst)(struct e1000_hw *);
38228 };
38229+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
38230
38231 struct e1000_mbx_stats {
38232 u32 msgs_tx;
38233@@ -222,7 +224,7 @@ struct e1000_mbx_stats {
38234 };
38235
38236 struct e1000_mbx_info {
38237- struct e1000_mbx_operations ops;
38238+ e1000_mbx_operations_no_const ops;
38239 struct e1000_mbx_stats stats;
38240 u32 timeout;
38241 u32 usec_delay;
38242diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
38243index aa7286b..a61394f 100644
38244--- a/drivers/net/iseries_veth.c
38245+++ b/drivers/net/iseries_veth.c
38246@@ -384,7 +384,7 @@ static struct attribute *veth_cnx_default_attrs[] = {
38247 NULL
38248 };
38249
38250-static struct sysfs_ops veth_cnx_sysfs_ops = {
38251+static const struct sysfs_ops veth_cnx_sysfs_ops = {
38252 .show = veth_cnx_attribute_show
38253 };
38254
38255@@ -441,7 +441,7 @@ static struct attribute *veth_port_default_attrs[] = {
38256 NULL
38257 };
38258
38259-static struct sysfs_ops veth_port_sysfs_ops = {
38260+static const struct sysfs_ops veth_port_sysfs_ops = {
38261 .show = veth_port_attribute_show
38262 };
38263
38264diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
38265index 8aa44dc..fa1e797 100644
38266--- a/drivers/net/ixgb/ixgb_main.c
38267+++ b/drivers/net/ixgb/ixgb_main.c
38268@@ -1052,6 +1052,8 @@ ixgb_set_multi(struct net_device *netdev)
38269 u32 rctl;
38270 int i;
38271
38272+ pax_track_stack();
38273+
38274 /* Check for Promiscuous and All Multicast modes */
38275
38276 rctl = IXGB_READ_REG(hw, RCTL);
38277diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
38278index af35e1d..8781785 100644
38279--- a/drivers/net/ixgb/ixgb_param.c
38280+++ b/drivers/net/ixgb/ixgb_param.c
38281@@ -260,6 +260,9 @@ void __devinit
38282 ixgb_check_options(struct ixgb_adapter *adapter)
38283 {
38284 int bd = adapter->bd_number;
38285+
38286+ pax_track_stack();
38287+
38288 if (bd >= IXGB_MAX_NIC) {
38289 printk(KERN_NOTICE
38290 "Warning: no configuration for board #%i\n", bd);
38291diff --git a/drivers/net/ixgbe/ixgbe_type.h b/drivers/net/ixgbe/ixgbe_type.h
38292index b17aa73..ed74540 100644
38293--- a/drivers/net/ixgbe/ixgbe_type.h
38294+++ b/drivers/net/ixgbe/ixgbe_type.h
38295@@ -2327,6 +2327,7 @@ struct ixgbe_eeprom_operations {
38296 s32 (*validate_checksum)(struct ixgbe_hw *, u16 *);
38297 s32 (*update_checksum)(struct ixgbe_hw *);
38298 };
38299+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
38300
38301 struct ixgbe_mac_operations {
38302 s32 (*init_hw)(struct ixgbe_hw *);
38303@@ -2376,6 +2377,7 @@ struct ixgbe_mac_operations {
38304 /* Flow Control */
38305 s32 (*fc_enable)(struct ixgbe_hw *, s32);
38306 };
38307+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
38308
38309 struct ixgbe_phy_operations {
38310 s32 (*identify)(struct ixgbe_hw *);
38311@@ -2394,9 +2396,10 @@ struct ixgbe_phy_operations {
38312 s32 (*read_i2c_eeprom)(struct ixgbe_hw *, u8 , u8 *);
38313 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
38314 };
38315+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
38316
38317 struct ixgbe_eeprom_info {
38318- struct ixgbe_eeprom_operations ops;
38319+ ixgbe_eeprom_operations_no_const ops;
38320 enum ixgbe_eeprom_type type;
38321 u32 semaphore_delay;
38322 u16 word_size;
38323@@ -2404,7 +2407,7 @@ struct ixgbe_eeprom_info {
38324 };
38325
38326 struct ixgbe_mac_info {
38327- struct ixgbe_mac_operations ops;
38328+ ixgbe_mac_operations_no_const ops;
38329 enum ixgbe_mac_type type;
38330 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
38331 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
38332@@ -2423,7 +2426,7 @@ struct ixgbe_mac_info {
38333 };
38334
38335 struct ixgbe_phy_info {
38336- struct ixgbe_phy_operations ops;
38337+ ixgbe_phy_operations_no_const ops;
38338 struct mdio_if_info mdio;
38339 enum ixgbe_phy_type type;
38340 u32 id;
38341diff --git a/drivers/net/mlx4/main.c b/drivers/net/mlx4/main.c
38342index 291a505..2543756 100644
38343--- a/drivers/net/mlx4/main.c
38344+++ b/drivers/net/mlx4/main.c
38345@@ -38,6 +38,7 @@
38346 #include <linux/errno.h>
38347 #include <linux/pci.h>
38348 #include <linux/dma-mapping.h>
38349+#include <linux/sched.h>
38350
38351 #include <linux/mlx4/device.h>
38352 #include <linux/mlx4/doorbell.h>
38353@@ -730,6 +731,8 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
38354 u64 icm_size;
38355 int err;
38356
38357+ pax_track_stack();
38358+
38359 err = mlx4_QUERY_FW(dev);
38360 if (err) {
38361 if (err == -EACCES)
38362diff --git a/drivers/net/niu.c b/drivers/net/niu.c
38363index 2dce134..fa5ce75 100644
38364--- a/drivers/net/niu.c
38365+++ b/drivers/net/niu.c
38366@@ -9128,6 +9128,8 @@ static void __devinit niu_try_msix(struct niu *np, u8 *ldg_num_map)
38367 int i, num_irqs, err;
38368 u8 first_ldg;
38369
38370+ pax_track_stack();
38371+
38372 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
38373 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
38374 ldg_num_map[i] = first_ldg + i;
38375diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
38376index c1b3f09..97cd8c4 100644
38377--- a/drivers/net/pcnet32.c
38378+++ b/drivers/net/pcnet32.c
38379@@ -79,7 +79,7 @@ static int cards_found;
38380 /*
38381 * VLB I/O addresses
38382 */
38383-static unsigned int pcnet32_portlist[] __initdata =
38384+static unsigned int pcnet32_portlist[] __devinitdata =
38385 { 0x300, 0x320, 0x340, 0x360, 0 };
38386
38387 static int pcnet32_debug = 0;
38388@@ -267,7 +267,7 @@ struct pcnet32_private {
38389 struct sk_buff **rx_skbuff;
38390 dma_addr_t *tx_dma_addr;
38391 dma_addr_t *rx_dma_addr;
38392- struct pcnet32_access a;
38393+ struct pcnet32_access *a;
38394 spinlock_t lock; /* Guard lock */
38395 unsigned int cur_rx, cur_tx; /* The next free ring entry */
38396 unsigned int rx_ring_size; /* current rx ring size */
38397@@ -457,9 +457,9 @@ static void pcnet32_netif_start(struct net_device *dev)
38398 u16 val;
38399
38400 netif_wake_queue(dev);
38401- val = lp->a.read_csr(ioaddr, CSR3);
38402+ val = lp->a->read_csr(ioaddr, CSR3);
38403 val &= 0x00ff;
38404- lp->a.write_csr(ioaddr, CSR3, val);
38405+ lp->a->write_csr(ioaddr, CSR3, val);
38406 napi_enable(&lp->napi);
38407 }
38408
38409@@ -744,7 +744,7 @@ static u32 pcnet32_get_link(struct net_device *dev)
38410 r = mii_link_ok(&lp->mii_if);
38411 } else if (lp->chip_version >= PCNET32_79C970A) {
38412 ulong ioaddr = dev->base_addr; /* card base I/O address */
38413- r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
38414+ r = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
38415 } else { /* can not detect link on really old chips */
38416 r = 1;
38417 }
38418@@ -806,7 +806,7 @@ static int pcnet32_set_ringparam(struct net_device *dev,
38419 pcnet32_netif_stop(dev);
38420
38421 spin_lock_irqsave(&lp->lock, flags);
38422- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38423+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38424
38425 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
38426
38427@@ -886,7 +886,7 @@ static void pcnet32_ethtool_test(struct net_device *dev,
38428 static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38429 {
38430 struct pcnet32_private *lp = netdev_priv(dev);
38431- struct pcnet32_access *a = &lp->a; /* access to registers */
38432+ struct pcnet32_access *a = lp->a; /* access to registers */
38433 ulong ioaddr = dev->base_addr; /* card base I/O address */
38434 struct sk_buff *skb; /* sk buff */
38435 int x, i; /* counters */
38436@@ -906,21 +906,21 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38437 pcnet32_netif_stop(dev);
38438
38439 spin_lock_irqsave(&lp->lock, flags);
38440- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38441+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38442
38443 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
38444
38445 /* Reset the PCNET32 */
38446- lp->a.reset(ioaddr);
38447- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38448+ lp->a->reset(ioaddr);
38449+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38450
38451 /* switch pcnet32 to 32bit mode */
38452- lp->a.write_bcr(ioaddr, 20, 2);
38453+ lp->a->write_bcr(ioaddr, 20, 2);
38454
38455 /* purge & init rings but don't actually restart */
38456 pcnet32_restart(dev, 0x0000);
38457
38458- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38459+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38460
38461 /* Initialize Transmit buffers. */
38462 size = data_len + 15;
38463@@ -966,10 +966,10 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38464
38465 /* set int loopback in CSR15 */
38466 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
38467- lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
38468+ lp->a->write_csr(ioaddr, CSR15, x | 0x0044);
38469
38470 teststatus = cpu_to_le16(0x8000);
38471- lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
38472+ lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
38473
38474 /* Check status of descriptors */
38475 for (x = 0; x < numbuffs; x++) {
38476@@ -990,7 +990,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38477 }
38478 }
38479
38480- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38481+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38482 wmb();
38483 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
38484 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
38485@@ -1039,7 +1039,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38486 pcnet32_restart(dev, CSR0_NORMAL);
38487 } else {
38488 pcnet32_purge_rx_ring(dev);
38489- lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
38490+ lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
38491 }
38492 spin_unlock_irqrestore(&lp->lock, flags);
38493
38494@@ -1049,7 +1049,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38495 static void pcnet32_led_blink_callback(struct net_device *dev)
38496 {
38497 struct pcnet32_private *lp = netdev_priv(dev);
38498- struct pcnet32_access *a = &lp->a;
38499+ struct pcnet32_access *a = lp->a;
38500 ulong ioaddr = dev->base_addr;
38501 unsigned long flags;
38502 int i;
38503@@ -1066,7 +1066,7 @@ static void pcnet32_led_blink_callback(struct net_device *dev)
38504 static int pcnet32_phys_id(struct net_device *dev, u32 data)
38505 {
38506 struct pcnet32_private *lp = netdev_priv(dev);
38507- struct pcnet32_access *a = &lp->a;
38508+ struct pcnet32_access *a = lp->a;
38509 ulong ioaddr = dev->base_addr;
38510 unsigned long flags;
38511 int i, regs[4];
38512@@ -1112,7 +1112,7 @@ static int pcnet32_suspend(struct net_device *dev, unsigned long *flags,
38513 {
38514 int csr5;
38515 struct pcnet32_private *lp = netdev_priv(dev);
38516- struct pcnet32_access *a = &lp->a;
38517+ struct pcnet32_access *a = lp->a;
38518 ulong ioaddr = dev->base_addr;
38519 int ticks;
38520
38521@@ -1388,8 +1388,8 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
38522 spin_lock_irqsave(&lp->lock, flags);
38523 if (pcnet32_tx(dev)) {
38524 /* reset the chip to clear the error condition, then restart */
38525- lp->a.reset(ioaddr);
38526- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38527+ lp->a->reset(ioaddr);
38528+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38529 pcnet32_restart(dev, CSR0_START);
38530 netif_wake_queue(dev);
38531 }
38532@@ -1401,12 +1401,12 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
38533 __napi_complete(napi);
38534
38535 /* clear interrupt masks */
38536- val = lp->a.read_csr(ioaddr, CSR3);
38537+ val = lp->a->read_csr(ioaddr, CSR3);
38538 val &= 0x00ff;
38539- lp->a.write_csr(ioaddr, CSR3, val);
38540+ lp->a->write_csr(ioaddr, CSR3, val);
38541
38542 /* Set interrupt enable. */
38543- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
38544+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
38545
38546 spin_unlock_irqrestore(&lp->lock, flags);
38547 }
38548@@ -1429,7 +1429,7 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
38549 int i, csr0;
38550 u16 *buff = ptr;
38551 struct pcnet32_private *lp = netdev_priv(dev);
38552- struct pcnet32_access *a = &lp->a;
38553+ struct pcnet32_access *a = lp->a;
38554 ulong ioaddr = dev->base_addr;
38555 unsigned long flags;
38556
38557@@ -1466,9 +1466,9 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
38558 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
38559 if (lp->phymask & (1 << j)) {
38560 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
38561- lp->a.write_bcr(ioaddr, 33,
38562+ lp->a->write_bcr(ioaddr, 33,
38563 (j << 5) | i);
38564- *buff++ = lp->a.read_bcr(ioaddr, 34);
38565+ *buff++ = lp->a->read_bcr(ioaddr, 34);
38566 }
38567 }
38568 }
38569@@ -1858,7 +1858,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38570 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
38571 lp->options |= PCNET32_PORT_FD;
38572
38573- lp->a = *a;
38574+ lp->a = a;
38575
38576 /* prior to register_netdev, dev->name is not yet correct */
38577 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
38578@@ -1917,7 +1917,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38579 if (lp->mii) {
38580 /* lp->phycount and lp->phymask are set to 0 by memset above */
38581
38582- lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
38583+ lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
38584 /* scan for PHYs */
38585 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
38586 unsigned short id1, id2;
38587@@ -1938,7 +1938,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38588 "Found PHY %04x:%04x at address %d.\n",
38589 id1, id2, i);
38590 }
38591- lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
38592+ lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
38593 if (lp->phycount > 1) {
38594 lp->options |= PCNET32_PORT_MII;
38595 }
38596@@ -2109,10 +2109,10 @@ static int pcnet32_open(struct net_device *dev)
38597 }
38598
38599 /* Reset the PCNET32 */
38600- lp->a.reset(ioaddr);
38601+ lp->a->reset(ioaddr);
38602
38603 /* switch pcnet32 to 32bit mode */
38604- lp->a.write_bcr(ioaddr, 20, 2);
38605+ lp->a->write_bcr(ioaddr, 20, 2);
38606
38607 if (netif_msg_ifup(lp))
38608 printk(KERN_DEBUG
38609@@ -2122,14 +2122,14 @@ static int pcnet32_open(struct net_device *dev)
38610 (u32) (lp->init_dma_addr));
38611
38612 /* set/reset autoselect bit */
38613- val = lp->a.read_bcr(ioaddr, 2) & ~2;
38614+ val = lp->a->read_bcr(ioaddr, 2) & ~2;
38615 if (lp->options & PCNET32_PORT_ASEL)
38616 val |= 2;
38617- lp->a.write_bcr(ioaddr, 2, val);
38618+ lp->a->write_bcr(ioaddr, 2, val);
38619
38620 /* handle full duplex setting */
38621 if (lp->mii_if.full_duplex) {
38622- val = lp->a.read_bcr(ioaddr, 9) & ~3;
38623+ val = lp->a->read_bcr(ioaddr, 9) & ~3;
38624 if (lp->options & PCNET32_PORT_FD) {
38625 val |= 1;
38626 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
38627@@ -2139,14 +2139,14 @@ static int pcnet32_open(struct net_device *dev)
38628 if (lp->chip_version == 0x2627)
38629 val |= 3;
38630 }
38631- lp->a.write_bcr(ioaddr, 9, val);
38632+ lp->a->write_bcr(ioaddr, 9, val);
38633 }
38634
38635 /* set/reset GPSI bit in test register */
38636- val = lp->a.read_csr(ioaddr, 124) & ~0x10;
38637+ val = lp->a->read_csr(ioaddr, 124) & ~0x10;
38638 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
38639 val |= 0x10;
38640- lp->a.write_csr(ioaddr, 124, val);
38641+ lp->a->write_csr(ioaddr, 124, val);
38642
38643 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
38644 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
38645@@ -2167,24 +2167,24 @@ static int pcnet32_open(struct net_device *dev)
38646 * duplex, and/or enable auto negotiation, and clear DANAS
38647 */
38648 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
38649- lp->a.write_bcr(ioaddr, 32,
38650- lp->a.read_bcr(ioaddr, 32) | 0x0080);
38651+ lp->a->write_bcr(ioaddr, 32,
38652+ lp->a->read_bcr(ioaddr, 32) | 0x0080);
38653 /* disable Auto Negotiation, set 10Mpbs, HD */
38654- val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
38655+ val = lp->a->read_bcr(ioaddr, 32) & ~0xb8;
38656 if (lp->options & PCNET32_PORT_FD)
38657 val |= 0x10;
38658 if (lp->options & PCNET32_PORT_100)
38659 val |= 0x08;
38660- lp->a.write_bcr(ioaddr, 32, val);
38661+ lp->a->write_bcr(ioaddr, 32, val);
38662 } else {
38663 if (lp->options & PCNET32_PORT_ASEL) {
38664- lp->a.write_bcr(ioaddr, 32,
38665- lp->a.read_bcr(ioaddr,
38666+ lp->a->write_bcr(ioaddr, 32,
38667+ lp->a->read_bcr(ioaddr,
38668 32) | 0x0080);
38669 /* enable auto negotiate, setup, disable fd */
38670- val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
38671+ val = lp->a->read_bcr(ioaddr, 32) & ~0x98;
38672 val |= 0x20;
38673- lp->a.write_bcr(ioaddr, 32, val);
38674+ lp->a->write_bcr(ioaddr, 32, val);
38675 }
38676 }
38677 } else {
38678@@ -2197,10 +2197,10 @@ static int pcnet32_open(struct net_device *dev)
38679 * There is really no good other way to handle multiple PHYs
38680 * other than turning off all automatics
38681 */
38682- val = lp->a.read_bcr(ioaddr, 2);
38683- lp->a.write_bcr(ioaddr, 2, val & ~2);
38684- val = lp->a.read_bcr(ioaddr, 32);
38685- lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
38686+ val = lp->a->read_bcr(ioaddr, 2);
38687+ lp->a->write_bcr(ioaddr, 2, val & ~2);
38688+ val = lp->a->read_bcr(ioaddr, 32);
38689+ lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
38690
38691 if (!(lp->options & PCNET32_PORT_ASEL)) {
38692 /* setup ecmd */
38693@@ -2210,7 +2210,7 @@ static int pcnet32_open(struct net_device *dev)
38694 ecmd.speed =
38695 lp->
38696 options & PCNET32_PORT_100 ? SPEED_100 : SPEED_10;
38697- bcr9 = lp->a.read_bcr(ioaddr, 9);
38698+ bcr9 = lp->a->read_bcr(ioaddr, 9);
38699
38700 if (lp->options & PCNET32_PORT_FD) {
38701 ecmd.duplex = DUPLEX_FULL;
38702@@ -2219,7 +2219,7 @@ static int pcnet32_open(struct net_device *dev)
38703 ecmd.duplex = DUPLEX_HALF;
38704 bcr9 |= ~(1 << 0);
38705 }
38706- lp->a.write_bcr(ioaddr, 9, bcr9);
38707+ lp->a->write_bcr(ioaddr, 9, bcr9);
38708 }
38709
38710 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
38711@@ -2252,9 +2252,9 @@ static int pcnet32_open(struct net_device *dev)
38712
38713 #ifdef DO_DXSUFLO
38714 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
38715- val = lp->a.read_csr(ioaddr, CSR3);
38716+ val = lp->a->read_csr(ioaddr, CSR3);
38717 val |= 0x40;
38718- lp->a.write_csr(ioaddr, CSR3, val);
38719+ lp->a->write_csr(ioaddr, CSR3, val);
38720 }
38721 #endif
38722
38723@@ -2270,11 +2270,11 @@ static int pcnet32_open(struct net_device *dev)
38724 napi_enable(&lp->napi);
38725
38726 /* Re-initialize the PCNET32, and start it when done. */
38727- lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
38728- lp->a.write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
38729+ lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
38730+ lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
38731
38732- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38733- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
38734+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38735+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
38736
38737 netif_start_queue(dev);
38738
38739@@ -2286,20 +2286,20 @@ static int pcnet32_open(struct net_device *dev)
38740
38741 i = 0;
38742 while (i++ < 100)
38743- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
38744+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
38745 break;
38746 /*
38747 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
38748 * reports that doing so triggers a bug in the '974.
38749 */
38750- lp->a.write_csr(ioaddr, CSR0, CSR0_NORMAL);
38751+ lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL);
38752
38753 if (netif_msg_ifup(lp))
38754 printk(KERN_DEBUG
38755 "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n",
38756 dev->name, i,
38757 (u32) (lp->init_dma_addr),
38758- lp->a.read_csr(ioaddr, CSR0));
38759+ lp->a->read_csr(ioaddr, CSR0));
38760
38761 spin_unlock_irqrestore(&lp->lock, flags);
38762
38763@@ -2313,7 +2313,7 @@ static int pcnet32_open(struct net_device *dev)
38764 * Switch back to 16bit mode to avoid problems with dumb
38765 * DOS packet driver after a warm reboot
38766 */
38767- lp->a.write_bcr(ioaddr, 20, 4);
38768+ lp->a->write_bcr(ioaddr, 20, 4);
38769
38770 err_free_irq:
38771 spin_unlock_irqrestore(&lp->lock, flags);
38772@@ -2420,7 +2420,7 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
38773
38774 /* wait for stop */
38775 for (i = 0; i < 100; i++)
38776- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_STOP)
38777+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP)
38778 break;
38779
38780 if (i >= 100 && netif_msg_drv(lp))
38781@@ -2433,13 +2433,13 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
38782 return;
38783
38784 /* ReInit Ring */
38785- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
38786+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
38787 i = 0;
38788 while (i++ < 1000)
38789- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
38790+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
38791 break;
38792
38793- lp->a.write_csr(ioaddr, CSR0, csr0_bits);
38794+ lp->a->write_csr(ioaddr, CSR0, csr0_bits);
38795 }
38796
38797 static void pcnet32_tx_timeout(struct net_device *dev)
38798@@ -2452,8 +2452,8 @@ static void pcnet32_tx_timeout(struct net_device *dev)
38799 if (pcnet32_debug & NETIF_MSG_DRV)
38800 printk(KERN_ERR
38801 "%s: transmit timed out, status %4.4x, resetting.\n",
38802- dev->name, lp->a.read_csr(ioaddr, CSR0));
38803- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38804+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38805+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38806 dev->stats.tx_errors++;
38807 if (netif_msg_tx_err(lp)) {
38808 int i;
38809@@ -2497,7 +2497,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
38810 if (netif_msg_tx_queued(lp)) {
38811 printk(KERN_DEBUG
38812 "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n",
38813- dev->name, lp->a.read_csr(ioaddr, CSR0));
38814+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38815 }
38816
38817 /* Default status -- will not enable Successful-TxDone
38818@@ -2528,7 +2528,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
38819 dev->stats.tx_bytes += skb->len;
38820
38821 /* Trigger an immediate send poll. */
38822- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
38823+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
38824
38825 dev->trans_start = jiffies;
38826
38827@@ -2555,18 +2555,18 @@ pcnet32_interrupt(int irq, void *dev_id)
38828
38829 spin_lock(&lp->lock);
38830
38831- csr0 = lp->a.read_csr(ioaddr, CSR0);
38832+ csr0 = lp->a->read_csr(ioaddr, CSR0);
38833 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
38834 if (csr0 == 0xffff) {
38835 break; /* PCMCIA remove happened */
38836 }
38837 /* Acknowledge all of the current interrupt sources ASAP. */
38838- lp->a.write_csr(ioaddr, CSR0, csr0 & ~0x004f);
38839+ lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f);
38840
38841 if (netif_msg_intr(lp))
38842 printk(KERN_DEBUG
38843 "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
38844- dev->name, csr0, lp->a.read_csr(ioaddr, CSR0));
38845+ dev->name, csr0, lp->a->read_csr(ioaddr, CSR0));
38846
38847 /* Log misc errors. */
38848 if (csr0 & 0x4000)
38849@@ -2595,19 +2595,19 @@ pcnet32_interrupt(int irq, void *dev_id)
38850 if (napi_schedule_prep(&lp->napi)) {
38851 u16 val;
38852 /* set interrupt masks */
38853- val = lp->a.read_csr(ioaddr, CSR3);
38854+ val = lp->a->read_csr(ioaddr, CSR3);
38855 val |= 0x5f00;
38856- lp->a.write_csr(ioaddr, CSR3, val);
38857+ lp->a->write_csr(ioaddr, CSR3, val);
38858
38859 __napi_schedule(&lp->napi);
38860 break;
38861 }
38862- csr0 = lp->a.read_csr(ioaddr, CSR0);
38863+ csr0 = lp->a->read_csr(ioaddr, CSR0);
38864 }
38865
38866 if (netif_msg_intr(lp))
38867 printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
38868- dev->name, lp->a.read_csr(ioaddr, CSR0));
38869+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38870
38871 spin_unlock(&lp->lock);
38872
38873@@ -2627,21 +2627,21 @@ static int pcnet32_close(struct net_device *dev)
38874
38875 spin_lock_irqsave(&lp->lock, flags);
38876
38877- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
38878+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
38879
38880 if (netif_msg_ifdown(lp))
38881 printk(KERN_DEBUG
38882 "%s: Shutting down ethercard, status was %2.2x.\n",
38883- dev->name, lp->a.read_csr(ioaddr, CSR0));
38884+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38885
38886 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
38887- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38888+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38889
38890 /*
38891 * Switch back to 16bit mode to avoid problems with dumb
38892 * DOS packet driver after a warm reboot
38893 */
38894- lp->a.write_bcr(ioaddr, 20, 4);
38895+ lp->a->write_bcr(ioaddr, 20, 4);
38896
38897 spin_unlock_irqrestore(&lp->lock, flags);
38898
38899@@ -2664,7 +2664,7 @@ static struct net_device_stats *pcnet32_get_stats(struct net_device *dev)
38900 unsigned long flags;
38901
38902 spin_lock_irqsave(&lp->lock, flags);
38903- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
38904+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
38905 spin_unlock_irqrestore(&lp->lock, flags);
38906
38907 return &dev->stats;
38908@@ -2686,10 +2686,10 @@ static void pcnet32_load_multicast(struct net_device *dev)
38909 if (dev->flags & IFF_ALLMULTI) {
38910 ib->filter[0] = cpu_to_le32(~0U);
38911 ib->filter[1] = cpu_to_le32(~0U);
38912- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
38913- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
38914- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
38915- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
38916+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
38917+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
38918+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
38919+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
38920 return;
38921 }
38922 /* clear the multicast filter */
38923@@ -2710,7 +2710,7 @@ static void pcnet32_load_multicast(struct net_device *dev)
38924 mcast_table[crc >> 4] |= cpu_to_le16(1 << (crc & 0xf));
38925 }
38926 for (i = 0; i < 4; i++)
38927- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
38928+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i,
38929 le16_to_cpu(mcast_table[i]));
38930 return;
38931 }
38932@@ -2726,7 +2726,7 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
38933
38934 spin_lock_irqsave(&lp->lock, flags);
38935 suspended = pcnet32_suspend(dev, &flags, 0);
38936- csr15 = lp->a.read_csr(ioaddr, CSR15);
38937+ csr15 = lp->a->read_csr(ioaddr, CSR15);
38938 if (dev->flags & IFF_PROMISC) {
38939 /* Log any net taps. */
38940 if (netif_msg_hw(lp))
38941@@ -2735,21 +2735,21 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
38942 lp->init_block->mode =
38943 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
38944 7);
38945- lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
38946+ lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000);
38947 } else {
38948 lp->init_block->mode =
38949 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7);
38950- lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
38951+ lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff);
38952 pcnet32_load_multicast(dev);
38953 }
38954
38955 if (suspended) {
38956 int csr5;
38957 /* clear SUSPEND (SPND) - CSR5 bit 0 */
38958- csr5 = lp->a.read_csr(ioaddr, CSR5);
38959- lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
38960+ csr5 = lp->a->read_csr(ioaddr, CSR5);
38961+ lp->a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
38962 } else {
38963- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38964+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38965 pcnet32_restart(dev, CSR0_NORMAL);
38966 netif_wake_queue(dev);
38967 }
38968@@ -2767,8 +2767,8 @@ static int mdio_read(struct net_device *dev, int phy_id, int reg_num)
38969 if (!lp->mii)
38970 return 0;
38971
38972- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38973- val_out = lp->a.read_bcr(ioaddr, 34);
38974+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38975+ val_out = lp->a->read_bcr(ioaddr, 34);
38976
38977 return val_out;
38978 }
38979@@ -2782,8 +2782,8 @@ static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val)
38980 if (!lp->mii)
38981 return;
38982
38983- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38984- lp->a.write_bcr(ioaddr, 34, val);
38985+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38986+ lp->a->write_bcr(ioaddr, 34, val);
38987 }
38988
38989 static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38990@@ -2862,7 +2862,7 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
38991 curr_link = mii_link_ok(&lp->mii_if);
38992 } else {
38993 ulong ioaddr = dev->base_addr; /* card base I/O address */
38994- curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
38995+ curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
38996 }
38997 if (!curr_link) {
38998 if (prev_link || verbose) {
38999@@ -2887,13 +2887,13 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
39000 (ecmd.duplex ==
39001 DUPLEX_FULL) ? "full" : "half");
39002 }
39003- bcr9 = lp->a.read_bcr(dev->base_addr, 9);
39004+ bcr9 = lp->a->read_bcr(dev->base_addr, 9);
39005 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
39006 if (lp->mii_if.full_duplex)
39007 bcr9 |= (1 << 0);
39008 else
39009 bcr9 &= ~(1 << 0);
39010- lp->a.write_bcr(dev->base_addr, 9, bcr9);
39011+ lp->a->write_bcr(dev->base_addr, 9, bcr9);
39012 }
39013 } else {
39014 if (netif_msg_link(lp))
39015diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
39016index 7cc9898..6eb50d3 100644
39017--- a/drivers/net/sis190.c
39018+++ b/drivers/net/sis190.c
39019@@ -1598,7 +1598,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
39020 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
39021 struct net_device *dev)
39022 {
39023- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
39024+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
39025 struct sis190_private *tp = netdev_priv(dev);
39026 struct pci_dev *isa_bridge;
39027 u8 reg, tmp8;
39028diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
39029index e13685a..60c948c 100644
39030--- a/drivers/net/sundance.c
39031+++ b/drivers/net/sundance.c
39032@@ -225,7 +225,7 @@ enum {
39033 struct pci_id_info {
39034 const char *name;
39035 };
39036-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
39037+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
39038 {"D-Link DFE-550TX FAST Ethernet Adapter"},
39039 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
39040 {"D-Link DFE-580TX 4 port Server Adapter"},
39041diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
39042index 529f55a..cccaa18 100644
39043--- a/drivers/net/tg3.h
39044+++ b/drivers/net/tg3.h
39045@@ -95,6 +95,7 @@
39046 #define CHIPREV_ID_5750_A0 0x4000
39047 #define CHIPREV_ID_5750_A1 0x4001
39048 #define CHIPREV_ID_5750_A3 0x4003
39049+#define CHIPREV_ID_5750_C1 0x4201
39050 #define CHIPREV_ID_5750_C2 0x4202
39051 #define CHIPREV_ID_5752_A0_HW 0x5000
39052 #define CHIPREV_ID_5752_A0 0x6000
39053diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
39054index b9db1b5..720f9ce 100644
39055--- a/drivers/net/tokenring/abyss.c
39056+++ b/drivers/net/tokenring/abyss.c
39057@@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
39058
39059 static int __init abyss_init (void)
39060 {
39061- abyss_netdev_ops = tms380tr_netdev_ops;
39062+ pax_open_kernel();
39063+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
39064
39065- abyss_netdev_ops.ndo_open = abyss_open;
39066- abyss_netdev_ops.ndo_stop = abyss_close;
39067+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
39068+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
39069+ pax_close_kernel();
39070
39071 return pci_register_driver(&abyss_driver);
39072 }
39073diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
39074index 456f8bf..373e56d 100644
39075--- a/drivers/net/tokenring/madgemc.c
39076+++ b/drivers/net/tokenring/madgemc.c
39077@@ -755,9 +755,11 @@ static struct mca_driver madgemc_driver = {
39078
39079 static int __init madgemc_init (void)
39080 {
39081- madgemc_netdev_ops = tms380tr_netdev_ops;
39082- madgemc_netdev_ops.ndo_open = madgemc_open;
39083- madgemc_netdev_ops.ndo_stop = madgemc_close;
39084+ pax_open_kernel();
39085+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
39086+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
39087+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
39088+ pax_close_kernel();
39089
39090 return mca_register_driver (&madgemc_driver);
39091 }
39092diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
39093index 16e8783..925bd49 100644
39094--- a/drivers/net/tokenring/proteon.c
39095+++ b/drivers/net/tokenring/proteon.c
39096@@ -353,9 +353,11 @@ static int __init proteon_init(void)
39097 struct platform_device *pdev;
39098 int i, num = 0, err = 0;
39099
39100- proteon_netdev_ops = tms380tr_netdev_ops;
39101- proteon_netdev_ops.ndo_open = proteon_open;
39102- proteon_netdev_ops.ndo_stop = tms380tr_close;
39103+ pax_open_kernel();
39104+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
39105+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
39106+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
39107+ pax_close_kernel();
39108
39109 err = platform_driver_register(&proteon_driver);
39110 if (err)
39111diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
39112index 46db5c5..37c1536 100644
39113--- a/drivers/net/tokenring/skisa.c
39114+++ b/drivers/net/tokenring/skisa.c
39115@@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
39116 struct platform_device *pdev;
39117 int i, num = 0, err = 0;
39118
39119- sk_isa_netdev_ops = tms380tr_netdev_ops;
39120- sk_isa_netdev_ops.ndo_open = sk_isa_open;
39121- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
39122+ pax_open_kernel();
39123+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
39124+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
39125+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
39126+ pax_close_kernel();
39127
39128 err = platform_driver_register(&sk_isa_driver);
39129 if (err)
39130diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
39131index 74e5ba4..5cf6bc9 100644
39132--- a/drivers/net/tulip/de2104x.c
39133+++ b/drivers/net/tulip/de2104x.c
39134@@ -1785,6 +1785,8 @@ static void __devinit de21041_get_srom_info (struct de_private *de)
39135 struct de_srom_info_leaf *il;
39136 void *bufp;
39137
39138+ pax_track_stack();
39139+
39140 /* download entire eeprom */
39141 for (i = 0; i < DE_EEPROM_WORDS; i++)
39142 ((__le16 *)ee_data)[i] =
39143diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c
39144index a8349b7..90f9dfe 100644
39145--- a/drivers/net/tulip/de4x5.c
39146+++ b/drivers/net/tulip/de4x5.c
39147@@ -5472,7 +5472,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39148 for (i=0; i<ETH_ALEN; i++) {
39149 tmp.addr[i] = dev->dev_addr[i];
39150 }
39151- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39152+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39153 break;
39154
39155 case DE4X5_SET_HWADDR: /* Set the hardware address */
39156@@ -5512,7 +5512,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39157 spin_lock_irqsave(&lp->lock, flags);
39158 memcpy(&statbuf, &lp->pktStats, ioc->len);
39159 spin_unlock_irqrestore(&lp->lock, flags);
39160- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39161+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39162 return -EFAULT;
39163 break;
39164 }
39165diff --git a/drivers/net/tulip/eeprom.c b/drivers/net/tulip/eeprom.c
39166index 391acd3..56d11cd 100644
39167--- a/drivers/net/tulip/eeprom.c
39168+++ b/drivers/net/tulip/eeprom.c
39169@@ -80,7 +80,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
39170 {NULL}};
39171
39172
39173-static const char *block_name[] __devinitdata = {
39174+static const char *block_name[] __devinitconst = {
39175 "21140 non-MII",
39176 "21140 MII PHY",
39177 "21142 Serial PHY",
39178diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
39179index b38d3b7..b1cff23 100644
39180--- a/drivers/net/tulip/winbond-840.c
39181+++ b/drivers/net/tulip/winbond-840.c
39182@@ -235,7 +235,7 @@ struct pci_id_info {
39183 int drv_flags; /* Driver use, intended as capability flags. */
39184 };
39185
39186-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
39187+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
39188 { /* Sometime a Level-One switch card. */
39189 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
39190 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
39191diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39192index f450bc9..2b747c8 100644
39193--- a/drivers/net/usb/hso.c
39194+++ b/drivers/net/usb/hso.c
39195@@ -71,7 +71,7 @@
39196 #include <asm/byteorder.h>
39197 #include <linux/serial_core.h>
39198 #include <linux/serial.h>
39199-
39200+#include <asm/local.h>
39201
39202 #define DRIVER_VERSION "1.2"
39203 #define MOD_AUTHOR "Option Wireless"
39204@@ -258,7 +258,7 @@ struct hso_serial {
39205
39206 /* from usb_serial_port */
39207 struct tty_struct *tty;
39208- int open_count;
39209+ local_t open_count;
39210 spinlock_t serial_lock;
39211
39212 int (*write_data) (struct hso_serial *serial);
39213@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39214 struct urb *urb;
39215
39216 urb = serial->rx_urb[0];
39217- if (serial->open_count > 0) {
39218+ if (local_read(&serial->open_count) > 0) {
39219 count = put_rxbuf_data(urb, serial);
39220 if (count == -1)
39221 return;
39222@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39223 DUMP1(urb->transfer_buffer, urb->actual_length);
39224
39225 /* Anyone listening? */
39226- if (serial->open_count == 0)
39227+ if (local_read(&serial->open_count) == 0)
39228 return;
39229
39230 if (status == 0) {
39231@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39232 spin_unlock_irq(&serial->serial_lock);
39233
39234 /* check for port already opened, if not set the termios */
39235- serial->open_count++;
39236- if (serial->open_count == 1) {
39237+ if (local_inc_return(&serial->open_count) == 1) {
39238 tty->low_latency = 1;
39239 serial->rx_state = RX_IDLE;
39240 /* Force default termio settings */
39241@@ -1325,7 +1324,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39242 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39243 if (result) {
39244 hso_stop_serial_device(serial->parent);
39245- serial->open_count--;
39246+ local_dec(&serial->open_count);
39247 kref_put(&serial->parent->ref, hso_serial_ref_free);
39248 }
39249 } else {
39250@@ -1362,10 +1361,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39251
39252 /* reset the rts and dtr */
39253 /* do the actual close */
39254- serial->open_count--;
39255+ local_dec(&serial->open_count);
39256
39257- if (serial->open_count <= 0) {
39258- serial->open_count = 0;
39259+ if (local_read(&serial->open_count) <= 0) {
39260+ local_set(&serial->open_count, 0);
39261 spin_lock_irq(&serial->serial_lock);
39262 if (serial->tty == tty) {
39263 serial->tty->driver_data = NULL;
39264@@ -1447,7 +1446,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39265
39266 /* the actual setup */
39267 spin_lock_irqsave(&serial->serial_lock, flags);
39268- if (serial->open_count)
39269+ if (local_read(&serial->open_count))
39270 _hso_serial_set_termios(tty, old);
39271 else
39272 tty->termios = old;
39273@@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interface *iface)
39274 /* Start all serial ports */
39275 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39276 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39277- if (dev2ser(serial_table[i])->open_count) {
39278+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
39279 result =
39280 hso_start_serial_device(serial_table[i], GFP_NOIO);
39281 hso_kick_transmit(dev2ser(serial_table[i]));
39282diff --git a/drivers/net/vxge/vxge-config.h b/drivers/net/vxge/vxge-config.h
39283index 3e94f0c..ffdd926 100644
39284--- a/drivers/net/vxge/vxge-config.h
39285+++ b/drivers/net/vxge/vxge-config.h
39286@@ -474,7 +474,7 @@ struct vxge_hw_uld_cbs {
39287 void (*link_down)(struct __vxge_hw_device *devh);
39288 void (*crit_err)(struct __vxge_hw_device *devh,
39289 enum vxge_hw_event type, u64 ext_data);
39290-};
39291+} __no_const;
39292
39293 /*
39294 * struct __vxge_hw_blockpool_entry - Block private data structure
39295diff --git a/drivers/net/vxge/vxge-main.c b/drivers/net/vxge/vxge-main.c
39296index 068d7a9..35293de 100644
39297--- a/drivers/net/vxge/vxge-main.c
39298+++ b/drivers/net/vxge/vxge-main.c
39299@@ -93,6 +93,8 @@ static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
39300 struct sk_buff *completed[NR_SKB_COMPLETED];
39301 int more;
39302
39303+ pax_track_stack();
39304+
39305 do {
39306 more = 0;
39307 skb_ptr = completed;
39308@@ -1779,6 +1781,8 @@ static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
39309 u8 mtable[256] = {0}; /* CPU to vpath mapping */
39310 int index;
39311
39312+ pax_track_stack();
39313+
39314 /*
39315 * Filling
39316 * - itable with bucket numbers
39317diff --git a/drivers/net/vxge/vxge-traffic.h b/drivers/net/vxge/vxge-traffic.h
39318index 461742b..81be42e 100644
39319--- a/drivers/net/vxge/vxge-traffic.h
39320+++ b/drivers/net/vxge/vxge-traffic.h
39321@@ -2123,7 +2123,7 @@ struct vxge_hw_mempool_cbs {
39322 struct vxge_hw_mempool_dma *dma_object,
39323 u32 index,
39324 u32 is_last);
39325-};
39326+} __no_const;
39327
39328 void
39329 __vxge_hw_mempool_destroy(
39330diff --git a/drivers/net/wan/cycx_x25.c b/drivers/net/wan/cycx_x25.c
39331index cd8cb95..4153b79 100644
39332--- a/drivers/net/wan/cycx_x25.c
39333+++ b/drivers/net/wan/cycx_x25.c
39334@@ -1017,6 +1017,8 @@ static void hex_dump(char *msg, unsigned char *p, int len)
39335 unsigned char hex[1024],
39336 * phex = hex;
39337
39338+ pax_track_stack();
39339+
39340 if (len >= (sizeof(hex) / 2))
39341 len = (sizeof(hex) / 2) - 1;
39342
39343diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
39344index aa9248f..a4e3c3b 100644
39345--- a/drivers/net/wan/hdlc_x25.c
39346+++ b/drivers/net/wan/hdlc_x25.c
39347@@ -136,16 +136,16 @@ static netdev_tx_t x25_xmit(struct sk_buff *skb, struct net_device *dev)
39348
39349 static int x25_open(struct net_device *dev)
39350 {
39351- struct lapb_register_struct cb;
39352+ static struct lapb_register_struct cb = {
39353+ .connect_confirmation = x25_connected,
39354+ .connect_indication = x25_connected,
39355+ .disconnect_confirmation = x25_disconnected,
39356+ .disconnect_indication = x25_disconnected,
39357+ .data_indication = x25_data_indication,
39358+ .data_transmit = x25_data_transmit
39359+ };
39360 int result;
39361
39362- cb.connect_confirmation = x25_connected;
39363- cb.connect_indication = x25_connected;
39364- cb.disconnect_confirmation = x25_disconnected;
39365- cb.disconnect_indication = x25_disconnected;
39366- cb.data_indication = x25_data_indication;
39367- cb.data_transmit = x25_data_transmit;
39368-
39369 result = lapb_register(dev, &cb);
39370 if (result != LAPB_OK)
39371 return result;
39372diff --git a/drivers/net/wimax/i2400m/usb-fw.c b/drivers/net/wimax/i2400m/usb-fw.c
39373index 5ad287c..783b020 100644
39374--- a/drivers/net/wimax/i2400m/usb-fw.c
39375+++ b/drivers/net/wimax/i2400m/usb-fw.c
39376@@ -263,6 +263,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(struct i2400m *i2400m,
39377 int do_autopm = 1;
39378 DECLARE_COMPLETION_ONSTACK(notif_completion);
39379
39380+ pax_track_stack();
39381+
39382 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
39383 i2400m, ack, ack_size);
39384 BUG_ON(_ack == i2400m->bm_ack_buf);
39385diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
39386index 6c26840..62c97c3 100644
39387--- a/drivers/net/wireless/airo.c
39388+++ b/drivers/net/wireless/airo.c
39389@@ -3003,6 +3003,8 @@ static void airo_process_scan_results (struct airo_info *ai) {
39390 BSSListElement * loop_net;
39391 BSSListElement * tmp_net;
39392
39393+ pax_track_stack();
39394+
39395 /* Blow away current list of scan results */
39396 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
39397 list_move_tail (&loop_net->list, &ai->network_free_list);
39398@@ -3783,6 +3785,8 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
39399 WepKeyRid wkr;
39400 int rc;
39401
39402+ pax_track_stack();
39403+
39404 memset( &mySsid, 0, sizeof( mySsid ) );
39405 kfree (ai->flash);
39406 ai->flash = NULL;
39407@@ -4758,6 +4762,8 @@ static int proc_stats_rid_open( struct inode *inode,
39408 __le32 *vals = stats.vals;
39409 int len;
39410
39411+ pax_track_stack();
39412+
39413 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
39414 return -ENOMEM;
39415 data = (struct proc_data *)file->private_data;
39416@@ -5487,6 +5493,8 @@ static int proc_BSSList_open( struct inode *inode, struct file *file ) {
39417 /* If doLoseSync is not 1, we won't do a Lose Sync */
39418 int doLoseSync = -1;
39419
39420+ pax_track_stack();
39421+
39422 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
39423 return -ENOMEM;
39424 data = (struct proc_data *)file->private_data;
39425@@ -7193,6 +7201,8 @@ static int airo_get_aplist(struct net_device *dev,
39426 int i;
39427 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
39428
39429+ pax_track_stack();
39430+
39431 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
39432 if (!qual)
39433 return -ENOMEM;
39434@@ -7753,6 +7763,8 @@ static void airo_read_wireless_stats(struct airo_info *local)
39435 CapabilityRid cap_rid;
39436 __le32 *vals = stats_rid.vals;
39437
39438+ pax_track_stack();
39439+
39440 /* Get stats out of the card */
39441 clear_bit(JOB_WSTATS, &local->jobs);
39442 if (local->power.event) {
39443diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
39444index 747508c..82e965d 100644
39445--- a/drivers/net/wireless/ath/ath5k/debug.c
39446+++ b/drivers/net/wireless/ath/ath5k/debug.c
39447@@ -205,6 +205,8 @@ static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
39448 unsigned int v;
39449 u64 tsf;
39450
39451+ pax_track_stack();
39452+
39453 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
39454 len += snprintf(buf+len, sizeof(buf)-len,
39455 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
39456@@ -318,6 +320,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
39457 unsigned int len = 0;
39458 unsigned int i;
39459
39460+ pax_track_stack();
39461+
39462 len += snprintf(buf+len, sizeof(buf)-len,
39463 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
39464
39465diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
39466index 2be4c22..593b1eb 100644
39467--- a/drivers/net/wireless/ath/ath9k/debug.c
39468+++ b/drivers/net/wireless/ath/ath9k/debug.c
39469@@ -220,6 +220,8 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
39470 char buf[512];
39471 unsigned int len = 0;
39472
39473+ pax_track_stack();
39474+
39475 len += snprintf(buf + len, sizeof(buf) - len,
39476 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
39477 len += snprintf(buf + len, sizeof(buf) - len,
39478@@ -360,6 +362,8 @@ static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
39479 int i;
39480 u8 addr[ETH_ALEN];
39481
39482+ pax_track_stack();
39483+
39484 len += snprintf(buf + len, sizeof(buf) - len,
39485 "primary: %s (%s chan=%d ht=%d)\n",
39486 wiphy_name(sc->pri_wiphy->hw->wiphy),
39487diff --git a/drivers/net/wireless/b43/debugfs.c b/drivers/net/wireless/b43/debugfs.c
39488index 80b19a4..dab3a45 100644
39489--- a/drivers/net/wireless/b43/debugfs.c
39490+++ b/drivers/net/wireless/b43/debugfs.c
39491@@ -43,7 +43,7 @@ static struct dentry *rootdir;
39492 struct b43_debugfs_fops {
39493 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
39494 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
39495- struct file_operations fops;
39496+ const struct file_operations fops;
39497 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
39498 size_t file_struct_offset;
39499 };
39500diff --git a/drivers/net/wireless/b43legacy/debugfs.c b/drivers/net/wireless/b43legacy/debugfs.c
39501index 1f85ac5..c99b4b4 100644
39502--- a/drivers/net/wireless/b43legacy/debugfs.c
39503+++ b/drivers/net/wireless/b43legacy/debugfs.c
39504@@ -44,7 +44,7 @@ static struct dentry *rootdir;
39505 struct b43legacy_debugfs_fops {
39506 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
39507 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
39508- struct file_operations fops;
39509+ const struct file_operations fops;
39510 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
39511 size_t file_struct_offset;
39512 /* Take wl->irq_lock before calling read/write? */
39513diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
39514index 43102bf..3b569c3 100644
39515--- a/drivers/net/wireless/ipw2x00/ipw2100.c
39516+++ b/drivers/net/wireless/ipw2x00/ipw2100.c
39517@@ -2014,6 +2014,8 @@ static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
39518 int err;
39519 DECLARE_SSID_BUF(ssid);
39520
39521+ pax_track_stack();
39522+
39523 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
39524
39525 if (ssid_len)
39526@@ -5380,6 +5382,8 @@ static int ipw2100_set_key(struct ipw2100_priv *priv,
39527 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
39528 int err;
39529
39530+ pax_track_stack();
39531+
39532 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
39533 idx, keylen, len);
39534
39535diff --git a/drivers/net/wireless/ipw2x00/libipw_rx.c b/drivers/net/wireless/ipw2x00/libipw_rx.c
39536index 282b1f7..169f0cf 100644
39537--- a/drivers/net/wireless/ipw2x00/libipw_rx.c
39538+++ b/drivers/net/wireless/ipw2x00/libipw_rx.c
39539@@ -1566,6 +1566,8 @@ static void libipw_process_probe_response(struct libipw_device
39540 unsigned long flags;
39541 DECLARE_SSID_BUF(ssid);
39542
39543+ pax_track_stack();
39544+
39545 LIBIPW_DEBUG_SCAN("'%s' (%pM"
39546 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
39547 print_ssid(ssid, info_element->data, info_element->len),
39548diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
39549index 950267a..80d5fd2 100644
39550--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
39551+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
39552@@ -137,7 +137,7 @@ static struct iwl_lib_ops iwl1000_lib = {
39553 },
39554 };
39555
39556-static struct iwl_ops iwl1000_ops = {
39557+static const struct iwl_ops iwl1000_ops = {
39558 .ucode = &iwl5000_ucode,
39559 .lib = &iwl1000_lib,
39560 .hcmd = &iwl5000_hcmd,
39561diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
39562index 56bfcc3..b348020 100644
39563--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
39564+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
39565@@ -2874,7 +2874,7 @@ static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
39566 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
39567 };
39568
39569-static struct iwl_ops iwl3945_ops = {
39570+static const struct iwl_ops iwl3945_ops = {
39571 .ucode = &iwl3945_ucode,
39572 .lib = &iwl3945_lib,
39573 .hcmd = &iwl3945_hcmd,
39574diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
39575index 585b8d4..e142963 100644
39576--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
39577+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
39578@@ -2345,7 +2345,7 @@ static struct iwl_lib_ops iwl4965_lib = {
39579 },
39580 };
39581
39582-static struct iwl_ops iwl4965_ops = {
39583+static const struct iwl_ops iwl4965_ops = {
39584 .ucode = &iwl4965_ucode,
39585 .lib = &iwl4965_lib,
39586 .hcmd = &iwl4965_hcmd,
39587diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
39588index 1f423f2..e37c192 100644
39589--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
39590+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
39591@@ -1633,14 +1633,14 @@ static struct iwl_lib_ops iwl5150_lib = {
39592 },
39593 };
39594
39595-struct iwl_ops iwl5000_ops = {
39596+const struct iwl_ops iwl5000_ops = {
39597 .ucode = &iwl5000_ucode,
39598 .lib = &iwl5000_lib,
39599 .hcmd = &iwl5000_hcmd,
39600 .utils = &iwl5000_hcmd_utils,
39601 };
39602
39603-static struct iwl_ops iwl5150_ops = {
39604+static const struct iwl_ops iwl5150_ops = {
39605 .ucode = &iwl5000_ucode,
39606 .lib = &iwl5150_lib,
39607 .hcmd = &iwl5000_hcmd,
39608diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
39609index 1473452..f07d5e1 100644
39610--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
39611+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
39612@@ -146,7 +146,7 @@ static struct iwl_hcmd_utils_ops iwl6000_hcmd_utils = {
39613 .calc_rssi = iwl5000_calc_rssi,
39614 };
39615
39616-static struct iwl_ops iwl6000_ops = {
39617+static const struct iwl_ops iwl6000_ops = {
39618 .ucode = &iwl5000_ucode,
39619 .lib = &iwl6000_lib,
39620 .hcmd = &iwl5000_hcmd,
39621diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39622index 1a3dfa2..b3e0a61 100644
39623--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39624+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39625@@ -857,6 +857,8 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
39626 u8 active_index = 0;
39627 s32 tpt = 0;
39628
39629+ pax_track_stack();
39630+
39631 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
39632
39633 if (!ieee80211_is_data(hdr->frame_control) ||
39634@@ -2722,6 +2724,8 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
39635 u8 valid_tx_ant = 0;
39636 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
39637
39638+ pax_track_stack();
39639+
39640 /* Override starting rate (index 0) if needed for debug purposes */
39641 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
39642
39643diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
39644index 0e56d78..6a3c107 100644
39645--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
39646+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
39647@@ -2911,7 +2911,9 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39648 if (iwl_debug_level & IWL_DL_INFO)
39649 dev_printk(KERN_DEBUG, &(pdev->dev),
39650 "Disabling hw_scan\n");
39651- iwl_hw_ops.hw_scan = NULL;
39652+ pax_open_kernel();
39653+ *(void **)&iwl_hw_ops.hw_scan = NULL;
39654+ pax_close_kernel();
39655 }
39656
39657 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
39658diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
39659index cbc6290..eb323d7 100644
39660--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
39661+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
39662@@ -118,8 +118,8 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv);
39663 #endif
39664
39665 #else
39666-#define IWL_DEBUG(__priv, level, fmt, args...)
39667-#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
39668+#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
39669+#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
39670 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
39671 void *p, u32 len)
39672 {}
39673diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39674index a198bcf..8e68233 100644
39675--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39676+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39677@@ -524,6 +524,8 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
39678 int pos = 0;
39679 const size_t bufsz = sizeof(buf);
39680
39681+ pax_track_stack();
39682+
39683 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
39684 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
39685 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
39686@@ -658,6 +660,8 @@ static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
39687 const size_t bufsz = sizeof(buf);
39688 ssize_t ret;
39689
39690+ pax_track_stack();
39691+
39692 for (i = 0; i < AC_NUM; i++) {
39693 pos += scnprintf(buf + pos, bufsz - pos,
39694 "\tcw_min\tcw_max\taifsn\ttxop\n");
39695diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
39696index 3539ea4..b174bfa 100644
39697--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
39698+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
39699@@ -68,7 +68,7 @@ struct iwl_tx_queue;
39700
39701 /* shared structures from iwl-5000.c */
39702 extern struct iwl_mod_params iwl50_mod_params;
39703-extern struct iwl_ops iwl5000_ops;
39704+extern const struct iwl_ops iwl5000_ops;
39705 extern struct iwl_ucode_ops iwl5000_ucode;
39706 extern struct iwl_lib_ops iwl5000_lib;
39707 extern struct iwl_hcmd_ops iwl5000_hcmd;
39708diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
39709index 619590d..69235ee 100644
39710--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
39711+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
39712@@ -3927,7 +3927,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
39713 */
39714 if (iwl3945_mod_params.disable_hw_scan) {
39715 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
39716- iwl3945_hw_ops.hw_scan = NULL;
39717+ pax_open_kernel();
39718+ *(void **)&iwl3945_hw_ops.hw_scan = NULL;
39719+ pax_close_kernel();
39720 }
39721
39722
39723diff --git a/drivers/net/wireless/iwmc3200wifi/debugfs.c b/drivers/net/wireless/iwmc3200wifi/debugfs.c
39724index 1465379..fe4d78b 100644
39725--- a/drivers/net/wireless/iwmc3200wifi/debugfs.c
39726+++ b/drivers/net/wireless/iwmc3200wifi/debugfs.c
39727@@ -299,6 +299,8 @@ static ssize_t iwm_debugfs_fw_err_read(struct file *filp,
39728 int buf_len = 512;
39729 size_t len = 0;
39730
39731+ pax_track_stack();
39732+
39733 if (*ppos != 0)
39734 return 0;
39735 if (count < sizeof(buf))
39736diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
39737index 893a55c..7f66a50 100644
39738--- a/drivers/net/wireless/libertas/debugfs.c
39739+++ b/drivers/net/wireless/libertas/debugfs.c
39740@@ -708,7 +708,7 @@ out_unlock:
39741 struct lbs_debugfs_files {
39742 const char *name;
39743 int perm;
39744- struct file_operations fops;
39745+ const struct file_operations fops;
39746 };
39747
39748 static const struct lbs_debugfs_files debugfs_files[] = {
39749diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
39750index 2ecbedb..42704f0 100644
39751--- a/drivers/net/wireless/rndis_wlan.c
39752+++ b/drivers/net/wireless/rndis_wlan.c
39753@@ -1176,7 +1176,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
39754
39755 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
39756
39757- if (rts_threshold < 0 || rts_threshold > 2347)
39758+ if (rts_threshold > 2347)
39759 rts_threshold = 2347;
39760
39761 tmp = cpu_to_le32(rts_threshold);
39762diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
39763index 334ccd6..47f8944 100644
39764--- a/drivers/oprofile/buffer_sync.c
39765+++ b/drivers/oprofile/buffer_sync.c
39766@@ -342,7 +342,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
39767 if (cookie == NO_COOKIE)
39768 offset = pc;
39769 if (cookie == INVALID_COOKIE) {
39770- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39771+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39772 offset = pc;
39773 }
39774 if (cookie != last_cookie) {
39775@@ -386,14 +386,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
39776 /* add userspace sample */
39777
39778 if (!mm) {
39779- atomic_inc(&oprofile_stats.sample_lost_no_mm);
39780+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
39781 return 0;
39782 }
39783
39784 cookie = lookup_dcookie(mm, s->eip, &offset);
39785
39786 if (cookie == INVALID_COOKIE) {
39787- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39788+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39789 return 0;
39790 }
39791
39792@@ -562,7 +562,7 @@ void sync_buffer(int cpu)
39793 /* ignore backtraces if failed to add a sample */
39794 if (state == sb_bt_start) {
39795 state = sb_bt_ignore;
39796- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
39797+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
39798 }
39799 }
39800 release_mm(mm);
39801diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
39802index 5df60a6..72f5c1c 100644
39803--- a/drivers/oprofile/event_buffer.c
39804+++ b/drivers/oprofile/event_buffer.c
39805@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
39806 }
39807
39808 if (buffer_pos == buffer_size) {
39809- atomic_inc(&oprofile_stats.event_lost_overflow);
39810+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
39811 return;
39812 }
39813
39814diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
39815index dc8a042..fe5f315 100644
39816--- a/drivers/oprofile/oprof.c
39817+++ b/drivers/oprofile/oprof.c
39818@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
39819 if (oprofile_ops.switch_events())
39820 return;
39821
39822- atomic_inc(&oprofile_stats.multiplex_counter);
39823+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
39824 start_switch_worker();
39825 }
39826
39827diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
39828index 61689e8..387f7f8 100644
39829--- a/drivers/oprofile/oprofile_stats.c
39830+++ b/drivers/oprofile/oprofile_stats.c
39831@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
39832 cpu_buf->sample_invalid_eip = 0;
39833 }
39834
39835- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
39836- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
39837- atomic_set(&oprofile_stats.event_lost_overflow, 0);
39838- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
39839- atomic_set(&oprofile_stats.multiplex_counter, 0);
39840+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
39841+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
39842+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
39843+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
39844+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
39845 }
39846
39847
39848diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
39849index 0b54e46..a37c527 100644
39850--- a/drivers/oprofile/oprofile_stats.h
39851+++ b/drivers/oprofile/oprofile_stats.h
39852@@ -13,11 +13,11 @@
39853 #include <asm/atomic.h>
39854
39855 struct oprofile_stat_struct {
39856- atomic_t sample_lost_no_mm;
39857- atomic_t sample_lost_no_mapping;
39858- atomic_t bt_lost_no_mapping;
39859- atomic_t event_lost_overflow;
39860- atomic_t multiplex_counter;
39861+ atomic_unchecked_t sample_lost_no_mm;
39862+ atomic_unchecked_t sample_lost_no_mapping;
39863+ atomic_unchecked_t bt_lost_no_mapping;
39864+ atomic_unchecked_t event_lost_overflow;
39865+ atomic_unchecked_t multiplex_counter;
39866 };
39867
39868 extern struct oprofile_stat_struct oprofile_stats;
39869diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
39870index 2766a6d..80c77e2 100644
39871--- a/drivers/oprofile/oprofilefs.c
39872+++ b/drivers/oprofile/oprofilefs.c
39873@@ -187,7 +187,7 @@ static const struct file_operations atomic_ro_fops = {
39874
39875
39876 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
39877- char const *name, atomic_t *val)
39878+ char const *name, atomic_unchecked_t *val)
39879 {
39880 struct dentry *d = __oprofilefs_create_file(sb, root, name,
39881 &atomic_ro_fops, 0444);
39882diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
39883index 13a64bc..ad62835 100644
39884--- a/drivers/parisc/pdc_stable.c
39885+++ b/drivers/parisc/pdc_stable.c
39886@@ -481,7 +481,7 @@ pdcspath_attr_store(struct kobject *kobj, struct attribute *attr,
39887 return ret;
39888 }
39889
39890-static struct sysfs_ops pdcspath_attr_ops = {
39891+static const struct sysfs_ops pdcspath_attr_ops = {
39892 .show = pdcspath_attr_show,
39893 .store = pdcspath_attr_store,
39894 };
39895diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
39896index 8eefe56..40751a7 100644
39897--- a/drivers/parport/procfs.c
39898+++ b/drivers/parport/procfs.c
39899@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
39900
39901 *ppos += len;
39902
39903- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
39904+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
39905 }
39906
39907 #ifdef CONFIG_PARPORT_1284
39908@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
39909
39910 *ppos += len;
39911
39912- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
39913+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
39914 }
39915 #endif /* IEEE1284.3 support. */
39916
39917diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
39918index 73e7d8e..c80f3d2 100644
39919--- a/drivers/pci/hotplug/acpiphp_glue.c
39920+++ b/drivers/pci/hotplug/acpiphp_glue.c
39921@@ -111,7 +111,7 @@ static int post_dock_fixups(struct notifier_block *nb, unsigned long val,
39922 }
39923
39924
39925-static struct acpi_dock_ops acpiphp_dock_ops = {
39926+static const struct acpi_dock_ops acpiphp_dock_ops = {
39927 .handler = handle_hotplug_event_func,
39928 };
39929
39930diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
39931index 9fff878..ad0ad53 100644
39932--- a/drivers/pci/hotplug/cpci_hotplug.h
39933+++ b/drivers/pci/hotplug/cpci_hotplug.h
39934@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
39935 int (*hardware_test) (struct slot* slot, u32 value);
39936 u8 (*get_power) (struct slot* slot);
39937 int (*set_power) (struct slot* slot, int value);
39938-};
39939+} __no_const;
39940
39941 struct cpci_hp_controller {
39942 unsigned int irq;
39943diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
39944index 76ba8a1..20ca857 100644
39945--- a/drivers/pci/hotplug/cpqphp_nvram.c
39946+++ b/drivers/pci/hotplug/cpqphp_nvram.c
39947@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
39948
39949 void compaq_nvram_init (void __iomem *rom_start)
39950 {
39951+
39952+#ifndef CONFIG_PAX_KERNEXEC
39953 if (rom_start) {
39954 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
39955 }
39956+#endif
39957+
39958 dbg("int15 entry = %p\n", compaq_int15_entry_point);
39959
39960 /* initialize our int15 lock */
39961diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
39962index 6151389..0a894ef 100644
39963--- a/drivers/pci/hotplug/fakephp.c
39964+++ b/drivers/pci/hotplug/fakephp.c
39965@@ -73,7 +73,7 @@ static void legacy_release(struct kobject *kobj)
39966 }
39967
39968 static struct kobj_type legacy_ktype = {
39969- .sysfs_ops = &(struct sysfs_ops){
39970+ .sysfs_ops = &(const struct sysfs_ops){
39971 .store = legacy_store, .show = legacy_show
39972 },
39973 .release = &legacy_release,
39974diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
39975index 5b680df..fe05b7e 100644
39976--- a/drivers/pci/intel-iommu.c
39977+++ b/drivers/pci/intel-iommu.c
39978@@ -2643,7 +2643,7 @@ error:
39979 return 0;
39980 }
39981
39982-static dma_addr_t intel_map_page(struct device *dev, struct page *page,
39983+dma_addr_t intel_map_page(struct device *dev, struct page *page,
39984 unsigned long offset, size_t size,
39985 enum dma_data_direction dir,
39986 struct dma_attrs *attrs)
39987@@ -2719,7 +2719,7 @@ static void add_unmap(struct dmar_domain *dom, struct iova *iova)
39988 spin_unlock_irqrestore(&async_umap_flush_lock, flags);
39989 }
39990
39991-static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39992+void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39993 size_t size, enum dma_data_direction dir,
39994 struct dma_attrs *attrs)
39995 {
39996@@ -2768,7 +2768,7 @@ static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39997 }
39998 }
39999
40000-static void *intel_alloc_coherent(struct device *hwdev, size_t size,
40001+void *intel_alloc_coherent(struct device *hwdev, size_t size,
40002 dma_addr_t *dma_handle, gfp_t flags)
40003 {
40004 void *vaddr;
40005@@ -2800,7 +2800,7 @@ static void *intel_alloc_coherent(struct device *hwdev, size_t size,
40006 return NULL;
40007 }
40008
40009-static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
40010+void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
40011 dma_addr_t dma_handle)
40012 {
40013 int order;
40014@@ -2812,7 +2812,7 @@ static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
40015 free_pages((unsigned long)vaddr, order);
40016 }
40017
40018-static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
40019+void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
40020 int nelems, enum dma_data_direction dir,
40021 struct dma_attrs *attrs)
40022 {
40023@@ -2872,7 +2872,7 @@ static int intel_nontranslate_map_sg(struct device *hddev,
40024 return nelems;
40025 }
40026
40027-static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
40028+int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
40029 enum dma_data_direction dir, struct dma_attrs *attrs)
40030 {
40031 int i;
40032@@ -2941,12 +2941,12 @@ static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int ne
40033 return nelems;
40034 }
40035
40036-static int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
40037+int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
40038 {
40039 return !dma_addr;
40040 }
40041
40042-struct dma_map_ops intel_dma_ops = {
40043+const struct dma_map_ops intel_dma_ops = {
40044 .alloc_coherent = intel_alloc_coherent,
40045 .free_coherent = intel_free_coherent,
40046 .map_sg = intel_map_sg,
40047diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
40048index 5b7056c..607bc94 100644
40049--- a/drivers/pci/pcie/aspm.c
40050+++ b/drivers/pci/pcie/aspm.c
40051@@ -27,9 +27,9 @@
40052 #define MODULE_PARAM_PREFIX "pcie_aspm."
40053
40054 /* Note: those are not register definitions */
40055-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
40056-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
40057-#define ASPM_STATE_L1 (4) /* L1 state */
40058+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
40059+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
40060+#define ASPM_STATE_L1 (4U) /* L1 state */
40061 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
40062 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
40063
40064diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
40065index 8105e32..ca10419 100644
40066--- a/drivers/pci/probe.c
40067+++ b/drivers/pci/probe.c
40068@@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(struct device *dev,
40069 return ret;
40070 }
40071
40072-static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
40073+static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
40074 struct device_attribute *attr,
40075 char *buf)
40076 {
40077 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
40078 }
40079
40080-static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
40081+static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
40082 struct device_attribute *attr,
40083 char *buf)
40084 {
40085diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
40086index a03ad8c..024b0da 100644
40087--- a/drivers/pci/proc.c
40088+++ b/drivers/pci/proc.c
40089@@ -480,7 +480,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
40090 static int __init pci_proc_init(void)
40091 {
40092 struct pci_dev *dev = NULL;
40093+
40094+#ifdef CONFIG_GRKERNSEC_PROC_ADD
40095+#ifdef CONFIG_GRKERNSEC_PROC_USER
40096+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
40097+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
40098+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
40099+#endif
40100+#else
40101 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
40102+#endif
40103 proc_create("devices", 0, proc_bus_pci_dir,
40104 &proc_bus_pci_dev_operations);
40105 proc_initialized = 1;
40106diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
40107index 8c02b6c..5584d8e 100644
40108--- a/drivers/pci/slot.c
40109+++ b/drivers/pci/slot.c
40110@@ -29,7 +29,7 @@ static ssize_t pci_slot_attr_store(struct kobject *kobj,
40111 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
40112 }
40113
40114-static struct sysfs_ops pci_slot_sysfs_ops = {
40115+static const struct sysfs_ops pci_slot_sysfs_ops = {
40116 .show = pci_slot_attr_show,
40117 .store = pci_slot_attr_store,
40118 };
40119diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
40120index 30cf71d2..50938f1 100644
40121--- a/drivers/pcmcia/pcmcia_ioctl.c
40122+++ b/drivers/pcmcia/pcmcia_ioctl.c
40123@@ -819,7 +819,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
40124 return -EFAULT;
40125 }
40126 }
40127- buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
40128+ buf = kzalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
40129 if (!buf)
40130 return -ENOMEM;
40131
40132diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
40133index 52183c4..b224c69 100644
40134--- a/drivers/platform/x86/acer-wmi.c
40135+++ b/drivers/platform/x86/acer-wmi.c
40136@@ -918,7 +918,7 @@ static int update_bl_status(struct backlight_device *bd)
40137 return 0;
40138 }
40139
40140-static struct backlight_ops acer_bl_ops = {
40141+static const struct backlight_ops acer_bl_ops = {
40142 .get_brightness = read_brightness,
40143 .update_status = update_bl_status,
40144 };
40145diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
40146index 767cb61..a87380b 100644
40147--- a/drivers/platform/x86/asus-laptop.c
40148+++ b/drivers/platform/x86/asus-laptop.c
40149@@ -250,7 +250,7 @@ static struct backlight_device *asus_backlight_device;
40150 */
40151 static int read_brightness(struct backlight_device *bd);
40152 static int update_bl_status(struct backlight_device *bd);
40153-static struct backlight_ops asusbl_ops = {
40154+static const struct backlight_ops asusbl_ops = {
40155 .get_brightness = read_brightness,
40156 .update_status = update_bl_status,
40157 };
40158diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
40159index d66c07a..a4abaac 100644
40160--- a/drivers/platform/x86/asus_acpi.c
40161+++ b/drivers/platform/x86/asus_acpi.c
40162@@ -1396,7 +1396,7 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
40163 return 0;
40164 }
40165
40166-static struct backlight_ops asus_backlight_data = {
40167+static const struct backlight_ops asus_backlight_data = {
40168 .get_brightness = read_brightness,
40169 .update_status = set_brightness_status,
40170 };
40171diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
40172index 11003bb..550ff1b 100644
40173--- a/drivers/platform/x86/compal-laptop.c
40174+++ b/drivers/platform/x86/compal-laptop.c
40175@@ -163,7 +163,7 @@ static int bl_update_status(struct backlight_device *b)
40176 return set_lcd_level(b->props.brightness);
40177 }
40178
40179-static struct backlight_ops compalbl_ops = {
40180+static const struct backlight_ops compalbl_ops = {
40181 .get_brightness = bl_get_brightness,
40182 .update_status = bl_update_status,
40183 };
40184diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
40185index 07a74da..9dc99fa 100644
40186--- a/drivers/platform/x86/dell-laptop.c
40187+++ b/drivers/platform/x86/dell-laptop.c
40188@@ -318,7 +318,7 @@ static int dell_get_intensity(struct backlight_device *bd)
40189 return buffer.output[1];
40190 }
40191
40192-static struct backlight_ops dell_ops = {
40193+static const struct backlight_ops dell_ops = {
40194 .get_brightness = dell_get_intensity,
40195 .update_status = dell_send_intensity,
40196 };
40197diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
40198index c533b1c..5c81f22 100644
40199--- a/drivers/platform/x86/eeepc-laptop.c
40200+++ b/drivers/platform/x86/eeepc-laptop.c
40201@@ -245,7 +245,7 @@ static struct device *eeepc_hwmon_device;
40202 */
40203 static int read_brightness(struct backlight_device *bd);
40204 static int update_bl_status(struct backlight_device *bd);
40205-static struct backlight_ops eeepcbl_ops = {
40206+static const struct backlight_ops eeepcbl_ops = {
40207 .get_brightness = read_brightness,
40208 .update_status = update_bl_status,
40209 };
40210diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
40211index bcd4ba8..a249b35 100644
40212--- a/drivers/platform/x86/fujitsu-laptop.c
40213+++ b/drivers/platform/x86/fujitsu-laptop.c
40214@@ -436,7 +436,7 @@ static int bl_update_status(struct backlight_device *b)
40215 return ret;
40216 }
40217
40218-static struct backlight_ops fujitsubl_ops = {
40219+static const struct backlight_ops fujitsubl_ops = {
40220 .get_brightness = bl_get_brightness,
40221 .update_status = bl_update_status,
40222 };
40223diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40224index 759763d..1093ba2 100644
40225--- a/drivers/platform/x86/msi-laptop.c
40226+++ b/drivers/platform/x86/msi-laptop.c
40227@@ -161,7 +161,7 @@ static int bl_update_status(struct backlight_device *b)
40228 return set_lcd_level(b->props.brightness);
40229 }
40230
40231-static struct backlight_ops msibl_ops = {
40232+static const struct backlight_ops msibl_ops = {
40233 .get_brightness = bl_get_brightness,
40234 .update_status = bl_update_status,
40235 };
40236diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
40237index fe7cf01..9012d8d 100644
40238--- a/drivers/platform/x86/panasonic-laptop.c
40239+++ b/drivers/platform/x86/panasonic-laptop.c
40240@@ -352,7 +352,7 @@ static int bl_set_status(struct backlight_device *bd)
40241 return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
40242 }
40243
40244-static struct backlight_ops pcc_backlight_ops = {
40245+static const struct backlight_ops pcc_backlight_ops = {
40246 .get_brightness = bl_get,
40247 .update_status = bl_set_status,
40248 };
40249diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40250index a2a742c..b37e25e 100644
40251--- a/drivers/platform/x86/sony-laptop.c
40252+++ b/drivers/platform/x86/sony-laptop.c
40253@@ -850,7 +850,7 @@ static int sony_backlight_get_brightness(struct backlight_device *bd)
40254 }
40255
40256 static struct backlight_device *sony_backlight_device;
40257-static struct backlight_ops sony_backlight_ops = {
40258+static const struct backlight_ops sony_backlight_ops = {
40259 .update_status = sony_backlight_update_status,
40260 .get_brightness = sony_backlight_get_brightness,
40261 };
40262diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40263index 68271ae..5e8fb10 100644
40264--- a/drivers/platform/x86/thinkpad_acpi.c
40265+++ b/drivers/platform/x86/thinkpad_acpi.c
40266@@ -2139,7 +2139,7 @@ static int hotkey_mask_get(void)
40267 return 0;
40268 }
40269
40270-void static hotkey_mask_warn_incomplete_mask(void)
40271+static void hotkey_mask_warn_incomplete_mask(void)
40272 {
40273 /* log only what the user can fix... */
40274 const u32 wantedmask = hotkey_driver_mask &
40275@@ -6125,7 +6125,7 @@ static void tpacpi_brightness_notify_change(void)
40276 BACKLIGHT_UPDATE_HOTKEY);
40277 }
40278
40279-static struct backlight_ops ibm_backlight_data = {
40280+static const struct backlight_ops ibm_backlight_data = {
40281 .get_brightness = brightness_get,
40282 .update_status = brightness_update_status,
40283 };
40284diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
40285index 51c0a8b..0786629 100644
40286--- a/drivers/platform/x86/toshiba_acpi.c
40287+++ b/drivers/platform/x86/toshiba_acpi.c
40288@@ -671,7 +671,7 @@ static acpi_status remove_device(void)
40289 return AE_OK;
40290 }
40291
40292-static struct backlight_ops toshiba_backlight_data = {
40293+static const struct backlight_ops toshiba_backlight_data = {
40294 .get_brightness = get_lcd,
40295 .update_status = set_lcd_status,
40296 };
40297diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40298index fc83783c..cf370d7 100644
40299--- a/drivers/pnp/pnpbios/bioscalls.c
40300+++ b/drivers/pnp/pnpbios/bioscalls.c
40301@@ -60,7 +60,7 @@ do { \
40302 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40303 } while(0)
40304
40305-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40306+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40307 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40308
40309 /*
40310@@ -97,7 +97,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40311
40312 cpu = get_cpu();
40313 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40314+
40315+ pax_open_kernel();
40316 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40317+ pax_close_kernel();
40318
40319 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40320 spin_lock_irqsave(&pnp_bios_lock, flags);
40321@@ -135,7 +138,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40322 :"memory");
40323 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40324
40325+ pax_open_kernel();
40326 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40327+ pax_close_kernel();
40328+
40329 put_cpu();
40330
40331 /* If we get here and this is set then the PnP BIOS faulted on us. */
40332@@ -469,7 +475,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40333 return status;
40334 }
40335
40336-void pnpbios_calls_init(union pnp_bios_install_struct *header)
40337+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40338 {
40339 int i;
40340
40341@@ -477,6 +483,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40342 pnp_bios_callpoint.offset = header->fields.pm16offset;
40343 pnp_bios_callpoint.segment = PNP_CS16;
40344
40345+ pax_open_kernel();
40346+
40347 for_each_possible_cpu(i) {
40348 struct desc_struct *gdt = get_cpu_gdt_table(i);
40349 if (!gdt)
40350@@ -488,4 +496,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40351 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40352 (unsigned long)__va(header->fields.pm16dseg));
40353 }
40354+
40355+ pax_close_kernel();
40356 }
40357diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40358index ba97654..66b99d4 100644
40359--- a/drivers/pnp/resource.c
40360+++ b/drivers/pnp/resource.c
40361@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40362 return 1;
40363
40364 /* check if the resource is valid */
40365- if (*irq < 0 || *irq > 15)
40366+ if (*irq > 15)
40367 return 0;
40368
40369 /* check if the resource is reserved */
40370@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40371 return 1;
40372
40373 /* check if the resource is valid */
40374- if (*dma < 0 || *dma == 4 || *dma > 7)
40375+ if (*dma == 4 || *dma > 7)
40376 return 0;
40377
40378 /* check if the resource is reserved */
40379diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
40380index 62bb981..24a2dc9 100644
40381--- a/drivers/power/bq27x00_battery.c
40382+++ b/drivers/power/bq27x00_battery.c
40383@@ -44,7 +44,7 @@ struct bq27x00_device_info;
40384 struct bq27x00_access_methods {
40385 int (*read)(u8 reg, int *rt_value, int b_single,
40386 struct bq27x00_device_info *di);
40387-};
40388+} __no_const;
40389
40390 struct bq27x00_device_info {
40391 struct device *dev;
40392diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
40393index 62227cd..b5b538b 100644
40394--- a/drivers/rtc/rtc-dev.c
40395+++ b/drivers/rtc/rtc-dev.c
40396@@ -14,6 +14,7 @@
40397 #include <linux/module.h>
40398 #include <linux/rtc.h>
40399 #include <linux/sched.h>
40400+#include <linux/grsecurity.h>
40401 #include "rtc-core.h"
40402
40403 static dev_t rtc_devt;
40404@@ -357,6 +358,8 @@ static long rtc_dev_ioctl(struct file *file,
40405 if (copy_from_user(&tm, uarg, sizeof(tm)))
40406 return -EFAULT;
40407
40408+ gr_log_timechange();
40409+
40410 return rtc_set_time(rtc, &tm);
40411
40412 case RTC_PIE_ON:
40413diff --git a/drivers/s390/cio/qdio_perf.c b/drivers/s390/cio/qdio_perf.c
40414index 968e3c7..fbc637a 100644
40415--- a/drivers/s390/cio/qdio_perf.c
40416+++ b/drivers/s390/cio/qdio_perf.c
40417@@ -31,51 +31,51 @@ static struct proc_dir_entry *qdio_perf_pde;
40418 static int qdio_perf_proc_show(struct seq_file *m, void *v)
40419 {
40420 seq_printf(m, "Number of qdio interrupts\t\t\t: %li\n",
40421- (long)atomic_long_read(&perf_stats.qdio_int));
40422+ (long)atomic_long_read_unchecked(&perf_stats.qdio_int));
40423 seq_printf(m, "Number of PCI interrupts\t\t\t: %li\n",
40424- (long)atomic_long_read(&perf_stats.pci_int));
40425+ (long)atomic_long_read_unchecked(&perf_stats.pci_int));
40426 seq_printf(m, "Number of adapter interrupts\t\t\t: %li\n",
40427- (long)atomic_long_read(&perf_stats.thin_int));
40428+ (long)atomic_long_read_unchecked(&perf_stats.thin_int));
40429 seq_printf(m, "\n");
40430 seq_printf(m, "Inbound tasklet runs\t\t\t\t: %li\n",
40431- (long)atomic_long_read(&perf_stats.tasklet_inbound));
40432+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_inbound));
40433 seq_printf(m, "Outbound tasklet runs\t\t\t\t: %li\n",
40434- (long)atomic_long_read(&perf_stats.tasklet_outbound));
40435+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_outbound));
40436 seq_printf(m, "Adapter interrupt tasklet runs/loops\t\t: %li/%li\n",
40437- (long)atomic_long_read(&perf_stats.tasklet_thinint),
40438- (long)atomic_long_read(&perf_stats.tasklet_thinint_loop));
40439+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint),
40440+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint_loop));
40441 seq_printf(m, "Adapter interrupt inbound tasklet runs/loops\t: %li/%li\n",
40442- (long)atomic_long_read(&perf_stats.thinint_inbound),
40443- (long)atomic_long_read(&perf_stats.thinint_inbound_loop));
40444+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound),
40445+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop));
40446 seq_printf(m, "\n");
40447 seq_printf(m, "Number of SIGA In issued\t\t\t: %li\n",
40448- (long)atomic_long_read(&perf_stats.siga_in));
40449+ (long)atomic_long_read_unchecked(&perf_stats.siga_in));
40450 seq_printf(m, "Number of SIGA Out issued\t\t\t: %li\n",
40451- (long)atomic_long_read(&perf_stats.siga_out));
40452+ (long)atomic_long_read_unchecked(&perf_stats.siga_out));
40453 seq_printf(m, "Number of SIGA Sync issued\t\t\t: %li\n",
40454- (long)atomic_long_read(&perf_stats.siga_sync));
40455+ (long)atomic_long_read_unchecked(&perf_stats.siga_sync));
40456 seq_printf(m, "\n");
40457 seq_printf(m, "Number of inbound transfers\t\t\t: %li\n",
40458- (long)atomic_long_read(&perf_stats.inbound_handler));
40459+ (long)atomic_long_read_unchecked(&perf_stats.inbound_handler));
40460 seq_printf(m, "Number of outbound transfers\t\t\t: %li\n",
40461- (long)atomic_long_read(&perf_stats.outbound_handler));
40462+ (long)atomic_long_read_unchecked(&perf_stats.outbound_handler));
40463 seq_printf(m, "\n");
40464 seq_printf(m, "Number of fast requeues (outg. SBAL w/o SIGA)\t: %li\n",
40465- (long)atomic_long_read(&perf_stats.fast_requeue));
40466+ (long)atomic_long_read_unchecked(&perf_stats.fast_requeue));
40467 seq_printf(m, "Number of outbound target full condition\t: %li\n",
40468- (long)atomic_long_read(&perf_stats.outbound_target_full));
40469+ (long)atomic_long_read_unchecked(&perf_stats.outbound_target_full));
40470 seq_printf(m, "Number of outbound tasklet mod_timer calls\t: %li\n",
40471- (long)atomic_long_read(&perf_stats.debug_tl_out_timer));
40472+ (long)atomic_long_read_unchecked(&perf_stats.debug_tl_out_timer));
40473 seq_printf(m, "Number of stop polling calls\t\t\t: %li\n",
40474- (long)atomic_long_read(&perf_stats.debug_stop_polling));
40475+ (long)atomic_long_read_unchecked(&perf_stats.debug_stop_polling));
40476 seq_printf(m, "AI inbound tasklet loops after stop polling\t: %li\n",
40477- (long)atomic_long_read(&perf_stats.thinint_inbound_loop2));
40478+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop2));
40479 seq_printf(m, "QEBSM EQBS total/incomplete\t\t\t: %li/%li\n",
40480- (long)atomic_long_read(&perf_stats.debug_eqbs_all),
40481- (long)atomic_long_read(&perf_stats.debug_eqbs_incomplete));
40482+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_all),
40483+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_incomplete));
40484 seq_printf(m, "QEBSM SQBS total/incomplete\t\t\t: %li/%li\n",
40485- (long)atomic_long_read(&perf_stats.debug_sqbs_all),
40486- (long)atomic_long_read(&perf_stats.debug_sqbs_incomplete));
40487+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_all),
40488+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_incomplete));
40489 seq_printf(m, "\n");
40490 return 0;
40491 }
40492diff --git a/drivers/s390/cio/qdio_perf.h b/drivers/s390/cio/qdio_perf.h
40493index ff4504c..b3604c3 100644
40494--- a/drivers/s390/cio/qdio_perf.h
40495+++ b/drivers/s390/cio/qdio_perf.h
40496@@ -13,46 +13,46 @@
40497
40498 struct qdio_perf_stats {
40499 /* interrupt handler calls */
40500- atomic_long_t qdio_int;
40501- atomic_long_t pci_int;
40502- atomic_long_t thin_int;
40503+ atomic_long_unchecked_t qdio_int;
40504+ atomic_long_unchecked_t pci_int;
40505+ atomic_long_unchecked_t thin_int;
40506
40507 /* tasklet runs */
40508- atomic_long_t tasklet_inbound;
40509- atomic_long_t tasklet_outbound;
40510- atomic_long_t tasklet_thinint;
40511- atomic_long_t tasklet_thinint_loop;
40512- atomic_long_t thinint_inbound;
40513- atomic_long_t thinint_inbound_loop;
40514- atomic_long_t thinint_inbound_loop2;
40515+ atomic_long_unchecked_t tasklet_inbound;
40516+ atomic_long_unchecked_t tasklet_outbound;
40517+ atomic_long_unchecked_t tasklet_thinint;
40518+ atomic_long_unchecked_t tasklet_thinint_loop;
40519+ atomic_long_unchecked_t thinint_inbound;
40520+ atomic_long_unchecked_t thinint_inbound_loop;
40521+ atomic_long_unchecked_t thinint_inbound_loop2;
40522
40523 /* signal adapter calls */
40524- atomic_long_t siga_out;
40525- atomic_long_t siga_in;
40526- atomic_long_t siga_sync;
40527+ atomic_long_unchecked_t siga_out;
40528+ atomic_long_unchecked_t siga_in;
40529+ atomic_long_unchecked_t siga_sync;
40530
40531 /* misc */
40532- atomic_long_t inbound_handler;
40533- atomic_long_t outbound_handler;
40534- atomic_long_t fast_requeue;
40535- atomic_long_t outbound_target_full;
40536+ atomic_long_unchecked_t inbound_handler;
40537+ atomic_long_unchecked_t outbound_handler;
40538+ atomic_long_unchecked_t fast_requeue;
40539+ atomic_long_unchecked_t outbound_target_full;
40540
40541 /* for debugging */
40542- atomic_long_t debug_tl_out_timer;
40543- atomic_long_t debug_stop_polling;
40544- atomic_long_t debug_eqbs_all;
40545- atomic_long_t debug_eqbs_incomplete;
40546- atomic_long_t debug_sqbs_all;
40547- atomic_long_t debug_sqbs_incomplete;
40548+ atomic_long_unchecked_t debug_tl_out_timer;
40549+ atomic_long_unchecked_t debug_stop_polling;
40550+ atomic_long_unchecked_t debug_eqbs_all;
40551+ atomic_long_unchecked_t debug_eqbs_incomplete;
40552+ atomic_long_unchecked_t debug_sqbs_all;
40553+ atomic_long_unchecked_t debug_sqbs_incomplete;
40554 };
40555
40556 extern struct qdio_perf_stats perf_stats;
40557 extern int qdio_performance_stats;
40558
40559-static inline void qdio_perf_stat_inc(atomic_long_t *count)
40560+static inline void qdio_perf_stat_inc(atomic_long_unchecked_t *count)
40561 {
40562 if (qdio_performance_stats)
40563- atomic_long_inc(count);
40564+ atomic_long_inc_unchecked(count);
40565 }
40566
40567 int qdio_setup_perf_stats(void);
40568diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
40569index 1ddcf40..a85f062 100644
40570--- a/drivers/scsi/BusLogic.c
40571+++ b/drivers/scsi/BusLogic.c
40572@@ -961,6 +961,8 @@ static int __init BusLogic_InitializeFlashPointProbeInfo(struct BusLogic_HostAda
40573 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
40574 *PrototypeHostAdapter)
40575 {
40576+ pax_track_stack();
40577+
40578 /*
40579 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
40580 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
40581diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
40582index cdbdec9..b7d560b 100644
40583--- a/drivers/scsi/aacraid/aacraid.h
40584+++ b/drivers/scsi/aacraid/aacraid.h
40585@@ -471,7 +471,7 @@ struct adapter_ops
40586 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
40587 /* Administrative operations */
40588 int (*adapter_comm)(struct aac_dev * dev, int comm);
40589-};
40590+} __no_const;
40591
40592 /*
40593 * Define which interrupt handler needs to be installed
40594diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
40595index a5b8e7b..a6a0e43 100644
40596--- a/drivers/scsi/aacraid/commctrl.c
40597+++ b/drivers/scsi/aacraid/commctrl.c
40598@@ -481,6 +481,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
40599 u32 actual_fibsize64, actual_fibsize = 0;
40600 int i;
40601
40602+ pax_track_stack();
40603
40604 if (dev->in_reset) {
40605 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
40606diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
40607index 9b97c3e..f099725 100644
40608--- a/drivers/scsi/aacraid/linit.c
40609+++ b/drivers/scsi/aacraid/linit.c
40610@@ -91,7 +91,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
40611 #elif defined(__devinitconst)
40612 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
40613 #else
40614-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
40615+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
40616 #endif
40617 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
40618 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
40619diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
40620index 996f722..9127845 100644
40621--- a/drivers/scsi/aic94xx/aic94xx_init.c
40622+++ b/drivers/scsi/aic94xx/aic94xx_init.c
40623@@ -485,7 +485,7 @@ static ssize_t asd_show_update_bios(struct device *dev,
40624 flash_error_table[i].reason);
40625 }
40626
40627-static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
40628+static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
40629 asd_show_update_bios, asd_store_update_bios);
40630
40631 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
40632@@ -1011,7 +1011,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
40633 .lldd_control_phy = asd_control_phy,
40634 };
40635
40636-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
40637+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
40638 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
40639 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
40640 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
40641diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
40642index 58efd4b..cb48dc7 100644
40643--- a/drivers/scsi/bfa/bfa_ioc.h
40644+++ b/drivers/scsi/bfa/bfa_ioc.h
40645@@ -127,7 +127,7 @@ struct bfa_ioc_cbfn_s {
40646 bfa_ioc_disable_cbfn_t disable_cbfn;
40647 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
40648 bfa_ioc_reset_cbfn_t reset_cbfn;
40649-};
40650+} __no_const;
40651
40652 /**
40653 * Heartbeat failure notification queue element.
40654diff --git a/drivers/scsi/bfa/bfa_iocfc.h b/drivers/scsi/bfa/bfa_iocfc.h
40655index 7ad177e..5503586 100644
40656--- a/drivers/scsi/bfa/bfa_iocfc.h
40657+++ b/drivers/scsi/bfa/bfa_iocfc.h
40658@@ -61,7 +61,7 @@ struct bfa_hwif_s {
40659 void (*hw_isr_mode_set)(struct bfa_s *bfa, bfa_boolean_t msix);
40660 void (*hw_msix_getvecs)(struct bfa_s *bfa, u32 *vecmap,
40661 u32 *nvecs, u32 *maxvec);
40662-};
40663+} __no_const;
40664 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
40665
40666 struct bfa_iocfc_s {
40667diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
40668index 4967643..cbec06b 100644
40669--- a/drivers/scsi/dpt_i2o.c
40670+++ b/drivers/scsi/dpt_i2o.c
40671@@ -1804,6 +1804,8 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
40672 dma_addr_t addr;
40673 ulong flags = 0;
40674
40675+ pax_track_stack();
40676+
40677 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
40678 // get user msg size in u32s
40679 if(get_user(size, &user_msg[0])){
40680@@ -2297,6 +2299,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
40681 s32 rcode;
40682 dma_addr_t addr;
40683
40684+ pax_track_stack();
40685+
40686 memset(msg, 0 , sizeof(msg));
40687 len = scsi_bufflen(cmd);
40688 direction = 0x00000000;
40689diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
40690index c7076ce..e20c67c 100644
40691--- a/drivers/scsi/eata.c
40692+++ b/drivers/scsi/eata.c
40693@@ -1087,6 +1087,8 @@ static int port_detect(unsigned long port_base, unsigned int j,
40694 struct hostdata *ha;
40695 char name[16];
40696
40697+ pax_track_stack();
40698+
40699 sprintf(name, "%s%d", driver_name, j);
40700
40701 if (!request_region(port_base, REGION_SIZE, driver_name)) {
40702diff --git a/drivers/scsi/fcoe/libfcoe.c b/drivers/scsi/fcoe/libfcoe.c
40703index 11ae5c9..891daec 100644
40704--- a/drivers/scsi/fcoe/libfcoe.c
40705+++ b/drivers/scsi/fcoe/libfcoe.c
40706@@ -809,6 +809,8 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
40707 size_t rlen;
40708 size_t dlen;
40709
40710+ pax_track_stack();
40711+
40712 fiph = (struct fip_header *)skb->data;
40713 sub = fiph->fip_subcode;
40714 if (sub != FIP_SC_REQ && sub != FIP_SC_REP)
40715diff --git a/drivers/scsi/fnic/fnic_main.c b/drivers/scsi/fnic/fnic_main.c
40716index 71c7bbe..e93088a 100644
40717--- a/drivers/scsi/fnic/fnic_main.c
40718+++ b/drivers/scsi/fnic/fnic_main.c
40719@@ -669,7 +669,7 @@ static int __devinit fnic_probe(struct pci_dev *pdev,
40720 /* Start local port initiatialization */
40721
40722 lp->link_up = 0;
40723- lp->tt = fnic_transport_template;
40724+ memcpy((void *)&lp->tt, &fnic_transport_template, sizeof(fnic_transport_template));
40725
40726 lp->max_retry_count = fnic->config.flogi_retries;
40727 lp->max_rport_retry_count = fnic->config.plogi_retries;
40728diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
40729index bb96d74..9ec3ce4 100644
40730--- a/drivers/scsi/gdth.c
40731+++ b/drivers/scsi/gdth.c
40732@@ -4102,6 +4102,8 @@ static int ioc_lockdrv(void __user *arg)
40733 ulong flags;
40734 gdth_ha_str *ha;
40735
40736+ pax_track_stack();
40737+
40738 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
40739 return -EFAULT;
40740 ha = gdth_find_ha(ldrv.ionode);
40741@@ -4134,6 +4136,8 @@ static int ioc_resetdrv(void __user *arg, char *cmnd)
40742 gdth_ha_str *ha;
40743 int rval;
40744
40745+ pax_track_stack();
40746+
40747 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
40748 res.number >= MAX_HDRIVES)
40749 return -EFAULT;
40750@@ -4169,6 +4173,8 @@ static int ioc_general(void __user *arg, char *cmnd)
40751 gdth_ha_str *ha;
40752 int rval;
40753
40754+ pax_track_stack();
40755+
40756 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
40757 return -EFAULT;
40758 ha = gdth_find_ha(gen.ionode);
40759@@ -4625,6 +4631,9 @@ static void gdth_flush(gdth_ha_str *ha)
40760 int i;
40761 gdth_cmd_str gdtcmd;
40762 char cmnd[MAX_COMMAND_SIZE];
40763+
40764+ pax_track_stack();
40765+
40766 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
40767
40768 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
40769diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
40770index 1258da3..20d8ae6 100644
40771--- a/drivers/scsi/gdth_proc.c
40772+++ b/drivers/scsi/gdth_proc.c
40773@@ -46,6 +46,9 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
40774 ulong64 paddr;
40775
40776 char cmnd[MAX_COMMAND_SIZE];
40777+
40778+ pax_track_stack();
40779+
40780 memset(cmnd, 0xff, 12);
40781 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
40782
40783@@ -174,6 +177,8 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
40784 gdth_hget_str *phg;
40785 char cmnd[MAX_COMMAND_SIZE];
40786
40787+ pax_track_stack();
40788+
40789 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
40790 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
40791 if (!gdtcmd || !estr)
40792diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
40793index d03a926..f324286 100644
40794--- a/drivers/scsi/hosts.c
40795+++ b/drivers/scsi/hosts.c
40796@@ -40,7 +40,7 @@
40797 #include "scsi_logging.h"
40798
40799
40800-static atomic_t scsi_host_next_hn; /* host_no for next new host */
40801+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
40802
40803
40804 static void scsi_host_cls_release(struct device *dev)
40805@@ -347,7 +347,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
40806 * subtract one because we increment first then return, but we need to
40807 * know what the next host number was before increment
40808 */
40809- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
40810+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
40811 shost->dma_channel = 0xff;
40812
40813 /* These three are default values which can be overridden */
40814diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
40815index a601159..55e19d2 100644
40816--- a/drivers/scsi/ipr.c
40817+++ b/drivers/scsi/ipr.c
40818@@ -5286,7 +5286,7 @@ static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
40819 return true;
40820 }
40821
40822-static struct ata_port_operations ipr_sata_ops = {
40823+static const struct ata_port_operations ipr_sata_ops = {
40824 .phy_reset = ipr_ata_phy_reset,
40825 .hardreset = ipr_sata_reset,
40826 .post_internal_cmd = ipr_ata_post_internal,
40827diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
40828index 4e49fbc..97907ff 100644
40829--- a/drivers/scsi/ips.h
40830+++ b/drivers/scsi/ips.h
40831@@ -1027,7 +1027,7 @@ typedef struct {
40832 int (*intr)(struct ips_ha *);
40833 void (*enableint)(struct ips_ha *);
40834 uint32_t (*statupd)(struct ips_ha *);
40835-} ips_hw_func_t;
40836+} __no_const ips_hw_func_t;
40837
40838 typedef struct ips_ha {
40839 uint8_t ha_id[IPS_MAX_CHANNELS+1];
40840diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
40841index c1c1574..a9c9348 100644
40842--- a/drivers/scsi/libfc/fc_exch.c
40843+++ b/drivers/scsi/libfc/fc_exch.c
40844@@ -86,12 +86,12 @@ struct fc_exch_mgr {
40845 * all together if not used XXX
40846 */
40847 struct {
40848- atomic_t no_free_exch;
40849- atomic_t no_free_exch_xid;
40850- atomic_t xid_not_found;
40851- atomic_t xid_busy;
40852- atomic_t seq_not_found;
40853- atomic_t non_bls_resp;
40854+ atomic_unchecked_t no_free_exch;
40855+ atomic_unchecked_t no_free_exch_xid;
40856+ atomic_unchecked_t xid_not_found;
40857+ atomic_unchecked_t xid_busy;
40858+ atomic_unchecked_t seq_not_found;
40859+ atomic_unchecked_t non_bls_resp;
40860 } stats;
40861 };
40862 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
40863@@ -510,7 +510,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
40864 /* allocate memory for exchange */
40865 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
40866 if (!ep) {
40867- atomic_inc(&mp->stats.no_free_exch);
40868+ atomic_inc_unchecked(&mp->stats.no_free_exch);
40869 goto out;
40870 }
40871 memset(ep, 0, sizeof(*ep));
40872@@ -557,7 +557,7 @@ out:
40873 return ep;
40874 err:
40875 spin_unlock_bh(&pool->lock);
40876- atomic_inc(&mp->stats.no_free_exch_xid);
40877+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
40878 mempool_free(ep, mp->ep_pool);
40879 return NULL;
40880 }
40881@@ -690,7 +690,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40882 xid = ntohs(fh->fh_ox_id); /* we originated exch */
40883 ep = fc_exch_find(mp, xid);
40884 if (!ep) {
40885- atomic_inc(&mp->stats.xid_not_found);
40886+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40887 reject = FC_RJT_OX_ID;
40888 goto out;
40889 }
40890@@ -720,7 +720,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40891 ep = fc_exch_find(mp, xid);
40892 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
40893 if (ep) {
40894- atomic_inc(&mp->stats.xid_busy);
40895+ atomic_inc_unchecked(&mp->stats.xid_busy);
40896 reject = FC_RJT_RX_ID;
40897 goto rel;
40898 }
40899@@ -731,7 +731,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40900 }
40901 xid = ep->xid; /* get our XID */
40902 } else if (!ep) {
40903- atomic_inc(&mp->stats.xid_not_found);
40904+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40905 reject = FC_RJT_RX_ID; /* XID not found */
40906 goto out;
40907 }
40908@@ -752,7 +752,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40909 } else {
40910 sp = &ep->seq;
40911 if (sp->id != fh->fh_seq_id) {
40912- atomic_inc(&mp->stats.seq_not_found);
40913+ atomic_inc_unchecked(&mp->stats.seq_not_found);
40914 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
40915 goto rel;
40916 }
40917@@ -1163,22 +1163,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40918
40919 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
40920 if (!ep) {
40921- atomic_inc(&mp->stats.xid_not_found);
40922+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40923 goto out;
40924 }
40925 if (ep->esb_stat & ESB_ST_COMPLETE) {
40926- atomic_inc(&mp->stats.xid_not_found);
40927+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40928 goto out;
40929 }
40930 if (ep->rxid == FC_XID_UNKNOWN)
40931 ep->rxid = ntohs(fh->fh_rx_id);
40932 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
40933- atomic_inc(&mp->stats.xid_not_found);
40934+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40935 goto rel;
40936 }
40937 if (ep->did != ntoh24(fh->fh_s_id) &&
40938 ep->did != FC_FID_FLOGI) {
40939- atomic_inc(&mp->stats.xid_not_found);
40940+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40941 goto rel;
40942 }
40943 sof = fr_sof(fp);
40944@@ -1189,7 +1189,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40945 } else {
40946 sp = &ep->seq;
40947 if (sp->id != fh->fh_seq_id) {
40948- atomic_inc(&mp->stats.seq_not_found);
40949+ atomic_inc_unchecked(&mp->stats.seq_not_found);
40950 goto rel;
40951 }
40952 }
40953@@ -1249,9 +1249,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40954 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
40955
40956 if (!sp)
40957- atomic_inc(&mp->stats.xid_not_found);
40958+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40959 else
40960- atomic_inc(&mp->stats.non_bls_resp);
40961+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
40962
40963 fc_frame_free(fp);
40964 }
40965diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
40966index 0ee989f..a582241 100644
40967--- a/drivers/scsi/libsas/sas_ata.c
40968+++ b/drivers/scsi/libsas/sas_ata.c
40969@@ -343,7 +343,7 @@ static int sas_ata_scr_read(struct ata_link *link, unsigned int sc_reg_in,
40970 }
40971 }
40972
40973-static struct ata_port_operations sas_sata_ops = {
40974+static const struct ata_port_operations sas_sata_ops = {
40975 .phy_reset = sas_ata_phy_reset,
40976 .post_internal_cmd = sas_ata_post_internal,
40977 .qc_defer = ata_std_qc_defer,
40978diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
40979index aa10f79..5cc79e4 100644
40980--- a/drivers/scsi/lpfc/lpfc.h
40981+++ b/drivers/scsi/lpfc/lpfc.h
40982@@ -400,7 +400,7 @@ struct lpfc_vport {
40983 struct dentry *debug_nodelist;
40984 struct dentry *vport_debugfs_root;
40985 struct lpfc_debugfs_trc *disc_trc;
40986- atomic_t disc_trc_cnt;
40987+ atomic_unchecked_t disc_trc_cnt;
40988 #endif
40989 uint8_t stat_data_enabled;
40990 uint8_t stat_data_blocked;
40991@@ -725,8 +725,8 @@ struct lpfc_hba {
40992 struct timer_list fabric_block_timer;
40993 unsigned long bit_flags;
40994 #define FABRIC_COMANDS_BLOCKED 0
40995- atomic_t num_rsrc_err;
40996- atomic_t num_cmd_success;
40997+ atomic_unchecked_t num_rsrc_err;
40998+ atomic_unchecked_t num_cmd_success;
40999 unsigned long last_rsrc_error_time;
41000 unsigned long last_ramp_down_time;
41001 unsigned long last_ramp_up_time;
41002@@ -740,7 +740,7 @@ struct lpfc_hba {
41003 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
41004 struct dentry *debug_slow_ring_trc;
41005 struct lpfc_debugfs_trc *slow_ring_trc;
41006- atomic_t slow_ring_trc_cnt;
41007+ atomic_unchecked_t slow_ring_trc_cnt;
41008 #endif
41009
41010 /* Used for deferred freeing of ELS data buffers */
41011diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
41012index 8d0f0de..7c77a62 100644
41013--- a/drivers/scsi/lpfc/lpfc_debugfs.c
41014+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
41015@@ -124,7 +124,7 @@ struct lpfc_debug {
41016 int len;
41017 };
41018
41019-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41020+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41021 static unsigned long lpfc_debugfs_start_time = 0L;
41022
41023 /**
41024@@ -158,7 +158,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
41025 lpfc_debugfs_enable = 0;
41026
41027 len = 0;
41028- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
41029+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
41030 (lpfc_debugfs_max_disc_trc - 1);
41031 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
41032 dtp = vport->disc_trc + i;
41033@@ -219,7 +219,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
41034 lpfc_debugfs_enable = 0;
41035
41036 len = 0;
41037- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
41038+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
41039 (lpfc_debugfs_max_slow_ring_trc - 1);
41040 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
41041 dtp = phba->slow_ring_trc + i;
41042@@ -397,6 +397,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
41043 uint32_t *ptr;
41044 char buffer[1024];
41045
41046+ pax_track_stack();
41047+
41048 off = 0;
41049 spin_lock_irq(&phba->hbalock);
41050
41051@@ -634,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
41052 !vport || !vport->disc_trc)
41053 return;
41054
41055- index = atomic_inc_return(&vport->disc_trc_cnt) &
41056+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
41057 (lpfc_debugfs_max_disc_trc - 1);
41058 dtp = vport->disc_trc + index;
41059 dtp->fmt = fmt;
41060 dtp->data1 = data1;
41061 dtp->data2 = data2;
41062 dtp->data3 = data3;
41063- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41064+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41065 dtp->jif = jiffies;
41066 #endif
41067 return;
41068@@ -672,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
41069 !phba || !phba->slow_ring_trc)
41070 return;
41071
41072- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
41073+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
41074 (lpfc_debugfs_max_slow_ring_trc - 1);
41075 dtp = phba->slow_ring_trc + index;
41076 dtp->fmt = fmt;
41077 dtp->data1 = data1;
41078 dtp->data2 = data2;
41079 dtp->data3 = data3;
41080- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41081+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41082 dtp->jif = jiffies;
41083 #endif
41084 return;
41085@@ -1364,7 +1366,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41086 "slow_ring buffer\n");
41087 goto debug_failed;
41088 }
41089- atomic_set(&phba->slow_ring_trc_cnt, 0);
41090+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
41091 memset(phba->slow_ring_trc, 0,
41092 (sizeof(struct lpfc_debugfs_trc) *
41093 lpfc_debugfs_max_slow_ring_trc));
41094@@ -1410,7 +1412,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41095 "buffer\n");
41096 goto debug_failed;
41097 }
41098- atomic_set(&vport->disc_trc_cnt, 0);
41099+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
41100
41101 snprintf(name, sizeof(name), "discovery_trace");
41102 vport->debug_disc_trc =
41103diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
41104index 549bc7d..8189dbb 100644
41105--- a/drivers/scsi/lpfc/lpfc_init.c
41106+++ b/drivers/scsi/lpfc/lpfc_init.c
41107@@ -8021,8 +8021,10 @@ lpfc_init(void)
41108 printk(LPFC_COPYRIGHT "\n");
41109
41110 if (lpfc_enable_npiv) {
41111- lpfc_transport_functions.vport_create = lpfc_vport_create;
41112- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41113+ pax_open_kernel();
41114+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
41115+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41116+ pax_close_kernel();
41117 }
41118 lpfc_transport_template =
41119 fc_attach_transport(&lpfc_transport_functions);
41120diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
41121index c88f59f..ff2a42f 100644
41122--- a/drivers/scsi/lpfc/lpfc_scsi.c
41123+++ b/drivers/scsi/lpfc/lpfc_scsi.c
41124@@ -259,7 +259,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
41125 uint32_t evt_posted;
41126
41127 spin_lock_irqsave(&phba->hbalock, flags);
41128- atomic_inc(&phba->num_rsrc_err);
41129+ atomic_inc_unchecked(&phba->num_rsrc_err);
41130 phba->last_rsrc_error_time = jiffies;
41131
41132 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
41133@@ -300,7 +300,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
41134 unsigned long flags;
41135 struct lpfc_hba *phba = vport->phba;
41136 uint32_t evt_posted;
41137- atomic_inc(&phba->num_cmd_success);
41138+ atomic_inc_unchecked(&phba->num_cmd_success);
41139
41140 if (vport->cfg_lun_queue_depth <= queue_depth)
41141 return;
41142@@ -343,8 +343,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41143 int i;
41144 struct lpfc_rport_data *rdata;
41145
41146- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
41147- num_cmd_success = atomic_read(&phba->num_cmd_success);
41148+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
41149+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
41150
41151 vports = lpfc_create_vport_work_array(phba);
41152 if (vports != NULL)
41153@@ -378,8 +378,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41154 }
41155 }
41156 lpfc_destroy_vport_work_array(phba, vports);
41157- atomic_set(&phba->num_rsrc_err, 0);
41158- atomic_set(&phba->num_cmd_success, 0);
41159+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41160+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41161 }
41162
41163 /**
41164@@ -427,8 +427,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41165 }
41166 }
41167 lpfc_destroy_vport_work_array(phba, vports);
41168- atomic_set(&phba->num_rsrc_err, 0);
41169- atomic_set(&phba->num_cmd_success, 0);
41170+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41171+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41172 }
41173
41174 /**
41175diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
41176index 234f0b7..3020aea 100644
41177--- a/drivers/scsi/megaraid/megaraid_mbox.c
41178+++ b/drivers/scsi/megaraid/megaraid_mbox.c
41179@@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter)
41180 int rval;
41181 int i;
41182
41183+ pax_track_stack();
41184+
41185 // Allocate memory for the base list of scb for management module.
41186 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
41187
41188diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
41189index 7a117c1..ee01e9e 100644
41190--- a/drivers/scsi/osd/osd_initiator.c
41191+++ b/drivers/scsi/osd/osd_initiator.c
41192@@ -94,6 +94,8 @@ static int _osd_print_system_info(struct osd_dev *od, void *caps)
41193 int nelem = ARRAY_SIZE(get_attrs), a = 0;
41194 int ret;
41195
41196+ pax_track_stack();
41197+
41198 or = osd_start_request(od, GFP_KERNEL);
41199 if (!or)
41200 return -ENOMEM;
41201diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41202index 9ab8c86..9425ad3 100644
41203--- a/drivers/scsi/pmcraid.c
41204+++ b/drivers/scsi/pmcraid.c
41205@@ -189,8 +189,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41206 res->scsi_dev = scsi_dev;
41207 scsi_dev->hostdata = res;
41208 res->change_detected = 0;
41209- atomic_set(&res->read_failures, 0);
41210- atomic_set(&res->write_failures, 0);
41211+ atomic_set_unchecked(&res->read_failures, 0);
41212+ atomic_set_unchecked(&res->write_failures, 0);
41213 rc = 0;
41214 }
41215 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41216@@ -2396,9 +2396,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41217
41218 /* If this was a SCSI read/write command keep count of errors */
41219 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41220- atomic_inc(&res->read_failures);
41221+ atomic_inc_unchecked(&res->read_failures);
41222 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41223- atomic_inc(&res->write_failures);
41224+ atomic_inc_unchecked(&res->write_failures);
41225
41226 if (!RES_IS_GSCSI(res->cfg_entry) &&
41227 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41228@@ -4116,7 +4116,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41229
41230 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41231 /* add resources only after host is added into system */
41232- if (!atomic_read(&pinstance->expose_resources))
41233+ if (!atomic_read_unchecked(&pinstance->expose_resources))
41234 return;
41235
41236 spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
41237@@ -4850,7 +4850,7 @@ static int __devinit pmcraid_init_instance(
41238 init_waitqueue_head(&pinstance->reset_wait_q);
41239
41240 atomic_set(&pinstance->outstanding_cmds, 0);
41241- atomic_set(&pinstance->expose_resources, 0);
41242+ atomic_set_unchecked(&pinstance->expose_resources, 0);
41243
41244 INIT_LIST_HEAD(&pinstance->free_res_q);
41245 INIT_LIST_HEAD(&pinstance->used_res_q);
41246@@ -5502,7 +5502,7 @@ static int __devinit pmcraid_probe(
41247 /* Schedule worker thread to handle CCN and take care of adding and
41248 * removing devices to OS
41249 */
41250- atomic_set(&pinstance->expose_resources, 1);
41251+ atomic_set_unchecked(&pinstance->expose_resources, 1);
41252 schedule_work(&pinstance->worker_q);
41253 return rc;
41254
41255diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41256index 3441b3f..6cbe8f7 100644
41257--- a/drivers/scsi/pmcraid.h
41258+++ b/drivers/scsi/pmcraid.h
41259@@ -690,7 +690,7 @@ struct pmcraid_instance {
41260 atomic_t outstanding_cmds;
41261
41262 /* should add/delete resources to mid-layer now ?*/
41263- atomic_t expose_resources;
41264+ atomic_unchecked_t expose_resources;
41265
41266 /* Tasklet to handle deferred processing */
41267 struct tasklet_struct isr_tasklet[PMCRAID_NUM_MSIX_VECTORS];
41268@@ -727,8 +727,8 @@ struct pmcraid_resource_entry {
41269 struct list_head queue; /* link to "to be exposed" resources */
41270 struct pmcraid_config_table_entry cfg_entry;
41271 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41272- atomic_t read_failures; /* count of failed READ commands */
41273- atomic_t write_failures; /* count of failed WRITE commands */
41274+ atomic_unchecked_t read_failures; /* count of failed READ commands */
41275+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41276
41277 /* To indicate add/delete/modify during CCN */
41278 u8 change_detected;
41279diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
41280index 2150618..7034215 100644
41281--- a/drivers/scsi/qla2xxx/qla_def.h
41282+++ b/drivers/scsi/qla2xxx/qla_def.h
41283@@ -2089,7 +2089,7 @@ struct isp_operations {
41284
41285 int (*get_flash_version) (struct scsi_qla_host *, void *);
41286 int (*start_scsi) (srb_t *);
41287-};
41288+} __no_const;
41289
41290 /* MSI-X Support *************************************************************/
41291
41292diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41293index 81b5f29..2ae1fad 100644
41294--- a/drivers/scsi/qla4xxx/ql4_def.h
41295+++ b/drivers/scsi/qla4xxx/ql4_def.h
41296@@ -240,7 +240,7 @@ struct ddb_entry {
41297 atomic_t retry_relogin_timer; /* Min Time between relogins
41298 * (4000 only) */
41299 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
41300- atomic_t relogin_retry_count; /* Num of times relogin has been
41301+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41302 * retried */
41303
41304 uint16_t port;
41305diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
41306index af8c323..515dd51 100644
41307--- a/drivers/scsi/qla4xxx/ql4_init.c
41308+++ b/drivers/scsi/qla4xxx/ql4_init.c
41309@@ -482,7 +482,7 @@ static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
41310 atomic_set(&ddb_entry->port_down_timer, ha->port_down_retry_count);
41311 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41312 atomic_set(&ddb_entry->relogin_timer, 0);
41313- atomic_set(&ddb_entry->relogin_retry_count, 0);
41314+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41315 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
41316 list_add_tail(&ddb_entry->list, &ha->ddb_list);
41317 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
41318@@ -1308,7 +1308,7 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha,
41319 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
41320 atomic_set(&ddb_entry->port_down_timer,
41321 ha->port_down_retry_count);
41322- atomic_set(&ddb_entry->relogin_retry_count, 0);
41323+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41324 atomic_set(&ddb_entry->relogin_timer, 0);
41325 clear_bit(DF_RELOGIN, &ddb_entry->flags);
41326 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
41327diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41328index 83c8b5e..a82b348 100644
41329--- a/drivers/scsi/qla4xxx/ql4_os.c
41330+++ b/drivers/scsi/qla4xxx/ql4_os.c
41331@@ -641,13 +641,13 @@ static void qla4xxx_timer(struct scsi_qla_host *ha)
41332 ddb_entry->fw_ddb_device_state ==
41333 DDB_DS_SESSION_FAILED) {
41334 /* Reset retry relogin timer */
41335- atomic_inc(&ddb_entry->relogin_retry_count);
41336+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41337 DEBUG2(printk("scsi%ld: index[%d] relogin"
41338 " timed out-retrying"
41339 " relogin (%d)\n",
41340 ha->host_no,
41341 ddb_entry->fw_ddb_index,
41342- atomic_read(&ddb_entry->
41343+ atomic_read_unchecked(&ddb_entry->
41344 relogin_retry_count))
41345 );
41346 start_dpc++;
41347diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41348index dd098ca..686ce01 100644
41349--- a/drivers/scsi/scsi.c
41350+++ b/drivers/scsi/scsi.c
41351@@ -652,7 +652,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41352 unsigned long timeout;
41353 int rtn = 0;
41354
41355- atomic_inc(&cmd->device->iorequest_cnt);
41356+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41357
41358 /* check if the device is still usable */
41359 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41360diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
41361index bc3e363..e1a8e50 100644
41362--- a/drivers/scsi/scsi_debug.c
41363+++ b/drivers/scsi/scsi_debug.c
41364@@ -1395,6 +1395,8 @@ static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
41365 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
41366 unsigned char *cmd = (unsigned char *)scp->cmnd;
41367
41368+ pax_track_stack();
41369+
41370 if ((errsts = check_readiness(scp, 1, devip)))
41371 return errsts;
41372 memset(arr, 0, sizeof(arr));
41373@@ -1492,6 +1494,8 @@ static int resp_log_sense(struct scsi_cmnd * scp,
41374 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
41375 unsigned char *cmd = (unsigned char *)scp->cmnd;
41376
41377+ pax_track_stack();
41378+
41379 if ((errsts = check_readiness(scp, 1, devip)))
41380 return errsts;
41381 memset(arr, 0, sizeof(arr));
41382diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41383index 8df12522..c4c1472 100644
41384--- a/drivers/scsi/scsi_lib.c
41385+++ b/drivers/scsi/scsi_lib.c
41386@@ -1389,7 +1389,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41387 shost = sdev->host;
41388 scsi_init_cmd_errh(cmd);
41389 cmd->result = DID_NO_CONNECT << 16;
41390- atomic_inc(&cmd->device->iorequest_cnt);
41391+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41392
41393 /*
41394 * SCSI request completion path will do scsi_device_unbusy(),
41395@@ -1420,9 +1420,9 @@ static void scsi_softirq_done(struct request *rq)
41396 */
41397 cmd->serial_number = 0;
41398
41399- atomic_inc(&cmd->device->iodone_cnt);
41400+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
41401 if (cmd->result)
41402- atomic_inc(&cmd->device->ioerr_cnt);
41403+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41404
41405 disposition = scsi_decide_disposition(cmd);
41406 if (disposition != SUCCESS &&
41407diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41408index 91a93e0..eae0fe3 100644
41409--- a/drivers/scsi/scsi_sysfs.c
41410+++ b/drivers/scsi/scsi_sysfs.c
41411@@ -662,7 +662,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41412 char *buf) \
41413 { \
41414 struct scsi_device *sdev = to_scsi_device(dev); \
41415- unsigned long long count = atomic_read(&sdev->field); \
41416+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
41417 return snprintf(buf, 20, "0x%llx\n", count); \
41418 } \
41419 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41420diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41421index 1030327..f91fd30 100644
41422--- a/drivers/scsi/scsi_tgt_lib.c
41423+++ b/drivers/scsi/scsi_tgt_lib.c
41424@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41425 int err;
41426
41427 dprintk("%lx %u\n", uaddr, len);
41428- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41429+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41430 if (err) {
41431 /*
41432 * TODO: need to fixup sg_tablesize, max_segment_size,
41433diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41434index db02e31..1b42ea9 100644
41435--- a/drivers/scsi/scsi_transport_fc.c
41436+++ b/drivers/scsi/scsi_transport_fc.c
41437@@ -480,7 +480,7 @@ MODULE_PARM_DESC(dev_loss_tmo,
41438 * Netlink Infrastructure
41439 */
41440
41441-static atomic_t fc_event_seq;
41442+static atomic_unchecked_t fc_event_seq;
41443
41444 /**
41445 * fc_get_event_number - Obtain the next sequential FC event number
41446@@ -493,7 +493,7 @@ static atomic_t fc_event_seq;
41447 u32
41448 fc_get_event_number(void)
41449 {
41450- return atomic_add_return(1, &fc_event_seq);
41451+ return atomic_add_return_unchecked(1, &fc_event_seq);
41452 }
41453 EXPORT_SYMBOL(fc_get_event_number);
41454
41455@@ -641,7 +641,7 @@ static __init int fc_transport_init(void)
41456 {
41457 int error;
41458
41459- atomic_set(&fc_event_seq, 0);
41460+ atomic_set_unchecked(&fc_event_seq, 0);
41461
41462 error = transport_class_register(&fc_host_class);
41463 if (error)
41464diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
41465index de2f8c4..63c5278 100644
41466--- a/drivers/scsi/scsi_transport_iscsi.c
41467+++ b/drivers/scsi/scsi_transport_iscsi.c
41468@@ -81,7 +81,7 @@ struct iscsi_internal {
41469 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
41470 };
41471
41472-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
41473+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
41474 static struct workqueue_struct *iscsi_eh_timer_workq;
41475
41476 /*
41477@@ -728,7 +728,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
41478 int err;
41479
41480 ihost = shost->shost_data;
41481- session->sid = atomic_add_return(1, &iscsi_session_nr);
41482+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
41483
41484 if (id == ISCSI_MAX_TARGET) {
41485 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
41486@@ -2060,7 +2060,7 @@ static __init int iscsi_transport_init(void)
41487 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
41488 ISCSI_TRANSPORT_VERSION);
41489
41490- atomic_set(&iscsi_session_nr, 0);
41491+ atomic_set_unchecked(&iscsi_session_nr, 0);
41492
41493 err = class_register(&iscsi_transport_class);
41494 if (err)
41495diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
41496index 21a045e..ec89e03 100644
41497--- a/drivers/scsi/scsi_transport_srp.c
41498+++ b/drivers/scsi/scsi_transport_srp.c
41499@@ -33,7 +33,7 @@
41500 #include "scsi_transport_srp_internal.h"
41501
41502 struct srp_host_attrs {
41503- atomic_t next_port_id;
41504+ atomic_unchecked_t next_port_id;
41505 };
41506 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
41507
41508@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
41509 struct Scsi_Host *shost = dev_to_shost(dev);
41510 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
41511
41512- atomic_set(&srp_host->next_port_id, 0);
41513+ atomic_set_unchecked(&srp_host->next_port_id, 0);
41514 return 0;
41515 }
41516
41517@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
41518 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
41519 rport->roles = ids->roles;
41520
41521- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
41522+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
41523 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
41524
41525 transport_setup_device(&rport->dev);
41526diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
41527index 2dd1b73..fd8145f 100644
41528--- a/drivers/scsi/sd.c
41529+++ b/drivers/scsi/sd.c
41530@@ -817,6 +817,10 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,
41531 SCSI_LOG_IOCTL(1, printk("sd_ioctl: disk=%s, cmd=0x%x\n",
41532 disk->disk_name, cmd));
41533
41534+ error = scsi_verify_blk_ioctl(bdev, cmd);
41535+ if (error < 0)
41536+ return error;
41537+
41538 /*
41539 * If we are in the middle of error recovery, don't let anyone
41540 * else try and use this device. Also, if error recovery fails, it
41541@@ -996,6 +1000,11 @@ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
41542 unsigned int cmd, unsigned long arg)
41543 {
41544 struct scsi_device *sdev = scsi_disk(bdev->bd_disk)->device;
41545+ int ret;
41546+
41547+ ret = scsi_verify_blk_ioctl(bdev, cmd);
41548+ if (ret < 0)
41549+ return ret;
41550
41551 /*
41552 * If we are in the middle of error recovery, don't let anyone
41553@@ -1007,8 +1016,6 @@ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
41554 return -ENODEV;
41555
41556 if (sdev->host->hostt->compat_ioctl) {
41557- int ret;
41558-
41559 ret = sdev->host->hostt->compat_ioctl(sdev, cmd, (void __user *)arg);
41560
41561 return ret;
41562diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
41563index 040f751..98a5ed2 100644
41564--- a/drivers/scsi/sg.c
41565+++ b/drivers/scsi/sg.c
41566@@ -1064,7 +1064,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
41567 sdp->disk->disk_name,
41568 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
41569 NULL,
41570- (char *)arg);
41571+ (char __user *)arg);
41572 case BLKTRACESTART:
41573 return blk_trace_startstop(sdp->device->request_queue, 1);
41574 case BLKTRACESTOP:
41575@@ -2292,7 +2292,7 @@ struct sg_proc_leaf {
41576 const struct file_operations * fops;
41577 };
41578
41579-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
41580+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
41581 {"allow_dio", &adio_fops},
41582 {"debug", &debug_fops},
41583 {"def_reserved_size", &dressz_fops},
41584@@ -2307,7 +2307,7 @@ sg_proc_init(void)
41585 {
41586 int k, mask;
41587 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
41588- struct sg_proc_leaf * leaf;
41589+ const struct sg_proc_leaf * leaf;
41590
41591 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
41592 if (!sg_proc_sgp)
41593diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
41594index c19ca5e..3eb5959 100644
41595--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
41596+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
41597@@ -1758,6 +1758,8 @@ static int __devinit sym2_probe(struct pci_dev *pdev,
41598 int do_iounmap = 0;
41599 int do_disable_device = 1;
41600
41601+ pax_track_stack();
41602+
41603 memset(&sym_dev, 0, sizeof(sym_dev));
41604 memset(&nvram, 0, sizeof(nvram));
41605 sym_dev.pdev = pdev;
41606diff --git a/drivers/serial/kgdboc.c b/drivers/serial/kgdboc.c
41607index eadc1ab..2d81457 100644
41608--- a/drivers/serial/kgdboc.c
41609+++ b/drivers/serial/kgdboc.c
41610@@ -18,7 +18,7 @@
41611
41612 #define MAX_CONFIG_LEN 40
41613
41614-static struct kgdb_io kgdboc_io_ops;
41615+static const struct kgdb_io kgdboc_io_ops;
41616
41617 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
41618 static int configured = -1;
41619@@ -154,7 +154,7 @@ static void kgdboc_post_exp_handler(void)
41620 module_put(THIS_MODULE);
41621 }
41622
41623-static struct kgdb_io kgdboc_io_ops = {
41624+static const struct kgdb_io kgdboc_io_ops = {
41625 .name = "kgdboc",
41626 .read_char = kgdboc_get_char,
41627 .write_char = kgdboc_put_char,
41628diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
41629index b76f246..7f41af7 100644
41630--- a/drivers/spi/spi.c
41631+++ b/drivers/spi/spi.c
41632@@ -774,7 +774,7 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
41633 EXPORT_SYMBOL_GPL(spi_sync);
41634
41635 /* portable code must never pass more than 32 bytes */
41636-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
41637+#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
41638
41639 static u8 *buf;
41640
41641diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
41642index 99010d4..6bad87b 100644
41643--- a/drivers/staging/android/binder.c
41644+++ b/drivers/staging/android/binder.c
41645@@ -2756,7 +2756,7 @@ static void binder_vma_close(struct vm_area_struct *vma)
41646 binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
41647 }
41648
41649-static struct vm_operations_struct binder_vm_ops = {
41650+static const struct vm_operations_struct binder_vm_ops = {
41651 .open = binder_vma_open,
41652 .close = binder_vma_close,
41653 };
41654diff --git a/drivers/staging/b3dfg/b3dfg.c b/drivers/staging/b3dfg/b3dfg.c
41655index cda26bb..39fed3f 100644
41656--- a/drivers/staging/b3dfg/b3dfg.c
41657+++ b/drivers/staging/b3dfg/b3dfg.c
41658@@ -455,7 +455,7 @@ static int b3dfg_vma_fault(struct vm_area_struct *vma,
41659 return VM_FAULT_NOPAGE;
41660 }
41661
41662-static struct vm_operations_struct b3dfg_vm_ops = {
41663+static const struct vm_operations_struct b3dfg_vm_ops = {
41664 .fault = b3dfg_vma_fault,
41665 };
41666
41667@@ -848,7 +848,7 @@ static int b3dfg_mmap(struct file *filp, struct vm_area_struct *vma)
41668 return r;
41669 }
41670
41671-static struct file_operations b3dfg_fops = {
41672+static const struct file_operations b3dfg_fops = {
41673 .owner = THIS_MODULE,
41674 .open = b3dfg_open,
41675 .release = b3dfg_release,
41676diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
41677index 908f25a..c9a579b 100644
41678--- a/drivers/staging/comedi/comedi_fops.c
41679+++ b/drivers/staging/comedi/comedi_fops.c
41680@@ -1389,7 +1389,7 @@ void comedi_unmap(struct vm_area_struct *area)
41681 mutex_unlock(&dev->mutex);
41682 }
41683
41684-static struct vm_operations_struct comedi_vm_ops = {
41685+static const struct vm_operations_struct comedi_vm_ops = {
41686 .close = comedi_unmap,
41687 };
41688
41689diff --git a/drivers/staging/dream/qdsp5/adsp_driver.c b/drivers/staging/dream/qdsp5/adsp_driver.c
41690index e55a0db..577b776 100644
41691--- a/drivers/staging/dream/qdsp5/adsp_driver.c
41692+++ b/drivers/staging/dream/qdsp5/adsp_driver.c
41693@@ -576,7 +576,7 @@ static struct adsp_device *inode_to_device(struct inode *inode)
41694 static dev_t adsp_devno;
41695 static struct class *adsp_class;
41696
41697-static struct file_operations adsp_fops = {
41698+static const struct file_operations adsp_fops = {
41699 .owner = THIS_MODULE,
41700 .open = adsp_open,
41701 .unlocked_ioctl = adsp_ioctl,
41702diff --git a/drivers/staging/dream/qdsp5/audio_aac.c b/drivers/staging/dream/qdsp5/audio_aac.c
41703index ad2390f..4116ee8 100644
41704--- a/drivers/staging/dream/qdsp5/audio_aac.c
41705+++ b/drivers/staging/dream/qdsp5/audio_aac.c
41706@@ -1022,7 +1022,7 @@ done:
41707 return rc;
41708 }
41709
41710-static struct file_operations audio_aac_fops = {
41711+static const struct file_operations audio_aac_fops = {
41712 .owner = THIS_MODULE,
41713 .open = audio_open,
41714 .release = audio_release,
41715diff --git a/drivers/staging/dream/qdsp5/audio_amrnb.c b/drivers/staging/dream/qdsp5/audio_amrnb.c
41716index cd818a5..870b37b 100644
41717--- a/drivers/staging/dream/qdsp5/audio_amrnb.c
41718+++ b/drivers/staging/dream/qdsp5/audio_amrnb.c
41719@@ -833,7 +833,7 @@ done:
41720 return rc;
41721 }
41722
41723-static struct file_operations audio_amrnb_fops = {
41724+static const struct file_operations audio_amrnb_fops = {
41725 .owner = THIS_MODULE,
41726 .open = audamrnb_open,
41727 .release = audamrnb_release,
41728diff --git a/drivers/staging/dream/qdsp5/audio_evrc.c b/drivers/staging/dream/qdsp5/audio_evrc.c
41729index 4b43e18..cedafda 100644
41730--- a/drivers/staging/dream/qdsp5/audio_evrc.c
41731+++ b/drivers/staging/dream/qdsp5/audio_evrc.c
41732@@ -805,7 +805,7 @@ dma_fail:
41733 return rc;
41734 }
41735
41736-static struct file_operations audio_evrc_fops = {
41737+static const struct file_operations audio_evrc_fops = {
41738 .owner = THIS_MODULE,
41739 .open = audevrc_open,
41740 .release = audevrc_release,
41741diff --git a/drivers/staging/dream/qdsp5/audio_in.c b/drivers/staging/dream/qdsp5/audio_in.c
41742index 3d950a2..9431118 100644
41743--- a/drivers/staging/dream/qdsp5/audio_in.c
41744+++ b/drivers/staging/dream/qdsp5/audio_in.c
41745@@ -913,7 +913,7 @@ static int audpre_open(struct inode *inode, struct file *file)
41746 return 0;
41747 }
41748
41749-static struct file_operations audio_fops = {
41750+static const struct file_operations audio_fops = {
41751 .owner = THIS_MODULE,
41752 .open = audio_in_open,
41753 .release = audio_in_release,
41754@@ -922,7 +922,7 @@ static struct file_operations audio_fops = {
41755 .unlocked_ioctl = audio_in_ioctl,
41756 };
41757
41758-static struct file_operations audpre_fops = {
41759+static const struct file_operations audpre_fops = {
41760 .owner = THIS_MODULE,
41761 .open = audpre_open,
41762 .unlocked_ioctl = audpre_ioctl,
41763diff --git a/drivers/staging/dream/qdsp5/audio_mp3.c b/drivers/staging/dream/qdsp5/audio_mp3.c
41764index b95574f..286c2f4 100644
41765--- a/drivers/staging/dream/qdsp5/audio_mp3.c
41766+++ b/drivers/staging/dream/qdsp5/audio_mp3.c
41767@@ -941,7 +941,7 @@ done:
41768 return rc;
41769 }
41770
41771-static struct file_operations audio_mp3_fops = {
41772+static const struct file_operations audio_mp3_fops = {
41773 .owner = THIS_MODULE,
41774 .open = audio_open,
41775 .release = audio_release,
41776diff --git a/drivers/staging/dream/qdsp5/audio_out.c b/drivers/staging/dream/qdsp5/audio_out.c
41777index d1adcf6..f8f9833 100644
41778--- a/drivers/staging/dream/qdsp5/audio_out.c
41779+++ b/drivers/staging/dream/qdsp5/audio_out.c
41780@@ -810,7 +810,7 @@ static int audpp_open(struct inode *inode, struct file *file)
41781 return 0;
41782 }
41783
41784-static struct file_operations audio_fops = {
41785+static const struct file_operations audio_fops = {
41786 .owner = THIS_MODULE,
41787 .open = audio_open,
41788 .release = audio_release,
41789@@ -819,7 +819,7 @@ static struct file_operations audio_fops = {
41790 .unlocked_ioctl = audio_ioctl,
41791 };
41792
41793-static struct file_operations audpp_fops = {
41794+static const struct file_operations audpp_fops = {
41795 .owner = THIS_MODULE,
41796 .open = audpp_open,
41797 .unlocked_ioctl = audpp_ioctl,
41798diff --git a/drivers/staging/dream/qdsp5/audio_qcelp.c b/drivers/staging/dream/qdsp5/audio_qcelp.c
41799index f0f50e3..f6b9dbc 100644
41800--- a/drivers/staging/dream/qdsp5/audio_qcelp.c
41801+++ b/drivers/staging/dream/qdsp5/audio_qcelp.c
41802@@ -816,7 +816,7 @@ err:
41803 return rc;
41804 }
41805
41806-static struct file_operations audio_qcelp_fops = {
41807+static const struct file_operations audio_qcelp_fops = {
41808 .owner = THIS_MODULE,
41809 .open = audqcelp_open,
41810 .release = audqcelp_release,
41811diff --git a/drivers/staging/dream/qdsp5/snd.c b/drivers/staging/dream/qdsp5/snd.c
41812index 037d7ff..5469ec3 100644
41813--- a/drivers/staging/dream/qdsp5/snd.c
41814+++ b/drivers/staging/dream/qdsp5/snd.c
41815@@ -242,7 +242,7 @@ err:
41816 return rc;
41817 }
41818
41819-static struct file_operations snd_fops = {
41820+static const struct file_operations snd_fops = {
41821 .owner = THIS_MODULE,
41822 .open = snd_open,
41823 .release = snd_release,
41824diff --git a/drivers/staging/dream/smd/smd_qmi.c b/drivers/staging/dream/smd/smd_qmi.c
41825index d4e7d88..0ea632a 100644
41826--- a/drivers/staging/dream/smd/smd_qmi.c
41827+++ b/drivers/staging/dream/smd/smd_qmi.c
41828@@ -793,7 +793,7 @@ static int qmi_release(struct inode *ip, struct file *fp)
41829 return 0;
41830 }
41831
41832-static struct file_operations qmi_fops = {
41833+static const struct file_operations qmi_fops = {
41834 .owner = THIS_MODULE,
41835 .read = qmi_read,
41836 .write = qmi_write,
41837diff --git a/drivers/staging/dream/smd/smd_rpcrouter_device.c b/drivers/staging/dream/smd/smd_rpcrouter_device.c
41838index cd3910b..ff053d3 100644
41839--- a/drivers/staging/dream/smd/smd_rpcrouter_device.c
41840+++ b/drivers/staging/dream/smd/smd_rpcrouter_device.c
41841@@ -214,7 +214,7 @@ static long rpcrouter_ioctl(struct file *filp, unsigned int cmd,
41842 return rc;
41843 }
41844
41845-static struct file_operations rpcrouter_server_fops = {
41846+static const struct file_operations rpcrouter_server_fops = {
41847 .owner = THIS_MODULE,
41848 .open = rpcrouter_open,
41849 .release = rpcrouter_release,
41850@@ -224,7 +224,7 @@ static struct file_operations rpcrouter_server_fops = {
41851 .unlocked_ioctl = rpcrouter_ioctl,
41852 };
41853
41854-static struct file_operations rpcrouter_router_fops = {
41855+static const struct file_operations rpcrouter_router_fops = {
41856 .owner = THIS_MODULE,
41857 .open = rpcrouter_open,
41858 .release = rpcrouter_release,
41859diff --git a/drivers/staging/dst/dcore.c b/drivers/staging/dst/dcore.c
41860index c24e4e0..07665be 100644
41861--- a/drivers/staging/dst/dcore.c
41862+++ b/drivers/staging/dst/dcore.c
41863@@ -149,7 +149,7 @@ static int dst_bdev_release(struct gendisk *disk, fmode_t mode)
41864 return 0;
41865 }
41866
41867-static struct block_device_operations dst_blk_ops = {
41868+static const struct block_device_operations dst_blk_ops = {
41869 .open = dst_bdev_open,
41870 .release = dst_bdev_release,
41871 .owner = THIS_MODULE,
41872@@ -588,7 +588,7 @@ static struct dst_node *dst_alloc_node(struct dst_ctl *ctl,
41873 n->size = ctl->size;
41874
41875 atomic_set(&n->refcnt, 1);
41876- atomic_long_set(&n->gen, 0);
41877+ atomic_long_set_unchecked(&n->gen, 0);
41878 snprintf(n->name, sizeof(n->name), "%s", ctl->name);
41879
41880 err = dst_node_sysfs_init(n);
41881diff --git a/drivers/staging/dst/trans.c b/drivers/staging/dst/trans.c
41882index 557d372..8d84422 100644
41883--- a/drivers/staging/dst/trans.c
41884+++ b/drivers/staging/dst/trans.c
41885@@ -169,7 +169,7 @@ int dst_process_bio(struct dst_node *n, struct bio *bio)
41886 t->error = 0;
41887 t->retries = 0;
41888 atomic_set(&t->refcnt, 1);
41889- t->gen = atomic_long_inc_return(&n->gen);
41890+ t->gen = atomic_long_inc_return_unchecked(&n->gen);
41891
41892 t->enc = bio_data_dir(bio);
41893 dst_bio_to_cmd(bio, &t->cmd, DST_IO, t->gen);
41894diff --git a/drivers/staging/et131x/et1310_tx.c b/drivers/staging/et131x/et1310_tx.c
41895index 94f7752..d051514 100644
41896--- a/drivers/staging/et131x/et1310_tx.c
41897+++ b/drivers/staging/et131x/et1310_tx.c
41898@@ -710,11 +710,11 @@ inline void et131x_free_send_packet(struct et131x_adapter *etdev,
41899 struct net_device_stats *stats = &etdev->net_stats;
41900
41901 if (pMpTcb->Flags & fMP_DEST_BROAD)
41902- atomic_inc(&etdev->Stats.brdcstxmt);
41903+ atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
41904 else if (pMpTcb->Flags & fMP_DEST_MULTI)
41905- atomic_inc(&etdev->Stats.multixmt);
41906+ atomic_inc_unchecked(&etdev->Stats.multixmt);
41907 else
41908- atomic_inc(&etdev->Stats.unixmt);
41909+ atomic_inc_unchecked(&etdev->Stats.unixmt);
41910
41911 if (pMpTcb->Packet) {
41912 stats->tx_bytes += pMpTcb->Packet->len;
41913diff --git a/drivers/staging/et131x/et131x_adapter.h b/drivers/staging/et131x/et131x_adapter.h
41914index 1dfe06f..f469b4d 100644
41915--- a/drivers/staging/et131x/et131x_adapter.h
41916+++ b/drivers/staging/et131x/et131x_adapter.h
41917@@ -145,11 +145,11 @@ typedef struct _ce_stats_t {
41918 * operations
41919 */
41920 u32 unircv; /* # multicast packets received */
41921- atomic_t unixmt; /* # multicast packets for Tx */
41922+ atomic_unchecked_t unixmt; /* # multicast packets for Tx */
41923 u32 multircv; /* # multicast packets received */
41924- atomic_t multixmt; /* # multicast packets for Tx */
41925+ atomic_unchecked_t multixmt; /* # multicast packets for Tx */
41926 u32 brdcstrcv; /* # broadcast packets received */
41927- atomic_t brdcstxmt; /* # broadcast packets for Tx */
41928+ atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
41929 u32 norcvbuf; /* # Rx packets discarded */
41930 u32 noxmtbuf; /* # Tx packets discarded */
41931
41932diff --git a/drivers/staging/go7007/go7007-v4l2.c b/drivers/staging/go7007/go7007-v4l2.c
41933index 4bd353a..e28f455 100644
41934--- a/drivers/staging/go7007/go7007-v4l2.c
41935+++ b/drivers/staging/go7007/go7007-v4l2.c
41936@@ -1700,7 +1700,7 @@ static int go7007_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41937 return 0;
41938 }
41939
41940-static struct vm_operations_struct go7007_vm_ops = {
41941+static const struct vm_operations_struct go7007_vm_ops = {
41942 .open = go7007_vm_open,
41943 .close = go7007_vm_close,
41944 .fault = go7007_vm_fault,
41945diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c
41946index 366dc95..b974d87 100644
41947--- a/drivers/staging/hv/Channel.c
41948+++ b/drivers/staging/hv/Channel.c
41949@@ -464,8 +464,8 @@ int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, void *Kbuffer,
41950
41951 DPRINT_ENTER(VMBUS);
41952
41953- nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
41954- atomic_inc(&gVmbusConnection.NextGpadlHandle);
41955+ nextGpadlHandle = atomic_read_unchecked(&gVmbusConnection.NextGpadlHandle);
41956+ atomic_inc_unchecked(&gVmbusConnection.NextGpadlHandle);
41957
41958 VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
41959 ASSERT(msgInfo != NULL);
41960diff --git a/drivers/staging/hv/Hv.c b/drivers/staging/hv/Hv.c
41961index b12237f..01ae28a 100644
41962--- a/drivers/staging/hv/Hv.c
41963+++ b/drivers/staging/hv/Hv.c
41964@@ -161,7 +161,7 @@ static u64 HvDoHypercall(u64 Control, void *Input, void *Output)
41965 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0;
41966 u32 outputAddressHi = outputAddress >> 32;
41967 u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
41968- volatile void *hypercallPage = gHvContext.HypercallPage;
41969+ volatile void *hypercallPage = ktva_ktla(gHvContext.HypercallPage);
41970
41971 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
41972 Control, Input, Output);
41973diff --git a/drivers/staging/hv/VmbusApi.h b/drivers/staging/hv/VmbusApi.h
41974index d089bb1..2ebc158 100644
41975--- a/drivers/staging/hv/VmbusApi.h
41976+++ b/drivers/staging/hv/VmbusApi.h
41977@@ -109,7 +109,7 @@ struct vmbus_channel_interface {
41978 u32 *GpadlHandle);
41979 int (*TeardownGpadl)(struct hv_device *device, u32 GpadlHandle);
41980 void (*GetInfo)(struct hv_device *dev, struct hv_device_info *devinfo);
41981-};
41982+} __no_const;
41983
41984 /* Base driver object */
41985 struct hv_driver {
41986diff --git a/drivers/staging/hv/VmbusPrivate.h b/drivers/staging/hv/VmbusPrivate.h
41987index 5a37cce..6ecc88c 100644
41988--- a/drivers/staging/hv/VmbusPrivate.h
41989+++ b/drivers/staging/hv/VmbusPrivate.h
41990@@ -59,7 +59,7 @@ enum VMBUS_CONNECT_STATE {
41991 struct VMBUS_CONNECTION {
41992 enum VMBUS_CONNECT_STATE ConnectState;
41993
41994- atomic_t NextGpadlHandle;
41995+ atomic_unchecked_t NextGpadlHandle;
41996
41997 /*
41998 * Represents channel interrupts. Each bit position represents a
41999diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
42000index 871a202..ca50ddf 100644
42001--- a/drivers/staging/hv/blkvsc_drv.c
42002+++ b/drivers/staging/hv/blkvsc_drv.c
42003@@ -153,7 +153,7 @@ static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
42004 /* The one and only one */
42005 static struct blkvsc_driver_context g_blkvsc_drv;
42006
42007-static struct block_device_operations block_ops = {
42008+static const struct block_device_operations block_ops = {
42009 .owner = THIS_MODULE,
42010 .open = blkvsc_open,
42011 .release = blkvsc_release,
42012diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
42013index 6acc49a..fbc8d46 100644
42014--- a/drivers/staging/hv/vmbus_drv.c
42015+++ b/drivers/staging/hv/vmbus_drv.c
42016@@ -532,7 +532,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
42017 to_device_context(root_device_obj);
42018 struct device_context *child_device_ctx =
42019 to_device_context(child_device_obj);
42020- static atomic_t device_num = ATOMIC_INIT(0);
42021+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42022
42023 DPRINT_ENTER(VMBUS_DRV);
42024
42025@@ -541,7 +541,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
42026
42027 /* Set the device name. Otherwise, device_register() will fail. */
42028 dev_set_name(&child_device_ctx->device, "vmbus_0_%d",
42029- atomic_inc_return(&device_num));
42030+ atomic_inc_return_unchecked(&device_num));
42031
42032 /* The new device belongs to this bus */
42033 child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */
42034diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h
42035index d926189..17b19fd 100644
42036--- a/drivers/staging/iio/ring_generic.h
42037+++ b/drivers/staging/iio/ring_generic.h
42038@@ -87,7 +87,7 @@ struct iio_ring_access_funcs {
42039
42040 int (*is_enabled)(struct iio_ring_buffer *ring);
42041 int (*enable)(struct iio_ring_buffer *ring);
42042-};
42043+} __no_const;
42044
42045 /**
42046 * struct iio_ring_buffer - general ring buffer structure
42047diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42048index 1b237b7..88c624e 100644
42049--- a/drivers/staging/octeon/ethernet-rx.c
42050+++ b/drivers/staging/octeon/ethernet-rx.c
42051@@ -406,11 +406,11 @@ void cvm_oct_tasklet_rx(unsigned long unused)
42052 /* Increment RX stats for virtual ports */
42053 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42054 #ifdef CONFIG_64BIT
42055- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42056- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42057+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42058+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42059 #else
42060- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42061- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42062+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42063+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42064 #endif
42065 }
42066 netif_receive_skb(skb);
42067@@ -424,9 +424,9 @@ void cvm_oct_tasklet_rx(unsigned long unused)
42068 dev->name);
42069 */
42070 #ifdef CONFIG_64BIT
42071- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42072+ atomic64_add_unchecked(1, (atomic64_t *)&priv->stats.rx_dropped);
42073 #else
42074- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42075+ atomic_add_unchecked(1, (atomic_t *)&priv->stats.rx_dropped);
42076 #endif
42077 dev_kfree_skb_irq(skb);
42078 }
42079diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42080index 492c502..d9909f1 100644
42081--- a/drivers/staging/octeon/ethernet.c
42082+++ b/drivers/staging/octeon/ethernet.c
42083@@ -294,11 +294,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42084 * since the RX tasklet also increments it.
42085 */
42086 #ifdef CONFIG_64BIT
42087- atomic64_add(rx_status.dropped_packets,
42088- (atomic64_t *)&priv->stats.rx_dropped);
42089+ atomic64_add_unchecked(rx_status.dropped_packets,
42090+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42091 #else
42092- atomic_add(rx_status.dropped_packets,
42093- (atomic_t *)&priv->stats.rx_dropped);
42094+ atomic_add_unchecked(rx_status.dropped_packets,
42095+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42096 #endif
42097 }
42098
42099diff --git a/drivers/staging/otus/80211core/pub_zfi.h b/drivers/staging/otus/80211core/pub_zfi.h
42100index a35bd5d..28fff45 100644
42101--- a/drivers/staging/otus/80211core/pub_zfi.h
42102+++ b/drivers/staging/otus/80211core/pub_zfi.h
42103@@ -531,7 +531,7 @@ struct zsCbFuncTbl
42104 u8_t (*zfcbClassifyTxPacket)(zdev_t* dev, zbuf_t* buf);
42105
42106 void (*zfcbHwWatchDogNotify)(zdev_t* dev);
42107-};
42108+} __no_const;
42109
42110 extern void zfZeroMemory(u8_t* va, u16_t length);
42111 #define ZM_INIT_CB_FUNC_TABLE(p) zfZeroMemory((u8_t *)p, sizeof(struct zsCbFuncTbl));
42112diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c
42113index c39a25f..696f5aa 100644
42114--- a/drivers/staging/panel/panel.c
42115+++ b/drivers/staging/panel/panel.c
42116@@ -1305,7 +1305,7 @@ static int lcd_release(struct inode *inode, struct file *file)
42117 return 0;
42118 }
42119
42120-static struct file_operations lcd_fops = {
42121+static const struct file_operations lcd_fops = {
42122 .write = lcd_write,
42123 .open = lcd_open,
42124 .release = lcd_release,
42125@@ -1565,7 +1565,7 @@ static int keypad_release(struct inode *inode, struct file *file)
42126 return 0;
42127 }
42128
42129-static struct file_operations keypad_fops = {
42130+static const struct file_operations keypad_fops = {
42131 .read = keypad_read, /* read */
42132 .open = keypad_open, /* open */
42133 .release = keypad_release, /* close */
42134diff --git a/drivers/staging/phison/phison.c b/drivers/staging/phison/phison.c
42135index 270ebcb..37e46af 100644
42136--- a/drivers/staging/phison/phison.c
42137+++ b/drivers/staging/phison/phison.c
42138@@ -43,7 +43,7 @@ static struct scsi_host_template phison_sht = {
42139 ATA_BMDMA_SHT(DRV_NAME),
42140 };
42141
42142-static struct ata_port_operations phison_ops = {
42143+static const struct ata_port_operations phison_ops = {
42144 .inherits = &ata_bmdma_port_ops,
42145 .prereset = phison_pre_reset,
42146 };
42147diff --git a/drivers/staging/poch/poch.c b/drivers/staging/poch/poch.c
42148index 2eb8e3d..57616a7 100644
42149--- a/drivers/staging/poch/poch.c
42150+++ b/drivers/staging/poch/poch.c
42151@@ -1057,7 +1057,7 @@ static int poch_ioctl(struct inode *inode, struct file *filp,
42152 return 0;
42153 }
42154
42155-static struct file_operations poch_fops = {
42156+static const struct file_operations poch_fops = {
42157 .owner = THIS_MODULE,
42158 .open = poch_open,
42159 .release = poch_release,
42160diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
42161index c94de31..19402bc 100644
42162--- a/drivers/staging/pohmelfs/inode.c
42163+++ b/drivers/staging/pohmelfs/inode.c
42164@@ -1850,7 +1850,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
42165 mutex_init(&psb->mcache_lock);
42166 psb->mcache_root = RB_ROOT;
42167 psb->mcache_timeout = msecs_to_jiffies(5000);
42168- atomic_long_set(&psb->mcache_gen, 0);
42169+ atomic_long_set_unchecked(&psb->mcache_gen, 0);
42170
42171 psb->trans_max_pages = 100;
42172
42173@@ -1865,7 +1865,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
42174 INIT_LIST_HEAD(&psb->crypto_ready_list);
42175 INIT_LIST_HEAD(&psb->crypto_active_list);
42176
42177- atomic_set(&psb->trans_gen, 1);
42178+ atomic_set_unchecked(&psb->trans_gen, 1);
42179 atomic_long_set(&psb->total_inodes, 0);
42180
42181 mutex_init(&psb->state_lock);
42182diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
42183index e22665c..a2a9390 100644
42184--- a/drivers/staging/pohmelfs/mcache.c
42185+++ b/drivers/staging/pohmelfs/mcache.c
42186@@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
42187 m->data = data;
42188 m->start = start;
42189 m->size = size;
42190- m->gen = atomic_long_inc_return(&psb->mcache_gen);
42191+ m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
42192
42193 mutex_lock(&psb->mcache_lock);
42194 err = pohmelfs_mcache_insert(psb, m);
42195diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
42196index 623a07d..4035c19 100644
42197--- a/drivers/staging/pohmelfs/netfs.h
42198+++ b/drivers/staging/pohmelfs/netfs.h
42199@@ -570,14 +570,14 @@ struct pohmelfs_config;
42200 struct pohmelfs_sb {
42201 struct rb_root mcache_root;
42202 struct mutex mcache_lock;
42203- atomic_long_t mcache_gen;
42204+ atomic_long_unchecked_t mcache_gen;
42205 unsigned long mcache_timeout;
42206
42207 unsigned int idx;
42208
42209 unsigned int trans_retries;
42210
42211- atomic_t trans_gen;
42212+ atomic_unchecked_t trans_gen;
42213
42214 unsigned int crypto_attached_size;
42215 unsigned int crypto_align_size;
42216diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
42217index 36a2535..0591bf4 100644
42218--- a/drivers/staging/pohmelfs/trans.c
42219+++ b/drivers/staging/pohmelfs/trans.c
42220@@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
42221 int err;
42222 struct netfs_cmd *cmd = t->iovec.iov_base;
42223
42224- t->gen = atomic_inc_return(&psb->trans_gen);
42225+ t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
42226
42227 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
42228 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
42229diff --git a/drivers/staging/sep/sep_driver.c b/drivers/staging/sep/sep_driver.c
42230index f890a16..509ece8 100644
42231--- a/drivers/staging/sep/sep_driver.c
42232+++ b/drivers/staging/sep/sep_driver.c
42233@@ -2603,7 +2603,7 @@ static struct pci_driver sep_pci_driver = {
42234 static dev_t sep_devno;
42235
42236 /* the files operations structure of the driver */
42237-static struct file_operations sep_file_operations = {
42238+static const struct file_operations sep_file_operations = {
42239 .owner = THIS_MODULE,
42240 .ioctl = sep_ioctl,
42241 .poll = sep_poll,
42242diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
42243index 5e16bc3..7655b10 100644
42244--- a/drivers/staging/usbip/usbip_common.h
42245+++ b/drivers/staging/usbip/usbip_common.h
42246@@ -374,7 +374,7 @@ struct usbip_device {
42247 void (*shutdown)(struct usbip_device *);
42248 void (*reset)(struct usbip_device *);
42249 void (*unusable)(struct usbip_device *);
42250- } eh_ops;
42251+ } __no_const eh_ops;
42252 };
42253
42254
42255diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42256index 57f7946..d9df23d 100644
42257--- a/drivers/staging/usbip/vhci.h
42258+++ b/drivers/staging/usbip/vhci.h
42259@@ -92,7 +92,7 @@ struct vhci_hcd {
42260 unsigned resuming:1;
42261 unsigned long re_timeout;
42262
42263- atomic_t seqnum;
42264+ atomic_unchecked_t seqnum;
42265
42266 /*
42267 * NOTE:
42268diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42269index 20cd7db..c2693ff 100644
42270--- a/drivers/staging/usbip/vhci_hcd.c
42271+++ b/drivers/staging/usbip/vhci_hcd.c
42272@@ -534,7 +534,7 @@ static void vhci_tx_urb(struct urb *urb)
42273 return;
42274 }
42275
42276- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42277+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42278 if (priv->seqnum == 0xffff)
42279 usbip_uinfo("seqnum max\n");
42280
42281@@ -793,7 +793,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42282 return -ENOMEM;
42283 }
42284
42285- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42286+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42287 if (unlink->seqnum == 0xffff)
42288 usbip_uinfo("seqnum max\n");
42289
42290@@ -988,7 +988,7 @@ static int vhci_start(struct usb_hcd *hcd)
42291 vdev->rhport = rhport;
42292 }
42293
42294- atomic_set(&vhci->seqnum, 0);
42295+ atomic_set_unchecked(&vhci->seqnum, 0);
42296 spin_lock_init(&vhci->lock);
42297
42298
42299diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42300index 7fd76fe..673695a 100644
42301--- a/drivers/staging/usbip/vhci_rx.c
42302+++ b/drivers/staging/usbip/vhci_rx.c
42303@@ -79,7 +79,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42304 usbip_uerr("cannot find a urb of seqnum %u\n",
42305 pdu->base.seqnum);
42306 usbip_uinfo("max seqnum %d\n",
42307- atomic_read(&the_controller->seqnum));
42308+ atomic_read_unchecked(&the_controller->seqnum));
42309 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42310 return;
42311 }
42312diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
42313index 7891288..8e31300 100644
42314--- a/drivers/staging/vme/devices/vme_user.c
42315+++ b/drivers/staging/vme/devices/vme_user.c
42316@@ -136,7 +136,7 @@ static int vme_user_ioctl(struct inode *, struct file *, unsigned int,
42317 static int __init vme_user_probe(struct device *, int, int);
42318 static int __exit vme_user_remove(struct device *, int, int);
42319
42320-static struct file_operations vme_user_fops = {
42321+static const struct file_operations vme_user_fops = {
42322 .open = vme_user_open,
42323 .release = vme_user_release,
42324 .read = vme_user_read,
42325diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42326index 58abf44..00c1fc8 100644
42327--- a/drivers/staging/vt6655/hostap.c
42328+++ b/drivers/staging/vt6655/hostap.c
42329@@ -84,7 +84,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42330 PSDevice apdev_priv;
42331 struct net_device *dev = pDevice->dev;
42332 int ret;
42333- const struct net_device_ops apdev_netdev_ops = {
42334+ net_device_ops_no_const apdev_netdev_ops = {
42335 .ndo_start_xmit = pDevice->tx_80211,
42336 };
42337
42338diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42339index 0c8267a..db1f363 100644
42340--- a/drivers/staging/vt6656/hostap.c
42341+++ b/drivers/staging/vt6656/hostap.c
42342@@ -86,7 +86,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42343 PSDevice apdev_priv;
42344 struct net_device *dev = pDevice->dev;
42345 int ret;
42346- const struct net_device_ops apdev_netdev_ops = {
42347+ net_device_ops_no_const apdev_netdev_ops = {
42348 .ndo_start_xmit = pDevice->tx_80211,
42349 };
42350
42351diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
42352index 925678b..da7f5ed 100644
42353--- a/drivers/staging/wlan-ng/hfa384x_usb.c
42354+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
42355@@ -205,7 +205,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
42356
42357 struct usbctlx_completor {
42358 int (*complete) (struct usbctlx_completor *);
42359-};
42360+} __no_const;
42361 typedef struct usbctlx_completor usbctlx_completor_t;
42362
42363 static int
42364diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
42365index 40de151..924f268 100644
42366--- a/drivers/telephony/ixj.c
42367+++ b/drivers/telephony/ixj.c
42368@@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
42369 bool mContinue;
42370 char *pIn, *pOut;
42371
42372+ pax_track_stack();
42373+
42374 if (!SCI_Prepare(j))
42375 return 0;
42376
42377diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
42378index e941367..b631f5a 100644
42379--- a/drivers/uio/uio.c
42380+++ b/drivers/uio/uio.c
42381@@ -23,6 +23,7 @@
42382 #include <linux/string.h>
42383 #include <linux/kobject.h>
42384 #include <linux/uio_driver.h>
42385+#include <asm/local.h>
42386
42387 #define UIO_MAX_DEVICES 255
42388
42389@@ -30,10 +31,10 @@ struct uio_device {
42390 struct module *owner;
42391 struct device *dev;
42392 int minor;
42393- atomic_t event;
42394+ atomic_unchecked_t event;
42395 struct fasync_struct *async_queue;
42396 wait_queue_head_t wait;
42397- int vma_count;
42398+ local_t vma_count;
42399 struct uio_info *info;
42400 struct kobject *map_dir;
42401 struct kobject *portio_dir;
42402@@ -129,7 +130,7 @@ static ssize_t map_type_show(struct kobject *kobj, struct attribute *attr,
42403 return entry->show(mem, buf);
42404 }
42405
42406-static struct sysfs_ops map_sysfs_ops = {
42407+static const struct sysfs_ops map_sysfs_ops = {
42408 .show = map_type_show,
42409 };
42410
42411@@ -217,7 +218,7 @@ static ssize_t portio_type_show(struct kobject *kobj, struct attribute *attr,
42412 return entry->show(port, buf);
42413 }
42414
42415-static struct sysfs_ops portio_sysfs_ops = {
42416+static const struct sysfs_ops portio_sysfs_ops = {
42417 .show = portio_type_show,
42418 };
42419
42420@@ -255,7 +256,7 @@ static ssize_t show_event(struct device *dev,
42421 struct uio_device *idev = dev_get_drvdata(dev);
42422 if (idev)
42423 return sprintf(buf, "%u\n",
42424- (unsigned int)atomic_read(&idev->event));
42425+ (unsigned int)atomic_read_unchecked(&idev->event));
42426 else
42427 return -ENODEV;
42428 }
42429@@ -424,7 +425,7 @@ void uio_event_notify(struct uio_info *info)
42430 {
42431 struct uio_device *idev = info->uio_dev;
42432
42433- atomic_inc(&idev->event);
42434+ atomic_inc_unchecked(&idev->event);
42435 wake_up_interruptible(&idev->wait);
42436 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
42437 }
42438@@ -477,7 +478,7 @@ static int uio_open(struct inode *inode, struct file *filep)
42439 }
42440
42441 listener->dev = idev;
42442- listener->event_count = atomic_read(&idev->event);
42443+ listener->event_count = atomic_read_unchecked(&idev->event);
42444 filep->private_data = listener;
42445
42446 if (idev->info->open) {
42447@@ -528,7 +529,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
42448 return -EIO;
42449
42450 poll_wait(filep, &idev->wait, wait);
42451- if (listener->event_count != atomic_read(&idev->event))
42452+ if (listener->event_count != atomic_read_unchecked(&idev->event))
42453 return POLLIN | POLLRDNORM;
42454 return 0;
42455 }
42456@@ -553,7 +554,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
42457 do {
42458 set_current_state(TASK_INTERRUPTIBLE);
42459
42460- event_count = atomic_read(&idev->event);
42461+ event_count = atomic_read_unchecked(&idev->event);
42462 if (event_count != listener->event_count) {
42463 if (copy_to_user(buf, &event_count, count))
42464 retval = -EFAULT;
42465@@ -624,13 +625,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
42466 static void uio_vma_open(struct vm_area_struct *vma)
42467 {
42468 struct uio_device *idev = vma->vm_private_data;
42469- idev->vma_count++;
42470+ local_inc(&idev->vma_count);
42471 }
42472
42473 static void uio_vma_close(struct vm_area_struct *vma)
42474 {
42475 struct uio_device *idev = vma->vm_private_data;
42476- idev->vma_count--;
42477+ local_dec(&idev->vma_count);
42478 }
42479
42480 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42481@@ -840,7 +841,7 @@ int __uio_register_device(struct module *owner,
42482 idev->owner = owner;
42483 idev->info = info;
42484 init_waitqueue_head(&idev->wait);
42485- atomic_set(&idev->event, 0);
42486+ atomic_set_unchecked(&idev->event, 0);
42487
42488 ret = uio_get_minor(idev);
42489 if (ret)
42490diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
42491index fbea856..06efea6 100644
42492--- a/drivers/usb/atm/usbatm.c
42493+++ b/drivers/usb/atm/usbatm.c
42494@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42495 if (printk_ratelimit())
42496 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
42497 __func__, vpi, vci);
42498- atomic_inc(&vcc->stats->rx_err);
42499+ atomic_inc_unchecked(&vcc->stats->rx_err);
42500 return;
42501 }
42502
42503@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42504 if (length > ATM_MAX_AAL5_PDU) {
42505 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
42506 __func__, length, vcc);
42507- atomic_inc(&vcc->stats->rx_err);
42508+ atomic_inc_unchecked(&vcc->stats->rx_err);
42509 goto out;
42510 }
42511
42512@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42513 if (sarb->len < pdu_length) {
42514 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
42515 __func__, pdu_length, sarb->len, vcc);
42516- atomic_inc(&vcc->stats->rx_err);
42517+ atomic_inc_unchecked(&vcc->stats->rx_err);
42518 goto out;
42519 }
42520
42521 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
42522 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
42523 __func__, vcc);
42524- atomic_inc(&vcc->stats->rx_err);
42525+ atomic_inc_unchecked(&vcc->stats->rx_err);
42526 goto out;
42527 }
42528
42529@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42530 if (printk_ratelimit())
42531 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
42532 __func__, length);
42533- atomic_inc(&vcc->stats->rx_drop);
42534+ atomic_inc_unchecked(&vcc->stats->rx_drop);
42535 goto out;
42536 }
42537
42538@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42539
42540 vcc->push(vcc, skb);
42541
42542- atomic_inc(&vcc->stats->rx);
42543+ atomic_inc_unchecked(&vcc->stats->rx);
42544 out:
42545 skb_trim(sarb, 0);
42546 }
42547@@ -616,7 +616,7 @@ static void usbatm_tx_process(unsigned long data)
42548 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
42549
42550 usbatm_pop(vcc, skb);
42551- atomic_inc(&vcc->stats->tx);
42552+ atomic_inc_unchecked(&vcc->stats->tx);
42553
42554 skb = skb_dequeue(&instance->sndqueue);
42555 }
42556@@ -775,11 +775,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
42557 if (!left--)
42558 return sprintf(page,
42559 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
42560- atomic_read(&atm_dev->stats.aal5.tx),
42561- atomic_read(&atm_dev->stats.aal5.tx_err),
42562- atomic_read(&atm_dev->stats.aal5.rx),
42563- atomic_read(&atm_dev->stats.aal5.rx_err),
42564- atomic_read(&atm_dev->stats.aal5.rx_drop));
42565+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
42566+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
42567+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
42568+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
42569+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
42570
42571 if (!left--) {
42572 if (instance->disconnected)
42573diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
42574index 24e6205..fe5a5d4 100644
42575--- a/drivers/usb/core/hcd.c
42576+++ b/drivers/usb/core/hcd.c
42577@@ -2216,7 +2216,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown);
42578
42579 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42580
42581-struct usb_mon_operations *mon_ops;
42582+const struct usb_mon_operations *mon_ops;
42583
42584 /*
42585 * The registration is unlocked.
42586@@ -2226,7 +2226,7 @@ struct usb_mon_operations *mon_ops;
42587 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
42588 */
42589
42590-int usb_mon_register (struct usb_mon_operations *ops)
42591+int usb_mon_register (const struct usb_mon_operations *ops)
42592 {
42593
42594 if (mon_ops)
42595diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
42596index bcbe104..9cfd1c6 100644
42597--- a/drivers/usb/core/hcd.h
42598+++ b/drivers/usb/core/hcd.h
42599@@ -486,13 +486,13 @@ static inline void usbfs_cleanup(void) { }
42600 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42601
42602 struct usb_mon_operations {
42603- void (*urb_submit)(struct usb_bus *bus, struct urb *urb);
42604- void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
42605- void (*urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
42606+ void (* const urb_submit)(struct usb_bus *bus, struct urb *urb);
42607+ void (* const urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
42608+ void (* const urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
42609 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
42610 };
42611
42612-extern struct usb_mon_operations *mon_ops;
42613+extern const struct usb_mon_operations *mon_ops;
42614
42615 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
42616 {
42617@@ -514,7 +514,7 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
42618 (*mon_ops->urb_complete)(bus, urb, status);
42619 }
42620
42621-int usb_mon_register(struct usb_mon_operations *ops);
42622+int usb_mon_register(const struct usb_mon_operations *ops);
42623 void usb_mon_deregister(void);
42624
42625 #else
42626diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
42627index 409cc94..a673bad 100644
42628--- a/drivers/usb/core/message.c
42629+++ b/drivers/usb/core/message.c
42630@@ -914,8 +914,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
42631 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
42632 if (buf) {
42633 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
42634- if (len > 0) {
42635- smallbuf = kmalloc(++len, GFP_NOIO);
42636+ if (len++ > 0) {
42637+ smallbuf = kmalloc(len, GFP_NOIO);
42638 if (!smallbuf)
42639 return buf;
42640 memcpy(smallbuf, buf, len);
42641diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
42642index 62ff5e7..530b74e 100644
42643--- a/drivers/usb/misc/appledisplay.c
42644+++ b/drivers/usb/misc/appledisplay.c
42645@@ -178,7 +178,7 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd)
42646 return pdata->msgdata[1];
42647 }
42648
42649-static struct backlight_ops appledisplay_bl_data = {
42650+static const struct backlight_ops appledisplay_bl_data = {
42651 .get_brightness = appledisplay_bl_get_brightness,
42652 .update_status = appledisplay_bl_update_status,
42653 };
42654diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
42655index e0c2db3..bd8cb66 100644
42656--- a/drivers/usb/mon/mon_main.c
42657+++ b/drivers/usb/mon/mon_main.c
42658@@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
42659 /*
42660 * Ops
42661 */
42662-static struct usb_mon_operations mon_ops_0 = {
42663+static const struct usb_mon_operations mon_ops_0 = {
42664 .urb_submit = mon_submit,
42665 .urb_submit_error = mon_submit_error,
42666 .urb_complete = mon_complete,
42667diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
42668index d6bea3e..60b250e 100644
42669--- a/drivers/usb/wusbcore/wa-hc.h
42670+++ b/drivers/usb/wusbcore/wa-hc.h
42671@@ -192,7 +192,7 @@ struct wahc {
42672 struct list_head xfer_delayed_list;
42673 spinlock_t xfer_list_lock;
42674 struct work_struct xfer_work;
42675- atomic_t xfer_id_count;
42676+ atomic_unchecked_t xfer_id_count;
42677 };
42678
42679
42680@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
42681 INIT_LIST_HEAD(&wa->xfer_delayed_list);
42682 spin_lock_init(&wa->xfer_list_lock);
42683 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
42684- atomic_set(&wa->xfer_id_count, 1);
42685+ atomic_set_unchecked(&wa->xfer_id_count, 1);
42686 }
42687
42688 /**
42689diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
42690index 613a5fc..3174865 100644
42691--- a/drivers/usb/wusbcore/wa-xfer.c
42692+++ b/drivers/usb/wusbcore/wa-xfer.c
42693@@ -293,7 +293,7 @@ out:
42694 */
42695 static void wa_xfer_id_init(struct wa_xfer *xfer)
42696 {
42697- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
42698+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
42699 }
42700
42701 /*
42702diff --git a/drivers/uwb/wlp/messages.c b/drivers/uwb/wlp/messages.c
42703index aa42fce..f8a828c 100644
42704--- a/drivers/uwb/wlp/messages.c
42705+++ b/drivers/uwb/wlp/messages.c
42706@@ -903,7 +903,7 @@ int wlp_parse_f0(struct wlp *wlp, struct sk_buff *skb)
42707 size_t len = skb->len;
42708 size_t used;
42709 ssize_t result;
42710- struct wlp_nonce enonce, rnonce;
42711+ struct wlp_nonce enonce = {{0}}, rnonce = {{0}};
42712 enum wlp_assc_error assc_err;
42713 char enonce_buf[WLP_WSS_NONCE_STRSIZE];
42714 char rnonce_buf[WLP_WSS_NONCE_STRSIZE];
42715diff --git a/drivers/uwb/wlp/sysfs.c b/drivers/uwb/wlp/sysfs.c
42716index 0370399..6627c94 100644
42717--- a/drivers/uwb/wlp/sysfs.c
42718+++ b/drivers/uwb/wlp/sysfs.c
42719@@ -615,8 +615,7 @@ ssize_t wlp_wss_attr_store(struct kobject *kobj, struct attribute *attr,
42720 return ret;
42721 }
42722
42723-static
42724-struct sysfs_ops wss_sysfs_ops = {
42725+static const struct sysfs_ops wss_sysfs_ops = {
42726 .show = wlp_wss_attr_show,
42727 .store = wlp_wss_attr_store,
42728 };
42729diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
42730index d5e8010..5687b56 100644
42731--- a/drivers/video/atmel_lcdfb.c
42732+++ b/drivers/video/atmel_lcdfb.c
42733@@ -110,7 +110,7 @@ static int atmel_bl_get_brightness(struct backlight_device *bl)
42734 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
42735 }
42736
42737-static struct backlight_ops atmel_lcdc_bl_ops = {
42738+static const struct backlight_ops atmel_lcdc_bl_ops = {
42739 .update_status = atmel_bl_update_status,
42740 .get_brightness = atmel_bl_get_brightness,
42741 };
42742diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
42743index e4e4d43..66bcbcc 100644
42744--- a/drivers/video/aty/aty128fb.c
42745+++ b/drivers/video/aty/aty128fb.c
42746@@ -149,7 +149,7 @@ enum {
42747 };
42748
42749 /* Must match above enum */
42750-static const char *r128_family[] __devinitdata = {
42751+static const char *r128_family[] __devinitconst = {
42752 "AGP",
42753 "PCI",
42754 "PRO AGP",
42755@@ -1787,7 +1787,7 @@ static int aty128_bl_get_brightness(struct backlight_device *bd)
42756 return bd->props.brightness;
42757 }
42758
42759-static struct backlight_ops aty128_bl_data = {
42760+static const struct backlight_ops aty128_bl_data = {
42761 .get_brightness = aty128_bl_get_brightness,
42762 .update_status = aty128_bl_update_status,
42763 };
42764diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
42765index 913b4a4..9295a38 100644
42766--- a/drivers/video/aty/atyfb_base.c
42767+++ b/drivers/video/aty/atyfb_base.c
42768@@ -2225,7 +2225,7 @@ static int aty_bl_get_brightness(struct backlight_device *bd)
42769 return bd->props.brightness;
42770 }
42771
42772-static struct backlight_ops aty_bl_data = {
42773+static const struct backlight_ops aty_bl_data = {
42774 .get_brightness = aty_bl_get_brightness,
42775 .update_status = aty_bl_update_status,
42776 };
42777diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
42778index 1a056ad..221bd6a 100644
42779--- a/drivers/video/aty/radeon_backlight.c
42780+++ b/drivers/video/aty/radeon_backlight.c
42781@@ -127,7 +127,7 @@ static int radeon_bl_get_brightness(struct backlight_device *bd)
42782 return bd->props.brightness;
42783 }
42784
42785-static struct backlight_ops radeon_bl_data = {
42786+static const struct backlight_ops radeon_bl_data = {
42787 .get_brightness = radeon_bl_get_brightness,
42788 .update_status = radeon_bl_update_status,
42789 };
42790diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c
42791index ad05da5..3cb2cb9 100644
42792--- a/drivers/video/backlight/adp5520_bl.c
42793+++ b/drivers/video/backlight/adp5520_bl.c
42794@@ -84,7 +84,7 @@ static int adp5520_bl_get_brightness(struct backlight_device *bl)
42795 return error ? data->current_brightness : reg_val;
42796 }
42797
42798-static struct backlight_ops adp5520_bl_ops = {
42799+static const struct backlight_ops adp5520_bl_ops = {
42800 .update_status = adp5520_bl_update_status,
42801 .get_brightness = adp5520_bl_get_brightness,
42802 };
42803diff --git a/drivers/video/backlight/adx_bl.c b/drivers/video/backlight/adx_bl.c
42804index 2c3bdfc..d769b0b 100644
42805--- a/drivers/video/backlight/adx_bl.c
42806+++ b/drivers/video/backlight/adx_bl.c
42807@@ -61,7 +61,7 @@ static int adx_backlight_check_fb(struct fb_info *fb)
42808 return 1;
42809 }
42810
42811-static struct backlight_ops adx_backlight_ops = {
42812+static const struct backlight_ops adx_backlight_ops = {
42813 .options = 0,
42814 .update_status = adx_backlight_update_status,
42815 .get_brightness = adx_backlight_get_brightness,
42816diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
42817index 505c082..6b6b3cc 100644
42818--- a/drivers/video/backlight/atmel-pwm-bl.c
42819+++ b/drivers/video/backlight/atmel-pwm-bl.c
42820@@ -113,7 +113,7 @@ static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
42821 return pwm_channel_enable(&pwmbl->pwmc);
42822 }
42823
42824-static struct backlight_ops atmel_pwm_bl_ops = {
42825+static const struct backlight_ops atmel_pwm_bl_ops = {
42826 .get_brightness = atmel_pwm_bl_get_intensity,
42827 .update_status = atmel_pwm_bl_set_intensity,
42828 };
42829diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
42830index 5e20e6e..89025e6 100644
42831--- a/drivers/video/backlight/backlight.c
42832+++ b/drivers/video/backlight/backlight.c
42833@@ -269,7 +269,7 @@ EXPORT_SYMBOL(backlight_force_update);
42834 * ERR_PTR() or a pointer to the newly allocated device.
42835 */
42836 struct backlight_device *backlight_device_register(const char *name,
42837- struct device *parent, void *devdata, struct backlight_ops *ops)
42838+ struct device *parent, void *devdata, const struct backlight_ops *ops)
42839 {
42840 struct backlight_device *new_bd;
42841 int rc;
42842diff --git a/drivers/video/backlight/corgi_lcd.c b/drivers/video/backlight/corgi_lcd.c
42843index 9677494..b4bcf80 100644
42844--- a/drivers/video/backlight/corgi_lcd.c
42845+++ b/drivers/video/backlight/corgi_lcd.c
42846@@ -451,7 +451,7 @@ void corgi_lcd_limit_intensity(int limit)
42847 }
42848 EXPORT_SYMBOL(corgi_lcd_limit_intensity);
42849
42850-static struct backlight_ops corgi_bl_ops = {
42851+static const struct backlight_ops corgi_bl_ops = {
42852 .get_brightness = corgi_bl_get_intensity,
42853 .update_status = corgi_bl_update_status,
42854 };
42855diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c
42856index b9fe62b..2914bf1 100644
42857--- a/drivers/video/backlight/cr_bllcd.c
42858+++ b/drivers/video/backlight/cr_bllcd.c
42859@@ -108,7 +108,7 @@ static int cr_backlight_get_intensity(struct backlight_device *bd)
42860 return intensity;
42861 }
42862
42863-static struct backlight_ops cr_backlight_ops = {
42864+static const struct backlight_ops cr_backlight_ops = {
42865 .get_brightness = cr_backlight_get_intensity,
42866 .update_status = cr_backlight_set_intensity,
42867 };
42868diff --git a/drivers/video/backlight/da903x_bl.c b/drivers/video/backlight/da903x_bl.c
42869index 701a108..feacfd5 100644
42870--- a/drivers/video/backlight/da903x_bl.c
42871+++ b/drivers/video/backlight/da903x_bl.c
42872@@ -94,7 +94,7 @@ static int da903x_backlight_get_brightness(struct backlight_device *bl)
42873 return data->current_brightness;
42874 }
42875
42876-static struct backlight_ops da903x_backlight_ops = {
42877+static const struct backlight_ops da903x_backlight_ops = {
42878 .update_status = da903x_backlight_update_status,
42879 .get_brightness = da903x_backlight_get_brightness,
42880 };
42881diff --git a/drivers/video/backlight/generic_bl.c b/drivers/video/backlight/generic_bl.c
42882index 6d27f62..e6d348e 100644
42883--- a/drivers/video/backlight/generic_bl.c
42884+++ b/drivers/video/backlight/generic_bl.c
42885@@ -70,7 +70,7 @@ void corgibl_limit_intensity(int limit)
42886 }
42887 EXPORT_SYMBOL(corgibl_limit_intensity);
42888
42889-static struct backlight_ops genericbl_ops = {
42890+static const struct backlight_ops genericbl_ops = {
42891 .options = BL_CORE_SUSPENDRESUME,
42892 .get_brightness = genericbl_get_intensity,
42893 .update_status = genericbl_send_intensity,
42894diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
42895index 7fb4eef..f7cc528 100644
42896--- a/drivers/video/backlight/hp680_bl.c
42897+++ b/drivers/video/backlight/hp680_bl.c
42898@@ -98,7 +98,7 @@ static int hp680bl_get_intensity(struct backlight_device *bd)
42899 return current_intensity;
42900 }
42901
42902-static struct backlight_ops hp680bl_ops = {
42903+static const struct backlight_ops hp680bl_ops = {
42904 .get_brightness = hp680bl_get_intensity,
42905 .update_status = hp680bl_set_intensity,
42906 };
42907diff --git a/drivers/video/backlight/jornada720_bl.c b/drivers/video/backlight/jornada720_bl.c
42908index 7aed256..db9071f 100644
42909--- a/drivers/video/backlight/jornada720_bl.c
42910+++ b/drivers/video/backlight/jornada720_bl.c
42911@@ -93,7 +93,7 @@ out:
42912 return ret;
42913 }
42914
42915-static struct backlight_ops jornada_bl_ops = {
42916+static const struct backlight_ops jornada_bl_ops = {
42917 .get_brightness = jornada_bl_get_brightness,
42918 .update_status = jornada_bl_update_status,
42919 .options = BL_CORE_SUSPENDRESUME,
42920diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
42921index a38fda1..939e7b8 100644
42922--- a/drivers/video/backlight/kb3886_bl.c
42923+++ b/drivers/video/backlight/kb3886_bl.c
42924@@ -134,7 +134,7 @@ static int kb3886bl_get_intensity(struct backlight_device *bd)
42925 return kb3886bl_intensity;
42926 }
42927
42928-static struct backlight_ops kb3886bl_ops = {
42929+static const struct backlight_ops kb3886bl_ops = {
42930 .get_brightness = kb3886bl_get_intensity,
42931 .update_status = kb3886bl_send_intensity,
42932 };
42933diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
42934index 6b488b8..00a9591 100644
42935--- a/drivers/video/backlight/locomolcd.c
42936+++ b/drivers/video/backlight/locomolcd.c
42937@@ -141,7 +141,7 @@ static int locomolcd_get_intensity(struct backlight_device *bd)
42938 return current_intensity;
42939 }
42940
42941-static struct backlight_ops locomobl_data = {
42942+static const struct backlight_ops locomobl_data = {
42943 .get_brightness = locomolcd_get_intensity,
42944 .update_status = locomolcd_set_intensity,
42945 };
42946diff --git a/drivers/video/backlight/mbp_nvidia_bl.c b/drivers/video/backlight/mbp_nvidia_bl.c
42947index 99bdfa8..3dac448 100644
42948--- a/drivers/video/backlight/mbp_nvidia_bl.c
42949+++ b/drivers/video/backlight/mbp_nvidia_bl.c
42950@@ -33,7 +33,7 @@ struct dmi_match_data {
42951 unsigned long iostart;
42952 unsigned long iolen;
42953 /* Backlight operations structure. */
42954- struct backlight_ops backlight_ops;
42955+ const struct backlight_ops backlight_ops;
42956 };
42957
42958 /* Module parameters. */
42959diff --git a/drivers/video/backlight/omap1_bl.c b/drivers/video/backlight/omap1_bl.c
42960index cbad67e..3cf900e 100644
42961--- a/drivers/video/backlight/omap1_bl.c
42962+++ b/drivers/video/backlight/omap1_bl.c
42963@@ -125,7 +125,7 @@ static int omapbl_get_intensity(struct backlight_device *dev)
42964 return bl->current_intensity;
42965 }
42966
42967-static struct backlight_ops omapbl_ops = {
42968+static const struct backlight_ops omapbl_ops = {
42969 .get_brightness = omapbl_get_intensity,
42970 .update_status = omapbl_update_status,
42971 };
42972diff --git a/drivers/video/backlight/progear_bl.c b/drivers/video/backlight/progear_bl.c
42973index 9edaf24..075786e 100644
42974--- a/drivers/video/backlight/progear_bl.c
42975+++ b/drivers/video/backlight/progear_bl.c
42976@@ -54,7 +54,7 @@ static int progearbl_get_intensity(struct backlight_device *bd)
42977 return intensity - HW_LEVEL_MIN;
42978 }
42979
42980-static struct backlight_ops progearbl_ops = {
42981+static const struct backlight_ops progearbl_ops = {
42982 .get_brightness = progearbl_get_intensity,
42983 .update_status = progearbl_set_intensity,
42984 };
42985diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
42986index 8871662..df9e0b3 100644
42987--- a/drivers/video/backlight/pwm_bl.c
42988+++ b/drivers/video/backlight/pwm_bl.c
42989@@ -56,7 +56,7 @@ static int pwm_backlight_get_brightness(struct backlight_device *bl)
42990 return bl->props.brightness;
42991 }
42992
42993-static struct backlight_ops pwm_backlight_ops = {
42994+static const struct backlight_ops pwm_backlight_ops = {
42995 .update_status = pwm_backlight_update_status,
42996 .get_brightness = pwm_backlight_get_brightness,
42997 };
42998diff --git a/drivers/video/backlight/tosa_bl.c b/drivers/video/backlight/tosa_bl.c
42999index 43edbad..e14ce4d 100644
43000--- a/drivers/video/backlight/tosa_bl.c
43001+++ b/drivers/video/backlight/tosa_bl.c
43002@@ -72,7 +72,7 @@ static int tosa_bl_get_brightness(struct backlight_device *dev)
43003 return props->brightness;
43004 }
43005
43006-static struct backlight_ops bl_ops = {
43007+static const struct backlight_ops bl_ops = {
43008 .get_brightness = tosa_bl_get_brightness,
43009 .update_status = tosa_bl_update_status,
43010 };
43011diff --git a/drivers/video/backlight/wm831x_bl.c b/drivers/video/backlight/wm831x_bl.c
43012index 467bdb7..e32add3 100644
43013--- a/drivers/video/backlight/wm831x_bl.c
43014+++ b/drivers/video/backlight/wm831x_bl.c
43015@@ -112,7 +112,7 @@ static int wm831x_backlight_get_brightness(struct backlight_device *bl)
43016 return data->current_brightness;
43017 }
43018
43019-static struct backlight_ops wm831x_backlight_ops = {
43020+static const struct backlight_ops wm831x_backlight_ops = {
43021 .options = BL_CORE_SUSPENDRESUME,
43022 .update_status = wm831x_backlight_update_status,
43023 .get_brightness = wm831x_backlight_get_brightness,
43024diff --git a/drivers/video/bf54x-lq043fb.c b/drivers/video/bf54x-lq043fb.c
43025index e49ae5e..db4e6f7 100644
43026--- a/drivers/video/bf54x-lq043fb.c
43027+++ b/drivers/video/bf54x-lq043fb.c
43028@@ -463,7 +463,7 @@ static int bl_get_brightness(struct backlight_device *bd)
43029 return 0;
43030 }
43031
43032-static struct backlight_ops bfin_lq043fb_bl_ops = {
43033+static const struct backlight_ops bfin_lq043fb_bl_ops = {
43034 .get_brightness = bl_get_brightness,
43035 };
43036
43037diff --git a/drivers/video/bfin-t350mcqb-fb.c b/drivers/video/bfin-t350mcqb-fb.c
43038index 2c72a7c..d523e52 100644
43039--- a/drivers/video/bfin-t350mcqb-fb.c
43040+++ b/drivers/video/bfin-t350mcqb-fb.c
43041@@ -381,7 +381,7 @@ static int bl_get_brightness(struct backlight_device *bd)
43042 return 0;
43043 }
43044
43045-static struct backlight_ops bfin_lq043fb_bl_ops = {
43046+static const struct backlight_ops bfin_lq043fb_bl_ops = {
43047 .get_brightness = bl_get_brightness,
43048 };
43049
43050diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
43051index f53b9f1..958bf4e 100644
43052--- a/drivers/video/fbcmap.c
43053+++ b/drivers/video/fbcmap.c
43054@@ -266,8 +266,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
43055 rc = -ENODEV;
43056 goto out;
43057 }
43058- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
43059- !info->fbops->fb_setcmap)) {
43060+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
43061 rc = -EINVAL;
43062 goto out1;
43063 }
43064diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
43065index 99bbd28..ad3829e 100644
43066--- a/drivers/video/fbmem.c
43067+++ b/drivers/video/fbmem.c
43068@@ -403,7 +403,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
43069 image->dx += image->width + 8;
43070 }
43071 } else if (rotate == FB_ROTATE_UD) {
43072- for (x = 0; x < num && image->dx >= 0; x++) {
43073+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
43074 info->fbops->fb_imageblit(info, image);
43075 image->dx -= image->width + 8;
43076 }
43077@@ -415,7 +415,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
43078 image->dy += image->height + 8;
43079 }
43080 } else if (rotate == FB_ROTATE_CCW) {
43081- for (x = 0; x < num && image->dy >= 0; x++) {
43082+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
43083 info->fbops->fb_imageblit(info, image);
43084 image->dy -= image->height + 8;
43085 }
43086@@ -915,6 +915,8 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
43087 int flags = info->flags;
43088 int ret = 0;
43089
43090+ pax_track_stack();
43091+
43092 if (var->activate & FB_ACTIVATE_INV_MODE) {
43093 struct fb_videomode mode1, mode2;
43094
43095@@ -1040,6 +1042,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
43096 void __user *argp = (void __user *)arg;
43097 long ret = 0;
43098
43099+ pax_track_stack();
43100+
43101 switch (cmd) {
43102 case FBIOGET_VSCREENINFO:
43103 if (!lock_fb_info(info))
43104@@ -1119,7 +1123,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
43105 return -EFAULT;
43106 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
43107 return -EINVAL;
43108- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
43109+ if (con2fb.framebuffer >= FB_MAX)
43110 return -EINVAL;
43111 if (!registered_fb[con2fb.framebuffer])
43112 request_module("fb%d", con2fb.framebuffer);
43113diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
43114index f20eff8..3e4f622 100644
43115--- a/drivers/video/geode/gx1fb_core.c
43116+++ b/drivers/video/geode/gx1fb_core.c
43117@@ -30,7 +30,7 @@ static int crt_option = 1;
43118 static char panel_option[32] = "";
43119
43120 /* Modes relevant to the GX1 (taken from modedb.c) */
43121-static const struct fb_videomode __initdata gx1_modedb[] = {
43122+static const struct fb_videomode __initconst gx1_modedb[] = {
43123 /* 640x480-60 VESA */
43124 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
43125 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
43126diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
43127index 896e53d..4d87d0b 100644
43128--- a/drivers/video/gxt4500.c
43129+++ b/drivers/video/gxt4500.c
43130@@ -156,7 +156,7 @@ struct gxt4500_par {
43131 static char *mode_option;
43132
43133 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
43134-static const struct fb_videomode defaultmode __devinitdata = {
43135+static const struct fb_videomode defaultmode __devinitconst = {
43136 .refresh = 60,
43137 .xres = 1280,
43138 .yres = 1024,
43139@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
43140 return 0;
43141 }
43142
43143-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
43144+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
43145 .id = "IBM GXT4500P",
43146 .type = FB_TYPE_PACKED_PIXELS,
43147 .visual = FB_VISUAL_PSEUDOCOLOR,
43148diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
43149index f5bedee..28c6028 100644
43150--- a/drivers/video/i810/i810_accel.c
43151+++ b/drivers/video/i810/i810_accel.c
43152@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
43153 }
43154 }
43155 printk("ringbuffer lockup!!!\n");
43156+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
43157 i810_report_error(mmio);
43158 par->dev_flags |= LOCKUP;
43159 info->pixmap.scan_align = 1;
43160diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
43161index 5743ea2..457f82c 100644
43162--- a/drivers/video/i810/i810_main.c
43163+++ b/drivers/video/i810/i810_main.c
43164@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
43165 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
43166
43167 /* PCI */
43168-static const char *i810_pci_list[] __devinitdata = {
43169+static const char *i810_pci_list[] __devinitconst = {
43170 "Intel(R) 810 Framebuffer Device" ,
43171 "Intel(R) 810-DC100 Framebuffer Device" ,
43172 "Intel(R) 810E Framebuffer Device" ,
43173diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
43174index 3c14e43..eafa544 100644
43175--- a/drivers/video/logo/logo_linux_clut224.ppm
43176+++ b/drivers/video/logo/logo_linux_clut224.ppm
43177@@ -1,1604 +1,1123 @@
43178 P3
43179-# Standard 224-color Linux logo
43180 80 80
43181 255
43182- 0 0 0 0 0 0 0 0 0 0 0 0
43183- 0 0 0 0 0 0 0 0 0 0 0 0
43184- 0 0 0 0 0 0 0 0 0 0 0 0
43185- 0 0 0 0 0 0 0 0 0 0 0 0
43186- 0 0 0 0 0 0 0 0 0 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- 6 6 6 6 6 6 10 10 10 10 10 10
43192- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0
43198- 0 0 0 0 0 0 0 0 0 0 0 0
43199- 0 0 0 0 0 0 0 0 0 0 0 0
43200- 0 0 0 0 0 0 0 0 0 0 0 0
43201- 0 0 0 0 0 0 0 0 0 0 0 0
43202- 0 0 0 0 0 0 0 0 0 0 0 0
43203- 0 0 0 0 0 0 0 0 0 0 0 0
43204- 0 0 0 0 0 0 0 0 0 0 0 0
43205- 0 0 0 0 0 0 0 0 0 0 0 0
43206- 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
43211- 22 22 22 26 26 26 30 30 30 34 34 34
43212- 30 30 30 30 30 30 26 26 26 18 18 18
43213- 14 14 14 10 10 10 6 6 6 0 0 0
43214- 0 0 0 0 0 0 0 0 0 0 0 0
43215- 0 0 0 0 0 0 0 0 0 0 0 0
43216- 0 0 0 0 0 0 0 0 0 0 0 0
43217- 0 0 0 0 0 0 0 0 0 0 0 0
43218- 0 0 0 0 0 0 0 0 0 0 0 0
43219- 0 0 0 0 0 0 0 0 0 0 0 0
43220- 0 0 0 0 0 0 0 0 0 0 0 0
43221- 0 0 0 0 0 0 0 0 0 0 0 0
43222- 0 0 0 0 0 0 0 0 0 0 0 0
43223- 0 0 0 0 0 1 0 0 1 0 0 0
43224- 0 0 0 0 0 0 0 0 0 0 0 0
43225- 0 0 0 0 0 0 0 0 0 0 0 0
43226- 0 0 0 0 0 0 0 0 0 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- 6 6 6 14 14 14 26 26 26 42 42 42
43231- 54 54 54 66 66 66 78 78 78 78 78 78
43232- 78 78 78 74 74 74 66 66 66 54 54 54
43233- 42 42 42 26 26 26 18 18 18 10 10 10
43234- 6 6 6 0 0 0 0 0 0 0 0 0
43235- 0 0 0 0 0 0 0 0 0 0 0 0
43236- 0 0 0 0 0 0 0 0 0 0 0 0
43237- 0 0 0 0 0 0 0 0 0 0 0 0
43238- 0 0 0 0 0 0 0 0 0 0 0 0
43239- 0 0 0 0 0 0 0 0 0 0 0 0
43240- 0 0 0 0 0 0 0 0 0 0 0 0
43241- 0 0 0 0 0 0 0 0 0 0 0 0
43242- 0 0 0 0 0 0 0 0 0 0 0 0
43243- 0 0 1 0 0 0 0 0 0 0 0 0
43244- 0 0 0 0 0 0 0 0 0 0 0 0
43245- 0 0 0 0 0 0 0 0 0 0 0 0
43246- 0 0 0 0 0 0 0 0 0 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 10 10 10
43250- 22 22 22 42 42 42 66 66 66 86 86 86
43251- 66 66 66 38 38 38 38 38 38 22 22 22
43252- 26 26 26 34 34 34 54 54 54 66 66 66
43253- 86 86 86 70 70 70 46 46 46 26 26 26
43254- 14 14 14 6 6 6 0 0 0 0 0 0
43255- 0 0 0 0 0 0 0 0 0 0 0 0
43256- 0 0 0 0 0 0 0 0 0 0 0 0
43257- 0 0 0 0 0 0 0 0 0 0 0 0
43258- 0 0 0 0 0 0 0 0 0 0 0 0
43259- 0 0 0 0 0 0 0 0 0 0 0 0
43260- 0 0 0 0 0 0 0 0 0 0 0 0
43261- 0 0 0 0 0 0 0 0 0 0 0 0
43262- 0 0 0 0 0 0 0 0 0 0 0 0
43263- 0 0 1 0 0 1 0 0 1 0 0 0
43264- 0 0 0 0 0 0 0 0 0 0 0 0
43265- 0 0 0 0 0 0 0 0 0 0 0 0
43266- 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
43270- 50 50 50 82 82 82 58 58 58 6 6 6
43271- 2 2 6 2 2 6 2 2 6 2 2 6
43272- 2 2 6 2 2 6 2 2 6 2 2 6
43273- 6 6 6 54 54 54 86 86 86 66 66 66
43274- 38 38 38 18 18 18 6 6 6 0 0 0
43275- 0 0 0 0 0 0 0 0 0 0 0 0
43276- 0 0 0 0 0 0 0 0 0 0 0 0
43277- 0 0 0 0 0 0 0 0 0 0 0 0
43278- 0 0 0 0 0 0 0 0 0 0 0 0
43279- 0 0 0 0 0 0 0 0 0 0 0 0
43280- 0 0 0 0 0 0 0 0 0 0 0 0
43281- 0 0 0 0 0 0 0 0 0 0 0 0
43282- 0 0 0 0 0 0 0 0 0 0 0 0
43283- 0 0 0 0 0 0 0 0 0 0 0 0
43284- 0 0 0 0 0 0 0 0 0 0 0 0
43285- 0 0 0 0 0 0 0 0 0 0 0 0
43286- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
43290- 78 78 78 34 34 34 2 2 6 2 2 6
43291- 2 2 6 2 2 6 2 2 6 2 2 6
43292- 2 2 6 2 2 6 2 2 6 2 2 6
43293- 2 2 6 2 2 6 6 6 6 70 70 70
43294- 78 78 78 46 46 46 22 22 22 6 6 6
43295- 0 0 0 0 0 0 0 0 0 0 0 0
43296- 0 0 0 0 0 0 0 0 0 0 0 0
43297- 0 0 0 0 0 0 0 0 0 0 0 0
43298- 0 0 0 0 0 0 0 0 0 0 0 0
43299- 0 0 0 0 0 0 0 0 0 0 0 0
43300- 0 0 0 0 0 0 0 0 0 0 0 0
43301- 0 0 0 0 0 0 0 0 0 0 0 0
43302- 0 0 0 0 0 0 0 0 0 0 0 0
43303- 0 0 1 0 0 1 0 0 1 0 0 0
43304- 0 0 0 0 0 0 0 0 0 0 0 0
43305- 0 0 0 0 0 0 0 0 0 0 0 0
43306- 0 0 0 0 0 0 0 0 0 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- 6 6 6 18 18 18 42 42 42 82 82 82
43310- 26 26 26 2 2 6 2 2 6 2 2 6
43311- 2 2 6 2 2 6 2 2 6 2 2 6
43312- 2 2 6 2 2 6 2 2 6 14 14 14
43313- 46 46 46 34 34 34 6 6 6 2 2 6
43314- 42 42 42 78 78 78 42 42 42 18 18 18
43315- 6 6 6 0 0 0 0 0 0 0 0 0
43316- 0 0 0 0 0 0 0 0 0 0 0 0
43317- 0 0 0 0 0 0 0 0 0 0 0 0
43318- 0 0 0 0 0 0 0 0 0 0 0 0
43319- 0 0 0 0 0 0 0 0 0 0 0 0
43320- 0 0 0 0 0 0 0 0 0 0 0 0
43321- 0 0 0 0 0 0 0 0 0 0 0 0
43322- 0 0 0 0 0 0 0 0 0 0 0 0
43323- 0 0 1 0 0 0 0 0 1 0 0 0
43324- 0 0 0 0 0 0 0 0 0 0 0 0
43325- 0 0 0 0 0 0 0 0 0 0 0 0
43326- 0 0 0 0 0 0 0 0 0 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- 10 10 10 30 30 30 66 66 66 58 58 58
43330- 2 2 6 2 2 6 2 2 6 2 2 6
43331- 2 2 6 2 2 6 2 2 6 2 2 6
43332- 2 2 6 2 2 6 2 2 6 26 26 26
43333- 86 86 86 101 101 101 46 46 46 10 10 10
43334- 2 2 6 58 58 58 70 70 70 34 34 34
43335- 10 10 10 0 0 0 0 0 0 0 0 0
43336- 0 0 0 0 0 0 0 0 0 0 0 0
43337- 0 0 0 0 0 0 0 0 0 0 0 0
43338- 0 0 0 0 0 0 0 0 0 0 0 0
43339- 0 0 0 0 0 0 0 0 0 0 0 0
43340- 0 0 0 0 0 0 0 0 0 0 0 0
43341- 0 0 0 0 0 0 0 0 0 0 0 0
43342- 0 0 0 0 0 0 0 0 0 0 0 0
43343- 0 0 1 0 0 1 0 0 1 0 0 0
43344- 0 0 0 0 0 0 0 0 0 0 0 0
43345- 0 0 0 0 0 0 0 0 0 0 0 0
43346- 0 0 0 0 0 0 0 0 0 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- 14 14 14 42 42 42 86 86 86 10 10 10
43350- 2 2 6 2 2 6 2 2 6 2 2 6
43351- 2 2 6 2 2 6 2 2 6 2 2 6
43352- 2 2 6 2 2 6 2 2 6 30 30 30
43353- 94 94 94 94 94 94 58 58 58 26 26 26
43354- 2 2 6 6 6 6 78 78 78 54 54 54
43355- 22 22 22 6 6 6 0 0 0 0 0 0
43356- 0 0 0 0 0 0 0 0 0 0 0 0
43357- 0 0 0 0 0 0 0 0 0 0 0 0
43358- 0 0 0 0 0 0 0 0 0 0 0 0
43359- 0 0 0 0 0 0 0 0 0 0 0 0
43360- 0 0 0 0 0 0 0 0 0 0 0 0
43361- 0 0 0 0 0 0 0 0 0 0 0 0
43362- 0 0 0 0 0 0 0 0 0 0 0 0
43363- 0 0 0 0 0 0 0 0 0 0 0 0
43364- 0 0 0 0 0 0 0 0 0 0 0 0
43365- 0 0 0 0 0 0 0 0 0 0 0 0
43366- 0 0 0 0 0 0 0 0 0 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 6 6 6
43369- 22 22 22 62 62 62 62 62 62 2 2 6
43370- 2 2 6 2 2 6 2 2 6 2 2 6
43371- 2 2 6 2 2 6 2 2 6 2 2 6
43372- 2 2 6 2 2 6 2 2 6 26 26 26
43373- 54 54 54 38 38 38 18 18 18 10 10 10
43374- 2 2 6 2 2 6 34 34 34 82 82 82
43375- 38 38 38 14 14 14 0 0 0 0 0 0
43376- 0 0 0 0 0 0 0 0 0 0 0 0
43377- 0 0 0 0 0 0 0 0 0 0 0 0
43378- 0 0 0 0 0 0 0 0 0 0 0 0
43379- 0 0 0 0 0 0 0 0 0 0 0 0
43380- 0 0 0 0 0 0 0 0 0 0 0 0
43381- 0 0 0 0 0 0 0 0 0 0 0 0
43382- 0 0 0 0 0 0 0 0 0 0 0 0
43383- 0 0 0 0 0 1 0 0 1 0 0 0
43384- 0 0 0 0 0 0 0 0 0 0 0 0
43385- 0 0 0 0 0 0 0 0 0 0 0 0
43386- 0 0 0 0 0 0 0 0 0 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 6 6 6
43389- 30 30 30 78 78 78 30 30 30 2 2 6
43390- 2 2 6 2 2 6 2 2 6 2 2 6
43391- 2 2 6 2 2 6 2 2 6 2 2 6
43392- 2 2 6 2 2 6 2 2 6 10 10 10
43393- 10 10 10 2 2 6 2 2 6 2 2 6
43394- 2 2 6 2 2 6 2 2 6 78 78 78
43395- 50 50 50 18 18 18 6 6 6 0 0 0
43396- 0 0 0 0 0 0 0 0 0 0 0 0
43397- 0 0 0 0 0 0 0 0 0 0 0 0
43398- 0 0 0 0 0 0 0 0 0 0 0 0
43399- 0 0 0 0 0 0 0 0 0 0 0 0
43400- 0 0 0 0 0 0 0 0 0 0 0 0
43401- 0 0 0 0 0 0 0 0 0 0 0 0
43402- 0 0 0 0 0 0 0 0 0 0 0 0
43403- 0 0 1 0 0 0 0 0 0 0 0 0
43404- 0 0 0 0 0 0 0 0 0 0 0 0
43405- 0 0 0 0 0 0 0 0 0 0 0 0
43406- 0 0 0 0 0 0 0 0 0 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 10 10 10
43409- 38 38 38 86 86 86 14 14 14 2 2 6
43410- 2 2 6 2 2 6 2 2 6 2 2 6
43411- 2 2 6 2 2 6 2 2 6 2 2 6
43412- 2 2 6 2 2 6 2 2 6 2 2 6
43413- 2 2 6 2 2 6 2 2 6 2 2 6
43414- 2 2 6 2 2 6 2 2 6 54 54 54
43415- 66 66 66 26 26 26 6 6 6 0 0 0
43416- 0 0 0 0 0 0 0 0 0 0 0 0
43417- 0 0 0 0 0 0 0 0 0 0 0 0
43418- 0 0 0 0 0 0 0 0 0 0 0 0
43419- 0 0 0 0 0 0 0 0 0 0 0 0
43420- 0 0 0 0 0 0 0 0 0 0 0 0
43421- 0 0 0 0 0 0 0 0 0 0 0 0
43422- 0 0 0 0 0 0 0 0 0 0 0 0
43423- 0 0 0 0 0 1 0 0 1 0 0 0
43424- 0 0 0 0 0 0 0 0 0 0 0 0
43425- 0 0 0 0 0 0 0 0 0 0 0 0
43426- 0 0 0 0 0 0 0 0 0 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 14 14 14
43429- 42 42 42 82 82 82 2 2 6 2 2 6
43430- 2 2 6 6 6 6 10 10 10 2 2 6
43431- 2 2 6 2 2 6 2 2 6 2 2 6
43432- 2 2 6 2 2 6 2 2 6 6 6 6
43433- 14 14 14 10 10 10 2 2 6 2 2 6
43434- 2 2 6 2 2 6 2 2 6 18 18 18
43435- 82 82 82 34 34 34 10 10 10 0 0 0
43436- 0 0 0 0 0 0 0 0 0 0 0 0
43437- 0 0 0 0 0 0 0 0 0 0 0 0
43438- 0 0 0 0 0 0 0 0 0 0 0 0
43439- 0 0 0 0 0 0 0 0 0 0 0 0
43440- 0 0 0 0 0 0 0 0 0 0 0 0
43441- 0 0 0 0 0 0 0 0 0 0 0 0
43442- 0 0 0 0 0 0 0 0 0 0 0 0
43443- 0 0 1 0 0 0 0 0 0 0 0 0
43444- 0 0 0 0 0 0 0 0 0 0 0 0
43445- 0 0 0 0 0 0 0 0 0 0 0 0
43446- 0 0 0 0 0 0 0 0 0 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 14 14 14
43449- 46 46 46 86 86 86 2 2 6 2 2 6
43450- 6 6 6 6 6 6 22 22 22 34 34 34
43451- 6 6 6 2 2 6 2 2 6 2 2 6
43452- 2 2 6 2 2 6 18 18 18 34 34 34
43453- 10 10 10 50 50 50 22 22 22 2 2 6
43454- 2 2 6 2 2 6 2 2 6 10 10 10
43455- 86 86 86 42 42 42 14 14 14 0 0 0
43456- 0 0 0 0 0 0 0 0 0 0 0 0
43457- 0 0 0 0 0 0 0 0 0 0 0 0
43458- 0 0 0 0 0 0 0 0 0 0 0 0
43459- 0 0 0 0 0 0 0 0 0 0 0 0
43460- 0 0 0 0 0 0 0 0 0 0 0 0
43461- 0 0 0 0 0 0 0 0 0 0 0 0
43462- 0 0 0 0 0 0 0 0 0 0 0 0
43463- 0 0 1 0 0 1 0 0 1 0 0 0
43464- 0 0 0 0 0 0 0 0 0 0 0 0
43465- 0 0 0 0 0 0 0 0 0 0 0 0
43466- 0 0 0 0 0 0 0 0 0 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 14 14 14
43469- 46 46 46 86 86 86 2 2 6 2 2 6
43470- 38 38 38 116 116 116 94 94 94 22 22 22
43471- 22 22 22 2 2 6 2 2 6 2 2 6
43472- 14 14 14 86 86 86 138 138 138 162 162 162
43473-154 154 154 38 38 38 26 26 26 6 6 6
43474- 2 2 6 2 2 6 2 2 6 2 2 6
43475- 86 86 86 46 46 46 14 14 14 0 0 0
43476- 0 0 0 0 0 0 0 0 0 0 0 0
43477- 0 0 0 0 0 0 0 0 0 0 0 0
43478- 0 0 0 0 0 0 0 0 0 0 0 0
43479- 0 0 0 0 0 0 0 0 0 0 0 0
43480- 0 0 0 0 0 0 0 0 0 0 0 0
43481- 0 0 0 0 0 0 0 0 0 0 0 0
43482- 0 0 0 0 0 0 0 0 0 0 0 0
43483- 0 0 0 0 0 0 0 0 0 0 0 0
43484- 0 0 0 0 0 0 0 0 0 0 0 0
43485- 0 0 0 0 0 0 0 0 0 0 0 0
43486- 0 0 0 0 0 0 0 0 0 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 14 14 14
43489- 46 46 46 86 86 86 2 2 6 14 14 14
43490-134 134 134 198 198 198 195 195 195 116 116 116
43491- 10 10 10 2 2 6 2 2 6 6 6 6
43492-101 98 89 187 187 187 210 210 210 218 218 218
43493-214 214 214 134 134 134 14 14 14 6 6 6
43494- 2 2 6 2 2 6 2 2 6 2 2 6
43495- 86 86 86 50 50 50 18 18 18 6 6 6
43496- 0 0 0 0 0 0 0 0 0 0 0 0
43497- 0 0 0 0 0 0 0 0 0 0 0 0
43498- 0 0 0 0 0 0 0 0 0 0 0 0
43499- 0 0 0 0 0 0 0 0 0 0 0 0
43500- 0 0 0 0 0 0 0 0 0 0 0 0
43501- 0 0 0 0 0 0 0 0 0 0 0 0
43502- 0 0 0 0 0 0 0 0 1 0 0 0
43503- 0 0 1 0 0 1 0 0 1 0 0 0
43504- 0 0 0 0 0 0 0 0 0 0 0 0
43505- 0 0 0 0 0 0 0 0 0 0 0 0
43506- 0 0 0 0 0 0 0 0 0 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 14 14 14
43509- 46 46 46 86 86 86 2 2 6 54 54 54
43510-218 218 218 195 195 195 226 226 226 246 246 246
43511- 58 58 58 2 2 6 2 2 6 30 30 30
43512-210 210 210 253 253 253 174 174 174 123 123 123
43513-221 221 221 234 234 234 74 74 74 2 2 6
43514- 2 2 6 2 2 6 2 2 6 2 2 6
43515- 70 70 70 58 58 58 22 22 22 6 6 6
43516- 0 0 0 0 0 0 0 0 0 0 0 0
43517- 0 0 0 0 0 0 0 0 0 0 0 0
43518- 0 0 0 0 0 0 0 0 0 0 0 0
43519- 0 0 0 0 0 0 0 0 0 0 0 0
43520- 0 0 0 0 0 0 0 0 0 0 0 0
43521- 0 0 0 0 0 0 0 0 0 0 0 0
43522- 0 0 0 0 0 0 0 0 0 0 0 0
43523- 0 0 0 0 0 0 0 0 0 0 0 0
43524- 0 0 0 0 0 0 0 0 0 0 0 0
43525- 0 0 0 0 0 0 0 0 0 0 0 0
43526- 0 0 0 0 0 0 0 0 0 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 14 14 14
43529- 46 46 46 82 82 82 2 2 6 106 106 106
43530-170 170 170 26 26 26 86 86 86 226 226 226
43531-123 123 123 10 10 10 14 14 14 46 46 46
43532-231 231 231 190 190 190 6 6 6 70 70 70
43533- 90 90 90 238 238 238 158 158 158 2 2 6
43534- 2 2 6 2 2 6 2 2 6 2 2 6
43535- 70 70 70 58 58 58 22 22 22 6 6 6
43536- 0 0 0 0 0 0 0 0 0 0 0 0
43537- 0 0 0 0 0 0 0 0 0 0 0 0
43538- 0 0 0 0 0 0 0 0 0 0 0 0
43539- 0 0 0 0 0 0 0 0 0 0 0 0
43540- 0 0 0 0 0 0 0 0 0 0 0 0
43541- 0 0 0 0 0 0 0 0 0 0 0 0
43542- 0 0 0 0 0 0 0 0 1 0 0 0
43543- 0 0 1 0 0 1 0 0 1 0 0 0
43544- 0 0 0 0 0 0 0 0 0 0 0 0
43545- 0 0 0 0 0 0 0 0 0 0 0 0
43546- 0 0 0 0 0 0 0 0 0 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 14 14 14
43549- 42 42 42 86 86 86 6 6 6 116 116 116
43550-106 106 106 6 6 6 70 70 70 149 149 149
43551-128 128 128 18 18 18 38 38 38 54 54 54
43552-221 221 221 106 106 106 2 2 6 14 14 14
43553- 46 46 46 190 190 190 198 198 198 2 2 6
43554- 2 2 6 2 2 6 2 2 6 2 2 6
43555- 74 74 74 62 62 62 22 22 22 6 6 6
43556- 0 0 0 0 0 0 0 0 0 0 0 0
43557- 0 0 0 0 0 0 0 0 0 0 0 0
43558- 0 0 0 0 0 0 0 0 0 0 0 0
43559- 0 0 0 0 0 0 0 0 0 0 0 0
43560- 0 0 0 0 0 0 0 0 0 0 0 0
43561- 0 0 0 0 0 0 0 0 0 0 0 0
43562- 0 0 0 0 0 0 0 0 1 0 0 0
43563- 0 0 1 0 0 0 0 0 1 0 0 0
43564- 0 0 0 0 0 0 0 0 0 0 0 0
43565- 0 0 0 0 0 0 0 0 0 0 0 0
43566- 0 0 0 0 0 0 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 14 14 14
43569- 42 42 42 94 94 94 14 14 14 101 101 101
43570-128 128 128 2 2 6 18 18 18 116 116 116
43571-118 98 46 121 92 8 121 92 8 98 78 10
43572-162 162 162 106 106 106 2 2 6 2 2 6
43573- 2 2 6 195 195 195 195 195 195 6 6 6
43574- 2 2 6 2 2 6 2 2 6 2 2 6
43575- 74 74 74 62 62 62 22 22 22 6 6 6
43576- 0 0 0 0 0 0 0 0 0 0 0 0
43577- 0 0 0 0 0 0 0 0 0 0 0 0
43578- 0 0 0 0 0 0 0 0 0 0 0 0
43579- 0 0 0 0 0 0 0 0 0 0 0 0
43580- 0 0 0 0 0 0 0 0 0 0 0 0
43581- 0 0 0 0 0 0 0 0 0 0 0 0
43582- 0 0 0 0 0 0 0 0 1 0 0 1
43583- 0 0 1 0 0 0 0 0 1 0 0 0
43584- 0 0 0 0 0 0 0 0 0 0 0 0
43585- 0 0 0 0 0 0 0 0 0 0 0 0
43586- 0 0 0 0 0 0 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 10 10 10
43589- 38 38 38 90 90 90 14 14 14 58 58 58
43590-210 210 210 26 26 26 54 38 6 154 114 10
43591-226 170 11 236 186 11 225 175 15 184 144 12
43592-215 174 15 175 146 61 37 26 9 2 2 6
43593- 70 70 70 246 246 246 138 138 138 2 2 6
43594- 2 2 6 2 2 6 2 2 6 2 2 6
43595- 70 70 70 66 66 66 26 26 26 6 6 6
43596- 0 0 0 0 0 0 0 0 0 0 0 0
43597- 0 0 0 0 0 0 0 0 0 0 0 0
43598- 0 0 0 0 0 0 0 0 0 0 0 0
43599- 0 0 0 0 0 0 0 0 0 0 0 0
43600- 0 0 0 0 0 0 0 0 0 0 0 0
43601- 0 0 0 0 0 0 0 0 0 0 0 0
43602- 0 0 0 0 0 0 0 0 0 0 0 0
43603- 0 0 0 0 0 0 0 0 0 0 0 0
43604- 0 0 0 0 0 0 0 0 0 0 0 0
43605- 0 0 0 0 0 0 0 0 0 0 0 0
43606- 0 0 0 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 10 10 10
43609- 38 38 38 86 86 86 14 14 14 10 10 10
43610-195 195 195 188 164 115 192 133 9 225 175 15
43611-239 182 13 234 190 10 232 195 16 232 200 30
43612-245 207 45 241 208 19 232 195 16 184 144 12
43613-218 194 134 211 206 186 42 42 42 2 2 6
43614- 2 2 6 2 2 6 2 2 6 2 2 6
43615- 50 50 50 74 74 74 30 30 30 6 6 6
43616- 0 0 0 0 0 0 0 0 0 0 0 0
43617- 0 0 0 0 0 0 0 0 0 0 0 0
43618- 0 0 0 0 0 0 0 0 0 0 0 0
43619- 0 0 0 0 0 0 0 0 0 0 0 0
43620- 0 0 0 0 0 0 0 0 0 0 0 0
43621- 0 0 0 0 0 0 0 0 0 0 0 0
43622- 0 0 0 0 0 0 0 0 0 0 0 0
43623- 0 0 0 0 0 0 0 0 0 0 0 0
43624- 0 0 0 0 0 0 0 0 0 0 0 0
43625- 0 0 0 0 0 0 0 0 0 0 0 0
43626- 0 0 0 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 10 10 10
43629- 34 34 34 86 86 86 14 14 14 2 2 6
43630-121 87 25 192 133 9 219 162 10 239 182 13
43631-236 186 11 232 195 16 241 208 19 244 214 54
43632-246 218 60 246 218 38 246 215 20 241 208 19
43633-241 208 19 226 184 13 121 87 25 2 2 6
43634- 2 2 6 2 2 6 2 2 6 2 2 6
43635- 50 50 50 82 82 82 34 34 34 10 10 10
43636- 0 0 0 0 0 0 0 0 0 0 0 0
43637- 0 0 0 0 0 0 0 0 0 0 0 0
43638- 0 0 0 0 0 0 0 0 0 0 0 0
43639- 0 0 0 0 0 0 0 0 0 0 0 0
43640- 0 0 0 0 0 0 0 0 0 0 0 0
43641- 0 0 0 0 0 0 0 0 0 0 0 0
43642- 0 0 0 0 0 0 0 0 0 0 0 0
43643- 0 0 0 0 0 0 0 0 0 0 0 0
43644- 0 0 0 0 0 0 0 0 0 0 0 0
43645- 0 0 0 0 0 0 0 0 0 0 0 0
43646- 0 0 0 0 0 0 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 10 10 10
43649- 34 34 34 82 82 82 30 30 30 61 42 6
43650-180 123 7 206 145 10 230 174 11 239 182 13
43651-234 190 10 238 202 15 241 208 19 246 218 74
43652-246 218 38 246 215 20 246 215 20 246 215 20
43653-226 184 13 215 174 15 184 144 12 6 6 6
43654- 2 2 6 2 2 6 2 2 6 2 2 6
43655- 26 26 26 94 94 94 42 42 42 14 14 14
43656- 0 0 0 0 0 0 0 0 0 0 0 0
43657- 0 0 0 0 0 0 0 0 0 0 0 0
43658- 0 0 0 0 0 0 0 0 0 0 0 0
43659- 0 0 0 0 0 0 0 0 0 0 0 0
43660- 0 0 0 0 0 0 0 0 0 0 0 0
43661- 0 0 0 0 0 0 0 0 0 0 0 0
43662- 0 0 0 0 0 0 0 0 0 0 0 0
43663- 0 0 0 0 0 0 0 0 0 0 0 0
43664- 0 0 0 0 0 0 0 0 0 0 0 0
43665- 0 0 0 0 0 0 0 0 0 0 0 0
43666- 0 0 0 0 0 0 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 10 10 10
43669- 30 30 30 78 78 78 50 50 50 104 69 6
43670-192 133 9 216 158 10 236 178 12 236 186 11
43671-232 195 16 241 208 19 244 214 54 245 215 43
43672-246 215 20 246 215 20 241 208 19 198 155 10
43673-200 144 11 216 158 10 156 118 10 2 2 6
43674- 2 2 6 2 2 6 2 2 6 2 2 6
43675- 6 6 6 90 90 90 54 54 54 18 18 18
43676- 6 6 6 0 0 0 0 0 0 0 0 0
43677- 0 0 0 0 0 0 0 0 0 0 0 0
43678- 0 0 0 0 0 0 0 0 0 0 0 0
43679- 0 0 0 0 0 0 0 0 0 0 0 0
43680- 0 0 0 0 0 0 0 0 0 0 0 0
43681- 0 0 0 0 0 0 0 0 0 0 0 0
43682- 0 0 0 0 0 0 0 0 0 0 0 0
43683- 0 0 0 0 0 0 0 0 0 0 0 0
43684- 0 0 0 0 0 0 0 0 0 0 0 0
43685- 0 0 0 0 0 0 0 0 0 0 0 0
43686- 0 0 0 0 0 0 0 0 0 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 10 10 10
43689- 30 30 30 78 78 78 46 46 46 22 22 22
43690-137 92 6 210 162 10 239 182 13 238 190 10
43691-238 202 15 241 208 19 246 215 20 246 215 20
43692-241 208 19 203 166 17 185 133 11 210 150 10
43693-216 158 10 210 150 10 102 78 10 2 2 6
43694- 6 6 6 54 54 54 14 14 14 2 2 6
43695- 2 2 6 62 62 62 74 74 74 30 30 30
43696- 10 10 10 0 0 0 0 0 0 0 0 0
43697- 0 0 0 0 0 0 0 0 0 0 0 0
43698- 0 0 0 0 0 0 0 0 0 0 0 0
43699- 0 0 0 0 0 0 0 0 0 0 0 0
43700- 0 0 0 0 0 0 0 0 0 0 0 0
43701- 0 0 0 0 0 0 0 0 0 0 0 0
43702- 0 0 0 0 0 0 0 0 0 0 0 0
43703- 0 0 0 0 0 0 0 0 0 0 0 0
43704- 0 0 0 0 0 0 0 0 0 0 0 0
43705- 0 0 0 0 0 0 0 0 0 0 0 0
43706- 0 0 0 0 0 0 0 0 0 0 0 0
43707- 0 0 0 0 0 0 0 0 0 0 0 0
43708- 0 0 0 0 0 0 0 0 0 10 10 10
43709- 34 34 34 78 78 78 50 50 50 6 6 6
43710- 94 70 30 139 102 15 190 146 13 226 184 13
43711-232 200 30 232 195 16 215 174 15 190 146 13
43712-168 122 10 192 133 9 210 150 10 213 154 11
43713-202 150 34 182 157 106 101 98 89 2 2 6
43714- 2 2 6 78 78 78 116 116 116 58 58 58
43715- 2 2 6 22 22 22 90 90 90 46 46 46
43716- 18 18 18 6 6 6 0 0 0 0 0 0
43717- 0 0 0 0 0 0 0 0 0 0 0 0
43718- 0 0 0 0 0 0 0 0 0 0 0 0
43719- 0 0 0 0 0 0 0 0 0 0 0 0
43720- 0 0 0 0 0 0 0 0 0 0 0 0
43721- 0 0 0 0 0 0 0 0 0 0 0 0
43722- 0 0 0 0 0 0 0 0 0 0 0 0
43723- 0 0 0 0 0 0 0 0 0 0 0 0
43724- 0 0 0 0 0 0 0 0 0 0 0 0
43725- 0 0 0 0 0 0 0 0 0 0 0 0
43726- 0 0 0 0 0 0 0 0 0 0 0 0
43727- 0 0 0 0 0 0 0 0 0 0 0 0
43728- 0 0 0 0 0 0 0 0 0 10 10 10
43729- 38 38 38 86 86 86 50 50 50 6 6 6
43730-128 128 128 174 154 114 156 107 11 168 122 10
43731-198 155 10 184 144 12 197 138 11 200 144 11
43732-206 145 10 206 145 10 197 138 11 188 164 115
43733-195 195 195 198 198 198 174 174 174 14 14 14
43734- 2 2 6 22 22 22 116 116 116 116 116 116
43735- 22 22 22 2 2 6 74 74 74 70 70 70
43736- 30 30 30 10 10 10 0 0 0 0 0 0
43737- 0 0 0 0 0 0 0 0 0 0 0 0
43738- 0 0 0 0 0 0 0 0 0 0 0 0
43739- 0 0 0 0 0 0 0 0 0 0 0 0
43740- 0 0 0 0 0 0 0 0 0 0 0 0
43741- 0 0 0 0 0 0 0 0 0 0 0 0
43742- 0 0 0 0 0 0 0 0 0 0 0 0
43743- 0 0 0 0 0 0 0 0 0 0 0 0
43744- 0 0 0 0 0 0 0 0 0 0 0 0
43745- 0 0 0 0 0 0 0 0 0 0 0 0
43746- 0 0 0 0 0 0 0 0 0 0 0 0
43747- 0 0 0 0 0 0 0 0 0 0 0 0
43748- 0 0 0 0 0 0 6 6 6 18 18 18
43749- 50 50 50 101 101 101 26 26 26 10 10 10
43750-138 138 138 190 190 190 174 154 114 156 107 11
43751-197 138 11 200 144 11 197 138 11 192 133 9
43752-180 123 7 190 142 34 190 178 144 187 187 187
43753-202 202 202 221 221 221 214 214 214 66 66 66
43754- 2 2 6 2 2 6 50 50 50 62 62 62
43755- 6 6 6 2 2 6 10 10 10 90 90 90
43756- 50 50 50 18 18 18 6 6 6 0 0 0
43757- 0 0 0 0 0 0 0 0 0 0 0 0
43758- 0 0 0 0 0 0 0 0 0 0 0 0
43759- 0 0 0 0 0 0 0 0 0 0 0 0
43760- 0 0 0 0 0 0 0 0 0 0 0 0
43761- 0 0 0 0 0 0 0 0 0 0 0 0
43762- 0 0 0 0 0 0 0 0 0 0 0 0
43763- 0 0 0 0 0 0 0 0 0 0 0 0
43764- 0 0 0 0 0 0 0 0 0 0 0 0
43765- 0 0 0 0 0 0 0 0 0 0 0 0
43766- 0 0 0 0 0 0 0 0 0 0 0 0
43767- 0 0 0 0 0 0 0 0 0 0 0 0
43768- 0 0 0 0 0 0 10 10 10 34 34 34
43769- 74 74 74 74 74 74 2 2 6 6 6 6
43770-144 144 144 198 198 198 190 190 190 178 166 146
43771-154 121 60 156 107 11 156 107 11 168 124 44
43772-174 154 114 187 187 187 190 190 190 210 210 210
43773-246 246 246 253 253 253 253 253 253 182 182 182
43774- 6 6 6 2 2 6 2 2 6 2 2 6
43775- 2 2 6 2 2 6 2 2 6 62 62 62
43776- 74 74 74 34 34 34 14 14 14 0 0 0
43777- 0 0 0 0 0 0 0 0 0 0 0 0
43778- 0 0 0 0 0 0 0 0 0 0 0 0
43779- 0 0 0 0 0 0 0 0 0 0 0 0
43780- 0 0 0 0 0 0 0 0 0 0 0 0
43781- 0 0 0 0 0 0 0 0 0 0 0 0
43782- 0 0 0 0 0 0 0 0 0 0 0 0
43783- 0 0 0 0 0 0 0 0 0 0 0 0
43784- 0 0 0 0 0 0 0 0 0 0 0 0
43785- 0 0 0 0 0 0 0 0 0 0 0 0
43786- 0 0 0 0 0 0 0 0 0 0 0 0
43787- 0 0 0 0 0 0 0 0 0 0 0 0
43788- 0 0 0 10 10 10 22 22 22 54 54 54
43789- 94 94 94 18 18 18 2 2 6 46 46 46
43790-234 234 234 221 221 221 190 190 190 190 190 190
43791-190 190 190 187 187 187 187 187 187 190 190 190
43792-190 190 190 195 195 195 214 214 214 242 242 242
43793-253 253 253 253 253 253 253 253 253 253 253 253
43794- 82 82 82 2 2 6 2 2 6 2 2 6
43795- 2 2 6 2 2 6 2 2 6 14 14 14
43796- 86 86 86 54 54 54 22 22 22 6 6 6
43797- 0 0 0 0 0 0 0 0 0 0 0 0
43798- 0 0 0 0 0 0 0 0 0 0 0 0
43799- 0 0 0 0 0 0 0 0 0 0 0 0
43800- 0 0 0 0 0 0 0 0 0 0 0 0
43801- 0 0 0 0 0 0 0 0 0 0 0 0
43802- 0 0 0 0 0 0 0 0 0 0 0 0
43803- 0 0 0 0 0 0 0 0 0 0 0 0
43804- 0 0 0 0 0 0 0 0 0 0 0 0
43805- 0 0 0 0 0 0 0 0 0 0 0 0
43806- 0 0 0 0 0 0 0 0 0 0 0 0
43807- 0 0 0 0 0 0 0 0 0 0 0 0
43808- 6 6 6 18 18 18 46 46 46 90 90 90
43809- 46 46 46 18 18 18 6 6 6 182 182 182
43810-253 253 253 246 246 246 206 206 206 190 190 190
43811-190 190 190 190 190 190 190 190 190 190 190 190
43812-206 206 206 231 231 231 250 250 250 253 253 253
43813-253 253 253 253 253 253 253 253 253 253 253 253
43814-202 202 202 14 14 14 2 2 6 2 2 6
43815- 2 2 6 2 2 6 2 2 6 2 2 6
43816- 42 42 42 86 86 86 42 42 42 18 18 18
43817- 6 6 6 0 0 0 0 0 0 0 0 0
43818- 0 0 0 0 0 0 0 0 0 0 0 0
43819- 0 0 0 0 0 0 0 0 0 0 0 0
43820- 0 0 0 0 0 0 0 0 0 0 0 0
43821- 0 0 0 0 0 0 0 0 0 0 0 0
43822- 0 0 0 0 0 0 0 0 0 0 0 0
43823- 0 0 0 0 0 0 0 0 0 0 0 0
43824- 0 0 0 0 0 0 0 0 0 0 0 0
43825- 0 0 0 0 0 0 0 0 0 0 0 0
43826- 0 0 0 0 0 0 0 0 0 0 0 0
43827- 0 0 0 0 0 0 0 0 0 6 6 6
43828- 14 14 14 38 38 38 74 74 74 66 66 66
43829- 2 2 6 6 6 6 90 90 90 250 250 250
43830-253 253 253 253 253 253 238 238 238 198 198 198
43831-190 190 190 190 190 190 195 195 195 221 221 221
43832-246 246 246 253 253 253 253 253 253 253 253 253
43833-253 253 253 253 253 253 253 253 253 253 253 253
43834-253 253 253 82 82 82 2 2 6 2 2 6
43835- 2 2 6 2 2 6 2 2 6 2 2 6
43836- 2 2 6 78 78 78 70 70 70 34 34 34
43837- 14 14 14 6 6 6 0 0 0 0 0 0
43838- 0 0 0 0 0 0 0 0 0 0 0 0
43839- 0 0 0 0 0 0 0 0 0 0 0 0
43840- 0 0 0 0 0 0 0 0 0 0 0 0
43841- 0 0 0 0 0 0 0 0 0 0 0 0
43842- 0 0 0 0 0 0 0 0 0 0 0 0
43843- 0 0 0 0 0 0 0 0 0 0 0 0
43844- 0 0 0 0 0 0 0 0 0 0 0 0
43845- 0 0 0 0 0 0 0 0 0 0 0 0
43846- 0 0 0 0 0 0 0 0 0 0 0 0
43847- 0 0 0 0 0 0 0 0 0 14 14 14
43848- 34 34 34 66 66 66 78 78 78 6 6 6
43849- 2 2 6 18 18 18 218 218 218 253 253 253
43850-253 253 253 253 253 253 253 253 253 246 246 246
43851-226 226 226 231 231 231 246 246 246 253 253 253
43852-253 253 253 253 253 253 253 253 253 253 253 253
43853-253 253 253 253 253 253 253 253 253 253 253 253
43854-253 253 253 178 178 178 2 2 6 2 2 6
43855- 2 2 6 2 2 6 2 2 6 2 2 6
43856- 2 2 6 18 18 18 90 90 90 62 62 62
43857- 30 30 30 10 10 10 0 0 0 0 0 0
43858- 0 0 0 0 0 0 0 0 0 0 0 0
43859- 0 0 0 0 0 0 0 0 0 0 0 0
43860- 0 0 0 0 0 0 0 0 0 0 0 0
43861- 0 0 0 0 0 0 0 0 0 0 0 0
43862- 0 0 0 0 0 0 0 0 0 0 0 0
43863- 0 0 0 0 0 0 0 0 0 0 0 0
43864- 0 0 0 0 0 0 0 0 0 0 0 0
43865- 0 0 0 0 0 0 0 0 0 0 0 0
43866- 0 0 0 0 0 0 0 0 0 0 0 0
43867- 0 0 0 0 0 0 10 10 10 26 26 26
43868- 58 58 58 90 90 90 18 18 18 2 2 6
43869- 2 2 6 110 110 110 253 253 253 253 253 253
43870-253 253 253 253 253 253 253 253 253 253 253 253
43871-250 250 250 253 253 253 253 253 253 253 253 253
43872-253 253 253 253 253 253 253 253 253 253 253 253
43873-253 253 253 253 253 253 253 253 253 253 253 253
43874-253 253 253 231 231 231 18 18 18 2 2 6
43875- 2 2 6 2 2 6 2 2 6 2 2 6
43876- 2 2 6 2 2 6 18 18 18 94 94 94
43877- 54 54 54 26 26 26 10 10 10 0 0 0
43878- 0 0 0 0 0 0 0 0 0 0 0 0
43879- 0 0 0 0 0 0 0 0 0 0 0 0
43880- 0 0 0 0 0 0 0 0 0 0 0 0
43881- 0 0 0 0 0 0 0 0 0 0 0 0
43882- 0 0 0 0 0 0 0 0 0 0 0 0
43883- 0 0 0 0 0 0 0 0 0 0 0 0
43884- 0 0 0 0 0 0 0 0 0 0 0 0
43885- 0 0 0 0 0 0 0 0 0 0 0 0
43886- 0 0 0 0 0 0 0 0 0 0 0 0
43887- 0 0 0 6 6 6 22 22 22 50 50 50
43888- 90 90 90 26 26 26 2 2 6 2 2 6
43889- 14 14 14 195 195 195 250 250 250 253 253 253
43890-253 253 253 253 253 253 253 253 253 253 253 253
43891-253 253 253 253 253 253 253 253 253 253 253 253
43892-253 253 253 253 253 253 253 253 253 253 253 253
43893-253 253 253 253 253 253 253 253 253 253 253 253
43894-250 250 250 242 242 242 54 54 54 2 2 6
43895- 2 2 6 2 2 6 2 2 6 2 2 6
43896- 2 2 6 2 2 6 2 2 6 38 38 38
43897- 86 86 86 50 50 50 22 22 22 6 6 6
43898- 0 0 0 0 0 0 0 0 0 0 0 0
43899- 0 0 0 0 0 0 0 0 0 0 0 0
43900- 0 0 0 0 0 0 0 0 0 0 0 0
43901- 0 0 0 0 0 0 0 0 0 0 0 0
43902- 0 0 0 0 0 0 0 0 0 0 0 0
43903- 0 0 0 0 0 0 0 0 0 0 0 0
43904- 0 0 0 0 0 0 0 0 0 0 0 0
43905- 0 0 0 0 0 0 0 0 0 0 0 0
43906- 0 0 0 0 0 0 0 0 0 0 0 0
43907- 6 6 6 14 14 14 38 38 38 82 82 82
43908- 34 34 34 2 2 6 2 2 6 2 2 6
43909- 42 42 42 195 195 195 246 246 246 253 253 253
43910-253 253 253 253 253 253 253 253 253 250 250 250
43911-242 242 242 242 242 242 250 250 250 253 253 253
43912-253 253 253 253 253 253 253 253 253 253 253 253
43913-253 253 253 250 250 250 246 246 246 238 238 238
43914-226 226 226 231 231 231 101 101 101 6 6 6
43915- 2 2 6 2 2 6 2 2 6 2 2 6
43916- 2 2 6 2 2 6 2 2 6 2 2 6
43917- 38 38 38 82 82 82 42 42 42 14 14 14
43918- 6 6 6 0 0 0 0 0 0 0 0 0
43919- 0 0 0 0 0 0 0 0 0 0 0 0
43920- 0 0 0 0 0 0 0 0 0 0 0 0
43921- 0 0 0 0 0 0 0 0 0 0 0 0
43922- 0 0 0 0 0 0 0 0 0 0 0 0
43923- 0 0 0 0 0 0 0 0 0 0 0 0
43924- 0 0 0 0 0 0 0 0 0 0 0 0
43925- 0 0 0 0 0 0 0 0 0 0 0 0
43926- 0 0 0 0 0 0 0 0 0 0 0 0
43927- 10 10 10 26 26 26 62 62 62 66 66 66
43928- 2 2 6 2 2 6 2 2 6 6 6 6
43929- 70 70 70 170 170 170 206 206 206 234 234 234
43930-246 246 246 250 250 250 250 250 250 238 238 238
43931-226 226 226 231 231 231 238 238 238 250 250 250
43932-250 250 250 250 250 250 246 246 246 231 231 231
43933-214 214 214 206 206 206 202 202 202 202 202 202
43934-198 198 198 202 202 202 182 182 182 18 18 18
43935- 2 2 6 2 2 6 2 2 6 2 2 6
43936- 2 2 6 2 2 6 2 2 6 2 2 6
43937- 2 2 6 62 62 62 66 66 66 30 30 30
43938- 10 10 10 0 0 0 0 0 0 0 0 0
43939- 0 0 0 0 0 0 0 0 0 0 0 0
43940- 0 0 0 0 0 0 0 0 0 0 0 0
43941- 0 0 0 0 0 0 0 0 0 0 0 0
43942- 0 0 0 0 0 0 0 0 0 0 0 0
43943- 0 0 0 0 0 0 0 0 0 0 0 0
43944- 0 0 0 0 0 0 0 0 0 0 0 0
43945- 0 0 0 0 0 0 0 0 0 0 0 0
43946- 0 0 0 0 0 0 0 0 0 0 0 0
43947- 14 14 14 42 42 42 82 82 82 18 18 18
43948- 2 2 6 2 2 6 2 2 6 10 10 10
43949- 94 94 94 182 182 182 218 218 218 242 242 242
43950-250 250 250 253 253 253 253 253 253 250 250 250
43951-234 234 234 253 253 253 253 253 253 253 253 253
43952-253 253 253 253 253 253 253 253 253 246 246 246
43953-238 238 238 226 226 226 210 210 210 202 202 202
43954-195 195 195 195 195 195 210 210 210 158 158 158
43955- 6 6 6 14 14 14 50 50 50 14 14 14
43956- 2 2 6 2 2 6 2 2 6 2 2 6
43957- 2 2 6 6 6 6 86 86 86 46 46 46
43958- 18 18 18 6 6 6 0 0 0 0 0 0
43959- 0 0 0 0 0 0 0 0 0 0 0 0
43960- 0 0 0 0 0 0 0 0 0 0 0 0
43961- 0 0 0 0 0 0 0 0 0 0 0 0
43962- 0 0 0 0 0 0 0 0 0 0 0 0
43963- 0 0 0 0 0 0 0 0 0 0 0 0
43964- 0 0 0 0 0 0 0 0 0 0 0 0
43965- 0 0 0 0 0 0 0 0 0 0 0 0
43966- 0 0 0 0 0 0 0 0 0 6 6 6
43967- 22 22 22 54 54 54 70 70 70 2 2 6
43968- 2 2 6 10 10 10 2 2 6 22 22 22
43969-166 166 166 231 231 231 250 250 250 253 253 253
43970-253 253 253 253 253 253 253 253 253 250 250 250
43971-242 242 242 253 253 253 253 253 253 253 253 253
43972-253 253 253 253 253 253 253 253 253 253 253 253
43973-253 253 253 253 253 253 253 253 253 246 246 246
43974-231 231 231 206 206 206 198 198 198 226 226 226
43975- 94 94 94 2 2 6 6 6 6 38 38 38
43976- 30 30 30 2 2 6 2 2 6 2 2 6
43977- 2 2 6 2 2 6 62 62 62 66 66 66
43978- 26 26 26 10 10 10 0 0 0 0 0 0
43979- 0 0 0 0 0 0 0 0 0 0 0 0
43980- 0 0 0 0 0 0 0 0 0 0 0 0
43981- 0 0 0 0 0 0 0 0 0 0 0 0
43982- 0 0 0 0 0 0 0 0 0 0 0 0
43983- 0 0 0 0 0 0 0 0 0 0 0 0
43984- 0 0 0 0 0 0 0 0 0 0 0 0
43985- 0 0 0 0 0 0 0 0 0 0 0 0
43986- 0 0 0 0 0 0 0 0 0 10 10 10
43987- 30 30 30 74 74 74 50 50 50 2 2 6
43988- 26 26 26 26 26 26 2 2 6 106 106 106
43989-238 238 238 253 253 253 253 253 253 253 253 253
43990-253 253 253 253 253 253 253 253 253 253 253 253
43991-253 253 253 253 253 253 253 253 253 253 253 253
43992-253 253 253 253 253 253 253 253 253 253 253 253
43993-253 253 253 253 253 253 253 253 253 253 253 253
43994-253 253 253 246 246 246 218 218 218 202 202 202
43995-210 210 210 14 14 14 2 2 6 2 2 6
43996- 30 30 30 22 22 22 2 2 6 2 2 6
43997- 2 2 6 2 2 6 18 18 18 86 86 86
43998- 42 42 42 14 14 14 0 0 0 0 0 0
43999- 0 0 0 0 0 0 0 0 0 0 0 0
44000- 0 0 0 0 0 0 0 0 0 0 0 0
44001- 0 0 0 0 0 0 0 0 0 0 0 0
44002- 0 0 0 0 0 0 0 0 0 0 0 0
44003- 0 0 0 0 0 0 0 0 0 0 0 0
44004- 0 0 0 0 0 0 0 0 0 0 0 0
44005- 0 0 0 0 0 0 0 0 0 0 0 0
44006- 0 0 0 0 0 0 0 0 0 14 14 14
44007- 42 42 42 90 90 90 22 22 22 2 2 6
44008- 42 42 42 2 2 6 18 18 18 218 218 218
44009-253 253 253 253 253 253 253 253 253 253 253 253
44010-253 253 253 253 253 253 253 253 253 253 253 253
44011-253 253 253 253 253 253 253 253 253 253 253 253
44012-253 253 253 253 253 253 253 253 253 253 253 253
44013-253 253 253 253 253 253 253 253 253 253 253 253
44014-253 253 253 253 253 253 250 250 250 221 221 221
44015-218 218 218 101 101 101 2 2 6 14 14 14
44016- 18 18 18 38 38 38 10 10 10 2 2 6
44017- 2 2 6 2 2 6 2 2 6 78 78 78
44018- 58 58 58 22 22 22 6 6 6 0 0 0
44019- 0 0 0 0 0 0 0 0 0 0 0 0
44020- 0 0 0 0 0 0 0 0 0 0 0 0
44021- 0 0 0 0 0 0 0 0 0 0 0 0
44022- 0 0 0 0 0 0 0 0 0 0 0 0
44023- 0 0 0 0 0 0 0 0 0 0 0 0
44024- 0 0 0 0 0 0 0 0 0 0 0 0
44025- 0 0 0 0 0 0 0 0 0 0 0 0
44026- 0 0 0 0 0 0 6 6 6 18 18 18
44027- 54 54 54 82 82 82 2 2 6 26 26 26
44028- 22 22 22 2 2 6 123 123 123 253 253 253
44029-253 253 253 253 253 253 253 253 253 253 253 253
44030-253 253 253 253 253 253 253 253 253 253 253 253
44031-253 253 253 253 253 253 253 253 253 253 253 253
44032-253 253 253 253 253 253 253 253 253 253 253 253
44033-253 253 253 253 253 253 253 253 253 253 253 253
44034-253 253 253 253 253 253 253 253 253 250 250 250
44035-238 238 238 198 198 198 6 6 6 38 38 38
44036- 58 58 58 26 26 26 38 38 38 2 2 6
44037- 2 2 6 2 2 6 2 2 6 46 46 46
44038- 78 78 78 30 30 30 10 10 10 0 0 0
44039- 0 0 0 0 0 0 0 0 0 0 0 0
44040- 0 0 0 0 0 0 0 0 0 0 0 0
44041- 0 0 0 0 0 0 0 0 0 0 0 0
44042- 0 0 0 0 0 0 0 0 0 0 0 0
44043- 0 0 0 0 0 0 0 0 0 0 0 0
44044- 0 0 0 0 0 0 0 0 0 0 0 0
44045- 0 0 0 0 0 0 0 0 0 0 0 0
44046- 0 0 0 0 0 0 10 10 10 30 30 30
44047- 74 74 74 58 58 58 2 2 6 42 42 42
44048- 2 2 6 22 22 22 231 231 231 253 253 253
44049-253 253 253 253 253 253 253 253 253 253 253 253
44050-253 253 253 253 253 253 253 253 253 250 250 250
44051-253 253 253 253 253 253 253 253 253 253 253 253
44052-253 253 253 253 253 253 253 253 253 253 253 253
44053-253 253 253 253 253 253 253 253 253 253 253 253
44054-253 253 253 253 253 253 253 253 253 253 253 253
44055-253 253 253 246 246 246 46 46 46 38 38 38
44056- 42 42 42 14 14 14 38 38 38 14 14 14
44057- 2 2 6 2 2 6 2 2 6 6 6 6
44058- 86 86 86 46 46 46 14 14 14 0 0 0
44059- 0 0 0 0 0 0 0 0 0 0 0 0
44060- 0 0 0 0 0 0 0 0 0 0 0 0
44061- 0 0 0 0 0 0 0 0 0 0 0 0
44062- 0 0 0 0 0 0 0 0 0 0 0 0
44063- 0 0 0 0 0 0 0 0 0 0 0 0
44064- 0 0 0 0 0 0 0 0 0 0 0 0
44065- 0 0 0 0 0 0 0 0 0 0 0 0
44066- 0 0 0 6 6 6 14 14 14 42 42 42
44067- 90 90 90 18 18 18 18 18 18 26 26 26
44068- 2 2 6 116 116 116 253 253 253 253 253 253
44069-253 253 253 253 253 253 253 253 253 253 253 253
44070-253 253 253 253 253 253 250 250 250 238 238 238
44071-253 253 253 253 253 253 253 253 253 253 253 253
44072-253 253 253 253 253 253 253 253 253 253 253 253
44073-253 253 253 253 253 253 253 253 253 253 253 253
44074-253 253 253 253 253 253 253 253 253 253 253 253
44075-253 253 253 253 253 253 94 94 94 6 6 6
44076- 2 2 6 2 2 6 10 10 10 34 34 34
44077- 2 2 6 2 2 6 2 2 6 2 2 6
44078- 74 74 74 58 58 58 22 22 22 6 6 6
44079- 0 0 0 0 0 0 0 0 0 0 0 0
44080- 0 0 0 0 0 0 0 0 0 0 0 0
44081- 0 0 0 0 0 0 0 0 0 0 0 0
44082- 0 0 0 0 0 0 0 0 0 0 0 0
44083- 0 0 0 0 0 0 0 0 0 0 0 0
44084- 0 0 0 0 0 0 0 0 0 0 0 0
44085- 0 0 0 0 0 0 0 0 0 0 0 0
44086- 0 0 0 10 10 10 26 26 26 66 66 66
44087- 82 82 82 2 2 6 38 38 38 6 6 6
44088- 14 14 14 210 210 210 253 253 253 253 253 253
44089-253 253 253 253 253 253 253 253 253 253 253 253
44090-253 253 253 253 253 253 246 246 246 242 242 242
44091-253 253 253 253 253 253 253 253 253 253 253 253
44092-253 253 253 253 253 253 253 253 253 253 253 253
44093-253 253 253 253 253 253 253 253 253 253 253 253
44094-253 253 253 253 253 253 253 253 253 253 253 253
44095-253 253 253 253 253 253 144 144 144 2 2 6
44096- 2 2 6 2 2 6 2 2 6 46 46 46
44097- 2 2 6 2 2 6 2 2 6 2 2 6
44098- 42 42 42 74 74 74 30 30 30 10 10 10
44099- 0 0 0 0 0 0 0 0 0 0 0 0
44100- 0 0 0 0 0 0 0 0 0 0 0 0
44101- 0 0 0 0 0 0 0 0 0 0 0 0
44102- 0 0 0 0 0 0 0 0 0 0 0 0
44103- 0 0 0 0 0 0 0 0 0 0 0 0
44104- 0 0 0 0 0 0 0 0 0 0 0 0
44105- 0 0 0 0 0 0 0 0 0 0 0 0
44106- 6 6 6 14 14 14 42 42 42 90 90 90
44107- 26 26 26 6 6 6 42 42 42 2 2 6
44108- 74 74 74 250 250 250 253 253 253 253 253 253
44109-253 253 253 253 253 253 253 253 253 253 253 253
44110-253 253 253 253 253 253 242 242 242 242 242 242
44111-253 253 253 253 253 253 253 253 253 253 253 253
44112-253 253 253 253 253 253 253 253 253 253 253 253
44113-253 253 253 253 253 253 253 253 253 253 253 253
44114-253 253 253 253 253 253 253 253 253 253 253 253
44115-253 253 253 253 253 253 182 182 182 2 2 6
44116- 2 2 6 2 2 6 2 2 6 46 46 46
44117- 2 2 6 2 2 6 2 2 6 2 2 6
44118- 10 10 10 86 86 86 38 38 38 10 10 10
44119- 0 0 0 0 0 0 0 0 0 0 0 0
44120- 0 0 0 0 0 0 0 0 0 0 0 0
44121- 0 0 0 0 0 0 0 0 0 0 0 0
44122- 0 0 0 0 0 0 0 0 0 0 0 0
44123- 0 0 0 0 0 0 0 0 0 0 0 0
44124- 0 0 0 0 0 0 0 0 0 0 0 0
44125- 0 0 0 0 0 0 0 0 0 0 0 0
44126- 10 10 10 26 26 26 66 66 66 82 82 82
44127- 2 2 6 22 22 22 18 18 18 2 2 6
44128-149 149 149 253 253 253 253 253 253 253 253 253
44129-253 253 253 253 253 253 253 253 253 253 253 253
44130-253 253 253 253 253 253 234 234 234 242 242 242
44131-253 253 253 253 253 253 253 253 253 253 253 253
44132-253 253 253 253 253 253 253 253 253 253 253 253
44133-253 253 253 253 253 253 253 253 253 253 253 253
44134-253 253 253 253 253 253 253 253 253 253 253 253
44135-253 253 253 253 253 253 206 206 206 2 2 6
44136- 2 2 6 2 2 6 2 2 6 38 38 38
44137- 2 2 6 2 2 6 2 2 6 2 2 6
44138- 6 6 6 86 86 86 46 46 46 14 14 14
44139- 0 0 0 0 0 0 0 0 0 0 0 0
44140- 0 0 0 0 0 0 0 0 0 0 0 0
44141- 0 0 0 0 0 0 0 0 0 0 0 0
44142- 0 0 0 0 0 0 0 0 0 0 0 0
44143- 0 0 0 0 0 0 0 0 0 0 0 0
44144- 0 0 0 0 0 0 0 0 0 0 0 0
44145- 0 0 0 0 0 0 0 0 0 6 6 6
44146- 18 18 18 46 46 46 86 86 86 18 18 18
44147- 2 2 6 34 34 34 10 10 10 6 6 6
44148-210 210 210 253 253 253 253 253 253 253 253 253
44149-253 253 253 253 253 253 253 253 253 253 253 253
44150-253 253 253 253 253 253 234 234 234 242 242 242
44151-253 253 253 253 253 253 253 253 253 253 253 253
44152-253 253 253 253 253 253 253 253 253 253 253 253
44153-253 253 253 253 253 253 253 253 253 253 253 253
44154-253 253 253 253 253 253 253 253 253 253 253 253
44155-253 253 253 253 253 253 221 221 221 6 6 6
44156- 2 2 6 2 2 6 6 6 6 30 30 30
44157- 2 2 6 2 2 6 2 2 6 2 2 6
44158- 2 2 6 82 82 82 54 54 54 18 18 18
44159- 6 6 6 0 0 0 0 0 0 0 0 0
44160- 0 0 0 0 0 0 0 0 0 0 0 0
44161- 0 0 0 0 0 0 0 0 0 0 0 0
44162- 0 0 0 0 0 0 0 0 0 0 0 0
44163- 0 0 0 0 0 0 0 0 0 0 0 0
44164- 0 0 0 0 0 0 0 0 0 0 0 0
44165- 0 0 0 0 0 0 0 0 0 10 10 10
44166- 26 26 26 66 66 66 62 62 62 2 2 6
44167- 2 2 6 38 38 38 10 10 10 26 26 26
44168-238 238 238 253 253 253 253 253 253 253 253 253
44169-253 253 253 253 253 253 253 253 253 253 253 253
44170-253 253 253 253 253 253 231 231 231 238 238 238
44171-253 253 253 253 253 253 253 253 253 253 253 253
44172-253 253 253 253 253 253 253 253 253 253 253 253
44173-253 253 253 253 253 253 253 253 253 253 253 253
44174-253 253 253 253 253 253 253 253 253 253 253 253
44175-253 253 253 253 253 253 231 231 231 6 6 6
44176- 2 2 6 2 2 6 10 10 10 30 30 30
44177- 2 2 6 2 2 6 2 2 6 2 2 6
44178- 2 2 6 66 66 66 58 58 58 22 22 22
44179- 6 6 6 0 0 0 0 0 0 0 0 0
44180- 0 0 0 0 0 0 0 0 0 0 0 0
44181- 0 0 0 0 0 0 0 0 0 0 0 0
44182- 0 0 0 0 0 0 0 0 0 0 0 0
44183- 0 0 0 0 0 0 0 0 0 0 0 0
44184- 0 0 0 0 0 0 0 0 0 0 0 0
44185- 0 0 0 0 0 0 0 0 0 10 10 10
44186- 38 38 38 78 78 78 6 6 6 2 2 6
44187- 2 2 6 46 46 46 14 14 14 42 42 42
44188-246 246 246 253 253 253 253 253 253 253 253 253
44189-253 253 253 253 253 253 253 253 253 253 253 253
44190-253 253 253 253 253 253 231 231 231 242 242 242
44191-253 253 253 253 253 253 253 253 253 253 253 253
44192-253 253 253 253 253 253 253 253 253 253 253 253
44193-253 253 253 253 253 253 253 253 253 253 253 253
44194-253 253 253 253 253 253 253 253 253 253 253 253
44195-253 253 253 253 253 253 234 234 234 10 10 10
44196- 2 2 6 2 2 6 22 22 22 14 14 14
44197- 2 2 6 2 2 6 2 2 6 2 2 6
44198- 2 2 6 66 66 66 62 62 62 22 22 22
44199- 6 6 6 0 0 0 0 0 0 0 0 0
44200- 0 0 0 0 0 0 0 0 0 0 0 0
44201- 0 0 0 0 0 0 0 0 0 0 0 0
44202- 0 0 0 0 0 0 0 0 0 0 0 0
44203- 0 0 0 0 0 0 0 0 0 0 0 0
44204- 0 0 0 0 0 0 0 0 0 0 0 0
44205- 0 0 0 0 0 0 6 6 6 18 18 18
44206- 50 50 50 74 74 74 2 2 6 2 2 6
44207- 14 14 14 70 70 70 34 34 34 62 62 62
44208-250 250 250 253 253 253 253 253 253 253 253 253
44209-253 253 253 253 253 253 253 253 253 253 253 253
44210-253 253 253 253 253 253 231 231 231 246 246 246
44211-253 253 253 253 253 253 253 253 253 253 253 253
44212-253 253 253 253 253 253 253 253 253 253 253 253
44213-253 253 253 253 253 253 253 253 253 253 253 253
44214-253 253 253 253 253 253 253 253 253 253 253 253
44215-253 253 253 253 253 253 234 234 234 14 14 14
44216- 2 2 6 2 2 6 30 30 30 2 2 6
44217- 2 2 6 2 2 6 2 2 6 2 2 6
44218- 2 2 6 66 66 66 62 62 62 22 22 22
44219- 6 6 6 0 0 0 0 0 0 0 0 0
44220- 0 0 0 0 0 0 0 0 0 0 0 0
44221- 0 0 0 0 0 0 0 0 0 0 0 0
44222- 0 0 0 0 0 0 0 0 0 0 0 0
44223- 0 0 0 0 0 0 0 0 0 0 0 0
44224- 0 0 0 0 0 0 0 0 0 0 0 0
44225- 0 0 0 0 0 0 6 6 6 18 18 18
44226- 54 54 54 62 62 62 2 2 6 2 2 6
44227- 2 2 6 30 30 30 46 46 46 70 70 70
44228-250 250 250 253 253 253 253 253 253 253 253 253
44229-253 253 253 253 253 253 253 253 253 253 253 253
44230-253 253 253 253 253 253 231 231 231 246 246 246
44231-253 253 253 253 253 253 253 253 253 253 253 253
44232-253 253 253 253 253 253 253 253 253 253 253 253
44233-253 253 253 253 253 253 253 253 253 253 253 253
44234-253 253 253 253 253 253 253 253 253 253 253 253
44235-253 253 253 253 253 253 226 226 226 10 10 10
44236- 2 2 6 6 6 6 30 30 30 2 2 6
44237- 2 2 6 2 2 6 2 2 6 2 2 6
44238- 2 2 6 66 66 66 58 58 58 22 22 22
44239- 6 6 6 0 0 0 0 0 0 0 0 0
44240- 0 0 0 0 0 0 0 0 0 0 0 0
44241- 0 0 0 0 0 0 0 0 0 0 0 0
44242- 0 0 0 0 0 0 0 0 0 0 0 0
44243- 0 0 0 0 0 0 0 0 0 0 0 0
44244- 0 0 0 0 0 0 0 0 0 0 0 0
44245- 0 0 0 0 0 0 6 6 6 22 22 22
44246- 58 58 58 62 62 62 2 2 6 2 2 6
44247- 2 2 6 2 2 6 30 30 30 78 78 78
44248-250 250 250 253 253 253 253 253 253 253 253 253
44249-253 253 253 253 253 253 253 253 253 253 253 253
44250-253 253 253 253 253 253 231 231 231 246 246 246
44251-253 253 253 253 253 253 253 253 253 253 253 253
44252-253 253 253 253 253 253 253 253 253 253 253 253
44253-253 253 253 253 253 253 253 253 253 253 253 253
44254-253 253 253 253 253 253 253 253 253 253 253 253
44255-253 253 253 253 253 253 206 206 206 2 2 6
44256- 22 22 22 34 34 34 18 14 6 22 22 22
44257- 26 26 26 18 18 18 6 6 6 2 2 6
44258- 2 2 6 82 82 82 54 54 54 18 18 18
44259- 6 6 6 0 0 0 0 0 0 0 0 0
44260- 0 0 0 0 0 0 0 0 0 0 0 0
44261- 0 0 0 0 0 0 0 0 0 0 0 0
44262- 0 0 0 0 0 0 0 0 0 0 0 0
44263- 0 0 0 0 0 0 0 0 0 0 0 0
44264- 0 0 0 0 0 0 0 0 0 0 0 0
44265- 0 0 0 0 0 0 6 6 6 26 26 26
44266- 62 62 62 106 106 106 74 54 14 185 133 11
44267-210 162 10 121 92 8 6 6 6 62 62 62
44268-238 238 238 253 253 253 253 253 253 253 253 253
44269-253 253 253 253 253 253 253 253 253 253 253 253
44270-253 253 253 253 253 253 231 231 231 246 246 246
44271-253 253 253 253 253 253 253 253 253 253 253 253
44272-253 253 253 253 253 253 253 253 253 253 253 253
44273-253 253 253 253 253 253 253 253 253 253 253 253
44274-253 253 253 253 253 253 253 253 253 253 253 253
44275-253 253 253 253 253 253 158 158 158 18 18 18
44276- 14 14 14 2 2 6 2 2 6 2 2 6
44277- 6 6 6 18 18 18 66 66 66 38 38 38
44278- 6 6 6 94 94 94 50 50 50 18 18 18
44279- 6 6 6 0 0 0 0 0 0 0 0 0
44280- 0 0 0 0 0 0 0 0 0 0 0 0
44281- 0 0 0 0 0 0 0 0 0 0 0 0
44282- 0 0 0 0 0 0 0 0 0 0 0 0
44283- 0 0 0 0 0 0 0 0 0 0 0 0
44284- 0 0 0 0 0 0 0 0 0 6 6 6
44285- 10 10 10 10 10 10 18 18 18 38 38 38
44286- 78 78 78 142 134 106 216 158 10 242 186 14
44287-246 190 14 246 190 14 156 118 10 10 10 10
44288- 90 90 90 238 238 238 253 253 253 253 253 253
44289-253 253 253 253 253 253 253 253 253 253 253 253
44290-253 253 253 253 253 253 231 231 231 250 250 250
44291-253 253 253 253 253 253 253 253 253 253 253 253
44292-253 253 253 253 253 253 253 253 253 253 253 253
44293-253 253 253 253 253 253 253 253 253 253 253 253
44294-253 253 253 253 253 253 253 253 253 246 230 190
44295-238 204 91 238 204 91 181 142 44 37 26 9
44296- 2 2 6 2 2 6 2 2 6 2 2 6
44297- 2 2 6 2 2 6 38 38 38 46 46 46
44298- 26 26 26 106 106 106 54 54 54 18 18 18
44299- 6 6 6 0 0 0 0 0 0 0 0 0
44300- 0 0 0 0 0 0 0 0 0 0 0 0
44301- 0 0 0 0 0 0 0 0 0 0 0 0
44302- 0 0 0 0 0 0 0 0 0 0 0 0
44303- 0 0 0 0 0 0 0 0 0 0 0 0
44304- 0 0 0 6 6 6 14 14 14 22 22 22
44305- 30 30 30 38 38 38 50 50 50 70 70 70
44306-106 106 106 190 142 34 226 170 11 242 186 14
44307-246 190 14 246 190 14 246 190 14 154 114 10
44308- 6 6 6 74 74 74 226 226 226 253 253 253
44309-253 253 253 253 253 253 253 253 253 253 253 253
44310-253 253 253 253 253 253 231 231 231 250 250 250
44311-253 253 253 253 253 253 253 253 253 253 253 253
44312-253 253 253 253 253 253 253 253 253 253 253 253
44313-253 253 253 253 253 253 253 253 253 253 253 253
44314-253 253 253 253 253 253 253 253 253 228 184 62
44315-241 196 14 241 208 19 232 195 16 38 30 10
44316- 2 2 6 2 2 6 2 2 6 2 2 6
44317- 2 2 6 6 6 6 30 30 30 26 26 26
44318-203 166 17 154 142 90 66 66 66 26 26 26
44319- 6 6 6 0 0 0 0 0 0 0 0 0
44320- 0 0 0 0 0 0 0 0 0 0 0 0
44321- 0 0 0 0 0 0 0 0 0 0 0 0
44322- 0 0 0 0 0 0 0 0 0 0 0 0
44323- 0 0 0 0 0 0 0 0 0 0 0 0
44324- 6 6 6 18 18 18 38 38 38 58 58 58
44325- 78 78 78 86 86 86 101 101 101 123 123 123
44326-175 146 61 210 150 10 234 174 13 246 186 14
44327-246 190 14 246 190 14 246 190 14 238 190 10
44328-102 78 10 2 2 6 46 46 46 198 198 198
44329-253 253 253 253 253 253 253 253 253 253 253 253
44330-253 253 253 253 253 253 234 234 234 242 242 242
44331-253 253 253 253 253 253 253 253 253 253 253 253
44332-253 253 253 253 253 253 253 253 253 253 253 253
44333-253 253 253 253 253 253 253 253 253 253 253 253
44334-253 253 253 253 253 253 253 253 253 224 178 62
44335-242 186 14 241 196 14 210 166 10 22 18 6
44336- 2 2 6 2 2 6 2 2 6 2 2 6
44337- 2 2 6 2 2 6 6 6 6 121 92 8
44338-238 202 15 232 195 16 82 82 82 34 34 34
44339- 10 10 10 0 0 0 0 0 0 0 0 0
44340- 0 0 0 0 0 0 0 0 0 0 0 0
44341- 0 0 0 0 0 0 0 0 0 0 0 0
44342- 0 0 0 0 0 0 0 0 0 0 0 0
44343- 0 0 0 0 0 0 0 0 0 0 0 0
44344- 14 14 14 38 38 38 70 70 70 154 122 46
44345-190 142 34 200 144 11 197 138 11 197 138 11
44346-213 154 11 226 170 11 242 186 14 246 190 14
44347-246 190 14 246 190 14 246 190 14 246 190 14
44348-225 175 15 46 32 6 2 2 6 22 22 22
44349-158 158 158 250 250 250 253 253 253 253 253 253
44350-253 253 253 253 253 253 253 253 253 253 253 253
44351-253 253 253 253 253 253 253 253 253 253 253 253
44352-253 253 253 253 253 253 253 253 253 253 253 253
44353-253 253 253 253 253 253 253 253 253 253 253 253
44354-253 253 253 250 250 250 242 242 242 224 178 62
44355-239 182 13 236 186 11 213 154 11 46 32 6
44356- 2 2 6 2 2 6 2 2 6 2 2 6
44357- 2 2 6 2 2 6 61 42 6 225 175 15
44358-238 190 10 236 186 11 112 100 78 42 42 42
44359- 14 14 14 0 0 0 0 0 0 0 0 0
44360- 0 0 0 0 0 0 0 0 0 0 0 0
44361- 0 0 0 0 0 0 0 0 0 0 0 0
44362- 0 0 0 0 0 0 0 0 0 0 0 0
44363- 0 0 0 0 0 0 0 0 0 6 6 6
44364- 22 22 22 54 54 54 154 122 46 213 154 11
44365-226 170 11 230 174 11 226 170 11 226 170 11
44366-236 178 12 242 186 14 246 190 14 246 190 14
44367-246 190 14 246 190 14 246 190 14 246 190 14
44368-241 196 14 184 144 12 10 10 10 2 2 6
44369- 6 6 6 116 116 116 242 242 242 253 253 253
44370-253 253 253 253 253 253 253 253 253 253 253 253
44371-253 253 253 253 253 253 253 253 253 253 253 253
44372-253 253 253 253 253 253 253 253 253 253 253 253
44373-253 253 253 253 253 253 253 253 253 253 253 253
44374-253 253 253 231 231 231 198 198 198 214 170 54
44375-236 178 12 236 178 12 210 150 10 137 92 6
44376- 18 14 6 2 2 6 2 2 6 2 2 6
44377- 6 6 6 70 47 6 200 144 11 236 178 12
44378-239 182 13 239 182 13 124 112 88 58 58 58
44379- 22 22 22 6 6 6 0 0 0 0 0 0
44380- 0 0 0 0 0 0 0 0 0 0 0 0
44381- 0 0 0 0 0 0 0 0 0 0 0 0
44382- 0 0 0 0 0 0 0 0 0 0 0 0
44383- 0 0 0 0 0 0 0 0 0 10 10 10
44384- 30 30 30 70 70 70 180 133 36 226 170 11
44385-239 182 13 242 186 14 242 186 14 246 186 14
44386-246 190 14 246 190 14 246 190 14 246 190 14
44387-246 190 14 246 190 14 246 190 14 246 190 14
44388-246 190 14 232 195 16 98 70 6 2 2 6
44389- 2 2 6 2 2 6 66 66 66 221 221 221
44390-253 253 253 253 253 253 253 253 253 253 253 253
44391-253 253 253 253 253 253 253 253 253 253 253 253
44392-253 253 253 253 253 253 253 253 253 253 253 253
44393-253 253 253 253 253 253 253 253 253 253 253 253
44394-253 253 253 206 206 206 198 198 198 214 166 58
44395-230 174 11 230 174 11 216 158 10 192 133 9
44396-163 110 8 116 81 8 102 78 10 116 81 8
44397-167 114 7 197 138 11 226 170 11 239 182 13
44398-242 186 14 242 186 14 162 146 94 78 78 78
44399- 34 34 34 14 14 14 6 6 6 0 0 0
44400- 0 0 0 0 0 0 0 0 0 0 0 0
44401- 0 0 0 0 0 0 0 0 0 0 0 0
44402- 0 0 0 0 0 0 0 0 0 0 0 0
44403- 0 0 0 0 0 0 0 0 0 6 6 6
44404- 30 30 30 78 78 78 190 142 34 226 170 11
44405-239 182 13 246 190 14 246 190 14 246 190 14
44406-246 190 14 246 190 14 246 190 14 246 190 14
44407-246 190 14 246 190 14 246 190 14 246 190 14
44408-246 190 14 241 196 14 203 166 17 22 18 6
44409- 2 2 6 2 2 6 2 2 6 38 38 38
44410-218 218 218 253 253 253 253 253 253 253 253 253
44411-253 253 253 253 253 253 253 253 253 253 253 253
44412-253 253 253 253 253 253 253 253 253 253 253 253
44413-253 253 253 253 253 253 253 253 253 253 253 253
44414-250 250 250 206 206 206 198 198 198 202 162 69
44415-226 170 11 236 178 12 224 166 10 210 150 10
44416-200 144 11 197 138 11 192 133 9 197 138 11
44417-210 150 10 226 170 11 242 186 14 246 190 14
44418-246 190 14 246 186 14 225 175 15 124 112 88
44419- 62 62 62 30 30 30 14 14 14 6 6 6
44420- 0 0 0 0 0 0 0 0 0 0 0 0
44421- 0 0 0 0 0 0 0 0 0 0 0 0
44422- 0 0 0 0 0 0 0 0 0 0 0 0
44423- 0 0 0 0 0 0 0 0 0 10 10 10
44424- 30 30 30 78 78 78 174 135 50 224 166 10
44425-239 182 13 246 190 14 246 190 14 246 190 14
44426-246 190 14 246 190 14 246 190 14 246 190 14
44427-246 190 14 246 190 14 246 190 14 246 190 14
44428-246 190 14 246 190 14 241 196 14 139 102 15
44429- 2 2 6 2 2 6 2 2 6 2 2 6
44430- 78 78 78 250 250 250 253 253 253 253 253 253
44431-253 253 253 253 253 253 253 253 253 253 253 253
44432-253 253 253 253 253 253 253 253 253 253 253 253
44433-253 253 253 253 253 253 253 253 253 253 253 253
44434-250 250 250 214 214 214 198 198 198 190 150 46
44435-219 162 10 236 178 12 234 174 13 224 166 10
44436-216 158 10 213 154 11 213 154 11 216 158 10
44437-226 170 11 239 182 13 246 190 14 246 190 14
44438-246 190 14 246 190 14 242 186 14 206 162 42
44439-101 101 101 58 58 58 30 30 30 14 14 14
44440- 6 6 6 0 0 0 0 0 0 0 0 0
44441- 0 0 0 0 0 0 0 0 0 0 0 0
44442- 0 0 0 0 0 0 0 0 0 0 0 0
44443- 0 0 0 0 0 0 0 0 0 10 10 10
44444- 30 30 30 74 74 74 174 135 50 216 158 10
44445-236 178 12 246 190 14 246 190 14 246 190 14
44446-246 190 14 246 190 14 246 190 14 246 190 14
44447-246 190 14 246 190 14 246 190 14 246 190 14
44448-246 190 14 246 190 14 241 196 14 226 184 13
44449- 61 42 6 2 2 6 2 2 6 2 2 6
44450- 22 22 22 238 238 238 253 253 253 253 253 253
44451-253 253 253 253 253 253 253 253 253 253 253 253
44452-253 253 253 253 253 253 253 253 253 253 253 253
44453-253 253 253 253 253 253 253 253 253 253 253 253
44454-253 253 253 226 226 226 187 187 187 180 133 36
44455-216 158 10 236 178 12 239 182 13 236 178 12
44456-230 174 11 226 170 11 226 170 11 230 174 11
44457-236 178 12 242 186 14 246 190 14 246 190 14
44458-246 190 14 246 190 14 246 186 14 239 182 13
44459-206 162 42 106 106 106 66 66 66 34 34 34
44460- 14 14 14 6 6 6 0 0 0 0 0 0
44461- 0 0 0 0 0 0 0 0 0 0 0 0
44462- 0 0 0 0 0 0 0 0 0 0 0 0
44463- 0 0 0 0 0 0 0 0 0 6 6 6
44464- 26 26 26 70 70 70 163 133 67 213 154 11
44465-236 178 12 246 190 14 246 190 14 246 190 14
44466-246 190 14 246 190 14 246 190 14 246 190 14
44467-246 190 14 246 190 14 246 190 14 246 190 14
44468-246 190 14 246 190 14 246 190 14 241 196 14
44469-190 146 13 18 14 6 2 2 6 2 2 6
44470- 46 46 46 246 246 246 253 253 253 253 253 253
44471-253 253 253 253 253 253 253 253 253 253 253 253
44472-253 253 253 253 253 253 253 253 253 253 253 253
44473-253 253 253 253 253 253 253 253 253 253 253 253
44474-253 253 253 221 221 221 86 86 86 156 107 11
44475-216 158 10 236 178 12 242 186 14 246 186 14
44476-242 186 14 239 182 13 239 182 13 242 186 14
44477-242 186 14 246 186 14 246 190 14 246 190 14
44478-246 190 14 246 190 14 246 190 14 246 190 14
44479-242 186 14 225 175 15 142 122 72 66 66 66
44480- 30 30 30 10 10 10 0 0 0 0 0 0
44481- 0 0 0 0 0 0 0 0 0 0 0 0
44482- 0 0 0 0 0 0 0 0 0 0 0 0
44483- 0 0 0 0 0 0 0 0 0 6 6 6
44484- 26 26 26 70 70 70 163 133 67 210 150 10
44485-236 178 12 246 190 14 246 190 14 246 190 14
44486-246 190 14 246 190 14 246 190 14 246 190 14
44487-246 190 14 246 190 14 246 190 14 246 190 14
44488-246 190 14 246 190 14 246 190 14 246 190 14
44489-232 195 16 121 92 8 34 34 34 106 106 106
44490-221 221 221 253 253 253 253 253 253 253 253 253
44491-253 253 253 253 253 253 253 253 253 253 253 253
44492-253 253 253 253 253 253 253 253 253 253 253 253
44493-253 253 253 253 253 253 253 253 253 253 253 253
44494-242 242 242 82 82 82 18 14 6 163 110 8
44495-216 158 10 236 178 12 242 186 14 246 190 14
44496-246 190 14 246 190 14 246 190 14 246 190 14
44497-246 190 14 246 190 14 246 190 14 246 190 14
44498-246 190 14 246 190 14 246 190 14 246 190 14
44499-246 190 14 246 190 14 242 186 14 163 133 67
44500- 46 46 46 18 18 18 6 6 6 0 0 0
44501- 0 0 0 0 0 0 0 0 0 0 0 0
44502- 0 0 0 0 0 0 0 0 0 0 0 0
44503- 0 0 0 0 0 0 0 0 0 10 10 10
44504- 30 30 30 78 78 78 163 133 67 210 150 10
44505-236 178 12 246 186 14 246 190 14 246 190 14
44506-246 190 14 246 190 14 246 190 14 246 190 14
44507-246 190 14 246 190 14 246 190 14 246 190 14
44508-246 190 14 246 190 14 246 190 14 246 190 14
44509-241 196 14 215 174 15 190 178 144 253 253 253
44510-253 253 253 253 253 253 253 253 253 253 253 253
44511-253 253 253 253 253 253 253 253 253 253 253 253
44512-253 253 253 253 253 253 253 253 253 253 253 253
44513-253 253 253 253 253 253 253 253 253 218 218 218
44514- 58 58 58 2 2 6 22 18 6 167 114 7
44515-216 158 10 236 178 12 246 186 14 246 190 14
44516-246 190 14 246 190 14 246 190 14 246 190 14
44517-246 190 14 246 190 14 246 190 14 246 190 14
44518-246 190 14 246 190 14 246 190 14 246 190 14
44519-246 190 14 246 186 14 242 186 14 190 150 46
44520- 54 54 54 22 22 22 6 6 6 0 0 0
44521- 0 0 0 0 0 0 0 0 0 0 0 0
44522- 0 0 0 0 0 0 0 0 0 0 0 0
44523- 0 0 0 0 0 0 0 0 0 14 14 14
44524- 38 38 38 86 86 86 180 133 36 213 154 11
44525-236 178 12 246 186 14 246 190 14 246 190 14
44526-246 190 14 246 190 14 246 190 14 246 190 14
44527-246 190 14 246 190 14 246 190 14 246 190 14
44528-246 190 14 246 190 14 246 190 14 246 190 14
44529-246 190 14 232 195 16 190 146 13 214 214 214
44530-253 253 253 253 253 253 253 253 253 253 253 253
44531-253 253 253 253 253 253 253 253 253 253 253 253
44532-253 253 253 253 253 253 253 253 253 253 253 253
44533-253 253 253 250 250 250 170 170 170 26 26 26
44534- 2 2 6 2 2 6 37 26 9 163 110 8
44535-219 162 10 239 182 13 246 186 14 246 190 14
44536-246 190 14 246 190 14 246 190 14 246 190 14
44537-246 190 14 246 190 14 246 190 14 246 190 14
44538-246 190 14 246 190 14 246 190 14 246 190 14
44539-246 186 14 236 178 12 224 166 10 142 122 72
44540- 46 46 46 18 18 18 6 6 6 0 0 0
44541- 0 0 0 0 0 0 0 0 0 0 0 0
44542- 0 0 0 0 0 0 0 0 0 0 0 0
44543- 0 0 0 0 0 0 6 6 6 18 18 18
44544- 50 50 50 109 106 95 192 133 9 224 166 10
44545-242 186 14 246 190 14 246 190 14 246 190 14
44546-246 190 14 246 190 14 246 190 14 246 190 14
44547-246 190 14 246 190 14 246 190 14 246 190 14
44548-246 190 14 246 190 14 246 190 14 246 190 14
44549-242 186 14 226 184 13 210 162 10 142 110 46
44550-226 226 226 253 253 253 253 253 253 253 253 253
44551-253 253 253 253 253 253 253 253 253 253 253 253
44552-253 253 253 253 253 253 253 253 253 253 253 253
44553-198 198 198 66 66 66 2 2 6 2 2 6
44554- 2 2 6 2 2 6 50 34 6 156 107 11
44555-219 162 10 239 182 13 246 186 14 246 190 14
44556-246 190 14 246 190 14 246 190 14 246 190 14
44557-246 190 14 246 190 14 246 190 14 246 190 14
44558-246 190 14 246 190 14 246 190 14 242 186 14
44559-234 174 13 213 154 11 154 122 46 66 66 66
44560- 30 30 30 10 10 10 0 0 0 0 0 0
44561- 0 0 0 0 0 0 0 0 0 0 0 0
44562- 0 0 0 0 0 0 0 0 0 0 0 0
44563- 0 0 0 0 0 0 6 6 6 22 22 22
44564- 58 58 58 154 121 60 206 145 10 234 174 13
44565-242 186 14 246 186 14 246 190 14 246 190 14
44566-246 190 14 246 190 14 246 190 14 246 190 14
44567-246 190 14 246 190 14 246 190 14 246 190 14
44568-246 190 14 246 190 14 246 190 14 246 190 14
44569-246 186 14 236 178 12 210 162 10 163 110 8
44570- 61 42 6 138 138 138 218 218 218 250 250 250
44571-253 253 253 253 253 253 253 253 253 250 250 250
44572-242 242 242 210 210 210 144 144 144 66 66 66
44573- 6 6 6 2 2 6 2 2 6 2 2 6
44574- 2 2 6 2 2 6 61 42 6 163 110 8
44575-216 158 10 236 178 12 246 190 14 246 190 14
44576-246 190 14 246 190 14 246 190 14 246 190 14
44577-246 190 14 246 190 14 246 190 14 246 190 14
44578-246 190 14 239 182 13 230 174 11 216 158 10
44579-190 142 34 124 112 88 70 70 70 38 38 38
44580- 18 18 18 6 6 6 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 6 6 6 22 22 22
44584- 62 62 62 168 124 44 206 145 10 224 166 10
44585-236 178 12 239 182 13 242 186 14 242 186 14
44586-246 186 14 246 190 14 246 190 14 246 190 14
44587-246 190 14 246 190 14 246 190 14 246 190 14
44588-246 190 14 246 190 14 246 190 14 246 190 14
44589-246 190 14 236 178 12 216 158 10 175 118 6
44590- 80 54 7 2 2 6 6 6 6 30 30 30
44591- 54 54 54 62 62 62 50 50 50 38 38 38
44592- 14 14 14 2 2 6 2 2 6 2 2 6
44593- 2 2 6 2 2 6 2 2 6 2 2 6
44594- 2 2 6 6 6 6 80 54 7 167 114 7
44595-213 154 11 236 178 12 246 190 14 246 190 14
44596-246 190 14 246 190 14 246 190 14 246 190 14
44597-246 190 14 242 186 14 239 182 13 239 182 13
44598-230 174 11 210 150 10 174 135 50 124 112 88
44599- 82 82 82 54 54 54 34 34 34 18 18 18
44600- 6 6 6 0 0 0 0 0 0 0 0 0
44601- 0 0 0 0 0 0 0 0 0 0 0 0
44602- 0 0 0 0 0 0 0 0 0 0 0 0
44603- 0 0 0 0 0 0 6 6 6 18 18 18
44604- 50 50 50 158 118 36 192 133 9 200 144 11
44605-216 158 10 219 162 10 224 166 10 226 170 11
44606-230 174 11 236 178 12 239 182 13 239 182 13
44607-242 186 14 246 186 14 246 190 14 246 190 14
44608-246 190 14 246 190 14 246 190 14 246 190 14
44609-246 186 14 230 174 11 210 150 10 163 110 8
44610-104 69 6 10 10 10 2 2 6 2 2 6
44611- 2 2 6 2 2 6 2 2 6 2 2 6
44612- 2 2 6 2 2 6 2 2 6 2 2 6
44613- 2 2 6 2 2 6 2 2 6 2 2 6
44614- 2 2 6 6 6 6 91 60 6 167 114 7
44615-206 145 10 230 174 11 242 186 14 246 190 14
44616-246 190 14 246 190 14 246 186 14 242 186 14
44617-239 182 13 230 174 11 224 166 10 213 154 11
44618-180 133 36 124 112 88 86 86 86 58 58 58
44619- 38 38 38 22 22 22 10 10 10 6 6 6
44620- 0 0 0 0 0 0 0 0 0 0 0 0
44621- 0 0 0 0 0 0 0 0 0 0 0 0
44622- 0 0 0 0 0 0 0 0 0 0 0 0
44623- 0 0 0 0 0 0 0 0 0 14 14 14
44624- 34 34 34 70 70 70 138 110 50 158 118 36
44625-167 114 7 180 123 7 192 133 9 197 138 11
44626-200 144 11 206 145 10 213 154 11 219 162 10
44627-224 166 10 230 174 11 239 182 13 242 186 14
44628-246 186 14 246 186 14 246 186 14 246 186 14
44629-239 182 13 216 158 10 185 133 11 152 99 6
44630-104 69 6 18 14 6 2 2 6 2 2 6
44631- 2 2 6 2 2 6 2 2 6 2 2 6
44632- 2 2 6 2 2 6 2 2 6 2 2 6
44633- 2 2 6 2 2 6 2 2 6 2 2 6
44634- 2 2 6 6 6 6 80 54 7 152 99 6
44635-192 133 9 219 162 10 236 178 12 239 182 13
44636-246 186 14 242 186 14 239 182 13 236 178 12
44637-224 166 10 206 145 10 192 133 9 154 121 60
44638- 94 94 94 62 62 62 42 42 42 22 22 22
44639- 14 14 14 6 6 6 0 0 0 0 0 0
44640- 0 0 0 0 0 0 0 0 0 0 0 0
44641- 0 0 0 0 0 0 0 0 0 0 0 0
44642- 0 0 0 0 0 0 0 0 0 0 0 0
44643- 0 0 0 0 0 0 0 0 0 6 6 6
44644- 18 18 18 34 34 34 58 58 58 78 78 78
44645-101 98 89 124 112 88 142 110 46 156 107 11
44646-163 110 8 167 114 7 175 118 6 180 123 7
44647-185 133 11 197 138 11 210 150 10 219 162 10
44648-226 170 11 236 178 12 236 178 12 234 174 13
44649-219 162 10 197 138 11 163 110 8 130 83 6
44650- 91 60 6 10 10 10 2 2 6 2 2 6
44651- 18 18 18 38 38 38 38 38 38 38 38 38
44652- 38 38 38 38 38 38 38 38 38 38 38 38
44653- 38 38 38 38 38 38 26 26 26 2 2 6
44654- 2 2 6 6 6 6 70 47 6 137 92 6
44655-175 118 6 200 144 11 219 162 10 230 174 11
44656-234 174 13 230 174 11 219 162 10 210 150 10
44657-192 133 9 163 110 8 124 112 88 82 82 82
44658- 50 50 50 30 30 30 14 14 14 6 6 6
44659- 0 0 0 0 0 0 0 0 0 0 0 0
44660- 0 0 0 0 0 0 0 0 0 0 0 0
44661- 0 0 0 0 0 0 0 0 0 0 0 0
44662- 0 0 0 0 0 0 0 0 0 0 0 0
44663- 0 0 0 0 0 0 0 0 0 0 0 0
44664- 6 6 6 14 14 14 22 22 22 34 34 34
44665- 42 42 42 58 58 58 74 74 74 86 86 86
44666-101 98 89 122 102 70 130 98 46 121 87 25
44667-137 92 6 152 99 6 163 110 8 180 123 7
44668-185 133 11 197 138 11 206 145 10 200 144 11
44669-180 123 7 156 107 11 130 83 6 104 69 6
44670- 50 34 6 54 54 54 110 110 110 101 98 89
44671- 86 86 86 82 82 82 78 78 78 78 78 78
44672- 78 78 78 78 78 78 78 78 78 78 78 78
44673- 78 78 78 82 82 82 86 86 86 94 94 94
44674-106 106 106 101 101 101 86 66 34 124 80 6
44675-156 107 11 180 123 7 192 133 9 200 144 11
44676-206 145 10 200 144 11 192 133 9 175 118 6
44677-139 102 15 109 106 95 70 70 70 42 42 42
44678- 22 22 22 10 10 10 0 0 0 0 0 0
44679- 0 0 0 0 0 0 0 0 0 0 0 0
44680- 0 0 0 0 0 0 0 0 0 0 0 0
44681- 0 0 0 0 0 0 0 0 0 0 0 0
44682- 0 0 0 0 0 0 0 0 0 0 0 0
44683- 0 0 0 0 0 0 0 0 0 0 0 0
44684- 0 0 0 0 0 0 6 6 6 10 10 10
44685- 14 14 14 22 22 22 30 30 30 38 38 38
44686- 50 50 50 62 62 62 74 74 74 90 90 90
44687-101 98 89 112 100 78 121 87 25 124 80 6
44688-137 92 6 152 99 6 152 99 6 152 99 6
44689-138 86 6 124 80 6 98 70 6 86 66 30
44690-101 98 89 82 82 82 58 58 58 46 46 46
44691- 38 38 38 34 34 34 34 34 34 34 34 34
44692- 34 34 34 34 34 34 34 34 34 34 34 34
44693- 34 34 34 34 34 34 38 38 38 42 42 42
44694- 54 54 54 82 82 82 94 86 76 91 60 6
44695-134 86 6 156 107 11 167 114 7 175 118 6
44696-175 118 6 167 114 7 152 99 6 121 87 25
44697-101 98 89 62 62 62 34 34 34 18 18 18
44698- 6 6 6 0 0 0 0 0 0 0 0 0
44699- 0 0 0 0 0 0 0 0 0 0 0 0
44700- 0 0 0 0 0 0 0 0 0 0 0 0
44701- 0 0 0 0 0 0 0 0 0 0 0 0
44702- 0 0 0 0 0 0 0 0 0 0 0 0
44703- 0 0 0 0 0 0 0 0 0 0 0 0
44704- 0 0 0 0 0 0 0 0 0 0 0 0
44705- 0 0 0 6 6 6 6 6 6 10 10 10
44706- 18 18 18 22 22 22 30 30 30 42 42 42
44707- 50 50 50 66 66 66 86 86 86 101 98 89
44708-106 86 58 98 70 6 104 69 6 104 69 6
44709-104 69 6 91 60 6 82 62 34 90 90 90
44710- 62 62 62 38 38 38 22 22 22 14 14 14
44711- 10 10 10 10 10 10 10 10 10 10 10 10
44712- 10 10 10 10 10 10 6 6 6 10 10 10
44713- 10 10 10 10 10 10 10 10 10 14 14 14
44714- 22 22 22 42 42 42 70 70 70 89 81 66
44715- 80 54 7 104 69 6 124 80 6 137 92 6
44716-134 86 6 116 81 8 100 82 52 86 86 86
44717- 58 58 58 30 30 30 14 14 14 6 6 6
44718- 0 0 0 0 0 0 0 0 0 0 0 0
44719- 0 0 0 0 0 0 0 0 0 0 0 0
44720- 0 0 0 0 0 0 0 0 0 0 0 0
44721- 0 0 0 0 0 0 0 0 0 0 0 0
44722- 0 0 0 0 0 0 0 0 0 0 0 0
44723- 0 0 0 0 0 0 0 0 0 0 0 0
44724- 0 0 0 0 0 0 0 0 0 0 0 0
44725- 0 0 0 0 0 0 0 0 0 0 0 0
44726- 0 0 0 6 6 6 10 10 10 14 14 14
44727- 18 18 18 26 26 26 38 38 38 54 54 54
44728- 70 70 70 86 86 86 94 86 76 89 81 66
44729- 89 81 66 86 86 86 74 74 74 50 50 50
44730- 30 30 30 14 14 14 6 6 6 0 0 0
44731- 0 0 0 0 0 0 0 0 0 0 0 0
44732- 0 0 0 0 0 0 0 0 0 0 0 0
44733- 0 0 0 0 0 0 0 0 0 0 0 0
44734- 6 6 6 18 18 18 34 34 34 58 58 58
44735- 82 82 82 89 81 66 89 81 66 89 81 66
44736- 94 86 66 94 86 76 74 74 74 50 50 50
44737- 26 26 26 14 14 14 6 6 6 0 0 0
44738- 0 0 0 0 0 0 0 0 0 0 0 0
44739- 0 0 0 0 0 0 0 0 0 0 0 0
44740- 0 0 0 0 0 0 0 0 0 0 0 0
44741- 0 0 0 0 0 0 0 0 0 0 0 0
44742- 0 0 0 0 0 0 0 0 0 0 0 0
44743- 0 0 0 0 0 0 0 0 0 0 0 0
44744- 0 0 0 0 0 0 0 0 0 0 0 0
44745- 0 0 0 0 0 0 0 0 0 0 0 0
44746- 0 0 0 0 0 0 0 0 0 0 0 0
44747- 6 6 6 6 6 6 14 14 14 18 18 18
44748- 30 30 30 38 38 38 46 46 46 54 54 54
44749- 50 50 50 42 42 42 30 30 30 18 18 18
44750- 10 10 10 0 0 0 0 0 0 0 0 0
44751- 0 0 0 0 0 0 0 0 0 0 0 0
44752- 0 0 0 0 0 0 0 0 0 0 0 0
44753- 0 0 0 0 0 0 0 0 0 0 0 0
44754- 0 0 0 6 6 6 14 14 14 26 26 26
44755- 38 38 38 50 50 50 58 58 58 58 58 58
44756- 54 54 54 42 42 42 30 30 30 18 18 18
44757- 10 10 10 0 0 0 0 0 0 0 0 0
44758- 0 0 0 0 0 0 0 0 0 0 0 0
44759- 0 0 0 0 0 0 0 0 0 0 0 0
44760- 0 0 0 0 0 0 0 0 0 0 0 0
44761- 0 0 0 0 0 0 0 0 0 0 0 0
44762- 0 0 0 0 0 0 0 0 0 0 0 0
44763- 0 0 0 0 0 0 0 0 0 0 0 0
44764- 0 0 0 0 0 0 0 0 0 0 0 0
44765- 0 0 0 0 0 0 0 0 0 0 0 0
44766- 0 0 0 0 0 0 0 0 0 0 0 0
44767- 0 0 0 0 0 0 0 0 0 6 6 6
44768- 6 6 6 10 10 10 14 14 14 18 18 18
44769- 18 18 18 14 14 14 10 10 10 6 6 6
44770- 0 0 0 0 0 0 0 0 0 0 0 0
44771- 0 0 0 0 0 0 0 0 0 0 0 0
44772- 0 0 0 0 0 0 0 0 0 0 0 0
44773- 0 0 0 0 0 0 0 0 0 0 0 0
44774- 0 0 0 0 0 0 0 0 0 6 6 6
44775- 14 14 14 18 18 18 22 22 22 22 22 22
44776- 18 18 18 14 14 14 10 10 10 6 6 6
44777- 0 0 0 0 0 0 0 0 0 0 0 0
44778- 0 0 0 0 0 0 0 0 0 0 0 0
44779- 0 0 0 0 0 0 0 0 0 0 0 0
44780- 0 0 0 0 0 0 0 0 0 0 0 0
44781- 0 0 0 0 0 0 0 0 0 0 0 0
44782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44786+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44795+4 4 4 4 4 4
44796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44800+4 4 4 4 4 4 4 4 4 4 4 4 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44809+4 4 4 4 4 4
44810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44814+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
44817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44823+4 4 4 4 4 4
44824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44828+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44837+4 4 4 4 4 4
44838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44851+4 4 4 4 4 4
44852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44865+4 4 4 4 4 4
44866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44870+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
44871+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
44872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44875+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
44876+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44877+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
44878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44879+4 4 4 4 4 4
44880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44884+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
44885+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
44886+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44889+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
44890+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
44891+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
44892+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44893+4 4 4 4 4 4
44894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44898+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
44899+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
44900+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44903+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
44904+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
44905+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
44906+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
44907+4 4 4 4 4 4
44908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44911+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
44912+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
44913+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
44914+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
44915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44916+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
44917+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
44918+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
44919+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
44920+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
44921+4 4 4 4 4 4
44922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44925+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
44926+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
44927+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
44928+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
44929+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44930+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
44931+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
44932+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
44933+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
44934+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
44935+4 4 4 4 4 4
44936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44938+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44939+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
44940+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
44941+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
44942+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
44943+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44944+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
44945+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
44946+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
44947+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
44948+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
44949+4 4 4 4 4 4
44950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44952+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
44953+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
44954+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
44955+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
44956+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
44957+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
44958+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
44959+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
44960+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
44961+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
44962+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
44963+4 4 4 4 4 4
44964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44966+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
44967+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
44968+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
44969+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
44970+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
44971+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
44972+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
44973+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
44974+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
44975+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
44976+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
44977+4 4 4 4 4 4
44978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44980+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
44981+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
44982+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
44983+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
44984+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
44985+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
44986+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
44987+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
44988+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
44989+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
44990+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44991+4 4 4 4 4 4
44992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44994+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
44995+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
44996+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
44997+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
44998+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
44999+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
45000+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
45001+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
45002+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
45003+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
45004+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
45005+4 4 4 4 4 4
45006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45007+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
45008+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
45009+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
45010+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
45011+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
45012+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
45013+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
45014+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
45015+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
45016+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
45017+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
45018+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
45019+4 4 4 4 4 4
45020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45021+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
45022+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
45023+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
45024+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
45025+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
45026+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
45027+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
45028+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
45029+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
45030+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
45031+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
45032+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
45033+0 0 0 4 4 4
45034+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
45035+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
45036+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
45037+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
45038+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
45039+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
45040+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
45041+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
45042+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
45043+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
45044+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
45045+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
45046+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
45047+2 0 0 0 0 0
45048+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
45049+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
45050+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
45051+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
45052+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
45053+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
45054+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
45055+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
45056+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
45057+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
45058+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
45059+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
45060+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
45061+37 38 37 0 0 0
45062+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
45063+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
45064+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
45065+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
45066+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
45067+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
45068+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
45069+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
45070+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
45071+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
45072+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
45073+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
45074+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
45075+85 115 134 4 0 0
45076+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
45077+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
45078+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
45079+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
45080+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
45081+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
45082+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
45083+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
45084+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
45085+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
45086+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
45087+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
45088+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
45089+60 73 81 4 0 0
45090+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
45091+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
45092+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
45093+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
45094+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
45095+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
45096+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
45097+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
45098+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
45099+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
45100+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
45101+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
45102+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
45103+16 19 21 4 0 0
45104+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
45105+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
45106+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
45107+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
45108+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
45109+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
45110+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
45111+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
45112+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
45113+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
45114+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
45115+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
45116+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
45117+4 0 0 4 3 3
45118+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
45119+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
45120+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
45121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
45122+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
45123+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
45124+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
45125+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
45126+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
45127+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
45128+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
45129+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
45130+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
45131+3 2 2 4 4 4
45132+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
45133+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
45134+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
45135+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
45136+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
45137+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
45138+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
45139+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
45140+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
45141+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
45142+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
45143+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
45144+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
45145+4 4 4 4 4 4
45146+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
45147+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
45148+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
45149+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
45150+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
45151+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
45152+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
45153+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
45154+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
45155+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
45156+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
45157+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
45158+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
45159+4 4 4 4 4 4
45160+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
45161+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
45162+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
45163+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
45164+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
45165+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45166+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
45167+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
45168+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
45169+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
45170+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
45171+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
45172+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
45173+5 5 5 5 5 5
45174+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
45175+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
45176+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
45177+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
45178+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
45179+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45180+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
45181+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
45182+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
45183+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
45184+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
45185+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
45186+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
45187+5 5 5 4 4 4
45188+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
45189+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
45190+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
45191+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
45192+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45193+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
45194+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
45195+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
45196+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
45197+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
45198+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
45199+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
45200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45201+4 4 4 4 4 4
45202+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
45203+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
45204+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
45205+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
45206+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
45207+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45208+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45209+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
45210+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
45211+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
45212+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
45213+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
45214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45215+4 4 4 4 4 4
45216+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
45217+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
45218+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
45219+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
45220+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45221+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
45222+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
45223+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
45224+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
45225+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
45226+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
45227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45229+4 4 4 4 4 4
45230+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
45231+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
45232+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
45233+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
45234+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45235+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45236+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45237+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
45238+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
45239+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
45240+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
45241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45243+4 4 4 4 4 4
45244+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
45245+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
45246+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
45247+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
45248+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45249+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
45250+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45251+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
45252+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
45253+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
45254+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45257+4 4 4 4 4 4
45258+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
45259+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
45260+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
45261+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
45262+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45263+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
45264+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
45265+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
45266+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
45267+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
45268+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
45269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45271+4 4 4 4 4 4
45272+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
45273+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
45274+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
45275+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
45276+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45277+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
45278+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
45279+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
45280+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
45281+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
45282+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
45283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45285+4 4 4 4 4 4
45286+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
45287+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
45288+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
45289+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45290+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
45291+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
45292+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
45293+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
45294+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
45295+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
45296+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45299+4 4 4 4 4 4
45300+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
45301+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
45302+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
45303+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
45304+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45305+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
45306+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
45307+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
45308+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
45309+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
45310+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45313+4 4 4 4 4 4
45314+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
45315+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
45316+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
45317+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45318+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45319+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
45320+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
45321+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
45322+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
45323+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
45324+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45327+4 4 4 4 4 4
45328+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
45329+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
45330+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
45331+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
45332+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45333+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
45334+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
45335+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
45336+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
45337+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45338+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45341+4 4 4 4 4 4
45342+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
45343+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
45344+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
45345+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
45346+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
45347+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
45348+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
45349+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
45350+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45351+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45352+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45355+4 4 4 4 4 4
45356+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
45357+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
45358+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
45359+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
45360+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45361+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
45362+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
45363+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
45364+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45365+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45366+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45369+4 4 4 4 4 4
45370+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
45371+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
45372+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
45373+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
45374+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
45375+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
45376+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
45377+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
45378+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45379+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45380+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45383+4 4 4 4 4 4
45384+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
45385+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
45386+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45387+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
45388+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
45389+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
45390+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
45391+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
45392+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
45393+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45394+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45397+4 4 4 4 4 4
45398+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
45399+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
45400+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
45401+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
45402+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
45403+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
45404+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
45405+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
45406+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45407+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45408+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45411+4 4 4 4 4 4
45412+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
45413+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
45414+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45415+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
45416+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
45417+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
45418+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
45419+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
45420+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
45421+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45422+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45425+4 4 4 4 4 4
45426+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
45427+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
45428+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
45429+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
45430+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
45431+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
45432+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
45433+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
45434+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45435+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45436+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45439+4 4 4 4 4 4
45440+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45441+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
45442+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45443+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
45444+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
45445+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
45446+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
45447+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
45448+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45449+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45450+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45453+4 4 4 4 4 4
45454+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
45455+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
45456+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
45457+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
45458+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
45459+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
45460+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45461+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
45462+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45463+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45464+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45467+4 4 4 4 4 4
45468+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45469+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
45470+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
45471+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
45472+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
45473+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
45474+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45475+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
45476+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45477+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45478+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45481+4 4 4 4 4 4
45482+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
45483+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
45484+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
45485+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
45486+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
45487+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
45488+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
45489+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
45490+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
45491+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45492+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45495+4 4 4 4 4 4
45496+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45497+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
45498+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
45499+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
45500+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
45501+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
45502+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
45503+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
45504+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
45505+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45506+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45509+4 4 4 4 4 4
45510+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
45511+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
45512+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
45513+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
45514+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
45515+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
45516+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
45517+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
45518+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
45519+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45520+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45523+4 4 4 4 4 4
45524+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45525+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
45526+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
45527+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
45528+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
45529+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
45530+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
45531+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
45532+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
45533+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45534+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45537+4 4 4 4 4 4
45538+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
45539+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
45540+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
45541+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
45542+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
45543+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
45544+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
45545+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
45546+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
45547+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
45548+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45551+4 4 4 4 4 4
45552+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
45553+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
45554+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
45555+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
45556+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
45557+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
45558+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
45559+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
45560+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
45561+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
45562+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45565+4 4 4 4 4 4
45566+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
45567+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
45568+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
45569+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
45570+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
45571+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
45572+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45573+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
45574+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
45575+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
45576+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45579+4 4 4 4 4 4
45580+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
45581+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
45582+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
45583+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
45584+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
45585+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
45586+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
45587+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
45588+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
45589+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
45590+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45593+4 4 4 4 4 4
45594+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
45595+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
45596+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
45597+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
45598+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
45599+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
45600+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
45601+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
45602+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
45603+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
45604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45607+4 4 4 4 4 4
45608+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45609+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
45610+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
45611+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
45612+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
45613+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
45614+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
45615+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
45616+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
45617+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
45618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45621+4 4 4 4 4 4
45622+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
45623+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
45624+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
45625+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
45626+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
45627+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
45628+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
45629+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
45630+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
45631+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
45632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45635+4 4 4 4 4 4
45636+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
45637+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
45638+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
45639+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
45640+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
45641+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
45642+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
45643+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
45644+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
45645+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45649+4 4 4 4 4 4
45650+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
45651+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45652+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
45653+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
45654+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
45655+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
45656+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
45657+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
45658+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
45659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45663+4 4 4 4 4 4
45664+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
45665+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
45666+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
45667+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
45668+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
45669+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
45670+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
45671+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
45672+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
45673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45677+4 4 4 4 4 4
45678+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
45679+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
45680+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
45681+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
45682+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
45683+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
45684+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
45685+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
45686+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45691+4 4 4 4 4 4
45692+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
45693+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
45694+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
45695+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
45696+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
45697+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
45698+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
45699+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
45700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45705+4 4 4 4 4 4
45706+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
45707+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
45708+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
45709+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
45710+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
45711+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
45712+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
45713+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
45714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45719+4 4 4 4 4 4
45720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45721+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
45722+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45723+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
45724+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
45725+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
45726+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
45727+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
45728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45733+4 4 4 4 4 4
45734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45735+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
45736+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
45737+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
45738+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
45739+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
45740+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
45741+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
45742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45747+4 4 4 4 4 4
45748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45749+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
45750+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
45751+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
45752+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
45753+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
45754+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
45755+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45761+4 4 4 4 4 4
45762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45764+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
45765+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
45766+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
45767+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
45768+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
45769+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45775+4 4 4 4 4 4
45776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45779+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45780+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
45781+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
45782+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
45783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45789+4 4 4 4 4 4
45790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45793+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
45794+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
45795+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
45796+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
45797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45803+4 4 4 4 4 4
45804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45807+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
45808+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45809+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
45810+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
45811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45817+4 4 4 4 4 4
45818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45821+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
45822+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
45823+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
45824+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
45825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45831+4 4 4 4 4 4
45832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45836+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
45837+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45838+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45845+4 4 4 4 4 4
45846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45850+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
45851+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
45852+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
45853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45859+4 4 4 4 4 4
45860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45864+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
45865+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
45866+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45873+4 4 4 4 4 4
45874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45878+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
45879+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
45880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45887+4 4 4 4 4 4
45888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45892+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
45893+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
45894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45901+4 4 4 4 4 4
45902diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c
45903index 443e3c8..c443d6a 100644
45904--- a/drivers/video/nvidia/nv_backlight.c
45905+++ b/drivers/video/nvidia/nv_backlight.c
45906@@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(struct backlight_device *bd)
45907 return bd->props.brightness;
45908 }
45909
45910-static struct backlight_ops nvidia_bl_ops = {
45911+static const struct backlight_ops nvidia_bl_ops = {
45912 .get_brightness = nvidia_bl_get_brightness,
45913 .update_status = nvidia_bl_update_status,
45914 };
45915diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
45916index d94c57f..912984c 100644
45917--- a/drivers/video/riva/fbdev.c
45918+++ b/drivers/video/riva/fbdev.c
45919@@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct backlight_device *bd)
45920 return bd->props.brightness;
45921 }
45922
45923-static struct backlight_ops riva_bl_ops = {
45924+static const struct backlight_ops riva_bl_ops = {
45925 .get_brightness = riva_bl_get_brightness,
45926 .update_status = riva_bl_update_status,
45927 };
45928diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
45929index 54fbb29..2c108fc 100644
45930--- a/drivers/video/uvesafb.c
45931+++ b/drivers/video/uvesafb.c
45932@@ -18,6 +18,7 @@
45933 #include <linux/fb.h>
45934 #include <linux/io.h>
45935 #include <linux/mutex.h>
45936+#include <linux/moduleloader.h>
45937 #include <video/edid.h>
45938 #include <video/uvesafb.h>
45939 #ifdef CONFIG_X86
45940@@ -120,7 +121,7 @@ static int uvesafb_helper_start(void)
45941 NULL,
45942 };
45943
45944- return call_usermodehelper(v86d_path, argv, envp, 1);
45945+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
45946 }
45947
45948 /*
45949@@ -568,10 +569,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
45950 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
45951 par->pmi_setpal = par->ypan = 0;
45952 } else {
45953+
45954+#ifdef CONFIG_PAX_KERNEXEC
45955+#ifdef CONFIG_MODULES
45956+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
45957+#endif
45958+ if (!par->pmi_code) {
45959+ par->pmi_setpal = par->ypan = 0;
45960+ return 0;
45961+ }
45962+#endif
45963+
45964 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
45965 + task->t.regs.edi);
45966+
45967+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45968+ pax_open_kernel();
45969+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
45970+ pax_close_kernel();
45971+
45972+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
45973+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
45974+#else
45975 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
45976 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
45977+#endif
45978+
45979 printk(KERN_INFO "uvesafb: protected mode interface info at "
45980 "%04x:%04x\n",
45981 (u16)task->t.regs.es, (u16)task->t.regs.edi);
45982@@ -1799,6 +1822,11 @@ out:
45983 if (par->vbe_modes)
45984 kfree(par->vbe_modes);
45985
45986+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45987+ if (par->pmi_code)
45988+ module_free_exec(NULL, par->pmi_code);
45989+#endif
45990+
45991 framebuffer_release(info);
45992 return err;
45993 }
45994@@ -1825,6 +1853,12 @@ static int uvesafb_remove(struct platform_device *dev)
45995 kfree(par->vbe_state_orig);
45996 if (par->vbe_state_saved)
45997 kfree(par->vbe_state_saved);
45998+
45999+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46000+ if (par->pmi_code)
46001+ module_free_exec(NULL, par->pmi_code);
46002+#endif
46003+
46004 }
46005
46006 framebuffer_release(info);
46007diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
46008index bd37ee1..cb827e8 100644
46009--- a/drivers/video/vesafb.c
46010+++ b/drivers/video/vesafb.c
46011@@ -9,6 +9,7 @@
46012 */
46013
46014 #include <linux/module.h>
46015+#include <linux/moduleloader.h>
46016 #include <linux/kernel.h>
46017 #include <linux/errno.h>
46018 #include <linux/string.h>
46019@@ -53,8 +54,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
46020 static int vram_total __initdata; /* Set total amount of memory */
46021 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
46022 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
46023-static void (*pmi_start)(void) __read_mostly;
46024-static void (*pmi_pal) (void) __read_mostly;
46025+static void (*pmi_start)(void) __read_only;
46026+static void (*pmi_pal) (void) __read_only;
46027 static int depth __read_mostly;
46028 static int vga_compat __read_mostly;
46029 /* --------------------------------------------------------------------- */
46030@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
46031 unsigned int size_vmode;
46032 unsigned int size_remap;
46033 unsigned int size_total;
46034+ void *pmi_code = NULL;
46035
46036 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
46037 return -ENODEV;
46038@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
46039 size_remap = size_total;
46040 vesafb_fix.smem_len = size_remap;
46041
46042-#ifndef __i386__
46043- screen_info.vesapm_seg = 0;
46044-#endif
46045-
46046 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
46047 printk(KERN_WARNING
46048 "vesafb: cannot reserve video memory at 0x%lx\n",
46049@@ -315,9 +313,21 @@ static int __init vesafb_probe(struct platform_device *dev)
46050 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
46051 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
46052
46053+#ifdef __i386__
46054+
46055+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46056+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
46057+ if (!pmi_code)
46058+#elif !defined(CONFIG_PAX_KERNEXEC)
46059+ if (0)
46060+#endif
46061+
46062+#endif
46063+ screen_info.vesapm_seg = 0;
46064+
46065 if (screen_info.vesapm_seg) {
46066- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
46067- screen_info.vesapm_seg,screen_info.vesapm_off);
46068+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
46069+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
46070 }
46071
46072 if (screen_info.vesapm_seg < 0xc000)
46073@@ -325,9 +335,25 @@ static int __init vesafb_probe(struct platform_device *dev)
46074
46075 if (ypan || pmi_setpal) {
46076 unsigned short *pmi_base;
46077+
46078 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
46079- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
46080- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
46081+
46082+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46083+ pax_open_kernel();
46084+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
46085+#else
46086+ pmi_code = pmi_base;
46087+#endif
46088+
46089+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
46090+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
46091+
46092+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46093+ pmi_start = ktva_ktla(pmi_start);
46094+ pmi_pal = ktva_ktla(pmi_pal);
46095+ pax_close_kernel();
46096+#endif
46097+
46098 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
46099 if (pmi_base[3]) {
46100 printk(KERN_INFO "vesafb: pmi: ports = ");
46101@@ -469,6 +495,11 @@ static int __init vesafb_probe(struct platform_device *dev)
46102 info->node, info->fix.id);
46103 return 0;
46104 err:
46105+
46106+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46107+ module_free_exec(NULL, pmi_code);
46108+#endif
46109+
46110 if (info->screen_base)
46111 iounmap(info->screen_base);
46112 framebuffer_release(info);
46113diff --git a/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c
46114index 88a60e0..6783cc2 100644
46115--- a/drivers/xen/sys-hypervisor.c
46116+++ b/drivers/xen/sys-hypervisor.c
46117@@ -425,7 +425,7 @@ static ssize_t hyp_sysfs_store(struct kobject *kobj,
46118 return 0;
46119 }
46120
46121-static struct sysfs_ops hyp_sysfs_ops = {
46122+static const struct sysfs_ops hyp_sysfs_ops = {
46123 .show = hyp_sysfs_show,
46124 .store = hyp_sysfs_store,
46125 };
46126diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
46127index 18f74ec..3227009 100644
46128--- a/fs/9p/vfs_inode.c
46129+++ b/fs/9p/vfs_inode.c
46130@@ -1079,7 +1079,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
46131 static void
46132 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46133 {
46134- char *s = nd_get_link(nd);
46135+ const char *s = nd_get_link(nd);
46136
46137 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
46138 IS_ERR(s) ? "<error>" : s);
46139diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
46140index bb4cc5b..df5eaa0 100644
46141--- a/fs/Kconfig.binfmt
46142+++ b/fs/Kconfig.binfmt
46143@@ -86,7 +86,7 @@ config HAVE_AOUT
46144
46145 config BINFMT_AOUT
46146 tristate "Kernel support for a.out and ECOFF binaries"
46147- depends on HAVE_AOUT
46148+ depends on HAVE_AOUT && BROKEN
46149 ---help---
46150 A.out (Assembler.OUTput) is a set of formats for libraries and
46151 executables used in the earliest versions of UNIX. Linux used
46152diff --git a/fs/aio.c b/fs/aio.c
46153index 22a19ad..d484e5b 100644
46154--- a/fs/aio.c
46155+++ b/fs/aio.c
46156@@ -115,7 +115,7 @@ static int aio_setup_ring(struct kioctx *ctx)
46157 size += sizeof(struct io_event) * nr_events;
46158 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
46159
46160- if (nr_pages < 0)
46161+ if (nr_pages <= 0)
46162 return -EINVAL;
46163
46164 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
46165@@ -1089,6 +1089,8 @@ static int read_events(struct kioctx *ctx,
46166 struct aio_timeout to;
46167 int retry = 0;
46168
46169+ pax_track_stack();
46170+
46171 /* needed to zero any padding within an entry (there shouldn't be
46172 * any, but C is fun!
46173 */
46174@@ -1382,13 +1384,18 @@ static ssize_t aio_fsync(struct kiocb *iocb)
46175 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb)
46176 {
46177 ssize_t ret;
46178+ struct iovec iovstack;
46179
46180 ret = rw_copy_check_uvector(type, (struct iovec __user *)kiocb->ki_buf,
46181 kiocb->ki_nbytes, 1,
46182- &kiocb->ki_inline_vec, &kiocb->ki_iovec);
46183+ &iovstack, &kiocb->ki_iovec);
46184 if (ret < 0)
46185 goto out;
46186
46187+ if (kiocb->ki_iovec == &iovstack) {
46188+ kiocb->ki_inline_vec = iovstack;
46189+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
46190+ }
46191 kiocb->ki_nr_segs = kiocb->ki_nbytes;
46192 kiocb->ki_cur_seg = 0;
46193 /* ki_nbytes/left now reflect bytes instead of segs */
46194diff --git a/fs/attr.c b/fs/attr.c
46195index 96d394b..33cf5b4 100644
46196--- a/fs/attr.c
46197+++ b/fs/attr.c
46198@@ -83,6 +83,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
46199 unsigned long limit;
46200
46201 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
46202+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
46203 if (limit != RLIM_INFINITY && offset > limit)
46204 goto out_sig;
46205 if (offset > inode->i_sb->s_maxbytes)
46206diff --git a/fs/autofs/root.c b/fs/autofs/root.c
46207index 4a1401c..05eb5ca 100644
46208--- a/fs/autofs/root.c
46209+++ b/fs/autofs/root.c
46210@@ -299,7 +299,8 @@ static int autofs_root_symlink(struct inode *dir, struct dentry *dentry, const c
46211 set_bit(n,sbi->symlink_bitmap);
46212 sl = &sbi->symlink[n];
46213 sl->len = strlen(symname);
46214- sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
46215+ slsize = sl->len+1;
46216+ sl->data = kmalloc(slsize, GFP_KERNEL);
46217 if (!sl->data) {
46218 clear_bit(n,sbi->symlink_bitmap);
46219 unlock_kernel();
46220diff --git a/fs/autofs4/symlink.c b/fs/autofs4/symlink.c
46221index b4ea829..e63ef18 100644
46222--- a/fs/autofs4/symlink.c
46223+++ b/fs/autofs4/symlink.c
46224@@ -15,7 +15,7 @@
46225 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
46226 {
46227 struct autofs_info *ino = autofs4_dentry_ino(dentry);
46228- nd_set_link(nd, (char *)ino->u.symlink);
46229+ nd_set_link(nd, ino->u.symlink);
46230 return NULL;
46231 }
46232
46233diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
46234index 2341375..df9d1c2 100644
46235--- a/fs/autofs4/waitq.c
46236+++ b/fs/autofs4/waitq.c
46237@@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
46238 {
46239 unsigned long sigpipe, flags;
46240 mm_segment_t fs;
46241- const char *data = (const char *)addr;
46242+ const char __user *data = (const char __force_user *)addr;
46243 ssize_t wr = 0;
46244
46245 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
46246diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
46247index 9158c07..3f06659 100644
46248--- a/fs/befs/linuxvfs.c
46249+++ b/fs/befs/linuxvfs.c
46250@@ -498,7 +498,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46251 {
46252 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
46253 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
46254- char *link = nd_get_link(nd);
46255+ const char *link = nd_get_link(nd);
46256 if (!IS_ERR(link))
46257 kfree(link);
46258 }
46259diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
46260index 0133b5a..b3baa9f 100644
46261--- a/fs/binfmt_aout.c
46262+++ b/fs/binfmt_aout.c
46263@@ -16,6 +16,7 @@
46264 #include <linux/string.h>
46265 #include <linux/fs.h>
46266 #include <linux/file.h>
46267+#include <linux/security.h>
46268 #include <linux/stat.h>
46269 #include <linux/fcntl.h>
46270 #include <linux/ptrace.h>
46271@@ -102,6 +103,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46272 #endif
46273 # define START_STACK(u) (u.start_stack)
46274
46275+ memset(&dump, 0, sizeof(dump));
46276+
46277 fs = get_fs();
46278 set_fs(KERNEL_DS);
46279 has_dumped = 1;
46280@@ -113,10 +116,12 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46281
46282 /* If the size of the dump file exceeds the rlimit, then see what would happen
46283 if we wrote the stack, but not the data area. */
46284+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
46285 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
46286 dump.u_dsize = 0;
46287
46288 /* Make sure we have enough room to write the stack and data areas. */
46289+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
46290 if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
46291 dump.u_ssize = 0;
46292
46293@@ -146,9 +151,7 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46294 dump_size = dump.u_ssize << PAGE_SHIFT;
46295 DUMP_WRITE(dump_start,dump_size);
46296 }
46297-/* Finally dump the task struct. Not be used by gdb, but could be useful */
46298- set_fs(KERNEL_DS);
46299- DUMP_WRITE(current,sizeof(*current));
46300+/* Finally, let's not dump the task struct. Not be used by gdb, but could be useful to an attacker */
46301 end_coredump:
46302 set_fs(fs);
46303 return has_dumped;
46304@@ -249,6 +252,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46305 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
46306 if (rlim >= RLIM_INFINITY)
46307 rlim = ~0;
46308+
46309+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
46310 if (ex.a_data + ex.a_bss > rlim)
46311 return -ENOMEM;
46312
46313@@ -277,6 +282,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46314 install_exec_creds(bprm);
46315 current->flags &= ~PF_FORKNOEXEC;
46316
46317+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46318+ current->mm->pax_flags = 0UL;
46319+#endif
46320+
46321+#ifdef CONFIG_PAX_PAGEEXEC
46322+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
46323+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
46324+
46325+#ifdef CONFIG_PAX_EMUTRAMP
46326+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
46327+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
46328+#endif
46329+
46330+#ifdef CONFIG_PAX_MPROTECT
46331+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
46332+ current->mm->pax_flags |= MF_PAX_MPROTECT;
46333+#endif
46334+
46335+ }
46336+#endif
46337+
46338 if (N_MAGIC(ex) == OMAGIC) {
46339 unsigned long text_addr, map_size;
46340 loff_t pos;
46341@@ -349,7 +375,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46342
46343 down_write(&current->mm->mmap_sem);
46344 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
46345- PROT_READ | PROT_WRITE | PROT_EXEC,
46346+ PROT_READ | PROT_WRITE,
46347 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
46348 fd_offset + ex.a_text);
46349 up_write(&current->mm->mmap_sem);
46350diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
46351index 1ed37ba..b9c035f 100644
46352--- a/fs/binfmt_elf.c
46353+++ b/fs/binfmt_elf.c
46354@@ -31,6 +31,7 @@
46355 #include <linux/random.h>
46356 #include <linux/elf.h>
46357 #include <linux/utsname.h>
46358+#include <linux/xattr.h>
46359 #include <asm/uaccess.h>
46360 #include <asm/param.h>
46361 #include <asm/page.h>
46362@@ -50,6 +51,10 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46363 #define elf_core_dump NULL
46364 #endif
46365
46366+#ifdef CONFIG_PAX_MPROTECT
46367+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
46368+#endif
46369+
46370 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
46371 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
46372 #else
46373@@ -69,6 +74,11 @@ static struct linux_binfmt elf_format = {
46374 .load_binary = load_elf_binary,
46375 .load_shlib = load_elf_library,
46376 .core_dump = elf_core_dump,
46377+
46378+#ifdef CONFIG_PAX_MPROTECT
46379+ .handle_mprotect= elf_handle_mprotect,
46380+#endif
46381+
46382 .min_coredump = ELF_EXEC_PAGESIZE,
46383 .hasvdso = 1
46384 };
46385@@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
46386
46387 static int set_brk(unsigned long start, unsigned long end)
46388 {
46389+ unsigned long e = end;
46390+
46391 start = ELF_PAGEALIGN(start);
46392 end = ELF_PAGEALIGN(end);
46393 if (end > start) {
46394@@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
46395 if (BAD_ADDR(addr))
46396 return addr;
46397 }
46398- current->mm->start_brk = current->mm->brk = end;
46399+ current->mm->start_brk = current->mm->brk = e;
46400 return 0;
46401 }
46402
46403@@ -148,12 +160,15 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46404 elf_addr_t __user *u_rand_bytes;
46405 const char *k_platform = ELF_PLATFORM;
46406 const char *k_base_platform = ELF_BASE_PLATFORM;
46407- unsigned char k_rand_bytes[16];
46408+ u32 k_rand_bytes[4];
46409 int items;
46410 elf_addr_t *elf_info;
46411 int ei_index = 0;
46412 const struct cred *cred = current_cred();
46413 struct vm_area_struct *vma;
46414+ unsigned long saved_auxv[AT_VECTOR_SIZE];
46415+
46416+ pax_track_stack();
46417
46418 /*
46419 * In some cases (e.g. Hyper-Threading), we want to avoid L1
46420@@ -195,8 +210,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46421 * Generate 16 random bytes for userspace PRNG seeding.
46422 */
46423 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
46424- u_rand_bytes = (elf_addr_t __user *)
46425- STACK_ALLOC(p, sizeof(k_rand_bytes));
46426+ srandom32(k_rand_bytes[0] ^ random32());
46427+ srandom32(k_rand_bytes[1] ^ random32());
46428+ srandom32(k_rand_bytes[2] ^ random32());
46429+ srandom32(k_rand_bytes[3] ^ random32());
46430+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
46431+ u_rand_bytes = (elf_addr_t __user *) p;
46432 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
46433 return -EFAULT;
46434
46435@@ -308,9 +327,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46436 return -EFAULT;
46437 current->mm->env_end = p;
46438
46439+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
46440+
46441 /* Put the elf_info on the stack in the right place. */
46442 sp = (elf_addr_t __user *)envp + 1;
46443- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
46444+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
46445 return -EFAULT;
46446 return 0;
46447 }
46448@@ -385,10 +406,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46449 {
46450 struct elf_phdr *elf_phdata;
46451 struct elf_phdr *eppnt;
46452- unsigned long load_addr = 0;
46453+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
46454 int load_addr_set = 0;
46455 unsigned long last_bss = 0, elf_bss = 0;
46456- unsigned long error = ~0UL;
46457+ unsigned long error = -EINVAL;
46458 unsigned long total_size;
46459 int retval, i, size;
46460
46461@@ -434,6 +455,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46462 goto out_close;
46463 }
46464
46465+#ifdef CONFIG_PAX_SEGMEXEC
46466+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
46467+ pax_task_size = SEGMEXEC_TASK_SIZE;
46468+#endif
46469+
46470 eppnt = elf_phdata;
46471 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
46472 if (eppnt->p_type == PT_LOAD) {
46473@@ -477,8 +503,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46474 k = load_addr + eppnt->p_vaddr;
46475 if (BAD_ADDR(k) ||
46476 eppnt->p_filesz > eppnt->p_memsz ||
46477- eppnt->p_memsz > TASK_SIZE ||
46478- TASK_SIZE - eppnt->p_memsz < k) {
46479+ eppnt->p_memsz > pax_task_size ||
46480+ pax_task_size - eppnt->p_memsz < k) {
46481 error = -ENOMEM;
46482 goto out_close;
46483 }
46484@@ -532,6 +558,348 @@ out:
46485 return error;
46486 }
46487
46488+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
46489+{
46490+ unsigned long pax_flags = 0UL;
46491+
46492+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46493+
46494+#ifdef CONFIG_PAX_PAGEEXEC
46495+ if (elf_phdata->p_flags & PF_PAGEEXEC)
46496+ pax_flags |= MF_PAX_PAGEEXEC;
46497+#endif
46498+
46499+#ifdef CONFIG_PAX_SEGMEXEC
46500+ if (elf_phdata->p_flags & PF_SEGMEXEC)
46501+ pax_flags |= MF_PAX_SEGMEXEC;
46502+#endif
46503+
46504+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46505+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46506+ if (nx_enabled)
46507+ pax_flags &= ~MF_PAX_SEGMEXEC;
46508+ else
46509+ pax_flags &= ~MF_PAX_PAGEEXEC;
46510+ }
46511+#endif
46512+
46513+#ifdef CONFIG_PAX_EMUTRAMP
46514+ if (elf_phdata->p_flags & PF_EMUTRAMP)
46515+ pax_flags |= MF_PAX_EMUTRAMP;
46516+#endif
46517+
46518+#ifdef CONFIG_PAX_MPROTECT
46519+ if (elf_phdata->p_flags & PF_MPROTECT)
46520+ pax_flags |= MF_PAX_MPROTECT;
46521+#endif
46522+
46523+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46524+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
46525+ pax_flags |= MF_PAX_RANDMMAP;
46526+#endif
46527+
46528+#endif
46529+
46530+ return pax_flags;
46531+}
46532+
46533+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
46534+{
46535+ unsigned long pax_flags = 0UL;
46536+
46537+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46538+
46539+#ifdef CONFIG_PAX_PAGEEXEC
46540+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
46541+ pax_flags |= MF_PAX_PAGEEXEC;
46542+#endif
46543+
46544+#ifdef CONFIG_PAX_SEGMEXEC
46545+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
46546+ pax_flags |= MF_PAX_SEGMEXEC;
46547+#endif
46548+
46549+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46550+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46551+ if (nx_enabled)
46552+ pax_flags &= ~MF_PAX_SEGMEXEC;
46553+ else
46554+ pax_flags &= ~MF_PAX_PAGEEXEC;
46555+ }
46556+#endif
46557+
46558+#ifdef CONFIG_PAX_EMUTRAMP
46559+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
46560+ pax_flags |= MF_PAX_EMUTRAMP;
46561+#endif
46562+
46563+#ifdef CONFIG_PAX_MPROTECT
46564+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
46565+ pax_flags |= MF_PAX_MPROTECT;
46566+#endif
46567+
46568+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46569+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
46570+ pax_flags |= MF_PAX_RANDMMAP;
46571+#endif
46572+
46573+#endif
46574+
46575+ return pax_flags;
46576+}
46577+
46578+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
46579+{
46580+ unsigned long pax_flags = 0UL;
46581+
46582+#ifdef CONFIG_PAX_EI_PAX
46583+
46584+#ifdef CONFIG_PAX_PAGEEXEC
46585+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
46586+ pax_flags |= MF_PAX_PAGEEXEC;
46587+#endif
46588+
46589+#ifdef CONFIG_PAX_SEGMEXEC
46590+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
46591+ pax_flags |= MF_PAX_SEGMEXEC;
46592+#endif
46593+
46594+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46595+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46596+ if (nx_enabled)
46597+ pax_flags &= ~MF_PAX_SEGMEXEC;
46598+ else
46599+ pax_flags &= ~MF_PAX_PAGEEXEC;
46600+ }
46601+#endif
46602+
46603+#ifdef CONFIG_PAX_EMUTRAMP
46604+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
46605+ pax_flags |= MF_PAX_EMUTRAMP;
46606+#endif
46607+
46608+#ifdef CONFIG_PAX_MPROTECT
46609+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
46610+ pax_flags |= MF_PAX_MPROTECT;
46611+#endif
46612+
46613+#ifdef CONFIG_PAX_ASLR
46614+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
46615+ pax_flags |= MF_PAX_RANDMMAP;
46616+#endif
46617+
46618+#else
46619+
46620+#ifdef CONFIG_PAX_PAGEEXEC
46621+ pax_flags |= MF_PAX_PAGEEXEC;
46622+#endif
46623+
46624+#ifdef CONFIG_PAX_MPROTECT
46625+ pax_flags |= MF_PAX_MPROTECT;
46626+#endif
46627+
46628+#ifdef CONFIG_PAX_RANDMMAP
46629+ pax_flags |= MF_PAX_RANDMMAP;
46630+#endif
46631+
46632+#ifdef CONFIG_PAX_SEGMEXEC
46633+ if (!(__supported_pte_mask & _PAGE_NX)) {
46634+ pax_flags &= ~MF_PAX_PAGEEXEC;
46635+ pax_flags |= MF_PAX_SEGMEXEC;
46636+ }
46637+#endif
46638+
46639+#endif
46640+
46641+ return pax_flags;
46642+}
46643+
46644+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
46645+{
46646+
46647+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46648+ unsigned long i;
46649+
46650+ for (i = 0UL; i < elf_ex->e_phnum; i++)
46651+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
46652+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
46653+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
46654+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
46655+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
46656+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
46657+ return ~0UL;
46658+
46659+#ifdef CONFIG_PAX_SOFTMODE
46660+ if (pax_softmode)
46661+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
46662+ else
46663+#endif
46664+
46665+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
46666+ break;
46667+ }
46668+#endif
46669+
46670+ return ~0UL;
46671+}
46672+
46673+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
46674+{
46675+ unsigned long pax_flags = 0UL;
46676+
46677+#ifdef CONFIG_PAX_PAGEEXEC
46678+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
46679+ pax_flags |= MF_PAX_PAGEEXEC;
46680+#endif
46681+
46682+#ifdef CONFIG_PAX_SEGMEXEC
46683+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
46684+ pax_flags |= MF_PAX_SEGMEXEC;
46685+#endif
46686+
46687+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46688+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46689+ if ((__supported_pte_mask & _PAGE_NX))
46690+ pax_flags &= ~MF_PAX_SEGMEXEC;
46691+ else
46692+ pax_flags &= ~MF_PAX_PAGEEXEC;
46693+ }
46694+#endif
46695+
46696+#ifdef CONFIG_PAX_EMUTRAMP
46697+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
46698+ pax_flags |= MF_PAX_EMUTRAMP;
46699+#endif
46700+
46701+#ifdef CONFIG_PAX_MPROTECT
46702+ if (pax_flags_softmode & MF_PAX_MPROTECT)
46703+ pax_flags |= MF_PAX_MPROTECT;
46704+#endif
46705+
46706+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46707+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
46708+ pax_flags |= MF_PAX_RANDMMAP;
46709+#endif
46710+
46711+ return pax_flags;
46712+}
46713+
46714+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
46715+{
46716+ unsigned long pax_flags = 0UL;
46717+
46718+#ifdef CONFIG_PAX_PAGEEXEC
46719+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
46720+ pax_flags |= MF_PAX_PAGEEXEC;
46721+#endif
46722+
46723+#ifdef CONFIG_PAX_SEGMEXEC
46724+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
46725+ pax_flags |= MF_PAX_SEGMEXEC;
46726+#endif
46727+
46728+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46729+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46730+ if ((__supported_pte_mask & _PAGE_NX))
46731+ pax_flags &= ~MF_PAX_SEGMEXEC;
46732+ else
46733+ pax_flags &= ~MF_PAX_PAGEEXEC;
46734+ }
46735+#endif
46736+
46737+#ifdef CONFIG_PAX_EMUTRAMP
46738+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
46739+ pax_flags |= MF_PAX_EMUTRAMP;
46740+#endif
46741+
46742+#ifdef CONFIG_PAX_MPROTECT
46743+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
46744+ pax_flags |= MF_PAX_MPROTECT;
46745+#endif
46746+
46747+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46748+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
46749+ pax_flags |= MF_PAX_RANDMMAP;
46750+#endif
46751+
46752+ return pax_flags;
46753+}
46754+
46755+static unsigned long pax_parse_xattr_pax(struct file * const file)
46756+{
46757+
46758+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
46759+ ssize_t xattr_size, i;
46760+ unsigned char xattr_value[5];
46761+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
46762+
46763+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
46764+ if (xattr_size <= 0)
46765+ return ~0UL;
46766+
46767+ for (i = 0; i < xattr_size; i++)
46768+ switch (xattr_value[i]) {
46769+ default:
46770+ return ~0UL;
46771+
46772+#define parse_flag(option1, option2, flag) \
46773+ case option1: \
46774+ pax_flags_hardmode |= MF_PAX_##flag; \
46775+ break; \
46776+ case option2: \
46777+ pax_flags_softmode |= MF_PAX_##flag; \
46778+ break;
46779+
46780+ parse_flag('p', 'P', PAGEEXEC);
46781+ parse_flag('e', 'E', EMUTRAMP);
46782+ parse_flag('m', 'M', MPROTECT);
46783+ parse_flag('r', 'R', RANDMMAP);
46784+ parse_flag('s', 'S', SEGMEXEC);
46785+
46786+#undef parse_flag
46787+ }
46788+
46789+ if (pax_flags_hardmode & pax_flags_softmode)
46790+ return ~0UL;
46791+
46792+#ifdef CONFIG_PAX_SOFTMODE
46793+ if (pax_softmode)
46794+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
46795+ else
46796+#endif
46797+
46798+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
46799+#else
46800+ return ~0UL;
46801+#endif
46802+}
46803+
46804+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
46805+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
46806+{
46807+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
46808+
46809+ pax_flags = pax_parse_ei_pax(elf_ex);
46810+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
46811+ xattr_pax_flags = pax_parse_xattr_pax(file);
46812+
46813+ if (pt_pax_flags == ~0UL)
46814+ pt_pax_flags = xattr_pax_flags;
46815+ else if (xattr_pax_flags == ~0UL)
46816+ xattr_pax_flags = pt_pax_flags;
46817+ if (pt_pax_flags != xattr_pax_flags)
46818+ return -EINVAL;
46819+ if (pt_pax_flags != ~0UL)
46820+ pax_flags = pt_pax_flags;
46821+
46822+ if (0 > pax_check_flags(&pax_flags))
46823+ return -EINVAL;
46824+
46825+ current->mm->pax_flags = pax_flags;
46826+ return 0;
46827+}
46828+#endif
46829+
46830 /*
46831 * These are the functions used to load ELF style executables and shared
46832 * libraries. There is no binary dependent code anywhere else.
46833@@ -548,6 +916,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
46834 {
46835 unsigned int random_variable = 0;
46836
46837+#ifdef CONFIG_PAX_RANDUSTACK
46838+ if (randomize_va_space)
46839+ return stack_top - current->mm->delta_stack;
46840+#endif
46841+
46842 if ((current->flags & PF_RANDOMIZE) &&
46843 !(current->personality & ADDR_NO_RANDOMIZE)) {
46844 random_variable = get_random_int() & STACK_RND_MASK;
46845@@ -566,7 +939,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46846 unsigned long load_addr = 0, load_bias = 0;
46847 int load_addr_set = 0;
46848 char * elf_interpreter = NULL;
46849- unsigned long error;
46850+ unsigned long error = 0;
46851 struct elf_phdr *elf_ppnt, *elf_phdata;
46852 unsigned long elf_bss, elf_brk;
46853 int retval, i;
46854@@ -576,11 +949,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46855 unsigned long start_code, end_code, start_data, end_data;
46856 unsigned long reloc_func_desc = 0;
46857 int executable_stack = EXSTACK_DEFAULT;
46858- unsigned long def_flags = 0;
46859 struct {
46860 struct elfhdr elf_ex;
46861 struct elfhdr interp_elf_ex;
46862 } *loc;
46863+ unsigned long pax_task_size = TASK_SIZE;
46864
46865 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
46866 if (!loc) {
46867@@ -718,11 +1091,80 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46868
46869 /* OK, This is the point of no return */
46870 current->flags &= ~PF_FORKNOEXEC;
46871- current->mm->def_flags = def_flags;
46872+
46873+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46874+ current->mm->pax_flags = 0UL;
46875+#endif
46876+
46877+#ifdef CONFIG_PAX_DLRESOLVE
46878+ current->mm->call_dl_resolve = 0UL;
46879+#endif
46880+
46881+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
46882+ current->mm->call_syscall = 0UL;
46883+#endif
46884+
46885+#ifdef CONFIG_PAX_ASLR
46886+ current->mm->delta_mmap = 0UL;
46887+ current->mm->delta_stack = 0UL;
46888+#endif
46889+
46890+ current->mm->def_flags = 0;
46891+
46892+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
46893+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
46894+ send_sig(SIGKILL, current, 0);
46895+ goto out_free_dentry;
46896+ }
46897+#endif
46898+
46899+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46900+ pax_set_initial_flags(bprm);
46901+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
46902+ if (pax_set_initial_flags_func)
46903+ (pax_set_initial_flags_func)(bprm);
46904+#endif
46905+
46906+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46907+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
46908+ current->mm->context.user_cs_limit = PAGE_SIZE;
46909+ current->mm->def_flags |= VM_PAGEEXEC;
46910+ }
46911+#endif
46912+
46913+#ifdef CONFIG_PAX_SEGMEXEC
46914+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
46915+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
46916+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
46917+ pax_task_size = SEGMEXEC_TASK_SIZE;
46918+ }
46919+#endif
46920+
46921+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
46922+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46923+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
46924+ put_cpu();
46925+ }
46926+#endif
46927
46928 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
46929 may depend on the personality. */
46930 SET_PERSONALITY(loc->elf_ex);
46931+
46932+#ifdef CONFIG_PAX_ASLR
46933+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
46934+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
46935+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
46936+ }
46937+#endif
46938+
46939+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46940+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46941+ executable_stack = EXSTACK_DISABLE_X;
46942+ current->personality &= ~READ_IMPLIES_EXEC;
46943+ } else
46944+#endif
46945+
46946 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
46947 current->personality |= READ_IMPLIES_EXEC;
46948
46949@@ -800,10 +1242,27 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46950 * might try to exec. This is because the brk will
46951 * follow the loader, and is not movable. */
46952 #ifdef CONFIG_X86
46953- load_bias = 0;
46954+ if (current->flags & PF_RANDOMIZE)
46955+ load_bias = 0;
46956+ else
46957+ load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
46958 #else
46959 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
46960 #endif
46961+
46962+#ifdef CONFIG_PAX_RANDMMAP
46963+ /* PaX: randomize base address at the default exe base if requested */
46964+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
46965+#ifdef CONFIG_SPARC64
46966+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
46967+#else
46968+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
46969+#endif
46970+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
46971+ elf_flags |= MAP_FIXED;
46972+ }
46973+#endif
46974+
46975 }
46976
46977 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
46978@@ -836,9 +1295,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46979 * allowed task size. Note that p_filesz must always be
46980 * <= p_memsz so it is only necessary to check p_memsz.
46981 */
46982- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46983- elf_ppnt->p_memsz > TASK_SIZE ||
46984- TASK_SIZE - elf_ppnt->p_memsz < k) {
46985+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46986+ elf_ppnt->p_memsz > pax_task_size ||
46987+ pax_task_size - elf_ppnt->p_memsz < k) {
46988 /* set_brk can never work. Avoid overflows. */
46989 send_sig(SIGKILL, current, 0);
46990 retval = -EINVAL;
46991@@ -866,6 +1325,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46992 start_data += load_bias;
46993 end_data += load_bias;
46994
46995+#ifdef CONFIG_PAX_RANDMMAP
46996+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
46997+ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
46998+#endif
46999+
47000 /* Calling set_brk effectively mmaps the pages that we need
47001 * for the bss and break sections. We must do this before
47002 * mapping in the interpreter, to make sure it doesn't wind
47003@@ -877,9 +1341,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
47004 goto out_free_dentry;
47005 }
47006 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
47007- send_sig(SIGSEGV, current, 0);
47008- retval = -EFAULT; /* Nobody gets to see this, but.. */
47009- goto out_free_dentry;
47010+ /*
47011+ * This bss-zeroing can fail if the ELF
47012+ * file specifies odd protections. So
47013+ * we don't check the return value
47014+ */
47015 }
47016
47017 if (elf_interpreter) {
47018@@ -1112,8 +1578,10 @@ static int dump_seek(struct file *file, loff_t off)
47019 unsigned long n = off;
47020 if (n > PAGE_SIZE)
47021 n = PAGE_SIZE;
47022- if (!dump_write(file, buf, n))
47023+ if (!dump_write(file, buf, n)) {
47024+ free_page((unsigned long)buf);
47025 return 0;
47026+ }
47027 off -= n;
47028 }
47029 free_page((unsigned long)buf);
47030@@ -1125,7 +1593,7 @@ static int dump_seek(struct file *file, loff_t off)
47031 * Decide what to dump of a segment, part, all or none.
47032 */
47033 static unsigned long vma_dump_size(struct vm_area_struct *vma,
47034- unsigned long mm_flags)
47035+ unsigned long mm_flags, long signr)
47036 {
47037 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
47038
47039@@ -1159,7 +1627,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
47040 if (vma->vm_file == NULL)
47041 return 0;
47042
47043- if (FILTER(MAPPED_PRIVATE))
47044+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
47045 goto whole;
47046
47047 /*
47048@@ -1255,8 +1723,11 @@ static int writenote(struct memelfnote *men, struct file *file,
47049 #undef DUMP_WRITE
47050
47051 #define DUMP_WRITE(addr, nr) \
47052+ do { \
47053+ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
47054 if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
47055- goto end_coredump;
47056+ goto end_coredump; \
47057+ } while (0);
47058
47059 static void fill_elf_header(struct elfhdr *elf, int segs,
47060 u16 machine, u32 flags, u8 osabi)
47061@@ -1385,9 +1856,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
47062 {
47063 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
47064 int i = 0;
47065- do
47066+ do {
47067 i += 2;
47068- while (auxv[i - 2] != AT_NULL);
47069+ } while (auxv[i - 2] != AT_NULL);
47070 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
47071 }
47072
47073@@ -1973,7 +2444,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
47074 phdr.p_offset = offset;
47075 phdr.p_vaddr = vma->vm_start;
47076 phdr.p_paddr = 0;
47077- phdr.p_filesz = vma_dump_size(vma, mm_flags);
47078+ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
47079 phdr.p_memsz = vma->vm_end - vma->vm_start;
47080 offset += phdr.p_filesz;
47081 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
47082@@ -2006,7 +2477,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
47083 unsigned long addr;
47084 unsigned long end;
47085
47086- end = vma->vm_start + vma_dump_size(vma, mm_flags);
47087+ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
47088
47089 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
47090 struct page *page;
47091@@ -2015,6 +2486,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
47092 page = get_dump_page(addr);
47093 if (page) {
47094 void *kaddr = kmap(page);
47095+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
47096 stop = ((size += PAGE_SIZE) > limit) ||
47097 !dump_write(file, kaddr, PAGE_SIZE);
47098 kunmap(page);
47099@@ -2042,6 +2514,97 @@ out:
47100
47101 #endif /* USE_ELF_CORE_DUMP */
47102
47103+#ifdef CONFIG_PAX_MPROTECT
47104+/* PaX: non-PIC ELF libraries need relocations on their executable segments
47105+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
47106+ * we'll remove VM_MAYWRITE for good on RELRO segments.
47107+ *
47108+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
47109+ * basis because we want to allow the common case and not the special ones.
47110+ */
47111+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
47112+{
47113+ struct elfhdr elf_h;
47114+ struct elf_phdr elf_p;
47115+ unsigned long i;
47116+ unsigned long oldflags;
47117+ bool is_textrel_rw, is_textrel_rx, is_relro;
47118+
47119+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
47120+ return;
47121+
47122+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
47123+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
47124+
47125+#ifdef CONFIG_PAX_ELFRELOCS
47126+ /* possible TEXTREL */
47127+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
47128+ 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);
47129+#else
47130+ is_textrel_rw = false;
47131+ is_textrel_rx = false;
47132+#endif
47133+
47134+ /* possible RELRO */
47135+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
47136+
47137+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
47138+ return;
47139+
47140+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
47141+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
47142+
47143+#ifdef CONFIG_PAX_ETEXECRELOCS
47144+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
47145+#else
47146+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
47147+#endif
47148+
47149+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
47150+ !elf_check_arch(&elf_h) ||
47151+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
47152+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
47153+ return;
47154+
47155+ for (i = 0UL; i < elf_h.e_phnum; i++) {
47156+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
47157+ return;
47158+ switch (elf_p.p_type) {
47159+ case PT_DYNAMIC:
47160+ if (!is_textrel_rw && !is_textrel_rx)
47161+ continue;
47162+ i = 0UL;
47163+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
47164+ elf_dyn dyn;
47165+
47166+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
47167+ return;
47168+ if (dyn.d_tag == DT_NULL)
47169+ return;
47170+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
47171+ gr_log_textrel(vma);
47172+ if (is_textrel_rw)
47173+ vma->vm_flags |= VM_MAYWRITE;
47174+ else
47175+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
47176+ vma->vm_flags &= ~VM_MAYWRITE;
47177+ return;
47178+ }
47179+ i++;
47180+ }
47181+ return;
47182+
47183+ case PT_GNU_RELRO:
47184+ if (!is_relro)
47185+ continue;
47186+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
47187+ vma->vm_flags &= ~VM_MAYWRITE;
47188+ return;
47189+ }
47190+ }
47191+}
47192+#endif
47193+
47194 static int __init init_elf_binfmt(void)
47195 {
47196 return register_binfmt(&elf_format);
47197diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
47198index ca88c46..f155a60 100644
47199--- a/fs/binfmt_flat.c
47200+++ b/fs/binfmt_flat.c
47201@@ -564,7 +564,9 @@ static int load_flat_file(struct linux_binprm * bprm,
47202 realdatastart = (unsigned long) -ENOMEM;
47203 printk("Unable to allocate RAM for process data, errno %d\n",
47204 (int)-realdatastart);
47205+ down_write(&current->mm->mmap_sem);
47206 do_munmap(current->mm, textpos, text_len);
47207+ up_write(&current->mm->mmap_sem);
47208 ret = realdatastart;
47209 goto err;
47210 }
47211@@ -588,8 +590,10 @@ static int load_flat_file(struct linux_binprm * bprm,
47212 }
47213 if (IS_ERR_VALUE(result)) {
47214 printk("Unable to read data+bss, errno %d\n", (int)-result);
47215+ down_write(&current->mm->mmap_sem);
47216 do_munmap(current->mm, textpos, text_len);
47217 do_munmap(current->mm, realdatastart, data_len + extra);
47218+ up_write(&current->mm->mmap_sem);
47219 ret = result;
47220 goto err;
47221 }
47222@@ -658,8 +662,10 @@ static int load_flat_file(struct linux_binprm * bprm,
47223 }
47224 if (IS_ERR_VALUE(result)) {
47225 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
47226+ down_write(&current->mm->mmap_sem);
47227 do_munmap(current->mm, textpos, text_len + data_len + extra +
47228 MAX_SHARED_LIBS * sizeof(unsigned long));
47229+ up_write(&current->mm->mmap_sem);
47230 ret = result;
47231 goto err;
47232 }
47233diff --git a/fs/bio.c b/fs/bio.c
47234index e696713..83de133 100644
47235--- a/fs/bio.c
47236+++ b/fs/bio.c
47237@@ -78,7 +78,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
47238
47239 i = 0;
47240 while (i < bio_slab_nr) {
47241- struct bio_slab *bslab = &bio_slabs[i];
47242+ bslab = &bio_slabs[i];
47243
47244 if (!bslab->slab && entry == -1)
47245 entry = i;
47246@@ -1236,7 +1236,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
47247 const int read = bio_data_dir(bio) == READ;
47248 struct bio_map_data *bmd = bio->bi_private;
47249 int i;
47250- char *p = bmd->sgvecs[0].iov_base;
47251+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
47252
47253 __bio_for_each_segment(bvec, bio, i, 0) {
47254 char *addr = page_address(bvec->bv_page);
47255diff --git a/fs/block_dev.c b/fs/block_dev.c
47256index e65efa2..04fae57 100644
47257--- a/fs/block_dev.c
47258+++ b/fs/block_dev.c
47259@@ -664,7 +664,7 @@ int bd_claim(struct block_device *bdev, void *holder)
47260 else if (bdev->bd_contains == bdev)
47261 res = 0; /* is a whole device which isn't held */
47262
47263- else if (bdev->bd_contains->bd_holder == bd_claim)
47264+ else if (bdev->bd_contains->bd_holder == (void *)bd_claim)
47265 res = 0; /* is a partition of a device that is being partitioned */
47266 else if (bdev->bd_contains->bd_holder != NULL)
47267 res = -EBUSY; /* is a partition of a held device */
47268diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
47269index c4bc570..42acd8d 100644
47270--- a/fs/btrfs/ctree.c
47271+++ b/fs/btrfs/ctree.c
47272@@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
47273 free_extent_buffer(buf);
47274 add_root_to_dirty_list(root);
47275 } else {
47276- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
47277- parent_start = parent->start;
47278- else
47279+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
47280+ if (parent)
47281+ parent_start = parent->start;
47282+ else
47283+ parent_start = 0;
47284+ } else
47285 parent_start = 0;
47286
47287 WARN_ON(trans->transid != btrfs_header_generation(parent));
47288@@ -3645,7 +3648,6 @@ setup_items_for_insert(struct btrfs_trans_handle *trans,
47289
47290 ret = 0;
47291 if (slot == 0) {
47292- struct btrfs_disk_key disk_key;
47293 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
47294 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
47295 }
47296diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
47297index f447188..59c17c5 100644
47298--- a/fs/btrfs/disk-io.c
47299+++ b/fs/btrfs/disk-io.c
47300@@ -39,7 +39,7 @@
47301 #include "tree-log.h"
47302 #include "free-space-cache.h"
47303
47304-static struct extent_io_ops btree_extent_io_ops;
47305+static const struct extent_io_ops btree_extent_io_ops;
47306 static void end_workqueue_fn(struct btrfs_work *work);
47307 static void free_fs_root(struct btrfs_root *root);
47308
47309@@ -2607,7 +2607,7 @@ out:
47310 return 0;
47311 }
47312
47313-static struct extent_io_ops btree_extent_io_ops = {
47314+static const struct extent_io_ops btree_extent_io_ops = {
47315 .write_cache_pages_lock_hook = btree_lock_page_hook,
47316 .readpage_end_io_hook = btree_readpage_end_io_hook,
47317 .submit_bio_hook = btree_submit_bio_hook,
47318diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
47319index 559f724..a026171 100644
47320--- a/fs/btrfs/extent-tree.c
47321+++ b/fs/btrfs/extent-tree.c
47322@@ -7141,6 +7141,10 @@ static noinline int relocate_one_extent(struct btrfs_root *extent_root,
47323 u64 group_start = group->key.objectid;
47324 new_extents = kmalloc(sizeof(*new_extents),
47325 GFP_NOFS);
47326+ if (!new_extents) {
47327+ ret = -ENOMEM;
47328+ goto out;
47329+ }
47330 nr_extents = 1;
47331 ret = get_new_locations(reloc_inode,
47332 extent_key,
47333diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
47334index 36de250..7ec75c7 100644
47335--- a/fs/btrfs/extent_io.h
47336+++ b/fs/btrfs/extent_io.h
47337@@ -49,36 +49,36 @@ typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
47338 struct bio *bio, int mirror_num,
47339 unsigned long bio_flags);
47340 struct extent_io_ops {
47341- int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
47342+ int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
47343 u64 start, u64 end, int *page_started,
47344 unsigned long *nr_written);
47345- int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
47346- int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
47347+ int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
47348+ int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
47349 extent_submit_bio_hook_t *submit_bio_hook;
47350- int (*merge_bio_hook)(struct page *page, unsigned long offset,
47351+ int (* const merge_bio_hook)(struct page *page, unsigned long offset,
47352 size_t size, struct bio *bio,
47353 unsigned long bio_flags);
47354- int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
47355- int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
47356+ int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
47357+ int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
47358 u64 start, u64 end,
47359 struct extent_state *state);
47360- int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
47361+ int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
47362 u64 start, u64 end,
47363 struct extent_state *state);
47364- int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
47365+ int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
47366 struct extent_state *state);
47367- int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
47368+ int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
47369 struct extent_state *state, int uptodate);
47370- int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
47371+ int (* const set_bit_hook)(struct inode *inode, u64 start, u64 end,
47372 unsigned long old, unsigned long bits);
47373- int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
47374+ int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
47375 unsigned long bits);
47376- int (*merge_extent_hook)(struct inode *inode,
47377+ int (* const merge_extent_hook)(struct inode *inode,
47378 struct extent_state *new,
47379 struct extent_state *other);
47380- int (*split_extent_hook)(struct inode *inode,
47381+ int (* const split_extent_hook)(struct inode *inode,
47382 struct extent_state *orig, u64 split);
47383- int (*write_cache_pages_lock_hook)(struct page *page);
47384+ int (* const write_cache_pages_lock_hook)(struct page *page);
47385 };
47386
47387 struct extent_io_tree {
47388@@ -88,7 +88,7 @@ struct extent_io_tree {
47389 u64 dirty_bytes;
47390 spinlock_t lock;
47391 spinlock_t buffer_lock;
47392- struct extent_io_ops *ops;
47393+ const struct extent_io_ops *ops;
47394 };
47395
47396 struct extent_state {
47397diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
47398index cb2849f..3718fb4 100644
47399--- a/fs/btrfs/free-space-cache.c
47400+++ b/fs/btrfs/free-space-cache.c
47401@@ -1074,8 +1074,6 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group,
47402
47403 while(1) {
47404 if (entry->bytes < bytes || entry->offset < min_start) {
47405- struct rb_node *node;
47406-
47407 node = rb_next(&entry->offset_index);
47408 if (!node)
47409 break;
47410@@ -1226,7 +1224,7 @@ again:
47411 */
47412 while (entry->bitmap || found_bitmap ||
47413 (!entry->bitmap && entry->bytes < min_bytes)) {
47414- struct rb_node *node = rb_next(&entry->offset_index);
47415+ node = rb_next(&entry->offset_index);
47416
47417 if (entry->bitmap && entry->bytes > bytes + empty_size) {
47418 ret = btrfs_bitmap_cluster(block_group, entry, cluster,
47419diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
47420index e03a836..323837e 100644
47421--- a/fs/btrfs/inode.c
47422+++ b/fs/btrfs/inode.c
47423@@ -63,7 +63,7 @@ static const struct inode_operations btrfs_file_inode_operations;
47424 static const struct address_space_operations btrfs_aops;
47425 static const struct address_space_operations btrfs_symlink_aops;
47426 static const struct file_operations btrfs_dir_file_operations;
47427-static struct extent_io_ops btrfs_extent_io_ops;
47428+static const struct extent_io_ops btrfs_extent_io_ops;
47429
47430 static struct kmem_cache *btrfs_inode_cachep;
47431 struct kmem_cache *btrfs_trans_handle_cachep;
47432@@ -925,6 +925,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
47433 1, 0, NULL, GFP_NOFS);
47434 while (start < end) {
47435 async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
47436+ BUG_ON(!async_cow);
47437 async_cow->inode = inode;
47438 async_cow->root = root;
47439 async_cow->locked_page = locked_page;
47440@@ -4591,6 +4592,8 @@ static noinline int uncompress_inline(struct btrfs_path *path,
47441 inline_size = btrfs_file_extent_inline_item_len(leaf,
47442 btrfs_item_nr(leaf, path->slots[0]));
47443 tmp = kmalloc(inline_size, GFP_NOFS);
47444+ if (!tmp)
47445+ return -ENOMEM;
47446 ptr = btrfs_file_extent_inline_start(item);
47447
47448 read_extent_buffer(leaf, tmp, ptr, inline_size);
47449@@ -5410,7 +5413,7 @@ fail:
47450 return -ENOMEM;
47451 }
47452
47453-static int btrfs_getattr(struct vfsmount *mnt,
47454+int btrfs_getattr(struct vfsmount *mnt,
47455 struct dentry *dentry, struct kstat *stat)
47456 {
47457 struct inode *inode = dentry->d_inode;
47458@@ -5422,6 +5425,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
47459 return 0;
47460 }
47461
47462+EXPORT_SYMBOL(btrfs_getattr);
47463+
47464+dev_t get_btrfs_dev_from_inode(struct inode *inode)
47465+{
47466+ return BTRFS_I(inode)->root->anon_super.s_dev;
47467+}
47468+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
47469+
47470 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
47471 struct inode *new_dir, struct dentry *new_dentry)
47472 {
47473@@ -5972,7 +5983,7 @@ static const struct file_operations btrfs_dir_file_operations = {
47474 .fsync = btrfs_sync_file,
47475 };
47476
47477-static struct extent_io_ops btrfs_extent_io_ops = {
47478+static const struct extent_io_ops btrfs_extent_io_ops = {
47479 .fill_delalloc = run_delalloc_range,
47480 .submit_bio_hook = btrfs_submit_bio_hook,
47481 .merge_bio_hook = btrfs_merge_bio_hook,
47482diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
47483index ab7ab53..94e0781 100644
47484--- a/fs/btrfs/relocation.c
47485+++ b/fs/btrfs/relocation.c
47486@@ -884,7 +884,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
47487 }
47488 spin_unlock(&rc->reloc_root_tree.lock);
47489
47490- BUG_ON((struct btrfs_root *)node->data != root);
47491+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
47492
47493 if (!del) {
47494 spin_lock(&rc->reloc_root_tree.lock);
47495diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
47496index a240b6f..4ce16ef 100644
47497--- a/fs/btrfs/sysfs.c
47498+++ b/fs/btrfs/sysfs.c
47499@@ -164,12 +164,12 @@ static void btrfs_root_release(struct kobject *kobj)
47500 complete(&root->kobj_unregister);
47501 }
47502
47503-static struct sysfs_ops btrfs_super_attr_ops = {
47504+static const struct sysfs_ops btrfs_super_attr_ops = {
47505 .show = btrfs_super_attr_show,
47506 .store = btrfs_super_attr_store,
47507 };
47508
47509-static struct sysfs_ops btrfs_root_attr_ops = {
47510+static const struct sysfs_ops btrfs_root_attr_ops = {
47511 .show = btrfs_root_attr_show,
47512 .store = btrfs_root_attr_store,
47513 };
47514diff --git a/fs/buffer.c b/fs/buffer.c
47515index 6fa5302..395d9f6 100644
47516--- a/fs/buffer.c
47517+++ b/fs/buffer.c
47518@@ -25,6 +25,7 @@
47519 #include <linux/percpu.h>
47520 #include <linux/slab.h>
47521 #include <linux/capability.h>
47522+#include <linux/security.h>
47523 #include <linux/blkdev.h>
47524 #include <linux/file.h>
47525 #include <linux/quotaops.h>
47526diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
47527index 3797e00..ce776f6 100644
47528--- a/fs/cachefiles/bind.c
47529+++ b/fs/cachefiles/bind.c
47530@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
47531 args);
47532
47533 /* start by checking things over */
47534- ASSERT(cache->fstop_percent >= 0 &&
47535- cache->fstop_percent < cache->fcull_percent &&
47536+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
47537 cache->fcull_percent < cache->frun_percent &&
47538 cache->frun_percent < 100);
47539
47540- ASSERT(cache->bstop_percent >= 0 &&
47541- cache->bstop_percent < cache->bcull_percent &&
47542+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
47543 cache->bcull_percent < cache->brun_percent &&
47544 cache->brun_percent < 100);
47545
47546diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
47547index 4618516..bb30d01 100644
47548--- a/fs/cachefiles/daemon.c
47549+++ b/fs/cachefiles/daemon.c
47550@@ -220,7 +220,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
47551 if (test_bit(CACHEFILES_DEAD, &cache->flags))
47552 return -EIO;
47553
47554- if (datalen < 0 || datalen > PAGE_SIZE - 1)
47555+ if (datalen > PAGE_SIZE - 1)
47556 return -EOPNOTSUPP;
47557
47558 /* drag the command string into the kernel so we can parse it */
47559@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
47560 if (args[0] != '%' || args[1] != '\0')
47561 return -EINVAL;
47562
47563- if (fstop < 0 || fstop >= cache->fcull_percent)
47564+ if (fstop >= cache->fcull_percent)
47565 return cachefiles_daemon_range_error(cache, args);
47566
47567 cache->fstop_percent = fstop;
47568@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
47569 if (args[0] != '%' || args[1] != '\0')
47570 return -EINVAL;
47571
47572- if (bstop < 0 || bstop >= cache->bcull_percent)
47573+ if (bstop >= cache->bcull_percent)
47574 return cachefiles_daemon_range_error(cache, args);
47575
47576 cache->bstop_percent = bstop;
47577diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
47578index f7c255f..fcd61de 100644
47579--- a/fs/cachefiles/internal.h
47580+++ b/fs/cachefiles/internal.h
47581@@ -56,7 +56,7 @@ struct cachefiles_cache {
47582 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
47583 struct rb_root active_nodes; /* active nodes (can't be culled) */
47584 rwlock_t active_lock; /* lock for active_nodes */
47585- atomic_t gravecounter; /* graveyard uniquifier */
47586+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
47587 unsigned frun_percent; /* when to stop culling (% files) */
47588 unsigned fcull_percent; /* when to start culling (% files) */
47589 unsigned fstop_percent; /* when to stop allocating (% files) */
47590@@ -168,19 +168,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
47591 * proc.c
47592 */
47593 #ifdef CONFIG_CACHEFILES_HISTOGRAM
47594-extern atomic_t cachefiles_lookup_histogram[HZ];
47595-extern atomic_t cachefiles_mkdir_histogram[HZ];
47596-extern atomic_t cachefiles_create_histogram[HZ];
47597+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
47598+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
47599+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
47600
47601 extern int __init cachefiles_proc_init(void);
47602 extern void cachefiles_proc_cleanup(void);
47603 static inline
47604-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
47605+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
47606 {
47607 unsigned long jif = jiffies - start_jif;
47608 if (jif >= HZ)
47609 jif = HZ - 1;
47610- atomic_inc(&histogram[jif]);
47611+ atomic_inc_unchecked(&histogram[jif]);
47612 }
47613
47614 #else
47615diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
47616index 14ac480..a62766c 100644
47617--- a/fs/cachefiles/namei.c
47618+++ b/fs/cachefiles/namei.c
47619@@ -250,7 +250,7 @@ try_again:
47620 /* first step is to make up a grave dentry in the graveyard */
47621 sprintf(nbuffer, "%08x%08x",
47622 (uint32_t) get_seconds(),
47623- (uint32_t) atomic_inc_return(&cache->gravecounter));
47624+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
47625
47626 /* do the multiway lock magic */
47627 trap = lock_rename(cache->graveyard, dir);
47628diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
47629index eccd339..4c1d995 100644
47630--- a/fs/cachefiles/proc.c
47631+++ b/fs/cachefiles/proc.c
47632@@ -14,9 +14,9 @@
47633 #include <linux/seq_file.h>
47634 #include "internal.h"
47635
47636-atomic_t cachefiles_lookup_histogram[HZ];
47637-atomic_t cachefiles_mkdir_histogram[HZ];
47638-atomic_t cachefiles_create_histogram[HZ];
47639+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
47640+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
47641+atomic_unchecked_t cachefiles_create_histogram[HZ];
47642
47643 /*
47644 * display the latency histogram
47645@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
47646 return 0;
47647 default:
47648 index = (unsigned long) v - 3;
47649- x = atomic_read(&cachefiles_lookup_histogram[index]);
47650- y = atomic_read(&cachefiles_mkdir_histogram[index]);
47651- z = atomic_read(&cachefiles_create_histogram[index]);
47652+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
47653+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
47654+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
47655 if (x == 0 && y == 0 && z == 0)
47656 return 0;
47657
47658diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
47659index a6c8c6f..5cf8517 100644
47660--- a/fs/cachefiles/rdwr.c
47661+++ b/fs/cachefiles/rdwr.c
47662@@ -946,7 +946,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
47663 old_fs = get_fs();
47664 set_fs(KERNEL_DS);
47665 ret = file->f_op->write(
47666- file, (const void __user *) data, len, &pos);
47667+ file, (const void __force_user *) data, len, &pos);
47668 set_fs(old_fs);
47669 kunmap(page);
47670 if (ret != len)
47671diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
47672index 42cec2a..2aba466 100644
47673--- a/fs/cifs/cifs_debug.c
47674+++ b/fs/cifs/cifs_debug.c
47675@@ -256,25 +256,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
47676 tcon = list_entry(tmp3,
47677 struct cifsTconInfo,
47678 tcon_list);
47679- atomic_set(&tcon->num_smbs_sent, 0);
47680- atomic_set(&tcon->num_writes, 0);
47681- atomic_set(&tcon->num_reads, 0);
47682- atomic_set(&tcon->num_oplock_brks, 0);
47683- atomic_set(&tcon->num_opens, 0);
47684- atomic_set(&tcon->num_posixopens, 0);
47685- atomic_set(&tcon->num_posixmkdirs, 0);
47686- atomic_set(&tcon->num_closes, 0);
47687- atomic_set(&tcon->num_deletes, 0);
47688- atomic_set(&tcon->num_mkdirs, 0);
47689- atomic_set(&tcon->num_rmdirs, 0);
47690- atomic_set(&tcon->num_renames, 0);
47691- atomic_set(&tcon->num_t2renames, 0);
47692- atomic_set(&tcon->num_ffirst, 0);
47693- atomic_set(&tcon->num_fnext, 0);
47694- atomic_set(&tcon->num_fclose, 0);
47695- atomic_set(&tcon->num_hardlinks, 0);
47696- atomic_set(&tcon->num_symlinks, 0);
47697- atomic_set(&tcon->num_locks, 0);
47698+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
47699+ atomic_set_unchecked(&tcon->num_writes, 0);
47700+ atomic_set_unchecked(&tcon->num_reads, 0);
47701+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
47702+ atomic_set_unchecked(&tcon->num_opens, 0);
47703+ atomic_set_unchecked(&tcon->num_posixopens, 0);
47704+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
47705+ atomic_set_unchecked(&tcon->num_closes, 0);
47706+ atomic_set_unchecked(&tcon->num_deletes, 0);
47707+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
47708+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
47709+ atomic_set_unchecked(&tcon->num_renames, 0);
47710+ atomic_set_unchecked(&tcon->num_t2renames, 0);
47711+ atomic_set_unchecked(&tcon->num_ffirst, 0);
47712+ atomic_set_unchecked(&tcon->num_fnext, 0);
47713+ atomic_set_unchecked(&tcon->num_fclose, 0);
47714+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
47715+ atomic_set_unchecked(&tcon->num_symlinks, 0);
47716+ atomic_set_unchecked(&tcon->num_locks, 0);
47717 }
47718 }
47719 }
47720@@ -334,41 +334,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
47721 if (tcon->need_reconnect)
47722 seq_puts(m, "\tDISCONNECTED ");
47723 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
47724- atomic_read(&tcon->num_smbs_sent),
47725- atomic_read(&tcon->num_oplock_brks));
47726+ atomic_read_unchecked(&tcon->num_smbs_sent),
47727+ atomic_read_unchecked(&tcon->num_oplock_brks));
47728 seq_printf(m, "\nReads: %d Bytes: %lld",
47729- atomic_read(&tcon->num_reads),
47730+ atomic_read_unchecked(&tcon->num_reads),
47731 (long long)(tcon->bytes_read));
47732 seq_printf(m, "\nWrites: %d Bytes: %lld",
47733- atomic_read(&tcon->num_writes),
47734+ atomic_read_unchecked(&tcon->num_writes),
47735 (long long)(tcon->bytes_written));
47736 seq_printf(m, "\nFlushes: %d",
47737- atomic_read(&tcon->num_flushes));
47738+ atomic_read_unchecked(&tcon->num_flushes));
47739 seq_printf(m, "\nLocks: %d HardLinks: %d "
47740 "Symlinks: %d",
47741- atomic_read(&tcon->num_locks),
47742- atomic_read(&tcon->num_hardlinks),
47743- atomic_read(&tcon->num_symlinks));
47744+ atomic_read_unchecked(&tcon->num_locks),
47745+ atomic_read_unchecked(&tcon->num_hardlinks),
47746+ atomic_read_unchecked(&tcon->num_symlinks));
47747 seq_printf(m, "\nOpens: %d Closes: %d "
47748 "Deletes: %d",
47749- atomic_read(&tcon->num_opens),
47750- atomic_read(&tcon->num_closes),
47751- atomic_read(&tcon->num_deletes));
47752+ atomic_read_unchecked(&tcon->num_opens),
47753+ atomic_read_unchecked(&tcon->num_closes),
47754+ atomic_read_unchecked(&tcon->num_deletes));
47755 seq_printf(m, "\nPosix Opens: %d "
47756 "Posix Mkdirs: %d",
47757- atomic_read(&tcon->num_posixopens),
47758- atomic_read(&tcon->num_posixmkdirs));
47759+ atomic_read_unchecked(&tcon->num_posixopens),
47760+ atomic_read_unchecked(&tcon->num_posixmkdirs));
47761 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
47762- atomic_read(&tcon->num_mkdirs),
47763- atomic_read(&tcon->num_rmdirs));
47764+ atomic_read_unchecked(&tcon->num_mkdirs),
47765+ atomic_read_unchecked(&tcon->num_rmdirs));
47766 seq_printf(m, "\nRenames: %d T2 Renames %d",
47767- atomic_read(&tcon->num_renames),
47768- atomic_read(&tcon->num_t2renames));
47769+ atomic_read_unchecked(&tcon->num_renames),
47770+ atomic_read_unchecked(&tcon->num_t2renames));
47771 seq_printf(m, "\nFindFirst: %d FNext %d "
47772 "FClose %d",
47773- atomic_read(&tcon->num_ffirst),
47774- atomic_read(&tcon->num_fnext),
47775- atomic_read(&tcon->num_fclose));
47776+ atomic_read_unchecked(&tcon->num_ffirst),
47777+ atomic_read_unchecked(&tcon->num_fnext),
47778+ atomic_read_unchecked(&tcon->num_fclose));
47779 }
47780 }
47781 }
47782diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
47783index 1445407..68cb0dc 100644
47784--- a/fs/cifs/cifsfs.c
47785+++ b/fs/cifs/cifsfs.c
47786@@ -869,7 +869,7 @@ cifs_init_request_bufs(void)
47787 cifs_req_cachep = kmem_cache_create("cifs_request",
47788 CIFSMaxBufSize +
47789 MAX_CIFS_HDR_SIZE, 0,
47790- SLAB_HWCACHE_ALIGN, NULL);
47791+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
47792 if (cifs_req_cachep == NULL)
47793 return -ENOMEM;
47794
47795@@ -896,7 +896,7 @@ cifs_init_request_bufs(void)
47796 efficient to alloc 1 per page off the slab compared to 17K (5page)
47797 alloc of large cifs buffers even when page debugging is on */
47798 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
47799- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
47800+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
47801 NULL);
47802 if (cifs_sm_req_cachep == NULL) {
47803 mempool_destroy(cifs_req_poolp);
47804@@ -991,8 +991,8 @@ init_cifs(void)
47805 atomic_set(&bufAllocCount, 0);
47806 atomic_set(&smBufAllocCount, 0);
47807 #ifdef CONFIG_CIFS_STATS2
47808- atomic_set(&totBufAllocCount, 0);
47809- atomic_set(&totSmBufAllocCount, 0);
47810+ atomic_set_unchecked(&totBufAllocCount, 0);
47811+ atomic_set_unchecked(&totSmBufAllocCount, 0);
47812 #endif /* CONFIG_CIFS_STATS2 */
47813
47814 atomic_set(&midCount, 0);
47815diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
47816index e29581e..1c22bab 100644
47817--- a/fs/cifs/cifsglob.h
47818+++ b/fs/cifs/cifsglob.h
47819@@ -252,28 +252,28 @@ struct cifsTconInfo {
47820 __u16 Flags; /* optional support bits */
47821 enum statusEnum tidStatus;
47822 #ifdef CONFIG_CIFS_STATS
47823- atomic_t num_smbs_sent;
47824- atomic_t num_writes;
47825- atomic_t num_reads;
47826- atomic_t num_flushes;
47827- atomic_t num_oplock_brks;
47828- atomic_t num_opens;
47829- atomic_t num_closes;
47830- atomic_t num_deletes;
47831- atomic_t num_mkdirs;
47832- atomic_t num_posixopens;
47833- atomic_t num_posixmkdirs;
47834- atomic_t num_rmdirs;
47835- atomic_t num_renames;
47836- atomic_t num_t2renames;
47837- atomic_t num_ffirst;
47838- atomic_t num_fnext;
47839- atomic_t num_fclose;
47840- atomic_t num_hardlinks;
47841- atomic_t num_symlinks;
47842- atomic_t num_locks;
47843- atomic_t num_acl_get;
47844- atomic_t num_acl_set;
47845+ atomic_unchecked_t num_smbs_sent;
47846+ atomic_unchecked_t num_writes;
47847+ atomic_unchecked_t num_reads;
47848+ atomic_unchecked_t num_flushes;
47849+ atomic_unchecked_t num_oplock_brks;
47850+ atomic_unchecked_t num_opens;
47851+ atomic_unchecked_t num_closes;
47852+ atomic_unchecked_t num_deletes;
47853+ atomic_unchecked_t num_mkdirs;
47854+ atomic_unchecked_t num_posixopens;
47855+ atomic_unchecked_t num_posixmkdirs;
47856+ atomic_unchecked_t num_rmdirs;
47857+ atomic_unchecked_t num_renames;
47858+ atomic_unchecked_t num_t2renames;
47859+ atomic_unchecked_t num_ffirst;
47860+ atomic_unchecked_t num_fnext;
47861+ atomic_unchecked_t num_fclose;
47862+ atomic_unchecked_t num_hardlinks;
47863+ atomic_unchecked_t num_symlinks;
47864+ atomic_unchecked_t num_locks;
47865+ atomic_unchecked_t num_acl_get;
47866+ atomic_unchecked_t num_acl_set;
47867 #ifdef CONFIG_CIFS_STATS2
47868 unsigned long long time_writes;
47869 unsigned long long time_reads;
47870@@ -414,7 +414,7 @@ static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
47871 }
47872
47873 #ifdef CONFIG_CIFS_STATS
47874-#define cifs_stats_inc atomic_inc
47875+#define cifs_stats_inc atomic_inc_unchecked
47876
47877 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
47878 unsigned int bytes)
47879@@ -701,8 +701,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
47880 /* Various Debug counters */
47881 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
47882 #ifdef CONFIG_CIFS_STATS2
47883-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
47884-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
47885+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
47886+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
47887 #endif
47888 GLOBAL_EXTERN atomic_t smBufAllocCount;
47889 GLOBAL_EXTERN atomic_t midCount;
47890diff --git a/fs/cifs/link.c b/fs/cifs/link.c
47891index fc1e048..28b3441 100644
47892--- a/fs/cifs/link.c
47893+++ b/fs/cifs/link.c
47894@@ -215,7 +215,7 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
47895
47896 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
47897 {
47898- char *p = nd_get_link(nd);
47899+ const char *p = nd_get_link(nd);
47900 if (!IS_ERR(p))
47901 kfree(p);
47902 }
47903diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
47904index 95b82e8..12a538d 100644
47905--- a/fs/cifs/misc.c
47906+++ b/fs/cifs/misc.c
47907@@ -155,7 +155,7 @@ cifs_buf_get(void)
47908 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
47909 atomic_inc(&bufAllocCount);
47910 #ifdef CONFIG_CIFS_STATS2
47911- atomic_inc(&totBufAllocCount);
47912+ atomic_inc_unchecked(&totBufAllocCount);
47913 #endif /* CONFIG_CIFS_STATS2 */
47914 }
47915
47916@@ -190,7 +190,7 @@ cifs_small_buf_get(void)
47917 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
47918 atomic_inc(&smBufAllocCount);
47919 #ifdef CONFIG_CIFS_STATS2
47920- atomic_inc(&totSmBufAllocCount);
47921+ atomic_inc_unchecked(&totSmBufAllocCount);
47922 #endif /* CONFIG_CIFS_STATS2 */
47923
47924 }
47925diff --git a/fs/coda/cache.c b/fs/coda/cache.c
47926index a5bf577..6d19845 100644
47927--- a/fs/coda/cache.c
47928+++ b/fs/coda/cache.c
47929@@ -24,14 +24,14 @@
47930 #include <linux/coda_fs_i.h>
47931 #include <linux/coda_cache.h>
47932
47933-static atomic_t permission_epoch = ATOMIC_INIT(0);
47934+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
47935
47936 /* replace or extend an acl cache hit */
47937 void coda_cache_enter(struct inode *inode, int mask)
47938 {
47939 struct coda_inode_info *cii = ITOC(inode);
47940
47941- cii->c_cached_epoch = atomic_read(&permission_epoch);
47942+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
47943 if (cii->c_uid != current_fsuid()) {
47944 cii->c_uid = current_fsuid();
47945 cii->c_cached_perm = mask;
47946@@ -43,13 +43,13 @@ void coda_cache_enter(struct inode *inode, int mask)
47947 void coda_cache_clear_inode(struct inode *inode)
47948 {
47949 struct coda_inode_info *cii = ITOC(inode);
47950- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
47951+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
47952 }
47953
47954 /* remove all acl caches */
47955 void coda_cache_clear_all(struct super_block *sb)
47956 {
47957- atomic_inc(&permission_epoch);
47958+ atomic_inc_unchecked(&permission_epoch);
47959 }
47960
47961
47962@@ -61,7 +61,7 @@ int coda_cache_check(struct inode *inode, int mask)
47963
47964 hit = (mask & cii->c_cached_perm) == mask &&
47965 cii->c_uid == current_fsuid() &&
47966- cii->c_cached_epoch == atomic_read(&permission_epoch);
47967+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
47968
47969 return hit;
47970 }
47971diff --git a/fs/compat.c b/fs/compat.c
47972index d1e2411..27064e4 100644
47973--- a/fs/compat.c
47974+++ b/fs/compat.c
47975@@ -133,8 +133,8 @@ asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval _
47976 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
47977 {
47978 compat_ino_t ino = stat->ino;
47979- typeof(ubuf->st_uid) uid = 0;
47980- typeof(ubuf->st_gid) gid = 0;
47981+ typeof(((struct compat_stat *)0)->st_uid) uid = 0;
47982+ typeof(((struct compat_stat *)0)->st_gid) gid = 0;
47983 int err;
47984
47985 SET_UID(uid, stat->uid);
47986@@ -533,7 +533,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
47987
47988 set_fs(KERNEL_DS);
47989 /* The __user pointer cast is valid because of the set_fs() */
47990- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
47991+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
47992 set_fs(oldfs);
47993 /* truncating is ok because it's a user address */
47994 if (!ret)
47995@@ -830,6 +830,7 @@ struct compat_old_linux_dirent {
47996
47997 struct compat_readdir_callback {
47998 struct compat_old_linux_dirent __user *dirent;
47999+ struct file * file;
48000 int result;
48001 };
48002
48003@@ -847,6 +848,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
48004 buf->result = -EOVERFLOW;
48005 return -EOVERFLOW;
48006 }
48007+
48008+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48009+ return 0;
48010+
48011 buf->result++;
48012 dirent = buf->dirent;
48013 if (!access_ok(VERIFY_WRITE, dirent,
48014@@ -879,6 +884,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
48015
48016 buf.result = 0;
48017 buf.dirent = dirent;
48018+ buf.file = file;
48019
48020 error = vfs_readdir(file, compat_fillonedir, &buf);
48021 if (buf.result)
48022@@ -899,6 +905,7 @@ struct compat_linux_dirent {
48023 struct compat_getdents_callback {
48024 struct compat_linux_dirent __user *current_dir;
48025 struct compat_linux_dirent __user *previous;
48026+ struct file * file;
48027 int count;
48028 int error;
48029 };
48030@@ -919,6 +926,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
48031 buf->error = -EOVERFLOW;
48032 return -EOVERFLOW;
48033 }
48034+
48035+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48036+ return 0;
48037+
48038 dirent = buf->previous;
48039 if (dirent) {
48040 if (__put_user(offset, &dirent->d_off))
48041@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
48042 buf.previous = NULL;
48043 buf.count = count;
48044 buf.error = 0;
48045+ buf.file = file;
48046
48047 error = vfs_readdir(file, compat_filldir, &buf);
48048 if (error >= 0)
48049@@ -987,6 +999,7 @@ out:
48050 struct compat_getdents_callback64 {
48051 struct linux_dirent64 __user *current_dir;
48052 struct linux_dirent64 __user *previous;
48053+ struct file * file;
48054 int count;
48055 int error;
48056 };
48057@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
48058 buf->error = -EINVAL; /* only used if we fail.. */
48059 if (reclen > buf->count)
48060 return -EINVAL;
48061+
48062+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48063+ return 0;
48064+
48065 dirent = buf->previous;
48066
48067 if (dirent) {
48068@@ -1054,13 +1071,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
48069 buf.previous = NULL;
48070 buf.count = count;
48071 buf.error = 0;
48072+ buf.file = file;
48073
48074 error = vfs_readdir(file, compat_filldir64, &buf);
48075 if (error >= 0)
48076 error = buf.error;
48077 lastdirent = buf.previous;
48078 if (lastdirent) {
48079- typeof(lastdirent->d_off) d_off = file->f_pos;
48080+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48081 if (__put_user_unaligned(d_off, &lastdirent->d_off))
48082 error = -EFAULT;
48083 else
48084@@ -1098,7 +1116,7 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
48085 * verify all the pointers
48086 */
48087 ret = -EINVAL;
48088- if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
48089+ if (nr_segs > UIO_MAXIOV)
48090 goto out;
48091 if (!file->f_op)
48092 goto out;
48093@@ -1463,11 +1481,35 @@ int compat_do_execve(char * filename,
48094 compat_uptr_t __user *envp,
48095 struct pt_regs * regs)
48096 {
48097+#ifdef CONFIG_GRKERNSEC
48098+ struct file *old_exec_file;
48099+ struct acl_subject_label *old_acl;
48100+ struct rlimit old_rlim[RLIM_NLIMITS];
48101+#endif
48102 struct linux_binprm *bprm;
48103 struct file *file;
48104 struct files_struct *displaced;
48105 bool clear_in_exec;
48106 int retval;
48107+ const struct cred *cred = current_cred();
48108+
48109+ /*
48110+ * We move the actual failure in case of RLIMIT_NPROC excess from
48111+ * set*uid() to execve() because too many poorly written programs
48112+ * don't check setuid() return code. Here we additionally recheck
48113+ * whether NPROC limit is still exceeded.
48114+ */
48115+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
48116+
48117+ if ((current->flags & PF_NPROC_EXCEEDED) &&
48118+ atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
48119+ retval = -EAGAIN;
48120+ goto out_ret;
48121+ }
48122+
48123+ /* We're below the limit (still or again), so we don't want to make
48124+ * further execve() calls fail. */
48125+ current->flags &= ~PF_NPROC_EXCEEDED;
48126
48127 retval = unshare_files(&displaced);
48128 if (retval)
48129@@ -1499,6 +1541,15 @@ int compat_do_execve(char * filename,
48130 bprm->filename = filename;
48131 bprm->interp = filename;
48132
48133+ if (gr_process_user_ban()) {
48134+ retval = -EPERM;
48135+ goto out_file;
48136+ }
48137+
48138+ retval = -EACCES;
48139+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
48140+ goto out_file;
48141+
48142 retval = bprm_mm_init(bprm);
48143 if (retval)
48144 goto out_file;
48145@@ -1528,9 +1579,40 @@ int compat_do_execve(char * filename,
48146 if (retval < 0)
48147 goto out;
48148
48149+ if (!gr_tpe_allow(file)) {
48150+ retval = -EACCES;
48151+ goto out;
48152+ }
48153+
48154+ if (gr_check_crash_exec(file)) {
48155+ retval = -EACCES;
48156+ goto out;
48157+ }
48158+
48159+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
48160+
48161+ gr_handle_exec_args_compat(bprm, argv);
48162+
48163+#ifdef CONFIG_GRKERNSEC
48164+ old_acl = current->acl;
48165+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
48166+ old_exec_file = current->exec_file;
48167+ get_file(file);
48168+ current->exec_file = file;
48169+#endif
48170+
48171+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
48172+ bprm->unsafe & LSM_UNSAFE_SHARE);
48173+ if (retval < 0)
48174+ goto out_fail;
48175+
48176 retval = search_binary_handler(bprm, regs);
48177 if (retval < 0)
48178- goto out;
48179+ goto out_fail;
48180+#ifdef CONFIG_GRKERNSEC
48181+ if (old_exec_file)
48182+ fput(old_exec_file);
48183+#endif
48184
48185 /* execve succeeded */
48186 current->fs->in_exec = 0;
48187@@ -1541,6 +1623,14 @@ int compat_do_execve(char * filename,
48188 put_files_struct(displaced);
48189 return retval;
48190
48191+out_fail:
48192+#ifdef CONFIG_GRKERNSEC
48193+ current->acl = old_acl;
48194+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
48195+ fput(current->exec_file);
48196+ current->exec_file = old_exec_file;
48197+#endif
48198+
48199 out:
48200 if (bprm->mm) {
48201 acct_arg_size(bprm, 0);
48202@@ -1711,6 +1801,8 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp,
48203 struct fdtable *fdt;
48204 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
48205
48206+ pax_track_stack();
48207+
48208 if (n < 0)
48209 goto out_nofds;
48210
48211@@ -2151,7 +2243,7 @@ asmlinkage long compat_sys_nfsservctl(int cmd,
48212 oldfs = get_fs();
48213 set_fs(KERNEL_DS);
48214 /* The __user pointer casts are valid because of the set_fs() */
48215- err = sys_nfsservctl(cmd, (void __user *) karg, (void __user *) kres);
48216+ err = sys_nfsservctl(cmd, (void __force_user *) karg, (void __force_user *) kres);
48217 set_fs(oldfs);
48218
48219 if (err)
48220diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
48221index 0adced2..bbb1b0d 100644
48222--- a/fs/compat_binfmt_elf.c
48223+++ b/fs/compat_binfmt_elf.c
48224@@ -29,10 +29,12 @@
48225 #undef elfhdr
48226 #undef elf_phdr
48227 #undef elf_note
48228+#undef elf_dyn
48229 #undef elf_addr_t
48230 #define elfhdr elf32_hdr
48231 #define elf_phdr elf32_phdr
48232 #define elf_note elf32_note
48233+#define elf_dyn Elf32_Dyn
48234 #define elf_addr_t Elf32_Addr
48235
48236 /*
48237diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
48238index d84e705..d8c364c 100644
48239--- a/fs/compat_ioctl.c
48240+++ b/fs/compat_ioctl.c
48241@@ -234,6 +234,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned
48242 up = (struct compat_video_spu_palette __user *) arg;
48243 err = get_user(palp, &up->palette);
48244 err |= get_user(length, &up->length);
48245+ if (err)
48246+ return -EFAULT;
48247
48248 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
48249 err = put_user(compat_ptr(palp), &up_native->palette);
48250@@ -1513,7 +1515,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
48251 return -EFAULT;
48252 if (__get_user(udata, &ss32->iomem_base))
48253 return -EFAULT;
48254- ss.iomem_base = compat_ptr(udata);
48255+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
48256 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
48257 __get_user(ss.port_high, &ss32->port_high))
48258 return -EFAULT;
48259@@ -1809,7 +1811,7 @@ static int compat_ioctl_preallocate(struct file *file, unsigned long arg)
48260 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
48261 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
48262 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
48263- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
48264+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
48265 return -EFAULT;
48266
48267 return ioctl_preallocate(file, p);
48268diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
48269index 8e48b52..f01ed91 100644
48270--- a/fs/configfs/dir.c
48271+++ b/fs/configfs/dir.c
48272@@ -1572,7 +1572,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
48273 }
48274 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
48275 struct configfs_dirent *next;
48276- const char * name;
48277+ const unsigned char * name;
48278+ char d_name[sizeof(next->s_dentry->d_iname)];
48279 int len;
48280
48281 next = list_entry(p, struct configfs_dirent,
48282@@ -1581,7 +1582,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
48283 continue;
48284
48285 name = configfs_get_name(next);
48286- len = strlen(name);
48287+ if (next->s_dentry && name == next->s_dentry->d_iname) {
48288+ len = next->s_dentry->d_name.len;
48289+ memcpy(d_name, name, len);
48290+ name = d_name;
48291+ } else
48292+ len = strlen(name);
48293 if (next->s_dentry)
48294 ino = next->s_dentry->d_inode->i_ino;
48295 else
48296diff --git a/fs/dcache.c b/fs/dcache.c
48297index 44c0aea..2529092 100644
48298--- a/fs/dcache.c
48299+++ b/fs/dcache.c
48300@@ -45,8 +45,6 @@ EXPORT_SYMBOL(dcache_lock);
48301
48302 static struct kmem_cache *dentry_cache __read_mostly;
48303
48304-#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
48305-
48306 /*
48307 * This is the single most critical data structure when it comes
48308 * to the dcache: the hashtable for lookups. Somebody should try
48309@@ -2319,7 +2317,7 @@ void __init vfs_caches_init(unsigned long mempages)
48310 mempages -= reserve;
48311
48312 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
48313- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
48314+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
48315
48316 dcache_init();
48317 inode_init();
48318diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
48319index c010ecf..a8d8c59 100644
48320--- a/fs/dlm/lockspace.c
48321+++ b/fs/dlm/lockspace.c
48322@@ -148,7 +148,7 @@ static void lockspace_kobj_release(struct kobject *k)
48323 kfree(ls);
48324 }
48325
48326-static struct sysfs_ops dlm_attr_ops = {
48327+static const struct sysfs_ops dlm_attr_ops = {
48328 .show = dlm_attr_show,
48329 .store = dlm_attr_store,
48330 };
48331diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
48332index 88ba4d4..073f003 100644
48333--- a/fs/ecryptfs/inode.c
48334+++ b/fs/ecryptfs/inode.c
48335@@ -660,7 +660,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
48336 old_fs = get_fs();
48337 set_fs(get_ds());
48338 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
48339- (char __user *)lower_buf,
48340+ (char __force_user *)lower_buf,
48341 lower_bufsiz);
48342 set_fs(old_fs);
48343 if (rc < 0)
48344@@ -706,7 +706,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48345 }
48346 old_fs = get_fs();
48347 set_fs(get_ds());
48348- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
48349+ rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
48350 set_fs(old_fs);
48351 if (rc < 0)
48352 goto out_free;
48353diff --git a/fs/exec.c b/fs/exec.c
48354index 86fafc6..6d33cbb 100644
48355--- a/fs/exec.c
48356+++ b/fs/exec.c
48357@@ -56,12 +56,28 @@
48358 #include <linux/fsnotify.h>
48359 #include <linux/fs_struct.h>
48360 #include <linux/pipe_fs_i.h>
48361+#include <linux/random.h>
48362+#include <linux/seq_file.h>
48363+
48364+#ifdef CONFIG_PAX_REFCOUNT
48365+#include <linux/kallsyms.h>
48366+#include <linux/kdebug.h>
48367+#endif
48368
48369 #include <asm/uaccess.h>
48370 #include <asm/mmu_context.h>
48371 #include <asm/tlb.h>
48372 #include "internal.h"
48373
48374+#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
48375+void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
48376+#endif
48377+
48378+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
48379+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
48380+EXPORT_SYMBOL(pax_set_initial_flags_func);
48381+#endif
48382+
48383 int core_uses_pid;
48384 char core_pattern[CORENAME_MAX_SIZE] = "core";
48385 unsigned int core_pipe_limit;
48386@@ -178,18 +194,10 @@ struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
48387 int write)
48388 {
48389 struct page *page;
48390- int ret;
48391
48392-#ifdef CONFIG_STACK_GROWSUP
48393- if (write) {
48394- ret = expand_stack_downwards(bprm->vma, pos);
48395- if (ret < 0)
48396- return NULL;
48397- }
48398-#endif
48399- ret = get_user_pages(current, bprm->mm, pos,
48400- 1, write, 1, &page, NULL);
48401- if (ret <= 0)
48402+ if (0 > expand_stack_downwards(bprm->vma, pos))
48403+ return NULL;
48404+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
48405 return NULL;
48406
48407 if (write) {
48408@@ -263,6 +271,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
48409 vma->vm_end = STACK_TOP_MAX;
48410 vma->vm_start = vma->vm_end - PAGE_SIZE;
48411 vma->vm_flags = VM_STACK_FLAGS;
48412+
48413+#ifdef CONFIG_PAX_SEGMEXEC
48414+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
48415+#endif
48416+
48417 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
48418
48419 err = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
48420@@ -276,6 +289,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
48421 mm->stack_vm = mm->total_vm = 1;
48422 up_write(&mm->mmap_sem);
48423 bprm->p = vma->vm_end - sizeof(void *);
48424+
48425+#ifdef CONFIG_PAX_RANDUSTACK
48426+ if (randomize_va_space)
48427+ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
48428+#endif
48429+
48430 return 0;
48431 err:
48432 up_write(&mm->mmap_sem);
48433@@ -510,7 +529,7 @@ int copy_strings_kernel(int argc,char ** argv, struct linux_binprm *bprm)
48434 int r;
48435 mm_segment_t oldfs = get_fs();
48436 set_fs(KERNEL_DS);
48437- r = copy_strings(argc, (char __user * __user *)argv, bprm);
48438+ r = copy_strings(argc, (__force char __user * __user *)argv, bprm);
48439 set_fs(oldfs);
48440 return r;
48441 }
48442@@ -540,7 +559,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
48443 unsigned long new_end = old_end - shift;
48444 struct mmu_gather *tlb;
48445
48446- BUG_ON(new_start > new_end);
48447+ if (new_start >= new_end || new_start < mmap_min_addr)
48448+ return -ENOMEM;
48449
48450 /*
48451 * ensure there are no vmas between where we want to go
48452@@ -549,6 +569,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
48453 if (vma != find_vma(mm, new_start))
48454 return -EFAULT;
48455
48456+#ifdef CONFIG_PAX_SEGMEXEC
48457+ BUG_ON(pax_find_mirror_vma(vma));
48458+#endif
48459+
48460 /*
48461 * cover the whole range: [new_start, old_end)
48462 */
48463@@ -630,10 +654,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
48464 stack_top = arch_align_stack(stack_top);
48465 stack_top = PAGE_ALIGN(stack_top);
48466
48467- if (unlikely(stack_top < mmap_min_addr) ||
48468- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
48469- return -ENOMEM;
48470-
48471 stack_shift = vma->vm_end - stack_top;
48472
48473 bprm->p -= stack_shift;
48474@@ -645,6 +665,14 @@ int setup_arg_pages(struct linux_binprm *bprm,
48475 bprm->exec -= stack_shift;
48476
48477 down_write(&mm->mmap_sem);
48478+
48479+ /* Move stack pages down in memory. */
48480+ if (stack_shift) {
48481+ ret = shift_arg_pages(vma, stack_shift);
48482+ if (ret)
48483+ goto out_unlock;
48484+ }
48485+
48486 vm_flags = VM_STACK_FLAGS;
48487
48488 /*
48489@@ -658,19 +686,24 @@ int setup_arg_pages(struct linux_binprm *bprm,
48490 vm_flags &= ~VM_EXEC;
48491 vm_flags |= mm->def_flags;
48492
48493+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48494+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48495+ vm_flags &= ~VM_EXEC;
48496+
48497+#ifdef CONFIG_PAX_MPROTECT
48498+ if (mm->pax_flags & MF_PAX_MPROTECT)
48499+ vm_flags &= ~VM_MAYEXEC;
48500+#endif
48501+
48502+ }
48503+#endif
48504+
48505 ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
48506 vm_flags);
48507 if (ret)
48508 goto out_unlock;
48509 BUG_ON(prev != vma);
48510
48511- /* Move stack pages down in memory. */
48512- if (stack_shift) {
48513- ret = shift_arg_pages(vma, stack_shift);
48514- if (ret)
48515- goto out_unlock;
48516- }
48517-
48518 stack_expand = EXTRA_STACK_VM_PAGES * PAGE_SIZE;
48519 stack_size = vma->vm_end - vma->vm_start;
48520 /*
48521@@ -744,7 +777,7 @@ int kernel_read(struct file *file, loff_t offset,
48522 old_fs = get_fs();
48523 set_fs(get_ds());
48524 /* The cast to a user pointer is valid due to the set_fs() */
48525- result = vfs_read(file, (void __user *)addr, count, &pos);
48526+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
48527 set_fs(old_fs);
48528 return result;
48529 }
48530@@ -1152,7 +1185,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
48531 }
48532 rcu_read_unlock();
48533
48534- if (p->fs->users > n_fs) {
48535+ if (atomic_read(&p->fs->users) > n_fs) {
48536 bprm->unsafe |= LSM_UNSAFE_SHARE;
48537 } else {
48538 res = -EAGAIN;
48539@@ -1347,11 +1380,35 @@ int do_execve(char * filename,
48540 char __user *__user *envp,
48541 struct pt_regs * regs)
48542 {
48543+#ifdef CONFIG_GRKERNSEC
48544+ struct file *old_exec_file;
48545+ struct acl_subject_label *old_acl;
48546+ struct rlimit old_rlim[RLIM_NLIMITS];
48547+#endif
48548 struct linux_binprm *bprm;
48549 struct file *file;
48550 struct files_struct *displaced;
48551 bool clear_in_exec;
48552 int retval;
48553+ const struct cred *cred = current_cred();
48554+
48555+ /*
48556+ * We move the actual failure in case of RLIMIT_NPROC excess from
48557+ * set*uid() to execve() because too many poorly written programs
48558+ * don't check setuid() return code. Here we additionally recheck
48559+ * whether NPROC limit is still exceeded.
48560+ */
48561+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
48562+
48563+ if ((current->flags & PF_NPROC_EXCEEDED) &&
48564+ atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
48565+ retval = -EAGAIN;
48566+ goto out_ret;
48567+ }
48568+
48569+ /* We're below the limit (still or again), so we don't want to make
48570+ * further execve() calls fail. */
48571+ current->flags &= ~PF_NPROC_EXCEEDED;
48572
48573 retval = unshare_files(&displaced);
48574 if (retval)
48575@@ -1383,6 +1440,16 @@ int do_execve(char * filename,
48576 bprm->filename = filename;
48577 bprm->interp = filename;
48578
48579+ if (gr_process_user_ban()) {
48580+ retval = -EPERM;
48581+ goto out_file;
48582+ }
48583+
48584+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
48585+ retval = -EACCES;
48586+ goto out_file;
48587+ }
48588+
48589 retval = bprm_mm_init(bprm);
48590 if (retval)
48591 goto out_file;
48592@@ -1412,10 +1479,41 @@ int do_execve(char * filename,
48593 if (retval < 0)
48594 goto out;
48595
48596+ if (!gr_tpe_allow(file)) {
48597+ retval = -EACCES;
48598+ goto out;
48599+ }
48600+
48601+ if (gr_check_crash_exec(file)) {
48602+ retval = -EACCES;
48603+ goto out;
48604+ }
48605+
48606+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
48607+
48608+ gr_handle_exec_args(bprm, (const char __user *const __user *)argv);
48609+
48610+#ifdef CONFIG_GRKERNSEC
48611+ old_acl = current->acl;
48612+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
48613+ old_exec_file = current->exec_file;
48614+ get_file(file);
48615+ current->exec_file = file;
48616+#endif
48617+
48618+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
48619+ bprm->unsafe & LSM_UNSAFE_SHARE);
48620+ if (retval < 0)
48621+ goto out_fail;
48622+
48623 current->flags &= ~PF_KTHREAD;
48624 retval = search_binary_handler(bprm,regs);
48625 if (retval < 0)
48626- goto out;
48627+ goto out_fail;
48628+#ifdef CONFIG_GRKERNSEC
48629+ if (old_exec_file)
48630+ fput(old_exec_file);
48631+#endif
48632
48633 /* execve succeeded */
48634 current->fs->in_exec = 0;
48635@@ -1426,6 +1524,14 @@ int do_execve(char * filename,
48636 put_files_struct(displaced);
48637 return retval;
48638
48639+out_fail:
48640+#ifdef CONFIG_GRKERNSEC
48641+ current->acl = old_acl;
48642+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
48643+ fput(current->exec_file);
48644+ current->exec_file = old_exec_file;
48645+#endif
48646+
48647 out:
48648 if (bprm->mm) {
48649 acct_arg_size(bprm, 0);
48650@@ -1591,6 +1697,220 @@ out:
48651 return ispipe;
48652 }
48653
48654+int pax_check_flags(unsigned long *flags)
48655+{
48656+ int retval = 0;
48657+
48658+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
48659+ if (*flags & MF_PAX_SEGMEXEC)
48660+ {
48661+ *flags &= ~MF_PAX_SEGMEXEC;
48662+ retval = -EINVAL;
48663+ }
48664+#endif
48665+
48666+ if ((*flags & MF_PAX_PAGEEXEC)
48667+
48668+#ifdef CONFIG_PAX_PAGEEXEC
48669+ && (*flags & MF_PAX_SEGMEXEC)
48670+#endif
48671+
48672+ )
48673+ {
48674+ *flags &= ~MF_PAX_PAGEEXEC;
48675+ retval = -EINVAL;
48676+ }
48677+
48678+ if ((*flags & MF_PAX_MPROTECT)
48679+
48680+#ifdef CONFIG_PAX_MPROTECT
48681+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48682+#endif
48683+
48684+ )
48685+ {
48686+ *flags &= ~MF_PAX_MPROTECT;
48687+ retval = -EINVAL;
48688+ }
48689+
48690+ if ((*flags & MF_PAX_EMUTRAMP)
48691+
48692+#ifdef CONFIG_PAX_EMUTRAMP
48693+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48694+#endif
48695+
48696+ )
48697+ {
48698+ *flags &= ~MF_PAX_EMUTRAMP;
48699+ retval = -EINVAL;
48700+ }
48701+
48702+ return retval;
48703+}
48704+
48705+EXPORT_SYMBOL(pax_check_flags);
48706+
48707+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48708+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
48709+{
48710+ struct task_struct *tsk = current;
48711+ struct mm_struct *mm = current->mm;
48712+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
48713+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
48714+ char *path_exec = NULL;
48715+ char *path_fault = NULL;
48716+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
48717+
48718+ if (buffer_exec && buffer_fault) {
48719+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
48720+
48721+ down_read(&mm->mmap_sem);
48722+ vma = mm->mmap;
48723+ while (vma && (!vma_exec || !vma_fault)) {
48724+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
48725+ vma_exec = vma;
48726+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
48727+ vma_fault = vma;
48728+ vma = vma->vm_next;
48729+ }
48730+ if (vma_exec) {
48731+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
48732+ if (IS_ERR(path_exec))
48733+ path_exec = "<path too long>";
48734+ else {
48735+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
48736+ if (path_exec) {
48737+ *path_exec = 0;
48738+ path_exec = buffer_exec;
48739+ } else
48740+ path_exec = "<path too long>";
48741+ }
48742+ }
48743+ if (vma_fault) {
48744+ start = vma_fault->vm_start;
48745+ end = vma_fault->vm_end;
48746+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
48747+ if (vma_fault->vm_file) {
48748+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
48749+ if (IS_ERR(path_fault))
48750+ path_fault = "<path too long>";
48751+ else {
48752+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
48753+ if (path_fault) {
48754+ *path_fault = 0;
48755+ path_fault = buffer_fault;
48756+ } else
48757+ path_fault = "<path too long>";
48758+ }
48759+ } else
48760+ path_fault = "<anonymous mapping>";
48761+ }
48762+ up_read(&mm->mmap_sem);
48763+ }
48764+ if (tsk->signal->curr_ip)
48765+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
48766+ else
48767+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
48768+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
48769+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
48770+ task_uid(tsk), task_euid(tsk), pc, sp);
48771+ free_page((unsigned long)buffer_exec);
48772+ free_page((unsigned long)buffer_fault);
48773+ pax_report_insns(regs, pc, sp);
48774+ do_coredump(SIGKILL, SIGKILL, regs);
48775+}
48776+#endif
48777+
48778+#ifdef CONFIG_PAX_REFCOUNT
48779+void pax_report_refcount_overflow(struct pt_regs *regs)
48780+{
48781+ if (current->signal->curr_ip)
48782+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48783+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
48784+ else
48785+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48786+ current->comm, task_pid_nr(current), current_uid(), current_euid());
48787+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
48788+ show_regs(regs);
48789+ force_sig_specific(SIGKILL, current);
48790+}
48791+#endif
48792+
48793+#ifdef CONFIG_PAX_USERCOPY
48794+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
48795+int object_is_on_stack(const void *obj, unsigned long len)
48796+{
48797+ const void * const stack = task_stack_page(current);
48798+ const void * const stackend = stack + THREAD_SIZE;
48799+
48800+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48801+ const void *frame = NULL;
48802+ const void *oldframe;
48803+#endif
48804+
48805+ if (obj + len < obj)
48806+ return -1;
48807+
48808+ if (obj + len <= stack || stackend <= obj)
48809+ return 0;
48810+
48811+ if (obj < stack || stackend < obj + len)
48812+ return -1;
48813+
48814+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48815+ oldframe = __builtin_frame_address(1);
48816+ if (oldframe)
48817+ frame = __builtin_frame_address(2);
48818+ /*
48819+ low ----------------------------------------------> high
48820+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
48821+ ^----------------^
48822+ allow copies only within here
48823+ */
48824+ while (stack <= frame && frame < stackend) {
48825+ /* if obj + len extends past the last frame, this
48826+ check won't pass and the next frame will be 0,
48827+ causing us to bail out and correctly report
48828+ the copy as invalid
48829+ */
48830+ if (obj + len <= frame)
48831+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
48832+ oldframe = frame;
48833+ frame = *(const void * const *)frame;
48834+ }
48835+ return -1;
48836+#else
48837+ return 1;
48838+#endif
48839+}
48840+
48841+
48842+NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
48843+{
48844+ if (current->signal->curr_ip)
48845+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48846+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48847+ else
48848+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48849+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48850+
48851+ dump_stack();
48852+ gr_handle_kernel_exploit();
48853+ do_group_exit(SIGKILL);
48854+}
48855+#endif
48856+
48857+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
48858+void pax_track_stack(void)
48859+{
48860+ unsigned long sp = (unsigned long)&sp;
48861+ if (sp < current_thread_info()->lowest_stack &&
48862+ sp > (unsigned long)task_stack_page(current))
48863+ current_thread_info()->lowest_stack = sp;
48864+}
48865+EXPORT_SYMBOL(pax_track_stack);
48866+#endif
48867+
48868 static int zap_process(struct task_struct *start)
48869 {
48870 struct task_struct *t;
48871@@ -1793,17 +2113,17 @@ static void wait_for_dump_helpers(struct file *file)
48872 pipe = file->f_path.dentry->d_inode->i_pipe;
48873
48874 pipe_lock(pipe);
48875- pipe->readers++;
48876- pipe->writers--;
48877+ atomic_inc(&pipe->readers);
48878+ atomic_dec(&pipe->writers);
48879
48880- while ((pipe->readers > 1) && (!signal_pending(current))) {
48881+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
48882 wake_up_interruptible_sync(&pipe->wait);
48883 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48884 pipe_wait(pipe);
48885 }
48886
48887- pipe->readers--;
48888- pipe->writers++;
48889+ atomic_dec(&pipe->readers);
48890+ atomic_inc(&pipe->writers);
48891 pipe_unlock(pipe);
48892
48893 }
48894@@ -1826,10 +2146,13 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48895 char **helper_argv = NULL;
48896 int helper_argc = 0;
48897 int dump_count = 0;
48898- static atomic_t core_dump_count = ATOMIC_INIT(0);
48899+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
48900
48901 audit_core_dumps(signr);
48902
48903+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
48904+ gr_handle_brute_attach(current, mm->flags);
48905+
48906 binfmt = mm->binfmt;
48907 if (!binfmt || !binfmt->core_dump)
48908 goto fail;
48909@@ -1874,6 +2197,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48910 */
48911 clear_thread_flag(TIF_SIGPENDING);
48912
48913+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
48914+
48915 /*
48916 * lock_kernel() because format_corename() is controlled by sysctl, which
48917 * uses lock_kernel()
48918@@ -1908,7 +2233,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48919 goto fail_unlock;
48920 }
48921
48922- dump_count = atomic_inc_return(&core_dump_count);
48923+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
48924 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
48925 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
48926 task_tgid_vnr(current), current->comm);
48927@@ -1972,7 +2297,7 @@ close_fail:
48928 filp_close(file, NULL);
48929 fail_dropcount:
48930 if (dump_count)
48931- atomic_dec(&core_dump_count);
48932+ atomic_dec_unchecked(&core_dump_count);
48933 fail_unlock:
48934 if (helper_argv)
48935 argv_free(helper_argv);
48936diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
48937index 7f8d2e5..a1abdbb 100644
48938--- a/fs/ext2/balloc.c
48939+++ b/fs/ext2/balloc.c
48940@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
48941
48942 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48943 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48944- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48945+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
48946 sbi->s_resuid != current_fsuid() &&
48947 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
48948 return 0;
48949diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
48950index 27967f9..9f2a5fb 100644
48951--- a/fs/ext3/balloc.c
48952+++ b/fs/ext3/balloc.c
48953@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
48954
48955 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48956 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48957- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48958+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
48959 sbi->s_resuid != current_fsuid() &&
48960 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
48961 return 0;
48962diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
48963index e85b63c..80398e6 100644
48964--- a/fs/ext4/balloc.c
48965+++ b/fs/ext4/balloc.c
48966@@ -570,7 +570,7 @@ int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks)
48967 /* Hm, nope. Are (enough) root reserved blocks available? */
48968 if (sbi->s_resuid == current_fsuid() ||
48969 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
48970- capable(CAP_SYS_RESOURCE)) {
48971+ capable_nolog(CAP_SYS_RESOURCE)) {
48972 if (free_blocks >= (nblocks + dirty_blocks))
48973 return 1;
48974 }
48975diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
48976index 67c46ed..1f237e5 100644
48977--- a/fs/ext4/ext4.h
48978+++ b/fs/ext4/ext4.h
48979@@ -1077,19 +1077,19 @@ struct ext4_sb_info {
48980
48981 /* stats for buddy allocator */
48982 spinlock_t s_mb_pa_lock;
48983- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
48984- atomic_t s_bal_success; /* we found long enough chunks */
48985- atomic_t s_bal_allocated; /* in blocks */
48986- atomic_t s_bal_ex_scanned; /* total extents scanned */
48987- atomic_t s_bal_goals; /* goal hits */
48988- atomic_t s_bal_breaks; /* too long searches */
48989- atomic_t s_bal_2orders; /* 2^order hits */
48990+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
48991+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
48992+ atomic_unchecked_t s_bal_allocated; /* in blocks */
48993+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
48994+ atomic_unchecked_t s_bal_goals; /* goal hits */
48995+ atomic_unchecked_t s_bal_breaks; /* too long searches */
48996+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
48997 spinlock_t s_bal_lock;
48998 unsigned long s_mb_buddies_generated;
48999 unsigned long long s_mb_generation_time;
49000- atomic_t s_mb_lost_chunks;
49001- atomic_t s_mb_preallocated;
49002- atomic_t s_mb_discarded;
49003+ atomic_unchecked_t s_mb_lost_chunks;
49004+ atomic_unchecked_t s_mb_preallocated;
49005+ atomic_unchecked_t s_mb_discarded;
49006 atomic_t s_lock_busy;
49007
49008 /* locality groups */
49009diff --git a/fs/ext4/file.c b/fs/ext4/file.c
49010index 2a60541..7439d61 100644
49011--- a/fs/ext4/file.c
49012+++ b/fs/ext4/file.c
49013@@ -122,8 +122,8 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
49014 cp = d_path(&path, buf, sizeof(buf));
49015 path_put(&path);
49016 if (!IS_ERR(cp)) {
49017- memcpy(sbi->s_es->s_last_mounted, cp,
49018- sizeof(sbi->s_es->s_last_mounted));
49019+ strlcpy(sbi->s_es->s_last_mounted, cp,
49020+ sizeof(sbi->s_es->s_last_mounted));
49021 sb->s_dirt = 1;
49022 }
49023 }
49024diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
49025index 42bac1b..0aab9d8 100644
49026--- a/fs/ext4/mballoc.c
49027+++ b/fs/ext4/mballoc.c
49028@@ -1755,7 +1755,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
49029 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
49030
49031 if (EXT4_SB(sb)->s_mb_stats)
49032- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
49033+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
49034
49035 break;
49036 }
49037@@ -2131,7 +2131,7 @@ repeat:
49038 ac->ac_status = AC_STATUS_CONTINUE;
49039 ac->ac_flags |= EXT4_MB_HINT_FIRST;
49040 cr = 3;
49041- atomic_inc(&sbi->s_mb_lost_chunks);
49042+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
49043 goto repeat;
49044 }
49045 }
49046@@ -2174,6 +2174,8 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
49047 ext4_grpblk_t counters[16];
49048 } sg;
49049
49050+ pax_track_stack();
49051+
49052 group--;
49053 if (group == 0)
49054 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
49055@@ -2534,25 +2536,25 @@ int ext4_mb_release(struct super_block *sb)
49056 if (sbi->s_mb_stats) {
49057 printk(KERN_INFO
49058 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
49059- atomic_read(&sbi->s_bal_allocated),
49060- atomic_read(&sbi->s_bal_reqs),
49061- atomic_read(&sbi->s_bal_success));
49062+ atomic_read_unchecked(&sbi->s_bal_allocated),
49063+ atomic_read_unchecked(&sbi->s_bal_reqs),
49064+ atomic_read_unchecked(&sbi->s_bal_success));
49065 printk(KERN_INFO
49066 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
49067 "%u 2^N hits, %u breaks, %u lost\n",
49068- atomic_read(&sbi->s_bal_ex_scanned),
49069- atomic_read(&sbi->s_bal_goals),
49070- atomic_read(&sbi->s_bal_2orders),
49071- atomic_read(&sbi->s_bal_breaks),
49072- atomic_read(&sbi->s_mb_lost_chunks));
49073+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
49074+ atomic_read_unchecked(&sbi->s_bal_goals),
49075+ atomic_read_unchecked(&sbi->s_bal_2orders),
49076+ atomic_read_unchecked(&sbi->s_bal_breaks),
49077+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
49078 printk(KERN_INFO
49079 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
49080 sbi->s_mb_buddies_generated++,
49081 sbi->s_mb_generation_time);
49082 printk(KERN_INFO
49083 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
49084- atomic_read(&sbi->s_mb_preallocated),
49085- atomic_read(&sbi->s_mb_discarded));
49086+ atomic_read_unchecked(&sbi->s_mb_preallocated),
49087+ atomic_read_unchecked(&sbi->s_mb_discarded));
49088 }
49089
49090 free_percpu(sbi->s_locality_groups);
49091@@ -3034,16 +3036,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
49092 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
49093
49094 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
49095- atomic_inc(&sbi->s_bal_reqs);
49096- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
49097+ atomic_inc_unchecked(&sbi->s_bal_reqs);
49098+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
49099 if (ac->ac_o_ex.fe_len >= ac->ac_g_ex.fe_len)
49100- atomic_inc(&sbi->s_bal_success);
49101- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
49102+ atomic_inc_unchecked(&sbi->s_bal_success);
49103+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
49104 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
49105 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
49106- atomic_inc(&sbi->s_bal_goals);
49107+ atomic_inc_unchecked(&sbi->s_bal_goals);
49108 if (ac->ac_found > sbi->s_mb_max_to_scan)
49109- atomic_inc(&sbi->s_bal_breaks);
49110+ atomic_inc_unchecked(&sbi->s_bal_breaks);
49111 }
49112
49113 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
49114@@ -3443,7 +3445,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
49115 trace_ext4_mb_new_inode_pa(ac, pa);
49116
49117 ext4_mb_use_inode_pa(ac, pa);
49118- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
49119+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
49120
49121 ei = EXT4_I(ac->ac_inode);
49122 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
49123@@ -3503,7 +3505,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
49124 trace_ext4_mb_new_group_pa(ac, pa);
49125
49126 ext4_mb_use_group_pa(ac, pa);
49127- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
49128+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
49129
49130 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
49131 lg = ac->ac_lg;
49132@@ -3607,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
49133 * from the bitmap and continue.
49134 */
49135 }
49136- atomic_add(free, &sbi->s_mb_discarded);
49137+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
49138
49139 return err;
49140 }
49141@@ -3626,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
49142 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
49143 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
49144 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
49145- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
49146+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
49147
49148 if (ac) {
49149 ac->ac_sb = sb;
49150diff --git a/fs/ext4/super.c b/fs/ext4/super.c
49151index f1e7077..edd86b2 100644
49152--- a/fs/ext4/super.c
49153+++ b/fs/ext4/super.c
49154@@ -2286,7 +2286,7 @@ static void ext4_sb_release(struct kobject *kobj)
49155 }
49156
49157
49158-static struct sysfs_ops ext4_attr_ops = {
49159+static const struct sysfs_ops ext4_attr_ops = {
49160 .show = ext4_attr_show,
49161 .store = ext4_attr_store,
49162 };
49163diff --git a/fs/fcntl.c b/fs/fcntl.c
49164index 97e01dc..e9aab2d 100644
49165--- a/fs/fcntl.c
49166+++ b/fs/fcntl.c
49167@@ -223,6 +223,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
49168 if (err)
49169 return err;
49170
49171+ if (gr_handle_chroot_fowner(pid, type))
49172+ return -ENOENT;
49173+ if (gr_check_protected_task_fowner(pid, type))
49174+ return -EACCES;
49175+
49176 f_modown(filp, pid, type, force);
49177 return 0;
49178 }
49179@@ -265,7 +270,7 @@ pid_t f_getown(struct file *filp)
49180
49181 static int f_setown_ex(struct file *filp, unsigned long arg)
49182 {
49183- struct f_owner_ex * __user owner_p = (void * __user)arg;
49184+ struct f_owner_ex __user *owner_p = (void __user *)arg;
49185 struct f_owner_ex owner;
49186 struct pid *pid;
49187 int type;
49188@@ -305,7 +310,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
49189
49190 static int f_getown_ex(struct file *filp, unsigned long arg)
49191 {
49192- struct f_owner_ex * __user owner_p = (void * __user)arg;
49193+ struct f_owner_ex __user *owner_p = (void __user *)arg;
49194 struct f_owner_ex owner;
49195 int ret = 0;
49196
49197@@ -344,6 +349,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
49198 switch (cmd) {
49199 case F_DUPFD:
49200 case F_DUPFD_CLOEXEC:
49201+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
49202 if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
49203 break;
49204 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
49205diff --git a/fs/fifo.c b/fs/fifo.c
49206index f8f97b8..b1f2259 100644
49207--- a/fs/fifo.c
49208+++ b/fs/fifo.c
49209@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
49210 */
49211 filp->f_op = &read_pipefifo_fops;
49212 pipe->r_counter++;
49213- if (pipe->readers++ == 0)
49214+ if (atomic_inc_return(&pipe->readers) == 1)
49215 wake_up_partner(inode);
49216
49217- if (!pipe->writers) {
49218+ if (!atomic_read(&pipe->writers)) {
49219 if ((filp->f_flags & O_NONBLOCK)) {
49220 /* suppress POLLHUP until we have
49221 * seen a writer */
49222@@ -83,15 +83,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
49223 * errno=ENXIO when there is no process reading the FIFO.
49224 */
49225 ret = -ENXIO;
49226- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
49227+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
49228 goto err;
49229
49230 filp->f_op = &write_pipefifo_fops;
49231 pipe->w_counter++;
49232- if (!pipe->writers++)
49233+ if (atomic_inc_return(&pipe->writers) == 1)
49234 wake_up_partner(inode);
49235
49236- if (!pipe->readers) {
49237+ if (!atomic_read(&pipe->readers)) {
49238 wait_for_partner(inode, &pipe->r_counter);
49239 if (signal_pending(current))
49240 goto err_wr;
49241@@ -107,11 +107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
49242 */
49243 filp->f_op = &rdwr_pipefifo_fops;
49244
49245- pipe->readers++;
49246- pipe->writers++;
49247+ atomic_inc(&pipe->readers);
49248+ atomic_inc(&pipe->writers);
49249 pipe->r_counter++;
49250 pipe->w_counter++;
49251- if (pipe->readers == 1 || pipe->writers == 1)
49252+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
49253 wake_up_partner(inode);
49254 break;
49255
49256@@ -125,19 +125,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
49257 return 0;
49258
49259 err_rd:
49260- if (!--pipe->readers)
49261+ if (atomic_dec_and_test(&pipe->readers))
49262 wake_up_interruptible(&pipe->wait);
49263 ret = -ERESTARTSYS;
49264 goto err;
49265
49266 err_wr:
49267- if (!--pipe->writers)
49268+ if (atomic_dec_and_test(&pipe->writers))
49269 wake_up_interruptible(&pipe->wait);
49270 ret = -ERESTARTSYS;
49271 goto err;
49272
49273 err:
49274- if (!pipe->readers && !pipe->writers)
49275+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
49276 free_pipe_info(inode);
49277
49278 err_nocleanup:
49279diff --git a/fs/file.c b/fs/file.c
49280index 87e1290..a930cc4 100644
49281--- a/fs/file.c
49282+++ b/fs/file.c
49283@@ -14,6 +14,7 @@
49284 #include <linux/slab.h>
49285 #include <linux/vmalloc.h>
49286 #include <linux/file.h>
49287+#include <linux/security.h>
49288 #include <linux/fdtable.h>
49289 #include <linux/bitops.h>
49290 #include <linux/interrupt.h>
49291@@ -257,6 +258,8 @@ int expand_files(struct files_struct *files, int nr)
49292 * N.B. For clone tasks sharing a files structure, this test
49293 * will limit the total number of files that can be opened.
49294 */
49295+
49296+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
49297 if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
49298 return -EMFILE;
49299
49300diff --git a/fs/filesystems.c b/fs/filesystems.c
49301index a24c58e..53f91ee 100644
49302--- a/fs/filesystems.c
49303+++ b/fs/filesystems.c
49304@@ -272,7 +272,12 @@ struct file_system_type *get_fs_type(const char *name)
49305 int len = dot ? dot - name : strlen(name);
49306
49307 fs = __get_fs_type(name, len);
49308+
49309+#ifdef CONFIG_GRKERNSEC_MODHARDEN
49310+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
49311+#else
49312 if (!fs && (request_module("%.*s", len, name) == 0))
49313+#endif
49314 fs = __get_fs_type(name, len);
49315
49316 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
49317diff --git a/fs/fs_struct.c b/fs/fs_struct.c
49318index eee0590..ef5bc0e 100644
49319--- a/fs/fs_struct.c
49320+++ b/fs/fs_struct.c
49321@@ -4,6 +4,7 @@
49322 #include <linux/path.h>
49323 #include <linux/slab.h>
49324 #include <linux/fs_struct.h>
49325+#include <linux/grsecurity.h>
49326
49327 /*
49328 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
49329@@ -17,6 +18,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
49330 old_root = fs->root;
49331 fs->root = *path;
49332 path_get(path);
49333+ gr_set_chroot_entries(current, path);
49334 write_unlock(&fs->lock);
49335 if (old_root.dentry)
49336 path_put(&old_root);
49337@@ -56,6 +58,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
49338 && fs->root.mnt == old_root->mnt) {
49339 path_get(new_root);
49340 fs->root = *new_root;
49341+ gr_set_chroot_entries(p, new_root);
49342 count++;
49343 }
49344 if (fs->pwd.dentry == old_root->dentry
49345@@ -89,7 +92,8 @@ void exit_fs(struct task_struct *tsk)
49346 task_lock(tsk);
49347 write_lock(&fs->lock);
49348 tsk->fs = NULL;
49349- kill = !--fs->users;
49350+ gr_clear_chroot_entries(tsk);
49351+ kill = !atomic_dec_return(&fs->users);
49352 write_unlock(&fs->lock);
49353 task_unlock(tsk);
49354 if (kill)
49355@@ -102,7 +106,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
49356 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
49357 /* We don't need to lock fs - think why ;-) */
49358 if (fs) {
49359- fs->users = 1;
49360+ atomic_set(&fs->users, 1);
49361 fs->in_exec = 0;
49362 rwlock_init(&fs->lock);
49363 fs->umask = old->umask;
49364@@ -127,8 +131,9 @@ int unshare_fs_struct(void)
49365
49366 task_lock(current);
49367 write_lock(&fs->lock);
49368- kill = !--fs->users;
49369+ kill = !atomic_dec_return(&fs->users);
49370 current->fs = new_fs;
49371+ gr_set_chroot_entries(current, &new_fs->root);
49372 write_unlock(&fs->lock);
49373 task_unlock(current);
49374
49375@@ -147,7 +152,7 @@ EXPORT_SYMBOL(current_umask);
49376
49377 /* to be mentioned only in INIT_TASK */
49378 struct fs_struct init_fs = {
49379- .users = 1,
49380+ .users = ATOMIC_INIT(1),
49381 .lock = __RW_LOCK_UNLOCKED(init_fs.lock),
49382 .umask = 0022,
49383 };
49384@@ -162,12 +167,13 @@ void daemonize_fs_struct(void)
49385 task_lock(current);
49386
49387 write_lock(&init_fs.lock);
49388- init_fs.users++;
49389+ atomic_inc(&init_fs.users);
49390 write_unlock(&init_fs.lock);
49391
49392 write_lock(&fs->lock);
49393 current->fs = &init_fs;
49394- kill = !--fs->users;
49395+ gr_set_chroot_entries(current, &current->fs->root);
49396+ kill = !atomic_dec_return(&fs->users);
49397 write_unlock(&fs->lock);
49398
49399 task_unlock(current);
49400diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
49401index 9905350..02eaec4 100644
49402--- a/fs/fscache/cookie.c
49403+++ b/fs/fscache/cookie.c
49404@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
49405 parent ? (char *) parent->def->name : "<no-parent>",
49406 def->name, netfs_data);
49407
49408- fscache_stat(&fscache_n_acquires);
49409+ fscache_stat_unchecked(&fscache_n_acquires);
49410
49411 /* if there's no parent cookie, then we don't create one here either */
49412 if (!parent) {
49413- fscache_stat(&fscache_n_acquires_null);
49414+ fscache_stat_unchecked(&fscache_n_acquires_null);
49415 _leave(" [no parent]");
49416 return NULL;
49417 }
49418@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
49419 /* allocate and initialise a cookie */
49420 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
49421 if (!cookie) {
49422- fscache_stat(&fscache_n_acquires_oom);
49423+ fscache_stat_unchecked(&fscache_n_acquires_oom);
49424 _leave(" [ENOMEM]");
49425 return NULL;
49426 }
49427@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
49428
49429 switch (cookie->def->type) {
49430 case FSCACHE_COOKIE_TYPE_INDEX:
49431- fscache_stat(&fscache_n_cookie_index);
49432+ fscache_stat_unchecked(&fscache_n_cookie_index);
49433 break;
49434 case FSCACHE_COOKIE_TYPE_DATAFILE:
49435- fscache_stat(&fscache_n_cookie_data);
49436+ fscache_stat_unchecked(&fscache_n_cookie_data);
49437 break;
49438 default:
49439- fscache_stat(&fscache_n_cookie_special);
49440+ fscache_stat_unchecked(&fscache_n_cookie_special);
49441 break;
49442 }
49443
49444@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
49445 if (fscache_acquire_non_index_cookie(cookie) < 0) {
49446 atomic_dec(&parent->n_children);
49447 __fscache_cookie_put(cookie);
49448- fscache_stat(&fscache_n_acquires_nobufs);
49449+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
49450 _leave(" = NULL");
49451 return NULL;
49452 }
49453 }
49454
49455- fscache_stat(&fscache_n_acquires_ok);
49456+ fscache_stat_unchecked(&fscache_n_acquires_ok);
49457 _leave(" = %p", cookie);
49458 return cookie;
49459 }
49460@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
49461 cache = fscache_select_cache_for_object(cookie->parent);
49462 if (!cache) {
49463 up_read(&fscache_addremove_sem);
49464- fscache_stat(&fscache_n_acquires_no_cache);
49465+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
49466 _leave(" = -ENOMEDIUM [no cache]");
49467 return -ENOMEDIUM;
49468 }
49469@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
49470 object = cache->ops->alloc_object(cache, cookie);
49471 fscache_stat_d(&fscache_n_cop_alloc_object);
49472 if (IS_ERR(object)) {
49473- fscache_stat(&fscache_n_object_no_alloc);
49474+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
49475 ret = PTR_ERR(object);
49476 goto error;
49477 }
49478
49479- fscache_stat(&fscache_n_object_alloc);
49480+ fscache_stat_unchecked(&fscache_n_object_alloc);
49481
49482 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
49483
49484@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
49485 struct fscache_object *object;
49486 struct hlist_node *_p;
49487
49488- fscache_stat(&fscache_n_updates);
49489+ fscache_stat_unchecked(&fscache_n_updates);
49490
49491 if (!cookie) {
49492- fscache_stat(&fscache_n_updates_null);
49493+ fscache_stat_unchecked(&fscache_n_updates_null);
49494 _leave(" [no cookie]");
49495 return;
49496 }
49497@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
49498 struct fscache_object *object;
49499 unsigned long event;
49500
49501- fscache_stat(&fscache_n_relinquishes);
49502+ fscache_stat_unchecked(&fscache_n_relinquishes);
49503 if (retire)
49504- fscache_stat(&fscache_n_relinquishes_retire);
49505+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
49506
49507 if (!cookie) {
49508- fscache_stat(&fscache_n_relinquishes_null);
49509+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
49510 _leave(" [no cookie]");
49511 return;
49512 }
49513@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
49514
49515 /* wait for the cookie to finish being instantiated (or to fail) */
49516 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
49517- fscache_stat(&fscache_n_relinquishes_waitcrt);
49518+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
49519 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
49520 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
49521 }
49522diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
49523index edd7434..0725e66 100644
49524--- a/fs/fscache/internal.h
49525+++ b/fs/fscache/internal.h
49526@@ -136,94 +136,94 @@ extern void fscache_proc_cleanup(void);
49527 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
49528 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
49529
49530-extern atomic_t fscache_n_op_pend;
49531-extern atomic_t fscache_n_op_run;
49532-extern atomic_t fscache_n_op_enqueue;
49533-extern atomic_t fscache_n_op_deferred_release;
49534-extern atomic_t fscache_n_op_release;
49535-extern atomic_t fscache_n_op_gc;
49536-extern atomic_t fscache_n_op_cancelled;
49537-extern atomic_t fscache_n_op_rejected;
49538+extern atomic_unchecked_t fscache_n_op_pend;
49539+extern atomic_unchecked_t fscache_n_op_run;
49540+extern atomic_unchecked_t fscache_n_op_enqueue;
49541+extern atomic_unchecked_t fscache_n_op_deferred_release;
49542+extern atomic_unchecked_t fscache_n_op_release;
49543+extern atomic_unchecked_t fscache_n_op_gc;
49544+extern atomic_unchecked_t fscache_n_op_cancelled;
49545+extern atomic_unchecked_t fscache_n_op_rejected;
49546
49547-extern atomic_t fscache_n_attr_changed;
49548-extern atomic_t fscache_n_attr_changed_ok;
49549-extern atomic_t fscache_n_attr_changed_nobufs;
49550-extern atomic_t fscache_n_attr_changed_nomem;
49551-extern atomic_t fscache_n_attr_changed_calls;
49552+extern atomic_unchecked_t fscache_n_attr_changed;
49553+extern atomic_unchecked_t fscache_n_attr_changed_ok;
49554+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
49555+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
49556+extern atomic_unchecked_t fscache_n_attr_changed_calls;
49557
49558-extern atomic_t fscache_n_allocs;
49559-extern atomic_t fscache_n_allocs_ok;
49560-extern atomic_t fscache_n_allocs_wait;
49561-extern atomic_t fscache_n_allocs_nobufs;
49562-extern atomic_t fscache_n_allocs_intr;
49563-extern atomic_t fscache_n_allocs_object_dead;
49564-extern atomic_t fscache_n_alloc_ops;
49565-extern atomic_t fscache_n_alloc_op_waits;
49566+extern atomic_unchecked_t fscache_n_allocs;
49567+extern atomic_unchecked_t fscache_n_allocs_ok;
49568+extern atomic_unchecked_t fscache_n_allocs_wait;
49569+extern atomic_unchecked_t fscache_n_allocs_nobufs;
49570+extern atomic_unchecked_t fscache_n_allocs_intr;
49571+extern atomic_unchecked_t fscache_n_allocs_object_dead;
49572+extern atomic_unchecked_t fscache_n_alloc_ops;
49573+extern atomic_unchecked_t fscache_n_alloc_op_waits;
49574
49575-extern atomic_t fscache_n_retrievals;
49576-extern atomic_t fscache_n_retrievals_ok;
49577-extern atomic_t fscache_n_retrievals_wait;
49578-extern atomic_t fscache_n_retrievals_nodata;
49579-extern atomic_t fscache_n_retrievals_nobufs;
49580-extern atomic_t fscache_n_retrievals_intr;
49581-extern atomic_t fscache_n_retrievals_nomem;
49582-extern atomic_t fscache_n_retrievals_object_dead;
49583-extern atomic_t fscache_n_retrieval_ops;
49584-extern atomic_t fscache_n_retrieval_op_waits;
49585+extern atomic_unchecked_t fscache_n_retrievals;
49586+extern atomic_unchecked_t fscache_n_retrievals_ok;
49587+extern atomic_unchecked_t fscache_n_retrievals_wait;
49588+extern atomic_unchecked_t fscache_n_retrievals_nodata;
49589+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
49590+extern atomic_unchecked_t fscache_n_retrievals_intr;
49591+extern atomic_unchecked_t fscache_n_retrievals_nomem;
49592+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
49593+extern atomic_unchecked_t fscache_n_retrieval_ops;
49594+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
49595
49596-extern atomic_t fscache_n_stores;
49597-extern atomic_t fscache_n_stores_ok;
49598-extern atomic_t fscache_n_stores_again;
49599-extern atomic_t fscache_n_stores_nobufs;
49600-extern atomic_t fscache_n_stores_oom;
49601-extern atomic_t fscache_n_store_ops;
49602-extern atomic_t fscache_n_store_calls;
49603-extern atomic_t fscache_n_store_pages;
49604-extern atomic_t fscache_n_store_radix_deletes;
49605-extern atomic_t fscache_n_store_pages_over_limit;
49606+extern atomic_unchecked_t fscache_n_stores;
49607+extern atomic_unchecked_t fscache_n_stores_ok;
49608+extern atomic_unchecked_t fscache_n_stores_again;
49609+extern atomic_unchecked_t fscache_n_stores_nobufs;
49610+extern atomic_unchecked_t fscache_n_stores_oom;
49611+extern atomic_unchecked_t fscache_n_store_ops;
49612+extern atomic_unchecked_t fscache_n_store_calls;
49613+extern atomic_unchecked_t fscache_n_store_pages;
49614+extern atomic_unchecked_t fscache_n_store_radix_deletes;
49615+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
49616
49617-extern atomic_t fscache_n_store_vmscan_not_storing;
49618-extern atomic_t fscache_n_store_vmscan_gone;
49619-extern atomic_t fscache_n_store_vmscan_busy;
49620-extern atomic_t fscache_n_store_vmscan_cancelled;
49621+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49622+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
49623+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
49624+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49625
49626-extern atomic_t fscache_n_marks;
49627-extern atomic_t fscache_n_uncaches;
49628+extern atomic_unchecked_t fscache_n_marks;
49629+extern atomic_unchecked_t fscache_n_uncaches;
49630
49631-extern atomic_t fscache_n_acquires;
49632-extern atomic_t fscache_n_acquires_null;
49633-extern atomic_t fscache_n_acquires_no_cache;
49634-extern atomic_t fscache_n_acquires_ok;
49635-extern atomic_t fscache_n_acquires_nobufs;
49636-extern atomic_t fscache_n_acquires_oom;
49637+extern atomic_unchecked_t fscache_n_acquires;
49638+extern atomic_unchecked_t fscache_n_acquires_null;
49639+extern atomic_unchecked_t fscache_n_acquires_no_cache;
49640+extern atomic_unchecked_t fscache_n_acquires_ok;
49641+extern atomic_unchecked_t fscache_n_acquires_nobufs;
49642+extern atomic_unchecked_t fscache_n_acquires_oom;
49643
49644-extern atomic_t fscache_n_updates;
49645-extern atomic_t fscache_n_updates_null;
49646-extern atomic_t fscache_n_updates_run;
49647+extern atomic_unchecked_t fscache_n_updates;
49648+extern atomic_unchecked_t fscache_n_updates_null;
49649+extern atomic_unchecked_t fscache_n_updates_run;
49650
49651-extern atomic_t fscache_n_relinquishes;
49652-extern atomic_t fscache_n_relinquishes_null;
49653-extern atomic_t fscache_n_relinquishes_waitcrt;
49654-extern atomic_t fscache_n_relinquishes_retire;
49655+extern atomic_unchecked_t fscache_n_relinquishes;
49656+extern atomic_unchecked_t fscache_n_relinquishes_null;
49657+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49658+extern atomic_unchecked_t fscache_n_relinquishes_retire;
49659
49660-extern atomic_t fscache_n_cookie_index;
49661-extern atomic_t fscache_n_cookie_data;
49662-extern atomic_t fscache_n_cookie_special;
49663+extern atomic_unchecked_t fscache_n_cookie_index;
49664+extern atomic_unchecked_t fscache_n_cookie_data;
49665+extern atomic_unchecked_t fscache_n_cookie_special;
49666
49667-extern atomic_t fscache_n_object_alloc;
49668-extern atomic_t fscache_n_object_no_alloc;
49669-extern atomic_t fscache_n_object_lookups;
49670-extern atomic_t fscache_n_object_lookups_negative;
49671-extern atomic_t fscache_n_object_lookups_positive;
49672-extern atomic_t fscache_n_object_lookups_timed_out;
49673-extern atomic_t fscache_n_object_created;
49674-extern atomic_t fscache_n_object_avail;
49675-extern atomic_t fscache_n_object_dead;
49676+extern atomic_unchecked_t fscache_n_object_alloc;
49677+extern atomic_unchecked_t fscache_n_object_no_alloc;
49678+extern atomic_unchecked_t fscache_n_object_lookups;
49679+extern atomic_unchecked_t fscache_n_object_lookups_negative;
49680+extern atomic_unchecked_t fscache_n_object_lookups_positive;
49681+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
49682+extern atomic_unchecked_t fscache_n_object_created;
49683+extern atomic_unchecked_t fscache_n_object_avail;
49684+extern atomic_unchecked_t fscache_n_object_dead;
49685
49686-extern atomic_t fscache_n_checkaux_none;
49687-extern atomic_t fscache_n_checkaux_okay;
49688-extern atomic_t fscache_n_checkaux_update;
49689-extern atomic_t fscache_n_checkaux_obsolete;
49690+extern atomic_unchecked_t fscache_n_checkaux_none;
49691+extern atomic_unchecked_t fscache_n_checkaux_okay;
49692+extern atomic_unchecked_t fscache_n_checkaux_update;
49693+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
49694
49695 extern atomic_t fscache_n_cop_alloc_object;
49696 extern atomic_t fscache_n_cop_lookup_object;
49697@@ -247,6 +247,11 @@ static inline void fscache_stat(atomic_t *stat)
49698 atomic_inc(stat);
49699 }
49700
49701+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
49702+{
49703+ atomic_inc_unchecked(stat);
49704+}
49705+
49706 static inline void fscache_stat_d(atomic_t *stat)
49707 {
49708 atomic_dec(stat);
49709@@ -259,6 +264,7 @@ extern const struct file_operations fscache_stats_fops;
49710
49711 #define __fscache_stat(stat) (NULL)
49712 #define fscache_stat(stat) do {} while (0)
49713+#define fscache_stat_unchecked(stat) do {} while (0)
49714 #define fscache_stat_d(stat) do {} while (0)
49715 #endif
49716
49717diff --git a/fs/fscache/object.c b/fs/fscache/object.c
49718index e513ac5..e888d34 100644
49719--- a/fs/fscache/object.c
49720+++ b/fs/fscache/object.c
49721@@ -144,7 +144,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49722 /* update the object metadata on disk */
49723 case FSCACHE_OBJECT_UPDATING:
49724 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
49725- fscache_stat(&fscache_n_updates_run);
49726+ fscache_stat_unchecked(&fscache_n_updates_run);
49727 fscache_stat(&fscache_n_cop_update_object);
49728 object->cache->ops->update_object(object);
49729 fscache_stat_d(&fscache_n_cop_update_object);
49730@@ -233,7 +233,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49731 spin_lock(&object->lock);
49732 object->state = FSCACHE_OBJECT_DEAD;
49733 spin_unlock(&object->lock);
49734- fscache_stat(&fscache_n_object_dead);
49735+ fscache_stat_unchecked(&fscache_n_object_dead);
49736 goto terminal_transit;
49737
49738 /* handle the parent cache of this object being withdrawn from
49739@@ -248,7 +248,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49740 spin_lock(&object->lock);
49741 object->state = FSCACHE_OBJECT_DEAD;
49742 spin_unlock(&object->lock);
49743- fscache_stat(&fscache_n_object_dead);
49744+ fscache_stat_unchecked(&fscache_n_object_dead);
49745 goto terminal_transit;
49746
49747 /* complain about the object being woken up once it is
49748@@ -492,7 +492,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49749 parent->cookie->def->name, cookie->def->name,
49750 object->cache->tag->name);
49751
49752- fscache_stat(&fscache_n_object_lookups);
49753+ fscache_stat_unchecked(&fscache_n_object_lookups);
49754 fscache_stat(&fscache_n_cop_lookup_object);
49755 ret = object->cache->ops->lookup_object(object);
49756 fscache_stat_d(&fscache_n_cop_lookup_object);
49757@@ -503,7 +503,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49758 if (ret == -ETIMEDOUT) {
49759 /* probably stuck behind another object, so move this one to
49760 * the back of the queue */
49761- fscache_stat(&fscache_n_object_lookups_timed_out);
49762+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
49763 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49764 }
49765
49766@@ -526,7 +526,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
49767
49768 spin_lock(&object->lock);
49769 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49770- fscache_stat(&fscache_n_object_lookups_negative);
49771+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
49772
49773 /* transit here to allow write requests to begin stacking up
49774 * and read requests to begin returning ENODATA */
49775@@ -572,7 +572,7 @@ void fscache_obtained_object(struct fscache_object *object)
49776 * result, in which case there may be data available */
49777 spin_lock(&object->lock);
49778 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49779- fscache_stat(&fscache_n_object_lookups_positive);
49780+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
49781
49782 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
49783
49784@@ -586,7 +586,7 @@ void fscache_obtained_object(struct fscache_object *object)
49785 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49786 } else {
49787 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
49788- fscache_stat(&fscache_n_object_created);
49789+ fscache_stat_unchecked(&fscache_n_object_created);
49790
49791 object->state = FSCACHE_OBJECT_AVAILABLE;
49792 spin_unlock(&object->lock);
49793@@ -633,7 +633,7 @@ static void fscache_object_available(struct fscache_object *object)
49794 fscache_enqueue_dependents(object);
49795
49796 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
49797- fscache_stat(&fscache_n_object_avail);
49798+ fscache_stat_unchecked(&fscache_n_object_avail);
49799
49800 _leave("");
49801 }
49802@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49803 enum fscache_checkaux result;
49804
49805 if (!object->cookie->def->check_aux) {
49806- fscache_stat(&fscache_n_checkaux_none);
49807+ fscache_stat_unchecked(&fscache_n_checkaux_none);
49808 return FSCACHE_CHECKAUX_OKAY;
49809 }
49810
49811@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49812 switch (result) {
49813 /* entry okay as is */
49814 case FSCACHE_CHECKAUX_OKAY:
49815- fscache_stat(&fscache_n_checkaux_okay);
49816+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
49817 break;
49818
49819 /* entry requires update */
49820 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
49821- fscache_stat(&fscache_n_checkaux_update);
49822+ fscache_stat_unchecked(&fscache_n_checkaux_update);
49823 break;
49824
49825 /* entry requires deletion */
49826 case FSCACHE_CHECKAUX_OBSOLETE:
49827- fscache_stat(&fscache_n_checkaux_obsolete);
49828+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
49829 break;
49830
49831 default:
49832diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
49833index 313e79a..775240f 100644
49834--- a/fs/fscache/operation.c
49835+++ b/fs/fscache/operation.c
49836@@ -16,7 +16,7 @@
49837 #include <linux/seq_file.h>
49838 #include "internal.h"
49839
49840-atomic_t fscache_op_debug_id;
49841+atomic_unchecked_t fscache_op_debug_id;
49842 EXPORT_SYMBOL(fscache_op_debug_id);
49843
49844 /**
49845@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
49846 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
49847 ASSERTCMP(atomic_read(&op->usage), >, 0);
49848
49849- fscache_stat(&fscache_n_op_enqueue);
49850+ fscache_stat_unchecked(&fscache_n_op_enqueue);
49851 switch (op->flags & FSCACHE_OP_TYPE) {
49852 case FSCACHE_OP_FAST:
49853 _debug("queue fast");
49854@@ -76,7 +76,7 @@ static void fscache_run_op(struct fscache_object *object,
49855 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
49856 if (op->processor)
49857 fscache_enqueue_operation(op);
49858- fscache_stat(&fscache_n_op_run);
49859+ fscache_stat_unchecked(&fscache_n_op_run);
49860 }
49861
49862 /*
49863@@ -107,11 +107,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49864 if (object->n_ops > 0) {
49865 atomic_inc(&op->usage);
49866 list_add_tail(&op->pend_link, &object->pending_ops);
49867- fscache_stat(&fscache_n_op_pend);
49868+ fscache_stat_unchecked(&fscache_n_op_pend);
49869 } else if (!list_empty(&object->pending_ops)) {
49870 atomic_inc(&op->usage);
49871 list_add_tail(&op->pend_link, &object->pending_ops);
49872- fscache_stat(&fscache_n_op_pend);
49873+ fscache_stat_unchecked(&fscache_n_op_pend);
49874 fscache_start_operations(object);
49875 } else {
49876 ASSERTCMP(object->n_in_progress, ==, 0);
49877@@ -127,7 +127,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49878 object->n_exclusive++; /* reads and writes must wait */
49879 atomic_inc(&op->usage);
49880 list_add_tail(&op->pend_link, &object->pending_ops);
49881- fscache_stat(&fscache_n_op_pend);
49882+ fscache_stat_unchecked(&fscache_n_op_pend);
49883 ret = 0;
49884 } else {
49885 /* not allowed to submit ops in any other state */
49886@@ -214,11 +214,11 @@ int fscache_submit_op(struct fscache_object *object,
49887 if (object->n_exclusive > 0) {
49888 atomic_inc(&op->usage);
49889 list_add_tail(&op->pend_link, &object->pending_ops);
49890- fscache_stat(&fscache_n_op_pend);
49891+ fscache_stat_unchecked(&fscache_n_op_pend);
49892 } else if (!list_empty(&object->pending_ops)) {
49893 atomic_inc(&op->usage);
49894 list_add_tail(&op->pend_link, &object->pending_ops);
49895- fscache_stat(&fscache_n_op_pend);
49896+ fscache_stat_unchecked(&fscache_n_op_pend);
49897 fscache_start_operations(object);
49898 } else {
49899 ASSERTCMP(object->n_exclusive, ==, 0);
49900@@ -230,12 +230,12 @@ int fscache_submit_op(struct fscache_object *object,
49901 object->n_ops++;
49902 atomic_inc(&op->usage);
49903 list_add_tail(&op->pend_link, &object->pending_ops);
49904- fscache_stat(&fscache_n_op_pend);
49905+ fscache_stat_unchecked(&fscache_n_op_pend);
49906 ret = 0;
49907 } else if (object->state == FSCACHE_OBJECT_DYING ||
49908 object->state == FSCACHE_OBJECT_LC_DYING ||
49909 object->state == FSCACHE_OBJECT_WITHDRAWING) {
49910- fscache_stat(&fscache_n_op_rejected);
49911+ fscache_stat_unchecked(&fscache_n_op_rejected);
49912 ret = -ENOBUFS;
49913 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
49914 fscache_report_unexpected_submission(object, op, ostate);
49915@@ -305,7 +305,7 @@ int fscache_cancel_op(struct fscache_operation *op)
49916
49917 ret = -EBUSY;
49918 if (!list_empty(&op->pend_link)) {
49919- fscache_stat(&fscache_n_op_cancelled);
49920+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49921 list_del_init(&op->pend_link);
49922 object->n_ops--;
49923 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
49924@@ -344,7 +344,7 @@ void fscache_put_operation(struct fscache_operation *op)
49925 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
49926 BUG();
49927
49928- fscache_stat(&fscache_n_op_release);
49929+ fscache_stat_unchecked(&fscache_n_op_release);
49930
49931 if (op->release) {
49932 op->release(op);
49933@@ -361,7 +361,7 @@ void fscache_put_operation(struct fscache_operation *op)
49934 * lock, and defer it otherwise */
49935 if (!spin_trylock(&object->lock)) {
49936 _debug("defer put");
49937- fscache_stat(&fscache_n_op_deferred_release);
49938+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
49939
49940 cache = object->cache;
49941 spin_lock(&cache->op_gc_list_lock);
49942@@ -423,7 +423,7 @@ void fscache_operation_gc(struct work_struct *work)
49943
49944 _debug("GC DEFERRED REL OBJ%x OP%x",
49945 object->debug_id, op->debug_id);
49946- fscache_stat(&fscache_n_op_gc);
49947+ fscache_stat_unchecked(&fscache_n_op_gc);
49948
49949 ASSERTCMP(atomic_read(&op->usage), ==, 0);
49950
49951diff --git a/fs/fscache/page.c b/fs/fscache/page.c
49952index c598ea4..6aac13e 100644
49953--- a/fs/fscache/page.c
49954+++ b/fs/fscache/page.c
49955@@ -59,7 +59,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
49956 val = radix_tree_lookup(&cookie->stores, page->index);
49957 if (!val) {
49958 rcu_read_unlock();
49959- fscache_stat(&fscache_n_store_vmscan_not_storing);
49960+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
49961 __fscache_uncache_page(cookie, page);
49962 return true;
49963 }
49964@@ -89,11 +89,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
49965 spin_unlock(&cookie->stores_lock);
49966
49967 if (xpage) {
49968- fscache_stat(&fscache_n_store_vmscan_cancelled);
49969- fscache_stat(&fscache_n_store_radix_deletes);
49970+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
49971+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49972 ASSERTCMP(xpage, ==, page);
49973 } else {
49974- fscache_stat(&fscache_n_store_vmscan_gone);
49975+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
49976 }
49977
49978 wake_up_bit(&cookie->flags, 0);
49979@@ -106,7 +106,7 @@ page_busy:
49980 /* we might want to wait here, but that could deadlock the allocator as
49981 * the slow-work threads writing to the cache may all end up sleeping
49982 * on memory allocation */
49983- fscache_stat(&fscache_n_store_vmscan_busy);
49984+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
49985 return false;
49986 }
49987 EXPORT_SYMBOL(__fscache_maybe_release_page);
49988@@ -130,7 +130,7 @@ static void fscache_end_page_write(struct fscache_object *object,
49989 FSCACHE_COOKIE_STORING_TAG);
49990 if (!radix_tree_tag_get(&cookie->stores, page->index,
49991 FSCACHE_COOKIE_PENDING_TAG)) {
49992- fscache_stat(&fscache_n_store_radix_deletes);
49993+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49994 xpage = radix_tree_delete(&cookie->stores, page->index);
49995 }
49996 spin_unlock(&cookie->stores_lock);
49997@@ -151,7 +151,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
49998
49999 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
50000
50001- fscache_stat(&fscache_n_attr_changed_calls);
50002+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
50003
50004 if (fscache_object_is_active(object)) {
50005 fscache_set_op_state(op, "CallFS");
50006@@ -178,11 +178,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
50007
50008 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
50009
50010- fscache_stat(&fscache_n_attr_changed);
50011+ fscache_stat_unchecked(&fscache_n_attr_changed);
50012
50013 op = kzalloc(sizeof(*op), GFP_KERNEL);
50014 if (!op) {
50015- fscache_stat(&fscache_n_attr_changed_nomem);
50016+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
50017 _leave(" = -ENOMEM");
50018 return -ENOMEM;
50019 }
50020@@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
50021 if (fscache_submit_exclusive_op(object, op) < 0)
50022 goto nobufs;
50023 spin_unlock(&cookie->lock);
50024- fscache_stat(&fscache_n_attr_changed_ok);
50025+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
50026 fscache_put_operation(op);
50027 _leave(" = 0");
50028 return 0;
50029@@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
50030 nobufs:
50031 spin_unlock(&cookie->lock);
50032 kfree(op);
50033- fscache_stat(&fscache_n_attr_changed_nobufs);
50034+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
50035 _leave(" = %d", -ENOBUFS);
50036 return -ENOBUFS;
50037 }
50038@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
50039 /* allocate a retrieval operation and attempt to submit it */
50040 op = kzalloc(sizeof(*op), GFP_NOIO);
50041 if (!op) {
50042- fscache_stat(&fscache_n_retrievals_nomem);
50043+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
50044 return NULL;
50045 }
50046
50047@@ -294,13 +294,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
50048 return 0;
50049 }
50050
50051- fscache_stat(&fscache_n_retrievals_wait);
50052+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
50053
50054 jif = jiffies;
50055 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
50056 fscache_wait_bit_interruptible,
50057 TASK_INTERRUPTIBLE) != 0) {
50058- fscache_stat(&fscache_n_retrievals_intr);
50059+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
50060 _leave(" = -ERESTARTSYS");
50061 return -ERESTARTSYS;
50062 }
50063@@ -318,8 +318,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
50064 */
50065 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
50066 struct fscache_retrieval *op,
50067- atomic_t *stat_op_waits,
50068- atomic_t *stat_object_dead)
50069+ atomic_unchecked_t *stat_op_waits,
50070+ atomic_unchecked_t *stat_object_dead)
50071 {
50072 int ret;
50073
50074@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
50075 goto check_if_dead;
50076
50077 _debug(">>> WT");
50078- fscache_stat(stat_op_waits);
50079+ fscache_stat_unchecked(stat_op_waits);
50080 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
50081 fscache_wait_bit_interruptible,
50082 TASK_INTERRUPTIBLE) < 0) {
50083@@ -344,7 +344,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
50084
50085 check_if_dead:
50086 if (unlikely(fscache_object_is_dead(object))) {
50087- fscache_stat(stat_object_dead);
50088+ fscache_stat_unchecked(stat_object_dead);
50089 return -ENOBUFS;
50090 }
50091 return 0;
50092@@ -371,7 +371,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
50093
50094 _enter("%p,%p,,,", cookie, page);
50095
50096- fscache_stat(&fscache_n_retrievals);
50097+ fscache_stat_unchecked(&fscache_n_retrievals);
50098
50099 if (hlist_empty(&cookie->backing_objects))
50100 goto nobufs;
50101@@ -405,7 +405,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
50102 goto nobufs_unlock;
50103 spin_unlock(&cookie->lock);
50104
50105- fscache_stat(&fscache_n_retrieval_ops);
50106+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
50107
50108 /* pin the netfs read context in case we need to do the actual netfs
50109 * read because we've encountered a cache read failure */
50110@@ -435,15 +435,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
50111
50112 error:
50113 if (ret == -ENOMEM)
50114- fscache_stat(&fscache_n_retrievals_nomem);
50115+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
50116 else if (ret == -ERESTARTSYS)
50117- fscache_stat(&fscache_n_retrievals_intr);
50118+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
50119 else if (ret == -ENODATA)
50120- fscache_stat(&fscache_n_retrievals_nodata);
50121+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
50122 else if (ret < 0)
50123- fscache_stat(&fscache_n_retrievals_nobufs);
50124+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
50125 else
50126- fscache_stat(&fscache_n_retrievals_ok);
50127+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
50128
50129 fscache_put_retrieval(op);
50130 _leave(" = %d", ret);
50131@@ -453,7 +453,7 @@ nobufs_unlock:
50132 spin_unlock(&cookie->lock);
50133 kfree(op);
50134 nobufs:
50135- fscache_stat(&fscache_n_retrievals_nobufs);
50136+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
50137 _leave(" = -ENOBUFS");
50138 return -ENOBUFS;
50139 }
50140@@ -491,7 +491,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
50141
50142 _enter("%p,,%d,,,", cookie, *nr_pages);
50143
50144- fscache_stat(&fscache_n_retrievals);
50145+ fscache_stat_unchecked(&fscache_n_retrievals);
50146
50147 if (hlist_empty(&cookie->backing_objects))
50148 goto nobufs;
50149@@ -522,7 +522,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
50150 goto nobufs_unlock;
50151 spin_unlock(&cookie->lock);
50152
50153- fscache_stat(&fscache_n_retrieval_ops);
50154+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
50155
50156 /* pin the netfs read context in case we need to do the actual netfs
50157 * read because we've encountered a cache read failure */
50158@@ -552,15 +552,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
50159
50160 error:
50161 if (ret == -ENOMEM)
50162- fscache_stat(&fscache_n_retrievals_nomem);
50163+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
50164 else if (ret == -ERESTARTSYS)
50165- fscache_stat(&fscache_n_retrievals_intr);
50166+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
50167 else if (ret == -ENODATA)
50168- fscache_stat(&fscache_n_retrievals_nodata);
50169+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
50170 else if (ret < 0)
50171- fscache_stat(&fscache_n_retrievals_nobufs);
50172+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
50173 else
50174- fscache_stat(&fscache_n_retrievals_ok);
50175+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
50176
50177 fscache_put_retrieval(op);
50178 _leave(" = %d", ret);
50179@@ -570,7 +570,7 @@ nobufs_unlock:
50180 spin_unlock(&cookie->lock);
50181 kfree(op);
50182 nobufs:
50183- fscache_stat(&fscache_n_retrievals_nobufs);
50184+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
50185 _leave(" = -ENOBUFS");
50186 return -ENOBUFS;
50187 }
50188@@ -594,7 +594,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
50189
50190 _enter("%p,%p,,,", cookie, page);
50191
50192- fscache_stat(&fscache_n_allocs);
50193+ fscache_stat_unchecked(&fscache_n_allocs);
50194
50195 if (hlist_empty(&cookie->backing_objects))
50196 goto nobufs;
50197@@ -621,7 +621,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
50198 goto nobufs_unlock;
50199 spin_unlock(&cookie->lock);
50200
50201- fscache_stat(&fscache_n_alloc_ops);
50202+ fscache_stat_unchecked(&fscache_n_alloc_ops);
50203
50204 ret = fscache_wait_for_retrieval_activation(
50205 object, op,
50206@@ -637,11 +637,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
50207
50208 error:
50209 if (ret == -ERESTARTSYS)
50210- fscache_stat(&fscache_n_allocs_intr);
50211+ fscache_stat_unchecked(&fscache_n_allocs_intr);
50212 else if (ret < 0)
50213- fscache_stat(&fscache_n_allocs_nobufs);
50214+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
50215 else
50216- fscache_stat(&fscache_n_allocs_ok);
50217+ fscache_stat_unchecked(&fscache_n_allocs_ok);
50218
50219 fscache_put_retrieval(op);
50220 _leave(" = %d", ret);
50221@@ -651,7 +651,7 @@ nobufs_unlock:
50222 spin_unlock(&cookie->lock);
50223 kfree(op);
50224 nobufs:
50225- fscache_stat(&fscache_n_allocs_nobufs);
50226+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
50227 _leave(" = -ENOBUFS");
50228 return -ENOBUFS;
50229 }
50230@@ -694,7 +694,7 @@ static void fscache_write_op(struct fscache_operation *_op)
50231
50232 spin_lock(&cookie->stores_lock);
50233
50234- fscache_stat(&fscache_n_store_calls);
50235+ fscache_stat_unchecked(&fscache_n_store_calls);
50236
50237 /* find a page to store */
50238 page = NULL;
50239@@ -705,7 +705,7 @@ static void fscache_write_op(struct fscache_operation *_op)
50240 page = results[0];
50241 _debug("gang %d [%lx]", n, page->index);
50242 if (page->index > op->store_limit) {
50243- fscache_stat(&fscache_n_store_pages_over_limit);
50244+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
50245 goto superseded;
50246 }
50247
50248@@ -721,7 +721,7 @@ static void fscache_write_op(struct fscache_operation *_op)
50249
50250 if (page) {
50251 fscache_set_op_state(&op->op, "Store");
50252- fscache_stat(&fscache_n_store_pages);
50253+ fscache_stat_unchecked(&fscache_n_store_pages);
50254 fscache_stat(&fscache_n_cop_write_page);
50255 ret = object->cache->ops->write_page(op, page);
50256 fscache_stat_d(&fscache_n_cop_write_page);
50257@@ -792,7 +792,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
50258 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
50259 ASSERT(PageFsCache(page));
50260
50261- fscache_stat(&fscache_n_stores);
50262+ fscache_stat_unchecked(&fscache_n_stores);
50263
50264 op = kzalloc(sizeof(*op), GFP_NOIO);
50265 if (!op)
50266@@ -844,7 +844,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
50267 spin_unlock(&cookie->stores_lock);
50268 spin_unlock(&object->lock);
50269
50270- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
50271+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
50272 op->store_limit = object->store_limit;
50273
50274 if (fscache_submit_op(object, &op->op) < 0)
50275@@ -852,8 +852,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
50276
50277 spin_unlock(&cookie->lock);
50278 radix_tree_preload_end();
50279- fscache_stat(&fscache_n_store_ops);
50280- fscache_stat(&fscache_n_stores_ok);
50281+ fscache_stat_unchecked(&fscache_n_store_ops);
50282+ fscache_stat_unchecked(&fscache_n_stores_ok);
50283
50284 /* the slow work queue now carries its own ref on the object */
50285 fscache_put_operation(&op->op);
50286@@ -861,14 +861,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
50287 return 0;
50288
50289 already_queued:
50290- fscache_stat(&fscache_n_stores_again);
50291+ fscache_stat_unchecked(&fscache_n_stores_again);
50292 already_pending:
50293 spin_unlock(&cookie->stores_lock);
50294 spin_unlock(&object->lock);
50295 spin_unlock(&cookie->lock);
50296 radix_tree_preload_end();
50297 kfree(op);
50298- fscache_stat(&fscache_n_stores_ok);
50299+ fscache_stat_unchecked(&fscache_n_stores_ok);
50300 _leave(" = 0");
50301 return 0;
50302
50303@@ -886,14 +886,14 @@ nobufs:
50304 spin_unlock(&cookie->lock);
50305 radix_tree_preload_end();
50306 kfree(op);
50307- fscache_stat(&fscache_n_stores_nobufs);
50308+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
50309 _leave(" = -ENOBUFS");
50310 return -ENOBUFS;
50311
50312 nomem_free:
50313 kfree(op);
50314 nomem:
50315- fscache_stat(&fscache_n_stores_oom);
50316+ fscache_stat_unchecked(&fscache_n_stores_oom);
50317 _leave(" = -ENOMEM");
50318 return -ENOMEM;
50319 }
50320@@ -911,7 +911,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
50321 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
50322 ASSERTCMP(page, !=, NULL);
50323
50324- fscache_stat(&fscache_n_uncaches);
50325+ fscache_stat_unchecked(&fscache_n_uncaches);
50326
50327 /* cache withdrawal may beat us to it */
50328 if (!PageFsCache(page))
50329@@ -964,7 +964,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
50330 unsigned long loop;
50331
50332 #ifdef CONFIG_FSCACHE_STATS
50333- atomic_add(pagevec->nr, &fscache_n_marks);
50334+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
50335 #endif
50336
50337 for (loop = 0; loop < pagevec->nr; loop++) {
50338diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
50339index 46435f3..8cddf18 100644
50340--- a/fs/fscache/stats.c
50341+++ b/fs/fscache/stats.c
50342@@ -18,95 +18,95 @@
50343 /*
50344 * operation counters
50345 */
50346-atomic_t fscache_n_op_pend;
50347-atomic_t fscache_n_op_run;
50348-atomic_t fscache_n_op_enqueue;
50349-atomic_t fscache_n_op_requeue;
50350-atomic_t fscache_n_op_deferred_release;
50351-atomic_t fscache_n_op_release;
50352-atomic_t fscache_n_op_gc;
50353-atomic_t fscache_n_op_cancelled;
50354-atomic_t fscache_n_op_rejected;
50355+atomic_unchecked_t fscache_n_op_pend;
50356+atomic_unchecked_t fscache_n_op_run;
50357+atomic_unchecked_t fscache_n_op_enqueue;
50358+atomic_unchecked_t fscache_n_op_requeue;
50359+atomic_unchecked_t fscache_n_op_deferred_release;
50360+atomic_unchecked_t fscache_n_op_release;
50361+atomic_unchecked_t fscache_n_op_gc;
50362+atomic_unchecked_t fscache_n_op_cancelled;
50363+atomic_unchecked_t fscache_n_op_rejected;
50364
50365-atomic_t fscache_n_attr_changed;
50366-atomic_t fscache_n_attr_changed_ok;
50367-atomic_t fscache_n_attr_changed_nobufs;
50368-atomic_t fscache_n_attr_changed_nomem;
50369-atomic_t fscache_n_attr_changed_calls;
50370+atomic_unchecked_t fscache_n_attr_changed;
50371+atomic_unchecked_t fscache_n_attr_changed_ok;
50372+atomic_unchecked_t fscache_n_attr_changed_nobufs;
50373+atomic_unchecked_t fscache_n_attr_changed_nomem;
50374+atomic_unchecked_t fscache_n_attr_changed_calls;
50375
50376-atomic_t fscache_n_allocs;
50377-atomic_t fscache_n_allocs_ok;
50378-atomic_t fscache_n_allocs_wait;
50379-atomic_t fscache_n_allocs_nobufs;
50380-atomic_t fscache_n_allocs_intr;
50381-atomic_t fscache_n_allocs_object_dead;
50382-atomic_t fscache_n_alloc_ops;
50383-atomic_t fscache_n_alloc_op_waits;
50384+atomic_unchecked_t fscache_n_allocs;
50385+atomic_unchecked_t fscache_n_allocs_ok;
50386+atomic_unchecked_t fscache_n_allocs_wait;
50387+atomic_unchecked_t fscache_n_allocs_nobufs;
50388+atomic_unchecked_t fscache_n_allocs_intr;
50389+atomic_unchecked_t fscache_n_allocs_object_dead;
50390+atomic_unchecked_t fscache_n_alloc_ops;
50391+atomic_unchecked_t fscache_n_alloc_op_waits;
50392
50393-atomic_t fscache_n_retrievals;
50394-atomic_t fscache_n_retrievals_ok;
50395-atomic_t fscache_n_retrievals_wait;
50396-atomic_t fscache_n_retrievals_nodata;
50397-atomic_t fscache_n_retrievals_nobufs;
50398-atomic_t fscache_n_retrievals_intr;
50399-atomic_t fscache_n_retrievals_nomem;
50400-atomic_t fscache_n_retrievals_object_dead;
50401-atomic_t fscache_n_retrieval_ops;
50402-atomic_t fscache_n_retrieval_op_waits;
50403+atomic_unchecked_t fscache_n_retrievals;
50404+atomic_unchecked_t fscache_n_retrievals_ok;
50405+atomic_unchecked_t fscache_n_retrievals_wait;
50406+atomic_unchecked_t fscache_n_retrievals_nodata;
50407+atomic_unchecked_t fscache_n_retrievals_nobufs;
50408+atomic_unchecked_t fscache_n_retrievals_intr;
50409+atomic_unchecked_t fscache_n_retrievals_nomem;
50410+atomic_unchecked_t fscache_n_retrievals_object_dead;
50411+atomic_unchecked_t fscache_n_retrieval_ops;
50412+atomic_unchecked_t fscache_n_retrieval_op_waits;
50413
50414-atomic_t fscache_n_stores;
50415-atomic_t fscache_n_stores_ok;
50416-atomic_t fscache_n_stores_again;
50417-atomic_t fscache_n_stores_nobufs;
50418-atomic_t fscache_n_stores_oom;
50419-atomic_t fscache_n_store_ops;
50420-atomic_t fscache_n_store_calls;
50421-atomic_t fscache_n_store_pages;
50422-atomic_t fscache_n_store_radix_deletes;
50423-atomic_t fscache_n_store_pages_over_limit;
50424+atomic_unchecked_t fscache_n_stores;
50425+atomic_unchecked_t fscache_n_stores_ok;
50426+atomic_unchecked_t fscache_n_stores_again;
50427+atomic_unchecked_t fscache_n_stores_nobufs;
50428+atomic_unchecked_t fscache_n_stores_oom;
50429+atomic_unchecked_t fscache_n_store_ops;
50430+atomic_unchecked_t fscache_n_store_calls;
50431+atomic_unchecked_t fscache_n_store_pages;
50432+atomic_unchecked_t fscache_n_store_radix_deletes;
50433+atomic_unchecked_t fscache_n_store_pages_over_limit;
50434
50435-atomic_t fscache_n_store_vmscan_not_storing;
50436-atomic_t fscache_n_store_vmscan_gone;
50437-atomic_t fscache_n_store_vmscan_busy;
50438-atomic_t fscache_n_store_vmscan_cancelled;
50439+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
50440+atomic_unchecked_t fscache_n_store_vmscan_gone;
50441+atomic_unchecked_t fscache_n_store_vmscan_busy;
50442+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
50443
50444-atomic_t fscache_n_marks;
50445-atomic_t fscache_n_uncaches;
50446+atomic_unchecked_t fscache_n_marks;
50447+atomic_unchecked_t fscache_n_uncaches;
50448
50449-atomic_t fscache_n_acquires;
50450-atomic_t fscache_n_acquires_null;
50451-atomic_t fscache_n_acquires_no_cache;
50452-atomic_t fscache_n_acquires_ok;
50453-atomic_t fscache_n_acquires_nobufs;
50454-atomic_t fscache_n_acquires_oom;
50455+atomic_unchecked_t fscache_n_acquires;
50456+atomic_unchecked_t fscache_n_acquires_null;
50457+atomic_unchecked_t fscache_n_acquires_no_cache;
50458+atomic_unchecked_t fscache_n_acquires_ok;
50459+atomic_unchecked_t fscache_n_acquires_nobufs;
50460+atomic_unchecked_t fscache_n_acquires_oom;
50461
50462-atomic_t fscache_n_updates;
50463-atomic_t fscache_n_updates_null;
50464-atomic_t fscache_n_updates_run;
50465+atomic_unchecked_t fscache_n_updates;
50466+atomic_unchecked_t fscache_n_updates_null;
50467+atomic_unchecked_t fscache_n_updates_run;
50468
50469-atomic_t fscache_n_relinquishes;
50470-atomic_t fscache_n_relinquishes_null;
50471-atomic_t fscache_n_relinquishes_waitcrt;
50472-atomic_t fscache_n_relinquishes_retire;
50473+atomic_unchecked_t fscache_n_relinquishes;
50474+atomic_unchecked_t fscache_n_relinquishes_null;
50475+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
50476+atomic_unchecked_t fscache_n_relinquishes_retire;
50477
50478-atomic_t fscache_n_cookie_index;
50479-atomic_t fscache_n_cookie_data;
50480-atomic_t fscache_n_cookie_special;
50481+atomic_unchecked_t fscache_n_cookie_index;
50482+atomic_unchecked_t fscache_n_cookie_data;
50483+atomic_unchecked_t fscache_n_cookie_special;
50484
50485-atomic_t fscache_n_object_alloc;
50486-atomic_t fscache_n_object_no_alloc;
50487-atomic_t fscache_n_object_lookups;
50488-atomic_t fscache_n_object_lookups_negative;
50489-atomic_t fscache_n_object_lookups_positive;
50490-atomic_t fscache_n_object_lookups_timed_out;
50491-atomic_t fscache_n_object_created;
50492-atomic_t fscache_n_object_avail;
50493-atomic_t fscache_n_object_dead;
50494+atomic_unchecked_t fscache_n_object_alloc;
50495+atomic_unchecked_t fscache_n_object_no_alloc;
50496+atomic_unchecked_t fscache_n_object_lookups;
50497+atomic_unchecked_t fscache_n_object_lookups_negative;
50498+atomic_unchecked_t fscache_n_object_lookups_positive;
50499+atomic_unchecked_t fscache_n_object_lookups_timed_out;
50500+atomic_unchecked_t fscache_n_object_created;
50501+atomic_unchecked_t fscache_n_object_avail;
50502+atomic_unchecked_t fscache_n_object_dead;
50503
50504-atomic_t fscache_n_checkaux_none;
50505-atomic_t fscache_n_checkaux_okay;
50506-atomic_t fscache_n_checkaux_update;
50507-atomic_t fscache_n_checkaux_obsolete;
50508+atomic_unchecked_t fscache_n_checkaux_none;
50509+atomic_unchecked_t fscache_n_checkaux_okay;
50510+atomic_unchecked_t fscache_n_checkaux_update;
50511+atomic_unchecked_t fscache_n_checkaux_obsolete;
50512
50513 atomic_t fscache_n_cop_alloc_object;
50514 atomic_t fscache_n_cop_lookup_object;
50515@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
50516 seq_puts(m, "FS-Cache statistics\n");
50517
50518 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
50519- atomic_read(&fscache_n_cookie_index),
50520- atomic_read(&fscache_n_cookie_data),
50521- atomic_read(&fscache_n_cookie_special));
50522+ atomic_read_unchecked(&fscache_n_cookie_index),
50523+ atomic_read_unchecked(&fscache_n_cookie_data),
50524+ atomic_read_unchecked(&fscache_n_cookie_special));
50525
50526 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
50527- atomic_read(&fscache_n_object_alloc),
50528- atomic_read(&fscache_n_object_no_alloc),
50529- atomic_read(&fscache_n_object_avail),
50530- atomic_read(&fscache_n_object_dead));
50531+ atomic_read_unchecked(&fscache_n_object_alloc),
50532+ atomic_read_unchecked(&fscache_n_object_no_alloc),
50533+ atomic_read_unchecked(&fscache_n_object_avail),
50534+ atomic_read_unchecked(&fscache_n_object_dead));
50535 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
50536- atomic_read(&fscache_n_checkaux_none),
50537- atomic_read(&fscache_n_checkaux_okay),
50538- atomic_read(&fscache_n_checkaux_update),
50539- atomic_read(&fscache_n_checkaux_obsolete));
50540+ atomic_read_unchecked(&fscache_n_checkaux_none),
50541+ atomic_read_unchecked(&fscache_n_checkaux_okay),
50542+ atomic_read_unchecked(&fscache_n_checkaux_update),
50543+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
50544
50545 seq_printf(m, "Pages : mrk=%u unc=%u\n",
50546- atomic_read(&fscache_n_marks),
50547- atomic_read(&fscache_n_uncaches));
50548+ atomic_read_unchecked(&fscache_n_marks),
50549+ atomic_read_unchecked(&fscache_n_uncaches));
50550
50551 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
50552 " oom=%u\n",
50553- atomic_read(&fscache_n_acquires),
50554- atomic_read(&fscache_n_acquires_null),
50555- atomic_read(&fscache_n_acquires_no_cache),
50556- atomic_read(&fscache_n_acquires_ok),
50557- atomic_read(&fscache_n_acquires_nobufs),
50558- atomic_read(&fscache_n_acquires_oom));
50559+ atomic_read_unchecked(&fscache_n_acquires),
50560+ atomic_read_unchecked(&fscache_n_acquires_null),
50561+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
50562+ atomic_read_unchecked(&fscache_n_acquires_ok),
50563+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
50564+ atomic_read_unchecked(&fscache_n_acquires_oom));
50565
50566 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
50567- atomic_read(&fscache_n_object_lookups),
50568- atomic_read(&fscache_n_object_lookups_negative),
50569- atomic_read(&fscache_n_object_lookups_positive),
50570- atomic_read(&fscache_n_object_lookups_timed_out),
50571- atomic_read(&fscache_n_object_created));
50572+ atomic_read_unchecked(&fscache_n_object_lookups),
50573+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
50574+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
50575+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out),
50576+ atomic_read_unchecked(&fscache_n_object_created));
50577
50578 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
50579- atomic_read(&fscache_n_updates),
50580- atomic_read(&fscache_n_updates_null),
50581- atomic_read(&fscache_n_updates_run));
50582+ atomic_read_unchecked(&fscache_n_updates),
50583+ atomic_read_unchecked(&fscache_n_updates_null),
50584+ atomic_read_unchecked(&fscache_n_updates_run));
50585
50586 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
50587- atomic_read(&fscache_n_relinquishes),
50588- atomic_read(&fscache_n_relinquishes_null),
50589- atomic_read(&fscache_n_relinquishes_waitcrt),
50590- atomic_read(&fscache_n_relinquishes_retire));
50591+ atomic_read_unchecked(&fscache_n_relinquishes),
50592+ atomic_read_unchecked(&fscache_n_relinquishes_null),
50593+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
50594+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
50595
50596 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
50597- atomic_read(&fscache_n_attr_changed),
50598- atomic_read(&fscache_n_attr_changed_ok),
50599- atomic_read(&fscache_n_attr_changed_nobufs),
50600- atomic_read(&fscache_n_attr_changed_nomem),
50601- atomic_read(&fscache_n_attr_changed_calls));
50602+ atomic_read_unchecked(&fscache_n_attr_changed),
50603+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
50604+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
50605+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
50606+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
50607
50608 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
50609- atomic_read(&fscache_n_allocs),
50610- atomic_read(&fscache_n_allocs_ok),
50611- atomic_read(&fscache_n_allocs_wait),
50612- atomic_read(&fscache_n_allocs_nobufs),
50613- atomic_read(&fscache_n_allocs_intr));
50614+ atomic_read_unchecked(&fscache_n_allocs),
50615+ atomic_read_unchecked(&fscache_n_allocs_ok),
50616+ atomic_read_unchecked(&fscache_n_allocs_wait),
50617+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
50618+ atomic_read_unchecked(&fscache_n_allocs_intr));
50619 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
50620- atomic_read(&fscache_n_alloc_ops),
50621- atomic_read(&fscache_n_alloc_op_waits),
50622- atomic_read(&fscache_n_allocs_object_dead));
50623+ atomic_read_unchecked(&fscache_n_alloc_ops),
50624+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
50625+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
50626
50627 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
50628 " int=%u oom=%u\n",
50629- atomic_read(&fscache_n_retrievals),
50630- atomic_read(&fscache_n_retrievals_ok),
50631- atomic_read(&fscache_n_retrievals_wait),
50632- atomic_read(&fscache_n_retrievals_nodata),
50633- atomic_read(&fscache_n_retrievals_nobufs),
50634- atomic_read(&fscache_n_retrievals_intr),
50635- atomic_read(&fscache_n_retrievals_nomem));
50636+ atomic_read_unchecked(&fscache_n_retrievals),
50637+ atomic_read_unchecked(&fscache_n_retrievals_ok),
50638+ atomic_read_unchecked(&fscache_n_retrievals_wait),
50639+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
50640+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
50641+ atomic_read_unchecked(&fscache_n_retrievals_intr),
50642+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
50643 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
50644- atomic_read(&fscache_n_retrieval_ops),
50645- atomic_read(&fscache_n_retrieval_op_waits),
50646- atomic_read(&fscache_n_retrievals_object_dead));
50647+ atomic_read_unchecked(&fscache_n_retrieval_ops),
50648+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
50649+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
50650
50651 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
50652- atomic_read(&fscache_n_stores),
50653- atomic_read(&fscache_n_stores_ok),
50654- atomic_read(&fscache_n_stores_again),
50655- atomic_read(&fscache_n_stores_nobufs),
50656- atomic_read(&fscache_n_stores_oom));
50657+ atomic_read_unchecked(&fscache_n_stores),
50658+ atomic_read_unchecked(&fscache_n_stores_ok),
50659+ atomic_read_unchecked(&fscache_n_stores_again),
50660+ atomic_read_unchecked(&fscache_n_stores_nobufs),
50661+ atomic_read_unchecked(&fscache_n_stores_oom));
50662 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
50663- atomic_read(&fscache_n_store_ops),
50664- atomic_read(&fscache_n_store_calls),
50665- atomic_read(&fscache_n_store_pages),
50666- atomic_read(&fscache_n_store_radix_deletes),
50667- atomic_read(&fscache_n_store_pages_over_limit));
50668+ atomic_read_unchecked(&fscache_n_store_ops),
50669+ atomic_read_unchecked(&fscache_n_store_calls),
50670+ atomic_read_unchecked(&fscache_n_store_pages),
50671+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
50672+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
50673
50674 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
50675- atomic_read(&fscache_n_store_vmscan_not_storing),
50676- atomic_read(&fscache_n_store_vmscan_gone),
50677- atomic_read(&fscache_n_store_vmscan_busy),
50678- atomic_read(&fscache_n_store_vmscan_cancelled));
50679+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
50680+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
50681+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
50682+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
50683
50684 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
50685- atomic_read(&fscache_n_op_pend),
50686- atomic_read(&fscache_n_op_run),
50687- atomic_read(&fscache_n_op_enqueue),
50688- atomic_read(&fscache_n_op_cancelled),
50689- atomic_read(&fscache_n_op_rejected));
50690+ atomic_read_unchecked(&fscache_n_op_pend),
50691+ atomic_read_unchecked(&fscache_n_op_run),
50692+ atomic_read_unchecked(&fscache_n_op_enqueue),
50693+ atomic_read_unchecked(&fscache_n_op_cancelled),
50694+ atomic_read_unchecked(&fscache_n_op_rejected));
50695 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
50696- atomic_read(&fscache_n_op_deferred_release),
50697- atomic_read(&fscache_n_op_release),
50698- atomic_read(&fscache_n_op_gc));
50699+ atomic_read_unchecked(&fscache_n_op_deferred_release),
50700+ atomic_read_unchecked(&fscache_n_op_release),
50701+ atomic_read_unchecked(&fscache_n_op_gc));
50702
50703 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
50704 atomic_read(&fscache_n_cop_alloc_object),
50705diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
50706index de792dc..448b532 100644
50707--- a/fs/fuse/cuse.c
50708+++ b/fs/fuse/cuse.c
50709@@ -576,10 +576,12 @@ static int __init cuse_init(void)
50710 INIT_LIST_HEAD(&cuse_conntbl[i]);
50711
50712 /* inherit and extend fuse_dev_operations */
50713- cuse_channel_fops = fuse_dev_operations;
50714- cuse_channel_fops.owner = THIS_MODULE;
50715- cuse_channel_fops.open = cuse_channel_open;
50716- cuse_channel_fops.release = cuse_channel_release;
50717+ pax_open_kernel();
50718+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
50719+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
50720+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
50721+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
50722+ pax_close_kernel();
50723
50724 cuse_class = class_create(THIS_MODULE, "cuse");
50725 if (IS_ERR(cuse_class))
50726diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
50727index 1facb39..7f48557 100644
50728--- a/fs/fuse/dev.c
50729+++ b/fs/fuse/dev.c
50730@@ -885,7 +885,7 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50731 {
50732 struct fuse_notify_inval_entry_out outarg;
50733 int err = -EINVAL;
50734- char buf[FUSE_NAME_MAX+1];
50735+ char *buf = NULL;
50736 struct qstr name;
50737
50738 if (size < sizeof(outarg))
50739@@ -899,6 +899,11 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50740 if (outarg.namelen > FUSE_NAME_MAX)
50741 goto err;
50742
50743+ err = -ENOMEM;
50744+ buf = kmalloc(FUSE_NAME_MAX+1, GFP_KERNEL);
50745+ if (!buf)
50746+ goto err;
50747+
50748 err = -EINVAL;
50749 if (size != sizeof(outarg) + outarg.namelen + 1)
50750 goto err;
50751@@ -914,17 +919,15 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50752
50753 down_read(&fc->killsb);
50754 err = -ENOENT;
50755- if (!fc->sb)
50756- goto err_unlock;
50757-
50758- err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
50759-
50760-err_unlock:
50761+ if (fc->sb)
50762+ err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
50763 up_read(&fc->killsb);
50764+ kfree(buf);
50765 return err;
50766
50767 err:
50768 fuse_copy_finish(cs);
50769+ kfree(buf);
50770 return err;
50771 }
50772
50773diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
50774index 4787ae6..73efff7 100644
50775--- a/fs/fuse/dir.c
50776+++ b/fs/fuse/dir.c
50777@@ -1127,7 +1127,7 @@ static char *read_link(struct dentry *dentry)
50778 return link;
50779 }
50780
50781-static void free_link(char *link)
50782+static void free_link(const char *link)
50783 {
50784 if (!IS_ERR(link))
50785 free_page((unsigned long) link);
50786diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
50787index 247436c..e650ccb 100644
50788--- a/fs/gfs2/ops_inode.c
50789+++ b/fs/gfs2/ops_inode.c
50790@@ -752,6 +752,8 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
50791 unsigned int x;
50792 int error;
50793
50794+ pax_track_stack();
50795+
50796 if (ndentry->d_inode) {
50797 nip = GFS2_I(ndentry->d_inode);
50798 if (ip == nip)
50799diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
50800index 4463297..4fed53b 100644
50801--- a/fs/gfs2/sys.c
50802+++ b/fs/gfs2/sys.c
50803@@ -49,7 +49,7 @@ static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr,
50804 return a->store ? a->store(sdp, buf, len) : len;
50805 }
50806
50807-static struct sysfs_ops gfs2_attr_ops = {
50808+static const struct sysfs_ops gfs2_attr_ops = {
50809 .show = gfs2_attr_show,
50810 .store = gfs2_attr_store,
50811 };
50812@@ -584,7 +584,7 @@ static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
50813 return 0;
50814 }
50815
50816-static struct kset_uevent_ops gfs2_uevent_ops = {
50817+static const struct kset_uevent_ops gfs2_uevent_ops = {
50818 .uevent = gfs2_uevent,
50819 };
50820
50821diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
50822index f6874ac..7cd98a8 100644
50823--- a/fs/hfsplus/catalog.c
50824+++ b/fs/hfsplus/catalog.c
50825@@ -157,6 +157,8 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
50826 int err;
50827 u16 type;
50828
50829+ pax_track_stack();
50830+
50831 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
50832 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
50833 if (err)
50834@@ -186,6 +188,8 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir, struct qstr *str, struct ino
50835 int entry_size;
50836 int err;
50837
50838+ pax_track_stack();
50839+
50840 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n", str->name, cnid, inode->i_nlink);
50841 sb = dir->i_sb;
50842 hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
50843@@ -318,6 +322,8 @@ int hfsplus_rename_cat(u32 cnid,
50844 int entry_size, type;
50845 int err = 0;
50846
50847+ pax_track_stack();
50848+
50849 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", cnid, src_dir->i_ino, src_name->name,
50850 dst_dir->i_ino, dst_name->name);
50851 sb = src_dir->i_sb;
50852diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
50853index 5f40236..dac3421 100644
50854--- a/fs/hfsplus/dir.c
50855+++ b/fs/hfsplus/dir.c
50856@@ -121,6 +121,8 @@ static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
50857 struct hfsplus_readdir_data *rd;
50858 u16 type;
50859
50860+ pax_track_stack();
50861+
50862 if (filp->f_pos >= inode->i_size)
50863 return 0;
50864
50865diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
50866index 1bcf597..905a251 100644
50867--- a/fs/hfsplus/inode.c
50868+++ b/fs/hfsplus/inode.c
50869@@ -399,6 +399,8 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
50870 int res = 0;
50871 u16 type;
50872
50873+ pax_track_stack();
50874+
50875 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
50876
50877 HFSPLUS_I(inode).dev = 0;
50878@@ -461,6 +463,8 @@ int hfsplus_cat_write_inode(struct inode *inode)
50879 struct hfs_find_data fd;
50880 hfsplus_cat_entry entry;
50881
50882+ pax_track_stack();
50883+
50884 if (HFSPLUS_IS_RSRC(inode))
50885 main_inode = HFSPLUS_I(inode).rsrc_inode;
50886
50887diff --git a/fs/hfsplus/ioctl.c b/fs/hfsplus/ioctl.c
50888index f457d2c..7ef4ad5 100644
50889--- a/fs/hfsplus/ioctl.c
50890+++ b/fs/hfsplus/ioctl.c
50891@@ -101,6 +101,8 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name,
50892 struct hfsplus_cat_file *file;
50893 int res;
50894
50895+ pax_track_stack();
50896+
50897 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
50898 return -EOPNOTSUPP;
50899
50900@@ -143,6 +145,8 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
50901 struct hfsplus_cat_file *file;
50902 ssize_t res = 0;
50903
50904+ pax_track_stack();
50905+
50906 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
50907 return -EOPNOTSUPP;
50908
50909diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
50910index 43022f3..7298079 100644
50911--- a/fs/hfsplus/super.c
50912+++ b/fs/hfsplus/super.c
50913@@ -312,6 +312,8 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
50914 struct nls_table *nls = NULL;
50915 int err = -EINVAL;
50916
50917+ pax_track_stack();
50918+
50919 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
50920 if (!sbi)
50921 return -ENOMEM;
50922diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
50923index 87a1258..5694d91 100644
50924--- a/fs/hugetlbfs/inode.c
50925+++ b/fs/hugetlbfs/inode.c
50926@@ -909,7 +909,7 @@ static struct file_system_type hugetlbfs_fs_type = {
50927 .kill_sb = kill_litter_super,
50928 };
50929
50930-static struct vfsmount *hugetlbfs_vfsmount;
50931+struct vfsmount *hugetlbfs_vfsmount;
50932
50933 static int can_do_hugetlb_shm(void)
50934 {
50935diff --git a/fs/ioctl.c b/fs/ioctl.c
50936index 6c75110..19d2c3c 100644
50937--- a/fs/ioctl.c
50938+++ b/fs/ioctl.c
50939@@ -97,7 +97,7 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,
50940 u64 phys, u64 len, u32 flags)
50941 {
50942 struct fiemap_extent extent;
50943- struct fiemap_extent *dest = fieinfo->fi_extents_start;
50944+ struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
50945
50946 /* only count the extents */
50947 if (fieinfo->fi_extents_max == 0) {
50948@@ -207,7 +207,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
50949
50950 fieinfo.fi_flags = fiemap.fm_flags;
50951 fieinfo.fi_extents_max = fiemap.fm_extent_count;
50952- fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap));
50953+ fieinfo.fi_extents_start = (struct fiemap_extent __user *)(arg + sizeof(fiemap));
50954
50955 if (fiemap.fm_extent_count != 0 &&
50956 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
50957@@ -220,7 +220,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
50958 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
50959 fiemap.fm_flags = fieinfo.fi_flags;
50960 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
50961- if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap)))
50962+ if (copy_to_user((__force char __user *)arg, &fiemap, sizeof(fiemap)))
50963 error = -EFAULT;
50964
50965 return error;
50966diff --git a/fs/jbd/checkpoint.c b/fs/jbd/checkpoint.c
50967index b0435dd..81ee0be 100644
50968--- a/fs/jbd/checkpoint.c
50969+++ b/fs/jbd/checkpoint.c
50970@@ -348,6 +348,8 @@ int log_do_checkpoint(journal_t *journal)
50971 tid_t this_tid;
50972 int result;
50973
50974+ pax_track_stack();
50975+
50976 jbd_debug(1, "Start checkpoint\n");
50977
50978 /*
50979diff --git a/fs/jffs2/compr_rtime.c b/fs/jffs2/compr_rtime.c
50980index 546d153..736896c 100644
50981--- a/fs/jffs2/compr_rtime.c
50982+++ b/fs/jffs2/compr_rtime.c
50983@@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned char *data_in,
50984 int outpos = 0;
50985 int pos=0;
50986
50987+ pax_track_stack();
50988+
50989 memset(positions,0,sizeof(positions));
50990
50991 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
50992@@ -79,6 +81,8 @@ static int jffs2_rtime_decompress(unsigned char *data_in,
50993 int outpos = 0;
50994 int pos=0;
50995
50996+ pax_track_stack();
50997+
50998 memset(positions,0,sizeof(positions));
50999
51000 while (outpos<destlen) {
51001diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c
51002index 170d289..3254b98 100644
51003--- a/fs/jffs2/compr_rubin.c
51004+++ b/fs/jffs2/compr_rubin.c
51005@@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsigned char *data_in,
51006 int ret;
51007 uint32_t mysrclen, mydstlen;
51008
51009+ pax_track_stack();
51010+
51011 mysrclen = *sourcelen;
51012 mydstlen = *dstlen - 8;
51013
51014diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
51015index b47679b..00d65d3 100644
51016--- a/fs/jffs2/erase.c
51017+++ b/fs/jffs2/erase.c
51018@@ -434,7 +434,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
51019 struct jffs2_unknown_node marker = {
51020 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
51021 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
51022- .totlen = cpu_to_je32(c->cleanmarker_size)
51023+ .totlen = cpu_to_je32(c->cleanmarker_size),
51024+ .hdr_crc = cpu_to_je32(0)
51025 };
51026
51027 jffs2_prealloc_raw_node_refs(c, jeb, 1);
51028diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
51029index 5ef7bac..4fd1e3c 100644
51030--- a/fs/jffs2/wbuf.c
51031+++ b/fs/jffs2/wbuf.c
51032@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
51033 {
51034 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
51035 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
51036- .totlen = constant_cpu_to_je32(8)
51037+ .totlen = constant_cpu_to_je32(8),
51038+ .hdr_crc = constant_cpu_to_je32(0)
51039 };
51040
51041 /*
51042diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
51043index 082e844..52012a1 100644
51044--- a/fs/jffs2/xattr.c
51045+++ b/fs/jffs2/xattr.c
51046@@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
51047
51048 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
51049
51050+ pax_track_stack();
51051+
51052 /* Phase.1 : Merge same xref */
51053 for (i=0; i < XREF_TMPHASH_SIZE; i++)
51054 xref_tmphash[i] = NULL;
51055diff --git a/fs/jfs/super.c b/fs/jfs/super.c
51056index 2234c73..f6e6e6b 100644
51057--- a/fs/jfs/super.c
51058+++ b/fs/jfs/super.c
51059@@ -793,7 +793,7 @@ static int __init init_jfs_fs(void)
51060
51061 jfs_inode_cachep =
51062 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
51063- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
51064+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
51065 init_once);
51066 if (jfs_inode_cachep == NULL)
51067 return -ENOMEM;
51068diff --git a/fs/libfs.c b/fs/libfs.c
51069index ba36e93..3153fce 100644
51070--- a/fs/libfs.c
51071+++ b/fs/libfs.c
51072@@ -157,12 +157,20 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
51073
51074 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
51075 struct dentry *next;
51076+ char d_name[sizeof(next->d_iname)];
51077+ const unsigned char *name;
51078+
51079 next = list_entry(p, struct dentry, d_u.d_child);
51080 if (d_unhashed(next) || !next->d_inode)
51081 continue;
51082
51083 spin_unlock(&dcache_lock);
51084- if (filldir(dirent, next->d_name.name,
51085+ name = next->d_name.name;
51086+ if (name == next->d_iname) {
51087+ memcpy(d_name, name, next->d_name.len);
51088+ name = d_name;
51089+ }
51090+ if (filldir(dirent, name,
51091 next->d_name.len, filp->f_pos,
51092 next->d_inode->i_ino,
51093 dt_type(next->d_inode)) < 0)
51094diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
51095index c325a83..d15b07b 100644
51096--- a/fs/lockd/clntproc.c
51097+++ b/fs/lockd/clntproc.c
51098@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
51099 /*
51100 * Cookie counter for NLM requests
51101 */
51102-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
51103+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
51104
51105 void nlmclnt_next_cookie(struct nlm_cookie *c)
51106 {
51107- u32 cookie = atomic_inc_return(&nlm_cookie);
51108+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
51109
51110 memcpy(c->data, &cookie, 4);
51111 c->len=4;
51112@@ -621,6 +621,8 @@ nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl)
51113 struct nlm_rqst reqst, *req;
51114 int status;
51115
51116+ pax_track_stack();
51117+
51118 req = &reqst;
51119 memset(req, 0, sizeof(*req));
51120 locks_init_lock(&req->a_args.lock.fl);
51121diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
51122index 1a54ae1..6a16c27 100644
51123--- a/fs/lockd/svc.c
51124+++ b/fs/lockd/svc.c
51125@@ -43,7 +43,7 @@
51126
51127 static struct svc_program nlmsvc_program;
51128
51129-struct nlmsvc_binding * nlmsvc_ops;
51130+const struct nlmsvc_binding * nlmsvc_ops;
51131 EXPORT_SYMBOL_GPL(nlmsvc_ops);
51132
51133 static DEFINE_MUTEX(nlmsvc_mutex);
51134diff --git a/fs/locks.c b/fs/locks.c
51135index a8794f2..4041e55 100644
51136--- a/fs/locks.c
51137+++ b/fs/locks.c
51138@@ -145,10 +145,28 @@ static LIST_HEAD(blocked_list);
51139
51140 static struct kmem_cache *filelock_cache __read_mostly;
51141
51142+static void locks_init_lock_always(struct file_lock *fl)
51143+{
51144+ fl->fl_next = NULL;
51145+ fl->fl_fasync = NULL;
51146+ fl->fl_owner = NULL;
51147+ fl->fl_pid = 0;
51148+ fl->fl_nspid = NULL;
51149+ fl->fl_file = NULL;
51150+ fl->fl_flags = 0;
51151+ fl->fl_type = 0;
51152+ fl->fl_start = fl->fl_end = 0;
51153+}
51154+
51155 /* Allocate an empty lock structure. */
51156 static struct file_lock *locks_alloc_lock(void)
51157 {
51158- return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
51159+ struct file_lock *fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
51160+
51161+ if (fl)
51162+ locks_init_lock_always(fl);
51163+
51164+ return fl;
51165 }
51166
51167 void locks_release_private(struct file_lock *fl)
51168@@ -183,17 +201,9 @@ void locks_init_lock(struct file_lock *fl)
51169 INIT_LIST_HEAD(&fl->fl_link);
51170 INIT_LIST_HEAD(&fl->fl_block);
51171 init_waitqueue_head(&fl->fl_wait);
51172- fl->fl_next = NULL;
51173- fl->fl_fasync = NULL;
51174- fl->fl_owner = NULL;
51175- fl->fl_pid = 0;
51176- fl->fl_nspid = NULL;
51177- fl->fl_file = NULL;
51178- fl->fl_flags = 0;
51179- fl->fl_type = 0;
51180- fl->fl_start = fl->fl_end = 0;
51181 fl->fl_ops = NULL;
51182 fl->fl_lmops = NULL;
51183+ locks_init_lock_always(fl);
51184 }
51185
51186 EXPORT_SYMBOL(locks_init_lock);
51187@@ -2007,16 +2017,16 @@ void locks_remove_flock(struct file *filp)
51188 return;
51189
51190 if (filp->f_op && filp->f_op->flock) {
51191- struct file_lock fl = {
51192+ struct file_lock flock = {
51193 .fl_pid = current->tgid,
51194 .fl_file = filp,
51195 .fl_flags = FL_FLOCK,
51196 .fl_type = F_UNLCK,
51197 .fl_end = OFFSET_MAX,
51198 };
51199- filp->f_op->flock(filp, F_SETLKW, &fl);
51200- if (fl.fl_ops && fl.fl_ops->fl_release_private)
51201- fl.fl_ops->fl_release_private(&fl);
51202+ filp->f_op->flock(filp, F_SETLKW, &flock);
51203+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
51204+ flock.fl_ops->fl_release_private(&flock);
51205 }
51206
51207 lock_kernel();
51208diff --git a/fs/mbcache.c b/fs/mbcache.c
51209index ec88ff3..b843a82 100644
51210--- a/fs/mbcache.c
51211+++ b/fs/mbcache.c
51212@@ -266,9 +266,9 @@ mb_cache_create(const char *name, struct mb_cache_op *cache_op,
51213 if (!cache)
51214 goto fail;
51215 cache->c_name = name;
51216- cache->c_op.free = NULL;
51217+ *(void **)&cache->c_op.free = NULL;
51218 if (cache_op)
51219- cache->c_op.free = cache_op->free;
51220+ *(void **)&cache->c_op.free = cache_op->free;
51221 atomic_set(&cache->c_entry_count, 0);
51222 cache->c_bucket_bits = bucket_bits;
51223 #ifdef MB_CACHE_INDEXES_COUNT
51224diff --git a/fs/namei.c b/fs/namei.c
51225index b0afbd4..8d065a1 100644
51226--- a/fs/namei.c
51227+++ b/fs/namei.c
51228@@ -224,6 +224,14 @@ int generic_permission(struct inode *inode, int mask,
51229 return ret;
51230
51231 /*
51232+ * Searching includes executable on directories, else just read.
51233+ */
51234+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
51235+ if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
51236+ if (capable(CAP_DAC_READ_SEARCH))
51237+ return 0;
51238+
51239+ /*
51240 * Read/write DACs are always overridable.
51241 * Executable DACs are overridable if at least one exec bit is set.
51242 */
51243@@ -231,14 +239,6 @@ int generic_permission(struct inode *inode, int mask,
51244 if (capable(CAP_DAC_OVERRIDE))
51245 return 0;
51246
51247- /*
51248- * Searching includes executable on directories, else just read.
51249- */
51250- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
51251- if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
51252- if (capable(CAP_DAC_READ_SEARCH))
51253- return 0;
51254-
51255 return -EACCES;
51256 }
51257
51258@@ -458,7 +458,8 @@ static int exec_permission_lite(struct inode *inode)
51259 if (!ret)
51260 goto ok;
51261
51262- if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH))
51263+ if (capable_nolog(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH) ||
51264+ capable(CAP_DAC_OVERRIDE))
51265 goto ok;
51266
51267 return ret;
51268@@ -638,7 +639,7 @@ static __always_inline int __do_follow_link(struct path *path, struct nameidata
51269 cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
51270 error = PTR_ERR(cookie);
51271 if (!IS_ERR(cookie)) {
51272- char *s = nd_get_link(nd);
51273+ const char *s = nd_get_link(nd);
51274 error = 0;
51275 if (s)
51276 error = __vfs_follow_link(nd, s);
51277@@ -669,6 +670,13 @@ static inline int do_follow_link(struct path *path, struct nameidata *nd)
51278 err = security_inode_follow_link(path->dentry, nd);
51279 if (err)
51280 goto loop;
51281+
51282+ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
51283+ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
51284+ err = -EACCES;
51285+ goto loop;
51286+ }
51287+
51288 current->link_count++;
51289 current->total_link_count++;
51290 nd->depth++;
51291@@ -1016,11 +1024,19 @@ return_reval:
51292 break;
51293 }
51294 return_base:
51295+ if (!(nd->flags & (LOOKUP_CONTINUE | LOOKUP_PARENT)) &&
51296+ !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
51297+ path_put(&nd->path);
51298+ return -ENOENT;
51299+ }
51300 return 0;
51301 out_dput:
51302 path_put_conditional(&next, nd);
51303 break;
51304 }
51305+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
51306+ err = -ENOENT;
51307+
51308 path_put(&nd->path);
51309 return_err:
51310 return err;
51311@@ -1091,13 +1107,20 @@ static int do_path_lookup(int dfd, const char *name,
51312 int retval = path_init(dfd, name, flags, nd);
51313 if (!retval)
51314 retval = path_walk(name, nd);
51315- if (unlikely(!retval && !audit_dummy_context() && nd->path.dentry &&
51316- nd->path.dentry->d_inode))
51317- audit_inode(name, nd->path.dentry);
51318+
51319+ if (likely(!retval)) {
51320+ if (nd->path.dentry && nd->path.dentry->d_inode) {
51321+ if (*name != '/' && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
51322+ retval = -ENOENT;
51323+ if (!audit_dummy_context())
51324+ audit_inode(name, nd->path.dentry);
51325+ }
51326+ }
51327 if (nd->root.mnt) {
51328 path_put(&nd->root);
51329 nd->root.mnt = NULL;
51330 }
51331+
51332 return retval;
51333 }
51334
51335@@ -1576,6 +1599,20 @@ int may_open(struct path *path, int acc_mode, int flag)
51336 if (error)
51337 goto err_out;
51338
51339+
51340+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
51341+ error = -EPERM;
51342+ goto err_out;
51343+ }
51344+ if (gr_handle_rawio(inode)) {
51345+ error = -EPERM;
51346+ goto err_out;
51347+ }
51348+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode)) {
51349+ error = -EACCES;
51350+ goto err_out;
51351+ }
51352+
51353 if (flag & O_TRUNC) {
51354 error = get_write_access(inode);
51355 if (error)
51356@@ -1620,6 +1657,17 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
51357 {
51358 int error;
51359 struct dentry *dir = nd->path.dentry;
51360+ int acc_mode = ACC_MODE(flag);
51361+
51362+ if (flag & O_TRUNC)
51363+ acc_mode |= MAY_WRITE;
51364+ if (flag & O_APPEND)
51365+ acc_mode |= MAY_APPEND;
51366+
51367+ if (!gr_acl_handle_creat(path->dentry, dir, nd->path.mnt, flag, acc_mode, mode)) {
51368+ error = -EACCES;
51369+ goto out_unlock;
51370+ }
51371
51372 if (!IS_POSIXACL(dir->d_inode))
51373 mode &= ~current_umask();
51374@@ -1627,6 +1675,8 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
51375 if (error)
51376 goto out_unlock;
51377 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
51378+ if (!error)
51379+ gr_handle_create(path->dentry, nd->path.mnt);
51380 out_unlock:
51381 mutex_unlock(&dir->d_inode->i_mutex);
51382 dput(nd->path.dentry);
51383@@ -1709,6 +1759,22 @@ struct file *do_filp_open(int dfd, const char *pathname,
51384 &nd, flag);
51385 if (error)
51386 return ERR_PTR(error);
51387+
51388+ if (gr_handle_rofs_blockwrite(nd.path.dentry, nd.path.mnt, acc_mode)) {
51389+ error = -EPERM;
51390+ goto exit;
51391+ }
51392+
51393+ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
51394+ error = -EPERM;
51395+ goto exit;
51396+ }
51397+
51398+ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, acc_mode)) {
51399+ error = -EACCES;
51400+ goto exit;
51401+ }
51402+
51403 goto ok;
51404 }
51405
51406@@ -1795,6 +1861,19 @@ do_last:
51407 /*
51408 * It already exists.
51409 */
51410+
51411+ if (!gr_acl_handle_hidden_file(path.dentry, path.mnt)) {
51412+ error = -ENOENT;
51413+ goto exit_mutex_unlock;
51414+ }
51415+
51416+ /* only check if O_CREAT is specified, all other checks need
51417+ to go into may_open */
51418+ if (gr_handle_fifo(path.dentry, path.mnt, dir, flag, acc_mode)) {
51419+ error = -EACCES;
51420+ goto exit_mutex_unlock;
51421+ }
51422+
51423 mutex_unlock(&dir->d_inode->i_mutex);
51424 audit_inode(pathname, path.dentry);
51425
51426@@ -1887,6 +1966,13 @@ do_link:
51427 error = security_inode_follow_link(path.dentry, &nd);
51428 if (error)
51429 goto exit_dput;
51430+
51431+ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
51432+ path.dentry, nd.path.mnt)) {
51433+ error = -EACCES;
51434+ goto exit_dput;
51435+ }
51436+
51437 error = __do_follow_link(&path, &nd);
51438 if (error) {
51439 /* Does someone understand code flow here? Or it is only
51440@@ -1984,6 +2070,10 @@ struct dentry *lookup_create(struct nameidata *nd, int is_dir)
51441 }
51442 return dentry;
51443 eexist:
51444+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
51445+ dput(dentry);
51446+ return ERR_PTR(-ENOENT);
51447+ }
51448 dput(dentry);
51449 dentry = ERR_PTR(-EEXIST);
51450 fail:
51451@@ -2061,6 +2151,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
51452 error = may_mknod(mode);
51453 if (error)
51454 goto out_dput;
51455+
51456+ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
51457+ error = -EPERM;
51458+ goto out_dput;
51459+ }
51460+
51461+ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
51462+ error = -EACCES;
51463+ goto out_dput;
51464+ }
51465+
51466 error = mnt_want_write(nd.path.mnt);
51467 if (error)
51468 goto out_dput;
51469@@ -2081,6 +2182,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
51470 }
51471 out_drop_write:
51472 mnt_drop_write(nd.path.mnt);
51473+
51474+ if (!error)
51475+ gr_handle_create(dentry, nd.path.mnt);
51476 out_dput:
51477 dput(dentry);
51478 out_unlock:
51479@@ -2134,6 +2238,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
51480 if (IS_ERR(dentry))
51481 goto out_unlock;
51482
51483+ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
51484+ error = -EACCES;
51485+ goto out_dput;
51486+ }
51487+
51488 if (!IS_POSIXACL(nd.path.dentry->d_inode))
51489 mode &= ~current_umask();
51490 error = mnt_want_write(nd.path.mnt);
51491@@ -2145,6 +2254,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
51492 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
51493 out_drop_write:
51494 mnt_drop_write(nd.path.mnt);
51495+
51496+ if (!error)
51497+ gr_handle_create(dentry, nd.path.mnt);
51498+
51499 out_dput:
51500 dput(dentry);
51501 out_unlock:
51502@@ -2226,6 +2339,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
51503 char * name;
51504 struct dentry *dentry;
51505 struct nameidata nd;
51506+ ino_t saved_ino = 0;
51507+ dev_t saved_dev = 0;
51508
51509 error = user_path_parent(dfd, pathname, &nd, &name);
51510 if (error)
51511@@ -2250,6 +2365,17 @@ static long do_rmdir(int dfd, const char __user *pathname)
51512 error = PTR_ERR(dentry);
51513 if (IS_ERR(dentry))
51514 goto exit2;
51515+
51516+ if (dentry->d_inode != NULL) {
51517+ saved_ino = dentry->d_inode->i_ino;
51518+ saved_dev = gr_get_dev_from_dentry(dentry);
51519+
51520+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
51521+ error = -EACCES;
51522+ goto exit3;
51523+ }
51524+ }
51525+
51526 error = mnt_want_write(nd.path.mnt);
51527 if (error)
51528 goto exit3;
51529@@ -2257,6 +2383,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
51530 if (error)
51531 goto exit4;
51532 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
51533+ if (!error && (saved_dev || saved_ino))
51534+ gr_handle_delete(saved_ino, saved_dev);
51535 exit4:
51536 mnt_drop_write(nd.path.mnt);
51537 exit3:
51538@@ -2318,6 +2446,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51539 struct dentry *dentry;
51540 struct nameidata nd;
51541 struct inode *inode = NULL;
51542+ ino_t saved_ino = 0;
51543+ dev_t saved_dev = 0;
51544
51545 error = user_path_parent(dfd, pathname, &nd, &name);
51546 if (error)
51547@@ -2337,8 +2467,19 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51548 if (nd.last.name[nd.last.len])
51549 goto slashes;
51550 inode = dentry->d_inode;
51551- if (inode)
51552+ if (inode) {
51553+ if (inode->i_nlink <= 1) {
51554+ saved_ino = inode->i_ino;
51555+ saved_dev = gr_get_dev_from_dentry(dentry);
51556+ }
51557+
51558 atomic_inc(&inode->i_count);
51559+
51560+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
51561+ error = -EACCES;
51562+ goto exit2;
51563+ }
51564+ }
51565 error = mnt_want_write(nd.path.mnt);
51566 if (error)
51567 goto exit2;
51568@@ -2346,6 +2487,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51569 if (error)
51570 goto exit3;
51571 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
51572+ if (!error && (saved_ino || saved_dev))
51573+ gr_handle_delete(saved_ino, saved_dev);
51574 exit3:
51575 mnt_drop_write(nd.path.mnt);
51576 exit2:
51577@@ -2424,6 +2567,11 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
51578 if (IS_ERR(dentry))
51579 goto out_unlock;
51580
51581+ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
51582+ error = -EACCES;
51583+ goto out_dput;
51584+ }
51585+
51586 error = mnt_want_write(nd.path.mnt);
51587 if (error)
51588 goto out_dput;
51589@@ -2431,6 +2579,8 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
51590 if (error)
51591 goto out_drop_write;
51592 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
51593+ if (!error)
51594+ gr_handle_create(dentry, nd.path.mnt);
51595 out_drop_write:
51596 mnt_drop_write(nd.path.mnt);
51597 out_dput:
51598@@ -2524,6 +2674,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
51599 error = PTR_ERR(new_dentry);
51600 if (IS_ERR(new_dentry))
51601 goto out_unlock;
51602+
51603+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
51604+ old_path.dentry->d_inode,
51605+ old_path.dentry->d_inode->i_mode, to)) {
51606+ error = -EACCES;
51607+ goto out_dput;
51608+ }
51609+
51610+ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
51611+ old_path.dentry, old_path.mnt, to)) {
51612+ error = -EACCES;
51613+ goto out_dput;
51614+ }
51615+
51616 error = mnt_want_write(nd.path.mnt);
51617 if (error)
51618 goto out_dput;
51619@@ -2531,6 +2695,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
51620 if (error)
51621 goto out_drop_write;
51622 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
51623+ if (!error)
51624+ gr_handle_create(new_dentry, nd.path.mnt);
51625 out_drop_write:
51626 mnt_drop_write(nd.path.mnt);
51627 out_dput:
51628@@ -2708,6 +2874,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51629 char *to;
51630 int error;
51631
51632+ pax_track_stack();
51633+
51634 error = user_path_parent(olddfd, oldname, &oldnd, &from);
51635 if (error)
51636 goto exit;
51637@@ -2764,6 +2932,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51638 if (new_dentry == trap)
51639 goto exit5;
51640
51641+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
51642+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
51643+ to);
51644+ if (error)
51645+ goto exit5;
51646+
51647 error = mnt_want_write(oldnd.path.mnt);
51648 if (error)
51649 goto exit5;
51650@@ -2773,6 +2947,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51651 goto exit6;
51652 error = vfs_rename(old_dir->d_inode, old_dentry,
51653 new_dir->d_inode, new_dentry);
51654+ if (!error)
51655+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
51656+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
51657 exit6:
51658 mnt_drop_write(oldnd.path.mnt);
51659 exit5:
51660@@ -2798,6 +2975,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
51661
51662 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
51663 {
51664+ char tmpbuf[64];
51665+ const char *newlink;
51666 int len;
51667
51668 len = PTR_ERR(link);
51669@@ -2807,7 +2986,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
51670 len = strlen(link);
51671 if (len > (unsigned) buflen)
51672 len = buflen;
51673- if (copy_to_user(buffer, link, len))
51674+
51675+ if (len < sizeof(tmpbuf)) {
51676+ memcpy(tmpbuf, link, len);
51677+ newlink = tmpbuf;
51678+ } else
51679+ newlink = link;
51680+
51681+ if (copy_to_user(buffer, newlink, len))
51682 len = -EFAULT;
51683 out:
51684 return len;
51685diff --git a/fs/namespace.c b/fs/namespace.c
51686index 2beb0fb..11a95a5 100644
51687--- a/fs/namespace.c
51688+++ b/fs/namespace.c
51689@@ -1083,6 +1083,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
51690 if (!(sb->s_flags & MS_RDONLY))
51691 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
51692 up_write(&sb->s_umount);
51693+
51694+ gr_log_remount(mnt->mnt_devname, retval);
51695+
51696 return retval;
51697 }
51698
51699@@ -1104,6 +1107,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
51700 security_sb_umount_busy(mnt);
51701 up_write(&namespace_sem);
51702 release_mounts(&umount_list);
51703+
51704+ gr_log_unmount(mnt->mnt_devname, retval);
51705+
51706 return retval;
51707 }
51708
51709@@ -1962,6 +1968,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
51710 if (retval)
51711 goto dput_out;
51712
51713+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
51714+ retval = -EPERM;
51715+ goto dput_out;
51716+ }
51717+
51718+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
51719+ retval = -EPERM;
51720+ goto dput_out;
51721+ }
51722+
51723 if (flags & MS_REMOUNT)
51724 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
51725 data_page);
51726@@ -1976,6 +1992,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
51727 dev_name, data_page);
51728 dput_out:
51729 path_put(&path);
51730+
51731+ gr_log_mount(dev_name, dir_name, retval);
51732+
51733 return retval;
51734 }
51735
51736@@ -2182,6 +2201,12 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
51737 goto out1;
51738 }
51739
51740+ if (gr_handle_chroot_pivot()) {
51741+ error = -EPERM;
51742+ path_put(&old);
51743+ goto out1;
51744+ }
51745+
51746 read_lock(&current->fs->lock);
51747 root = current->fs->root;
51748 path_get(&current->fs->root);
51749diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
51750index b8b5b30..2bd9ccb 100644
51751--- a/fs/ncpfs/dir.c
51752+++ b/fs/ncpfs/dir.c
51753@@ -275,6 +275,8 @@ __ncp_lookup_validate(struct dentry *dentry)
51754 int res, val = 0, len;
51755 __u8 __name[NCP_MAXPATHLEN + 1];
51756
51757+ pax_track_stack();
51758+
51759 parent = dget_parent(dentry);
51760 dir = parent->d_inode;
51761
51762@@ -799,6 +801,8 @@ static struct dentry *ncp_lookup(struct inode *dir, struct dentry *dentry, struc
51763 int error, res, len;
51764 __u8 __name[NCP_MAXPATHLEN + 1];
51765
51766+ pax_track_stack();
51767+
51768 lock_kernel();
51769 error = -EIO;
51770 if (!ncp_conn_valid(server))
51771@@ -883,10 +887,12 @@ int ncp_create_new(struct inode *dir, struct dentry *dentry, int mode,
51772 int error, result, len;
51773 int opmode;
51774 __u8 __name[NCP_MAXPATHLEN + 1];
51775-
51776+
51777 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
51778 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
51779
51780+ pax_track_stack();
51781+
51782 error = -EIO;
51783 lock_kernel();
51784 if (!ncp_conn_valid(server))
51785@@ -952,6 +958,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
51786 int error, len;
51787 __u8 __name[NCP_MAXPATHLEN + 1];
51788
51789+ pax_track_stack();
51790+
51791 DPRINTK("ncp_mkdir: making %s/%s\n",
51792 dentry->d_parent->d_name.name, dentry->d_name.name);
51793
51794@@ -960,6 +968,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
51795 if (!ncp_conn_valid(server))
51796 goto out;
51797
51798+ pax_track_stack();
51799+
51800 ncp_age_dentry(server, dentry);
51801 len = sizeof(__name);
51802 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
51803@@ -1114,6 +1124,8 @@ static int ncp_rename(struct inode *old_dir, struct dentry *old_dentry,
51804 int old_len, new_len;
51805 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
51806
51807+ pax_track_stack();
51808+
51809 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
51810 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
51811 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
51812diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
51813index cf98da1..da890a9 100644
51814--- a/fs/ncpfs/inode.c
51815+++ b/fs/ncpfs/inode.c
51816@@ -445,6 +445,8 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
51817 #endif
51818 struct ncp_entry_info finfo;
51819
51820+ pax_track_stack();
51821+
51822 data.wdog_pid = NULL;
51823 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
51824 if (!server)
51825diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
51826index bfaef7b..e9d03ca 100644
51827--- a/fs/nfs/inode.c
51828+++ b/fs/nfs/inode.c
51829@@ -156,7 +156,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
51830 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
51831 nfsi->attrtimeo_timestamp = jiffies;
51832
51833- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
51834+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
51835 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
51836 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
51837 else
51838@@ -973,16 +973,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
51839 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
51840 }
51841
51842-static atomic_long_t nfs_attr_generation_counter;
51843+static atomic_long_unchecked_t nfs_attr_generation_counter;
51844
51845 static unsigned long nfs_read_attr_generation_counter(void)
51846 {
51847- return atomic_long_read(&nfs_attr_generation_counter);
51848+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
51849 }
51850
51851 unsigned long nfs_inc_attr_generation_counter(void)
51852 {
51853- return atomic_long_inc_return(&nfs_attr_generation_counter);
51854+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
51855 }
51856
51857 void nfs_fattr_init(struct nfs_fattr *fattr)
51858diff --git a/fs/nfsd/lockd.c b/fs/nfsd/lockd.c
51859index cc2f505..f6a236f 100644
51860--- a/fs/nfsd/lockd.c
51861+++ b/fs/nfsd/lockd.c
51862@@ -66,7 +66,7 @@ nlm_fclose(struct file *filp)
51863 fput(filp);
51864 }
51865
51866-static struct nlmsvc_binding nfsd_nlm_ops = {
51867+static const struct nlmsvc_binding nfsd_nlm_ops = {
51868 .fopen = nlm_fopen, /* open file for locking */
51869 .fclose = nlm_fclose, /* close file */
51870 };
51871diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
51872index cfc3391..dcc083a 100644
51873--- a/fs/nfsd/nfs4state.c
51874+++ b/fs/nfsd/nfs4state.c
51875@@ -3459,6 +3459,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
51876 unsigned int cmd;
51877 int err;
51878
51879+ pax_track_stack();
51880+
51881 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
51882 (long long) lock->lk_offset,
51883 (long long) lock->lk_length);
51884diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
51885index 4a82a96..0d5fb49 100644
51886--- a/fs/nfsd/nfs4xdr.c
51887+++ b/fs/nfsd/nfs4xdr.c
51888@@ -1751,6 +1751,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
51889 struct nfsd4_compoundres *resp = rqstp->rq_resp;
51890 u32 minorversion = resp->cstate.minorversion;
51891
51892+ pax_track_stack();
51893+
51894 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
51895 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
51896 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
51897diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
51898index 2e09588..596421d 100644
51899--- a/fs/nfsd/vfs.c
51900+++ b/fs/nfsd/vfs.c
51901@@ -937,7 +937,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51902 } else {
51903 oldfs = get_fs();
51904 set_fs(KERNEL_DS);
51905- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
51906+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
51907 set_fs(oldfs);
51908 }
51909
51910@@ -1060,7 +1060,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51911
51912 /* Write the data. */
51913 oldfs = get_fs(); set_fs(KERNEL_DS);
51914- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
51915+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
51916 set_fs(oldfs);
51917 if (host_err < 0)
51918 goto out_nfserr;
51919@@ -1542,7 +1542,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
51920 */
51921
51922 oldfs = get_fs(); set_fs(KERNEL_DS);
51923- host_err = inode->i_op->readlink(dentry, buf, *lenp);
51924+ host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
51925 set_fs(oldfs);
51926
51927 if (host_err < 0)
51928diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
51929index f6af760..d0adf34 100644
51930--- a/fs/nilfs2/ioctl.c
51931+++ b/fs/nilfs2/ioctl.c
51932@@ -480,7 +480,7 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
51933 unsigned int cmd, void __user *argp)
51934 {
51935 struct nilfs_argv argv[5];
51936- const static size_t argsz[5] = {
51937+ static const size_t argsz[5] = {
51938 sizeof(struct nilfs_vdesc),
51939 sizeof(struct nilfs_period),
51940 sizeof(__u64),
51941@@ -522,6 +522,9 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
51942 if (argv[n].v_nmembs > nsegs * nilfs->ns_blocks_per_segment)
51943 goto out_free;
51944
51945+ if (argv[n].v_nmembs >= UINT_MAX / argv[n].v_size)
51946+ goto out_free;
51947+
51948 len = argv[n].v_size * argv[n].v_nmembs;
51949 base = (void __user *)(unsigned long)argv[n].v_base;
51950 if (len == 0) {
51951diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
51952index 7e54e52..9337248 100644
51953--- a/fs/notify/dnotify/dnotify.c
51954+++ b/fs/notify/dnotify/dnotify.c
51955@@ -173,7 +173,7 @@ static void dnotify_free_mark(struct fsnotify_mark_entry *entry)
51956 kmem_cache_free(dnotify_mark_entry_cache, dnentry);
51957 }
51958
51959-static struct fsnotify_ops dnotify_fsnotify_ops = {
51960+static const struct fsnotify_ops dnotify_fsnotify_ops = {
51961 .handle_event = dnotify_handle_event,
51962 .should_send_event = dnotify_should_send_event,
51963 .free_group_priv = NULL,
51964diff --git a/fs/notify/notification.c b/fs/notify/notification.c
51965index b8bf53b..c518688 100644
51966--- a/fs/notify/notification.c
51967+++ b/fs/notify/notification.c
51968@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
51969 * get set to 0 so it will never get 'freed'
51970 */
51971 static struct fsnotify_event q_overflow_event;
51972-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51973+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51974
51975 /**
51976 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
51977@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51978 */
51979 u32 fsnotify_get_cookie(void)
51980 {
51981- return atomic_inc_return(&fsnotify_sync_cookie);
51982+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
51983 }
51984 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
51985
51986diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
51987index 5a9e344..0f8cd28 100644
51988--- a/fs/ntfs/dir.c
51989+++ b/fs/ntfs/dir.c
51990@@ -1328,7 +1328,7 @@ find_next_index_buffer:
51991 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
51992 ~(s64)(ndir->itype.index.block_size - 1)));
51993 /* Bounds checks. */
51994- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51995+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51996 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
51997 "inode 0x%lx or driver bug.", vdir->i_ino);
51998 goto err_out;
51999diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
52000index 663c0e3..b6868e9 100644
52001--- a/fs/ntfs/file.c
52002+++ b/fs/ntfs/file.c
52003@@ -2243,6 +2243,6 @@ const struct inode_operations ntfs_file_inode_ops = {
52004 #endif /* NTFS_RW */
52005 };
52006
52007-const struct file_operations ntfs_empty_file_ops = {};
52008+const struct file_operations ntfs_empty_file_ops __read_only;
52009
52010-const struct inode_operations ntfs_empty_inode_ops = {};
52011+const struct inode_operations ntfs_empty_inode_ops __read_only;
52012diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
52013index 1cd2934..880b5d2 100644
52014--- a/fs/ocfs2/cluster/masklog.c
52015+++ b/fs/ocfs2/cluster/masklog.c
52016@@ -135,7 +135,7 @@ static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
52017 return mlog_mask_store(mlog_attr->mask, buf, count);
52018 }
52019
52020-static struct sysfs_ops mlog_attr_ops = {
52021+static const struct sysfs_ops mlog_attr_ops = {
52022 .show = mlog_show,
52023 .store = mlog_store,
52024 };
52025diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
52026index ac10f83..2cd2607 100644
52027--- a/fs/ocfs2/localalloc.c
52028+++ b/fs/ocfs2/localalloc.c
52029@@ -1188,7 +1188,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
52030 goto bail;
52031 }
52032
52033- atomic_inc(&osb->alloc_stats.moves);
52034+ atomic_inc_unchecked(&osb->alloc_stats.moves);
52035
52036 status = 0;
52037 bail:
52038diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
52039index f010b22..9f9ed34 100644
52040--- a/fs/ocfs2/namei.c
52041+++ b/fs/ocfs2/namei.c
52042@@ -1043,6 +1043,8 @@ static int ocfs2_rename(struct inode *old_dir,
52043 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
52044 struct ocfs2_dir_lookup_result target_insert = { NULL, };
52045
52046+ pax_track_stack();
52047+
52048 /* At some point it might be nice to break this function up a
52049 * bit. */
52050
52051diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
52052index d963d86..914cfbd 100644
52053--- a/fs/ocfs2/ocfs2.h
52054+++ b/fs/ocfs2/ocfs2.h
52055@@ -217,11 +217,11 @@ enum ocfs2_vol_state
52056
52057 struct ocfs2_alloc_stats
52058 {
52059- atomic_t moves;
52060- atomic_t local_data;
52061- atomic_t bitmap_data;
52062- atomic_t bg_allocs;
52063- atomic_t bg_extends;
52064+ atomic_unchecked_t moves;
52065+ atomic_unchecked_t local_data;
52066+ atomic_unchecked_t bitmap_data;
52067+ atomic_unchecked_t bg_allocs;
52068+ atomic_unchecked_t bg_extends;
52069 };
52070
52071 enum ocfs2_local_alloc_state
52072diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
52073index 79b5dac..d322952 100644
52074--- a/fs/ocfs2/suballoc.c
52075+++ b/fs/ocfs2/suballoc.c
52076@@ -623,7 +623,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
52077 mlog_errno(status);
52078 goto bail;
52079 }
52080- atomic_inc(&osb->alloc_stats.bg_extends);
52081+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
52082
52083 /* You should never ask for this much metadata */
52084 BUG_ON(bits_wanted >
52085@@ -1654,7 +1654,7 @@ int ocfs2_claim_metadata(struct ocfs2_super *osb,
52086 mlog_errno(status);
52087 goto bail;
52088 }
52089- atomic_inc(&osb->alloc_stats.bg_allocs);
52090+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
52091
52092 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
52093 ac->ac_bits_given += (*num_bits);
52094@@ -1728,7 +1728,7 @@ int ocfs2_claim_new_inode(struct ocfs2_super *osb,
52095 mlog_errno(status);
52096 goto bail;
52097 }
52098- atomic_inc(&osb->alloc_stats.bg_allocs);
52099+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
52100
52101 BUG_ON(num_bits != 1);
52102
52103@@ -1830,7 +1830,7 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb,
52104 cluster_start,
52105 num_clusters);
52106 if (!status)
52107- atomic_inc(&osb->alloc_stats.local_data);
52108+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
52109 } else {
52110 if (min_clusters > (osb->bitmap_cpg - 1)) {
52111 /* The only paths asking for contiguousness
52112@@ -1858,7 +1858,7 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb,
52113 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
52114 bg_blkno,
52115 bg_bit_off);
52116- atomic_inc(&osb->alloc_stats.bitmap_data);
52117+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
52118 }
52119 }
52120 if (status < 0) {
52121diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
52122index 9f55be4..a3f8048 100644
52123--- a/fs/ocfs2/super.c
52124+++ b/fs/ocfs2/super.c
52125@@ -284,11 +284,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
52126 "%10s => GlobalAllocs: %d LocalAllocs: %d "
52127 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
52128 "Stats",
52129- atomic_read(&osb->alloc_stats.bitmap_data),
52130- atomic_read(&osb->alloc_stats.local_data),
52131- atomic_read(&osb->alloc_stats.bg_allocs),
52132- atomic_read(&osb->alloc_stats.moves),
52133- atomic_read(&osb->alloc_stats.bg_extends));
52134+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
52135+ atomic_read_unchecked(&osb->alloc_stats.local_data),
52136+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
52137+ atomic_read_unchecked(&osb->alloc_stats.moves),
52138+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
52139
52140 out += snprintf(buf + out, len - out,
52141 "%10s => State: %u Descriptor: %llu Size: %u bits "
52142@@ -2002,11 +2002,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
52143 spin_lock_init(&osb->osb_xattr_lock);
52144 ocfs2_init_inode_steal_slot(osb);
52145
52146- atomic_set(&osb->alloc_stats.moves, 0);
52147- atomic_set(&osb->alloc_stats.local_data, 0);
52148- atomic_set(&osb->alloc_stats.bitmap_data, 0);
52149- atomic_set(&osb->alloc_stats.bg_allocs, 0);
52150- atomic_set(&osb->alloc_stats.bg_extends, 0);
52151+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
52152+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
52153+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
52154+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
52155+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
52156
52157 /* Copy the blockcheck stats from the superblock probe */
52158 osb->osb_ecc_stats = *stats;
52159diff --git a/fs/open.c b/fs/open.c
52160index 4f01e06..091f6c3 100644
52161--- a/fs/open.c
52162+++ b/fs/open.c
52163@@ -275,6 +275,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
52164 error = locks_verify_truncate(inode, NULL, length);
52165 if (!error)
52166 error = security_path_truncate(&path, length, 0);
52167+
52168+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
52169+ error = -EACCES;
52170+
52171 if (!error) {
52172 vfs_dq_init(inode);
52173 error = do_truncate(path.dentry, length, 0, NULL);
52174@@ -511,6 +515,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
52175 if (__mnt_is_readonly(path.mnt))
52176 res = -EROFS;
52177
52178+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
52179+ res = -EACCES;
52180+
52181 out_path_release:
52182 path_put(&path);
52183 out:
52184@@ -537,6 +544,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
52185 if (error)
52186 goto dput_and_out;
52187
52188+ gr_log_chdir(path.dentry, path.mnt);
52189+
52190 set_fs_pwd(current->fs, &path);
52191
52192 dput_and_out:
52193@@ -563,6 +572,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
52194 goto out_putf;
52195
52196 error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
52197+
52198+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
52199+ error = -EPERM;
52200+
52201+ if (!error)
52202+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
52203+
52204 if (!error)
52205 set_fs_pwd(current->fs, &file->f_path);
52206 out_putf:
52207@@ -588,7 +604,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
52208 if (!capable(CAP_SYS_CHROOT))
52209 goto dput_and_out;
52210
52211+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
52212+ goto dput_and_out;
52213+
52214 set_fs_root(current->fs, &path);
52215+
52216+ gr_handle_chroot_chdir(&path);
52217+
52218 error = 0;
52219 dput_and_out:
52220 path_put(&path);
52221@@ -616,12 +638,27 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
52222 err = mnt_want_write_file(file);
52223 if (err)
52224 goto out_putf;
52225+
52226 mutex_lock(&inode->i_mutex);
52227+
52228+ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
52229+ err = -EACCES;
52230+ goto out_unlock;
52231+ }
52232+
52233 if (mode == (mode_t) -1)
52234 mode = inode->i_mode;
52235+
52236+ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
52237+ err = -EPERM;
52238+ goto out_unlock;
52239+ }
52240+
52241 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
52242 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
52243 err = notify_change(dentry, &newattrs);
52244+
52245+out_unlock:
52246 mutex_unlock(&inode->i_mutex);
52247 mnt_drop_write(file->f_path.mnt);
52248 out_putf:
52249@@ -645,12 +682,27 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode)
52250 error = mnt_want_write(path.mnt);
52251 if (error)
52252 goto dput_and_out;
52253+
52254 mutex_lock(&inode->i_mutex);
52255+
52256+ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
52257+ error = -EACCES;
52258+ goto out_unlock;
52259+ }
52260+
52261 if (mode == (mode_t) -1)
52262 mode = inode->i_mode;
52263+
52264+ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
52265+ error = -EACCES;
52266+ goto out_unlock;
52267+ }
52268+
52269 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
52270 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
52271 error = notify_change(path.dentry, &newattrs);
52272+
52273+out_unlock:
52274 mutex_unlock(&inode->i_mutex);
52275 mnt_drop_write(path.mnt);
52276 dput_and_out:
52277@@ -664,12 +716,15 @@ SYSCALL_DEFINE2(chmod, const char __user *, filename, mode_t, mode)
52278 return sys_fchmodat(AT_FDCWD, filename, mode);
52279 }
52280
52281-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
52282+static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
52283 {
52284 struct inode *inode = dentry->d_inode;
52285 int error;
52286 struct iattr newattrs;
52287
52288+ if (!gr_acl_handle_chown(dentry, mnt))
52289+ return -EACCES;
52290+
52291 newattrs.ia_valid = ATTR_CTIME;
52292 if (user != (uid_t) -1) {
52293 newattrs.ia_valid |= ATTR_UID;
52294@@ -700,7 +755,7 @@ SYSCALL_DEFINE3(chown, const char __user *, filename, uid_t, user, gid_t, group)
52295 error = mnt_want_write(path.mnt);
52296 if (error)
52297 goto out_release;
52298- error = chown_common(path.dentry, user, group);
52299+ error = chown_common(path.dentry, user, group, path.mnt);
52300 mnt_drop_write(path.mnt);
52301 out_release:
52302 path_put(&path);
52303@@ -725,7 +780,7 @@ SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user,
52304 error = mnt_want_write(path.mnt);
52305 if (error)
52306 goto out_release;
52307- error = chown_common(path.dentry, user, group);
52308+ error = chown_common(path.dentry, user, group, path.mnt);
52309 mnt_drop_write(path.mnt);
52310 out_release:
52311 path_put(&path);
52312@@ -744,7 +799,7 @@ SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group
52313 error = mnt_want_write(path.mnt);
52314 if (error)
52315 goto out_release;
52316- error = chown_common(path.dentry, user, group);
52317+ error = chown_common(path.dentry, user, group, path.mnt);
52318 mnt_drop_write(path.mnt);
52319 out_release:
52320 path_put(&path);
52321@@ -767,7 +822,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
52322 goto out_fput;
52323 dentry = file->f_path.dentry;
52324 audit_inode(NULL, dentry);
52325- error = chown_common(dentry, user, group);
52326+ error = chown_common(dentry, user, group, file->f_path.mnt);
52327 mnt_drop_write(file->f_path.mnt);
52328 out_fput:
52329 fput(file);
52330@@ -1036,7 +1091,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, int mode)
52331 if (!IS_ERR(tmp)) {
52332 fd = get_unused_fd_flags(flags);
52333 if (fd >= 0) {
52334- struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
52335+ struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
52336 if (IS_ERR(f)) {
52337 put_unused_fd(fd);
52338 fd = PTR_ERR(f);
52339diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
52340index 6ab70f4..f4103d1 100644
52341--- a/fs/partitions/efi.c
52342+++ b/fs/partitions/efi.c
52343@@ -231,14 +231,14 @@ alloc_read_gpt_entries(struct block_device *bdev, gpt_header *gpt)
52344 if (!bdev || !gpt)
52345 return NULL;
52346
52347+ if (!le32_to_cpu(gpt->num_partition_entries))
52348+ return NULL;
52349+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
52350+ if (!pte)
52351+ return NULL;
52352+
52353 count = le32_to_cpu(gpt->num_partition_entries) *
52354 le32_to_cpu(gpt->sizeof_partition_entry);
52355- if (!count)
52356- return NULL;
52357- pte = kzalloc(count, GFP_KERNEL);
52358- if (!pte)
52359- return NULL;
52360-
52361 if (read_lba(bdev, le64_to_cpu(gpt->partition_entry_lba),
52362 (u8 *) pte,
52363 count) < count) {
52364diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
52365index dd6efdb..3babc6c 100644
52366--- a/fs/partitions/ldm.c
52367+++ b/fs/partitions/ldm.c
52368@@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
52369 ldm_error ("A VBLK claims to have %d parts.", num);
52370 return false;
52371 }
52372+
52373 if (rec >= num) {
52374 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
52375 return false;
52376@@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
52377 goto found;
52378 }
52379
52380- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
52381+ f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
52382 if (!f) {
52383 ldm_crit ("Out of memory.");
52384 return false;
52385diff --git a/fs/partitions/mac.c b/fs/partitions/mac.c
52386index 5765198..7f8e9e0 100644
52387--- a/fs/partitions/mac.c
52388+++ b/fs/partitions/mac.c
52389@@ -59,11 +59,11 @@ int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
52390 return 0; /* not a MacOS disk */
52391 }
52392 blocks_in_map = be32_to_cpu(part->map_count);
52393- if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
52394- put_dev_sector(sect);
52395- return 0;
52396- }
52397 printk(" [mac]");
52398+ if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
52399+ put_dev_sector(sect);
52400+ return 0;
52401+ }
52402 for (slot = 1; slot <= blocks_in_map; ++slot) {
52403 int pos = slot * secsize;
52404 put_dev_sector(sect);
52405diff --git a/fs/pipe.c b/fs/pipe.c
52406index d0cc080..8a6f211 100644
52407--- a/fs/pipe.c
52408+++ b/fs/pipe.c
52409@@ -401,9 +401,9 @@ redo:
52410 }
52411 if (bufs) /* More to do? */
52412 continue;
52413- if (!pipe->writers)
52414+ if (!atomic_read(&pipe->writers))
52415 break;
52416- if (!pipe->waiting_writers) {
52417+ if (!atomic_read(&pipe->waiting_writers)) {
52418 /* syscall merging: Usually we must not sleep
52419 * if O_NONBLOCK is set, or if we got some data.
52420 * But if a writer sleeps in kernel space, then
52421@@ -462,7 +462,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
52422 mutex_lock(&inode->i_mutex);
52423 pipe = inode->i_pipe;
52424
52425- if (!pipe->readers) {
52426+ if (!atomic_read(&pipe->readers)) {
52427 send_sig(SIGPIPE, current, 0);
52428 ret = -EPIPE;
52429 goto out;
52430@@ -511,7 +511,7 @@ redo1:
52431 for (;;) {
52432 int bufs;
52433
52434- if (!pipe->readers) {
52435+ if (!atomic_read(&pipe->readers)) {
52436 send_sig(SIGPIPE, current, 0);
52437 if (!ret)
52438 ret = -EPIPE;
52439@@ -597,9 +597,9 @@ redo2:
52440 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
52441 do_wakeup = 0;
52442 }
52443- pipe->waiting_writers++;
52444+ atomic_inc(&pipe->waiting_writers);
52445 pipe_wait(pipe);
52446- pipe->waiting_writers--;
52447+ atomic_dec(&pipe->waiting_writers);
52448 }
52449 out:
52450 mutex_unlock(&inode->i_mutex);
52451@@ -666,7 +666,7 @@ pipe_poll(struct file *filp, poll_table *wait)
52452 mask = 0;
52453 if (filp->f_mode & FMODE_READ) {
52454 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
52455- if (!pipe->writers && filp->f_version != pipe->w_counter)
52456+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
52457 mask |= POLLHUP;
52458 }
52459
52460@@ -676,7 +676,7 @@ pipe_poll(struct file *filp, poll_table *wait)
52461 * Most Unices do not set POLLERR for FIFOs but on Linux they
52462 * behave exactly like pipes for poll().
52463 */
52464- if (!pipe->readers)
52465+ if (!atomic_read(&pipe->readers))
52466 mask |= POLLERR;
52467 }
52468
52469@@ -690,10 +690,10 @@ pipe_release(struct inode *inode, int decr, int decw)
52470
52471 mutex_lock(&inode->i_mutex);
52472 pipe = inode->i_pipe;
52473- pipe->readers -= decr;
52474- pipe->writers -= decw;
52475+ atomic_sub(decr, &pipe->readers);
52476+ atomic_sub(decw, &pipe->writers);
52477
52478- if (!pipe->readers && !pipe->writers) {
52479+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
52480 free_pipe_info(inode);
52481 } else {
52482 wake_up_interruptible_sync(&pipe->wait);
52483@@ -783,7 +783,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
52484
52485 if (inode->i_pipe) {
52486 ret = 0;
52487- inode->i_pipe->readers++;
52488+ atomic_inc(&inode->i_pipe->readers);
52489 }
52490
52491 mutex_unlock(&inode->i_mutex);
52492@@ -800,7 +800,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
52493
52494 if (inode->i_pipe) {
52495 ret = 0;
52496- inode->i_pipe->writers++;
52497+ atomic_inc(&inode->i_pipe->writers);
52498 }
52499
52500 mutex_unlock(&inode->i_mutex);
52501@@ -818,9 +818,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
52502 if (inode->i_pipe) {
52503 ret = 0;
52504 if (filp->f_mode & FMODE_READ)
52505- inode->i_pipe->readers++;
52506+ atomic_inc(&inode->i_pipe->readers);
52507 if (filp->f_mode & FMODE_WRITE)
52508- inode->i_pipe->writers++;
52509+ atomic_inc(&inode->i_pipe->writers);
52510 }
52511
52512 mutex_unlock(&inode->i_mutex);
52513@@ -905,7 +905,7 @@ void free_pipe_info(struct inode *inode)
52514 inode->i_pipe = NULL;
52515 }
52516
52517-static struct vfsmount *pipe_mnt __read_mostly;
52518+struct vfsmount *pipe_mnt __read_mostly;
52519 static int pipefs_delete_dentry(struct dentry *dentry)
52520 {
52521 /*
52522@@ -945,7 +945,8 @@ static struct inode * get_pipe_inode(void)
52523 goto fail_iput;
52524 inode->i_pipe = pipe;
52525
52526- pipe->readers = pipe->writers = 1;
52527+ atomic_set(&pipe->readers, 1);
52528+ atomic_set(&pipe->writers, 1);
52529 inode->i_fop = &rdwr_pipefifo_fops;
52530
52531 /*
52532diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
52533index 50f8f06..c5755df 100644
52534--- a/fs/proc/Kconfig
52535+++ b/fs/proc/Kconfig
52536@@ -30,12 +30,12 @@ config PROC_FS
52537
52538 config PROC_KCORE
52539 bool "/proc/kcore support" if !ARM
52540- depends on PROC_FS && MMU
52541+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
52542
52543 config PROC_VMCORE
52544 bool "/proc/vmcore support (EXPERIMENTAL)"
52545- depends on PROC_FS && CRASH_DUMP
52546- default y
52547+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
52548+ default n
52549 help
52550 Exports the dump image of crashed kernel in ELF format.
52551
52552@@ -59,8 +59,8 @@ config PROC_SYSCTL
52553 limited in memory.
52554
52555 config PROC_PAGE_MONITOR
52556- default y
52557- depends on PROC_FS && MMU
52558+ default n
52559+ depends on PROC_FS && MMU && !GRKERNSEC
52560 bool "Enable /proc page monitoring" if EMBEDDED
52561 help
52562 Various /proc files exist to monitor process memory utilization:
52563diff --git a/fs/proc/array.c b/fs/proc/array.c
52564index c5ef152..1363194 100644
52565--- a/fs/proc/array.c
52566+++ b/fs/proc/array.c
52567@@ -60,6 +60,7 @@
52568 #include <linux/tty.h>
52569 #include <linux/string.h>
52570 #include <linux/mman.h>
52571+#include <linux/grsecurity.h>
52572 #include <linux/proc_fs.h>
52573 #include <linux/ioport.h>
52574 #include <linux/uaccess.h>
52575@@ -321,6 +322,21 @@ static inline void task_context_switch_counts(struct seq_file *m,
52576 p->nivcsw);
52577 }
52578
52579+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52580+static inline void task_pax(struct seq_file *m, struct task_struct *p)
52581+{
52582+ if (p->mm)
52583+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
52584+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
52585+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
52586+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
52587+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
52588+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
52589+ else
52590+ seq_printf(m, "PaX:\t-----\n");
52591+}
52592+#endif
52593+
52594 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52595 struct pid *pid, struct task_struct *task)
52596 {
52597@@ -337,9 +353,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52598 task_cap(m, task);
52599 cpuset_task_status_allowed(m, task);
52600 task_context_switch_counts(m, task);
52601+
52602+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52603+ task_pax(m, task);
52604+#endif
52605+
52606+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
52607+ task_grsec_rbac(m, task);
52608+#endif
52609+
52610 return 0;
52611 }
52612
52613+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52614+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52615+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52616+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52617+#endif
52618+
52619 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52620 struct pid *pid, struct task_struct *task, int whole)
52621 {
52622@@ -358,9 +389,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52623 cputime_t cutime, cstime, utime, stime;
52624 cputime_t cgtime, gtime;
52625 unsigned long rsslim = 0;
52626- char tcomm[sizeof(task->comm)];
52627+ char tcomm[sizeof(task->comm)] = { 0 };
52628 unsigned long flags;
52629
52630+ pax_track_stack();
52631+
52632 state = *get_task_state(task);
52633 vsize = eip = esp = 0;
52634 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
52635@@ -433,6 +466,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52636 gtime = task_gtime(task);
52637 }
52638
52639+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52640+ if (PAX_RAND_FLAGS(mm)) {
52641+ eip = 0;
52642+ esp = 0;
52643+ wchan = 0;
52644+ }
52645+#endif
52646+#ifdef CONFIG_GRKERNSEC_HIDESYM
52647+ wchan = 0;
52648+ eip =0;
52649+ esp =0;
52650+#endif
52651+
52652 /* scale priority and nice values from timeslices to -20..20 */
52653 /* to make it look like a "normal" Unix priority/nice value */
52654 priority = task_prio(task);
52655@@ -473,9 +519,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52656 vsize,
52657 mm ? get_mm_rss(mm) : 0,
52658 rsslim,
52659+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52660+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
52661+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
52662+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
52663+#else
52664 mm ? (permitted ? mm->start_code : 1) : 0,
52665 mm ? (permitted ? mm->end_code : 1) : 0,
52666 (permitted && mm) ? mm->start_stack : 0,
52667+#endif
52668 esp,
52669 eip,
52670 /* The signal information here is obsolete.
52671@@ -528,3 +580,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52672
52673 return 0;
52674 }
52675+
52676+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52677+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
52678+{
52679+ u32 curr_ip = 0;
52680+ unsigned long flags;
52681+
52682+ if (lock_task_sighand(task, &flags)) {
52683+ curr_ip = task->signal->curr_ip;
52684+ unlock_task_sighand(task, &flags);
52685+ }
52686+
52687+ return sprintf(buffer, "%pI4\n", &curr_ip);
52688+}
52689+#endif
52690diff --git a/fs/proc/base.c b/fs/proc/base.c
52691index 67f7dc0..67ab883 100644
52692--- a/fs/proc/base.c
52693+++ b/fs/proc/base.c
52694@@ -102,6 +102,22 @@ struct pid_entry {
52695 union proc_op op;
52696 };
52697
52698+struct getdents_callback {
52699+ struct linux_dirent __user * current_dir;
52700+ struct linux_dirent __user * previous;
52701+ struct file * file;
52702+ int count;
52703+ int error;
52704+};
52705+
52706+static int gr_fake_filldir(void * __buf, const char *name, int namlen,
52707+ loff_t offset, u64 ino, unsigned int d_type)
52708+{
52709+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
52710+ buf->error = -EINVAL;
52711+ return 0;
52712+}
52713+
52714 #define NOD(NAME, MODE, IOP, FOP, OP) { \
52715 .name = (NAME), \
52716 .len = sizeof(NAME) - 1, \
52717@@ -213,6 +229,9 @@ static int check_mem_permission(struct task_struct *task)
52718 if (task == current)
52719 return 0;
52720
52721+ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
52722+ return -EPERM;
52723+
52724 /*
52725 * If current is actively ptrace'ing, and would also be
52726 * permitted to freshly attach with ptrace now, permit it.
52727@@ -260,6 +279,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
52728 if (!mm->arg_end)
52729 goto out_mm; /* Shh! No looking before we're done */
52730
52731+ if (gr_acl_handle_procpidmem(task))
52732+ goto out_mm;
52733+
52734 len = mm->arg_end - mm->arg_start;
52735
52736 if (len > PAGE_SIZE)
52737@@ -287,12 +309,28 @@ out:
52738 return res;
52739 }
52740
52741+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52742+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52743+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52744+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52745+#endif
52746+
52747 static int proc_pid_auxv(struct task_struct *task, char *buffer)
52748 {
52749 int res = 0;
52750 struct mm_struct *mm = get_task_mm(task);
52751 if (mm) {
52752 unsigned int nwords = 0;
52753+
52754+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52755+ /* allow if we're currently ptracing this task */
52756+ if (PAX_RAND_FLAGS(mm) &&
52757+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
52758+ mmput(mm);
52759+ return 0;
52760+ }
52761+#endif
52762+
52763 do {
52764 nwords += 2;
52765 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
52766@@ -306,7 +344,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
52767 }
52768
52769
52770-#ifdef CONFIG_KALLSYMS
52771+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52772 /*
52773 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
52774 * Returns the resolved symbol. If that fails, simply return the address.
52775@@ -345,7 +383,7 @@ static void unlock_trace(struct task_struct *task)
52776 mutex_unlock(&task->cred_guard_mutex);
52777 }
52778
52779-#ifdef CONFIG_STACKTRACE
52780+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52781
52782 #define MAX_STACK_TRACE_DEPTH 64
52783
52784@@ -545,7 +583,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
52785 return count;
52786 }
52787
52788-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52789+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52790 static int proc_pid_syscall(struct task_struct *task, char *buffer)
52791 {
52792 long nr;
52793@@ -574,7 +612,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
52794 /************************************************************************/
52795
52796 /* permission checks */
52797-static int proc_fd_access_allowed(struct inode *inode)
52798+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
52799 {
52800 struct task_struct *task;
52801 int allowed = 0;
52802@@ -584,7 +622,10 @@ static int proc_fd_access_allowed(struct inode *inode)
52803 */
52804 task = get_proc_task(inode);
52805 if (task) {
52806- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
52807+ if (log)
52808+ allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
52809+ else
52810+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
52811 put_task_struct(task);
52812 }
52813 return allowed;
52814@@ -809,6 +850,8 @@ static int mem_open(struct inode* inode, struct file* file)
52815 return 0;
52816 }
52817
52818+static int task_dumpable(struct task_struct *task);
52819+
52820 static ssize_t mem_read(struct file * file, char __user * buf,
52821 size_t count, loff_t *ppos)
52822 {
52823@@ -824,6 +867,12 @@ static ssize_t mem_read(struct file * file, char __user * buf,
52824 if (check_mem_permission(task))
52825 goto out;
52826
52827+ // XXX: temporary workaround
52828+ if (!task_dumpable(task) && task == current) {
52829+ ret = -EACCES;
52830+ goto out;
52831+ }
52832+
52833 ret = -ENOMEM;
52834 page = (char *)__get_free_page(GFP_TEMPORARY);
52835 if (!page)
52836@@ -963,6 +1012,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
52837 if (!task)
52838 goto out_no_task;
52839
52840+ if (gr_acl_handle_procpidmem(task))
52841+ goto out;
52842+
52843 if (!ptrace_may_access(task, PTRACE_MODE_READ))
52844 goto out;
52845
52846@@ -1377,7 +1429,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
52847 path_put(&nd->path);
52848
52849 /* Are we allowed to snoop on the tasks file descriptors? */
52850- if (!proc_fd_access_allowed(inode))
52851+ if (!proc_fd_access_allowed(inode,0))
52852 goto out;
52853
52854 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
52855@@ -1417,8 +1469,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
52856 struct path path;
52857
52858 /* Are we allowed to snoop on the tasks file descriptors? */
52859- if (!proc_fd_access_allowed(inode))
52860- goto out;
52861+ /* logging this is needed for learning on chromium to work properly,
52862+ but we don't want to flood the logs from 'ps' which does a readlink
52863+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
52864+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
52865+ */
52866+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
52867+ if (!proc_fd_access_allowed(inode,0))
52868+ goto out;
52869+ } else {
52870+ if (!proc_fd_access_allowed(inode,1))
52871+ goto out;
52872+ }
52873
52874 error = PROC_I(inode)->op.proc_get_link(inode, &path);
52875 if (error)
52876@@ -1483,7 +1545,11 @@ static struct inode *proc_pid_make_inode(struct super_block * sb, struct task_st
52877 rcu_read_lock();
52878 cred = __task_cred(task);
52879 inode->i_uid = cred->euid;
52880+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52881+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52882+#else
52883 inode->i_gid = cred->egid;
52884+#endif
52885 rcu_read_unlock();
52886 }
52887 security_task_to_inode(task, inode);
52888@@ -1501,6 +1567,9 @@ static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat
52889 struct inode *inode = dentry->d_inode;
52890 struct task_struct *task;
52891 const struct cred *cred;
52892+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52893+ const struct cred *tmpcred = current_cred();
52894+#endif
52895
52896 generic_fillattr(inode, stat);
52897
52898@@ -1508,13 +1577,41 @@ static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat
52899 stat->uid = 0;
52900 stat->gid = 0;
52901 task = pid_task(proc_pid(inode), PIDTYPE_PID);
52902+
52903+ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
52904+ rcu_read_unlock();
52905+ return -ENOENT;
52906+ }
52907+
52908 if (task) {
52909+ cred = __task_cred(task);
52910+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52911+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
52912+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52913+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
52914+#endif
52915+ ) {
52916+#endif
52917 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
52918+#ifdef CONFIG_GRKERNSEC_PROC_USER
52919+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
52920+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52921+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
52922+#endif
52923 task_dumpable(task)) {
52924- cred = __task_cred(task);
52925 stat->uid = cred->euid;
52926+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52927+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
52928+#else
52929 stat->gid = cred->egid;
52930+#endif
52931 }
52932+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52933+ } else {
52934+ rcu_read_unlock();
52935+ return -ENOENT;
52936+ }
52937+#endif
52938 }
52939 rcu_read_unlock();
52940 return 0;
52941@@ -1545,11 +1642,20 @@ static int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
52942
52943 if (task) {
52944 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
52945+#ifdef CONFIG_GRKERNSEC_PROC_USER
52946+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
52947+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52948+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
52949+#endif
52950 task_dumpable(task)) {
52951 rcu_read_lock();
52952 cred = __task_cred(task);
52953 inode->i_uid = cred->euid;
52954+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52955+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52956+#else
52957 inode->i_gid = cred->egid;
52958+#endif
52959 rcu_read_unlock();
52960 } else {
52961 inode->i_uid = 0;
52962@@ -1670,7 +1776,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
52963 int fd = proc_fd(inode);
52964
52965 if (task) {
52966- files = get_files_struct(task);
52967+ if (!gr_acl_handle_procpidmem(task))
52968+ files = get_files_struct(task);
52969 put_task_struct(task);
52970 }
52971 if (files) {
52972@@ -1922,12 +2029,22 @@ static const struct file_operations proc_fd_operations = {
52973 static int proc_fd_permission(struct inode *inode, int mask)
52974 {
52975 int rv;
52976+ struct task_struct *task;
52977
52978 rv = generic_permission(inode, mask, NULL);
52979- if (rv == 0)
52980- return 0;
52981+
52982 if (task_pid(current) == proc_pid(inode))
52983 rv = 0;
52984+
52985+ task = get_proc_task(inode);
52986+ if (task == NULL)
52987+ return rv;
52988+
52989+ if (gr_acl_handle_procpidmem(task))
52990+ rv = -EACCES;
52991+
52992+ put_task_struct(task);
52993+
52994 return rv;
52995 }
52996
52997@@ -2036,6 +2153,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
52998 if (!task)
52999 goto out_no_task;
53000
53001+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
53002+ goto out;
53003+
53004 /*
53005 * Yes, it does not scale. And it should not. Don't add
53006 * new entries into /proc/<tgid>/ without very good reasons.
53007@@ -2080,6 +2200,9 @@ static int proc_pident_readdir(struct file *filp,
53008 if (!task)
53009 goto out_no_task;
53010
53011+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
53012+ goto out;
53013+
53014 ret = 0;
53015 i = filp->f_pos;
53016 switch (i) {
53017@@ -2347,7 +2470,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
53018 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
53019 void *cookie)
53020 {
53021- char *s = nd_get_link(nd);
53022+ const char *s = nd_get_link(nd);
53023 if (!IS_ERR(s))
53024 __putname(s);
53025 }
53026@@ -2553,7 +2676,7 @@ static const struct pid_entry tgid_base_stuff[] = {
53027 #ifdef CONFIG_SCHED_DEBUG
53028 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
53029 #endif
53030-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
53031+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53032 INF("syscall", S_IRUGO, proc_pid_syscall),
53033 #endif
53034 INF("cmdline", S_IRUGO, proc_pid_cmdline),
53035@@ -2578,10 +2701,10 @@ static const struct pid_entry tgid_base_stuff[] = {
53036 #ifdef CONFIG_SECURITY
53037 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
53038 #endif
53039-#ifdef CONFIG_KALLSYMS
53040+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53041 INF("wchan", S_IRUGO, proc_pid_wchan),
53042 #endif
53043-#ifdef CONFIG_STACKTRACE
53044+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53045 ONE("stack", S_IRUGO, proc_pid_stack),
53046 #endif
53047 #ifdef CONFIG_SCHEDSTATS
53048@@ -2611,6 +2734,9 @@ static const struct pid_entry tgid_base_stuff[] = {
53049 #ifdef CONFIG_TASK_IO_ACCOUNTING
53050 INF("io", S_IRUSR, proc_tgid_io_accounting),
53051 #endif
53052+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
53053+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
53054+#endif
53055 };
53056
53057 static int proc_tgid_base_readdir(struct file * filp,
53058@@ -2735,7 +2861,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
53059 if (!inode)
53060 goto out;
53061
53062+#ifdef CONFIG_GRKERNSEC_PROC_USER
53063+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
53064+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53065+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
53066+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
53067+#else
53068 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
53069+#endif
53070 inode->i_op = &proc_tgid_base_inode_operations;
53071 inode->i_fop = &proc_tgid_base_operations;
53072 inode->i_flags|=S_IMMUTABLE;
53073@@ -2777,7 +2910,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
53074 if (!task)
53075 goto out;
53076
53077+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
53078+ goto out_put_task;
53079+
53080 result = proc_pid_instantiate(dir, dentry, task, NULL);
53081+out_put_task:
53082 put_task_struct(task);
53083 out:
53084 return result;
53085@@ -2842,6 +2979,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
53086 {
53087 unsigned int nr;
53088 struct task_struct *reaper;
53089+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53090+ const struct cred *tmpcred = current_cred();
53091+ const struct cred *itercred;
53092+#endif
53093+ filldir_t __filldir = filldir;
53094 struct tgid_iter iter;
53095 struct pid_namespace *ns;
53096
53097@@ -2865,8 +3007,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
53098 for (iter = next_tgid(ns, iter);
53099 iter.task;
53100 iter.tgid += 1, iter = next_tgid(ns, iter)) {
53101+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53102+ rcu_read_lock();
53103+ itercred = __task_cred(iter.task);
53104+#endif
53105+ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
53106+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53107+ || (tmpcred->uid && (itercred->uid != tmpcred->uid)
53108+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
53109+ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
53110+#endif
53111+ )
53112+#endif
53113+ )
53114+ __filldir = &gr_fake_filldir;
53115+ else
53116+ __filldir = filldir;
53117+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53118+ rcu_read_unlock();
53119+#endif
53120 filp->f_pos = iter.tgid + TGID_OFFSET;
53121- if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
53122+ if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
53123 put_task_struct(iter.task);
53124 goto out;
53125 }
53126@@ -2892,7 +3053,7 @@ static const struct pid_entry tid_base_stuff[] = {
53127 #ifdef CONFIG_SCHED_DEBUG
53128 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
53129 #endif
53130-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
53131+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53132 INF("syscall", S_IRUGO, proc_pid_syscall),
53133 #endif
53134 INF("cmdline", S_IRUGO, proc_pid_cmdline),
53135@@ -2916,10 +3077,10 @@ static const struct pid_entry tid_base_stuff[] = {
53136 #ifdef CONFIG_SECURITY
53137 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
53138 #endif
53139-#ifdef CONFIG_KALLSYMS
53140+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53141 INF("wchan", S_IRUGO, proc_pid_wchan),
53142 #endif
53143-#ifdef CONFIG_STACKTRACE
53144+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53145 ONE("stack", S_IRUGO, proc_pid_stack),
53146 #endif
53147 #ifdef CONFIG_SCHEDSTATS
53148diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
53149index 82676e3..5f8518a 100644
53150--- a/fs/proc/cmdline.c
53151+++ b/fs/proc/cmdline.c
53152@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
53153
53154 static int __init proc_cmdline_init(void)
53155 {
53156+#ifdef CONFIG_GRKERNSEC_PROC_ADD
53157+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
53158+#else
53159 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
53160+#endif
53161 return 0;
53162 }
53163 module_init(proc_cmdline_init);
53164diff --git a/fs/proc/devices.c b/fs/proc/devices.c
53165index 59ee7da..469b4b6 100644
53166--- a/fs/proc/devices.c
53167+++ b/fs/proc/devices.c
53168@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
53169
53170 static int __init proc_devices_init(void)
53171 {
53172+#ifdef CONFIG_GRKERNSEC_PROC_ADD
53173+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
53174+#else
53175 proc_create("devices", 0, NULL, &proc_devinfo_operations);
53176+#endif
53177 return 0;
53178 }
53179 module_init(proc_devices_init);
53180diff --git a/fs/proc/inode.c b/fs/proc/inode.c
53181index d78ade3..81767f9 100644
53182--- a/fs/proc/inode.c
53183+++ b/fs/proc/inode.c
53184@@ -18,12 +18,19 @@
53185 #include <linux/module.h>
53186 #include <linux/smp_lock.h>
53187 #include <linux/sysctl.h>
53188+#include <linux/grsecurity.h>
53189
53190 #include <asm/system.h>
53191 #include <asm/uaccess.h>
53192
53193 #include "internal.h"
53194
53195+#ifdef CONFIG_PROC_SYSCTL
53196+extern const struct inode_operations proc_sys_inode_operations;
53197+extern const struct inode_operations proc_sys_dir_operations;
53198+#endif
53199+
53200+
53201 struct proc_dir_entry *de_get(struct proc_dir_entry *de)
53202 {
53203 atomic_inc(&de->count);
53204@@ -62,6 +69,13 @@ static void proc_delete_inode(struct inode *inode)
53205 de_put(de);
53206 if (PROC_I(inode)->sysctl)
53207 sysctl_head_put(PROC_I(inode)->sysctl);
53208+
53209+#ifdef CONFIG_PROC_SYSCTL
53210+ if (inode->i_op == &proc_sys_inode_operations ||
53211+ inode->i_op == &proc_sys_dir_operations)
53212+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
53213+#endif
53214+
53215 clear_inode(inode);
53216 }
53217
53218@@ -457,7 +471,11 @@ struct inode *proc_get_inode(struct super_block *sb, unsigned int ino,
53219 if (de->mode) {
53220 inode->i_mode = de->mode;
53221 inode->i_uid = de->uid;
53222+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
53223+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
53224+#else
53225 inode->i_gid = de->gid;
53226+#endif
53227 }
53228 if (de->size)
53229 inode->i_size = de->size;
53230diff --git a/fs/proc/internal.h b/fs/proc/internal.h
53231index 753ca37..26bcf3b 100644
53232--- a/fs/proc/internal.h
53233+++ b/fs/proc/internal.h
53234@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53235 struct pid *pid, struct task_struct *task);
53236 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53237 struct pid *pid, struct task_struct *task);
53238+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
53239+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
53240+#endif
53241 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
53242
53243 extern const struct file_operations proc_maps_operations;
53244diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
53245index b442dac..aab29cb 100644
53246--- a/fs/proc/kcore.c
53247+++ b/fs/proc/kcore.c
53248@@ -320,6 +320,8 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
53249 off_t offset = 0;
53250 struct kcore_list *m;
53251
53252+ pax_track_stack();
53253+
53254 /* setup ELF header */
53255 elf = (struct elfhdr *) bufp;
53256 bufp += sizeof(struct elfhdr);
53257@@ -477,9 +479,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
53258 * the addresses in the elf_phdr on our list.
53259 */
53260 start = kc_offset_to_vaddr(*fpos - elf_buflen);
53261- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
53262+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
53263+ if (tsz > buflen)
53264 tsz = buflen;
53265-
53266+
53267 while (buflen) {
53268 struct kcore_list *m;
53269
53270@@ -508,20 +511,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
53271 kfree(elf_buf);
53272 } else {
53273 if (kern_addr_valid(start)) {
53274- unsigned long n;
53275+ char *elf_buf;
53276+ mm_segment_t oldfs;
53277
53278- n = copy_to_user(buffer, (char *)start, tsz);
53279- /*
53280- * We cannot distingush between fault on source
53281- * and fault on destination. When this happens
53282- * we clear too and hope it will trigger the
53283- * EFAULT again.
53284- */
53285- if (n) {
53286- if (clear_user(buffer + tsz - n,
53287- n))
53288+ elf_buf = kmalloc(tsz, GFP_KERNEL);
53289+ if (!elf_buf)
53290+ return -ENOMEM;
53291+ oldfs = get_fs();
53292+ set_fs(KERNEL_DS);
53293+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
53294+ set_fs(oldfs);
53295+ if (copy_to_user(buffer, elf_buf, tsz)) {
53296+ kfree(elf_buf);
53297 return -EFAULT;
53298+ }
53299 }
53300+ set_fs(oldfs);
53301+ kfree(elf_buf);
53302 } else {
53303 if (clear_user(buffer, tsz))
53304 return -EFAULT;
53305@@ -541,6 +547,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
53306
53307 static int open_kcore(struct inode *inode, struct file *filp)
53308 {
53309+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
53310+ return -EPERM;
53311+#endif
53312 if (!capable(CAP_SYS_RAWIO))
53313 return -EPERM;
53314 if (kcore_need_update)
53315diff --git a/fs/proc/kmsg.c b/fs/proc/kmsg.c
53316index 7ca7834..cfe90a4 100644
53317--- a/fs/proc/kmsg.c
53318+++ b/fs/proc/kmsg.c
53319@@ -12,37 +12,37 @@
53320 #include <linux/poll.h>
53321 #include <linux/proc_fs.h>
53322 #include <linux/fs.h>
53323+#include <linux/syslog.h>
53324
53325 #include <asm/uaccess.h>
53326 #include <asm/io.h>
53327
53328 extern wait_queue_head_t log_wait;
53329
53330-extern int do_syslog(int type, char __user *bug, int count);
53331-
53332 static int kmsg_open(struct inode * inode, struct file * file)
53333 {
53334- return do_syslog(1,NULL,0);
53335+ return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_FILE);
53336 }
53337
53338 static int kmsg_release(struct inode * inode, struct file * file)
53339 {
53340- (void) do_syslog(0,NULL,0);
53341+ (void) do_syslog(SYSLOG_ACTION_CLOSE, NULL, 0, SYSLOG_FROM_FILE);
53342 return 0;
53343 }
53344
53345 static ssize_t kmsg_read(struct file *file, char __user *buf,
53346 size_t count, loff_t *ppos)
53347 {
53348- if ((file->f_flags & O_NONBLOCK) && !do_syslog(9, NULL, 0))
53349+ if ((file->f_flags & O_NONBLOCK) &&
53350+ !do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE))
53351 return -EAGAIN;
53352- return do_syslog(2, buf, count);
53353+ return do_syslog(SYSLOG_ACTION_READ, buf, count, SYSLOG_FROM_FILE);
53354 }
53355
53356 static unsigned int kmsg_poll(struct file *file, poll_table *wait)
53357 {
53358 poll_wait(file, &log_wait, wait);
53359- if (do_syslog(9, NULL, 0))
53360+ if (do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE))
53361 return POLLIN | POLLRDNORM;
53362 return 0;
53363 }
53364diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
53365index a65239c..ad1182a 100644
53366--- a/fs/proc/meminfo.c
53367+++ b/fs/proc/meminfo.c
53368@@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
53369 unsigned long pages[NR_LRU_LISTS];
53370 int lru;
53371
53372+ pax_track_stack();
53373+
53374 /*
53375 * display in kilobytes.
53376 */
53377@@ -149,7 +151,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
53378 vmi.used >> 10,
53379 vmi.largest_chunk >> 10
53380 #ifdef CONFIG_MEMORY_FAILURE
53381- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
53382+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
53383 #endif
53384 );
53385
53386diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
53387index 9fe7d7e..cdb62c9 100644
53388--- a/fs/proc/nommu.c
53389+++ b/fs/proc/nommu.c
53390@@ -67,7 +67,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
53391 if (len < 1)
53392 len = 1;
53393 seq_printf(m, "%*c", len, ' ');
53394- seq_path(m, &file->f_path, "");
53395+ seq_path(m, &file->f_path, "\n\\");
53396 }
53397
53398 seq_putc(m, '\n');
53399diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
53400index 04d1270..25e1173 100644
53401--- a/fs/proc/proc_net.c
53402+++ b/fs/proc/proc_net.c
53403@@ -104,6 +104,17 @@ static struct net *get_proc_task_net(struct inode *dir)
53404 struct task_struct *task;
53405 struct nsproxy *ns;
53406 struct net *net = NULL;
53407+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53408+ const struct cred *cred = current_cred();
53409+#endif
53410+
53411+#ifdef CONFIG_GRKERNSEC_PROC_USER
53412+ if (cred->fsuid)
53413+ return net;
53414+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53415+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
53416+ return net;
53417+#endif
53418
53419 rcu_read_lock();
53420 task = pid_task(proc_pid(dir), PIDTYPE_PID);
53421diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
53422index f667e8a..55f4d96 100644
53423--- a/fs/proc/proc_sysctl.c
53424+++ b/fs/proc/proc_sysctl.c
53425@@ -7,11 +7,13 @@
53426 #include <linux/security.h>
53427 #include "internal.h"
53428
53429+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
53430+
53431 static const struct dentry_operations proc_sys_dentry_operations;
53432 static const struct file_operations proc_sys_file_operations;
53433-static const struct inode_operations proc_sys_inode_operations;
53434+const struct inode_operations proc_sys_inode_operations;
53435 static const struct file_operations proc_sys_dir_file_operations;
53436-static const struct inode_operations proc_sys_dir_operations;
53437+const struct inode_operations proc_sys_dir_operations;
53438
53439 static struct inode *proc_sys_make_inode(struct super_block *sb,
53440 struct ctl_table_header *head, struct ctl_table *table)
53441@@ -109,6 +111,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
53442 if (!p)
53443 goto out;
53444
53445+ if (gr_handle_sysctl(p, MAY_EXEC))
53446+ goto out;
53447+
53448 err = ERR_PTR(-ENOMEM);
53449 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
53450 if (h)
53451@@ -119,6 +124,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
53452
53453 err = NULL;
53454 dentry->d_op = &proc_sys_dentry_operations;
53455+
53456+ gr_handle_proc_create(dentry, inode);
53457+
53458 d_add(dentry, inode);
53459
53460 out:
53461@@ -200,6 +208,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
53462 return -ENOMEM;
53463 } else {
53464 child->d_op = &proc_sys_dentry_operations;
53465+
53466+ gr_handle_proc_create(child, inode);
53467+
53468 d_add(child, inode);
53469 }
53470 } else {
53471@@ -228,6 +239,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
53472 if (*pos < file->f_pos)
53473 continue;
53474
53475+ if (gr_handle_sysctl(table, 0))
53476+ continue;
53477+
53478 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
53479 if (res)
53480 return res;
53481@@ -344,6 +358,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
53482 if (IS_ERR(head))
53483 return PTR_ERR(head);
53484
53485+ if (table && gr_handle_sysctl(table, MAY_EXEC))
53486+ return -ENOENT;
53487+
53488 generic_fillattr(inode, stat);
53489 if (table)
53490 stat->mode = (stat->mode & S_IFMT) | table->mode;
53491@@ -358,17 +375,18 @@ static const struct file_operations proc_sys_file_operations = {
53492 };
53493
53494 static const struct file_operations proc_sys_dir_file_operations = {
53495+ .read = generic_read_dir,
53496 .readdir = proc_sys_readdir,
53497 .llseek = generic_file_llseek,
53498 };
53499
53500-static const struct inode_operations proc_sys_inode_operations = {
53501+const struct inode_operations proc_sys_inode_operations = {
53502 .permission = proc_sys_permission,
53503 .setattr = proc_sys_setattr,
53504 .getattr = proc_sys_getattr,
53505 };
53506
53507-static const struct inode_operations proc_sys_dir_operations = {
53508+const struct inode_operations proc_sys_dir_operations = {
53509 .lookup = proc_sys_lookup,
53510 .permission = proc_sys_permission,
53511 .setattr = proc_sys_setattr,
53512diff --git a/fs/proc/root.c b/fs/proc/root.c
53513index b080b79..d957e63 100644
53514--- a/fs/proc/root.c
53515+++ b/fs/proc/root.c
53516@@ -134,7 +134,15 @@ void __init proc_root_init(void)
53517 #ifdef CONFIG_PROC_DEVICETREE
53518 proc_device_tree_init();
53519 #endif
53520+#ifdef CONFIG_GRKERNSEC_PROC_ADD
53521+#ifdef CONFIG_GRKERNSEC_PROC_USER
53522+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
53523+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53524+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
53525+#endif
53526+#else
53527 proc_mkdir("bus", NULL);
53528+#endif
53529 proc_sys_init();
53530 }
53531
53532diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
53533index 3b7b82a..7dbb571 100644
53534--- a/fs/proc/task_mmu.c
53535+++ b/fs/proc/task_mmu.c
53536@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
53537 "VmStk:\t%8lu kB\n"
53538 "VmExe:\t%8lu kB\n"
53539 "VmLib:\t%8lu kB\n"
53540- "VmPTE:\t%8lu kB\n",
53541- hiwater_vm << (PAGE_SHIFT-10),
53542+ "VmPTE:\t%8lu kB\n"
53543+
53544+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53545+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
53546+#endif
53547+
53548+ ,hiwater_vm << (PAGE_SHIFT-10),
53549 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
53550 mm->locked_vm << (PAGE_SHIFT-10),
53551 hiwater_rss << (PAGE_SHIFT-10),
53552 total_rss << (PAGE_SHIFT-10),
53553 data << (PAGE_SHIFT-10),
53554 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
53555- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
53556+ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
53557+
53558+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53559+ , mm->context.user_cs_base, mm->context.user_cs_limit
53560+#endif
53561+
53562+ );
53563 }
53564
53565 unsigned long task_vsize(struct mm_struct *mm)
53566@@ -175,7 +186,8 @@ static void m_stop(struct seq_file *m, void *v)
53567 struct proc_maps_private *priv = m->private;
53568 struct vm_area_struct *vma = v;
53569
53570- vma_stop(priv, vma);
53571+ if (!IS_ERR(vma))
53572+ vma_stop(priv, vma);
53573 if (priv->task)
53574 put_task_struct(priv->task);
53575 }
53576@@ -199,6 +211,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
53577 return ret;
53578 }
53579
53580+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53581+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53582+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
53583+ _mm->pax_flags & MF_PAX_SEGMEXEC))
53584+#endif
53585+
53586 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53587 {
53588 struct mm_struct *mm = vma->vm_mm;
53589@@ -206,7 +224,6 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53590 int flags = vma->vm_flags;
53591 unsigned long ino = 0;
53592 unsigned long long pgoff = 0;
53593- unsigned long start;
53594 dev_t dev = 0;
53595 int len;
53596
53597@@ -217,20 +234,23 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53598 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
53599 }
53600
53601- /* We don't show the stack guard page in /proc/maps */
53602- start = vma->vm_start;
53603- if (vma->vm_flags & VM_GROWSDOWN)
53604- if (!vma_stack_continue(vma->vm_prev, vma->vm_start))
53605- start += PAGE_SIZE;
53606-
53607 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
53608- start,
53609+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53610+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
53611+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
53612+#else
53613+ vma->vm_start,
53614 vma->vm_end,
53615+#endif
53616 flags & VM_READ ? 'r' : '-',
53617 flags & VM_WRITE ? 'w' : '-',
53618 flags & VM_EXEC ? 'x' : '-',
53619 flags & VM_MAYSHARE ? 's' : 'p',
53620+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53621+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
53622+#else
53623 pgoff,
53624+#endif
53625 MAJOR(dev), MINOR(dev), ino, &len);
53626
53627 /*
53628@@ -239,7 +259,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53629 */
53630 if (file) {
53631 pad_len_spaces(m, len);
53632- seq_path(m, &file->f_path, "\n");
53633+ seq_path(m, &file->f_path, "\n\\");
53634 } else {
53635 const char *name = arch_vma_name(vma);
53636 if (!name) {
53637@@ -247,8 +267,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53638 if (vma->vm_start <= mm->brk &&
53639 vma->vm_end >= mm->start_brk) {
53640 name = "[heap]";
53641- } else if (vma->vm_start <= mm->start_stack &&
53642- vma->vm_end >= mm->start_stack) {
53643+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
53644+ (vma->vm_start <= mm->start_stack &&
53645+ vma->vm_end >= mm->start_stack)) {
53646 name = "[stack]";
53647 }
53648 } else {
53649@@ -391,9 +412,16 @@ static int show_smap(struct seq_file *m, void *v)
53650 };
53651
53652 memset(&mss, 0, sizeof mss);
53653- mss.vma = vma;
53654- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
53655- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
53656+
53657+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53658+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
53659+#endif
53660+ mss.vma = vma;
53661+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
53662+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
53663+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53664+ }
53665+#endif
53666
53667 show_map_vma(m, vma);
53668
53669@@ -409,7 +437,11 @@ static int show_smap(struct seq_file *m, void *v)
53670 "Swap: %8lu kB\n"
53671 "KernelPageSize: %8lu kB\n"
53672 "MMUPageSize: %8lu kB\n",
53673+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53674+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
53675+#else
53676 (vma->vm_end - vma->vm_start) >> 10,
53677+#endif
53678 mss.resident >> 10,
53679 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
53680 mss.shared_clean >> 10,
53681diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
53682index 8f5c05d..c99c76d 100644
53683--- a/fs/proc/task_nommu.c
53684+++ b/fs/proc/task_nommu.c
53685@@ -50,7 +50,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
53686 else
53687 bytes += kobjsize(mm);
53688
53689- if (current->fs && current->fs->users > 1)
53690+ if (current->fs && atomic_read(&current->fs->users) > 1)
53691 sbytes += kobjsize(current->fs);
53692 else
53693 bytes += kobjsize(current->fs);
53694@@ -154,7 +154,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
53695 if (len < 1)
53696 len = 1;
53697 seq_printf(m, "%*c", len, ' ');
53698- seq_path(m, &file->f_path, "");
53699+ seq_path(m, &file->f_path, "\n\\");
53700 }
53701
53702 seq_putc(m, '\n');
53703diff --git a/fs/readdir.c b/fs/readdir.c
53704index 7723401..30059a6 100644
53705--- a/fs/readdir.c
53706+++ b/fs/readdir.c
53707@@ -16,6 +16,7 @@
53708 #include <linux/security.h>
53709 #include <linux/syscalls.h>
53710 #include <linux/unistd.h>
53711+#include <linux/namei.h>
53712
53713 #include <asm/uaccess.h>
53714
53715@@ -67,6 +68,7 @@ struct old_linux_dirent {
53716
53717 struct readdir_callback {
53718 struct old_linux_dirent __user * dirent;
53719+ struct file * file;
53720 int result;
53721 };
53722
53723@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
53724 buf->result = -EOVERFLOW;
53725 return -EOVERFLOW;
53726 }
53727+
53728+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53729+ return 0;
53730+
53731 buf->result++;
53732 dirent = buf->dirent;
53733 if (!access_ok(VERIFY_WRITE, dirent,
53734@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
53735
53736 buf.result = 0;
53737 buf.dirent = dirent;
53738+ buf.file = file;
53739
53740 error = vfs_readdir(file, fillonedir, &buf);
53741 if (buf.result)
53742@@ -142,6 +149,7 @@ struct linux_dirent {
53743 struct getdents_callback {
53744 struct linux_dirent __user * current_dir;
53745 struct linux_dirent __user * previous;
53746+ struct file * file;
53747 int count;
53748 int error;
53749 };
53750@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
53751 buf->error = -EOVERFLOW;
53752 return -EOVERFLOW;
53753 }
53754+
53755+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53756+ return 0;
53757+
53758 dirent = buf->previous;
53759 if (dirent) {
53760 if (__put_user(offset, &dirent->d_off))
53761@@ -209,6 +221,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
53762 buf.previous = NULL;
53763 buf.count = count;
53764 buf.error = 0;
53765+ buf.file = file;
53766
53767 error = vfs_readdir(file, filldir, &buf);
53768 if (error >= 0)
53769@@ -228,6 +241,7 @@ out:
53770 struct getdents_callback64 {
53771 struct linux_dirent64 __user * current_dir;
53772 struct linux_dirent64 __user * previous;
53773+ struct file *file;
53774 int count;
53775 int error;
53776 };
53777@@ -242,6 +256,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
53778 buf->error = -EINVAL; /* only used if we fail.. */
53779 if (reclen > buf->count)
53780 return -EINVAL;
53781+
53782+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53783+ return 0;
53784+
53785 dirent = buf->previous;
53786 if (dirent) {
53787 if (__put_user(offset, &dirent->d_off))
53788@@ -289,6 +307,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
53789
53790 buf.current_dir = dirent;
53791 buf.previous = NULL;
53792+ buf.file = file;
53793 buf.count = count;
53794 buf.error = 0;
53795
53796@@ -297,7 +316,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
53797 error = buf.error;
53798 lastdirent = buf.previous;
53799 if (lastdirent) {
53800- typeof(lastdirent->d_off) d_off = file->f_pos;
53801+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
53802 if (__put_user(d_off, &lastdirent->d_off))
53803 error = -EFAULT;
53804 else
53805diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
53806index d42c30c..4fd8718 100644
53807--- a/fs/reiserfs/dir.c
53808+++ b/fs/reiserfs/dir.c
53809@@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentry *dentry, void *dirent,
53810 struct reiserfs_dir_entry de;
53811 int ret = 0;
53812
53813+ pax_track_stack();
53814+
53815 reiserfs_write_lock(inode->i_sb);
53816
53817 reiserfs_check_lock_depth(inode->i_sb, "readdir");
53818diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
53819index 128d3f7..8840d44 100644
53820--- a/fs/reiserfs/do_balan.c
53821+++ b/fs/reiserfs/do_balan.c
53822@@ -2058,7 +2058,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
53823 return;
53824 }
53825
53826- atomic_inc(&(fs_generation(tb->tb_sb)));
53827+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
53828 do_balance_starts(tb);
53829
53830 /* balance leaf returns 0 except if combining L R and S into
53831diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
53832index 72cb1cc..d0e3181 100644
53833--- a/fs/reiserfs/item_ops.c
53834+++ b/fs/reiserfs/item_ops.c
53835@@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_item *vi)
53836 vi->vi_index, vi->vi_type, vi->vi_ih);
53837 }
53838
53839-static struct item_operations stat_data_ops = {
53840+static const struct item_operations stat_data_ops = {
53841 .bytes_number = sd_bytes_number,
53842 .decrement_key = sd_decrement_key,
53843 .is_left_mergeable = sd_is_left_mergeable,
53844@@ -196,7 +196,7 @@ static void direct_print_vi(struct virtual_item *vi)
53845 vi->vi_index, vi->vi_type, vi->vi_ih);
53846 }
53847
53848-static struct item_operations direct_ops = {
53849+static const struct item_operations direct_ops = {
53850 .bytes_number = direct_bytes_number,
53851 .decrement_key = direct_decrement_key,
53852 .is_left_mergeable = direct_is_left_mergeable,
53853@@ -341,7 +341,7 @@ static void indirect_print_vi(struct virtual_item *vi)
53854 vi->vi_index, vi->vi_type, vi->vi_ih);
53855 }
53856
53857-static struct item_operations indirect_ops = {
53858+static const struct item_operations indirect_ops = {
53859 .bytes_number = indirect_bytes_number,
53860 .decrement_key = indirect_decrement_key,
53861 .is_left_mergeable = indirect_is_left_mergeable,
53862@@ -628,7 +628,7 @@ static void direntry_print_vi(struct virtual_item *vi)
53863 printk("\n");
53864 }
53865
53866-static struct item_operations direntry_ops = {
53867+static const struct item_operations direntry_ops = {
53868 .bytes_number = direntry_bytes_number,
53869 .decrement_key = direntry_decrement_key,
53870 .is_left_mergeable = direntry_is_left_mergeable,
53871@@ -724,7 +724,7 @@ static void errcatch_print_vi(struct virtual_item *vi)
53872 "Invalid item type observed, run fsck ASAP");
53873 }
53874
53875-static struct item_operations errcatch_ops = {
53876+static const struct item_operations errcatch_ops = {
53877 errcatch_bytes_number,
53878 errcatch_decrement_key,
53879 errcatch_is_left_mergeable,
53880@@ -746,7 +746,7 @@ static struct item_operations errcatch_ops = {
53881 #error Item types must use disk-format assigned values.
53882 #endif
53883
53884-struct item_operations *item_ops[TYPE_ANY + 1] = {
53885+const struct item_operations * const item_ops[TYPE_ANY + 1] = {
53886 &stat_data_ops,
53887 &indirect_ops,
53888 &direct_ops,
53889diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
53890index b5fe0aa..e0e25c4 100644
53891--- a/fs/reiserfs/journal.c
53892+++ b/fs/reiserfs/journal.c
53893@@ -2329,6 +2329,8 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
53894 struct buffer_head *bh;
53895 int i, j;
53896
53897+ pax_track_stack();
53898+
53899 bh = __getblk(dev, block, bufsize);
53900 if (buffer_uptodate(bh))
53901 return (bh);
53902diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
53903index 2715791..b8996db 100644
53904--- a/fs/reiserfs/namei.c
53905+++ b/fs/reiserfs/namei.c
53906@@ -1214,6 +1214,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
53907 unsigned long savelink = 1;
53908 struct timespec ctime;
53909
53910+ pax_track_stack();
53911+
53912 /* three balancings: (1) old name removal, (2) new name insertion
53913 and (3) maybe "save" link insertion
53914 stat data updates: (1) old directory,
53915diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
53916index 9229e55..3d2e3b7 100644
53917--- a/fs/reiserfs/procfs.c
53918+++ b/fs/reiserfs/procfs.c
53919@@ -123,7 +123,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
53920 "SMALL_TAILS " : "NO_TAILS ",
53921 replay_only(sb) ? "REPLAY_ONLY " : "",
53922 convert_reiserfs(sb) ? "CONV " : "",
53923- atomic_read(&r->s_generation_counter),
53924+ atomic_read_unchecked(&r->s_generation_counter),
53925 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
53926 SF(s_do_balance), SF(s_unneeded_left_neighbor),
53927 SF(s_good_search_by_key_reada), SF(s_bmaps),
53928@@ -309,6 +309,8 @@ static int show_journal(struct seq_file *m, struct super_block *sb)
53929 struct journal_params *jp = &rs->s_v1.s_journal;
53930 char b[BDEVNAME_SIZE];
53931
53932+ pax_track_stack();
53933+
53934 seq_printf(m, /* on-disk fields */
53935 "jp_journal_1st_block: \t%i\n"
53936 "jp_journal_dev: \t%s[%x]\n"
53937diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
53938index d036ee5..4c7dca1 100644
53939--- a/fs/reiserfs/stree.c
53940+++ b/fs/reiserfs/stree.c
53941@@ -1159,6 +1159,8 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
53942 int iter = 0;
53943 #endif
53944
53945+ pax_track_stack();
53946+
53947 BUG_ON(!th->t_trans_id);
53948
53949 init_tb_struct(th, &s_del_balance, sb, path,
53950@@ -1296,6 +1298,8 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
53951 int retval;
53952 int quota_cut_bytes = 0;
53953
53954+ pax_track_stack();
53955+
53956 BUG_ON(!th->t_trans_id);
53957
53958 le_key2cpu_key(&cpu_key, key);
53959@@ -1525,6 +1529,8 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
53960 int quota_cut_bytes;
53961 loff_t tail_pos = 0;
53962
53963+ pax_track_stack();
53964+
53965 BUG_ON(!th->t_trans_id);
53966
53967 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
53968@@ -1920,6 +1926,8 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
53969 int retval;
53970 int fs_gen;
53971
53972+ pax_track_stack();
53973+
53974 BUG_ON(!th->t_trans_id);
53975
53976 fs_gen = get_generation(inode->i_sb);
53977@@ -2007,6 +2015,8 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
53978 int fs_gen = 0;
53979 int quota_bytes = 0;
53980
53981+ pax_track_stack();
53982+
53983 BUG_ON(!th->t_trans_id);
53984
53985 if (inode) { /* Do we count quotas for item? */
53986diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
53987index 7cb1285..c726cd0 100644
53988--- a/fs/reiserfs/super.c
53989+++ b/fs/reiserfs/super.c
53990@@ -916,6 +916,8 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
53991 {.option_name = NULL}
53992 };
53993
53994+ pax_track_stack();
53995+
53996 *blocks = 0;
53997 if (!options || !*options)
53998 /* use default configuration: create tails, journaling on, no
53999diff --git a/fs/select.c b/fs/select.c
54000index fd38ce2..f5381b8 100644
54001--- a/fs/select.c
54002+++ b/fs/select.c
54003@@ -20,6 +20,7 @@
54004 #include <linux/module.h>
54005 #include <linux/slab.h>
54006 #include <linux/poll.h>
54007+#include <linux/security.h>
54008 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
54009 #include <linux/file.h>
54010 #include <linux/fdtable.h>
54011@@ -401,6 +402,8 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
54012 int retval, i, timed_out = 0;
54013 unsigned long slack = 0;
54014
54015+ pax_track_stack();
54016+
54017 rcu_read_lock();
54018 retval = max_select_fd(n, fds);
54019 rcu_read_unlock();
54020@@ -529,6 +532,8 @@ int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
54021 /* Allocate small arguments on the stack to save memory and be faster */
54022 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
54023
54024+ pax_track_stack();
54025+
54026 ret = -EINVAL;
54027 if (n < 0)
54028 goto out_nofds;
54029@@ -821,6 +826,9 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
54030 struct poll_list *walk = head;
54031 unsigned long todo = nfds;
54032
54033+ pax_track_stack();
54034+
54035+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
54036 if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
54037 return -EINVAL;
54038
54039diff --git a/fs/seq_file.c b/fs/seq_file.c
54040index eae7d9d..679f099 100644
54041--- a/fs/seq_file.c
54042+++ b/fs/seq_file.c
54043@@ -76,7 +76,8 @@ static int traverse(struct seq_file *m, loff_t offset)
54044 return 0;
54045 }
54046 if (!m->buf) {
54047- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
54048+ m->size = PAGE_SIZE;
54049+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
54050 if (!m->buf)
54051 return -ENOMEM;
54052 }
54053@@ -116,7 +117,8 @@ static int traverse(struct seq_file *m, loff_t offset)
54054 Eoverflow:
54055 m->op->stop(m, p);
54056 kfree(m->buf);
54057- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
54058+ m->size <<= 1;
54059+ m->buf = kmalloc(m->size, GFP_KERNEL);
54060 return !m->buf ? -ENOMEM : -EAGAIN;
54061 }
54062
54063@@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
54064 m->version = file->f_version;
54065 /* grab buffer if we didn't have one */
54066 if (!m->buf) {
54067- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
54068+ m->size = PAGE_SIZE;
54069+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
54070 if (!m->buf)
54071 goto Enomem;
54072 }
54073@@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
54074 goto Fill;
54075 m->op->stop(m, p);
54076 kfree(m->buf);
54077- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
54078+ m->size <<= 1;
54079+ m->buf = kmalloc(m->size, GFP_KERNEL);
54080 if (!m->buf)
54081 goto Enomem;
54082 m->count = 0;
54083@@ -551,7 +555,7 @@ static void single_stop(struct seq_file *p, void *v)
54084 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
54085 void *data)
54086 {
54087- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
54088+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
54089 int res = -ENOMEM;
54090
54091 if (op) {
54092diff --git a/fs/smbfs/proc.c b/fs/smbfs/proc.c
54093index 71c29b6..54694dd 100644
54094--- a/fs/smbfs/proc.c
54095+++ b/fs/smbfs/proc.c
54096@@ -266,9 +266,9 @@ int smb_setcodepage(struct smb_sb_info *server, struct smb_nls_codepage *cp)
54097
54098 out:
54099 if (server->local_nls != NULL && server->remote_nls != NULL)
54100- server->ops->convert = convert_cp;
54101+ *(void **)&server->ops->convert = convert_cp;
54102 else
54103- server->ops->convert = convert_memcpy;
54104+ *(void **)&server->ops->convert = convert_memcpy;
54105
54106 smb_unlock_server(server);
54107 return n;
54108@@ -933,9 +933,9 @@ smb_newconn(struct smb_sb_info *server, struct smb_conn_opt *opt)
54109
54110 /* FIXME: the win9x code wants to modify these ... (seek/trunc bug) */
54111 if (server->mnt->flags & SMB_MOUNT_OLDATTR) {
54112- server->ops->getattr = smb_proc_getattr_core;
54113+ *(void **)&server->ops->getattr = smb_proc_getattr_core;
54114 } else if (server->mnt->flags & SMB_MOUNT_DIRATTR) {
54115- server->ops->getattr = smb_proc_getattr_ff;
54116+ *(void **)&server->ops->getattr = smb_proc_getattr_ff;
54117 }
54118
54119 /* Decode server capabilities */
54120@@ -3439,7 +3439,7 @@ out:
54121 static void
54122 install_ops(struct smb_ops *dst, struct smb_ops *src)
54123 {
54124- memcpy(dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
54125+ memcpy((void *)dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
54126 }
54127
54128 /* < LANMAN2 */
54129diff --git a/fs/smbfs/symlink.c b/fs/smbfs/symlink.c
54130index 00b2909..2ace383 100644
54131--- a/fs/smbfs/symlink.c
54132+++ b/fs/smbfs/symlink.c
54133@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dentry *dentry, struct nameidata *nd)
54134
54135 static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
54136 {
54137- char *s = nd_get_link(nd);
54138+ const char *s = nd_get_link(nd);
54139 if (!IS_ERR(s))
54140 __putname(s);
54141 }
54142diff --git a/fs/splice.c b/fs/splice.c
54143index bb92b7c..5aa72b0 100644
54144--- a/fs/splice.c
54145+++ b/fs/splice.c
54146@@ -185,7 +185,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
54147 pipe_lock(pipe);
54148
54149 for (;;) {
54150- if (!pipe->readers) {
54151+ if (!atomic_read(&pipe->readers)) {
54152 send_sig(SIGPIPE, current, 0);
54153 if (!ret)
54154 ret = -EPIPE;
54155@@ -239,9 +239,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
54156 do_wakeup = 0;
54157 }
54158
54159- pipe->waiting_writers++;
54160+ atomic_inc(&pipe->waiting_writers);
54161 pipe_wait(pipe);
54162- pipe->waiting_writers--;
54163+ atomic_dec(&pipe->waiting_writers);
54164 }
54165
54166 pipe_unlock(pipe);
54167@@ -285,6 +285,8 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
54168 .spd_release = spd_release_page,
54169 };
54170
54171+ pax_track_stack();
54172+
54173 index = *ppos >> PAGE_CACHE_SHIFT;
54174 loff = *ppos & ~PAGE_CACHE_MASK;
54175 req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
54176@@ -521,7 +523,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
54177 old_fs = get_fs();
54178 set_fs(get_ds());
54179 /* The cast to a user pointer is valid due to the set_fs() */
54180- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
54181+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
54182 set_fs(old_fs);
54183
54184 return res;
54185@@ -536,7 +538,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
54186 old_fs = get_fs();
54187 set_fs(get_ds());
54188 /* The cast to a user pointer is valid due to the set_fs() */
54189- res = vfs_write(file, (const char __user *)buf, count, &pos);
54190+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
54191 set_fs(old_fs);
54192
54193 return res;
54194@@ -565,6 +567,8 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
54195 .spd_release = spd_release_page,
54196 };
54197
54198+ pax_track_stack();
54199+
54200 index = *ppos >> PAGE_CACHE_SHIFT;
54201 offset = *ppos & ~PAGE_CACHE_MASK;
54202 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
54203@@ -578,7 +582,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
54204 goto err;
54205
54206 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
54207- vec[i].iov_base = (void __user *) page_address(page);
54208+ vec[i].iov_base = (__force void __user *) page_address(page);
54209 vec[i].iov_len = this_len;
54210 pages[i] = page;
54211 spd.nr_pages++;
54212@@ -800,10 +804,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
54213 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
54214 {
54215 while (!pipe->nrbufs) {
54216- if (!pipe->writers)
54217+ if (!atomic_read(&pipe->writers))
54218 return 0;
54219
54220- if (!pipe->waiting_writers && sd->num_spliced)
54221+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
54222 return 0;
54223
54224 if (sd->flags & SPLICE_F_NONBLOCK)
54225@@ -1140,7 +1144,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
54226 * out of the pipe right after the splice_to_pipe(). So set
54227 * PIPE_READERS appropriately.
54228 */
54229- pipe->readers = 1;
54230+ atomic_set(&pipe->readers, 1);
54231
54232 current->splice_pipe = pipe;
54233 }
54234@@ -1593,6 +1597,8 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
54235 .spd_release = spd_release_page,
54236 };
54237
54238+ pax_track_stack();
54239+
54240 pipe = pipe_info(file->f_path.dentry->d_inode);
54241 if (!pipe)
54242 return -EBADF;
54243@@ -1701,9 +1707,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
54244 ret = -ERESTARTSYS;
54245 break;
54246 }
54247- if (!pipe->writers)
54248+ if (!atomic_read(&pipe->writers))
54249 break;
54250- if (!pipe->waiting_writers) {
54251+ if (!atomic_read(&pipe->waiting_writers)) {
54252 if (flags & SPLICE_F_NONBLOCK) {
54253 ret = -EAGAIN;
54254 break;
54255@@ -1735,7 +1741,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
54256 pipe_lock(pipe);
54257
54258 while (pipe->nrbufs >= PIPE_BUFFERS) {
54259- if (!pipe->readers) {
54260+ if (!atomic_read(&pipe->readers)) {
54261 send_sig(SIGPIPE, current, 0);
54262 ret = -EPIPE;
54263 break;
54264@@ -1748,9 +1754,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
54265 ret = -ERESTARTSYS;
54266 break;
54267 }
54268- pipe->waiting_writers++;
54269+ atomic_inc(&pipe->waiting_writers);
54270 pipe_wait(pipe);
54271- pipe->waiting_writers--;
54272+ atomic_dec(&pipe->waiting_writers);
54273 }
54274
54275 pipe_unlock(pipe);
54276@@ -1786,14 +1792,14 @@ retry:
54277 pipe_double_lock(ipipe, opipe);
54278
54279 do {
54280- if (!opipe->readers) {
54281+ if (!atomic_read(&opipe->readers)) {
54282 send_sig(SIGPIPE, current, 0);
54283 if (!ret)
54284 ret = -EPIPE;
54285 break;
54286 }
54287
54288- if (!ipipe->nrbufs && !ipipe->writers)
54289+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
54290 break;
54291
54292 /*
54293@@ -1893,7 +1899,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
54294 pipe_double_lock(ipipe, opipe);
54295
54296 do {
54297- if (!opipe->readers) {
54298+ if (!atomic_read(&opipe->readers)) {
54299 send_sig(SIGPIPE, current, 0);
54300 if (!ret)
54301 ret = -EPIPE;
54302@@ -1938,7 +1944,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
54303 * return EAGAIN if we have the potential of some data in the
54304 * future, otherwise just return 0
54305 */
54306- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
54307+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
54308 ret = -EAGAIN;
54309
54310 pipe_unlock(ipipe);
54311diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
54312index 7118a38..70af853 100644
54313--- a/fs/sysfs/file.c
54314+++ b/fs/sysfs/file.c
54315@@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
54316
54317 struct sysfs_open_dirent {
54318 atomic_t refcnt;
54319- atomic_t event;
54320+ atomic_unchecked_t event;
54321 wait_queue_head_t poll;
54322 struct list_head buffers; /* goes through sysfs_buffer.list */
54323 };
54324@@ -53,7 +53,7 @@ struct sysfs_buffer {
54325 size_t count;
54326 loff_t pos;
54327 char * page;
54328- struct sysfs_ops * ops;
54329+ const struct sysfs_ops * ops;
54330 struct mutex mutex;
54331 int needs_read_fill;
54332 int event;
54333@@ -75,7 +75,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
54334 {
54335 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
54336 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
54337- struct sysfs_ops * ops = buffer->ops;
54338+ const struct sysfs_ops * ops = buffer->ops;
54339 int ret = 0;
54340 ssize_t count;
54341
54342@@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
54343 if (!sysfs_get_active_two(attr_sd))
54344 return -ENODEV;
54345
54346- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
54347+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
54348 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
54349
54350 sysfs_put_active_two(attr_sd);
54351@@ -199,7 +199,7 @@ flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t
54352 {
54353 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
54354 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
54355- struct sysfs_ops * ops = buffer->ops;
54356+ const struct sysfs_ops * ops = buffer->ops;
54357 int rc;
54358
54359 /* need attr_sd for attr and ops, its parent for kobj */
54360@@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
54361 return -ENOMEM;
54362
54363 atomic_set(&new_od->refcnt, 0);
54364- atomic_set(&new_od->event, 1);
54365+ atomic_set_unchecked(&new_od->event, 1);
54366 init_waitqueue_head(&new_od->poll);
54367 INIT_LIST_HEAD(&new_od->buffers);
54368 goto retry;
54369@@ -335,7 +335,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
54370 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
54371 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
54372 struct sysfs_buffer *buffer;
54373- struct sysfs_ops *ops;
54374+ const struct sysfs_ops *ops;
54375 int error = -EACCES;
54376 char *p;
54377
54378@@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
54379
54380 sysfs_put_active_two(attr_sd);
54381
54382- if (buffer->event != atomic_read(&od->event))
54383+ if (buffer->event != atomic_read_unchecked(&od->event))
54384 goto trigger;
54385
54386 return DEFAULT_POLLMASK;
54387@@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
54388
54389 od = sd->s_attr.open;
54390 if (od) {
54391- atomic_inc(&od->event);
54392+ atomic_inc_unchecked(&od->event);
54393 wake_up_interruptible(&od->poll);
54394 }
54395
54396diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
54397index 4974995..c26609c 100644
54398--- a/fs/sysfs/mount.c
54399+++ b/fs/sysfs/mount.c
54400@@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
54401 .s_name = "",
54402 .s_count = ATOMIC_INIT(1),
54403 .s_flags = SYSFS_DIR,
54404+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54405+ .s_mode = S_IFDIR | S_IRWXU,
54406+#else
54407 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54408+#endif
54409 .s_ino = 1,
54410 };
54411
54412diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
54413index c5081ad..342ea86 100644
54414--- a/fs/sysfs/symlink.c
54415+++ b/fs/sysfs/symlink.c
54416@@ -204,7 +204,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
54417
54418 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
54419 {
54420- char *page = nd_get_link(nd);
54421+ const char *page = nd_get_link(nd);
54422 if (!IS_ERR(page))
54423 free_page((unsigned long)page);
54424 }
54425diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
54426index 1e06853..b06d325 100644
54427--- a/fs/udf/balloc.c
54428+++ b/fs/udf/balloc.c
54429@@ -172,9 +172,7 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
54430
54431 mutex_lock(&sbi->s_alloc_mutex);
54432 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
54433- if (bloc->logicalBlockNum < 0 ||
54434- (bloc->logicalBlockNum + count) >
54435- partmap->s_partition_len) {
54436+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
54437 udf_debug("%d < %d || %d + %d > %d\n",
54438 bloc->logicalBlockNum, 0, bloc->logicalBlockNum,
54439 count, partmap->s_partition_len);
54440@@ -436,9 +434,7 @@ static void udf_table_free_blocks(struct super_block *sb,
54441
54442 mutex_lock(&sbi->s_alloc_mutex);
54443 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
54444- if (bloc->logicalBlockNum < 0 ||
54445- (bloc->logicalBlockNum + count) >
54446- partmap->s_partition_len) {
54447+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
54448 udf_debug("%d < %d || %d + %d > %d\n",
54449 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
54450 partmap->s_partition_len);
54451diff --git a/fs/udf/inode.c b/fs/udf/inode.c
54452index 6d24c2c..fff470f 100644
54453--- a/fs/udf/inode.c
54454+++ b/fs/udf/inode.c
54455@@ -484,6 +484,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
54456 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
54457 int lastblock = 0;
54458
54459+ pax_track_stack();
54460+
54461 prev_epos.offset = udf_file_entry_alloc_offset(inode);
54462 prev_epos.block = iinfo->i_location;
54463 prev_epos.bh = NULL;
54464diff --git a/fs/udf/misc.c b/fs/udf/misc.c
54465index 9215700..bf1f68e 100644
54466--- a/fs/udf/misc.c
54467+++ b/fs/udf/misc.c
54468@@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
54469
54470 u8 udf_tag_checksum(const struct tag *t)
54471 {
54472- u8 *data = (u8 *)t;
54473+ const u8 *data = (const u8 *)t;
54474 u8 checksum = 0;
54475 int i;
54476 for (i = 0; i < sizeof(struct tag); ++i)
54477diff --git a/fs/utimes.c b/fs/utimes.c
54478index e4c75db..b4df0e0 100644
54479--- a/fs/utimes.c
54480+++ b/fs/utimes.c
54481@@ -1,6 +1,7 @@
54482 #include <linux/compiler.h>
54483 #include <linux/file.h>
54484 #include <linux/fs.h>
54485+#include <linux/security.h>
54486 #include <linux/linkage.h>
54487 #include <linux/mount.h>
54488 #include <linux/namei.h>
54489@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
54490 goto mnt_drop_write_and_out;
54491 }
54492 }
54493+
54494+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
54495+ error = -EACCES;
54496+ goto mnt_drop_write_and_out;
54497+ }
54498+
54499 mutex_lock(&inode->i_mutex);
54500 error = notify_change(path->dentry, &newattrs);
54501 mutex_unlock(&inode->i_mutex);
54502diff --git a/fs/xattr.c b/fs/xattr.c
54503index 6d4f6d3..cda3958 100644
54504--- a/fs/xattr.c
54505+++ b/fs/xattr.c
54506@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
54507 * Extended attribute SET operations
54508 */
54509 static long
54510-setxattr(struct dentry *d, const char __user *name, const void __user *value,
54511+setxattr(struct path *path, const char __user *name, const void __user *value,
54512 size_t size, int flags)
54513 {
54514 int error;
54515@@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
54516 return PTR_ERR(kvalue);
54517 }
54518
54519- error = vfs_setxattr(d, kname, kvalue, size, flags);
54520+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
54521+ error = -EACCES;
54522+ goto out;
54523+ }
54524+
54525+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
54526+out:
54527 kfree(kvalue);
54528 return error;
54529 }
54530@@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
54531 return error;
54532 error = mnt_want_write(path.mnt);
54533 if (!error) {
54534- error = setxattr(path.dentry, name, value, size, flags);
54535+ error = setxattr(&path, name, value, size, flags);
54536 mnt_drop_write(path.mnt);
54537 }
54538 path_put(&path);
54539@@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
54540 return error;
54541 error = mnt_want_write(path.mnt);
54542 if (!error) {
54543- error = setxattr(path.dentry, name, value, size, flags);
54544+ error = setxattr(&path, name, value, size, flags);
54545 mnt_drop_write(path.mnt);
54546 }
54547 path_put(&path);
54548@@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
54549 const void __user *,value, size_t, size, int, flags)
54550 {
54551 struct file *f;
54552- struct dentry *dentry;
54553 int error = -EBADF;
54554
54555 f = fget(fd);
54556 if (!f)
54557 return error;
54558- dentry = f->f_path.dentry;
54559- audit_inode(NULL, dentry);
54560+ audit_inode(NULL, f->f_path.dentry);
54561 error = mnt_want_write_file(f);
54562 if (!error) {
54563- error = setxattr(dentry, name, value, size, flags);
54564+ error = setxattr(&f->f_path, name, value, size, flags);
54565 mnt_drop_write(f->f_path.mnt);
54566 }
54567 fput(f);
54568diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
54569index c6ad7c7..f2847a7 100644
54570--- a/fs/xattr_acl.c
54571+++ b/fs/xattr_acl.c
54572@@ -17,8 +17,8 @@
54573 struct posix_acl *
54574 posix_acl_from_xattr(const void *value, size_t size)
54575 {
54576- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
54577- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
54578+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
54579+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
54580 int count;
54581 struct posix_acl *acl;
54582 struct posix_acl_entry *acl_e;
54583diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
54584index 942362f..88f96f5 100644
54585--- a/fs/xfs/linux-2.6/xfs_ioctl.c
54586+++ b/fs/xfs/linux-2.6/xfs_ioctl.c
54587@@ -134,7 +134,7 @@ xfs_find_handle(
54588 }
54589
54590 error = -EFAULT;
54591- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
54592+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
54593 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
54594 goto out_put;
54595
54596@@ -423,7 +423,7 @@ xfs_attrlist_by_handle(
54597 if (IS_ERR(dentry))
54598 return PTR_ERR(dentry);
54599
54600- kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
54601+ kbuf = kzalloc(al_hreq.buflen, GFP_KERNEL);
54602 if (!kbuf)
54603 goto out_dput;
54604
54605@@ -697,7 +697,7 @@ xfs_ioc_fsgeometry_v1(
54606 xfs_mount_t *mp,
54607 void __user *arg)
54608 {
54609- xfs_fsop_geom_t fsgeo;
54610+ xfs_fsop_geom_t fsgeo;
54611 int error;
54612
54613 error = xfs_fs_geometry(mp, &fsgeo, 3);
54614diff --git a/fs/xfs/linux-2.6/xfs_ioctl32.c b/fs/xfs/linux-2.6/xfs_ioctl32.c
54615index bad485a..479bd32 100644
54616--- a/fs/xfs/linux-2.6/xfs_ioctl32.c
54617+++ b/fs/xfs/linux-2.6/xfs_ioctl32.c
54618@@ -75,6 +75,7 @@ xfs_compat_ioc_fsgeometry_v1(
54619 xfs_fsop_geom_t fsgeo;
54620 int error;
54621
54622+ memset(&fsgeo, 0, sizeof(fsgeo));
54623 error = xfs_fs_geometry(mp, &fsgeo, 3);
54624 if (error)
54625 return -error;
54626diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c
54627index 1f3b4b8..6102f6d 100644
54628--- a/fs/xfs/linux-2.6/xfs_iops.c
54629+++ b/fs/xfs/linux-2.6/xfs_iops.c
54630@@ -468,7 +468,7 @@ xfs_vn_put_link(
54631 struct nameidata *nd,
54632 void *p)
54633 {
54634- char *s = nd_get_link(nd);
54635+ const char *s = nd_get_link(nd);
54636
54637 if (!IS_ERR(s))
54638 kfree(s);
54639diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
54640index 8971fb0..5fc1eb2 100644
54641--- a/fs/xfs/xfs_bmap.c
54642+++ b/fs/xfs/xfs_bmap.c
54643@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
54644 int nmap,
54645 int ret_nmap);
54646 #else
54647-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
54648+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
54649 #endif /* DEBUG */
54650
54651 #if defined(XFS_RW_TRACE)
54652diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
54653index e89734e..5e84d8d 100644
54654--- a/fs/xfs/xfs_dir2_sf.c
54655+++ b/fs/xfs/xfs_dir2_sf.c
54656@@ -779,7 +779,15 @@ xfs_dir2_sf_getdents(
54657 }
54658
54659 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
54660- if (filldir(dirent, sfep->name, sfep->namelen,
54661+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
54662+ char name[sfep->namelen];
54663+ memcpy(name, sfep->name, sfep->namelen);
54664+ if (filldir(dirent, name, sfep->namelen,
54665+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
54666+ *offset = off & 0x7fffffff;
54667+ return 0;
54668+ }
54669+ } else if (filldir(dirent, sfep->name, sfep->namelen,
54670 off & 0x7fffffff, ino, DT_UNKNOWN)) {
54671 *offset = off & 0x7fffffff;
54672 return 0;
54673diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
54674index 8f32f50..859e8a3 100644
54675--- a/fs/xfs/xfs_vnodeops.c
54676+++ b/fs/xfs/xfs_vnodeops.c
54677@@ -564,13 +564,17 @@ xfs_readlink(
54678
54679 xfs_ilock(ip, XFS_ILOCK_SHARED);
54680
54681- ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFLNK);
54682- ASSERT(ip->i_d.di_size <= MAXPATHLEN);
54683-
54684 pathlen = ip->i_d.di_size;
54685 if (!pathlen)
54686 goto out;
54687
54688+ if (pathlen > MAXPATHLEN) {
54689+ xfs_fs_cmn_err(CE_ALERT, mp, "%s: inode (%llu) symlink length (%d) too long",
54690+ __func__, (unsigned long long)ip->i_ino, pathlen);
54691+ ASSERT(0);
54692+ return XFS_ERROR(EFSCORRUPTED);
54693+ }
54694+
54695 if (ip->i_df.if_flags & XFS_IFINLINE) {
54696 memcpy(link, ip->i_df.if_u1.if_data, pathlen);
54697 link[pathlen] = '\0';
54698diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
54699new file mode 100644
54700index 0000000..f27a8e8
54701--- /dev/null
54702+++ b/grsecurity/Kconfig
54703@@ -0,0 +1,1036 @@
54704+#
54705+# grecurity configuration
54706+#
54707+
54708+menu "Grsecurity"
54709+
54710+config GRKERNSEC
54711+ bool "Grsecurity"
54712+ select CRYPTO
54713+ select CRYPTO_SHA256
54714+ help
54715+ If you say Y here, you will be able to configure many features
54716+ that will enhance the security of your system. It is highly
54717+ recommended that you say Y here and read through the help
54718+ for each option so that you fully understand the features and
54719+ can evaluate their usefulness for your machine.
54720+
54721+choice
54722+ prompt "Security Level"
54723+ depends on GRKERNSEC
54724+ default GRKERNSEC_CUSTOM
54725+
54726+config GRKERNSEC_LOW
54727+ bool "Low"
54728+ select GRKERNSEC_LINK
54729+ select GRKERNSEC_FIFO
54730+ select GRKERNSEC_RANDNET
54731+ select GRKERNSEC_DMESG
54732+ select GRKERNSEC_CHROOT
54733+ select GRKERNSEC_CHROOT_CHDIR
54734+
54735+ help
54736+ If you choose this option, several of the grsecurity options will
54737+ be enabled that will give you greater protection against a number
54738+ of attacks, while assuring that none of your software will have any
54739+ conflicts with the additional security measures. If you run a lot
54740+ of unusual software, or you are having problems with the higher
54741+ security levels, you should say Y here. With this option, the
54742+ following features are enabled:
54743+
54744+ - Linking restrictions
54745+ - FIFO restrictions
54746+ - Restricted dmesg
54747+ - Enforced chdir("/") on chroot
54748+ - Runtime module disabling
54749+
54750+config GRKERNSEC_MEDIUM
54751+ bool "Medium"
54752+ select PAX
54753+ select PAX_EI_PAX
54754+ select PAX_PT_PAX_FLAGS
54755+ select PAX_HAVE_ACL_FLAGS
54756+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
54757+ select GRKERNSEC_CHROOT
54758+ select GRKERNSEC_CHROOT_SYSCTL
54759+ select GRKERNSEC_LINK
54760+ select GRKERNSEC_FIFO
54761+ select GRKERNSEC_DMESG
54762+ select GRKERNSEC_RANDNET
54763+ select GRKERNSEC_FORKFAIL
54764+ select GRKERNSEC_TIME
54765+ select GRKERNSEC_SIGNAL
54766+ select GRKERNSEC_CHROOT
54767+ select GRKERNSEC_CHROOT_UNIX
54768+ select GRKERNSEC_CHROOT_MOUNT
54769+ select GRKERNSEC_CHROOT_PIVOT
54770+ select GRKERNSEC_CHROOT_DOUBLE
54771+ select GRKERNSEC_CHROOT_CHDIR
54772+ select GRKERNSEC_CHROOT_MKNOD
54773+ select GRKERNSEC_PROC
54774+ select GRKERNSEC_PROC_USERGROUP
54775+ select PAX_RANDUSTACK
54776+ select PAX_ASLR
54777+ select PAX_RANDMMAP
54778+ select PAX_REFCOUNT if (X86 || SPARC64)
54779+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
54780+
54781+ help
54782+ If you say Y here, several features in addition to those included
54783+ in the low additional security level will be enabled. These
54784+ features provide even more security to your system, though in rare
54785+ cases they may be incompatible with very old or poorly written
54786+ software. If you enable this option, make sure that your auth
54787+ service (identd) is running as gid 1001. With this option,
54788+ the following features (in addition to those provided in the
54789+ low additional security level) will be enabled:
54790+
54791+ - Failed fork logging
54792+ - Time change logging
54793+ - Signal logging
54794+ - Deny mounts in chroot
54795+ - Deny double chrooting
54796+ - Deny sysctl writes in chroot
54797+ - Deny mknod in chroot
54798+ - Deny access to abstract AF_UNIX sockets out of chroot
54799+ - Deny pivot_root in chroot
54800+ - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
54801+ - /proc restrictions with special GID set to 10 (usually wheel)
54802+ - Address Space Layout Randomization (ASLR)
54803+ - Prevent exploitation of most refcount overflows
54804+ - Bounds checking of copying between the kernel and userland
54805+
54806+config GRKERNSEC_HIGH
54807+ bool "High"
54808+ select GRKERNSEC_LINK
54809+ select GRKERNSEC_FIFO
54810+ select GRKERNSEC_DMESG
54811+ select GRKERNSEC_FORKFAIL
54812+ select GRKERNSEC_TIME
54813+ select GRKERNSEC_SIGNAL
54814+ select GRKERNSEC_CHROOT
54815+ select GRKERNSEC_CHROOT_SHMAT
54816+ select GRKERNSEC_CHROOT_UNIX
54817+ select GRKERNSEC_CHROOT_MOUNT
54818+ select GRKERNSEC_CHROOT_FCHDIR
54819+ select GRKERNSEC_CHROOT_PIVOT
54820+ select GRKERNSEC_CHROOT_DOUBLE
54821+ select GRKERNSEC_CHROOT_CHDIR
54822+ select GRKERNSEC_CHROOT_MKNOD
54823+ select GRKERNSEC_CHROOT_CAPS
54824+ select GRKERNSEC_CHROOT_SYSCTL
54825+ select GRKERNSEC_CHROOT_FINDTASK
54826+ select GRKERNSEC_SYSFS_RESTRICT
54827+ select GRKERNSEC_PROC
54828+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
54829+ select GRKERNSEC_HIDESYM
54830+ select GRKERNSEC_BRUTE
54831+ select GRKERNSEC_PROC_USERGROUP
54832+ select GRKERNSEC_KMEM
54833+ select GRKERNSEC_RESLOG
54834+ select GRKERNSEC_RANDNET
54835+ select GRKERNSEC_PROC_ADD
54836+ select GRKERNSEC_CHROOT_CHMOD
54837+ select GRKERNSEC_CHROOT_NICE
54838+ select GRKERNSEC_AUDIT_MOUNT
54839+ select GRKERNSEC_MODHARDEN if (MODULES)
54840+ select GRKERNSEC_HARDEN_PTRACE
54841+ select GRKERNSEC_VM86 if (X86_32)
54842+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
54843+ select PAX
54844+ select PAX_RANDUSTACK
54845+ select PAX_ASLR
54846+ select PAX_RANDMMAP
54847+ select PAX_NOEXEC
54848+ select PAX_MPROTECT
54849+ select PAX_EI_PAX
54850+ select PAX_PT_PAX_FLAGS
54851+ select PAX_HAVE_ACL_FLAGS
54852+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
54853+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
54854+ select PAX_RANDKSTACK if (X86_TSC && X86)
54855+ select PAX_SEGMEXEC if (X86_32)
54856+ select PAX_PAGEEXEC
54857+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
54858+ select PAX_EMUTRAMP if (PARISC)
54859+ select PAX_EMUSIGRT if (PARISC)
54860+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
54861+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
54862+ select PAX_REFCOUNT if (X86 || SPARC64)
54863+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
54864+ help
54865+ If you say Y here, many of the features of grsecurity will be
54866+ enabled, which will protect you against many kinds of attacks
54867+ against your system. The heightened security comes at a cost
54868+ of an increased chance of incompatibilities with rare software
54869+ on your machine. Since this security level enables PaX, you should
54870+ view <http://pax.grsecurity.net> and read about the PaX
54871+ project. While you are there, download chpax and run it on
54872+ binaries that cause problems with PaX. Also remember that
54873+ since the /proc restrictions are enabled, you must run your
54874+ identd as gid 1001. This security level enables the following
54875+ features in addition to those listed in the low and medium
54876+ security levels:
54877+
54878+ - Additional /proc restrictions
54879+ - Chmod restrictions in chroot
54880+ - No signals, ptrace, or viewing of processes outside of chroot
54881+ - Capability restrictions in chroot
54882+ - Deny fchdir out of chroot
54883+ - Priority restrictions in chroot
54884+ - Segmentation-based implementation of PaX
54885+ - Mprotect restrictions
54886+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
54887+ - Kernel stack randomization
54888+ - Mount/unmount/remount logging
54889+ - Kernel symbol hiding
54890+ - Hardening of module auto-loading
54891+ - Ptrace restrictions
54892+ - Restricted vm86 mode
54893+ - Restricted sysfs/debugfs
54894+ - Active kernel exploit response
54895+
54896+config GRKERNSEC_CUSTOM
54897+ bool "Custom"
54898+ help
54899+ If you say Y here, you will be able to configure every grsecurity
54900+ option, which allows you to enable many more features that aren't
54901+ covered in the basic security levels. These additional features
54902+ include TPE, socket restrictions, and the sysctl system for
54903+ grsecurity. It is advised that you read through the help for
54904+ each option to determine its usefulness in your situation.
54905+
54906+endchoice
54907+
54908+menu "Address Space Protection"
54909+depends on GRKERNSEC
54910+
54911+config GRKERNSEC_KMEM
54912+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
54913+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
54914+ help
54915+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
54916+ be written to or read from to modify or leak the contents of the running
54917+ kernel. /dev/port will also not be allowed to be opened. If you have module
54918+ support disabled, enabling this will close up four ways that are
54919+ currently used to insert malicious code into the running kernel.
54920+ Even with all these features enabled, we still highly recommend that
54921+ you use the RBAC system, as it is still possible for an attacker to
54922+ modify the running kernel through privileged I/O granted by ioperm/iopl.
54923+ If you are not using XFree86, you may be able to stop this additional
54924+ case by enabling the 'Disable privileged I/O' option. Though nothing
54925+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
54926+ but only to video memory, which is the only writing we allow in this
54927+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
54928+ not be allowed to mprotect it with PROT_WRITE later.
54929+ It is highly recommended that you say Y here if you meet all the
54930+ conditions above.
54931+
54932+config GRKERNSEC_VM86
54933+ bool "Restrict VM86 mode"
54934+ depends on X86_32
54935+
54936+ help
54937+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
54938+ make use of a special execution mode on 32bit x86 processors called
54939+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
54940+ video cards and will still work with this option enabled. The purpose
54941+ of the option is to prevent exploitation of emulation errors in
54942+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
54943+ Nearly all users should be able to enable this option.
54944+
54945+config GRKERNSEC_IO
54946+ bool "Disable privileged I/O"
54947+ depends on X86
54948+ select RTC_CLASS
54949+ select RTC_INTF_DEV
54950+ select RTC_DRV_CMOS
54951+
54952+ help
54953+ If you say Y here, all ioperm and iopl calls will return an error.
54954+ Ioperm and iopl can be used to modify the running kernel.
54955+ Unfortunately, some programs need this access to operate properly,
54956+ the most notable of which are XFree86 and hwclock. hwclock can be
54957+ remedied by having RTC support in the kernel, so real-time
54958+ clock support is enabled if this option is enabled, to ensure
54959+ that hwclock operates correctly. XFree86 still will not
54960+ operate correctly with this option enabled, so DO NOT CHOOSE Y
54961+ IF YOU USE XFree86. If you use XFree86 and you still want to
54962+ protect your kernel against modification, use the RBAC system.
54963+
54964+config GRKERNSEC_PROC_MEMMAP
54965+ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
54966+ default y if (PAX_NOEXEC || PAX_ASLR)
54967+ depends on PAX_NOEXEC || PAX_ASLR
54968+ help
54969+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
54970+ give no information about the addresses of its mappings if
54971+ PaX features that rely on random addresses are enabled on the task.
54972+ If you use PaX it is greatly recommended that you say Y here as it
54973+ closes up a hole that makes the full ASLR useless for suid
54974+ binaries.
54975+
54976+config GRKERNSEC_BRUTE
54977+ bool "Deter exploit bruteforcing"
54978+ help
54979+ If you say Y here, attempts to bruteforce exploits against forking
54980+ daemons such as apache or sshd, as well as against suid/sgid binaries
54981+ will be deterred. When a child of a forking daemon is killed by PaX
54982+ or crashes due to an illegal instruction or other suspicious signal,
54983+ the parent process will be delayed 30 seconds upon every subsequent
54984+ fork until the administrator is able to assess the situation and
54985+ restart the daemon.
54986+ In the suid/sgid case, the attempt is logged, the user has all their
54987+ processes terminated, and they are prevented from executing any further
54988+ processes for 15 minutes.
54989+ It is recommended that you also enable signal logging in the auditing
54990+ section so that logs are generated when a process triggers a suspicious
54991+ signal.
54992+ If the sysctl option is enabled, a sysctl option with name
54993+ "deter_bruteforce" is created.
54994+
54995+config GRKERNSEC_MODHARDEN
54996+ bool "Harden module auto-loading"
54997+ depends on MODULES
54998+ help
54999+ If you say Y here, module auto-loading in response to use of some
55000+ feature implemented by an unloaded module will be restricted to
55001+ root users. Enabling this option helps defend against attacks
55002+ by unprivileged users who abuse the auto-loading behavior to
55003+ cause a vulnerable module to load that is then exploited.
55004+
55005+ If this option prevents a legitimate use of auto-loading for a
55006+ non-root user, the administrator can execute modprobe manually
55007+ with the exact name of the module mentioned in the alert log.
55008+ Alternatively, the administrator can add the module to the list
55009+ of modules loaded at boot by modifying init scripts.
55010+
55011+ Modification of init scripts will most likely be needed on
55012+ Ubuntu servers with encrypted home directory support enabled,
55013+ as the first non-root user logging in will cause the ecb(aes),
55014+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
55015+
55016+config GRKERNSEC_HIDESYM
55017+ bool "Hide kernel symbols"
55018+ help
55019+ If you say Y here, getting information on loaded modules, and
55020+ displaying all kernel symbols through a syscall will be restricted
55021+ to users with CAP_SYS_MODULE. For software compatibility reasons,
55022+ /proc/kallsyms will be restricted to the root user. The RBAC
55023+ system can hide that entry even from root.
55024+
55025+ This option also prevents leaking of kernel addresses through
55026+ several /proc entries.
55027+
55028+ Note that this option is only effective provided the following
55029+ conditions are met:
55030+ 1) The kernel using grsecurity is not precompiled by some distribution
55031+ 2) You have also enabled GRKERNSEC_DMESG
55032+ 3) You are using the RBAC system and hiding other files such as your
55033+ kernel image and System.map. Alternatively, enabling this option
55034+ causes the permissions on /boot, /lib/modules, and the kernel
55035+ source directory to change at compile time to prevent
55036+ reading by non-root users.
55037+ If the above conditions are met, this option will aid in providing a
55038+ useful protection against local kernel exploitation of overflows
55039+ and arbitrary read/write vulnerabilities.
55040+
55041+config GRKERNSEC_KERN_LOCKOUT
55042+ bool "Active kernel exploit response"
55043+ depends on X86 || ARM || PPC || SPARC
55044+ help
55045+ If you say Y here, when a PaX alert is triggered due to suspicious
55046+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
55047+ or an OOPs occurs due to bad memory accesses, instead of just
55048+ terminating the offending process (and potentially allowing
55049+ a subsequent exploit from the same user), we will take one of two
55050+ actions:
55051+ If the user was root, we will panic the system
55052+ If the user was non-root, we will log the attempt, terminate
55053+ all processes owned by the user, then prevent them from creating
55054+ any new processes until the system is restarted
55055+ This deters repeated kernel exploitation/bruteforcing attempts
55056+ and is useful for later forensics.
55057+
55058+endmenu
55059+menu "Role Based Access Control Options"
55060+depends on GRKERNSEC
55061+
55062+config GRKERNSEC_RBAC_DEBUG
55063+ bool
55064+
55065+config GRKERNSEC_NO_RBAC
55066+ bool "Disable RBAC system"
55067+ help
55068+ If you say Y here, the /dev/grsec device will be removed from the kernel,
55069+ preventing the RBAC system from being enabled. You should only say Y
55070+ here if you have no intention of using the RBAC system, so as to prevent
55071+ an attacker with root access from misusing the RBAC system to hide files
55072+ and processes when loadable module support and /dev/[k]mem have been
55073+ locked down.
55074+
55075+config GRKERNSEC_ACL_HIDEKERN
55076+ bool "Hide kernel processes"
55077+ help
55078+ If you say Y here, all kernel threads will be hidden to all
55079+ processes but those whose subject has the "view hidden processes"
55080+ flag.
55081+
55082+config GRKERNSEC_ACL_MAXTRIES
55083+ int "Maximum tries before password lockout"
55084+ default 3
55085+ help
55086+ This option enforces the maximum number of times a user can attempt
55087+ to authorize themselves with the grsecurity RBAC system before being
55088+ denied the ability to attempt authorization again for a specified time.
55089+ The lower the number, the harder it will be to brute-force a password.
55090+
55091+config GRKERNSEC_ACL_TIMEOUT
55092+ int "Time to wait after max password tries, in seconds"
55093+ default 30
55094+ help
55095+ This option specifies the time the user must wait after attempting to
55096+ authorize to the RBAC system with the maximum number of invalid
55097+ passwords. The higher the number, the harder it will be to brute-force
55098+ a password.
55099+
55100+endmenu
55101+menu "Filesystem Protections"
55102+depends on GRKERNSEC
55103+
55104+config GRKERNSEC_PROC
55105+ bool "Proc restrictions"
55106+ help
55107+ If you say Y here, the permissions of the /proc filesystem
55108+ will be altered to enhance system security and privacy. You MUST
55109+ choose either a user only restriction or a user and group restriction.
55110+ Depending upon the option you choose, you can either restrict users to
55111+ see only the processes they themselves run, or choose a group that can
55112+ view all processes and files normally restricted to root if you choose
55113+ the "restrict to user only" option. NOTE: If you're running identd as
55114+ a non-root user, you will have to run it as the group you specify here.
55115+
55116+config GRKERNSEC_PROC_USER
55117+ bool "Restrict /proc to user only"
55118+ depends on GRKERNSEC_PROC
55119+ help
55120+ If you say Y here, non-root users will only be able to view their own
55121+ processes, and restricts them from viewing network-related information,
55122+ and viewing kernel symbol and module information.
55123+
55124+config GRKERNSEC_PROC_USERGROUP
55125+ bool "Allow special group"
55126+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
55127+ help
55128+ If you say Y here, you will be able to select a group that will be
55129+ able to view all processes and network-related information. If you've
55130+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
55131+ remain hidden. This option is useful if you want to run identd as
55132+ a non-root user.
55133+
55134+config GRKERNSEC_PROC_GID
55135+ int "GID for special group"
55136+ depends on GRKERNSEC_PROC_USERGROUP
55137+ default 1001
55138+
55139+config GRKERNSEC_PROC_ADD
55140+ bool "Additional restrictions"
55141+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
55142+ help
55143+ If you say Y here, additional restrictions will be placed on
55144+ /proc that keep normal users from viewing device information and
55145+ slabinfo information that could be useful for exploits.
55146+
55147+config GRKERNSEC_LINK
55148+ bool "Linking restrictions"
55149+ help
55150+ If you say Y here, /tmp race exploits will be prevented, since users
55151+ will no longer be able to follow symlinks owned by other users in
55152+ world-writable +t directories (e.g. /tmp), unless the owner of the
55153+ symlink is the owner of the directory. users will also not be
55154+ able to hardlink to files they do not own. If the sysctl option is
55155+ enabled, a sysctl option with name "linking_restrictions" is created.
55156+
55157+config GRKERNSEC_FIFO
55158+ bool "FIFO restrictions"
55159+ help
55160+ If you say Y here, users will not be able to write to FIFOs they don't
55161+ own in world-writable +t directories (e.g. /tmp), unless the owner of
55162+ the FIFO is the same owner of the directory it's held in. If the sysctl
55163+ option is enabled, a sysctl option with name "fifo_restrictions" is
55164+ created.
55165+
55166+config GRKERNSEC_SYSFS_RESTRICT
55167+ bool "Sysfs/debugfs restriction"
55168+ depends on SYSFS
55169+ help
55170+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
55171+ any filesystem normally mounted under it (e.g. debugfs) will only
55172+ be accessible by root. These filesystems generally provide access
55173+ to hardware and debug information that isn't appropriate for unprivileged
55174+ users of the system. Sysfs and debugfs have also become a large source
55175+ of new vulnerabilities, ranging from infoleaks to local compromise.
55176+ There has been very little oversight with an eye toward security involved
55177+ in adding new exporters of information to these filesystems, so their
55178+ use is discouraged.
55179+ This option is equivalent to a chmod 0700 of the mount paths.
55180+
55181+config GRKERNSEC_ROFS
55182+ bool "Runtime read-only mount protection"
55183+ help
55184+ If you say Y here, a sysctl option with name "romount_protect" will
55185+ be created. By setting this option to 1 at runtime, filesystems
55186+ will be protected in the following ways:
55187+ * No new writable mounts will be allowed
55188+ * Existing read-only mounts won't be able to be remounted read/write
55189+ * Write operations will be denied on all block devices
55190+ This option acts independently of grsec_lock: once it is set to 1,
55191+ it cannot be turned off. Therefore, please be mindful of the resulting
55192+ behavior if this option is enabled in an init script on a read-only
55193+ filesystem. This feature is mainly intended for secure embedded systems.
55194+
55195+config GRKERNSEC_CHROOT
55196+ bool "Chroot jail restrictions"
55197+ help
55198+ If you say Y here, you will be able to choose several options that will
55199+ make breaking out of a chrooted jail much more difficult. If you
55200+ encounter no software incompatibilities with the following options, it
55201+ is recommended that you enable each one.
55202+
55203+config GRKERNSEC_CHROOT_MOUNT
55204+ bool "Deny mounts"
55205+ depends on GRKERNSEC_CHROOT
55206+ help
55207+ If you say Y here, processes inside a chroot will not be able to
55208+ mount or remount filesystems. If the sysctl option is enabled, a
55209+ sysctl option with name "chroot_deny_mount" is created.
55210+
55211+config GRKERNSEC_CHROOT_DOUBLE
55212+ bool "Deny double-chroots"
55213+ depends on GRKERNSEC_CHROOT
55214+ help
55215+ If you say Y here, processes inside a chroot will not be able to chroot
55216+ again outside the chroot. This is a widely used method of breaking
55217+ out of a chroot jail and should not be allowed. If the sysctl
55218+ option is enabled, a sysctl option with name
55219+ "chroot_deny_chroot" is created.
55220+
55221+config GRKERNSEC_CHROOT_PIVOT
55222+ bool "Deny pivot_root in chroot"
55223+ depends on GRKERNSEC_CHROOT
55224+ help
55225+ If you say Y here, processes inside a chroot will not be able to use
55226+ a function called pivot_root() that was introduced in Linux 2.3.41. It
55227+ works similar to chroot in that it changes the root filesystem. This
55228+ function could be misused in a chrooted process to attempt to break out
55229+ of the chroot, and therefore should not be allowed. If the sysctl
55230+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
55231+ created.
55232+
55233+config GRKERNSEC_CHROOT_CHDIR
55234+ bool "Enforce chdir(\"/\") on all chroots"
55235+ depends on GRKERNSEC_CHROOT
55236+ help
55237+ If you say Y here, the current working directory of all newly-chrooted
55238+ applications will be set to the the root directory of the chroot.
55239+ The man page on chroot(2) states:
55240+ Note that this call does not change the current working
55241+ directory, so that `.' can be outside the tree rooted at
55242+ `/'. In particular, the super-user can escape from a
55243+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
55244+
55245+ It is recommended that you say Y here, since it's not known to break
55246+ any software. If the sysctl option is enabled, a sysctl option with
55247+ name "chroot_enforce_chdir" is created.
55248+
55249+config GRKERNSEC_CHROOT_CHMOD
55250+ bool "Deny (f)chmod +s"
55251+ depends on GRKERNSEC_CHROOT
55252+ help
55253+ If you say Y here, processes inside a chroot will not be able to chmod
55254+ or fchmod files to make them have suid or sgid bits. This protects
55255+ against another published method of breaking a chroot. If the sysctl
55256+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
55257+ created.
55258+
55259+config GRKERNSEC_CHROOT_FCHDIR
55260+ bool "Deny fchdir out of chroot"
55261+ depends on GRKERNSEC_CHROOT
55262+ help
55263+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
55264+ to a file descriptor of the chrooting process that points to a directory
55265+ outside the filesystem will be stopped. If the sysctl option
55266+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
55267+
55268+config GRKERNSEC_CHROOT_MKNOD
55269+ bool "Deny mknod"
55270+ depends on GRKERNSEC_CHROOT
55271+ help
55272+ If you say Y here, processes inside a chroot will not be allowed to
55273+ mknod. The problem with using mknod inside a chroot is that it
55274+ would allow an attacker to create a device entry that is the same
55275+ as one on the physical root of your system, which could range from
55276+ anything from the console device to a device for your harddrive (which
55277+ they could then use to wipe the drive or steal data). It is recommended
55278+ that you say Y here, unless you run into software incompatibilities.
55279+ If the sysctl option is enabled, a sysctl option with name
55280+ "chroot_deny_mknod" is created.
55281+
55282+config GRKERNSEC_CHROOT_SHMAT
55283+ bool "Deny shmat() out of chroot"
55284+ depends on GRKERNSEC_CHROOT
55285+ help
55286+ If you say Y here, processes inside a chroot will not be able to attach
55287+ to shared memory segments that were created outside of the chroot jail.
55288+ It is recommended that you say Y here. If the sysctl option is enabled,
55289+ a sysctl option with name "chroot_deny_shmat" is created.
55290+
55291+config GRKERNSEC_CHROOT_UNIX
55292+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
55293+ depends on GRKERNSEC_CHROOT
55294+ help
55295+ If you say Y here, processes inside a chroot will not be able to
55296+ connect to abstract (meaning not belonging to a filesystem) Unix
55297+ domain sockets that were bound outside of a chroot. It is recommended
55298+ that you say Y here. If the sysctl option is enabled, a sysctl option
55299+ with name "chroot_deny_unix" is created.
55300+
55301+config GRKERNSEC_CHROOT_FINDTASK
55302+ bool "Protect outside processes"
55303+ depends on GRKERNSEC_CHROOT
55304+ help
55305+ If you say Y here, processes inside a chroot will not be able to
55306+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
55307+ getsid, or view any process outside of the chroot. If the sysctl
55308+ option is enabled, a sysctl option with name "chroot_findtask" is
55309+ created.
55310+
55311+config GRKERNSEC_CHROOT_NICE
55312+ bool "Restrict priority changes"
55313+ depends on GRKERNSEC_CHROOT
55314+ help
55315+ If you say Y here, processes inside a chroot will not be able to raise
55316+ the priority of processes in the chroot, or alter the priority of
55317+ processes outside the chroot. This provides more security than simply
55318+ removing CAP_SYS_NICE from the process' capability set. If the
55319+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
55320+ is created.
55321+
55322+config GRKERNSEC_CHROOT_SYSCTL
55323+ bool "Deny sysctl writes"
55324+ depends on GRKERNSEC_CHROOT
55325+ help
55326+ If you say Y here, an attacker in a chroot will not be able to
55327+ write to sysctl entries, either by sysctl(2) or through a /proc
55328+ interface. It is strongly recommended that you say Y here. If the
55329+ sysctl option is enabled, a sysctl option with name
55330+ "chroot_deny_sysctl" is created.
55331+
55332+config GRKERNSEC_CHROOT_CAPS
55333+ bool "Capability restrictions"
55334+ depends on GRKERNSEC_CHROOT
55335+ help
55336+ If you say Y here, the capabilities on all processes within a
55337+ chroot jail will be lowered to stop module insertion, raw i/o,
55338+ system and net admin tasks, rebooting the system, modifying immutable
55339+ files, modifying IPC owned by another, and changing the system time.
55340+ This is left an option because it can break some apps. Disable this
55341+ if your chrooted apps are having problems performing those kinds of
55342+ tasks. If the sysctl option is enabled, a sysctl option with
55343+ name "chroot_caps" is created.
55344+
55345+endmenu
55346+menu "Kernel Auditing"
55347+depends on GRKERNSEC
55348+
55349+config GRKERNSEC_AUDIT_GROUP
55350+ bool "Single group for auditing"
55351+ help
55352+ If you say Y here, the exec, chdir, and (un)mount logging features
55353+ will only operate on a group you specify. This option is recommended
55354+ if you only want to watch certain users instead of having a large
55355+ amount of logs from the entire system. If the sysctl option is enabled,
55356+ a sysctl option with name "audit_group" is created.
55357+
55358+config GRKERNSEC_AUDIT_GID
55359+ int "GID for auditing"
55360+ depends on GRKERNSEC_AUDIT_GROUP
55361+ default 1007
55362+
55363+config GRKERNSEC_EXECLOG
55364+ bool "Exec logging"
55365+ help
55366+ If you say Y here, all execve() calls will be logged (since the
55367+ other exec*() calls are frontends to execve(), all execution
55368+ will be logged). Useful for shell-servers that like to keep track
55369+ of their users. If the sysctl option is enabled, a sysctl option with
55370+ name "exec_logging" is created.
55371+ WARNING: This option when enabled will produce a LOT of logs, especially
55372+ on an active system.
55373+
55374+config GRKERNSEC_RESLOG
55375+ bool "Resource logging"
55376+ help
55377+ If you say Y here, all attempts to overstep resource limits will
55378+ be logged with the resource name, the requested size, and the current
55379+ limit. It is highly recommended that you say Y here. If the sysctl
55380+ option is enabled, a sysctl option with name "resource_logging" is
55381+ created. If the RBAC system is enabled, the sysctl value is ignored.
55382+
55383+config GRKERNSEC_CHROOT_EXECLOG
55384+ bool "Log execs within chroot"
55385+ help
55386+ If you say Y here, all executions inside a chroot jail will be logged
55387+ to syslog. This can cause a large amount of logs if certain
55388+ applications (eg. djb's daemontools) are installed on the system, and
55389+ is therefore left as an option. If the sysctl option is enabled, a
55390+ sysctl option with name "chroot_execlog" is created.
55391+
55392+config GRKERNSEC_AUDIT_PTRACE
55393+ bool "Ptrace logging"
55394+ help
55395+ If you say Y here, all attempts to attach to a process via ptrace
55396+ will be logged. If the sysctl option is enabled, a sysctl option
55397+ with name "audit_ptrace" is created.
55398+
55399+config GRKERNSEC_AUDIT_CHDIR
55400+ bool "Chdir logging"
55401+ help
55402+ If you say Y here, all chdir() calls will be logged. If the sysctl
55403+ option is enabled, a sysctl option with name "audit_chdir" is created.
55404+
55405+config GRKERNSEC_AUDIT_MOUNT
55406+ bool "(Un)Mount logging"
55407+ help
55408+ If you say Y here, all mounts and unmounts will be logged. If the
55409+ sysctl option is enabled, a sysctl option with name "audit_mount" is
55410+ created.
55411+
55412+config GRKERNSEC_SIGNAL
55413+ bool "Signal logging"
55414+ help
55415+ If you say Y here, certain important signals will be logged, such as
55416+ SIGSEGV, which will as a result inform you of when a error in a program
55417+ occurred, which in some cases could mean a possible exploit attempt.
55418+ If the sysctl option is enabled, a sysctl option with name
55419+ "signal_logging" is created.
55420+
55421+config GRKERNSEC_FORKFAIL
55422+ bool "Fork failure logging"
55423+ help
55424+ If you say Y here, all failed fork() attempts will be logged.
55425+ This could suggest a fork bomb, or someone attempting to overstep
55426+ their process limit. If the sysctl option is enabled, a sysctl option
55427+ with name "forkfail_logging" is created.
55428+
55429+config GRKERNSEC_TIME
55430+ bool "Time change logging"
55431+ help
55432+ If you say Y here, any changes of the system clock will be logged.
55433+ If the sysctl option is enabled, a sysctl option with name
55434+ "timechange_logging" is created.
55435+
55436+config GRKERNSEC_PROC_IPADDR
55437+ bool "/proc/<pid>/ipaddr support"
55438+ help
55439+ If you say Y here, a new entry will be added to each /proc/<pid>
55440+ directory that contains the IP address of the person using the task.
55441+ The IP is carried across local TCP and AF_UNIX stream sockets.
55442+ This information can be useful for IDS/IPSes to perform remote response
55443+ to a local attack. The entry is readable by only the owner of the
55444+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
55445+ the RBAC system), and thus does not create privacy concerns.
55446+
55447+config GRKERNSEC_RWXMAP_LOG
55448+ bool 'Denied RWX mmap/mprotect logging'
55449+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
55450+ help
55451+ If you say Y here, calls to mmap() and mprotect() with explicit
55452+ usage of PROT_WRITE and PROT_EXEC together will be logged when
55453+ denied by the PAX_MPROTECT feature. If the sysctl option is
55454+ enabled, a sysctl option with name "rwxmap_logging" is created.
55455+
55456+config GRKERNSEC_AUDIT_TEXTREL
55457+ bool 'ELF text relocations logging (READ HELP)'
55458+ depends on PAX_MPROTECT
55459+ help
55460+ If you say Y here, text relocations will be logged with the filename
55461+ of the offending library or binary. The purpose of the feature is
55462+ to help Linux distribution developers get rid of libraries and
55463+ binaries that need text relocations which hinder the future progress
55464+ of PaX. Only Linux distribution developers should say Y here, and
55465+ never on a production machine, as this option creates an information
55466+ leak that could aid an attacker in defeating the randomization of
55467+ a single memory region. If the sysctl option is enabled, a sysctl
55468+ option with name "audit_textrel" is created.
55469+
55470+endmenu
55471+
55472+menu "Executable Protections"
55473+depends on GRKERNSEC
55474+
55475+config GRKERNSEC_DMESG
55476+ bool "Dmesg(8) restriction"
55477+ help
55478+ If you say Y here, non-root users will not be able to use dmesg(8)
55479+ to view up to the last 4kb of messages in the kernel's log buffer.
55480+ The kernel's log buffer often contains kernel addresses and other
55481+ identifying information useful to an attacker in fingerprinting a
55482+ system for a targeted exploit.
55483+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
55484+ created.
55485+
55486+config GRKERNSEC_HARDEN_PTRACE
55487+ bool "Deter ptrace-based process snooping"
55488+ help
55489+ If you say Y here, TTY sniffers and other malicious monitoring
55490+ programs implemented through ptrace will be defeated. If you
55491+ have been using the RBAC system, this option has already been
55492+ enabled for several years for all users, with the ability to make
55493+ fine-grained exceptions.
55494+
55495+ This option only affects the ability of non-root users to ptrace
55496+ processes that are not a descendent of the ptracing process.
55497+ This means that strace ./binary and gdb ./binary will still work,
55498+ but attaching to arbitrary processes will not. If the sysctl
55499+ option is enabled, a sysctl option with name "harden_ptrace" is
55500+ created.
55501+
55502+config GRKERNSEC_TPE
55503+ bool "Trusted Path Execution (TPE)"
55504+ help
55505+ If you say Y here, you will be able to choose a gid to add to the
55506+ supplementary groups of users you want to mark as "untrusted."
55507+ These users will not be able to execute any files that are not in
55508+ root-owned directories writable only by root. If the sysctl option
55509+ is enabled, a sysctl option with name "tpe" is created.
55510+
55511+config GRKERNSEC_TPE_ALL
55512+ bool "Partially restrict all non-root users"
55513+ depends on GRKERNSEC_TPE
55514+ help
55515+ If you say Y here, all non-root users will be covered under
55516+ a weaker TPE restriction. This is separate from, and in addition to,
55517+ the main TPE options that you have selected elsewhere. Thus, if a
55518+ "trusted" GID is chosen, this restriction applies to even that GID.
55519+ Under this restriction, all non-root users will only be allowed to
55520+ execute files in directories they own that are not group or
55521+ world-writable, or in directories owned by root and writable only by
55522+ root. If the sysctl option is enabled, a sysctl option with name
55523+ "tpe_restrict_all" is created.
55524+
55525+config GRKERNSEC_TPE_INVERT
55526+ bool "Invert GID option"
55527+ depends on GRKERNSEC_TPE
55528+ help
55529+ If you say Y here, the group you specify in the TPE configuration will
55530+ decide what group TPE restrictions will be *disabled* for. This
55531+ option is useful if you want TPE restrictions to be applied to most
55532+ users on the system. If the sysctl option is enabled, a sysctl option
55533+ with name "tpe_invert" is created. Unlike other sysctl options, this
55534+ entry will default to on for backward-compatibility.
55535+
55536+config GRKERNSEC_TPE_GID
55537+ int "GID for untrusted users"
55538+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
55539+ default 1005
55540+ help
55541+ Setting this GID determines what group TPE restrictions will be
55542+ *enabled* for. If the sysctl option is enabled, a sysctl option
55543+ with name "tpe_gid" is created.
55544+
55545+config GRKERNSEC_TPE_GID
55546+ int "GID for trusted users"
55547+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
55548+ default 1005
55549+ help
55550+ Setting this GID determines what group TPE restrictions will be
55551+ *disabled* for. If the sysctl option is enabled, a sysctl option
55552+ with name "tpe_gid" is created.
55553+
55554+endmenu
55555+menu "Network Protections"
55556+depends on GRKERNSEC
55557+
55558+config GRKERNSEC_RANDNET
55559+ bool "Larger entropy pools"
55560+ help
55561+ If you say Y here, the entropy pools used for many features of Linux
55562+ and grsecurity will be doubled in size. Since several grsecurity
55563+ features use additional randomness, it is recommended that you say Y
55564+ here. Saying Y here has a similar effect as modifying
55565+ /proc/sys/kernel/random/poolsize.
55566+
55567+config GRKERNSEC_BLACKHOLE
55568+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
55569+ depends on NET
55570+ help
55571+ If you say Y here, neither TCP resets nor ICMP
55572+ destination-unreachable packets will be sent in response to packets
55573+ sent to ports for which no associated listening process exists.
55574+ This feature supports both IPV4 and IPV6 and exempts the
55575+ loopback interface from blackholing. Enabling this feature
55576+ makes a host more resilient to DoS attacks and reduces network
55577+ visibility against scanners.
55578+
55579+ The blackhole feature as-implemented is equivalent to the FreeBSD
55580+ blackhole feature, as it prevents RST responses to all packets, not
55581+ just SYNs. Under most application behavior this causes no
55582+ problems, but applications (like haproxy) may not close certain
55583+ connections in a way that cleanly terminates them on the remote
55584+ end, leaving the remote host in LAST_ACK state. Because of this
55585+ side-effect and to prevent intentional LAST_ACK DoSes, this
55586+ feature also adds automatic mitigation against such attacks.
55587+ The mitigation drastically reduces the amount of time a socket
55588+ can spend in LAST_ACK state. If you're using haproxy and not
55589+ all servers it connects to have this option enabled, consider
55590+ disabling this feature on the haproxy host.
55591+
55592+ If the sysctl option is enabled, two sysctl options with names
55593+ "ip_blackhole" and "lastack_retries" will be created.
55594+ While "ip_blackhole" takes the standard zero/non-zero on/off
55595+ toggle, "lastack_retries" uses the same kinds of values as
55596+ "tcp_retries1" and "tcp_retries2". The default value of 4
55597+ prevents a socket from lasting more than 45 seconds in LAST_ACK
55598+ state.
55599+
55600+config GRKERNSEC_SOCKET
55601+ bool "Socket restrictions"
55602+ depends on NET
55603+ help
55604+ If you say Y here, you will be able to choose from several options.
55605+ If you assign a GID on your system and add it to the supplementary
55606+ groups of users you want to restrict socket access to, this patch
55607+ will perform up to three things, based on the option(s) you choose.
55608+
55609+config GRKERNSEC_SOCKET_ALL
55610+ bool "Deny any sockets to group"
55611+ depends on GRKERNSEC_SOCKET
55612+ help
55613+ If you say Y here, you will be able to choose a GID of whose users will
55614+ be unable to connect to other hosts from your machine or run server
55615+ applications from your machine. If the sysctl option is enabled, a
55616+ sysctl option with name "socket_all" is created.
55617+
55618+config GRKERNSEC_SOCKET_ALL_GID
55619+ int "GID to deny all sockets for"
55620+ depends on GRKERNSEC_SOCKET_ALL
55621+ default 1004
55622+ help
55623+ Here you can choose the GID to disable socket access for. Remember to
55624+ add the users you want socket access disabled for to the GID
55625+ specified here. If the sysctl option is enabled, a sysctl option
55626+ with name "socket_all_gid" is created.
55627+
55628+config GRKERNSEC_SOCKET_CLIENT
55629+ bool "Deny client sockets to group"
55630+ depends on GRKERNSEC_SOCKET
55631+ help
55632+ If you say Y here, you will be able to choose a GID of whose users will
55633+ be unable to connect to other hosts from your machine, but will be
55634+ able to run servers. If this option is enabled, all users in the group
55635+ you specify will have to use passive mode when initiating ftp transfers
55636+ from the shell on your machine. If the sysctl option is enabled, a
55637+ sysctl option with name "socket_client" is created.
55638+
55639+config GRKERNSEC_SOCKET_CLIENT_GID
55640+ int "GID to deny client sockets for"
55641+ depends on GRKERNSEC_SOCKET_CLIENT
55642+ default 1003
55643+ help
55644+ Here you can choose the GID to disable client socket access for.
55645+ Remember to add the users you want client socket access disabled for to
55646+ the GID specified here. If the sysctl option is enabled, a sysctl
55647+ option with name "socket_client_gid" is created.
55648+
55649+config GRKERNSEC_SOCKET_SERVER
55650+ bool "Deny server sockets to group"
55651+ depends on GRKERNSEC_SOCKET
55652+ help
55653+ If you say Y here, you will be able to choose a GID of whose users will
55654+ be unable to run server applications from your machine. If the sysctl
55655+ option is enabled, a sysctl option with name "socket_server" is created.
55656+
55657+config GRKERNSEC_SOCKET_SERVER_GID
55658+ int "GID to deny server sockets for"
55659+ depends on GRKERNSEC_SOCKET_SERVER
55660+ default 1002
55661+ help
55662+ Here you can choose the GID to disable server socket access for.
55663+ Remember to add the users you want server socket access disabled for to
55664+ the GID specified here. If the sysctl option is enabled, a sysctl
55665+ option with name "socket_server_gid" is created.
55666+
55667+endmenu
55668+menu "Sysctl support"
55669+depends on GRKERNSEC && SYSCTL
55670+
55671+config GRKERNSEC_SYSCTL
55672+ bool "Sysctl support"
55673+ help
55674+ If you say Y here, you will be able to change the options that
55675+ grsecurity runs with at bootup, without having to recompile your
55676+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
55677+ to enable (1) or disable (0) various features. All the sysctl entries
55678+ are mutable until the "grsec_lock" entry is set to a non-zero value.
55679+ All features enabled in the kernel configuration are disabled at boot
55680+ if you do not say Y to the "Turn on features by default" option.
55681+ All options should be set at startup, and the grsec_lock entry should
55682+ be set to a non-zero value after all the options are set.
55683+ *THIS IS EXTREMELY IMPORTANT*
55684+
55685+config GRKERNSEC_SYSCTL_DISTRO
55686+ bool "Extra sysctl support for distro makers (READ HELP)"
55687+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
55688+ help
55689+ If you say Y here, additional sysctl options will be created
55690+ for features that affect processes running as root. Therefore,
55691+ it is critical when using this option that the grsec_lock entry be
55692+ enabled after boot. Only distros with prebuilt kernel packages
55693+ with this option enabled that can ensure grsec_lock is enabled
55694+ after boot should use this option.
55695+ *Failure to set grsec_lock after boot makes all grsec features
55696+ this option covers useless*
55697+
55698+ Currently this option creates the following sysctl entries:
55699+ "Disable Privileged I/O": "disable_priv_io"
55700+
55701+config GRKERNSEC_SYSCTL_ON
55702+ bool "Turn on features by default"
55703+ depends on GRKERNSEC_SYSCTL
55704+ help
55705+ If you say Y here, instead of having all features enabled in the
55706+ kernel configuration disabled at boot time, the features will be
55707+ enabled at boot time. It is recommended you say Y here unless
55708+ there is some reason you would want all sysctl-tunable features to
55709+ be disabled by default. As mentioned elsewhere, it is important
55710+ to enable the grsec_lock entry once you have finished modifying
55711+ the sysctl entries.
55712+
55713+endmenu
55714+menu "Logging Options"
55715+depends on GRKERNSEC
55716+
55717+config GRKERNSEC_FLOODTIME
55718+ int "Seconds in between log messages (minimum)"
55719+ default 10
55720+ help
55721+ This option allows you to enforce the number of seconds between
55722+ grsecurity log messages. The default should be suitable for most
55723+ people, however, if you choose to change it, choose a value small enough
55724+ to allow informative logs to be produced, but large enough to
55725+ prevent flooding.
55726+
55727+config GRKERNSEC_FLOODBURST
55728+ int "Number of messages in a burst (maximum)"
55729+ default 6
55730+ help
55731+ This option allows you to choose the maximum number of messages allowed
55732+ within the flood time interval you chose in a separate option. The
55733+ default should be suitable for most people, however if you find that
55734+ many of your logs are being interpreted as flooding, you may want to
55735+ raise this value.
55736+
55737+endmenu
55738+
55739+endmenu
55740diff --git a/grsecurity/Makefile b/grsecurity/Makefile
55741new file mode 100644
55742index 0000000..be9ae3a
55743--- /dev/null
55744+++ b/grsecurity/Makefile
55745@@ -0,0 +1,36 @@
55746+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
55747+# during 2001-2009 it has been completely redesigned by Brad Spengler
55748+# into an RBAC system
55749+#
55750+# All code in this directory and various hooks inserted throughout the kernel
55751+# are copyright Brad Spengler - Open Source Security, Inc., and released
55752+# under the GPL v2 or higher
55753+
55754+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
55755+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
55756+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
55757+
55758+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
55759+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
55760+ gracl_learn.o grsec_log.o
55761+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
55762+
55763+ifdef CONFIG_NET
55764+obj-y += grsec_sock.o
55765+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
55766+endif
55767+
55768+ifndef CONFIG_GRKERNSEC
55769+obj-y += grsec_disabled.o
55770+endif
55771+
55772+ifdef CONFIG_GRKERNSEC_HIDESYM
55773+extra-y := grsec_hidesym.o
55774+$(obj)/grsec_hidesym.o:
55775+ @-chmod -f 500 /boot
55776+ @-chmod -f 500 /lib/modules
55777+ @-chmod -f 500 /lib64/modules
55778+ @-chmod -f 500 /lib32/modules
55779+ @-chmod -f 700 .
55780+ @echo ' grsec: protected kernel image paths'
55781+endif
55782diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
55783new file mode 100644
55784index 0000000..6bd68d6
55785--- /dev/null
55786+++ b/grsecurity/gracl.c
55787@@ -0,0 +1,4141 @@
55788+#include <linux/kernel.h>
55789+#include <linux/module.h>
55790+#include <linux/sched.h>
55791+#include <linux/mm.h>
55792+#include <linux/file.h>
55793+#include <linux/fs.h>
55794+#include <linux/namei.h>
55795+#include <linux/mount.h>
55796+#include <linux/tty.h>
55797+#include <linux/proc_fs.h>
55798+#include <linux/smp_lock.h>
55799+#include <linux/slab.h>
55800+#include <linux/vmalloc.h>
55801+#include <linux/types.h>
55802+#include <linux/sysctl.h>
55803+#include <linux/netdevice.h>
55804+#include <linux/ptrace.h>
55805+#include <linux/gracl.h>
55806+#include <linux/gralloc.h>
55807+#include <linux/grsecurity.h>
55808+#include <linux/grinternal.h>
55809+#include <linux/pid_namespace.h>
55810+#include <linux/fdtable.h>
55811+#include <linux/percpu.h>
55812+
55813+#include <asm/uaccess.h>
55814+#include <asm/errno.h>
55815+#include <asm/mman.h>
55816+
55817+static struct acl_role_db acl_role_set;
55818+static struct name_db name_set;
55819+static struct inodev_db inodev_set;
55820+
55821+/* for keeping track of userspace pointers used for subjects, so we
55822+ can share references in the kernel as well
55823+*/
55824+
55825+static struct dentry *real_root;
55826+static struct vfsmount *real_root_mnt;
55827+
55828+static struct acl_subj_map_db subj_map_set;
55829+
55830+static struct acl_role_label *default_role;
55831+
55832+static struct acl_role_label *role_list;
55833+
55834+static u16 acl_sp_role_value;
55835+
55836+extern char *gr_shared_page[4];
55837+static DEFINE_MUTEX(gr_dev_mutex);
55838+DEFINE_RWLOCK(gr_inode_lock);
55839+
55840+struct gr_arg *gr_usermode;
55841+
55842+static unsigned int gr_status __read_only = GR_STATUS_INIT;
55843+
55844+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
55845+extern void gr_clear_learn_entries(void);
55846+
55847+#ifdef CONFIG_GRKERNSEC_RESLOG
55848+extern void gr_log_resource(const struct task_struct *task,
55849+ const int res, const unsigned long wanted, const int gt);
55850+#endif
55851+
55852+unsigned char *gr_system_salt;
55853+unsigned char *gr_system_sum;
55854+
55855+static struct sprole_pw **acl_special_roles = NULL;
55856+static __u16 num_sprole_pws = 0;
55857+
55858+static struct acl_role_label *kernel_role = NULL;
55859+
55860+static unsigned int gr_auth_attempts = 0;
55861+static unsigned long gr_auth_expires = 0UL;
55862+
55863+#ifdef CONFIG_NET
55864+extern struct vfsmount *sock_mnt;
55865+#endif
55866+extern struct vfsmount *pipe_mnt;
55867+extern struct vfsmount *shm_mnt;
55868+#ifdef CONFIG_HUGETLBFS
55869+extern struct vfsmount *hugetlbfs_vfsmount;
55870+#endif
55871+
55872+static struct acl_object_label *fakefs_obj_rw;
55873+static struct acl_object_label *fakefs_obj_rwx;
55874+
55875+extern int gr_init_uidset(void);
55876+extern void gr_free_uidset(void);
55877+extern void gr_remove_uid(uid_t uid);
55878+extern int gr_find_uid(uid_t uid);
55879+
55880+__inline__ int
55881+gr_acl_is_enabled(void)
55882+{
55883+ return (gr_status & GR_READY);
55884+}
55885+
55886+#ifdef CONFIG_BTRFS_FS
55887+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55888+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55889+#endif
55890+
55891+static inline dev_t __get_dev(const struct dentry *dentry)
55892+{
55893+#ifdef CONFIG_BTRFS_FS
55894+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55895+ return get_btrfs_dev_from_inode(dentry->d_inode);
55896+ else
55897+#endif
55898+ return dentry->d_inode->i_sb->s_dev;
55899+}
55900+
55901+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
55902+{
55903+ return __get_dev(dentry);
55904+}
55905+
55906+static char gr_task_roletype_to_char(struct task_struct *task)
55907+{
55908+ switch (task->role->roletype &
55909+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
55910+ GR_ROLE_SPECIAL)) {
55911+ case GR_ROLE_DEFAULT:
55912+ return 'D';
55913+ case GR_ROLE_USER:
55914+ return 'U';
55915+ case GR_ROLE_GROUP:
55916+ return 'G';
55917+ case GR_ROLE_SPECIAL:
55918+ return 'S';
55919+ }
55920+
55921+ return 'X';
55922+}
55923+
55924+char gr_roletype_to_char(void)
55925+{
55926+ return gr_task_roletype_to_char(current);
55927+}
55928+
55929+__inline__ int
55930+gr_acl_tpe_check(void)
55931+{
55932+ if (unlikely(!(gr_status & GR_READY)))
55933+ return 0;
55934+ if (current->role->roletype & GR_ROLE_TPE)
55935+ return 1;
55936+ else
55937+ return 0;
55938+}
55939+
55940+int
55941+gr_handle_rawio(const struct inode *inode)
55942+{
55943+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55944+ if (inode && S_ISBLK(inode->i_mode) &&
55945+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
55946+ !capable(CAP_SYS_RAWIO))
55947+ return 1;
55948+#endif
55949+ return 0;
55950+}
55951+
55952+static int
55953+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
55954+{
55955+ if (likely(lena != lenb))
55956+ return 0;
55957+
55958+ return !memcmp(a, b, lena);
55959+}
55960+
55961+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
55962+{
55963+ *buflen -= namelen;
55964+ if (*buflen < 0)
55965+ return -ENAMETOOLONG;
55966+ *buffer -= namelen;
55967+ memcpy(*buffer, str, namelen);
55968+ return 0;
55969+}
55970+
55971+/* this must be called with vfsmount_lock and dcache_lock held */
55972+
55973+static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
55974+ struct dentry *root, struct vfsmount *rootmnt,
55975+ char *buffer, int buflen)
55976+{
55977+ char * end = buffer+buflen;
55978+ char * retval;
55979+ int namelen;
55980+
55981+ *--end = '\0';
55982+ buflen--;
55983+
55984+ if (buflen < 1)
55985+ goto Elong;
55986+ /* Get '/' right */
55987+ retval = end-1;
55988+ *retval = '/';
55989+
55990+ for (;;) {
55991+ struct dentry * parent;
55992+
55993+ if (dentry == root && vfsmnt == rootmnt)
55994+ break;
55995+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
55996+ /* Global root? */
55997+ if (vfsmnt->mnt_parent == vfsmnt)
55998+ goto global_root;
55999+ dentry = vfsmnt->mnt_mountpoint;
56000+ vfsmnt = vfsmnt->mnt_parent;
56001+ continue;
56002+ }
56003+ parent = dentry->d_parent;
56004+ prefetch(parent);
56005+ namelen = dentry->d_name.len;
56006+ buflen -= namelen + 1;
56007+ if (buflen < 0)
56008+ goto Elong;
56009+ end -= namelen;
56010+ memcpy(end, dentry->d_name.name, namelen);
56011+ *--end = '/';
56012+ retval = end;
56013+ dentry = parent;
56014+ }
56015+
56016+out:
56017+ return retval;
56018+
56019+global_root:
56020+ namelen = dentry->d_name.len;
56021+ buflen -= namelen;
56022+ if (buflen < 0)
56023+ goto Elong;
56024+ retval -= namelen-1; /* hit the slash */
56025+ memcpy(retval, dentry->d_name.name, namelen);
56026+ goto out;
56027+Elong:
56028+ retval = ERR_PTR(-ENAMETOOLONG);
56029+ goto out;
56030+}
56031+
56032+static char *
56033+gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
56034+ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
56035+{
56036+ char *retval;
56037+
56038+ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
56039+ if (unlikely(IS_ERR(retval)))
56040+ retval = strcpy(buf, "<path too long>");
56041+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
56042+ retval[1] = '\0';
56043+
56044+ return retval;
56045+}
56046+
56047+static char *
56048+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
56049+ char *buf, int buflen)
56050+{
56051+ char *res;
56052+
56053+ /* we can use real_root, real_root_mnt, because this is only called
56054+ by the RBAC system */
56055+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
56056+
56057+ return res;
56058+}
56059+
56060+static char *
56061+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
56062+ char *buf, int buflen)
56063+{
56064+ char *res;
56065+ struct dentry *root;
56066+ struct vfsmount *rootmnt;
56067+ struct task_struct *reaper = &init_task;
56068+
56069+ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
56070+ read_lock(&reaper->fs->lock);
56071+ root = dget(reaper->fs->root.dentry);
56072+ rootmnt = mntget(reaper->fs->root.mnt);
56073+ read_unlock(&reaper->fs->lock);
56074+
56075+ spin_lock(&dcache_lock);
56076+ spin_lock(&vfsmount_lock);
56077+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
56078+ spin_unlock(&vfsmount_lock);
56079+ spin_unlock(&dcache_lock);
56080+
56081+ dput(root);
56082+ mntput(rootmnt);
56083+ return res;
56084+}
56085+
56086+static char *
56087+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
56088+{
56089+ char *ret;
56090+ spin_lock(&dcache_lock);
56091+ spin_lock(&vfsmount_lock);
56092+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
56093+ PAGE_SIZE);
56094+ spin_unlock(&vfsmount_lock);
56095+ spin_unlock(&dcache_lock);
56096+ return ret;
56097+}
56098+
56099+static char *
56100+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
56101+{
56102+ char *ret;
56103+ char *buf;
56104+ int buflen;
56105+
56106+ spin_lock(&dcache_lock);
56107+ spin_lock(&vfsmount_lock);
56108+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
56109+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
56110+ buflen = (int)(ret - buf);
56111+ if (buflen >= 5)
56112+ prepend(&ret, &buflen, "/proc", 5);
56113+ else
56114+ ret = strcpy(buf, "<path too long>");
56115+ spin_unlock(&vfsmount_lock);
56116+ spin_unlock(&dcache_lock);
56117+ return ret;
56118+}
56119+
56120+char *
56121+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
56122+{
56123+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
56124+ PAGE_SIZE);
56125+}
56126+
56127+char *
56128+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
56129+{
56130+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
56131+ PAGE_SIZE);
56132+}
56133+
56134+char *
56135+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
56136+{
56137+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
56138+ PAGE_SIZE);
56139+}
56140+
56141+char *
56142+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
56143+{
56144+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
56145+ PAGE_SIZE);
56146+}
56147+
56148+char *
56149+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
56150+{
56151+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
56152+ PAGE_SIZE);
56153+}
56154+
56155+__inline__ __u32
56156+to_gr_audit(const __u32 reqmode)
56157+{
56158+ /* masks off auditable permission flags, then shifts them to create
56159+ auditing flags, and adds the special case of append auditing if
56160+ we're requesting write */
56161+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
56162+}
56163+
56164+struct acl_subject_label *
56165+lookup_subject_map(const struct acl_subject_label *userp)
56166+{
56167+ unsigned int index = shash(userp, subj_map_set.s_size);
56168+ struct subject_map *match;
56169+
56170+ match = subj_map_set.s_hash[index];
56171+
56172+ while (match && match->user != userp)
56173+ match = match->next;
56174+
56175+ if (match != NULL)
56176+ return match->kernel;
56177+ else
56178+ return NULL;
56179+}
56180+
56181+static void
56182+insert_subj_map_entry(struct subject_map *subjmap)
56183+{
56184+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
56185+ struct subject_map **curr;
56186+
56187+ subjmap->prev = NULL;
56188+
56189+ curr = &subj_map_set.s_hash[index];
56190+ if (*curr != NULL)
56191+ (*curr)->prev = subjmap;
56192+
56193+ subjmap->next = *curr;
56194+ *curr = subjmap;
56195+
56196+ return;
56197+}
56198+
56199+static struct acl_role_label *
56200+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
56201+ const gid_t gid)
56202+{
56203+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
56204+ struct acl_role_label *match;
56205+ struct role_allowed_ip *ipp;
56206+ unsigned int x;
56207+ u32 curr_ip = task->signal->curr_ip;
56208+
56209+ task->signal->saved_ip = curr_ip;
56210+
56211+ match = acl_role_set.r_hash[index];
56212+
56213+ while (match) {
56214+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
56215+ for (x = 0; x < match->domain_child_num; x++) {
56216+ if (match->domain_children[x] == uid)
56217+ goto found;
56218+ }
56219+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
56220+ break;
56221+ match = match->next;
56222+ }
56223+found:
56224+ if (match == NULL) {
56225+ try_group:
56226+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
56227+ match = acl_role_set.r_hash[index];
56228+
56229+ while (match) {
56230+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
56231+ for (x = 0; x < match->domain_child_num; x++) {
56232+ if (match->domain_children[x] == gid)
56233+ goto found2;
56234+ }
56235+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
56236+ break;
56237+ match = match->next;
56238+ }
56239+found2:
56240+ if (match == NULL)
56241+ match = default_role;
56242+ if (match->allowed_ips == NULL)
56243+ return match;
56244+ else {
56245+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
56246+ if (likely
56247+ ((ntohl(curr_ip) & ipp->netmask) ==
56248+ (ntohl(ipp->addr) & ipp->netmask)))
56249+ return match;
56250+ }
56251+ match = default_role;
56252+ }
56253+ } else if (match->allowed_ips == NULL) {
56254+ return match;
56255+ } else {
56256+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
56257+ if (likely
56258+ ((ntohl(curr_ip) & ipp->netmask) ==
56259+ (ntohl(ipp->addr) & ipp->netmask)))
56260+ return match;
56261+ }
56262+ goto try_group;
56263+ }
56264+
56265+ return match;
56266+}
56267+
56268+struct acl_subject_label *
56269+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
56270+ const struct acl_role_label *role)
56271+{
56272+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
56273+ struct acl_subject_label *match;
56274+
56275+ match = role->subj_hash[index];
56276+
56277+ while (match && (match->inode != ino || match->device != dev ||
56278+ (match->mode & GR_DELETED))) {
56279+ match = match->next;
56280+ }
56281+
56282+ if (match && !(match->mode & GR_DELETED))
56283+ return match;
56284+ else
56285+ return NULL;
56286+}
56287+
56288+struct acl_subject_label *
56289+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
56290+ const struct acl_role_label *role)
56291+{
56292+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
56293+ struct acl_subject_label *match;
56294+
56295+ match = role->subj_hash[index];
56296+
56297+ while (match && (match->inode != ino || match->device != dev ||
56298+ !(match->mode & GR_DELETED))) {
56299+ match = match->next;
56300+ }
56301+
56302+ if (match && (match->mode & GR_DELETED))
56303+ return match;
56304+ else
56305+ return NULL;
56306+}
56307+
56308+static struct acl_object_label *
56309+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
56310+ const struct acl_subject_label *subj)
56311+{
56312+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
56313+ struct acl_object_label *match;
56314+
56315+ match = subj->obj_hash[index];
56316+
56317+ while (match && (match->inode != ino || match->device != dev ||
56318+ (match->mode & GR_DELETED))) {
56319+ match = match->next;
56320+ }
56321+
56322+ if (match && !(match->mode & GR_DELETED))
56323+ return match;
56324+ else
56325+ return NULL;
56326+}
56327+
56328+static struct acl_object_label *
56329+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
56330+ const struct acl_subject_label *subj)
56331+{
56332+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
56333+ struct acl_object_label *match;
56334+
56335+ match = subj->obj_hash[index];
56336+
56337+ while (match && (match->inode != ino || match->device != dev ||
56338+ !(match->mode & GR_DELETED))) {
56339+ match = match->next;
56340+ }
56341+
56342+ if (match && (match->mode & GR_DELETED))
56343+ return match;
56344+
56345+ match = subj->obj_hash[index];
56346+
56347+ while (match && (match->inode != ino || match->device != dev ||
56348+ (match->mode & GR_DELETED))) {
56349+ match = match->next;
56350+ }
56351+
56352+ if (match && !(match->mode & GR_DELETED))
56353+ return match;
56354+ else
56355+ return NULL;
56356+}
56357+
56358+static struct name_entry *
56359+lookup_name_entry(const char *name)
56360+{
56361+ unsigned int len = strlen(name);
56362+ unsigned int key = full_name_hash(name, len);
56363+ unsigned int index = key % name_set.n_size;
56364+ struct name_entry *match;
56365+
56366+ match = name_set.n_hash[index];
56367+
56368+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
56369+ match = match->next;
56370+
56371+ return match;
56372+}
56373+
56374+static struct name_entry *
56375+lookup_name_entry_create(const char *name)
56376+{
56377+ unsigned int len = strlen(name);
56378+ unsigned int key = full_name_hash(name, len);
56379+ unsigned int index = key % name_set.n_size;
56380+ struct name_entry *match;
56381+
56382+ match = name_set.n_hash[index];
56383+
56384+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
56385+ !match->deleted))
56386+ match = match->next;
56387+
56388+ if (match && match->deleted)
56389+ return match;
56390+
56391+ match = name_set.n_hash[index];
56392+
56393+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
56394+ match->deleted))
56395+ match = match->next;
56396+
56397+ if (match && !match->deleted)
56398+ return match;
56399+ else
56400+ return NULL;
56401+}
56402+
56403+static struct inodev_entry *
56404+lookup_inodev_entry(const ino_t ino, const dev_t dev)
56405+{
56406+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
56407+ struct inodev_entry *match;
56408+
56409+ match = inodev_set.i_hash[index];
56410+
56411+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
56412+ match = match->next;
56413+
56414+ return match;
56415+}
56416+
56417+static void
56418+insert_inodev_entry(struct inodev_entry *entry)
56419+{
56420+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
56421+ inodev_set.i_size);
56422+ struct inodev_entry **curr;
56423+
56424+ entry->prev = NULL;
56425+
56426+ curr = &inodev_set.i_hash[index];
56427+ if (*curr != NULL)
56428+ (*curr)->prev = entry;
56429+
56430+ entry->next = *curr;
56431+ *curr = entry;
56432+
56433+ return;
56434+}
56435+
56436+static void
56437+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
56438+{
56439+ unsigned int index =
56440+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
56441+ struct acl_role_label **curr;
56442+ struct acl_role_label *tmp;
56443+
56444+ curr = &acl_role_set.r_hash[index];
56445+
56446+ /* if role was already inserted due to domains and already has
56447+ a role in the same bucket as it attached, then we need to
56448+ combine these two buckets
56449+ */
56450+ if (role->next) {
56451+ tmp = role->next;
56452+ while (tmp->next)
56453+ tmp = tmp->next;
56454+ tmp->next = *curr;
56455+ } else
56456+ role->next = *curr;
56457+ *curr = role;
56458+
56459+ return;
56460+}
56461+
56462+static void
56463+insert_acl_role_label(struct acl_role_label *role)
56464+{
56465+ int i;
56466+
56467+ if (role_list == NULL) {
56468+ role_list = role;
56469+ role->prev = NULL;
56470+ } else {
56471+ role->prev = role_list;
56472+ role_list = role;
56473+ }
56474+
56475+ /* used for hash chains */
56476+ role->next = NULL;
56477+
56478+ if (role->roletype & GR_ROLE_DOMAIN) {
56479+ for (i = 0; i < role->domain_child_num; i++)
56480+ __insert_acl_role_label(role, role->domain_children[i]);
56481+ } else
56482+ __insert_acl_role_label(role, role->uidgid);
56483+}
56484+
56485+static int
56486+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
56487+{
56488+ struct name_entry **curr, *nentry;
56489+ struct inodev_entry *ientry;
56490+ unsigned int len = strlen(name);
56491+ unsigned int key = full_name_hash(name, len);
56492+ unsigned int index = key % name_set.n_size;
56493+
56494+ curr = &name_set.n_hash[index];
56495+
56496+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
56497+ curr = &((*curr)->next);
56498+
56499+ if (*curr != NULL)
56500+ return 1;
56501+
56502+ nentry = acl_alloc(sizeof (struct name_entry));
56503+ if (nentry == NULL)
56504+ return 0;
56505+ ientry = acl_alloc(sizeof (struct inodev_entry));
56506+ if (ientry == NULL)
56507+ return 0;
56508+ ientry->nentry = nentry;
56509+
56510+ nentry->key = key;
56511+ nentry->name = name;
56512+ nentry->inode = inode;
56513+ nentry->device = device;
56514+ nentry->len = len;
56515+ nentry->deleted = deleted;
56516+
56517+ nentry->prev = NULL;
56518+ curr = &name_set.n_hash[index];
56519+ if (*curr != NULL)
56520+ (*curr)->prev = nentry;
56521+ nentry->next = *curr;
56522+ *curr = nentry;
56523+
56524+ /* insert us into the table searchable by inode/dev */
56525+ insert_inodev_entry(ientry);
56526+
56527+ return 1;
56528+}
56529+
56530+static void
56531+insert_acl_obj_label(struct acl_object_label *obj,
56532+ struct acl_subject_label *subj)
56533+{
56534+ unsigned int index =
56535+ fhash(obj->inode, obj->device, subj->obj_hash_size);
56536+ struct acl_object_label **curr;
56537+
56538+
56539+ obj->prev = NULL;
56540+
56541+ curr = &subj->obj_hash[index];
56542+ if (*curr != NULL)
56543+ (*curr)->prev = obj;
56544+
56545+ obj->next = *curr;
56546+ *curr = obj;
56547+
56548+ return;
56549+}
56550+
56551+static void
56552+insert_acl_subj_label(struct acl_subject_label *obj,
56553+ struct acl_role_label *role)
56554+{
56555+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
56556+ struct acl_subject_label **curr;
56557+
56558+ obj->prev = NULL;
56559+
56560+ curr = &role->subj_hash[index];
56561+ if (*curr != NULL)
56562+ (*curr)->prev = obj;
56563+
56564+ obj->next = *curr;
56565+ *curr = obj;
56566+
56567+ return;
56568+}
56569+
56570+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
56571+
56572+static void *
56573+create_table(__u32 * len, int elementsize)
56574+{
56575+ unsigned int table_sizes[] = {
56576+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
56577+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
56578+ 4194301, 8388593, 16777213, 33554393, 67108859
56579+ };
56580+ void *newtable = NULL;
56581+ unsigned int pwr = 0;
56582+
56583+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
56584+ table_sizes[pwr] <= *len)
56585+ pwr++;
56586+
56587+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
56588+ return newtable;
56589+
56590+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
56591+ newtable =
56592+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
56593+ else
56594+ newtable = vmalloc(table_sizes[pwr] * elementsize);
56595+
56596+ *len = table_sizes[pwr];
56597+
56598+ return newtable;
56599+}
56600+
56601+static int
56602+init_variables(const struct gr_arg *arg)
56603+{
56604+ struct task_struct *reaper = &init_task;
56605+ unsigned int stacksize;
56606+
56607+ subj_map_set.s_size = arg->role_db.num_subjects;
56608+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
56609+ name_set.n_size = arg->role_db.num_objects;
56610+ inodev_set.i_size = arg->role_db.num_objects;
56611+
56612+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
56613+ !name_set.n_size || !inodev_set.i_size)
56614+ return 1;
56615+
56616+ if (!gr_init_uidset())
56617+ return 1;
56618+
56619+ /* set up the stack that holds allocation info */
56620+
56621+ stacksize = arg->role_db.num_pointers + 5;
56622+
56623+ if (!acl_alloc_stack_init(stacksize))
56624+ return 1;
56625+
56626+ /* grab reference for the real root dentry and vfsmount */
56627+ read_lock(&reaper->fs->lock);
56628+ real_root = dget(reaper->fs->root.dentry);
56629+ real_root_mnt = mntget(reaper->fs->root.mnt);
56630+ read_unlock(&reaper->fs->lock);
56631+
56632+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56633+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root), real_root->d_inode->i_ino);
56634+#endif
56635+
56636+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
56637+ if (fakefs_obj_rw == NULL)
56638+ return 1;
56639+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
56640+
56641+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
56642+ if (fakefs_obj_rwx == NULL)
56643+ return 1;
56644+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
56645+
56646+ subj_map_set.s_hash =
56647+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
56648+ acl_role_set.r_hash =
56649+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
56650+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
56651+ inodev_set.i_hash =
56652+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
56653+
56654+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
56655+ !name_set.n_hash || !inodev_set.i_hash)
56656+ return 1;
56657+
56658+ memset(subj_map_set.s_hash, 0,
56659+ sizeof(struct subject_map *) * subj_map_set.s_size);
56660+ memset(acl_role_set.r_hash, 0,
56661+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
56662+ memset(name_set.n_hash, 0,
56663+ sizeof (struct name_entry *) * name_set.n_size);
56664+ memset(inodev_set.i_hash, 0,
56665+ sizeof (struct inodev_entry *) * inodev_set.i_size);
56666+
56667+ return 0;
56668+}
56669+
56670+/* free information not needed after startup
56671+ currently contains user->kernel pointer mappings for subjects
56672+*/
56673+
56674+static void
56675+free_init_variables(void)
56676+{
56677+ __u32 i;
56678+
56679+ if (subj_map_set.s_hash) {
56680+ for (i = 0; i < subj_map_set.s_size; i++) {
56681+ if (subj_map_set.s_hash[i]) {
56682+ kfree(subj_map_set.s_hash[i]);
56683+ subj_map_set.s_hash[i] = NULL;
56684+ }
56685+ }
56686+
56687+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
56688+ PAGE_SIZE)
56689+ kfree(subj_map_set.s_hash);
56690+ else
56691+ vfree(subj_map_set.s_hash);
56692+ }
56693+
56694+ return;
56695+}
56696+
56697+static void
56698+free_variables(void)
56699+{
56700+ struct acl_subject_label *s;
56701+ struct acl_role_label *r;
56702+ struct task_struct *task, *task2;
56703+ unsigned int x;
56704+
56705+ gr_clear_learn_entries();
56706+
56707+ read_lock(&tasklist_lock);
56708+ do_each_thread(task2, task) {
56709+ task->acl_sp_role = 0;
56710+ task->acl_role_id = 0;
56711+ task->acl = NULL;
56712+ task->role = NULL;
56713+ } while_each_thread(task2, task);
56714+ read_unlock(&tasklist_lock);
56715+
56716+ /* release the reference to the real root dentry and vfsmount */
56717+ if (real_root)
56718+ dput(real_root);
56719+ real_root = NULL;
56720+ if (real_root_mnt)
56721+ mntput(real_root_mnt);
56722+ real_root_mnt = NULL;
56723+
56724+ /* free all object hash tables */
56725+
56726+ FOR_EACH_ROLE_START(r)
56727+ if (r->subj_hash == NULL)
56728+ goto next_role;
56729+ FOR_EACH_SUBJECT_START(r, s, x)
56730+ if (s->obj_hash == NULL)
56731+ break;
56732+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
56733+ kfree(s->obj_hash);
56734+ else
56735+ vfree(s->obj_hash);
56736+ FOR_EACH_SUBJECT_END(s, x)
56737+ FOR_EACH_NESTED_SUBJECT_START(r, s)
56738+ if (s->obj_hash == NULL)
56739+ break;
56740+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
56741+ kfree(s->obj_hash);
56742+ else
56743+ vfree(s->obj_hash);
56744+ FOR_EACH_NESTED_SUBJECT_END(s)
56745+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
56746+ kfree(r->subj_hash);
56747+ else
56748+ vfree(r->subj_hash);
56749+ r->subj_hash = NULL;
56750+next_role:
56751+ FOR_EACH_ROLE_END(r)
56752+
56753+ acl_free_all();
56754+
56755+ if (acl_role_set.r_hash) {
56756+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
56757+ PAGE_SIZE)
56758+ kfree(acl_role_set.r_hash);
56759+ else
56760+ vfree(acl_role_set.r_hash);
56761+ }
56762+ if (name_set.n_hash) {
56763+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
56764+ PAGE_SIZE)
56765+ kfree(name_set.n_hash);
56766+ else
56767+ vfree(name_set.n_hash);
56768+ }
56769+
56770+ if (inodev_set.i_hash) {
56771+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
56772+ PAGE_SIZE)
56773+ kfree(inodev_set.i_hash);
56774+ else
56775+ vfree(inodev_set.i_hash);
56776+ }
56777+
56778+ gr_free_uidset();
56779+
56780+ memset(&name_set, 0, sizeof (struct name_db));
56781+ memset(&inodev_set, 0, sizeof (struct inodev_db));
56782+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
56783+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
56784+
56785+ default_role = NULL;
56786+ role_list = NULL;
56787+
56788+ return;
56789+}
56790+
56791+static __u32
56792+count_user_objs(struct acl_object_label *userp)
56793+{
56794+ struct acl_object_label o_tmp;
56795+ __u32 num = 0;
56796+
56797+ while (userp) {
56798+ if (copy_from_user(&o_tmp, userp,
56799+ sizeof (struct acl_object_label)))
56800+ break;
56801+
56802+ userp = o_tmp.prev;
56803+ num++;
56804+ }
56805+
56806+ return num;
56807+}
56808+
56809+static struct acl_subject_label *
56810+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
56811+
56812+static int
56813+copy_user_glob(struct acl_object_label *obj)
56814+{
56815+ struct acl_object_label *g_tmp, **guser;
56816+ unsigned int len;
56817+ char *tmp;
56818+
56819+ if (obj->globbed == NULL)
56820+ return 0;
56821+
56822+ guser = &obj->globbed;
56823+ while (*guser) {
56824+ g_tmp = (struct acl_object_label *)
56825+ acl_alloc(sizeof (struct acl_object_label));
56826+ if (g_tmp == NULL)
56827+ return -ENOMEM;
56828+
56829+ if (copy_from_user(g_tmp, *guser,
56830+ sizeof (struct acl_object_label)))
56831+ return -EFAULT;
56832+
56833+ len = strnlen_user(g_tmp->filename, PATH_MAX);
56834+
56835+ if (!len || len >= PATH_MAX)
56836+ return -EINVAL;
56837+
56838+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56839+ return -ENOMEM;
56840+
56841+ if (copy_from_user(tmp, g_tmp->filename, len))
56842+ return -EFAULT;
56843+ tmp[len-1] = '\0';
56844+ g_tmp->filename = tmp;
56845+
56846+ *guser = g_tmp;
56847+ guser = &(g_tmp->next);
56848+ }
56849+
56850+ return 0;
56851+}
56852+
56853+static int
56854+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
56855+ struct acl_role_label *role)
56856+{
56857+ struct acl_object_label *o_tmp;
56858+ unsigned int len;
56859+ int ret;
56860+ char *tmp;
56861+
56862+ while (userp) {
56863+ if ((o_tmp = (struct acl_object_label *)
56864+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
56865+ return -ENOMEM;
56866+
56867+ if (copy_from_user(o_tmp, userp,
56868+ sizeof (struct acl_object_label)))
56869+ return -EFAULT;
56870+
56871+ userp = o_tmp->prev;
56872+
56873+ len = strnlen_user(o_tmp->filename, PATH_MAX);
56874+
56875+ if (!len || len >= PATH_MAX)
56876+ return -EINVAL;
56877+
56878+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56879+ return -ENOMEM;
56880+
56881+ if (copy_from_user(tmp, o_tmp->filename, len))
56882+ return -EFAULT;
56883+ tmp[len-1] = '\0';
56884+ o_tmp->filename = tmp;
56885+
56886+ insert_acl_obj_label(o_tmp, subj);
56887+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
56888+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
56889+ return -ENOMEM;
56890+
56891+ ret = copy_user_glob(o_tmp);
56892+ if (ret)
56893+ return ret;
56894+
56895+ if (o_tmp->nested) {
56896+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
56897+ if (IS_ERR(o_tmp->nested))
56898+ return PTR_ERR(o_tmp->nested);
56899+
56900+ /* insert into nested subject list */
56901+ o_tmp->nested->next = role->hash->first;
56902+ role->hash->first = o_tmp->nested;
56903+ }
56904+ }
56905+
56906+ return 0;
56907+}
56908+
56909+static __u32
56910+count_user_subjs(struct acl_subject_label *userp)
56911+{
56912+ struct acl_subject_label s_tmp;
56913+ __u32 num = 0;
56914+
56915+ while (userp) {
56916+ if (copy_from_user(&s_tmp, userp,
56917+ sizeof (struct acl_subject_label)))
56918+ break;
56919+
56920+ userp = s_tmp.prev;
56921+ /* do not count nested subjects against this count, since
56922+ they are not included in the hash table, but are
56923+ attached to objects. We have already counted
56924+ the subjects in userspace for the allocation
56925+ stack
56926+ */
56927+ if (!(s_tmp.mode & GR_NESTED))
56928+ num++;
56929+ }
56930+
56931+ return num;
56932+}
56933+
56934+static int
56935+copy_user_allowedips(struct acl_role_label *rolep)
56936+{
56937+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
56938+
56939+ ruserip = rolep->allowed_ips;
56940+
56941+ while (ruserip) {
56942+ rlast = rtmp;
56943+
56944+ if ((rtmp = (struct role_allowed_ip *)
56945+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
56946+ return -ENOMEM;
56947+
56948+ if (copy_from_user(rtmp, ruserip,
56949+ sizeof (struct role_allowed_ip)))
56950+ return -EFAULT;
56951+
56952+ ruserip = rtmp->prev;
56953+
56954+ if (!rlast) {
56955+ rtmp->prev = NULL;
56956+ rolep->allowed_ips = rtmp;
56957+ } else {
56958+ rlast->next = rtmp;
56959+ rtmp->prev = rlast;
56960+ }
56961+
56962+ if (!ruserip)
56963+ rtmp->next = NULL;
56964+ }
56965+
56966+ return 0;
56967+}
56968+
56969+static int
56970+copy_user_transitions(struct acl_role_label *rolep)
56971+{
56972+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
56973+
56974+ unsigned int len;
56975+ char *tmp;
56976+
56977+ rusertp = rolep->transitions;
56978+
56979+ while (rusertp) {
56980+ rlast = rtmp;
56981+
56982+ if ((rtmp = (struct role_transition *)
56983+ acl_alloc(sizeof (struct role_transition))) == NULL)
56984+ return -ENOMEM;
56985+
56986+ if (copy_from_user(rtmp, rusertp,
56987+ sizeof (struct role_transition)))
56988+ return -EFAULT;
56989+
56990+ rusertp = rtmp->prev;
56991+
56992+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
56993+
56994+ if (!len || len >= GR_SPROLE_LEN)
56995+ return -EINVAL;
56996+
56997+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56998+ return -ENOMEM;
56999+
57000+ if (copy_from_user(tmp, rtmp->rolename, len))
57001+ return -EFAULT;
57002+ tmp[len-1] = '\0';
57003+ rtmp->rolename = tmp;
57004+
57005+ if (!rlast) {
57006+ rtmp->prev = NULL;
57007+ rolep->transitions = rtmp;
57008+ } else {
57009+ rlast->next = rtmp;
57010+ rtmp->prev = rlast;
57011+ }
57012+
57013+ if (!rusertp)
57014+ rtmp->next = NULL;
57015+ }
57016+
57017+ return 0;
57018+}
57019+
57020+static struct acl_subject_label *
57021+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
57022+{
57023+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
57024+ unsigned int len;
57025+ char *tmp;
57026+ __u32 num_objs;
57027+ struct acl_ip_label **i_tmp, *i_utmp2;
57028+ struct gr_hash_struct ghash;
57029+ struct subject_map *subjmap;
57030+ unsigned int i_num;
57031+ int err;
57032+
57033+ s_tmp = lookup_subject_map(userp);
57034+
57035+ /* we've already copied this subject into the kernel, just return
57036+ the reference to it, and don't copy it over again
57037+ */
57038+ if (s_tmp)
57039+ return(s_tmp);
57040+
57041+ if ((s_tmp = (struct acl_subject_label *)
57042+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
57043+ return ERR_PTR(-ENOMEM);
57044+
57045+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
57046+ if (subjmap == NULL)
57047+ return ERR_PTR(-ENOMEM);
57048+
57049+ subjmap->user = userp;
57050+ subjmap->kernel = s_tmp;
57051+ insert_subj_map_entry(subjmap);
57052+
57053+ if (copy_from_user(s_tmp, userp,
57054+ sizeof (struct acl_subject_label)))
57055+ return ERR_PTR(-EFAULT);
57056+
57057+ len = strnlen_user(s_tmp->filename, PATH_MAX);
57058+
57059+ if (!len || len >= PATH_MAX)
57060+ return ERR_PTR(-EINVAL);
57061+
57062+ if ((tmp = (char *) acl_alloc(len)) == NULL)
57063+ return ERR_PTR(-ENOMEM);
57064+
57065+ if (copy_from_user(tmp, s_tmp->filename, len))
57066+ return ERR_PTR(-EFAULT);
57067+ tmp[len-1] = '\0';
57068+ s_tmp->filename = tmp;
57069+
57070+ if (!strcmp(s_tmp->filename, "/"))
57071+ role->root_label = s_tmp;
57072+
57073+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
57074+ return ERR_PTR(-EFAULT);
57075+
57076+ /* copy user and group transition tables */
57077+
57078+ if (s_tmp->user_trans_num) {
57079+ uid_t *uidlist;
57080+
57081+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
57082+ if (uidlist == NULL)
57083+ return ERR_PTR(-ENOMEM);
57084+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
57085+ return ERR_PTR(-EFAULT);
57086+
57087+ s_tmp->user_transitions = uidlist;
57088+ }
57089+
57090+ if (s_tmp->group_trans_num) {
57091+ gid_t *gidlist;
57092+
57093+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
57094+ if (gidlist == NULL)
57095+ return ERR_PTR(-ENOMEM);
57096+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
57097+ return ERR_PTR(-EFAULT);
57098+
57099+ s_tmp->group_transitions = gidlist;
57100+ }
57101+
57102+ /* set up object hash table */
57103+ num_objs = count_user_objs(ghash.first);
57104+
57105+ s_tmp->obj_hash_size = num_objs;
57106+ s_tmp->obj_hash =
57107+ (struct acl_object_label **)
57108+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
57109+
57110+ if (!s_tmp->obj_hash)
57111+ return ERR_PTR(-ENOMEM);
57112+
57113+ memset(s_tmp->obj_hash, 0,
57114+ s_tmp->obj_hash_size *
57115+ sizeof (struct acl_object_label *));
57116+
57117+ /* add in objects */
57118+ err = copy_user_objs(ghash.first, s_tmp, role);
57119+
57120+ if (err)
57121+ return ERR_PTR(err);
57122+
57123+ /* set pointer for parent subject */
57124+ if (s_tmp->parent_subject) {
57125+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
57126+
57127+ if (IS_ERR(s_tmp2))
57128+ return s_tmp2;
57129+
57130+ s_tmp->parent_subject = s_tmp2;
57131+ }
57132+
57133+ /* add in ip acls */
57134+
57135+ if (!s_tmp->ip_num) {
57136+ s_tmp->ips = NULL;
57137+ goto insert;
57138+ }
57139+
57140+ i_tmp =
57141+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
57142+ sizeof (struct acl_ip_label *));
57143+
57144+ if (!i_tmp)
57145+ return ERR_PTR(-ENOMEM);
57146+
57147+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
57148+ *(i_tmp + i_num) =
57149+ (struct acl_ip_label *)
57150+ acl_alloc(sizeof (struct acl_ip_label));
57151+ if (!*(i_tmp + i_num))
57152+ return ERR_PTR(-ENOMEM);
57153+
57154+ if (copy_from_user
57155+ (&i_utmp2, s_tmp->ips + i_num,
57156+ sizeof (struct acl_ip_label *)))
57157+ return ERR_PTR(-EFAULT);
57158+
57159+ if (copy_from_user
57160+ (*(i_tmp + i_num), i_utmp2,
57161+ sizeof (struct acl_ip_label)))
57162+ return ERR_PTR(-EFAULT);
57163+
57164+ if ((*(i_tmp + i_num))->iface == NULL)
57165+ continue;
57166+
57167+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
57168+ if (!len || len >= IFNAMSIZ)
57169+ return ERR_PTR(-EINVAL);
57170+ tmp = acl_alloc(len);
57171+ if (tmp == NULL)
57172+ return ERR_PTR(-ENOMEM);
57173+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
57174+ return ERR_PTR(-EFAULT);
57175+ (*(i_tmp + i_num))->iface = tmp;
57176+ }
57177+
57178+ s_tmp->ips = i_tmp;
57179+
57180+insert:
57181+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
57182+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
57183+ return ERR_PTR(-ENOMEM);
57184+
57185+ return s_tmp;
57186+}
57187+
57188+static int
57189+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
57190+{
57191+ struct acl_subject_label s_pre;
57192+ struct acl_subject_label * ret;
57193+ int err;
57194+
57195+ while (userp) {
57196+ if (copy_from_user(&s_pre, userp,
57197+ sizeof (struct acl_subject_label)))
57198+ return -EFAULT;
57199+
57200+ /* do not add nested subjects here, add
57201+ while parsing objects
57202+ */
57203+
57204+ if (s_pre.mode & GR_NESTED) {
57205+ userp = s_pre.prev;
57206+ continue;
57207+ }
57208+
57209+ ret = do_copy_user_subj(userp, role);
57210+
57211+ err = PTR_ERR(ret);
57212+ if (IS_ERR(ret))
57213+ return err;
57214+
57215+ insert_acl_subj_label(ret, role);
57216+
57217+ userp = s_pre.prev;
57218+ }
57219+
57220+ return 0;
57221+}
57222+
57223+static int
57224+copy_user_acl(struct gr_arg *arg)
57225+{
57226+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
57227+ struct sprole_pw *sptmp;
57228+ struct gr_hash_struct *ghash;
57229+ uid_t *domainlist;
57230+ unsigned int r_num;
57231+ unsigned int len;
57232+ char *tmp;
57233+ int err = 0;
57234+ __u16 i;
57235+ __u32 num_subjs;
57236+
57237+ /* we need a default and kernel role */
57238+ if (arg->role_db.num_roles < 2)
57239+ return -EINVAL;
57240+
57241+ /* copy special role authentication info from userspace */
57242+
57243+ num_sprole_pws = arg->num_sprole_pws;
57244+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
57245+
57246+ if (!acl_special_roles) {
57247+ err = -ENOMEM;
57248+ goto cleanup;
57249+ }
57250+
57251+ for (i = 0; i < num_sprole_pws; i++) {
57252+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
57253+ if (!sptmp) {
57254+ err = -ENOMEM;
57255+ goto cleanup;
57256+ }
57257+ if (copy_from_user(sptmp, arg->sprole_pws + i,
57258+ sizeof (struct sprole_pw))) {
57259+ err = -EFAULT;
57260+ goto cleanup;
57261+ }
57262+
57263+ len =
57264+ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
57265+
57266+ if (!len || len >= GR_SPROLE_LEN) {
57267+ err = -EINVAL;
57268+ goto cleanup;
57269+ }
57270+
57271+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
57272+ err = -ENOMEM;
57273+ goto cleanup;
57274+ }
57275+
57276+ if (copy_from_user(tmp, sptmp->rolename, len)) {
57277+ err = -EFAULT;
57278+ goto cleanup;
57279+ }
57280+ tmp[len-1] = '\0';
57281+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57282+ printk(KERN_ALERT "Copying special role %s\n", tmp);
57283+#endif
57284+ sptmp->rolename = tmp;
57285+ acl_special_roles[i] = sptmp;
57286+ }
57287+
57288+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
57289+
57290+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
57291+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
57292+
57293+ if (!r_tmp) {
57294+ err = -ENOMEM;
57295+ goto cleanup;
57296+ }
57297+
57298+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
57299+ sizeof (struct acl_role_label *))) {
57300+ err = -EFAULT;
57301+ goto cleanup;
57302+ }
57303+
57304+ if (copy_from_user(r_tmp, r_utmp2,
57305+ sizeof (struct acl_role_label))) {
57306+ err = -EFAULT;
57307+ goto cleanup;
57308+ }
57309+
57310+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
57311+
57312+ if (!len || len >= PATH_MAX) {
57313+ err = -EINVAL;
57314+ goto cleanup;
57315+ }
57316+
57317+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
57318+ err = -ENOMEM;
57319+ goto cleanup;
57320+ }
57321+ if (copy_from_user(tmp, r_tmp->rolename, len)) {
57322+ err = -EFAULT;
57323+ goto cleanup;
57324+ }
57325+ tmp[len-1] = '\0';
57326+ r_tmp->rolename = tmp;
57327+
57328+ if (!strcmp(r_tmp->rolename, "default")
57329+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
57330+ default_role = r_tmp;
57331+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
57332+ kernel_role = r_tmp;
57333+ }
57334+
57335+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
57336+ err = -ENOMEM;
57337+ goto cleanup;
57338+ }
57339+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
57340+ err = -EFAULT;
57341+ goto cleanup;
57342+ }
57343+
57344+ r_tmp->hash = ghash;
57345+
57346+ num_subjs = count_user_subjs(r_tmp->hash->first);
57347+
57348+ r_tmp->subj_hash_size = num_subjs;
57349+ r_tmp->subj_hash =
57350+ (struct acl_subject_label **)
57351+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
57352+
57353+ if (!r_tmp->subj_hash) {
57354+ err = -ENOMEM;
57355+ goto cleanup;
57356+ }
57357+
57358+ err = copy_user_allowedips(r_tmp);
57359+ if (err)
57360+ goto cleanup;
57361+
57362+ /* copy domain info */
57363+ if (r_tmp->domain_children != NULL) {
57364+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
57365+ if (domainlist == NULL) {
57366+ err = -ENOMEM;
57367+ goto cleanup;
57368+ }
57369+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
57370+ err = -EFAULT;
57371+ goto cleanup;
57372+ }
57373+ r_tmp->domain_children = domainlist;
57374+ }
57375+
57376+ err = copy_user_transitions(r_tmp);
57377+ if (err)
57378+ goto cleanup;
57379+
57380+ memset(r_tmp->subj_hash, 0,
57381+ r_tmp->subj_hash_size *
57382+ sizeof (struct acl_subject_label *));
57383+
57384+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
57385+
57386+ if (err)
57387+ goto cleanup;
57388+
57389+ /* set nested subject list to null */
57390+ r_tmp->hash->first = NULL;
57391+
57392+ insert_acl_role_label(r_tmp);
57393+ }
57394+
57395+ goto return_err;
57396+ cleanup:
57397+ free_variables();
57398+ return_err:
57399+ return err;
57400+
57401+}
57402+
57403+static int
57404+gracl_init(struct gr_arg *args)
57405+{
57406+ int error = 0;
57407+
57408+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
57409+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
57410+
57411+ if (init_variables(args)) {
57412+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
57413+ error = -ENOMEM;
57414+ free_variables();
57415+ goto out;
57416+ }
57417+
57418+ error = copy_user_acl(args);
57419+ free_init_variables();
57420+ if (error) {
57421+ free_variables();
57422+ goto out;
57423+ }
57424+
57425+ if ((error = gr_set_acls(0))) {
57426+ free_variables();
57427+ goto out;
57428+ }
57429+
57430+ pax_open_kernel();
57431+ gr_status |= GR_READY;
57432+ pax_close_kernel();
57433+
57434+ out:
57435+ return error;
57436+}
57437+
57438+/* derived from glibc fnmatch() 0: match, 1: no match*/
57439+
57440+static int
57441+glob_match(const char *p, const char *n)
57442+{
57443+ char c;
57444+
57445+ while ((c = *p++) != '\0') {
57446+ switch (c) {
57447+ case '?':
57448+ if (*n == '\0')
57449+ return 1;
57450+ else if (*n == '/')
57451+ return 1;
57452+ break;
57453+ case '\\':
57454+ if (*n != c)
57455+ return 1;
57456+ break;
57457+ case '*':
57458+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
57459+ if (*n == '/')
57460+ return 1;
57461+ else if (c == '?') {
57462+ if (*n == '\0')
57463+ return 1;
57464+ else
57465+ ++n;
57466+ }
57467+ }
57468+ if (c == '\0') {
57469+ return 0;
57470+ } else {
57471+ const char *endp;
57472+
57473+ if ((endp = strchr(n, '/')) == NULL)
57474+ endp = n + strlen(n);
57475+
57476+ if (c == '[') {
57477+ for (--p; n < endp; ++n)
57478+ if (!glob_match(p, n))
57479+ return 0;
57480+ } else if (c == '/') {
57481+ while (*n != '\0' && *n != '/')
57482+ ++n;
57483+ if (*n == '/' && !glob_match(p, n + 1))
57484+ return 0;
57485+ } else {
57486+ for (--p; n < endp; ++n)
57487+ if (*n == c && !glob_match(p, n))
57488+ return 0;
57489+ }
57490+
57491+ return 1;
57492+ }
57493+ case '[':
57494+ {
57495+ int not;
57496+ char cold;
57497+
57498+ if (*n == '\0' || *n == '/')
57499+ return 1;
57500+
57501+ not = (*p == '!' || *p == '^');
57502+ if (not)
57503+ ++p;
57504+
57505+ c = *p++;
57506+ for (;;) {
57507+ unsigned char fn = (unsigned char)*n;
57508+
57509+ if (c == '\0')
57510+ return 1;
57511+ else {
57512+ if (c == fn)
57513+ goto matched;
57514+ cold = c;
57515+ c = *p++;
57516+
57517+ if (c == '-' && *p != ']') {
57518+ unsigned char cend = *p++;
57519+
57520+ if (cend == '\0')
57521+ return 1;
57522+
57523+ if (cold <= fn && fn <= cend)
57524+ goto matched;
57525+
57526+ c = *p++;
57527+ }
57528+ }
57529+
57530+ if (c == ']')
57531+ break;
57532+ }
57533+ if (!not)
57534+ return 1;
57535+ break;
57536+ matched:
57537+ while (c != ']') {
57538+ if (c == '\0')
57539+ return 1;
57540+
57541+ c = *p++;
57542+ }
57543+ if (not)
57544+ return 1;
57545+ }
57546+ break;
57547+ default:
57548+ if (c != *n)
57549+ return 1;
57550+ }
57551+
57552+ ++n;
57553+ }
57554+
57555+ if (*n == '\0')
57556+ return 0;
57557+
57558+ if (*n == '/')
57559+ return 0;
57560+
57561+ return 1;
57562+}
57563+
57564+static struct acl_object_label *
57565+chk_glob_label(struct acl_object_label *globbed,
57566+ struct dentry *dentry, struct vfsmount *mnt, char **path)
57567+{
57568+ struct acl_object_label *tmp;
57569+
57570+ if (*path == NULL)
57571+ *path = gr_to_filename_nolock(dentry, mnt);
57572+
57573+ tmp = globbed;
57574+
57575+ while (tmp) {
57576+ if (!glob_match(tmp->filename, *path))
57577+ return tmp;
57578+ tmp = tmp->next;
57579+ }
57580+
57581+ return NULL;
57582+}
57583+
57584+static struct acl_object_label *
57585+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
57586+ const ino_t curr_ino, const dev_t curr_dev,
57587+ const struct acl_subject_label *subj, char **path, const int checkglob)
57588+{
57589+ struct acl_subject_label *tmpsubj;
57590+ struct acl_object_label *retval;
57591+ struct acl_object_label *retval2;
57592+
57593+ tmpsubj = (struct acl_subject_label *) subj;
57594+ read_lock(&gr_inode_lock);
57595+ do {
57596+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
57597+ if (retval) {
57598+ if (checkglob && retval->globbed) {
57599+ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
57600+ (struct vfsmount *)orig_mnt, path);
57601+ if (retval2)
57602+ retval = retval2;
57603+ }
57604+ break;
57605+ }
57606+ } while ((tmpsubj = tmpsubj->parent_subject));
57607+ read_unlock(&gr_inode_lock);
57608+
57609+ return retval;
57610+}
57611+
57612+static __inline__ struct acl_object_label *
57613+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
57614+ const struct dentry *curr_dentry,
57615+ const struct acl_subject_label *subj, char **path, const int checkglob)
57616+{
57617+ int newglob = checkglob;
57618+
57619+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
57620+ as we don't want a / * rule to match instead of the / object
57621+ don't do this for create lookups that call this function though, since they're looking up
57622+ on the parent and thus need globbing checks on all paths
57623+ */
57624+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
57625+ newglob = GR_NO_GLOB;
57626+
57627+ return __full_lookup(orig_dentry, orig_mnt,
57628+ curr_dentry->d_inode->i_ino,
57629+ __get_dev(curr_dentry), subj, path, newglob);
57630+}
57631+
57632+static struct acl_object_label *
57633+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57634+ const struct acl_subject_label *subj, char *path, const int checkglob)
57635+{
57636+ struct dentry *dentry = (struct dentry *) l_dentry;
57637+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
57638+ struct acl_object_label *retval;
57639+
57640+ spin_lock(&dcache_lock);
57641+ spin_lock(&vfsmount_lock);
57642+
57643+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
57644+#ifdef CONFIG_NET
57645+ mnt == sock_mnt ||
57646+#endif
57647+#ifdef CONFIG_HUGETLBFS
57648+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
57649+#endif
57650+ /* ignore Eric Biederman */
57651+ IS_PRIVATE(l_dentry->d_inode))) {
57652+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
57653+ goto out;
57654+ }
57655+
57656+ for (;;) {
57657+ if (dentry == real_root && mnt == real_root_mnt)
57658+ break;
57659+
57660+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
57661+ if (mnt->mnt_parent == mnt)
57662+ break;
57663+
57664+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57665+ if (retval != NULL)
57666+ goto out;
57667+
57668+ dentry = mnt->mnt_mountpoint;
57669+ mnt = mnt->mnt_parent;
57670+ continue;
57671+ }
57672+
57673+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57674+ if (retval != NULL)
57675+ goto out;
57676+
57677+ dentry = dentry->d_parent;
57678+ }
57679+
57680+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57681+
57682+ if (retval == NULL)
57683+ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path, checkglob);
57684+out:
57685+ spin_unlock(&vfsmount_lock);
57686+ spin_unlock(&dcache_lock);
57687+
57688+ BUG_ON(retval == NULL);
57689+
57690+ return retval;
57691+}
57692+
57693+static __inline__ struct acl_object_label *
57694+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57695+ const struct acl_subject_label *subj)
57696+{
57697+ char *path = NULL;
57698+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
57699+}
57700+
57701+static __inline__ struct acl_object_label *
57702+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57703+ const struct acl_subject_label *subj)
57704+{
57705+ char *path = NULL;
57706+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
57707+}
57708+
57709+static __inline__ struct acl_object_label *
57710+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57711+ const struct acl_subject_label *subj, char *path)
57712+{
57713+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
57714+}
57715+
57716+static struct acl_subject_label *
57717+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57718+ const struct acl_role_label *role)
57719+{
57720+ struct dentry *dentry = (struct dentry *) l_dentry;
57721+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
57722+ struct acl_subject_label *retval;
57723+
57724+ spin_lock(&dcache_lock);
57725+ spin_lock(&vfsmount_lock);
57726+
57727+ for (;;) {
57728+ if (dentry == real_root && mnt == real_root_mnt)
57729+ break;
57730+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
57731+ if (mnt->mnt_parent == mnt)
57732+ break;
57733+
57734+ read_lock(&gr_inode_lock);
57735+ retval =
57736+ lookup_acl_subj_label(dentry->d_inode->i_ino,
57737+ __get_dev(dentry), role);
57738+ read_unlock(&gr_inode_lock);
57739+ if (retval != NULL)
57740+ goto out;
57741+
57742+ dentry = mnt->mnt_mountpoint;
57743+ mnt = mnt->mnt_parent;
57744+ continue;
57745+ }
57746+
57747+ read_lock(&gr_inode_lock);
57748+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
57749+ __get_dev(dentry), role);
57750+ read_unlock(&gr_inode_lock);
57751+ if (retval != NULL)
57752+ goto out;
57753+
57754+ dentry = dentry->d_parent;
57755+ }
57756+
57757+ read_lock(&gr_inode_lock);
57758+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
57759+ __get_dev(dentry), role);
57760+ read_unlock(&gr_inode_lock);
57761+
57762+ if (unlikely(retval == NULL)) {
57763+ read_lock(&gr_inode_lock);
57764+ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
57765+ __get_dev(real_root), role);
57766+ read_unlock(&gr_inode_lock);
57767+ }
57768+out:
57769+ spin_unlock(&vfsmount_lock);
57770+ spin_unlock(&dcache_lock);
57771+
57772+ BUG_ON(retval == NULL);
57773+
57774+ return retval;
57775+}
57776+
57777+static void
57778+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
57779+{
57780+ struct task_struct *task = current;
57781+ const struct cred *cred = current_cred();
57782+
57783+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
57784+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57785+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57786+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
57787+
57788+ return;
57789+}
57790+
57791+static void
57792+gr_log_learn_sysctl(const char *path, const __u32 mode)
57793+{
57794+ struct task_struct *task = current;
57795+ const struct cred *cred = current_cred();
57796+
57797+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
57798+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57799+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57800+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
57801+
57802+ return;
57803+}
57804+
57805+static void
57806+gr_log_learn_id_change(const char type, const unsigned int real,
57807+ const unsigned int effective, const unsigned int fs)
57808+{
57809+ struct task_struct *task = current;
57810+ const struct cred *cred = current_cred();
57811+
57812+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
57813+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57814+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57815+ type, real, effective, fs, &task->signal->saved_ip);
57816+
57817+ return;
57818+}
57819+
57820+__u32
57821+gr_search_file(const struct dentry * dentry, const __u32 mode,
57822+ const struct vfsmount * mnt)
57823+{
57824+ __u32 retval = mode;
57825+ struct acl_subject_label *curracl;
57826+ struct acl_object_label *currobj;
57827+
57828+ if (unlikely(!(gr_status & GR_READY)))
57829+ return (mode & ~GR_AUDITS);
57830+
57831+ curracl = current->acl;
57832+
57833+ currobj = chk_obj_label(dentry, mnt, curracl);
57834+ retval = currobj->mode & mode;
57835+
57836+ /* if we're opening a specified transfer file for writing
57837+ (e.g. /dev/initctl), then transfer our role to init
57838+ */
57839+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
57840+ current->role->roletype & GR_ROLE_PERSIST)) {
57841+ struct task_struct *task = init_pid_ns.child_reaper;
57842+
57843+ if (task->role != current->role) {
57844+ task->acl_sp_role = 0;
57845+ task->acl_role_id = current->acl_role_id;
57846+ task->role = current->role;
57847+ rcu_read_lock();
57848+ read_lock(&grsec_exec_file_lock);
57849+ gr_apply_subject_to_task(task);
57850+ read_unlock(&grsec_exec_file_lock);
57851+ rcu_read_unlock();
57852+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
57853+ }
57854+ }
57855+
57856+ if (unlikely
57857+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
57858+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
57859+ __u32 new_mode = mode;
57860+
57861+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
57862+
57863+ retval = new_mode;
57864+
57865+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
57866+ new_mode |= GR_INHERIT;
57867+
57868+ if (!(mode & GR_NOLEARN))
57869+ gr_log_learn(dentry, mnt, new_mode);
57870+ }
57871+
57872+ return retval;
57873+}
57874+
57875+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
57876+ const struct dentry *parent,
57877+ const struct vfsmount *mnt)
57878+{
57879+ struct name_entry *match;
57880+ struct acl_object_label *matchpo;
57881+ struct acl_subject_label *curracl;
57882+ char *path;
57883+
57884+ if (unlikely(!(gr_status & GR_READY)))
57885+ return NULL;
57886+
57887+ preempt_disable();
57888+ path = gr_to_filename_rbac(new_dentry, mnt);
57889+ match = lookup_name_entry_create(path);
57890+
57891+ curracl = current->acl;
57892+
57893+ if (match) {
57894+ read_lock(&gr_inode_lock);
57895+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
57896+ read_unlock(&gr_inode_lock);
57897+
57898+ if (matchpo) {
57899+ preempt_enable();
57900+ return matchpo;
57901+ }
57902+ }
57903+
57904+ // lookup parent
57905+
57906+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
57907+
57908+ preempt_enable();
57909+ return matchpo;
57910+}
57911+
57912+__u32
57913+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
57914+ const struct vfsmount * mnt, const __u32 mode)
57915+{
57916+ struct acl_object_label *matchpo;
57917+ __u32 retval;
57918+
57919+ if (unlikely(!(gr_status & GR_READY)))
57920+ return (mode & ~GR_AUDITS);
57921+
57922+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
57923+
57924+ retval = matchpo->mode & mode;
57925+
57926+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
57927+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
57928+ __u32 new_mode = mode;
57929+
57930+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
57931+
57932+ gr_log_learn(new_dentry, mnt, new_mode);
57933+ return new_mode;
57934+ }
57935+
57936+ return retval;
57937+}
57938+
57939+__u32
57940+gr_check_link(const struct dentry * new_dentry,
57941+ const struct dentry * parent_dentry,
57942+ const struct vfsmount * parent_mnt,
57943+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
57944+{
57945+ struct acl_object_label *obj;
57946+ __u32 oldmode, newmode;
57947+ __u32 needmode;
57948+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
57949+ GR_DELETE | GR_INHERIT;
57950+
57951+ if (unlikely(!(gr_status & GR_READY)))
57952+ return (GR_CREATE | GR_LINK);
57953+
57954+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
57955+ oldmode = obj->mode;
57956+
57957+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
57958+ newmode = obj->mode;
57959+
57960+ needmode = newmode & checkmodes;
57961+
57962+ // old name for hardlink must have at least the permissions of the new name
57963+ if ((oldmode & needmode) != needmode)
57964+ goto bad;
57965+
57966+ // if old name had restrictions/auditing, make sure the new name does as well
57967+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
57968+
57969+ // don't allow hardlinking of suid/sgid files without permission
57970+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
57971+ needmode |= GR_SETID;
57972+
57973+ if ((newmode & needmode) != needmode)
57974+ goto bad;
57975+
57976+ // enforce minimum permissions
57977+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
57978+ return newmode;
57979+bad:
57980+ needmode = oldmode;
57981+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
57982+ needmode |= GR_SETID;
57983+
57984+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
57985+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
57986+ return (GR_CREATE | GR_LINK);
57987+ } else if (newmode & GR_SUPPRESS)
57988+ return GR_SUPPRESS;
57989+ else
57990+ return 0;
57991+}
57992+
57993+int
57994+gr_check_hidden_task(const struct task_struct *task)
57995+{
57996+ if (unlikely(!(gr_status & GR_READY)))
57997+ return 0;
57998+
57999+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
58000+ return 1;
58001+
58002+ return 0;
58003+}
58004+
58005+int
58006+gr_check_protected_task(const struct task_struct *task)
58007+{
58008+ if (unlikely(!(gr_status & GR_READY) || !task))
58009+ return 0;
58010+
58011+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
58012+ task->acl != current->acl)
58013+ return 1;
58014+
58015+ return 0;
58016+}
58017+
58018+int
58019+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
58020+{
58021+ struct task_struct *p;
58022+ int ret = 0;
58023+
58024+ if (unlikely(!(gr_status & GR_READY) || !pid))
58025+ return ret;
58026+
58027+ read_lock(&tasklist_lock);
58028+ do_each_pid_task(pid, type, p) {
58029+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
58030+ p->acl != current->acl) {
58031+ ret = 1;
58032+ goto out;
58033+ }
58034+ } while_each_pid_task(pid, type, p);
58035+out:
58036+ read_unlock(&tasklist_lock);
58037+
58038+ return ret;
58039+}
58040+
58041+void
58042+gr_copy_label(struct task_struct *tsk)
58043+{
58044+ tsk->signal->used_accept = 0;
58045+ tsk->acl_sp_role = 0;
58046+ tsk->acl_role_id = current->acl_role_id;
58047+ tsk->acl = current->acl;
58048+ tsk->role = current->role;
58049+ tsk->signal->curr_ip = current->signal->curr_ip;
58050+ tsk->signal->saved_ip = current->signal->saved_ip;
58051+ if (current->exec_file)
58052+ get_file(current->exec_file);
58053+ tsk->exec_file = current->exec_file;
58054+ tsk->is_writable = current->is_writable;
58055+ if (unlikely(current->signal->used_accept)) {
58056+ current->signal->curr_ip = 0;
58057+ current->signal->saved_ip = 0;
58058+ }
58059+
58060+ return;
58061+}
58062+
58063+static void
58064+gr_set_proc_res(struct task_struct *task)
58065+{
58066+ struct acl_subject_label *proc;
58067+ unsigned short i;
58068+
58069+ proc = task->acl;
58070+
58071+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
58072+ return;
58073+
58074+ for (i = 0; i < RLIM_NLIMITS; i++) {
58075+ if (!(proc->resmask & (1 << i)))
58076+ continue;
58077+
58078+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
58079+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
58080+ }
58081+
58082+ return;
58083+}
58084+
58085+extern int __gr_process_user_ban(struct user_struct *user);
58086+
58087+int
58088+gr_check_user_change(int real, int effective, int fs)
58089+{
58090+ unsigned int i;
58091+ __u16 num;
58092+ uid_t *uidlist;
58093+ int curuid;
58094+ int realok = 0;
58095+ int effectiveok = 0;
58096+ int fsok = 0;
58097+
58098+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58099+ struct user_struct *user;
58100+
58101+ if (real == -1)
58102+ goto skipit;
58103+
58104+ user = find_user(real);
58105+ if (user == NULL)
58106+ goto skipit;
58107+
58108+ if (__gr_process_user_ban(user)) {
58109+ /* for find_user */
58110+ free_uid(user);
58111+ return 1;
58112+ }
58113+
58114+ /* for find_user */
58115+ free_uid(user);
58116+
58117+skipit:
58118+#endif
58119+
58120+ if (unlikely(!(gr_status & GR_READY)))
58121+ return 0;
58122+
58123+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
58124+ gr_log_learn_id_change('u', real, effective, fs);
58125+
58126+ num = current->acl->user_trans_num;
58127+ uidlist = current->acl->user_transitions;
58128+
58129+ if (uidlist == NULL)
58130+ return 0;
58131+
58132+ if (real == -1)
58133+ realok = 1;
58134+ if (effective == -1)
58135+ effectiveok = 1;
58136+ if (fs == -1)
58137+ fsok = 1;
58138+
58139+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
58140+ for (i = 0; i < num; i++) {
58141+ curuid = (int)uidlist[i];
58142+ if (real == curuid)
58143+ realok = 1;
58144+ if (effective == curuid)
58145+ effectiveok = 1;
58146+ if (fs == curuid)
58147+ fsok = 1;
58148+ }
58149+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
58150+ for (i = 0; i < num; i++) {
58151+ curuid = (int)uidlist[i];
58152+ if (real == curuid)
58153+ break;
58154+ if (effective == curuid)
58155+ break;
58156+ if (fs == curuid)
58157+ break;
58158+ }
58159+ /* not in deny list */
58160+ if (i == num) {
58161+ realok = 1;
58162+ effectiveok = 1;
58163+ fsok = 1;
58164+ }
58165+ }
58166+
58167+ if (realok && effectiveok && fsok)
58168+ return 0;
58169+ else {
58170+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
58171+ return 1;
58172+ }
58173+}
58174+
58175+int
58176+gr_check_group_change(int real, int effective, int fs)
58177+{
58178+ unsigned int i;
58179+ __u16 num;
58180+ gid_t *gidlist;
58181+ int curgid;
58182+ int realok = 0;
58183+ int effectiveok = 0;
58184+ int fsok = 0;
58185+
58186+ if (unlikely(!(gr_status & GR_READY)))
58187+ return 0;
58188+
58189+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
58190+ gr_log_learn_id_change('g', real, effective, fs);
58191+
58192+ num = current->acl->group_trans_num;
58193+ gidlist = current->acl->group_transitions;
58194+
58195+ if (gidlist == NULL)
58196+ return 0;
58197+
58198+ if (real == -1)
58199+ realok = 1;
58200+ if (effective == -1)
58201+ effectiveok = 1;
58202+ if (fs == -1)
58203+ fsok = 1;
58204+
58205+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
58206+ for (i = 0; i < num; i++) {
58207+ curgid = (int)gidlist[i];
58208+ if (real == curgid)
58209+ realok = 1;
58210+ if (effective == curgid)
58211+ effectiveok = 1;
58212+ if (fs == curgid)
58213+ fsok = 1;
58214+ }
58215+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
58216+ for (i = 0; i < num; i++) {
58217+ curgid = (int)gidlist[i];
58218+ if (real == curgid)
58219+ break;
58220+ if (effective == curgid)
58221+ break;
58222+ if (fs == curgid)
58223+ break;
58224+ }
58225+ /* not in deny list */
58226+ if (i == num) {
58227+ realok = 1;
58228+ effectiveok = 1;
58229+ fsok = 1;
58230+ }
58231+ }
58232+
58233+ if (realok && effectiveok && fsok)
58234+ return 0;
58235+ else {
58236+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
58237+ return 1;
58238+ }
58239+}
58240+
58241+void
58242+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
58243+{
58244+ struct acl_role_label *role = task->role;
58245+ struct acl_subject_label *subj = NULL;
58246+ struct acl_object_label *obj;
58247+ struct file *filp;
58248+
58249+ if (unlikely(!(gr_status & GR_READY)))
58250+ return;
58251+
58252+ filp = task->exec_file;
58253+
58254+ /* kernel process, we'll give them the kernel role */
58255+ if (unlikely(!filp)) {
58256+ task->role = kernel_role;
58257+ task->acl = kernel_role->root_label;
58258+ return;
58259+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
58260+ role = lookup_acl_role_label(task, uid, gid);
58261+
58262+ /* perform subject lookup in possibly new role
58263+ we can use this result below in the case where role == task->role
58264+ */
58265+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
58266+
58267+ /* if we changed uid/gid, but result in the same role
58268+ and are using inheritance, don't lose the inherited subject
58269+ if current subject is other than what normal lookup
58270+ would result in, we arrived via inheritance, don't
58271+ lose subject
58272+ */
58273+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
58274+ (subj == task->acl)))
58275+ task->acl = subj;
58276+
58277+ task->role = role;
58278+
58279+ task->is_writable = 0;
58280+
58281+ /* ignore additional mmap checks for processes that are writable
58282+ by the default ACL */
58283+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58284+ if (unlikely(obj->mode & GR_WRITE))
58285+ task->is_writable = 1;
58286+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
58287+ if (unlikely(obj->mode & GR_WRITE))
58288+ task->is_writable = 1;
58289+
58290+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58291+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
58292+#endif
58293+
58294+ gr_set_proc_res(task);
58295+
58296+ return;
58297+}
58298+
58299+int
58300+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58301+ const int unsafe_share)
58302+{
58303+ struct task_struct *task = current;
58304+ struct acl_subject_label *newacl;
58305+ struct acl_object_label *obj;
58306+ __u32 retmode;
58307+
58308+ if (unlikely(!(gr_status & GR_READY)))
58309+ return 0;
58310+
58311+ newacl = chk_subj_label(dentry, mnt, task->role);
58312+
58313+ task_lock(task);
58314+ if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
58315+ !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
58316+ !(task->role->roletype & GR_ROLE_GOD) &&
58317+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
58318+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
58319+ task_unlock(task);
58320+ if (unsafe_share)
58321+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
58322+ else
58323+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
58324+ return -EACCES;
58325+ }
58326+ task_unlock(task);
58327+
58328+ obj = chk_obj_label(dentry, mnt, task->acl);
58329+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
58330+
58331+ if (!(task->acl->mode & GR_INHERITLEARN) &&
58332+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
58333+ if (obj->nested)
58334+ task->acl = obj->nested;
58335+ else
58336+ task->acl = newacl;
58337+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
58338+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
58339+
58340+ task->is_writable = 0;
58341+
58342+ /* ignore additional mmap checks for processes that are writable
58343+ by the default ACL */
58344+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
58345+ if (unlikely(obj->mode & GR_WRITE))
58346+ task->is_writable = 1;
58347+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
58348+ if (unlikely(obj->mode & GR_WRITE))
58349+ task->is_writable = 1;
58350+
58351+ gr_set_proc_res(task);
58352+
58353+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58354+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
58355+#endif
58356+ return 0;
58357+}
58358+
58359+/* always called with valid inodev ptr */
58360+static void
58361+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
58362+{
58363+ struct acl_object_label *matchpo;
58364+ struct acl_subject_label *matchps;
58365+ struct acl_subject_label *subj;
58366+ struct acl_role_label *role;
58367+ unsigned int x;
58368+
58369+ FOR_EACH_ROLE_START(role)
58370+ FOR_EACH_SUBJECT_START(role, subj, x)
58371+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
58372+ matchpo->mode |= GR_DELETED;
58373+ FOR_EACH_SUBJECT_END(subj,x)
58374+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
58375+ if (subj->inode == ino && subj->device == dev)
58376+ subj->mode |= GR_DELETED;
58377+ FOR_EACH_NESTED_SUBJECT_END(subj)
58378+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
58379+ matchps->mode |= GR_DELETED;
58380+ FOR_EACH_ROLE_END(role)
58381+
58382+ inodev->nentry->deleted = 1;
58383+
58384+ return;
58385+}
58386+
58387+void
58388+gr_handle_delete(const ino_t ino, const dev_t dev)
58389+{
58390+ struct inodev_entry *inodev;
58391+
58392+ if (unlikely(!(gr_status & GR_READY)))
58393+ return;
58394+
58395+ write_lock(&gr_inode_lock);
58396+ inodev = lookup_inodev_entry(ino, dev);
58397+ if (inodev != NULL)
58398+ do_handle_delete(inodev, ino, dev);
58399+ write_unlock(&gr_inode_lock);
58400+
58401+ return;
58402+}
58403+
58404+static void
58405+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
58406+ const ino_t newinode, const dev_t newdevice,
58407+ struct acl_subject_label *subj)
58408+{
58409+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
58410+ struct acl_object_label *match;
58411+
58412+ match = subj->obj_hash[index];
58413+
58414+ while (match && (match->inode != oldinode ||
58415+ match->device != olddevice ||
58416+ !(match->mode & GR_DELETED)))
58417+ match = match->next;
58418+
58419+ if (match && (match->inode == oldinode)
58420+ && (match->device == olddevice)
58421+ && (match->mode & GR_DELETED)) {
58422+ if (match->prev == NULL) {
58423+ subj->obj_hash[index] = match->next;
58424+ if (match->next != NULL)
58425+ match->next->prev = NULL;
58426+ } else {
58427+ match->prev->next = match->next;
58428+ if (match->next != NULL)
58429+ match->next->prev = match->prev;
58430+ }
58431+ match->prev = NULL;
58432+ match->next = NULL;
58433+ match->inode = newinode;
58434+ match->device = newdevice;
58435+ match->mode &= ~GR_DELETED;
58436+
58437+ insert_acl_obj_label(match, subj);
58438+ }
58439+
58440+ return;
58441+}
58442+
58443+static void
58444+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
58445+ const ino_t newinode, const dev_t newdevice,
58446+ struct acl_role_label *role)
58447+{
58448+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
58449+ struct acl_subject_label *match;
58450+
58451+ match = role->subj_hash[index];
58452+
58453+ while (match && (match->inode != oldinode ||
58454+ match->device != olddevice ||
58455+ !(match->mode & GR_DELETED)))
58456+ match = match->next;
58457+
58458+ if (match && (match->inode == oldinode)
58459+ && (match->device == olddevice)
58460+ && (match->mode & GR_DELETED)) {
58461+ if (match->prev == NULL) {
58462+ role->subj_hash[index] = match->next;
58463+ if (match->next != NULL)
58464+ match->next->prev = NULL;
58465+ } else {
58466+ match->prev->next = match->next;
58467+ if (match->next != NULL)
58468+ match->next->prev = match->prev;
58469+ }
58470+ match->prev = NULL;
58471+ match->next = NULL;
58472+ match->inode = newinode;
58473+ match->device = newdevice;
58474+ match->mode &= ~GR_DELETED;
58475+
58476+ insert_acl_subj_label(match, role);
58477+ }
58478+
58479+ return;
58480+}
58481+
58482+static void
58483+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
58484+ const ino_t newinode, const dev_t newdevice)
58485+{
58486+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
58487+ struct inodev_entry *match;
58488+
58489+ match = inodev_set.i_hash[index];
58490+
58491+ while (match && (match->nentry->inode != oldinode ||
58492+ match->nentry->device != olddevice || !match->nentry->deleted))
58493+ match = match->next;
58494+
58495+ if (match && (match->nentry->inode == oldinode)
58496+ && (match->nentry->device == olddevice) &&
58497+ match->nentry->deleted) {
58498+ if (match->prev == NULL) {
58499+ inodev_set.i_hash[index] = match->next;
58500+ if (match->next != NULL)
58501+ match->next->prev = NULL;
58502+ } else {
58503+ match->prev->next = match->next;
58504+ if (match->next != NULL)
58505+ match->next->prev = match->prev;
58506+ }
58507+ match->prev = NULL;
58508+ match->next = NULL;
58509+ match->nentry->inode = newinode;
58510+ match->nentry->device = newdevice;
58511+ match->nentry->deleted = 0;
58512+
58513+ insert_inodev_entry(match);
58514+ }
58515+
58516+ return;
58517+}
58518+
58519+static void
58520+__do_handle_create(const struct name_entry *matchn, ino_t inode, dev_t dev)
58521+{
58522+ struct acl_subject_label *subj;
58523+ struct acl_role_label *role;
58524+ unsigned int x;
58525+
58526+ FOR_EACH_ROLE_START(role)
58527+ update_acl_subj_label(matchn->inode, matchn->device,
58528+ inode, dev, role);
58529+
58530+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
58531+ if ((subj->inode == inode) && (subj->device == dev)) {
58532+ subj->inode = inode;
58533+ subj->device = dev;
58534+ }
58535+ FOR_EACH_NESTED_SUBJECT_END(subj)
58536+ FOR_EACH_SUBJECT_START(role, subj, x)
58537+ update_acl_obj_label(matchn->inode, matchn->device,
58538+ inode, dev, subj);
58539+ FOR_EACH_SUBJECT_END(subj,x)
58540+ FOR_EACH_ROLE_END(role)
58541+
58542+ update_inodev_entry(matchn->inode, matchn->device, inode, dev);
58543+
58544+ return;
58545+}
58546+
58547+static void
58548+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
58549+ const struct vfsmount *mnt)
58550+{
58551+ ino_t ino = dentry->d_inode->i_ino;
58552+ dev_t dev = __get_dev(dentry);
58553+
58554+ __do_handle_create(matchn, ino, dev);
58555+
58556+ return;
58557+}
58558+
58559+void
58560+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58561+{
58562+ struct name_entry *matchn;
58563+
58564+ if (unlikely(!(gr_status & GR_READY)))
58565+ return;
58566+
58567+ preempt_disable();
58568+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
58569+
58570+ if (unlikely((unsigned long)matchn)) {
58571+ write_lock(&gr_inode_lock);
58572+ do_handle_create(matchn, dentry, mnt);
58573+ write_unlock(&gr_inode_lock);
58574+ }
58575+ preempt_enable();
58576+
58577+ return;
58578+}
58579+
58580+void
58581+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58582+{
58583+ struct name_entry *matchn;
58584+
58585+ if (unlikely(!(gr_status & GR_READY)))
58586+ return;
58587+
58588+ preempt_disable();
58589+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
58590+
58591+ if (unlikely((unsigned long)matchn)) {
58592+ write_lock(&gr_inode_lock);
58593+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
58594+ write_unlock(&gr_inode_lock);
58595+ }
58596+ preempt_enable();
58597+
58598+ return;
58599+}
58600+
58601+void
58602+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58603+ struct dentry *old_dentry,
58604+ struct dentry *new_dentry,
58605+ struct vfsmount *mnt, const __u8 replace)
58606+{
58607+ struct name_entry *matchn;
58608+ struct inodev_entry *inodev;
58609+ struct inode *inode = new_dentry->d_inode;
58610+ ino_t oldinode = old_dentry->d_inode->i_ino;
58611+ dev_t olddev = __get_dev(old_dentry);
58612+
58613+ /* vfs_rename swaps the name and parent link for old_dentry and
58614+ new_dentry
58615+ at this point, old_dentry has the new name, parent link, and inode
58616+ for the renamed file
58617+ if a file is being replaced by a rename, new_dentry has the inode
58618+ and name for the replaced file
58619+ */
58620+
58621+ if (unlikely(!(gr_status & GR_READY)))
58622+ return;
58623+
58624+ preempt_disable();
58625+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
58626+
58627+ /* we wouldn't have to check d_inode if it weren't for
58628+ NFS silly-renaming
58629+ */
58630+
58631+ write_lock(&gr_inode_lock);
58632+ if (unlikely(replace && inode)) {
58633+ ino_t newinode = inode->i_ino;
58634+ dev_t newdev = __get_dev(new_dentry);
58635+ inodev = lookup_inodev_entry(newinode, newdev);
58636+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
58637+ do_handle_delete(inodev, newinode, newdev);
58638+ }
58639+
58640+ inodev = lookup_inodev_entry(oldinode, olddev);
58641+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
58642+ do_handle_delete(inodev, oldinode, olddev);
58643+
58644+ if (unlikely((unsigned long)matchn))
58645+ do_handle_create(matchn, old_dentry, mnt);
58646+
58647+ write_unlock(&gr_inode_lock);
58648+ preempt_enable();
58649+
58650+ return;
58651+}
58652+
58653+static int
58654+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
58655+ unsigned char **sum)
58656+{
58657+ struct acl_role_label *r;
58658+ struct role_allowed_ip *ipp;
58659+ struct role_transition *trans;
58660+ unsigned int i;
58661+ int found = 0;
58662+ u32 curr_ip = current->signal->curr_ip;
58663+
58664+ current->signal->saved_ip = curr_ip;
58665+
58666+ /* check transition table */
58667+
58668+ for (trans = current->role->transitions; trans; trans = trans->next) {
58669+ if (!strcmp(rolename, trans->rolename)) {
58670+ found = 1;
58671+ break;
58672+ }
58673+ }
58674+
58675+ if (!found)
58676+ return 0;
58677+
58678+ /* handle special roles that do not require authentication
58679+ and check ip */
58680+
58681+ FOR_EACH_ROLE_START(r)
58682+ if (!strcmp(rolename, r->rolename) &&
58683+ (r->roletype & GR_ROLE_SPECIAL)) {
58684+ found = 0;
58685+ if (r->allowed_ips != NULL) {
58686+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
58687+ if ((ntohl(curr_ip) & ipp->netmask) ==
58688+ (ntohl(ipp->addr) & ipp->netmask))
58689+ found = 1;
58690+ }
58691+ } else
58692+ found = 2;
58693+ if (!found)
58694+ return 0;
58695+
58696+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
58697+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
58698+ *salt = NULL;
58699+ *sum = NULL;
58700+ return 1;
58701+ }
58702+ }
58703+ FOR_EACH_ROLE_END(r)
58704+
58705+ for (i = 0; i < num_sprole_pws; i++) {
58706+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
58707+ *salt = acl_special_roles[i]->salt;
58708+ *sum = acl_special_roles[i]->sum;
58709+ return 1;
58710+ }
58711+ }
58712+
58713+ return 0;
58714+}
58715+
58716+static void
58717+assign_special_role(char *rolename)
58718+{
58719+ struct acl_object_label *obj;
58720+ struct acl_role_label *r;
58721+ struct acl_role_label *assigned = NULL;
58722+ struct task_struct *tsk;
58723+ struct file *filp;
58724+
58725+ FOR_EACH_ROLE_START(r)
58726+ if (!strcmp(rolename, r->rolename) &&
58727+ (r->roletype & GR_ROLE_SPECIAL)) {
58728+ assigned = r;
58729+ break;
58730+ }
58731+ FOR_EACH_ROLE_END(r)
58732+
58733+ if (!assigned)
58734+ return;
58735+
58736+ read_lock(&tasklist_lock);
58737+ read_lock(&grsec_exec_file_lock);
58738+
58739+ tsk = current->real_parent;
58740+ if (tsk == NULL)
58741+ goto out_unlock;
58742+
58743+ filp = tsk->exec_file;
58744+ if (filp == NULL)
58745+ goto out_unlock;
58746+
58747+ tsk->is_writable = 0;
58748+
58749+ tsk->acl_sp_role = 1;
58750+ tsk->acl_role_id = ++acl_sp_role_value;
58751+ tsk->role = assigned;
58752+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
58753+
58754+ /* ignore additional mmap checks for processes that are writable
58755+ by the default ACL */
58756+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58757+ if (unlikely(obj->mode & GR_WRITE))
58758+ tsk->is_writable = 1;
58759+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
58760+ if (unlikely(obj->mode & GR_WRITE))
58761+ tsk->is_writable = 1;
58762+
58763+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58764+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
58765+#endif
58766+
58767+out_unlock:
58768+ read_unlock(&grsec_exec_file_lock);
58769+ read_unlock(&tasklist_lock);
58770+ return;
58771+}
58772+
58773+int gr_check_secure_terminal(struct task_struct *task)
58774+{
58775+ struct task_struct *p, *p2, *p3;
58776+ struct files_struct *files;
58777+ struct fdtable *fdt;
58778+ struct file *our_file = NULL, *file;
58779+ int i;
58780+
58781+ if (task->signal->tty == NULL)
58782+ return 1;
58783+
58784+ files = get_files_struct(task);
58785+ if (files != NULL) {
58786+ rcu_read_lock();
58787+ fdt = files_fdtable(files);
58788+ for (i=0; i < fdt->max_fds; i++) {
58789+ file = fcheck_files(files, i);
58790+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
58791+ get_file(file);
58792+ our_file = file;
58793+ }
58794+ }
58795+ rcu_read_unlock();
58796+ put_files_struct(files);
58797+ }
58798+
58799+ if (our_file == NULL)
58800+ return 1;
58801+
58802+ read_lock(&tasklist_lock);
58803+ do_each_thread(p2, p) {
58804+ files = get_files_struct(p);
58805+ if (files == NULL ||
58806+ (p->signal && p->signal->tty == task->signal->tty)) {
58807+ if (files != NULL)
58808+ put_files_struct(files);
58809+ continue;
58810+ }
58811+ rcu_read_lock();
58812+ fdt = files_fdtable(files);
58813+ for (i=0; i < fdt->max_fds; i++) {
58814+ file = fcheck_files(files, i);
58815+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
58816+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
58817+ p3 = task;
58818+ while (p3->pid > 0) {
58819+ if (p3 == p)
58820+ break;
58821+ p3 = p3->real_parent;
58822+ }
58823+ if (p3 == p)
58824+ break;
58825+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
58826+ gr_handle_alertkill(p);
58827+ rcu_read_unlock();
58828+ put_files_struct(files);
58829+ read_unlock(&tasklist_lock);
58830+ fput(our_file);
58831+ return 0;
58832+ }
58833+ }
58834+ rcu_read_unlock();
58835+ put_files_struct(files);
58836+ } while_each_thread(p2, p);
58837+ read_unlock(&tasklist_lock);
58838+
58839+ fput(our_file);
58840+ return 1;
58841+}
58842+
58843+ssize_t
58844+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
58845+{
58846+ struct gr_arg_wrapper uwrap;
58847+ unsigned char *sprole_salt = NULL;
58848+ unsigned char *sprole_sum = NULL;
58849+ int error = sizeof (struct gr_arg_wrapper);
58850+ int error2 = 0;
58851+
58852+ mutex_lock(&gr_dev_mutex);
58853+
58854+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
58855+ error = -EPERM;
58856+ goto out;
58857+ }
58858+
58859+ if (count != sizeof (struct gr_arg_wrapper)) {
58860+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
58861+ error = -EINVAL;
58862+ goto out;
58863+ }
58864+
58865+
58866+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
58867+ gr_auth_expires = 0;
58868+ gr_auth_attempts = 0;
58869+ }
58870+
58871+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
58872+ error = -EFAULT;
58873+ goto out;
58874+ }
58875+
58876+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
58877+ error = -EINVAL;
58878+ goto out;
58879+ }
58880+
58881+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
58882+ error = -EFAULT;
58883+ goto out;
58884+ }
58885+
58886+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
58887+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
58888+ time_after(gr_auth_expires, get_seconds())) {
58889+ error = -EBUSY;
58890+ goto out;
58891+ }
58892+
58893+ /* if non-root trying to do anything other than use a special role,
58894+ do not attempt authentication, do not count towards authentication
58895+ locking
58896+ */
58897+
58898+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
58899+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
58900+ current_uid()) {
58901+ error = -EPERM;
58902+ goto out;
58903+ }
58904+
58905+ /* ensure pw and special role name are null terminated */
58906+
58907+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
58908+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
58909+
58910+ /* Okay.
58911+ * We have our enough of the argument structure..(we have yet
58912+ * to copy_from_user the tables themselves) . Copy the tables
58913+ * only if we need them, i.e. for loading operations. */
58914+
58915+ switch (gr_usermode->mode) {
58916+ case GR_STATUS:
58917+ if (gr_status & GR_READY) {
58918+ error = 1;
58919+ if (!gr_check_secure_terminal(current))
58920+ error = 3;
58921+ } else
58922+ error = 2;
58923+ goto out;
58924+ case GR_SHUTDOWN:
58925+ if ((gr_status & GR_READY)
58926+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58927+ pax_open_kernel();
58928+ gr_status &= ~GR_READY;
58929+ pax_close_kernel();
58930+
58931+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
58932+ free_variables();
58933+ memset(gr_usermode, 0, sizeof (struct gr_arg));
58934+ memset(gr_system_salt, 0, GR_SALT_LEN);
58935+ memset(gr_system_sum, 0, GR_SHA_LEN);
58936+ } else if (gr_status & GR_READY) {
58937+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
58938+ error = -EPERM;
58939+ } else {
58940+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
58941+ error = -EAGAIN;
58942+ }
58943+ break;
58944+ case GR_ENABLE:
58945+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
58946+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
58947+ else {
58948+ if (gr_status & GR_READY)
58949+ error = -EAGAIN;
58950+ else
58951+ error = error2;
58952+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
58953+ }
58954+ break;
58955+ case GR_RELOAD:
58956+ if (!(gr_status & GR_READY)) {
58957+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
58958+ error = -EAGAIN;
58959+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58960+ lock_kernel();
58961+
58962+ pax_open_kernel();
58963+ gr_status &= ~GR_READY;
58964+ pax_close_kernel();
58965+
58966+ free_variables();
58967+ if (!(error2 = gracl_init(gr_usermode))) {
58968+ unlock_kernel();
58969+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
58970+ } else {
58971+ unlock_kernel();
58972+ error = error2;
58973+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
58974+ }
58975+ } else {
58976+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
58977+ error = -EPERM;
58978+ }
58979+ break;
58980+ case GR_SEGVMOD:
58981+ if (unlikely(!(gr_status & GR_READY))) {
58982+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
58983+ error = -EAGAIN;
58984+ break;
58985+ }
58986+
58987+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58988+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
58989+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
58990+ struct acl_subject_label *segvacl;
58991+ segvacl =
58992+ lookup_acl_subj_label(gr_usermode->segv_inode,
58993+ gr_usermode->segv_device,
58994+ current->role);
58995+ if (segvacl) {
58996+ segvacl->crashes = 0;
58997+ segvacl->expires = 0;
58998+ }
58999+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
59000+ gr_remove_uid(gr_usermode->segv_uid);
59001+ }
59002+ } else {
59003+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
59004+ error = -EPERM;
59005+ }
59006+ break;
59007+ case GR_SPROLE:
59008+ case GR_SPROLEPAM:
59009+ if (unlikely(!(gr_status & GR_READY))) {
59010+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
59011+ error = -EAGAIN;
59012+ break;
59013+ }
59014+
59015+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
59016+ current->role->expires = 0;
59017+ current->role->auth_attempts = 0;
59018+ }
59019+
59020+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
59021+ time_after(current->role->expires, get_seconds())) {
59022+ error = -EBUSY;
59023+ goto out;
59024+ }
59025+
59026+ if (lookup_special_role_auth
59027+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
59028+ && ((!sprole_salt && !sprole_sum)
59029+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
59030+ char *p = "";
59031+ assign_special_role(gr_usermode->sp_role);
59032+ read_lock(&tasklist_lock);
59033+ if (current->real_parent)
59034+ p = current->real_parent->role->rolename;
59035+ read_unlock(&tasklist_lock);
59036+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
59037+ p, acl_sp_role_value);
59038+ } else {
59039+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
59040+ error = -EPERM;
59041+ if(!(current->role->auth_attempts++))
59042+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
59043+
59044+ goto out;
59045+ }
59046+ break;
59047+ case GR_UNSPROLE:
59048+ if (unlikely(!(gr_status & GR_READY))) {
59049+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
59050+ error = -EAGAIN;
59051+ break;
59052+ }
59053+
59054+ if (current->role->roletype & GR_ROLE_SPECIAL) {
59055+ char *p = "";
59056+ int i = 0;
59057+
59058+ read_lock(&tasklist_lock);
59059+ if (current->real_parent) {
59060+ p = current->real_parent->role->rolename;
59061+ i = current->real_parent->acl_role_id;
59062+ }
59063+ read_unlock(&tasklist_lock);
59064+
59065+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
59066+ gr_set_acls(1);
59067+ } else {
59068+ error = -EPERM;
59069+ goto out;
59070+ }
59071+ break;
59072+ default:
59073+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
59074+ error = -EINVAL;
59075+ break;
59076+ }
59077+
59078+ if (error != -EPERM)
59079+ goto out;
59080+
59081+ if(!(gr_auth_attempts++))
59082+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
59083+
59084+ out:
59085+ mutex_unlock(&gr_dev_mutex);
59086+ return error;
59087+}
59088+
59089+/* must be called with
59090+ rcu_read_lock();
59091+ read_lock(&tasklist_lock);
59092+ read_lock(&grsec_exec_file_lock);
59093+*/
59094+int gr_apply_subject_to_task(struct task_struct *task)
59095+{
59096+ struct acl_object_label *obj;
59097+ char *tmpname;
59098+ struct acl_subject_label *tmpsubj;
59099+ struct file *filp;
59100+ struct name_entry *nmatch;
59101+
59102+ filp = task->exec_file;
59103+ if (filp == NULL)
59104+ return 0;
59105+
59106+ /* the following is to apply the correct subject
59107+ on binaries running when the RBAC system
59108+ is enabled, when the binaries have been
59109+ replaced or deleted since their execution
59110+ -----
59111+ when the RBAC system starts, the inode/dev
59112+ from exec_file will be one the RBAC system
59113+ is unaware of. It only knows the inode/dev
59114+ of the present file on disk, or the absence
59115+ of it.
59116+ */
59117+ preempt_disable();
59118+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
59119+
59120+ nmatch = lookup_name_entry(tmpname);
59121+ preempt_enable();
59122+ tmpsubj = NULL;
59123+ if (nmatch) {
59124+ if (nmatch->deleted)
59125+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
59126+ else
59127+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
59128+ if (tmpsubj != NULL)
59129+ task->acl = tmpsubj;
59130+ }
59131+ if (tmpsubj == NULL)
59132+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
59133+ task->role);
59134+ if (task->acl) {
59135+ task->is_writable = 0;
59136+ /* ignore additional mmap checks for processes that are writable
59137+ by the default ACL */
59138+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59139+ if (unlikely(obj->mode & GR_WRITE))
59140+ task->is_writable = 1;
59141+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
59142+ if (unlikely(obj->mode & GR_WRITE))
59143+ task->is_writable = 1;
59144+
59145+ gr_set_proc_res(task);
59146+
59147+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59148+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
59149+#endif
59150+ } else {
59151+ return 1;
59152+ }
59153+
59154+ return 0;
59155+}
59156+
59157+int
59158+gr_set_acls(const int type)
59159+{
59160+ struct task_struct *task, *task2;
59161+ struct acl_role_label *role = current->role;
59162+ __u16 acl_role_id = current->acl_role_id;
59163+ const struct cred *cred;
59164+ int ret;
59165+
59166+ rcu_read_lock();
59167+ read_lock(&tasklist_lock);
59168+ read_lock(&grsec_exec_file_lock);
59169+ do_each_thread(task2, task) {
59170+ /* check to see if we're called from the exit handler,
59171+ if so, only replace ACLs that have inherited the admin
59172+ ACL */
59173+
59174+ if (type && (task->role != role ||
59175+ task->acl_role_id != acl_role_id))
59176+ continue;
59177+
59178+ task->acl_role_id = 0;
59179+ task->acl_sp_role = 0;
59180+
59181+ if (task->exec_file) {
59182+ cred = __task_cred(task);
59183+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
59184+
59185+ ret = gr_apply_subject_to_task(task);
59186+ if (ret) {
59187+ read_unlock(&grsec_exec_file_lock);
59188+ read_unlock(&tasklist_lock);
59189+ rcu_read_unlock();
59190+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
59191+ return ret;
59192+ }
59193+ } else {
59194+ // it's a kernel process
59195+ task->role = kernel_role;
59196+ task->acl = kernel_role->root_label;
59197+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
59198+ task->acl->mode &= ~GR_PROCFIND;
59199+#endif
59200+ }
59201+ } while_each_thread(task2, task);
59202+ read_unlock(&grsec_exec_file_lock);
59203+ read_unlock(&tasklist_lock);
59204+ rcu_read_unlock();
59205+
59206+ return 0;
59207+}
59208+
59209+void
59210+gr_learn_resource(const struct task_struct *task,
59211+ const int res, const unsigned long wanted, const int gt)
59212+{
59213+ struct acl_subject_label *acl;
59214+ const struct cred *cred;
59215+
59216+ if (unlikely((gr_status & GR_READY) &&
59217+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
59218+ goto skip_reslog;
59219+
59220+#ifdef CONFIG_GRKERNSEC_RESLOG
59221+ gr_log_resource(task, res, wanted, gt);
59222+#endif
59223+ skip_reslog:
59224+
59225+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
59226+ return;
59227+
59228+ acl = task->acl;
59229+
59230+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
59231+ !(acl->resmask & (1 << (unsigned short) res))))
59232+ return;
59233+
59234+ if (wanted >= acl->res[res].rlim_cur) {
59235+ unsigned long res_add;
59236+
59237+ res_add = wanted;
59238+ switch (res) {
59239+ case RLIMIT_CPU:
59240+ res_add += GR_RLIM_CPU_BUMP;
59241+ break;
59242+ case RLIMIT_FSIZE:
59243+ res_add += GR_RLIM_FSIZE_BUMP;
59244+ break;
59245+ case RLIMIT_DATA:
59246+ res_add += GR_RLIM_DATA_BUMP;
59247+ break;
59248+ case RLIMIT_STACK:
59249+ res_add += GR_RLIM_STACK_BUMP;
59250+ break;
59251+ case RLIMIT_CORE:
59252+ res_add += GR_RLIM_CORE_BUMP;
59253+ break;
59254+ case RLIMIT_RSS:
59255+ res_add += GR_RLIM_RSS_BUMP;
59256+ break;
59257+ case RLIMIT_NPROC:
59258+ res_add += GR_RLIM_NPROC_BUMP;
59259+ break;
59260+ case RLIMIT_NOFILE:
59261+ res_add += GR_RLIM_NOFILE_BUMP;
59262+ break;
59263+ case RLIMIT_MEMLOCK:
59264+ res_add += GR_RLIM_MEMLOCK_BUMP;
59265+ break;
59266+ case RLIMIT_AS:
59267+ res_add += GR_RLIM_AS_BUMP;
59268+ break;
59269+ case RLIMIT_LOCKS:
59270+ res_add += GR_RLIM_LOCKS_BUMP;
59271+ break;
59272+ case RLIMIT_SIGPENDING:
59273+ res_add += GR_RLIM_SIGPENDING_BUMP;
59274+ break;
59275+ case RLIMIT_MSGQUEUE:
59276+ res_add += GR_RLIM_MSGQUEUE_BUMP;
59277+ break;
59278+ case RLIMIT_NICE:
59279+ res_add += GR_RLIM_NICE_BUMP;
59280+ break;
59281+ case RLIMIT_RTPRIO:
59282+ res_add += GR_RLIM_RTPRIO_BUMP;
59283+ break;
59284+ case RLIMIT_RTTIME:
59285+ res_add += GR_RLIM_RTTIME_BUMP;
59286+ break;
59287+ }
59288+
59289+ acl->res[res].rlim_cur = res_add;
59290+
59291+ if (wanted > acl->res[res].rlim_max)
59292+ acl->res[res].rlim_max = res_add;
59293+
59294+ /* only log the subject filename, since resource logging is supported for
59295+ single-subject learning only */
59296+ rcu_read_lock();
59297+ cred = __task_cred(task);
59298+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
59299+ task->role->roletype, cred->uid, cred->gid, acl->filename,
59300+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
59301+ "", (unsigned long) res, &task->signal->saved_ip);
59302+ rcu_read_unlock();
59303+ }
59304+
59305+ return;
59306+}
59307+
59308+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
59309+void
59310+pax_set_initial_flags(struct linux_binprm *bprm)
59311+{
59312+ struct task_struct *task = current;
59313+ struct acl_subject_label *proc;
59314+ unsigned long flags;
59315+
59316+ if (unlikely(!(gr_status & GR_READY)))
59317+ return;
59318+
59319+ flags = pax_get_flags(task);
59320+
59321+ proc = task->acl;
59322+
59323+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
59324+ flags &= ~MF_PAX_PAGEEXEC;
59325+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
59326+ flags &= ~MF_PAX_SEGMEXEC;
59327+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
59328+ flags &= ~MF_PAX_RANDMMAP;
59329+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
59330+ flags &= ~MF_PAX_EMUTRAMP;
59331+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
59332+ flags &= ~MF_PAX_MPROTECT;
59333+
59334+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
59335+ flags |= MF_PAX_PAGEEXEC;
59336+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
59337+ flags |= MF_PAX_SEGMEXEC;
59338+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
59339+ flags |= MF_PAX_RANDMMAP;
59340+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
59341+ flags |= MF_PAX_EMUTRAMP;
59342+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
59343+ flags |= MF_PAX_MPROTECT;
59344+
59345+ pax_set_flags(task, flags);
59346+
59347+ return;
59348+}
59349+#endif
59350+
59351+#ifdef CONFIG_SYSCTL
59352+/* Eric Biederman likes breaking userland ABI and every inode-based security
59353+ system to save 35kb of memory */
59354+
59355+/* we modify the passed in filename, but adjust it back before returning */
59356+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
59357+{
59358+ struct name_entry *nmatch;
59359+ char *p, *lastp = NULL;
59360+ struct acl_object_label *obj = NULL, *tmp;
59361+ struct acl_subject_label *tmpsubj;
59362+ char c = '\0';
59363+
59364+ read_lock(&gr_inode_lock);
59365+
59366+ p = name + len - 1;
59367+ do {
59368+ nmatch = lookup_name_entry(name);
59369+ if (lastp != NULL)
59370+ *lastp = c;
59371+
59372+ if (nmatch == NULL)
59373+ goto next_component;
59374+ tmpsubj = current->acl;
59375+ do {
59376+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
59377+ if (obj != NULL) {
59378+ tmp = obj->globbed;
59379+ while (tmp) {
59380+ if (!glob_match(tmp->filename, name)) {
59381+ obj = tmp;
59382+ goto found_obj;
59383+ }
59384+ tmp = tmp->next;
59385+ }
59386+ goto found_obj;
59387+ }
59388+ } while ((tmpsubj = tmpsubj->parent_subject));
59389+next_component:
59390+ /* end case */
59391+ if (p == name)
59392+ break;
59393+
59394+ while (*p != '/')
59395+ p--;
59396+ if (p == name)
59397+ lastp = p + 1;
59398+ else {
59399+ lastp = p;
59400+ p--;
59401+ }
59402+ c = *lastp;
59403+ *lastp = '\0';
59404+ } while (1);
59405+found_obj:
59406+ read_unlock(&gr_inode_lock);
59407+ /* obj returned will always be non-null */
59408+ return obj;
59409+}
59410+
59411+/* returns 0 when allowing, non-zero on error
59412+ op of 0 is used for readdir, so we don't log the names of hidden files
59413+*/
59414+__u32
59415+gr_handle_sysctl(const struct ctl_table *table, const int op)
59416+{
59417+ ctl_table *tmp;
59418+ const char *proc_sys = "/proc/sys";
59419+ char *path;
59420+ struct acl_object_label *obj;
59421+ unsigned short len = 0, pos = 0, depth = 0, i;
59422+ __u32 err = 0;
59423+ __u32 mode = 0;
59424+
59425+ if (unlikely(!(gr_status & GR_READY)))
59426+ return 0;
59427+
59428+ /* for now, ignore operations on non-sysctl entries if it's not a
59429+ readdir*/
59430+ if (table->child != NULL && op != 0)
59431+ return 0;
59432+
59433+ mode |= GR_FIND;
59434+ /* it's only a read if it's an entry, read on dirs is for readdir */
59435+ if (op & MAY_READ)
59436+ mode |= GR_READ;
59437+ if (op & MAY_WRITE)
59438+ mode |= GR_WRITE;
59439+
59440+ preempt_disable();
59441+
59442+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
59443+
59444+ /* it's only a read/write if it's an actual entry, not a dir
59445+ (which are opened for readdir)
59446+ */
59447+
59448+ /* convert the requested sysctl entry into a pathname */
59449+
59450+ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
59451+ len += strlen(tmp->procname);
59452+ len++;
59453+ depth++;
59454+ }
59455+
59456+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
59457+ /* deny */
59458+ goto out;
59459+ }
59460+
59461+ memset(path, 0, PAGE_SIZE);
59462+
59463+ memcpy(path, proc_sys, strlen(proc_sys));
59464+
59465+ pos += strlen(proc_sys);
59466+
59467+ for (; depth > 0; depth--) {
59468+ path[pos] = '/';
59469+ pos++;
59470+ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
59471+ if (depth == i) {
59472+ memcpy(path + pos, tmp->procname,
59473+ strlen(tmp->procname));
59474+ pos += strlen(tmp->procname);
59475+ }
59476+ i++;
59477+ }
59478+ }
59479+
59480+ obj = gr_lookup_by_name(path, pos);
59481+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
59482+
59483+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
59484+ ((err & mode) != mode))) {
59485+ __u32 new_mode = mode;
59486+
59487+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59488+
59489+ err = 0;
59490+ gr_log_learn_sysctl(path, new_mode);
59491+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
59492+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
59493+ err = -ENOENT;
59494+ } else if (!(err & GR_FIND)) {
59495+ err = -ENOENT;
59496+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
59497+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
59498+ path, (mode & GR_READ) ? " reading" : "",
59499+ (mode & GR_WRITE) ? " writing" : "");
59500+ err = -EACCES;
59501+ } else if ((err & mode) != mode) {
59502+ err = -EACCES;
59503+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
59504+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
59505+ path, (mode & GR_READ) ? " reading" : "",
59506+ (mode & GR_WRITE) ? " writing" : "");
59507+ err = 0;
59508+ } else
59509+ err = 0;
59510+
59511+ out:
59512+ preempt_enable();
59513+
59514+ return err;
59515+}
59516+#endif
59517+
59518+int
59519+gr_handle_proc_ptrace(struct task_struct *task)
59520+{
59521+ struct file *filp;
59522+ struct task_struct *tmp = task;
59523+ struct task_struct *curtemp = current;
59524+ __u32 retmode;
59525+
59526+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
59527+ if (unlikely(!(gr_status & GR_READY)))
59528+ return 0;
59529+#endif
59530+
59531+ read_lock(&tasklist_lock);
59532+ read_lock(&grsec_exec_file_lock);
59533+ filp = task->exec_file;
59534+
59535+ while (tmp->pid > 0) {
59536+ if (tmp == curtemp)
59537+ break;
59538+ tmp = tmp->real_parent;
59539+ }
59540+
59541+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
59542+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
59543+ read_unlock(&grsec_exec_file_lock);
59544+ read_unlock(&tasklist_lock);
59545+ return 1;
59546+ }
59547+
59548+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59549+ if (!(gr_status & GR_READY)) {
59550+ read_unlock(&grsec_exec_file_lock);
59551+ read_unlock(&tasklist_lock);
59552+ return 0;
59553+ }
59554+#endif
59555+
59556+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
59557+ read_unlock(&grsec_exec_file_lock);
59558+ read_unlock(&tasklist_lock);
59559+
59560+ if (retmode & GR_NOPTRACE)
59561+ return 1;
59562+
59563+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
59564+ && (current->acl != task->acl || (current->acl != current->role->root_label
59565+ && current->pid != task->pid)))
59566+ return 1;
59567+
59568+ return 0;
59569+}
59570+
59571+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
59572+{
59573+ if (unlikely(!(gr_status & GR_READY)))
59574+ return;
59575+
59576+ if (!(current->role->roletype & GR_ROLE_GOD))
59577+ return;
59578+
59579+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
59580+ p->role->rolename, gr_task_roletype_to_char(p),
59581+ p->acl->filename);
59582+}
59583+
59584+int
59585+gr_handle_ptrace(struct task_struct *task, const long request)
59586+{
59587+ struct task_struct *tmp = task;
59588+ struct task_struct *curtemp = current;
59589+ __u32 retmode;
59590+
59591+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
59592+ if (unlikely(!(gr_status & GR_READY)))
59593+ return 0;
59594+#endif
59595+
59596+ read_lock(&tasklist_lock);
59597+ while (tmp->pid > 0) {
59598+ if (tmp == curtemp)
59599+ break;
59600+ tmp = tmp->real_parent;
59601+ }
59602+
59603+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
59604+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
59605+ read_unlock(&tasklist_lock);
59606+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59607+ return 1;
59608+ }
59609+ read_unlock(&tasklist_lock);
59610+
59611+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59612+ if (!(gr_status & GR_READY))
59613+ return 0;
59614+#endif
59615+
59616+ read_lock(&grsec_exec_file_lock);
59617+ if (unlikely(!task->exec_file)) {
59618+ read_unlock(&grsec_exec_file_lock);
59619+ return 0;
59620+ }
59621+
59622+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
59623+ read_unlock(&grsec_exec_file_lock);
59624+
59625+ if (retmode & GR_NOPTRACE) {
59626+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59627+ return 1;
59628+ }
59629+
59630+ if (retmode & GR_PTRACERD) {
59631+ switch (request) {
59632+ case PTRACE_POKETEXT:
59633+ case PTRACE_POKEDATA:
59634+ case PTRACE_POKEUSR:
59635+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
59636+ case PTRACE_SETREGS:
59637+ case PTRACE_SETFPREGS:
59638+#endif
59639+#ifdef CONFIG_X86
59640+ case PTRACE_SETFPXREGS:
59641+#endif
59642+#ifdef CONFIG_ALTIVEC
59643+ case PTRACE_SETVRREGS:
59644+#endif
59645+ return 1;
59646+ default:
59647+ return 0;
59648+ }
59649+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
59650+ !(current->role->roletype & GR_ROLE_GOD) &&
59651+ (current->acl != task->acl)) {
59652+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59653+ return 1;
59654+ }
59655+
59656+ return 0;
59657+}
59658+
59659+static int is_writable_mmap(const struct file *filp)
59660+{
59661+ struct task_struct *task = current;
59662+ struct acl_object_label *obj, *obj2;
59663+
59664+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
59665+ !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))) {
59666+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59667+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
59668+ task->role->root_label);
59669+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
59670+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
59671+ return 1;
59672+ }
59673+ }
59674+ return 0;
59675+}
59676+
59677+int
59678+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
59679+{
59680+ __u32 mode;
59681+
59682+ if (unlikely(!file || !(prot & PROT_EXEC)))
59683+ return 1;
59684+
59685+ if (is_writable_mmap(file))
59686+ return 0;
59687+
59688+ mode =
59689+ gr_search_file(file->f_path.dentry,
59690+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
59691+ file->f_path.mnt);
59692+
59693+ if (!gr_tpe_allow(file))
59694+ return 0;
59695+
59696+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
59697+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59698+ return 0;
59699+ } else if (unlikely(!(mode & GR_EXEC))) {
59700+ return 0;
59701+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
59702+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59703+ return 1;
59704+ }
59705+
59706+ return 1;
59707+}
59708+
59709+int
59710+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
59711+{
59712+ __u32 mode;
59713+
59714+ if (unlikely(!file || !(prot & PROT_EXEC)))
59715+ return 1;
59716+
59717+ if (is_writable_mmap(file))
59718+ return 0;
59719+
59720+ mode =
59721+ gr_search_file(file->f_path.dentry,
59722+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
59723+ file->f_path.mnt);
59724+
59725+ if (!gr_tpe_allow(file))
59726+ return 0;
59727+
59728+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
59729+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59730+ return 0;
59731+ } else if (unlikely(!(mode & GR_EXEC))) {
59732+ return 0;
59733+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
59734+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59735+ return 1;
59736+ }
59737+
59738+ return 1;
59739+}
59740+
59741+void
59742+gr_acl_handle_psacct(struct task_struct *task, const long code)
59743+{
59744+ unsigned long runtime;
59745+ unsigned long cputime;
59746+ unsigned int wday, cday;
59747+ __u8 whr, chr;
59748+ __u8 wmin, cmin;
59749+ __u8 wsec, csec;
59750+ struct timespec timeval;
59751+
59752+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
59753+ !(task->acl->mode & GR_PROCACCT)))
59754+ return;
59755+
59756+ do_posix_clock_monotonic_gettime(&timeval);
59757+ runtime = timeval.tv_sec - task->start_time.tv_sec;
59758+ wday = runtime / (3600 * 24);
59759+ runtime -= wday * (3600 * 24);
59760+ whr = runtime / 3600;
59761+ runtime -= whr * 3600;
59762+ wmin = runtime / 60;
59763+ runtime -= wmin * 60;
59764+ wsec = runtime;
59765+
59766+ cputime = (task->utime + task->stime) / HZ;
59767+ cday = cputime / (3600 * 24);
59768+ cputime -= cday * (3600 * 24);
59769+ chr = cputime / 3600;
59770+ cputime -= chr * 3600;
59771+ cmin = cputime / 60;
59772+ cputime -= cmin * 60;
59773+ csec = cputime;
59774+
59775+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
59776+
59777+ return;
59778+}
59779+
59780+void gr_set_kernel_label(struct task_struct *task)
59781+{
59782+ if (gr_status & GR_READY) {
59783+ task->role = kernel_role;
59784+ task->acl = kernel_role->root_label;
59785+ }
59786+ return;
59787+}
59788+
59789+#ifdef CONFIG_TASKSTATS
59790+int gr_is_taskstats_denied(int pid)
59791+{
59792+ struct task_struct *task;
59793+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59794+ const struct cred *cred;
59795+#endif
59796+ int ret = 0;
59797+
59798+ /* restrict taskstats viewing to un-chrooted root users
59799+ who have the 'view' subject flag if the RBAC system is enabled
59800+ */
59801+
59802+ rcu_read_lock();
59803+ read_lock(&tasklist_lock);
59804+ task = find_task_by_vpid(pid);
59805+ if (task) {
59806+#ifdef CONFIG_GRKERNSEC_CHROOT
59807+ if (proc_is_chrooted(task))
59808+ ret = -EACCES;
59809+#endif
59810+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59811+ cred = __task_cred(task);
59812+#ifdef CONFIG_GRKERNSEC_PROC_USER
59813+ if (cred->uid != 0)
59814+ ret = -EACCES;
59815+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59816+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
59817+ ret = -EACCES;
59818+#endif
59819+#endif
59820+ if (gr_status & GR_READY) {
59821+ if (!(task->acl->mode & GR_VIEW))
59822+ ret = -EACCES;
59823+ }
59824+ } else
59825+ ret = -ENOENT;
59826+
59827+ read_unlock(&tasklist_lock);
59828+ rcu_read_unlock();
59829+
59830+ return ret;
59831+}
59832+#endif
59833+
59834+/* AUXV entries are filled via a descendant of search_binary_handler
59835+ after we've already applied the subject for the target
59836+*/
59837+int gr_acl_enable_at_secure(void)
59838+{
59839+ if (unlikely(!(gr_status & GR_READY)))
59840+ return 0;
59841+
59842+ if (current->acl->mode & GR_ATSECURE)
59843+ return 1;
59844+
59845+ return 0;
59846+}
59847+
59848+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
59849+{
59850+ struct task_struct *task = current;
59851+ struct dentry *dentry = file->f_path.dentry;
59852+ struct vfsmount *mnt = file->f_path.mnt;
59853+ struct acl_object_label *obj, *tmp;
59854+ struct acl_subject_label *subj;
59855+ unsigned int bufsize;
59856+ int is_not_root;
59857+ char *path;
59858+ dev_t dev = __get_dev(dentry);
59859+
59860+ if (unlikely(!(gr_status & GR_READY)))
59861+ return 1;
59862+
59863+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59864+ return 1;
59865+
59866+ /* ignore Eric Biederman */
59867+ if (IS_PRIVATE(dentry->d_inode))
59868+ return 1;
59869+
59870+ subj = task->acl;
59871+ do {
59872+ obj = lookup_acl_obj_label(ino, dev, subj);
59873+ if (obj != NULL)
59874+ return (obj->mode & GR_FIND) ? 1 : 0;
59875+ } while ((subj = subj->parent_subject));
59876+
59877+ /* this is purely an optimization since we're looking for an object
59878+ for the directory we're doing a readdir on
59879+ if it's possible for any globbed object to match the entry we're
59880+ filling into the directory, then the object we find here will be
59881+ an anchor point with attached globbed objects
59882+ */
59883+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
59884+ if (obj->globbed == NULL)
59885+ return (obj->mode & GR_FIND) ? 1 : 0;
59886+
59887+ is_not_root = ((obj->filename[0] == '/') &&
59888+ (obj->filename[1] == '\0')) ? 0 : 1;
59889+ bufsize = PAGE_SIZE - namelen - is_not_root;
59890+
59891+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
59892+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
59893+ return 1;
59894+
59895+ preempt_disable();
59896+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
59897+ bufsize);
59898+
59899+ bufsize = strlen(path);
59900+
59901+ /* if base is "/", don't append an additional slash */
59902+ if (is_not_root)
59903+ *(path + bufsize) = '/';
59904+ memcpy(path + bufsize + is_not_root, name, namelen);
59905+ *(path + bufsize + namelen + is_not_root) = '\0';
59906+
59907+ tmp = obj->globbed;
59908+ while (tmp) {
59909+ if (!glob_match(tmp->filename, path)) {
59910+ preempt_enable();
59911+ return (tmp->mode & GR_FIND) ? 1 : 0;
59912+ }
59913+ tmp = tmp->next;
59914+ }
59915+ preempt_enable();
59916+ return (obj->mode & GR_FIND) ? 1 : 0;
59917+}
59918+
59919+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
59920+EXPORT_SYMBOL(gr_acl_is_enabled);
59921+#endif
59922+EXPORT_SYMBOL(gr_learn_resource);
59923+EXPORT_SYMBOL(gr_set_kernel_label);
59924+#ifdef CONFIG_SECURITY
59925+EXPORT_SYMBOL(gr_check_user_change);
59926+EXPORT_SYMBOL(gr_check_group_change);
59927+#endif
59928+
59929diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
59930new file mode 100644
59931index 0000000..34fefda
59932--- /dev/null
59933+++ b/grsecurity/gracl_alloc.c
59934@@ -0,0 +1,105 @@
59935+#include <linux/kernel.h>
59936+#include <linux/mm.h>
59937+#include <linux/slab.h>
59938+#include <linux/vmalloc.h>
59939+#include <linux/gracl.h>
59940+#include <linux/grsecurity.h>
59941+
59942+static unsigned long alloc_stack_next = 1;
59943+static unsigned long alloc_stack_size = 1;
59944+static void **alloc_stack;
59945+
59946+static __inline__ int
59947+alloc_pop(void)
59948+{
59949+ if (alloc_stack_next == 1)
59950+ return 0;
59951+
59952+ kfree(alloc_stack[alloc_stack_next - 2]);
59953+
59954+ alloc_stack_next--;
59955+
59956+ return 1;
59957+}
59958+
59959+static __inline__ int
59960+alloc_push(void *buf)
59961+{
59962+ if (alloc_stack_next >= alloc_stack_size)
59963+ return 1;
59964+
59965+ alloc_stack[alloc_stack_next - 1] = buf;
59966+
59967+ alloc_stack_next++;
59968+
59969+ return 0;
59970+}
59971+
59972+void *
59973+acl_alloc(unsigned long len)
59974+{
59975+ void *ret = NULL;
59976+
59977+ if (!len || len > PAGE_SIZE)
59978+ goto out;
59979+
59980+ ret = kmalloc(len, GFP_KERNEL);
59981+
59982+ if (ret) {
59983+ if (alloc_push(ret)) {
59984+ kfree(ret);
59985+ ret = NULL;
59986+ }
59987+ }
59988+
59989+out:
59990+ return ret;
59991+}
59992+
59993+void *
59994+acl_alloc_num(unsigned long num, unsigned long len)
59995+{
59996+ if (!len || (num > (PAGE_SIZE / len)))
59997+ return NULL;
59998+
59999+ return acl_alloc(num * len);
60000+}
60001+
60002+void
60003+acl_free_all(void)
60004+{
60005+ if (gr_acl_is_enabled() || !alloc_stack)
60006+ return;
60007+
60008+ while (alloc_pop()) ;
60009+
60010+ if (alloc_stack) {
60011+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
60012+ kfree(alloc_stack);
60013+ else
60014+ vfree(alloc_stack);
60015+ }
60016+
60017+ alloc_stack = NULL;
60018+ alloc_stack_size = 1;
60019+ alloc_stack_next = 1;
60020+
60021+ return;
60022+}
60023+
60024+int
60025+acl_alloc_stack_init(unsigned long size)
60026+{
60027+ if ((size * sizeof (void *)) <= PAGE_SIZE)
60028+ alloc_stack =
60029+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
60030+ else
60031+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
60032+
60033+ alloc_stack_size = size;
60034+
60035+ if (!alloc_stack)
60036+ return 0;
60037+ else
60038+ return 1;
60039+}
60040diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
60041new file mode 100644
60042index 0000000..955ddfb
60043--- /dev/null
60044+++ b/grsecurity/gracl_cap.c
60045@@ -0,0 +1,101 @@
60046+#include <linux/kernel.h>
60047+#include <linux/module.h>
60048+#include <linux/sched.h>
60049+#include <linux/gracl.h>
60050+#include <linux/grsecurity.h>
60051+#include <linux/grinternal.h>
60052+
60053+extern const char *captab_log[];
60054+extern int captab_log_entries;
60055+
60056+int
60057+gr_acl_is_capable(const int cap)
60058+{
60059+ struct task_struct *task = current;
60060+ const struct cred *cred = current_cred();
60061+ struct acl_subject_label *curracl;
60062+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
60063+ kernel_cap_t cap_audit = __cap_empty_set;
60064+
60065+ if (!gr_acl_is_enabled())
60066+ return 1;
60067+
60068+ curracl = task->acl;
60069+
60070+ cap_drop = curracl->cap_lower;
60071+ cap_mask = curracl->cap_mask;
60072+ cap_audit = curracl->cap_invert_audit;
60073+
60074+ while ((curracl = curracl->parent_subject)) {
60075+ /* if the cap isn't specified in the current computed mask but is specified in the
60076+ current level subject, and is lowered in the current level subject, then add
60077+ it to the set of dropped capabilities
60078+ otherwise, add the current level subject's mask to the current computed mask
60079+ */
60080+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
60081+ cap_raise(cap_mask, cap);
60082+ if (cap_raised(curracl->cap_lower, cap))
60083+ cap_raise(cap_drop, cap);
60084+ if (cap_raised(curracl->cap_invert_audit, cap))
60085+ cap_raise(cap_audit, cap);
60086+ }
60087+ }
60088+
60089+ if (!cap_raised(cap_drop, cap)) {
60090+ if (cap_raised(cap_audit, cap))
60091+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
60092+ return 1;
60093+ }
60094+
60095+ curracl = task->acl;
60096+
60097+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
60098+ && cap_raised(cred->cap_effective, cap)) {
60099+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60100+ task->role->roletype, cred->uid,
60101+ cred->gid, task->exec_file ?
60102+ gr_to_filename(task->exec_file->f_path.dentry,
60103+ task->exec_file->f_path.mnt) : curracl->filename,
60104+ curracl->filename, 0UL,
60105+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
60106+ return 1;
60107+ }
60108+
60109+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
60110+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
60111+ return 0;
60112+}
60113+
60114+int
60115+gr_acl_is_capable_nolog(const int cap)
60116+{
60117+ struct acl_subject_label *curracl;
60118+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
60119+
60120+ if (!gr_acl_is_enabled())
60121+ return 1;
60122+
60123+ curracl = current->acl;
60124+
60125+ cap_drop = curracl->cap_lower;
60126+ cap_mask = curracl->cap_mask;
60127+
60128+ while ((curracl = curracl->parent_subject)) {
60129+ /* if the cap isn't specified in the current computed mask but is specified in the
60130+ current level subject, and is lowered in the current level subject, then add
60131+ it to the set of dropped capabilities
60132+ otherwise, add the current level subject's mask to the current computed mask
60133+ */
60134+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
60135+ cap_raise(cap_mask, cap);
60136+ if (cap_raised(curracl->cap_lower, cap))
60137+ cap_raise(cap_drop, cap);
60138+ }
60139+ }
60140+
60141+ if (!cap_raised(cap_drop, cap))
60142+ return 1;
60143+
60144+ return 0;
60145+}
60146+
60147diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
60148new file mode 100644
60149index 0000000..d5f210c
60150--- /dev/null
60151+++ b/grsecurity/gracl_fs.c
60152@@ -0,0 +1,433 @@
60153+#include <linux/kernel.h>
60154+#include <linux/sched.h>
60155+#include <linux/types.h>
60156+#include <linux/fs.h>
60157+#include <linux/file.h>
60158+#include <linux/stat.h>
60159+#include <linux/grsecurity.h>
60160+#include <linux/grinternal.h>
60161+#include <linux/gracl.h>
60162+
60163+__u32
60164+gr_acl_handle_hidden_file(const struct dentry * dentry,
60165+ const struct vfsmount * mnt)
60166+{
60167+ __u32 mode;
60168+
60169+ if (unlikely(!dentry->d_inode))
60170+ return GR_FIND;
60171+
60172+ mode =
60173+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
60174+
60175+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
60176+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
60177+ return mode;
60178+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
60179+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
60180+ return 0;
60181+ } else if (unlikely(!(mode & GR_FIND)))
60182+ return 0;
60183+
60184+ return GR_FIND;
60185+}
60186+
60187+__u32
60188+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
60189+ int acc_mode)
60190+{
60191+ __u32 reqmode = GR_FIND;
60192+ __u32 mode;
60193+
60194+ if (unlikely(!dentry->d_inode))
60195+ return reqmode;
60196+
60197+ if (acc_mode & MAY_APPEND)
60198+ reqmode |= GR_APPEND;
60199+ else if (acc_mode & MAY_WRITE)
60200+ reqmode |= GR_WRITE;
60201+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
60202+ reqmode |= GR_READ;
60203+
60204+ mode =
60205+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
60206+ mnt);
60207+
60208+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
60209+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
60210+ reqmode & GR_READ ? " reading" : "",
60211+ reqmode & GR_WRITE ? " writing" : reqmode &
60212+ GR_APPEND ? " appending" : "");
60213+ return reqmode;
60214+ } else
60215+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
60216+ {
60217+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
60218+ reqmode & GR_READ ? " reading" : "",
60219+ reqmode & GR_WRITE ? " writing" : reqmode &
60220+ GR_APPEND ? " appending" : "");
60221+ return 0;
60222+ } else if (unlikely((mode & reqmode) != reqmode))
60223+ return 0;
60224+
60225+ return reqmode;
60226+}
60227+
60228+__u32
60229+gr_acl_handle_creat(const struct dentry * dentry,
60230+ const struct dentry * p_dentry,
60231+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60232+ const int imode)
60233+{
60234+ __u32 reqmode = GR_WRITE | GR_CREATE;
60235+ __u32 mode;
60236+
60237+ if (acc_mode & MAY_APPEND)
60238+ reqmode |= GR_APPEND;
60239+ // if a directory was required or the directory already exists, then
60240+ // don't count this open as a read
60241+ if ((acc_mode & MAY_READ) &&
60242+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
60243+ reqmode |= GR_READ;
60244+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
60245+ reqmode |= GR_SETID;
60246+
60247+ mode =
60248+ gr_check_create(dentry, p_dentry, p_mnt,
60249+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
60250+
60251+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
60252+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
60253+ reqmode & GR_READ ? " reading" : "",
60254+ reqmode & GR_WRITE ? " writing" : reqmode &
60255+ GR_APPEND ? " appending" : "");
60256+ return reqmode;
60257+ } else
60258+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
60259+ {
60260+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
60261+ reqmode & GR_READ ? " reading" : "",
60262+ reqmode & GR_WRITE ? " writing" : reqmode &
60263+ GR_APPEND ? " appending" : "");
60264+ return 0;
60265+ } else if (unlikely((mode & reqmode) != reqmode))
60266+ return 0;
60267+
60268+ return reqmode;
60269+}
60270+
60271+__u32
60272+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
60273+ const int fmode)
60274+{
60275+ __u32 mode, reqmode = GR_FIND;
60276+
60277+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
60278+ reqmode |= GR_EXEC;
60279+ if (fmode & S_IWOTH)
60280+ reqmode |= GR_WRITE;
60281+ if (fmode & S_IROTH)
60282+ reqmode |= GR_READ;
60283+
60284+ mode =
60285+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
60286+ mnt);
60287+
60288+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
60289+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
60290+ reqmode & GR_READ ? " reading" : "",
60291+ reqmode & GR_WRITE ? " writing" : "",
60292+ reqmode & GR_EXEC ? " executing" : "");
60293+ return reqmode;
60294+ } else
60295+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
60296+ {
60297+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
60298+ reqmode & GR_READ ? " reading" : "",
60299+ reqmode & GR_WRITE ? " writing" : "",
60300+ reqmode & GR_EXEC ? " executing" : "");
60301+ return 0;
60302+ } else if (unlikely((mode & reqmode) != reqmode))
60303+ return 0;
60304+
60305+ return reqmode;
60306+}
60307+
60308+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
60309+{
60310+ __u32 mode;
60311+
60312+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
60313+
60314+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
60315+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
60316+ return mode;
60317+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
60318+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
60319+ return 0;
60320+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
60321+ return 0;
60322+
60323+ return (reqmode);
60324+}
60325+
60326+__u32
60327+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
60328+{
60329+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
60330+}
60331+
60332+__u32
60333+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
60334+{
60335+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
60336+}
60337+
60338+__u32
60339+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
60340+{
60341+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
60342+}
60343+
60344+__u32
60345+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
60346+{
60347+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
60348+}
60349+
60350+__u32
60351+gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
60352+ mode_t mode)
60353+{
60354+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
60355+ return 1;
60356+
60357+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
60358+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
60359+ GR_FCHMOD_ACL_MSG);
60360+ } else {
60361+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
60362+ }
60363+}
60364+
60365+__u32
60366+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
60367+ mode_t mode)
60368+{
60369+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
60370+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
60371+ GR_CHMOD_ACL_MSG);
60372+ } else {
60373+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
60374+ }
60375+}
60376+
60377+__u32
60378+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
60379+{
60380+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
60381+}
60382+
60383+__u32
60384+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
60385+{
60386+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
60387+}
60388+
60389+__u32
60390+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
60391+{
60392+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
60393+}
60394+
60395+__u32
60396+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
60397+{
60398+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
60399+ GR_UNIXCONNECT_ACL_MSG);
60400+}
60401+
60402+/* hardlinks require at minimum create and link permission,
60403+ any additional privilege required is based on the
60404+ privilege of the file being linked to
60405+*/
60406+__u32
60407+gr_acl_handle_link(const struct dentry * new_dentry,
60408+ const struct dentry * parent_dentry,
60409+ const struct vfsmount * parent_mnt,
60410+ const struct dentry * old_dentry,
60411+ const struct vfsmount * old_mnt, const char *to)
60412+{
60413+ __u32 mode;
60414+ __u32 needmode = GR_CREATE | GR_LINK;
60415+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
60416+
60417+ mode =
60418+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
60419+ old_mnt);
60420+
60421+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
60422+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
60423+ return mode;
60424+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
60425+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
60426+ return 0;
60427+ } else if (unlikely((mode & needmode) != needmode))
60428+ return 0;
60429+
60430+ return 1;
60431+}
60432+
60433+__u32
60434+gr_acl_handle_symlink(const struct dentry * new_dentry,
60435+ const struct dentry * parent_dentry,
60436+ const struct vfsmount * parent_mnt, const char *from)
60437+{
60438+ __u32 needmode = GR_WRITE | GR_CREATE;
60439+ __u32 mode;
60440+
60441+ mode =
60442+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
60443+ GR_CREATE | GR_AUDIT_CREATE |
60444+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
60445+
60446+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
60447+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
60448+ return mode;
60449+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
60450+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
60451+ return 0;
60452+ } else if (unlikely((mode & needmode) != needmode))
60453+ return 0;
60454+
60455+ return (GR_WRITE | GR_CREATE);
60456+}
60457+
60458+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)
60459+{
60460+ __u32 mode;
60461+
60462+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
60463+
60464+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
60465+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
60466+ return mode;
60467+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
60468+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
60469+ return 0;
60470+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
60471+ return 0;
60472+
60473+ return (reqmode);
60474+}
60475+
60476+__u32
60477+gr_acl_handle_mknod(const struct dentry * new_dentry,
60478+ const struct dentry * parent_dentry,
60479+ const struct vfsmount * parent_mnt,
60480+ const int mode)
60481+{
60482+ __u32 reqmode = GR_WRITE | GR_CREATE;
60483+ if (unlikely(mode & (S_ISUID | S_ISGID)))
60484+ reqmode |= GR_SETID;
60485+
60486+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
60487+ reqmode, GR_MKNOD_ACL_MSG);
60488+}
60489+
60490+__u32
60491+gr_acl_handle_mkdir(const struct dentry *new_dentry,
60492+ const struct dentry *parent_dentry,
60493+ const struct vfsmount *parent_mnt)
60494+{
60495+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
60496+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
60497+}
60498+
60499+#define RENAME_CHECK_SUCCESS(old, new) \
60500+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
60501+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
60502+
60503+int
60504+gr_acl_handle_rename(struct dentry *new_dentry,
60505+ struct dentry *parent_dentry,
60506+ const struct vfsmount *parent_mnt,
60507+ struct dentry *old_dentry,
60508+ struct inode *old_parent_inode,
60509+ struct vfsmount *old_mnt, const char *newname)
60510+{
60511+ __u32 comp1, comp2;
60512+ int error = 0;
60513+
60514+ if (unlikely(!gr_acl_is_enabled()))
60515+ return 0;
60516+
60517+ if (!new_dentry->d_inode) {
60518+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
60519+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
60520+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
60521+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
60522+ GR_DELETE | GR_AUDIT_DELETE |
60523+ GR_AUDIT_READ | GR_AUDIT_WRITE |
60524+ GR_SUPPRESS, old_mnt);
60525+ } else {
60526+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
60527+ GR_CREATE | GR_DELETE |
60528+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
60529+ GR_AUDIT_READ | GR_AUDIT_WRITE |
60530+ GR_SUPPRESS, parent_mnt);
60531+ comp2 =
60532+ gr_search_file(old_dentry,
60533+ GR_READ | GR_WRITE | GR_AUDIT_READ |
60534+ GR_DELETE | GR_AUDIT_DELETE |
60535+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
60536+ }
60537+
60538+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
60539+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
60540+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
60541+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
60542+ && !(comp2 & GR_SUPPRESS)) {
60543+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
60544+ error = -EACCES;
60545+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
60546+ error = -EACCES;
60547+
60548+ return error;
60549+}
60550+
60551+void
60552+gr_acl_handle_exit(void)
60553+{
60554+ u16 id;
60555+ char *rolename;
60556+ struct file *exec_file;
60557+
60558+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
60559+ !(current->role->roletype & GR_ROLE_PERSIST))) {
60560+ id = current->acl_role_id;
60561+ rolename = current->role->rolename;
60562+ gr_set_acls(1);
60563+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
60564+ }
60565+
60566+ write_lock(&grsec_exec_file_lock);
60567+ exec_file = current->exec_file;
60568+ current->exec_file = NULL;
60569+ write_unlock(&grsec_exec_file_lock);
60570+
60571+ if (exec_file)
60572+ fput(exec_file);
60573+}
60574+
60575+int
60576+gr_acl_handle_procpidmem(const struct task_struct *task)
60577+{
60578+ if (unlikely(!gr_acl_is_enabled()))
60579+ return 0;
60580+
60581+ if (task != current && task->acl->mode & GR_PROTPROCFD)
60582+ return -EACCES;
60583+
60584+ return 0;
60585+}
60586diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
60587new file mode 100644
60588index 0000000..cd07b96
60589--- /dev/null
60590+++ b/grsecurity/gracl_ip.c
60591@@ -0,0 +1,382 @@
60592+#include <linux/kernel.h>
60593+#include <asm/uaccess.h>
60594+#include <asm/errno.h>
60595+#include <net/sock.h>
60596+#include <linux/file.h>
60597+#include <linux/fs.h>
60598+#include <linux/net.h>
60599+#include <linux/in.h>
60600+#include <linux/skbuff.h>
60601+#include <linux/ip.h>
60602+#include <linux/udp.h>
60603+#include <linux/smp_lock.h>
60604+#include <linux/types.h>
60605+#include <linux/sched.h>
60606+#include <linux/netdevice.h>
60607+#include <linux/inetdevice.h>
60608+#include <linux/gracl.h>
60609+#include <linux/grsecurity.h>
60610+#include <linux/grinternal.h>
60611+
60612+#define GR_BIND 0x01
60613+#define GR_CONNECT 0x02
60614+#define GR_INVERT 0x04
60615+#define GR_BINDOVERRIDE 0x08
60616+#define GR_CONNECTOVERRIDE 0x10
60617+#define GR_SOCK_FAMILY 0x20
60618+
60619+static const char * gr_protocols[IPPROTO_MAX] = {
60620+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
60621+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
60622+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
60623+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
60624+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
60625+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
60626+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
60627+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
60628+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
60629+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
60630+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
60631+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
60632+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
60633+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
60634+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
60635+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
60636+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
60637+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
60638+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
60639+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
60640+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
60641+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
60642+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
60643+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
60644+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
60645+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
60646+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
60647+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
60648+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
60649+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
60650+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
60651+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
60652+ };
60653+
60654+static const char * gr_socktypes[SOCK_MAX] = {
60655+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
60656+ "unknown:7", "unknown:8", "unknown:9", "packet"
60657+ };
60658+
60659+static const char * gr_sockfamilies[AF_MAX+1] = {
60660+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
60661+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
60662+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
60663+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154"
60664+ };
60665+
60666+const char *
60667+gr_proto_to_name(unsigned char proto)
60668+{
60669+ return gr_protocols[proto];
60670+}
60671+
60672+const char *
60673+gr_socktype_to_name(unsigned char type)
60674+{
60675+ return gr_socktypes[type];
60676+}
60677+
60678+const char *
60679+gr_sockfamily_to_name(unsigned char family)
60680+{
60681+ return gr_sockfamilies[family];
60682+}
60683+
60684+int
60685+gr_search_socket(const int domain, const int type, const int protocol)
60686+{
60687+ struct acl_subject_label *curr;
60688+ const struct cred *cred = current_cred();
60689+
60690+ if (unlikely(!gr_acl_is_enabled()))
60691+ goto exit;
60692+
60693+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
60694+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
60695+ goto exit; // let the kernel handle it
60696+
60697+ curr = current->acl;
60698+
60699+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
60700+ /* the family is allowed, if this is PF_INET allow it only if
60701+ the extra sock type/protocol checks pass */
60702+ if (domain == PF_INET)
60703+ goto inet_check;
60704+ goto exit;
60705+ } else {
60706+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60707+ __u32 fakeip = 0;
60708+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60709+ current->role->roletype, cred->uid,
60710+ cred->gid, current->exec_file ?
60711+ gr_to_filename(current->exec_file->f_path.dentry,
60712+ current->exec_file->f_path.mnt) :
60713+ curr->filename, curr->filename,
60714+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
60715+ &current->signal->saved_ip);
60716+ goto exit;
60717+ }
60718+ goto exit_fail;
60719+ }
60720+
60721+inet_check:
60722+ /* the rest of this checking is for IPv4 only */
60723+ if (!curr->ips)
60724+ goto exit;
60725+
60726+ if ((curr->ip_type & (1 << type)) &&
60727+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
60728+ goto exit;
60729+
60730+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60731+ /* we don't place acls on raw sockets , and sometimes
60732+ dgram/ip sockets are opened for ioctl and not
60733+ bind/connect, so we'll fake a bind learn log */
60734+ if (type == SOCK_RAW || type == SOCK_PACKET) {
60735+ __u32 fakeip = 0;
60736+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60737+ current->role->roletype, cred->uid,
60738+ cred->gid, current->exec_file ?
60739+ gr_to_filename(current->exec_file->f_path.dentry,
60740+ current->exec_file->f_path.mnt) :
60741+ curr->filename, curr->filename,
60742+ &fakeip, 0, type,
60743+ protocol, GR_CONNECT, &current->signal->saved_ip);
60744+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
60745+ __u32 fakeip = 0;
60746+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60747+ current->role->roletype, cred->uid,
60748+ cred->gid, current->exec_file ?
60749+ gr_to_filename(current->exec_file->f_path.dentry,
60750+ current->exec_file->f_path.mnt) :
60751+ curr->filename, curr->filename,
60752+ &fakeip, 0, type,
60753+ protocol, GR_BIND, &current->signal->saved_ip);
60754+ }
60755+ /* we'll log when they use connect or bind */
60756+ goto exit;
60757+ }
60758+
60759+exit_fail:
60760+ if (domain == PF_INET)
60761+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
60762+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
60763+ else
60764+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
60765+ gr_socktype_to_name(type), protocol);
60766+
60767+ return 0;
60768+exit:
60769+ return 1;
60770+}
60771+
60772+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)
60773+{
60774+ if ((ip->mode & mode) &&
60775+ (ip_port >= ip->low) &&
60776+ (ip_port <= ip->high) &&
60777+ ((ntohl(ip_addr) & our_netmask) ==
60778+ (ntohl(our_addr) & our_netmask))
60779+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
60780+ && (ip->type & (1 << type))) {
60781+ if (ip->mode & GR_INVERT)
60782+ return 2; // specifically denied
60783+ else
60784+ return 1; // allowed
60785+ }
60786+
60787+ return 0; // not specifically allowed, may continue parsing
60788+}
60789+
60790+static int
60791+gr_search_connectbind(const int full_mode, struct sock *sk,
60792+ struct sockaddr_in *addr, const int type)
60793+{
60794+ char iface[IFNAMSIZ] = {0};
60795+ struct acl_subject_label *curr;
60796+ struct acl_ip_label *ip;
60797+ struct inet_sock *isk;
60798+ struct net_device *dev;
60799+ struct in_device *idev;
60800+ unsigned long i;
60801+ int ret;
60802+ int mode = full_mode & (GR_BIND | GR_CONNECT);
60803+ __u32 ip_addr = 0;
60804+ __u32 our_addr;
60805+ __u32 our_netmask;
60806+ char *p;
60807+ __u16 ip_port = 0;
60808+ const struct cred *cred = current_cred();
60809+
60810+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
60811+ return 0;
60812+
60813+ curr = current->acl;
60814+ isk = inet_sk(sk);
60815+
60816+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
60817+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
60818+ addr->sin_addr.s_addr = curr->inaddr_any_override;
60819+ if ((full_mode & GR_CONNECT) && isk->saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
60820+ struct sockaddr_in saddr;
60821+ int err;
60822+
60823+ saddr.sin_family = AF_INET;
60824+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
60825+ saddr.sin_port = isk->sport;
60826+
60827+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
60828+ if (err)
60829+ return err;
60830+
60831+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
60832+ if (err)
60833+ return err;
60834+ }
60835+
60836+ if (!curr->ips)
60837+ return 0;
60838+
60839+ ip_addr = addr->sin_addr.s_addr;
60840+ ip_port = ntohs(addr->sin_port);
60841+
60842+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60843+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60844+ current->role->roletype, cred->uid,
60845+ cred->gid, current->exec_file ?
60846+ gr_to_filename(current->exec_file->f_path.dentry,
60847+ current->exec_file->f_path.mnt) :
60848+ curr->filename, curr->filename,
60849+ &ip_addr, ip_port, type,
60850+ sk->sk_protocol, mode, &current->signal->saved_ip);
60851+ return 0;
60852+ }
60853+
60854+ for (i = 0; i < curr->ip_num; i++) {
60855+ ip = *(curr->ips + i);
60856+ if (ip->iface != NULL) {
60857+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
60858+ p = strchr(iface, ':');
60859+ if (p != NULL)
60860+ *p = '\0';
60861+ dev = dev_get_by_name(sock_net(sk), iface);
60862+ if (dev == NULL)
60863+ continue;
60864+ idev = in_dev_get(dev);
60865+ if (idev == NULL) {
60866+ dev_put(dev);
60867+ continue;
60868+ }
60869+ rcu_read_lock();
60870+ for_ifa(idev) {
60871+ if (!strcmp(ip->iface, ifa->ifa_label)) {
60872+ our_addr = ifa->ifa_address;
60873+ our_netmask = 0xffffffff;
60874+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
60875+ if (ret == 1) {
60876+ rcu_read_unlock();
60877+ in_dev_put(idev);
60878+ dev_put(dev);
60879+ return 0;
60880+ } else if (ret == 2) {
60881+ rcu_read_unlock();
60882+ in_dev_put(idev);
60883+ dev_put(dev);
60884+ goto denied;
60885+ }
60886+ }
60887+ } endfor_ifa(idev);
60888+ rcu_read_unlock();
60889+ in_dev_put(idev);
60890+ dev_put(dev);
60891+ } else {
60892+ our_addr = ip->addr;
60893+ our_netmask = ip->netmask;
60894+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
60895+ if (ret == 1)
60896+ return 0;
60897+ else if (ret == 2)
60898+ goto denied;
60899+ }
60900+ }
60901+
60902+denied:
60903+ if (mode == GR_BIND)
60904+ 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));
60905+ else if (mode == GR_CONNECT)
60906+ 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));
60907+
60908+ return -EACCES;
60909+}
60910+
60911+int
60912+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
60913+{
60914+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
60915+}
60916+
60917+int
60918+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
60919+{
60920+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
60921+}
60922+
60923+int gr_search_listen(struct socket *sock)
60924+{
60925+ struct sock *sk = sock->sk;
60926+ struct sockaddr_in addr;
60927+
60928+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
60929+ addr.sin_port = inet_sk(sk)->sport;
60930+
60931+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
60932+}
60933+
60934+int gr_search_accept(struct socket *sock)
60935+{
60936+ struct sock *sk = sock->sk;
60937+ struct sockaddr_in addr;
60938+
60939+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
60940+ addr.sin_port = inet_sk(sk)->sport;
60941+
60942+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
60943+}
60944+
60945+int
60946+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
60947+{
60948+ if (addr)
60949+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
60950+ else {
60951+ struct sockaddr_in sin;
60952+ const struct inet_sock *inet = inet_sk(sk);
60953+
60954+ sin.sin_addr.s_addr = inet->daddr;
60955+ sin.sin_port = inet->dport;
60956+
60957+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
60958+ }
60959+}
60960+
60961+int
60962+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
60963+{
60964+ struct sockaddr_in sin;
60965+
60966+ if (unlikely(skb->len < sizeof (struct udphdr)))
60967+ return 0; // skip this packet
60968+
60969+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
60970+ sin.sin_port = udp_hdr(skb)->source;
60971+
60972+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
60973+}
60974diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
60975new file mode 100644
60976index 0000000..34bdd46
60977--- /dev/null
60978+++ b/grsecurity/gracl_learn.c
60979@@ -0,0 +1,208 @@
60980+#include <linux/kernel.h>
60981+#include <linux/mm.h>
60982+#include <linux/sched.h>
60983+#include <linux/poll.h>
60984+#include <linux/smp_lock.h>
60985+#include <linux/string.h>
60986+#include <linux/file.h>
60987+#include <linux/types.h>
60988+#include <linux/vmalloc.h>
60989+#include <linux/grinternal.h>
60990+
60991+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
60992+ size_t count, loff_t *ppos);
60993+extern int gr_acl_is_enabled(void);
60994+
60995+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
60996+static int gr_learn_attached;
60997+
60998+/* use a 512k buffer */
60999+#define LEARN_BUFFER_SIZE (512 * 1024)
61000+
61001+static DEFINE_SPINLOCK(gr_learn_lock);
61002+static DEFINE_MUTEX(gr_learn_user_mutex);
61003+
61004+/* we need to maintain two buffers, so that the kernel context of grlearn
61005+ uses a semaphore around the userspace copying, and the other kernel contexts
61006+ use a spinlock when copying into the buffer, since they cannot sleep
61007+*/
61008+static char *learn_buffer;
61009+static char *learn_buffer_user;
61010+static int learn_buffer_len;
61011+static int learn_buffer_user_len;
61012+
61013+static ssize_t
61014+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
61015+{
61016+ DECLARE_WAITQUEUE(wait, current);
61017+ ssize_t retval = 0;
61018+
61019+ add_wait_queue(&learn_wait, &wait);
61020+ set_current_state(TASK_INTERRUPTIBLE);
61021+ do {
61022+ mutex_lock(&gr_learn_user_mutex);
61023+ spin_lock(&gr_learn_lock);
61024+ if (learn_buffer_len)
61025+ break;
61026+ spin_unlock(&gr_learn_lock);
61027+ mutex_unlock(&gr_learn_user_mutex);
61028+ if (file->f_flags & O_NONBLOCK) {
61029+ retval = -EAGAIN;
61030+ goto out;
61031+ }
61032+ if (signal_pending(current)) {
61033+ retval = -ERESTARTSYS;
61034+ goto out;
61035+ }
61036+
61037+ schedule();
61038+ } while (1);
61039+
61040+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
61041+ learn_buffer_user_len = learn_buffer_len;
61042+ retval = learn_buffer_len;
61043+ learn_buffer_len = 0;
61044+
61045+ spin_unlock(&gr_learn_lock);
61046+
61047+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
61048+ retval = -EFAULT;
61049+
61050+ mutex_unlock(&gr_learn_user_mutex);
61051+out:
61052+ set_current_state(TASK_RUNNING);
61053+ remove_wait_queue(&learn_wait, &wait);
61054+ return retval;
61055+}
61056+
61057+static unsigned int
61058+poll_learn(struct file * file, poll_table * wait)
61059+{
61060+ poll_wait(file, &learn_wait, wait);
61061+
61062+ if (learn_buffer_len)
61063+ return (POLLIN | POLLRDNORM);
61064+
61065+ return 0;
61066+}
61067+
61068+void
61069+gr_clear_learn_entries(void)
61070+{
61071+ char *tmp;
61072+
61073+ mutex_lock(&gr_learn_user_mutex);
61074+ spin_lock(&gr_learn_lock);
61075+ tmp = learn_buffer;
61076+ learn_buffer = NULL;
61077+ spin_unlock(&gr_learn_lock);
61078+ if (tmp)
61079+ vfree(tmp);
61080+ if (learn_buffer_user != NULL) {
61081+ vfree(learn_buffer_user);
61082+ learn_buffer_user = NULL;
61083+ }
61084+ learn_buffer_len = 0;
61085+ mutex_unlock(&gr_learn_user_mutex);
61086+
61087+ return;
61088+}
61089+
61090+void
61091+gr_add_learn_entry(const char *fmt, ...)
61092+{
61093+ va_list args;
61094+ unsigned int len;
61095+
61096+ if (!gr_learn_attached)
61097+ return;
61098+
61099+ spin_lock(&gr_learn_lock);
61100+
61101+ /* leave a gap at the end so we know when it's "full" but don't have to
61102+ compute the exact length of the string we're trying to append
61103+ */
61104+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
61105+ spin_unlock(&gr_learn_lock);
61106+ wake_up_interruptible(&learn_wait);
61107+ return;
61108+ }
61109+ if (learn_buffer == NULL) {
61110+ spin_unlock(&gr_learn_lock);
61111+ return;
61112+ }
61113+
61114+ va_start(args, fmt);
61115+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
61116+ va_end(args);
61117+
61118+ learn_buffer_len += len + 1;
61119+
61120+ spin_unlock(&gr_learn_lock);
61121+ wake_up_interruptible(&learn_wait);
61122+
61123+ return;
61124+}
61125+
61126+static int
61127+open_learn(struct inode *inode, struct file *file)
61128+{
61129+ if (file->f_mode & FMODE_READ && gr_learn_attached)
61130+ return -EBUSY;
61131+ if (file->f_mode & FMODE_READ) {
61132+ int retval = 0;
61133+ mutex_lock(&gr_learn_user_mutex);
61134+ if (learn_buffer == NULL)
61135+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
61136+ if (learn_buffer_user == NULL)
61137+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
61138+ if (learn_buffer == NULL) {
61139+ retval = -ENOMEM;
61140+ goto out_error;
61141+ }
61142+ if (learn_buffer_user == NULL) {
61143+ retval = -ENOMEM;
61144+ goto out_error;
61145+ }
61146+ learn_buffer_len = 0;
61147+ learn_buffer_user_len = 0;
61148+ gr_learn_attached = 1;
61149+out_error:
61150+ mutex_unlock(&gr_learn_user_mutex);
61151+ return retval;
61152+ }
61153+ return 0;
61154+}
61155+
61156+static int
61157+close_learn(struct inode *inode, struct file *file)
61158+{
61159+ if (file->f_mode & FMODE_READ) {
61160+ char *tmp = NULL;
61161+ mutex_lock(&gr_learn_user_mutex);
61162+ spin_lock(&gr_learn_lock);
61163+ tmp = learn_buffer;
61164+ learn_buffer = NULL;
61165+ spin_unlock(&gr_learn_lock);
61166+ if (tmp)
61167+ vfree(tmp);
61168+ if (learn_buffer_user != NULL) {
61169+ vfree(learn_buffer_user);
61170+ learn_buffer_user = NULL;
61171+ }
61172+ learn_buffer_len = 0;
61173+ learn_buffer_user_len = 0;
61174+ gr_learn_attached = 0;
61175+ mutex_unlock(&gr_learn_user_mutex);
61176+ }
61177+
61178+ return 0;
61179+}
61180+
61181+const struct file_operations grsec_fops = {
61182+ .read = read_learn,
61183+ .write = write_grsec_handler,
61184+ .open = open_learn,
61185+ .release = close_learn,
61186+ .poll = poll_learn,
61187+};
61188diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
61189new file mode 100644
61190index 0000000..70b2179
61191--- /dev/null
61192+++ b/grsecurity/gracl_res.c
61193@@ -0,0 +1,67 @@
61194+#include <linux/kernel.h>
61195+#include <linux/sched.h>
61196+#include <linux/gracl.h>
61197+#include <linux/grinternal.h>
61198+
61199+static const char *restab_log[] = {
61200+ [RLIMIT_CPU] = "RLIMIT_CPU",
61201+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
61202+ [RLIMIT_DATA] = "RLIMIT_DATA",
61203+ [RLIMIT_STACK] = "RLIMIT_STACK",
61204+ [RLIMIT_CORE] = "RLIMIT_CORE",
61205+ [RLIMIT_RSS] = "RLIMIT_RSS",
61206+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
61207+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
61208+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
61209+ [RLIMIT_AS] = "RLIMIT_AS",
61210+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
61211+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
61212+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
61213+ [RLIMIT_NICE] = "RLIMIT_NICE",
61214+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
61215+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
61216+ [GR_CRASH_RES] = "RLIMIT_CRASH"
61217+};
61218+
61219+void
61220+gr_log_resource(const struct task_struct *task,
61221+ const int res, const unsigned long wanted, const int gt)
61222+{
61223+ const struct cred *cred;
61224+ unsigned long rlim;
61225+
61226+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
61227+ return;
61228+
61229+ // not yet supported resource
61230+ if (unlikely(!restab_log[res]))
61231+ return;
61232+
61233+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
61234+ rlim = task->signal->rlim[res].rlim_max;
61235+ else
61236+ rlim = task->signal->rlim[res].rlim_cur;
61237+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
61238+ return;
61239+
61240+ rcu_read_lock();
61241+ cred = __task_cred(task);
61242+
61243+ if (res == RLIMIT_NPROC &&
61244+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
61245+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
61246+ goto out_rcu_unlock;
61247+ else if (res == RLIMIT_MEMLOCK &&
61248+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
61249+ goto out_rcu_unlock;
61250+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
61251+ goto out_rcu_unlock;
61252+ rcu_read_unlock();
61253+
61254+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
61255+
61256+ return;
61257+out_rcu_unlock:
61258+ rcu_read_unlock();
61259+ return;
61260+}
61261diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
61262new file mode 100644
61263index 0000000..1d1b734
61264--- /dev/null
61265+++ b/grsecurity/gracl_segv.c
61266@@ -0,0 +1,284 @@
61267+#include <linux/kernel.h>
61268+#include <linux/mm.h>
61269+#include <asm/uaccess.h>
61270+#include <asm/errno.h>
61271+#include <asm/mman.h>
61272+#include <net/sock.h>
61273+#include <linux/file.h>
61274+#include <linux/fs.h>
61275+#include <linux/net.h>
61276+#include <linux/in.h>
61277+#include <linux/smp_lock.h>
61278+#include <linux/slab.h>
61279+#include <linux/types.h>
61280+#include <linux/sched.h>
61281+#include <linux/timer.h>
61282+#include <linux/gracl.h>
61283+#include <linux/grsecurity.h>
61284+#include <linux/grinternal.h>
61285+
61286+static struct crash_uid *uid_set;
61287+static unsigned short uid_used;
61288+static DEFINE_SPINLOCK(gr_uid_lock);
61289+extern rwlock_t gr_inode_lock;
61290+extern struct acl_subject_label *
61291+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
61292+ struct acl_role_label *role);
61293+extern int gr_fake_force_sig(int sig, struct task_struct *t);
61294+
61295+int
61296+gr_init_uidset(void)
61297+{
61298+ uid_set =
61299+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
61300+ uid_used = 0;
61301+
61302+ return uid_set ? 1 : 0;
61303+}
61304+
61305+void
61306+gr_free_uidset(void)
61307+{
61308+ if (uid_set)
61309+ kfree(uid_set);
61310+
61311+ return;
61312+}
61313+
61314+int
61315+gr_find_uid(const uid_t uid)
61316+{
61317+ struct crash_uid *tmp = uid_set;
61318+ uid_t buid;
61319+ int low = 0, high = uid_used - 1, mid;
61320+
61321+ while (high >= low) {
61322+ mid = (low + high) >> 1;
61323+ buid = tmp[mid].uid;
61324+ if (buid == uid)
61325+ return mid;
61326+ if (buid > uid)
61327+ high = mid - 1;
61328+ if (buid < uid)
61329+ low = mid + 1;
61330+ }
61331+
61332+ return -1;
61333+}
61334+
61335+static __inline__ void
61336+gr_insertsort(void)
61337+{
61338+ unsigned short i, j;
61339+ struct crash_uid index;
61340+
61341+ for (i = 1; i < uid_used; i++) {
61342+ index = uid_set[i];
61343+ j = i;
61344+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
61345+ uid_set[j] = uid_set[j - 1];
61346+ j--;
61347+ }
61348+ uid_set[j] = index;
61349+ }
61350+
61351+ return;
61352+}
61353+
61354+static __inline__ void
61355+gr_insert_uid(const uid_t uid, const unsigned long expires)
61356+{
61357+ int loc;
61358+
61359+ if (uid_used == GR_UIDTABLE_MAX)
61360+ return;
61361+
61362+ loc = gr_find_uid(uid);
61363+
61364+ if (loc >= 0) {
61365+ uid_set[loc].expires = expires;
61366+ return;
61367+ }
61368+
61369+ uid_set[uid_used].uid = uid;
61370+ uid_set[uid_used].expires = expires;
61371+ uid_used++;
61372+
61373+ gr_insertsort();
61374+
61375+ return;
61376+}
61377+
61378+void
61379+gr_remove_uid(const unsigned short loc)
61380+{
61381+ unsigned short i;
61382+
61383+ for (i = loc + 1; i < uid_used; i++)
61384+ uid_set[i - 1] = uid_set[i];
61385+
61386+ uid_used--;
61387+
61388+ return;
61389+}
61390+
61391+int
61392+gr_check_crash_uid(const uid_t uid)
61393+{
61394+ int loc;
61395+ int ret = 0;
61396+
61397+ if (unlikely(!gr_acl_is_enabled()))
61398+ return 0;
61399+
61400+ spin_lock(&gr_uid_lock);
61401+ loc = gr_find_uid(uid);
61402+
61403+ if (loc < 0)
61404+ goto out_unlock;
61405+
61406+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
61407+ gr_remove_uid(loc);
61408+ else
61409+ ret = 1;
61410+
61411+out_unlock:
61412+ spin_unlock(&gr_uid_lock);
61413+ return ret;
61414+}
61415+
61416+static __inline__ int
61417+proc_is_setxid(const struct cred *cred)
61418+{
61419+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
61420+ cred->uid != cred->fsuid)
61421+ return 1;
61422+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
61423+ cred->gid != cred->fsgid)
61424+ return 1;
61425+
61426+ return 0;
61427+}
61428+
61429+void
61430+gr_handle_crash(struct task_struct *task, const int sig)
61431+{
61432+ struct acl_subject_label *curr;
61433+ struct task_struct *tsk, *tsk2;
61434+ const struct cred *cred;
61435+ const struct cred *cred2;
61436+
61437+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
61438+ return;
61439+
61440+ if (unlikely(!gr_acl_is_enabled()))
61441+ return;
61442+
61443+ curr = task->acl;
61444+
61445+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
61446+ return;
61447+
61448+ if (time_before_eq(curr->expires, get_seconds())) {
61449+ curr->expires = 0;
61450+ curr->crashes = 0;
61451+ }
61452+
61453+ curr->crashes++;
61454+
61455+ if (!curr->expires)
61456+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
61457+
61458+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
61459+ time_after(curr->expires, get_seconds())) {
61460+ rcu_read_lock();
61461+ cred = __task_cred(task);
61462+ if (cred->uid && proc_is_setxid(cred)) {
61463+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
61464+ spin_lock(&gr_uid_lock);
61465+ gr_insert_uid(cred->uid, curr->expires);
61466+ spin_unlock(&gr_uid_lock);
61467+ curr->expires = 0;
61468+ curr->crashes = 0;
61469+ read_lock(&tasklist_lock);
61470+ do_each_thread(tsk2, tsk) {
61471+ cred2 = __task_cred(tsk);
61472+ if (tsk != task && cred2->uid == cred->uid)
61473+ gr_fake_force_sig(SIGKILL, tsk);
61474+ } while_each_thread(tsk2, tsk);
61475+ read_unlock(&tasklist_lock);
61476+ } else {
61477+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
61478+ read_lock(&tasklist_lock);
61479+ read_lock(&grsec_exec_file_lock);
61480+ do_each_thread(tsk2, tsk) {
61481+ if (likely(tsk != task)) {
61482+ // if this thread has the same subject as the one that triggered
61483+ // RES_CRASH and it's the same binary, kill it
61484+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
61485+ gr_fake_force_sig(SIGKILL, tsk);
61486+ }
61487+ } while_each_thread(tsk2, tsk);
61488+ read_unlock(&grsec_exec_file_lock);
61489+ read_unlock(&tasklist_lock);
61490+ }
61491+ rcu_read_unlock();
61492+ }
61493+
61494+ return;
61495+}
61496+
61497+int
61498+gr_check_crash_exec(const struct file *filp)
61499+{
61500+ struct acl_subject_label *curr;
61501+
61502+ if (unlikely(!gr_acl_is_enabled()))
61503+ return 0;
61504+
61505+ read_lock(&gr_inode_lock);
61506+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
61507+ filp->f_path.dentry->d_inode->i_sb->s_dev,
61508+ current->role);
61509+ read_unlock(&gr_inode_lock);
61510+
61511+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
61512+ (!curr->crashes && !curr->expires))
61513+ return 0;
61514+
61515+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
61516+ time_after(curr->expires, get_seconds()))
61517+ return 1;
61518+ else if (time_before_eq(curr->expires, get_seconds())) {
61519+ curr->crashes = 0;
61520+ curr->expires = 0;
61521+ }
61522+
61523+ return 0;
61524+}
61525+
61526+void
61527+gr_handle_alertkill(struct task_struct *task)
61528+{
61529+ struct acl_subject_label *curracl;
61530+ __u32 curr_ip;
61531+ struct task_struct *p, *p2;
61532+
61533+ if (unlikely(!gr_acl_is_enabled()))
61534+ return;
61535+
61536+ curracl = task->acl;
61537+ curr_ip = task->signal->curr_ip;
61538+
61539+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
61540+ read_lock(&tasklist_lock);
61541+ do_each_thread(p2, p) {
61542+ if (p->signal->curr_ip == curr_ip)
61543+ gr_fake_force_sig(SIGKILL, p);
61544+ } while_each_thread(p2, p);
61545+ read_unlock(&tasklist_lock);
61546+ } else if (curracl->mode & GR_KILLPROC)
61547+ gr_fake_force_sig(SIGKILL, task);
61548+
61549+ return;
61550+}
61551diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
61552new file mode 100644
61553index 0000000..9d83a69
61554--- /dev/null
61555+++ b/grsecurity/gracl_shm.c
61556@@ -0,0 +1,40 @@
61557+#include <linux/kernel.h>
61558+#include <linux/mm.h>
61559+#include <linux/sched.h>
61560+#include <linux/file.h>
61561+#include <linux/ipc.h>
61562+#include <linux/gracl.h>
61563+#include <linux/grsecurity.h>
61564+#include <linux/grinternal.h>
61565+
61566+int
61567+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61568+ const time_t shm_createtime, const uid_t cuid, const int shmid)
61569+{
61570+ struct task_struct *task;
61571+
61572+ if (!gr_acl_is_enabled())
61573+ return 1;
61574+
61575+ rcu_read_lock();
61576+ read_lock(&tasklist_lock);
61577+
61578+ task = find_task_by_vpid(shm_cprid);
61579+
61580+ if (unlikely(!task))
61581+ task = find_task_by_vpid(shm_lapid);
61582+
61583+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
61584+ (task->pid == shm_lapid)) &&
61585+ (task->acl->mode & GR_PROTSHM) &&
61586+ (task->acl != current->acl))) {
61587+ read_unlock(&tasklist_lock);
61588+ rcu_read_unlock();
61589+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
61590+ return 0;
61591+ }
61592+ read_unlock(&tasklist_lock);
61593+ rcu_read_unlock();
61594+
61595+ return 1;
61596+}
61597diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
61598new file mode 100644
61599index 0000000..bc0be01
61600--- /dev/null
61601+++ b/grsecurity/grsec_chdir.c
61602@@ -0,0 +1,19 @@
61603+#include <linux/kernel.h>
61604+#include <linux/sched.h>
61605+#include <linux/fs.h>
61606+#include <linux/file.h>
61607+#include <linux/grsecurity.h>
61608+#include <linux/grinternal.h>
61609+
61610+void
61611+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
61612+{
61613+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61614+ if ((grsec_enable_chdir && grsec_enable_group &&
61615+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
61616+ !grsec_enable_group)) {
61617+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
61618+ }
61619+#endif
61620+ return;
61621+}
61622diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
61623new file mode 100644
61624index 0000000..197bdd5
61625--- /dev/null
61626+++ b/grsecurity/grsec_chroot.c
61627@@ -0,0 +1,386 @@
61628+#include <linux/kernel.h>
61629+#include <linux/module.h>
61630+#include <linux/sched.h>
61631+#include <linux/file.h>
61632+#include <linux/fs.h>
61633+#include <linux/mount.h>
61634+#include <linux/types.h>
61635+#include <linux/pid_namespace.h>
61636+#include <linux/grsecurity.h>
61637+#include <linux/grinternal.h>
61638+
61639+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
61640+{
61641+#ifdef CONFIG_GRKERNSEC
61642+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
61643+ path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
61644+ task->gr_is_chrooted = 1;
61645+ else
61646+ task->gr_is_chrooted = 0;
61647+
61648+ task->gr_chroot_dentry = path->dentry;
61649+#endif
61650+ return;
61651+}
61652+
61653+void gr_clear_chroot_entries(struct task_struct *task)
61654+{
61655+#ifdef CONFIG_GRKERNSEC
61656+ task->gr_is_chrooted = 0;
61657+ task->gr_chroot_dentry = NULL;
61658+#endif
61659+ return;
61660+}
61661+
61662+int
61663+gr_handle_chroot_unix(const pid_t pid)
61664+{
61665+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61666+ struct task_struct *p;
61667+
61668+ if (unlikely(!grsec_enable_chroot_unix))
61669+ return 1;
61670+
61671+ if (likely(!proc_is_chrooted(current)))
61672+ return 1;
61673+
61674+ rcu_read_lock();
61675+ read_lock(&tasklist_lock);
61676+
61677+ p = find_task_by_vpid_unrestricted(pid);
61678+ if (unlikely(p && !have_same_root(current, p))) {
61679+ read_unlock(&tasklist_lock);
61680+ rcu_read_unlock();
61681+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
61682+ return 0;
61683+ }
61684+ read_unlock(&tasklist_lock);
61685+ rcu_read_unlock();
61686+#endif
61687+ return 1;
61688+}
61689+
61690+int
61691+gr_handle_chroot_nice(void)
61692+{
61693+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61694+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
61695+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
61696+ return -EPERM;
61697+ }
61698+#endif
61699+ return 0;
61700+}
61701+
61702+int
61703+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
61704+{
61705+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61706+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
61707+ && proc_is_chrooted(current)) {
61708+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
61709+ return -EACCES;
61710+ }
61711+#endif
61712+ return 0;
61713+}
61714+
61715+int
61716+gr_handle_chroot_rawio(const struct inode *inode)
61717+{
61718+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61719+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
61720+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
61721+ return 1;
61722+#endif
61723+ return 0;
61724+}
61725+
61726+int
61727+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
61728+{
61729+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61730+ struct task_struct *p;
61731+ int ret = 0;
61732+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
61733+ return ret;
61734+
61735+ read_lock(&tasklist_lock);
61736+ do_each_pid_task(pid, type, p) {
61737+ if (!have_same_root(current, p)) {
61738+ ret = 1;
61739+ goto out;
61740+ }
61741+ } while_each_pid_task(pid, type, p);
61742+out:
61743+ read_unlock(&tasklist_lock);
61744+ return ret;
61745+#endif
61746+ return 0;
61747+}
61748+
61749+int
61750+gr_pid_is_chrooted(struct task_struct *p)
61751+{
61752+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61753+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
61754+ return 0;
61755+
61756+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
61757+ !have_same_root(current, p)) {
61758+ return 1;
61759+ }
61760+#endif
61761+ return 0;
61762+}
61763+
61764+EXPORT_SYMBOL(gr_pid_is_chrooted);
61765+
61766+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
61767+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
61768+{
61769+ struct dentry *dentry = (struct dentry *)u_dentry;
61770+ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
61771+ struct dentry *realroot;
61772+ struct vfsmount *realrootmnt;
61773+ struct dentry *currentroot;
61774+ struct vfsmount *currentmnt;
61775+ struct task_struct *reaper = &init_task;
61776+ int ret = 1;
61777+
61778+ read_lock(&reaper->fs->lock);
61779+ realrootmnt = mntget(reaper->fs->root.mnt);
61780+ realroot = dget(reaper->fs->root.dentry);
61781+ read_unlock(&reaper->fs->lock);
61782+
61783+ read_lock(&current->fs->lock);
61784+ currentmnt = mntget(current->fs->root.mnt);
61785+ currentroot = dget(current->fs->root.dentry);
61786+ read_unlock(&current->fs->lock);
61787+
61788+ spin_lock(&dcache_lock);
61789+ for (;;) {
61790+ if (unlikely((dentry == realroot && mnt == realrootmnt)
61791+ || (dentry == currentroot && mnt == currentmnt)))
61792+ break;
61793+ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
61794+ if (mnt->mnt_parent == mnt)
61795+ break;
61796+ dentry = mnt->mnt_mountpoint;
61797+ mnt = mnt->mnt_parent;
61798+ continue;
61799+ }
61800+ dentry = dentry->d_parent;
61801+ }
61802+ spin_unlock(&dcache_lock);
61803+
61804+ dput(currentroot);
61805+ mntput(currentmnt);
61806+
61807+ /* access is outside of chroot */
61808+ if (dentry == realroot && mnt == realrootmnt)
61809+ ret = 0;
61810+
61811+ dput(realroot);
61812+ mntput(realrootmnt);
61813+ return ret;
61814+}
61815+#endif
61816+
61817+int
61818+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
61819+{
61820+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61821+ if (!grsec_enable_chroot_fchdir)
61822+ return 1;
61823+
61824+ if (!proc_is_chrooted(current))
61825+ return 1;
61826+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
61827+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
61828+ return 0;
61829+ }
61830+#endif
61831+ return 1;
61832+}
61833+
61834+int
61835+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61836+ const time_t shm_createtime)
61837+{
61838+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61839+ struct task_struct *p;
61840+ time_t starttime;
61841+
61842+ if (unlikely(!grsec_enable_chroot_shmat))
61843+ return 1;
61844+
61845+ if (likely(!proc_is_chrooted(current)))
61846+ return 1;
61847+
61848+ rcu_read_lock();
61849+ read_lock(&tasklist_lock);
61850+
61851+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
61852+ starttime = p->start_time.tv_sec;
61853+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
61854+ if (have_same_root(current, p)) {
61855+ goto allow;
61856+ } else {
61857+ read_unlock(&tasklist_lock);
61858+ rcu_read_unlock();
61859+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
61860+ return 0;
61861+ }
61862+ }
61863+ /* creator exited, pid reuse, fall through to next check */
61864+ }
61865+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
61866+ if (unlikely(!have_same_root(current, p))) {
61867+ read_unlock(&tasklist_lock);
61868+ rcu_read_unlock();
61869+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
61870+ return 0;
61871+ }
61872+ }
61873+
61874+allow:
61875+ read_unlock(&tasklist_lock);
61876+ rcu_read_unlock();
61877+#endif
61878+ return 1;
61879+}
61880+
61881+void
61882+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
61883+{
61884+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61885+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
61886+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
61887+#endif
61888+ return;
61889+}
61890+
61891+int
61892+gr_handle_chroot_mknod(const struct dentry *dentry,
61893+ const struct vfsmount *mnt, const int mode)
61894+{
61895+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61896+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
61897+ proc_is_chrooted(current)) {
61898+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
61899+ return -EPERM;
61900+ }
61901+#endif
61902+ return 0;
61903+}
61904+
61905+int
61906+gr_handle_chroot_mount(const struct dentry *dentry,
61907+ const struct vfsmount *mnt, const char *dev_name)
61908+{
61909+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61910+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
61911+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none" , dentry, mnt);
61912+ return -EPERM;
61913+ }
61914+#endif
61915+ return 0;
61916+}
61917+
61918+int
61919+gr_handle_chroot_pivot(void)
61920+{
61921+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61922+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
61923+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
61924+ return -EPERM;
61925+ }
61926+#endif
61927+ return 0;
61928+}
61929+
61930+int
61931+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
61932+{
61933+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61934+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
61935+ !gr_is_outside_chroot(dentry, mnt)) {
61936+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
61937+ return -EPERM;
61938+ }
61939+#endif
61940+ return 0;
61941+}
61942+
61943+extern const char *captab_log[];
61944+extern int captab_log_entries;
61945+
61946+int
61947+gr_chroot_is_capable(const int cap)
61948+{
61949+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61950+ if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
61951+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
61952+ if (cap_raised(chroot_caps, cap)) {
61953+ const struct cred *creds = current_cred();
61954+ if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
61955+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
61956+ }
61957+ return 0;
61958+ }
61959+ }
61960+#endif
61961+ return 1;
61962+}
61963+
61964+int
61965+gr_chroot_is_capable_nolog(const int cap)
61966+{
61967+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61968+ if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
61969+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
61970+ if (cap_raised(chroot_caps, cap)) {
61971+ return 0;
61972+ }
61973+ }
61974+#endif
61975+ return 1;
61976+}
61977+
61978+int
61979+gr_handle_chroot_sysctl(const int op)
61980+{
61981+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61982+ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
61983+ && (op & MAY_WRITE))
61984+ return -EACCES;
61985+#endif
61986+ return 0;
61987+}
61988+
61989+void
61990+gr_handle_chroot_chdir(struct path *path)
61991+{
61992+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61993+ if (grsec_enable_chroot_chdir)
61994+ set_fs_pwd(current->fs, path);
61995+#endif
61996+ return;
61997+}
61998+
61999+int
62000+gr_handle_chroot_chmod(const struct dentry *dentry,
62001+ const struct vfsmount *mnt, const int mode)
62002+{
62003+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62004+ /* allow chmod +s on directories, but not on files */
62005+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
62006+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
62007+ proc_is_chrooted(current)) {
62008+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
62009+ return -EPERM;
62010+ }
62011+#endif
62012+ return 0;
62013+}
62014diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
62015new file mode 100644
62016index 0000000..b81db5b
62017--- /dev/null
62018+++ b/grsecurity/grsec_disabled.c
62019@@ -0,0 +1,439 @@
62020+#include <linux/kernel.h>
62021+#include <linux/module.h>
62022+#include <linux/sched.h>
62023+#include <linux/file.h>
62024+#include <linux/fs.h>
62025+#include <linux/kdev_t.h>
62026+#include <linux/net.h>
62027+#include <linux/in.h>
62028+#include <linux/ip.h>
62029+#include <linux/skbuff.h>
62030+#include <linux/sysctl.h>
62031+
62032+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62033+void
62034+pax_set_initial_flags(struct linux_binprm *bprm)
62035+{
62036+ return;
62037+}
62038+#endif
62039+
62040+#ifdef CONFIG_SYSCTL
62041+__u32
62042+gr_handle_sysctl(const struct ctl_table * table, const int op)
62043+{
62044+ return 0;
62045+}
62046+#endif
62047+
62048+#ifdef CONFIG_TASKSTATS
62049+int gr_is_taskstats_denied(int pid)
62050+{
62051+ return 0;
62052+}
62053+#endif
62054+
62055+int
62056+gr_acl_is_enabled(void)
62057+{
62058+ return 0;
62059+}
62060+
62061+void
62062+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
62063+{
62064+ return;
62065+}
62066+
62067+int
62068+gr_handle_rawio(const struct inode *inode)
62069+{
62070+ return 0;
62071+}
62072+
62073+void
62074+gr_acl_handle_psacct(struct task_struct *task, const long code)
62075+{
62076+ return;
62077+}
62078+
62079+int
62080+gr_handle_ptrace(struct task_struct *task, const long request)
62081+{
62082+ return 0;
62083+}
62084+
62085+int
62086+gr_handle_proc_ptrace(struct task_struct *task)
62087+{
62088+ return 0;
62089+}
62090+
62091+void
62092+gr_learn_resource(const struct task_struct *task,
62093+ const int res, const unsigned long wanted, const int gt)
62094+{
62095+ return;
62096+}
62097+
62098+int
62099+gr_set_acls(const int type)
62100+{
62101+ return 0;
62102+}
62103+
62104+int
62105+gr_check_hidden_task(const struct task_struct *tsk)
62106+{
62107+ return 0;
62108+}
62109+
62110+int
62111+gr_check_protected_task(const struct task_struct *task)
62112+{
62113+ return 0;
62114+}
62115+
62116+int
62117+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
62118+{
62119+ return 0;
62120+}
62121+
62122+void
62123+gr_copy_label(struct task_struct *tsk)
62124+{
62125+ return;
62126+}
62127+
62128+void
62129+gr_set_pax_flags(struct task_struct *task)
62130+{
62131+ return;
62132+}
62133+
62134+int
62135+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
62136+ const int unsafe_share)
62137+{
62138+ return 0;
62139+}
62140+
62141+void
62142+gr_handle_delete(const ino_t ino, const dev_t dev)
62143+{
62144+ return;
62145+}
62146+
62147+void
62148+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
62149+{
62150+ return;
62151+}
62152+
62153+void
62154+gr_handle_crash(struct task_struct *task, const int sig)
62155+{
62156+ return;
62157+}
62158+
62159+int
62160+gr_check_crash_exec(const struct file *filp)
62161+{
62162+ return 0;
62163+}
62164+
62165+int
62166+gr_check_crash_uid(const uid_t uid)
62167+{
62168+ return 0;
62169+}
62170+
62171+void
62172+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62173+ struct dentry *old_dentry,
62174+ struct dentry *new_dentry,
62175+ struct vfsmount *mnt, const __u8 replace)
62176+{
62177+ return;
62178+}
62179+
62180+int
62181+gr_search_socket(const int family, const int type, const int protocol)
62182+{
62183+ return 1;
62184+}
62185+
62186+int
62187+gr_search_connectbind(const int mode, const struct socket *sock,
62188+ const struct sockaddr_in *addr)
62189+{
62190+ return 0;
62191+}
62192+
62193+void
62194+gr_handle_alertkill(struct task_struct *task)
62195+{
62196+ return;
62197+}
62198+
62199+__u32
62200+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
62201+{
62202+ return 1;
62203+}
62204+
62205+__u32
62206+gr_acl_handle_hidden_file(const struct dentry * dentry,
62207+ const struct vfsmount * mnt)
62208+{
62209+ return 1;
62210+}
62211+
62212+__u32
62213+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62214+ int acc_mode)
62215+{
62216+ return 1;
62217+}
62218+
62219+__u32
62220+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62221+{
62222+ return 1;
62223+}
62224+
62225+__u32
62226+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
62227+{
62228+ return 1;
62229+}
62230+
62231+int
62232+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
62233+ unsigned int *vm_flags)
62234+{
62235+ return 1;
62236+}
62237+
62238+__u32
62239+gr_acl_handle_truncate(const struct dentry * dentry,
62240+ const struct vfsmount * mnt)
62241+{
62242+ return 1;
62243+}
62244+
62245+__u32
62246+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
62247+{
62248+ return 1;
62249+}
62250+
62251+__u32
62252+gr_acl_handle_access(const struct dentry * dentry,
62253+ const struct vfsmount * mnt, const int fmode)
62254+{
62255+ return 1;
62256+}
62257+
62258+__u32
62259+gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
62260+ mode_t mode)
62261+{
62262+ return 1;
62263+}
62264+
62265+__u32
62266+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
62267+ mode_t mode)
62268+{
62269+ return 1;
62270+}
62271+
62272+__u32
62273+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
62274+{
62275+ return 1;
62276+}
62277+
62278+__u32
62279+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
62280+{
62281+ return 1;
62282+}
62283+
62284+void
62285+grsecurity_init(void)
62286+{
62287+ return;
62288+}
62289+
62290+__u32
62291+gr_acl_handle_mknod(const struct dentry * new_dentry,
62292+ const struct dentry * parent_dentry,
62293+ const struct vfsmount * parent_mnt,
62294+ const int mode)
62295+{
62296+ return 1;
62297+}
62298+
62299+__u32
62300+gr_acl_handle_mkdir(const struct dentry * new_dentry,
62301+ const struct dentry * parent_dentry,
62302+ const struct vfsmount * parent_mnt)
62303+{
62304+ return 1;
62305+}
62306+
62307+__u32
62308+gr_acl_handle_symlink(const struct dentry * new_dentry,
62309+ const struct dentry * parent_dentry,
62310+ const struct vfsmount * parent_mnt, const char *from)
62311+{
62312+ return 1;
62313+}
62314+
62315+__u32
62316+gr_acl_handle_link(const struct dentry * new_dentry,
62317+ const struct dentry * parent_dentry,
62318+ const struct vfsmount * parent_mnt,
62319+ const struct dentry * old_dentry,
62320+ const struct vfsmount * old_mnt, const char *to)
62321+{
62322+ return 1;
62323+}
62324+
62325+int
62326+gr_acl_handle_rename(const struct dentry *new_dentry,
62327+ const struct dentry *parent_dentry,
62328+ const struct vfsmount *parent_mnt,
62329+ const struct dentry *old_dentry,
62330+ const struct inode *old_parent_inode,
62331+ const struct vfsmount *old_mnt, const char *newname)
62332+{
62333+ return 0;
62334+}
62335+
62336+int
62337+gr_acl_handle_filldir(const struct file *file, const char *name,
62338+ const int namelen, const ino_t ino)
62339+{
62340+ return 1;
62341+}
62342+
62343+int
62344+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62345+ const time_t shm_createtime, const uid_t cuid, const int shmid)
62346+{
62347+ return 1;
62348+}
62349+
62350+int
62351+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
62352+{
62353+ return 0;
62354+}
62355+
62356+int
62357+gr_search_accept(const struct socket *sock)
62358+{
62359+ return 0;
62360+}
62361+
62362+int
62363+gr_search_listen(const struct socket *sock)
62364+{
62365+ return 0;
62366+}
62367+
62368+int
62369+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
62370+{
62371+ return 0;
62372+}
62373+
62374+__u32
62375+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
62376+{
62377+ return 1;
62378+}
62379+
62380+__u32
62381+gr_acl_handle_creat(const struct dentry * dentry,
62382+ const struct dentry * p_dentry,
62383+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62384+ const int imode)
62385+{
62386+ return 1;
62387+}
62388+
62389+void
62390+gr_acl_handle_exit(void)
62391+{
62392+ return;
62393+}
62394+
62395+int
62396+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62397+{
62398+ return 1;
62399+}
62400+
62401+void
62402+gr_set_role_label(const uid_t uid, const gid_t gid)
62403+{
62404+ return;
62405+}
62406+
62407+int
62408+gr_acl_handle_procpidmem(const struct task_struct *task)
62409+{
62410+ return 0;
62411+}
62412+
62413+int
62414+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
62415+{
62416+ return 0;
62417+}
62418+
62419+int
62420+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
62421+{
62422+ return 0;
62423+}
62424+
62425+void
62426+gr_set_kernel_label(struct task_struct *task)
62427+{
62428+ return;
62429+}
62430+
62431+int
62432+gr_check_user_change(int real, int effective, int fs)
62433+{
62434+ return 0;
62435+}
62436+
62437+int
62438+gr_check_group_change(int real, int effective, int fs)
62439+{
62440+ return 0;
62441+}
62442+
62443+int gr_acl_enable_at_secure(void)
62444+{
62445+ return 0;
62446+}
62447+
62448+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62449+{
62450+ return dentry->d_inode->i_sb->s_dev;
62451+}
62452+
62453+EXPORT_SYMBOL(gr_learn_resource);
62454+EXPORT_SYMBOL(gr_set_kernel_label);
62455+#ifdef CONFIG_SECURITY
62456+EXPORT_SYMBOL(gr_check_user_change);
62457+EXPORT_SYMBOL(gr_check_group_change);
62458+#endif
62459diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
62460new file mode 100644
62461index 0000000..a96e155
62462--- /dev/null
62463+++ b/grsecurity/grsec_exec.c
62464@@ -0,0 +1,204 @@
62465+#include <linux/kernel.h>
62466+#include <linux/sched.h>
62467+#include <linux/file.h>
62468+#include <linux/binfmts.h>
62469+#include <linux/smp_lock.h>
62470+#include <linux/fs.h>
62471+#include <linux/types.h>
62472+#include <linux/grdefs.h>
62473+#include <linux/grinternal.h>
62474+#include <linux/capability.h>
62475+#include <linux/compat.h>
62476+#include <linux/module.h>
62477+
62478+#include <asm/uaccess.h>
62479+
62480+#ifdef CONFIG_GRKERNSEC_EXECLOG
62481+static char gr_exec_arg_buf[132];
62482+static DEFINE_MUTEX(gr_exec_arg_mutex);
62483+#endif
62484+
62485+void
62486+gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
62487+{
62488+#ifdef CONFIG_GRKERNSEC_EXECLOG
62489+ char *grarg = gr_exec_arg_buf;
62490+ unsigned int i, x, execlen = 0;
62491+ char c;
62492+
62493+ if (!((grsec_enable_execlog && grsec_enable_group &&
62494+ in_group_p(grsec_audit_gid))
62495+ || (grsec_enable_execlog && !grsec_enable_group)))
62496+ return;
62497+
62498+ mutex_lock(&gr_exec_arg_mutex);
62499+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
62500+
62501+ if (unlikely(argv == NULL))
62502+ goto log;
62503+
62504+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
62505+ const char __user *p;
62506+ unsigned int len;
62507+
62508+ if (copy_from_user(&p, argv + i, sizeof(p)))
62509+ goto log;
62510+ if (!p)
62511+ goto log;
62512+ len = strnlen_user(p, 128 - execlen);
62513+ if (len > 128 - execlen)
62514+ len = 128 - execlen;
62515+ else if (len > 0)
62516+ len--;
62517+ if (copy_from_user(grarg + execlen, p, len))
62518+ goto log;
62519+
62520+ /* rewrite unprintable characters */
62521+ for (x = 0; x < len; x++) {
62522+ c = *(grarg + execlen + x);
62523+ if (c < 32 || c > 126)
62524+ *(grarg + execlen + x) = ' ';
62525+ }
62526+
62527+ execlen += len;
62528+ *(grarg + execlen) = ' ';
62529+ *(grarg + execlen + 1) = '\0';
62530+ execlen++;
62531+ }
62532+
62533+ log:
62534+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
62535+ bprm->file->f_path.mnt, grarg);
62536+ mutex_unlock(&gr_exec_arg_mutex);
62537+#endif
62538+ return;
62539+}
62540+
62541+#ifdef CONFIG_COMPAT
62542+void
62543+gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
62544+{
62545+#ifdef CONFIG_GRKERNSEC_EXECLOG
62546+ char *grarg = gr_exec_arg_buf;
62547+ unsigned int i, x, execlen = 0;
62548+ char c;
62549+
62550+ if (!((grsec_enable_execlog && grsec_enable_group &&
62551+ in_group_p(grsec_audit_gid))
62552+ || (grsec_enable_execlog && !grsec_enable_group)))
62553+ return;
62554+
62555+ mutex_lock(&gr_exec_arg_mutex);
62556+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
62557+
62558+ if (unlikely(argv == NULL))
62559+ goto log;
62560+
62561+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
62562+ compat_uptr_t p;
62563+ unsigned int len;
62564+
62565+ if (get_user(p, argv + i))
62566+ goto log;
62567+ len = strnlen_user(compat_ptr(p), 128 - execlen);
62568+ if (len > 128 - execlen)
62569+ len = 128 - execlen;
62570+ else if (len > 0)
62571+ len--;
62572+ else
62573+ goto log;
62574+ if (copy_from_user(grarg + execlen, compat_ptr(p), len))
62575+ goto log;
62576+
62577+ /* rewrite unprintable characters */
62578+ for (x = 0; x < len; x++) {
62579+ c = *(grarg + execlen + x);
62580+ if (c < 32 || c > 126)
62581+ *(grarg + execlen + x) = ' ';
62582+ }
62583+
62584+ execlen += len;
62585+ *(grarg + execlen) = ' ';
62586+ *(grarg + execlen + 1) = '\0';
62587+ execlen++;
62588+ }
62589+
62590+ log:
62591+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
62592+ bprm->file->f_path.mnt, grarg);
62593+ mutex_unlock(&gr_exec_arg_mutex);
62594+#endif
62595+ return;
62596+}
62597+#endif
62598+
62599+#ifdef CONFIG_GRKERNSEC
62600+extern int gr_acl_is_capable(const int cap);
62601+extern int gr_acl_is_capable_nolog(const int cap);
62602+extern int gr_chroot_is_capable(const int cap);
62603+extern int gr_chroot_is_capable_nolog(const int cap);
62604+#endif
62605+
62606+const char *captab_log[] = {
62607+ "CAP_CHOWN",
62608+ "CAP_DAC_OVERRIDE",
62609+ "CAP_DAC_READ_SEARCH",
62610+ "CAP_FOWNER",
62611+ "CAP_FSETID",
62612+ "CAP_KILL",
62613+ "CAP_SETGID",
62614+ "CAP_SETUID",
62615+ "CAP_SETPCAP",
62616+ "CAP_LINUX_IMMUTABLE",
62617+ "CAP_NET_BIND_SERVICE",
62618+ "CAP_NET_BROADCAST",
62619+ "CAP_NET_ADMIN",
62620+ "CAP_NET_RAW",
62621+ "CAP_IPC_LOCK",
62622+ "CAP_IPC_OWNER",
62623+ "CAP_SYS_MODULE",
62624+ "CAP_SYS_RAWIO",
62625+ "CAP_SYS_CHROOT",
62626+ "CAP_SYS_PTRACE",
62627+ "CAP_SYS_PACCT",
62628+ "CAP_SYS_ADMIN",
62629+ "CAP_SYS_BOOT",
62630+ "CAP_SYS_NICE",
62631+ "CAP_SYS_RESOURCE",
62632+ "CAP_SYS_TIME",
62633+ "CAP_SYS_TTY_CONFIG",
62634+ "CAP_MKNOD",
62635+ "CAP_LEASE",
62636+ "CAP_AUDIT_WRITE",
62637+ "CAP_AUDIT_CONTROL",
62638+ "CAP_SETFCAP",
62639+ "CAP_MAC_OVERRIDE",
62640+ "CAP_MAC_ADMIN"
62641+};
62642+
62643+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
62644+
62645+int gr_is_capable(const int cap)
62646+{
62647+#ifdef CONFIG_GRKERNSEC
62648+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
62649+ return 1;
62650+ return 0;
62651+#else
62652+ return 1;
62653+#endif
62654+}
62655+
62656+int gr_is_capable_nolog(const int cap)
62657+{
62658+#ifdef CONFIG_GRKERNSEC
62659+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
62660+ return 1;
62661+ return 0;
62662+#else
62663+ return 1;
62664+#endif
62665+}
62666+
62667+EXPORT_SYMBOL(gr_is_capable);
62668+EXPORT_SYMBOL(gr_is_capable_nolog);
62669diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
62670new file mode 100644
62671index 0000000..d3ee748
62672--- /dev/null
62673+++ b/grsecurity/grsec_fifo.c
62674@@ -0,0 +1,24 @@
62675+#include <linux/kernel.h>
62676+#include <linux/sched.h>
62677+#include <linux/fs.h>
62678+#include <linux/file.h>
62679+#include <linux/grinternal.h>
62680+
62681+int
62682+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
62683+ const struct dentry *dir, const int flag, const int acc_mode)
62684+{
62685+#ifdef CONFIG_GRKERNSEC_FIFO
62686+ const struct cred *cred = current_cred();
62687+
62688+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
62689+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
62690+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
62691+ (cred->fsuid != dentry->d_inode->i_uid)) {
62692+ if (!inode_permission(dentry->d_inode, acc_mode))
62693+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
62694+ return -EACCES;
62695+ }
62696+#endif
62697+ return 0;
62698+}
62699diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
62700new file mode 100644
62701index 0000000..8ca18bf
62702--- /dev/null
62703+++ b/grsecurity/grsec_fork.c
62704@@ -0,0 +1,23 @@
62705+#include <linux/kernel.h>
62706+#include <linux/sched.h>
62707+#include <linux/grsecurity.h>
62708+#include <linux/grinternal.h>
62709+#include <linux/errno.h>
62710+
62711+void
62712+gr_log_forkfail(const int retval)
62713+{
62714+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62715+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
62716+ switch (retval) {
62717+ case -EAGAIN:
62718+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
62719+ break;
62720+ case -ENOMEM:
62721+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
62722+ break;
62723+ }
62724+ }
62725+#endif
62726+ return;
62727+}
62728diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
62729new file mode 100644
62730index 0000000..f813c26
62731--- /dev/null
62732+++ b/grsecurity/grsec_init.c
62733@@ -0,0 +1,270 @@
62734+#include <linux/kernel.h>
62735+#include <linux/sched.h>
62736+#include <linux/mm.h>
62737+#include <linux/smp_lock.h>
62738+#include <linux/gracl.h>
62739+#include <linux/slab.h>
62740+#include <linux/vmalloc.h>
62741+#include <linux/percpu.h>
62742+#include <linux/module.h>
62743+
62744+int grsec_enable_brute;
62745+int grsec_enable_link;
62746+int grsec_enable_dmesg;
62747+int grsec_enable_harden_ptrace;
62748+int grsec_enable_fifo;
62749+int grsec_enable_execlog;
62750+int grsec_enable_signal;
62751+int grsec_enable_forkfail;
62752+int grsec_enable_audit_ptrace;
62753+int grsec_enable_time;
62754+int grsec_enable_audit_textrel;
62755+int grsec_enable_group;
62756+int grsec_audit_gid;
62757+int grsec_enable_chdir;
62758+int grsec_enable_mount;
62759+int grsec_enable_rofs;
62760+int grsec_enable_chroot_findtask;
62761+int grsec_enable_chroot_mount;
62762+int grsec_enable_chroot_shmat;
62763+int grsec_enable_chroot_fchdir;
62764+int grsec_enable_chroot_double;
62765+int grsec_enable_chroot_pivot;
62766+int grsec_enable_chroot_chdir;
62767+int grsec_enable_chroot_chmod;
62768+int grsec_enable_chroot_mknod;
62769+int grsec_enable_chroot_nice;
62770+int grsec_enable_chroot_execlog;
62771+int grsec_enable_chroot_caps;
62772+int grsec_enable_chroot_sysctl;
62773+int grsec_enable_chroot_unix;
62774+int grsec_enable_tpe;
62775+int grsec_tpe_gid;
62776+int grsec_enable_blackhole;
62777+#ifdef CONFIG_IPV6_MODULE
62778+EXPORT_SYMBOL(grsec_enable_blackhole);
62779+#endif
62780+int grsec_lastack_retries;
62781+int grsec_enable_tpe_all;
62782+int grsec_enable_tpe_invert;
62783+int grsec_enable_socket_all;
62784+int grsec_socket_all_gid;
62785+int grsec_enable_socket_client;
62786+int grsec_socket_client_gid;
62787+int grsec_enable_socket_server;
62788+int grsec_socket_server_gid;
62789+int grsec_resource_logging;
62790+int grsec_disable_privio;
62791+int grsec_enable_log_rwxmaps;
62792+int grsec_lock;
62793+
62794+DEFINE_SPINLOCK(grsec_alert_lock);
62795+unsigned long grsec_alert_wtime = 0;
62796+unsigned long grsec_alert_fyet = 0;
62797+
62798+DEFINE_SPINLOCK(grsec_audit_lock);
62799+
62800+DEFINE_RWLOCK(grsec_exec_file_lock);
62801+
62802+char *gr_shared_page[4];
62803+
62804+char *gr_alert_log_fmt;
62805+char *gr_audit_log_fmt;
62806+char *gr_alert_log_buf;
62807+char *gr_audit_log_buf;
62808+
62809+extern struct gr_arg *gr_usermode;
62810+extern unsigned char *gr_system_salt;
62811+extern unsigned char *gr_system_sum;
62812+
62813+void __init
62814+grsecurity_init(void)
62815+{
62816+ int j;
62817+ /* create the per-cpu shared pages */
62818+
62819+#ifdef CONFIG_X86
62820+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
62821+#endif
62822+
62823+ for (j = 0; j < 4; j++) {
62824+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
62825+ if (gr_shared_page[j] == NULL) {
62826+ panic("Unable to allocate grsecurity shared page");
62827+ return;
62828+ }
62829+ }
62830+
62831+ /* allocate log buffers */
62832+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
62833+ if (!gr_alert_log_fmt) {
62834+ panic("Unable to allocate grsecurity alert log format buffer");
62835+ return;
62836+ }
62837+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
62838+ if (!gr_audit_log_fmt) {
62839+ panic("Unable to allocate grsecurity audit log format buffer");
62840+ return;
62841+ }
62842+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
62843+ if (!gr_alert_log_buf) {
62844+ panic("Unable to allocate grsecurity alert log buffer");
62845+ return;
62846+ }
62847+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
62848+ if (!gr_audit_log_buf) {
62849+ panic("Unable to allocate grsecurity audit log buffer");
62850+ return;
62851+ }
62852+
62853+ /* allocate memory for authentication structure */
62854+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
62855+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
62856+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
62857+
62858+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
62859+ panic("Unable to allocate grsecurity authentication structure");
62860+ return;
62861+ }
62862+
62863+
62864+#ifdef CONFIG_GRKERNSEC_IO
62865+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
62866+ grsec_disable_privio = 1;
62867+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
62868+ grsec_disable_privio = 1;
62869+#else
62870+ grsec_disable_privio = 0;
62871+#endif
62872+#endif
62873+
62874+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62875+ /* for backward compatibility, tpe_invert always defaults to on if
62876+ enabled in the kernel
62877+ */
62878+ grsec_enable_tpe_invert = 1;
62879+#endif
62880+
62881+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
62882+#ifndef CONFIG_GRKERNSEC_SYSCTL
62883+ grsec_lock = 1;
62884+#endif
62885+
62886+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62887+ grsec_enable_audit_textrel = 1;
62888+#endif
62889+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62890+ grsec_enable_log_rwxmaps = 1;
62891+#endif
62892+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62893+ grsec_enable_group = 1;
62894+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
62895+#endif
62896+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62897+ grsec_enable_chdir = 1;
62898+#endif
62899+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62900+ grsec_enable_harden_ptrace = 1;
62901+#endif
62902+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62903+ grsec_enable_mount = 1;
62904+#endif
62905+#ifdef CONFIG_GRKERNSEC_LINK
62906+ grsec_enable_link = 1;
62907+#endif
62908+#ifdef CONFIG_GRKERNSEC_BRUTE
62909+ grsec_enable_brute = 1;
62910+#endif
62911+#ifdef CONFIG_GRKERNSEC_DMESG
62912+ grsec_enable_dmesg = 1;
62913+#endif
62914+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62915+ grsec_enable_blackhole = 1;
62916+ grsec_lastack_retries = 4;
62917+#endif
62918+#ifdef CONFIG_GRKERNSEC_FIFO
62919+ grsec_enable_fifo = 1;
62920+#endif
62921+#ifdef CONFIG_GRKERNSEC_EXECLOG
62922+ grsec_enable_execlog = 1;
62923+#endif
62924+#ifdef CONFIG_GRKERNSEC_SIGNAL
62925+ grsec_enable_signal = 1;
62926+#endif
62927+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62928+ grsec_enable_forkfail = 1;
62929+#endif
62930+#ifdef CONFIG_GRKERNSEC_TIME
62931+ grsec_enable_time = 1;
62932+#endif
62933+#ifdef CONFIG_GRKERNSEC_RESLOG
62934+ grsec_resource_logging = 1;
62935+#endif
62936+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62937+ grsec_enable_chroot_findtask = 1;
62938+#endif
62939+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62940+ grsec_enable_chroot_unix = 1;
62941+#endif
62942+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62943+ grsec_enable_chroot_mount = 1;
62944+#endif
62945+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62946+ grsec_enable_chroot_fchdir = 1;
62947+#endif
62948+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62949+ grsec_enable_chroot_shmat = 1;
62950+#endif
62951+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62952+ grsec_enable_audit_ptrace = 1;
62953+#endif
62954+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62955+ grsec_enable_chroot_double = 1;
62956+#endif
62957+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62958+ grsec_enable_chroot_pivot = 1;
62959+#endif
62960+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62961+ grsec_enable_chroot_chdir = 1;
62962+#endif
62963+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62964+ grsec_enable_chroot_chmod = 1;
62965+#endif
62966+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62967+ grsec_enable_chroot_mknod = 1;
62968+#endif
62969+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62970+ grsec_enable_chroot_nice = 1;
62971+#endif
62972+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62973+ grsec_enable_chroot_execlog = 1;
62974+#endif
62975+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62976+ grsec_enable_chroot_caps = 1;
62977+#endif
62978+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62979+ grsec_enable_chroot_sysctl = 1;
62980+#endif
62981+#ifdef CONFIG_GRKERNSEC_TPE
62982+ grsec_enable_tpe = 1;
62983+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
62984+#ifdef CONFIG_GRKERNSEC_TPE_ALL
62985+ grsec_enable_tpe_all = 1;
62986+#endif
62987+#endif
62988+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62989+ grsec_enable_socket_all = 1;
62990+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
62991+#endif
62992+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62993+ grsec_enable_socket_client = 1;
62994+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
62995+#endif
62996+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62997+ grsec_enable_socket_server = 1;
62998+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
62999+#endif
63000+#endif
63001+
63002+ return;
63003+}
63004diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
63005new file mode 100644
63006index 0000000..3efe141
63007--- /dev/null
63008+++ b/grsecurity/grsec_link.c
63009@@ -0,0 +1,43 @@
63010+#include <linux/kernel.h>
63011+#include <linux/sched.h>
63012+#include <linux/fs.h>
63013+#include <linux/file.h>
63014+#include <linux/grinternal.h>
63015+
63016+int
63017+gr_handle_follow_link(const struct inode *parent,
63018+ const struct inode *inode,
63019+ const struct dentry *dentry, const struct vfsmount *mnt)
63020+{
63021+#ifdef CONFIG_GRKERNSEC_LINK
63022+ const struct cred *cred = current_cred();
63023+
63024+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
63025+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
63026+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
63027+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
63028+ return -EACCES;
63029+ }
63030+#endif
63031+ return 0;
63032+}
63033+
63034+int
63035+gr_handle_hardlink(const struct dentry *dentry,
63036+ const struct vfsmount *mnt,
63037+ struct inode *inode, const int mode, const char *to)
63038+{
63039+#ifdef CONFIG_GRKERNSEC_LINK
63040+ const struct cred *cred = current_cred();
63041+
63042+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
63043+ (!S_ISREG(mode) || (mode & S_ISUID) ||
63044+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
63045+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
63046+ !capable(CAP_FOWNER) && cred->uid) {
63047+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
63048+ return -EPERM;
63049+ }
63050+#endif
63051+ return 0;
63052+}
63053diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
63054new file mode 100644
63055index 0000000..a45d2e9
63056--- /dev/null
63057+++ b/grsecurity/grsec_log.c
63058@@ -0,0 +1,322 @@
63059+#include <linux/kernel.h>
63060+#include <linux/sched.h>
63061+#include <linux/file.h>
63062+#include <linux/tty.h>
63063+#include <linux/fs.h>
63064+#include <linux/grinternal.h>
63065+
63066+#ifdef CONFIG_TREE_PREEMPT_RCU
63067+#define DISABLE_PREEMPT() preempt_disable()
63068+#define ENABLE_PREEMPT() preempt_enable()
63069+#else
63070+#define DISABLE_PREEMPT()
63071+#define ENABLE_PREEMPT()
63072+#endif
63073+
63074+#define BEGIN_LOCKS(x) \
63075+ DISABLE_PREEMPT(); \
63076+ rcu_read_lock(); \
63077+ read_lock(&tasklist_lock); \
63078+ read_lock(&grsec_exec_file_lock); \
63079+ if (x != GR_DO_AUDIT) \
63080+ spin_lock(&grsec_alert_lock); \
63081+ else \
63082+ spin_lock(&grsec_audit_lock)
63083+
63084+#define END_LOCKS(x) \
63085+ if (x != GR_DO_AUDIT) \
63086+ spin_unlock(&grsec_alert_lock); \
63087+ else \
63088+ spin_unlock(&grsec_audit_lock); \
63089+ read_unlock(&grsec_exec_file_lock); \
63090+ read_unlock(&tasklist_lock); \
63091+ rcu_read_unlock(); \
63092+ ENABLE_PREEMPT(); \
63093+ if (x == GR_DONT_AUDIT) \
63094+ gr_handle_alertkill(current)
63095+
63096+enum {
63097+ FLOODING,
63098+ NO_FLOODING
63099+};
63100+
63101+extern char *gr_alert_log_fmt;
63102+extern char *gr_audit_log_fmt;
63103+extern char *gr_alert_log_buf;
63104+extern char *gr_audit_log_buf;
63105+
63106+static int gr_log_start(int audit)
63107+{
63108+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
63109+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
63110+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63111+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
63112+ unsigned long curr_secs = get_seconds();
63113+
63114+ if (audit == GR_DO_AUDIT)
63115+ goto set_fmt;
63116+
63117+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
63118+ grsec_alert_wtime = curr_secs;
63119+ grsec_alert_fyet = 0;
63120+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
63121+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
63122+ grsec_alert_fyet++;
63123+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
63124+ grsec_alert_wtime = curr_secs;
63125+ grsec_alert_fyet++;
63126+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
63127+ return FLOODING;
63128+ }
63129+ else return FLOODING;
63130+
63131+set_fmt:
63132+#endif
63133+ memset(buf, 0, PAGE_SIZE);
63134+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
63135+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
63136+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
63137+ } else if (current->signal->curr_ip) {
63138+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
63139+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
63140+ } else if (gr_acl_is_enabled()) {
63141+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
63142+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
63143+ } else {
63144+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
63145+ strcpy(buf, fmt);
63146+ }
63147+
63148+ return NO_FLOODING;
63149+}
63150+
63151+static void gr_log_middle(int audit, const char *msg, va_list ap)
63152+ __attribute__ ((format (printf, 2, 0)));
63153+
63154+static void gr_log_middle(int audit, const char *msg, va_list ap)
63155+{
63156+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63157+ unsigned int len = strlen(buf);
63158+
63159+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
63160+
63161+ return;
63162+}
63163+
63164+static void gr_log_middle_varargs(int audit, const char *msg, ...)
63165+ __attribute__ ((format (printf, 2, 3)));
63166+
63167+static void gr_log_middle_varargs(int audit, const char *msg, ...)
63168+{
63169+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63170+ unsigned int len = strlen(buf);
63171+ va_list ap;
63172+
63173+ va_start(ap, msg);
63174+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
63175+ va_end(ap);
63176+
63177+ return;
63178+}
63179+
63180+static void gr_log_end(int audit, int append_default)
63181+{
63182+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63183+
63184+ if (append_default) {
63185+ unsigned int len = strlen(buf);
63186+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
63187+ }
63188+
63189+ printk("%s\n", buf);
63190+
63191+ return;
63192+}
63193+
63194+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
63195+{
63196+ int logtype;
63197+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
63198+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
63199+ void *voidptr = NULL;
63200+ int num1 = 0, num2 = 0;
63201+ unsigned long ulong1 = 0, ulong2 = 0;
63202+ struct dentry *dentry = NULL;
63203+ struct vfsmount *mnt = NULL;
63204+ struct file *file = NULL;
63205+ struct task_struct *task = NULL;
63206+ const struct cred *cred, *pcred;
63207+ va_list ap;
63208+
63209+ BEGIN_LOCKS(audit);
63210+ logtype = gr_log_start(audit);
63211+ if (logtype == FLOODING) {
63212+ END_LOCKS(audit);
63213+ return;
63214+ }
63215+ va_start(ap, argtypes);
63216+ switch (argtypes) {
63217+ case GR_TTYSNIFF:
63218+ task = va_arg(ap, struct task_struct *);
63219+ 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);
63220+ break;
63221+ case GR_SYSCTL_HIDDEN:
63222+ str1 = va_arg(ap, char *);
63223+ gr_log_middle_varargs(audit, msg, result, str1);
63224+ break;
63225+ case GR_RBAC:
63226+ dentry = va_arg(ap, struct dentry *);
63227+ mnt = va_arg(ap, struct vfsmount *);
63228+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
63229+ break;
63230+ case GR_RBAC_STR:
63231+ dentry = va_arg(ap, struct dentry *);
63232+ mnt = va_arg(ap, struct vfsmount *);
63233+ str1 = va_arg(ap, char *);
63234+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
63235+ break;
63236+ case GR_STR_RBAC:
63237+ str1 = va_arg(ap, char *);
63238+ dentry = va_arg(ap, struct dentry *);
63239+ mnt = va_arg(ap, struct vfsmount *);
63240+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
63241+ break;
63242+ case GR_RBAC_MODE2:
63243+ dentry = va_arg(ap, struct dentry *);
63244+ mnt = va_arg(ap, struct vfsmount *);
63245+ str1 = va_arg(ap, char *);
63246+ str2 = va_arg(ap, char *);
63247+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
63248+ break;
63249+ case GR_RBAC_MODE3:
63250+ dentry = va_arg(ap, struct dentry *);
63251+ mnt = va_arg(ap, struct vfsmount *);
63252+ str1 = va_arg(ap, char *);
63253+ str2 = va_arg(ap, char *);
63254+ str3 = va_arg(ap, char *);
63255+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
63256+ break;
63257+ case GR_FILENAME:
63258+ dentry = va_arg(ap, struct dentry *);
63259+ mnt = va_arg(ap, struct vfsmount *);
63260+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
63261+ break;
63262+ case GR_STR_FILENAME:
63263+ str1 = va_arg(ap, char *);
63264+ dentry = va_arg(ap, struct dentry *);
63265+ mnt = va_arg(ap, struct vfsmount *);
63266+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
63267+ break;
63268+ case GR_FILENAME_STR:
63269+ dentry = va_arg(ap, struct dentry *);
63270+ mnt = va_arg(ap, struct vfsmount *);
63271+ str1 = va_arg(ap, char *);
63272+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
63273+ break;
63274+ case GR_FILENAME_TWO_INT:
63275+ dentry = va_arg(ap, struct dentry *);
63276+ mnt = va_arg(ap, struct vfsmount *);
63277+ num1 = va_arg(ap, int);
63278+ num2 = va_arg(ap, int);
63279+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
63280+ break;
63281+ case GR_FILENAME_TWO_INT_STR:
63282+ dentry = va_arg(ap, struct dentry *);
63283+ mnt = va_arg(ap, struct vfsmount *);
63284+ num1 = va_arg(ap, int);
63285+ num2 = va_arg(ap, int);
63286+ str1 = va_arg(ap, char *);
63287+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
63288+ break;
63289+ case GR_TEXTREL:
63290+ file = va_arg(ap, struct file *);
63291+ ulong1 = va_arg(ap, unsigned long);
63292+ ulong2 = va_arg(ap, unsigned long);
63293+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
63294+ break;
63295+ case GR_PTRACE:
63296+ task = va_arg(ap, struct task_struct *);
63297+ 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);
63298+ break;
63299+ case GR_RESOURCE:
63300+ task = va_arg(ap, struct task_struct *);
63301+ cred = __task_cred(task);
63302+ pcred = __task_cred(task->real_parent);
63303+ ulong1 = va_arg(ap, unsigned long);
63304+ str1 = va_arg(ap, char *);
63305+ ulong2 = va_arg(ap, unsigned long);
63306+ 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);
63307+ break;
63308+ case GR_CAP:
63309+ task = va_arg(ap, struct task_struct *);
63310+ cred = __task_cred(task);
63311+ pcred = __task_cred(task->real_parent);
63312+ str1 = va_arg(ap, char *);
63313+ 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);
63314+ break;
63315+ case GR_SIG:
63316+ str1 = va_arg(ap, char *);
63317+ voidptr = va_arg(ap, void *);
63318+ gr_log_middle_varargs(audit, msg, str1, voidptr);
63319+ break;
63320+ case GR_SIG2:
63321+ task = va_arg(ap, struct task_struct *);
63322+ cred = __task_cred(task);
63323+ pcred = __task_cred(task->real_parent);
63324+ num1 = va_arg(ap, int);
63325+ 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);
63326+ break;
63327+ case GR_CRASH1:
63328+ task = va_arg(ap, struct task_struct *);
63329+ cred = __task_cred(task);
63330+ pcred = __task_cred(task->real_parent);
63331+ ulong1 = va_arg(ap, unsigned long);
63332+ 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);
63333+ break;
63334+ case GR_CRASH2:
63335+ task = va_arg(ap, struct task_struct *);
63336+ cred = __task_cred(task);
63337+ pcred = __task_cred(task->real_parent);
63338+ ulong1 = va_arg(ap, unsigned long);
63339+ 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);
63340+ break;
63341+ case GR_RWXMAP:
63342+ file = va_arg(ap, struct file *);
63343+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
63344+ break;
63345+ case GR_PSACCT:
63346+ {
63347+ unsigned int wday, cday;
63348+ __u8 whr, chr;
63349+ __u8 wmin, cmin;
63350+ __u8 wsec, csec;
63351+ char cur_tty[64] = { 0 };
63352+ char parent_tty[64] = { 0 };
63353+
63354+ task = va_arg(ap, struct task_struct *);
63355+ wday = va_arg(ap, unsigned int);
63356+ cday = va_arg(ap, unsigned int);
63357+ whr = va_arg(ap, int);
63358+ chr = va_arg(ap, int);
63359+ wmin = va_arg(ap, int);
63360+ cmin = va_arg(ap, int);
63361+ wsec = va_arg(ap, int);
63362+ csec = va_arg(ap, int);
63363+ ulong1 = va_arg(ap, unsigned long);
63364+ cred = __task_cred(task);
63365+ pcred = __task_cred(task->real_parent);
63366+
63367+ 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);
63368+ }
63369+ break;
63370+ default:
63371+ gr_log_middle(audit, msg, ap);
63372+ }
63373+ va_end(ap);
63374+ // these don't need DEFAULTSECARGS printed on the end
63375+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
63376+ gr_log_end(audit, 0);
63377+ else
63378+ gr_log_end(audit, 1);
63379+ END_LOCKS(audit);
63380+}
63381diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
63382new file mode 100644
63383index 0000000..6c0416b
63384--- /dev/null
63385+++ b/grsecurity/grsec_mem.c
63386@@ -0,0 +1,33 @@
63387+#include <linux/kernel.h>
63388+#include <linux/sched.h>
63389+#include <linux/mm.h>
63390+#include <linux/mman.h>
63391+#include <linux/grinternal.h>
63392+
63393+void
63394+gr_handle_ioperm(void)
63395+{
63396+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
63397+ return;
63398+}
63399+
63400+void
63401+gr_handle_iopl(void)
63402+{
63403+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
63404+ return;
63405+}
63406+
63407+void
63408+gr_handle_mem_readwrite(u64 from, u64 to)
63409+{
63410+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
63411+ return;
63412+}
63413+
63414+void
63415+gr_handle_vm86(void)
63416+{
63417+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
63418+ return;
63419+}
63420diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
63421new file mode 100644
63422index 0000000..2131422
63423--- /dev/null
63424+++ b/grsecurity/grsec_mount.c
63425@@ -0,0 +1,62 @@
63426+#include <linux/kernel.h>
63427+#include <linux/sched.h>
63428+#include <linux/mount.h>
63429+#include <linux/grsecurity.h>
63430+#include <linux/grinternal.h>
63431+
63432+void
63433+gr_log_remount(const char *devname, const int retval)
63434+{
63435+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63436+ if (grsec_enable_mount && (retval >= 0))
63437+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
63438+#endif
63439+ return;
63440+}
63441+
63442+void
63443+gr_log_unmount(const char *devname, const int retval)
63444+{
63445+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63446+ if (grsec_enable_mount && (retval >= 0))
63447+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
63448+#endif
63449+ return;
63450+}
63451+
63452+void
63453+gr_log_mount(const char *from, const char *to, const int retval)
63454+{
63455+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63456+ if (grsec_enable_mount && (retval >= 0))
63457+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
63458+#endif
63459+ return;
63460+}
63461+
63462+int
63463+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
63464+{
63465+#ifdef CONFIG_GRKERNSEC_ROFS
63466+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
63467+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
63468+ return -EPERM;
63469+ } else
63470+ return 0;
63471+#endif
63472+ return 0;
63473+}
63474+
63475+int
63476+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
63477+{
63478+#ifdef CONFIG_GRKERNSEC_ROFS
63479+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
63480+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
63481+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
63482+ return -EPERM;
63483+ } else
63484+ return 0;
63485+#endif
63486+ return 0;
63487+}
63488diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
63489new file mode 100644
63490index 0000000..a3b12a0
63491--- /dev/null
63492+++ b/grsecurity/grsec_pax.c
63493@@ -0,0 +1,36 @@
63494+#include <linux/kernel.h>
63495+#include <linux/sched.h>
63496+#include <linux/mm.h>
63497+#include <linux/file.h>
63498+#include <linux/grinternal.h>
63499+#include <linux/grsecurity.h>
63500+
63501+void
63502+gr_log_textrel(struct vm_area_struct * vma)
63503+{
63504+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63505+ if (grsec_enable_audit_textrel)
63506+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
63507+#endif
63508+ return;
63509+}
63510+
63511+void
63512+gr_log_rwxmmap(struct file *file)
63513+{
63514+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63515+ if (grsec_enable_log_rwxmaps)
63516+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
63517+#endif
63518+ return;
63519+}
63520+
63521+void
63522+gr_log_rwxmprotect(struct file *file)
63523+{
63524+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63525+ if (grsec_enable_log_rwxmaps)
63526+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
63527+#endif
63528+ return;
63529+}
63530diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
63531new file mode 100644
63532index 0000000..472c1d6
63533--- /dev/null
63534+++ b/grsecurity/grsec_ptrace.c
63535@@ -0,0 +1,14 @@
63536+#include <linux/kernel.h>
63537+#include <linux/sched.h>
63538+#include <linux/grinternal.h>
63539+#include <linux/grsecurity.h>
63540+
63541+void
63542+gr_audit_ptrace(struct task_struct *task)
63543+{
63544+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63545+ if (grsec_enable_audit_ptrace)
63546+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
63547+#endif
63548+ return;
63549+}
63550diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
63551new file mode 100644
63552index 0000000..c648492
63553--- /dev/null
63554+++ b/grsecurity/grsec_sig.c
63555@@ -0,0 +1,206 @@
63556+#include <linux/kernel.h>
63557+#include <linux/sched.h>
63558+#include <linux/delay.h>
63559+#include <linux/grsecurity.h>
63560+#include <linux/grinternal.h>
63561+#include <linux/hardirq.h>
63562+
63563+char *signames[] = {
63564+ [SIGSEGV] = "Segmentation fault",
63565+ [SIGILL] = "Illegal instruction",
63566+ [SIGABRT] = "Abort",
63567+ [SIGBUS] = "Invalid alignment/Bus error"
63568+};
63569+
63570+void
63571+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
63572+{
63573+#ifdef CONFIG_GRKERNSEC_SIGNAL
63574+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
63575+ (sig == SIGABRT) || (sig == SIGBUS))) {
63576+ if (t->pid == current->pid) {
63577+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
63578+ } else {
63579+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
63580+ }
63581+ }
63582+#endif
63583+ return;
63584+}
63585+
63586+int
63587+gr_handle_signal(const struct task_struct *p, const int sig)
63588+{
63589+#ifdef CONFIG_GRKERNSEC
63590+ /* ignore the 0 signal for protected task checks */
63591+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
63592+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
63593+ return -EPERM;
63594+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
63595+ return -EPERM;
63596+ }
63597+#endif
63598+ return 0;
63599+}
63600+
63601+#ifdef CONFIG_GRKERNSEC
63602+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
63603+
63604+int gr_fake_force_sig(int sig, struct task_struct *t)
63605+{
63606+ unsigned long int flags;
63607+ int ret, blocked, ignored;
63608+ struct k_sigaction *action;
63609+
63610+ spin_lock_irqsave(&t->sighand->siglock, flags);
63611+ action = &t->sighand->action[sig-1];
63612+ ignored = action->sa.sa_handler == SIG_IGN;
63613+ blocked = sigismember(&t->blocked, sig);
63614+ if (blocked || ignored) {
63615+ action->sa.sa_handler = SIG_DFL;
63616+ if (blocked) {
63617+ sigdelset(&t->blocked, sig);
63618+ recalc_sigpending_and_wake(t);
63619+ }
63620+ }
63621+ if (action->sa.sa_handler == SIG_DFL)
63622+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
63623+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
63624+
63625+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
63626+
63627+ return ret;
63628+}
63629+#endif
63630+
63631+#ifdef CONFIG_GRKERNSEC_BRUTE
63632+#define GR_USER_BAN_TIME (15 * 60)
63633+
63634+static int __get_dumpable(unsigned long mm_flags)
63635+{
63636+ int ret;
63637+
63638+ ret = mm_flags & MMF_DUMPABLE_MASK;
63639+ return (ret >= 2) ? 2 : ret;
63640+}
63641+#endif
63642+
63643+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
63644+{
63645+#ifdef CONFIG_GRKERNSEC_BRUTE
63646+ uid_t uid = 0;
63647+
63648+ if (!grsec_enable_brute)
63649+ return;
63650+
63651+ rcu_read_lock();
63652+ read_lock(&tasklist_lock);
63653+ read_lock(&grsec_exec_file_lock);
63654+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
63655+ p->real_parent->brute = 1;
63656+ else {
63657+ const struct cred *cred = __task_cred(p), *cred2;
63658+ struct task_struct *tsk, *tsk2;
63659+
63660+ if (!__get_dumpable(mm_flags) && cred->uid) {
63661+ struct user_struct *user;
63662+
63663+ uid = cred->uid;
63664+
63665+ /* this is put upon execution past expiration */
63666+ user = find_user(uid);
63667+ if (user == NULL)
63668+ goto unlock;
63669+ user->banned = 1;
63670+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
63671+ if (user->ban_expires == ~0UL)
63672+ user->ban_expires--;
63673+
63674+ do_each_thread(tsk2, tsk) {
63675+ cred2 = __task_cred(tsk);
63676+ if (tsk != p && cred2->uid == uid)
63677+ gr_fake_force_sig(SIGKILL, tsk);
63678+ } while_each_thread(tsk2, tsk);
63679+ }
63680+ }
63681+unlock:
63682+ read_unlock(&grsec_exec_file_lock);
63683+ read_unlock(&tasklist_lock);
63684+ rcu_read_unlock();
63685+
63686+ if (uid)
63687+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
63688+#endif
63689+ return;
63690+}
63691+
63692+void gr_handle_brute_check(void)
63693+{
63694+#ifdef CONFIG_GRKERNSEC_BRUTE
63695+ if (current->brute)
63696+ msleep(30 * 1000);
63697+#endif
63698+ return;
63699+}
63700+
63701+void gr_handle_kernel_exploit(void)
63702+{
63703+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
63704+ const struct cred *cred;
63705+ struct task_struct *tsk, *tsk2;
63706+ struct user_struct *user;
63707+ uid_t uid;
63708+
63709+ if (in_irq() || in_serving_softirq() || in_nmi())
63710+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
63711+
63712+ uid = current_uid();
63713+
63714+ if (uid == 0)
63715+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
63716+ else {
63717+ /* kill all the processes of this user, hold a reference
63718+ to their creds struct, and prevent them from creating
63719+ another process until system reset
63720+ */
63721+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
63722+ /* we intentionally leak this ref */
63723+ user = get_uid(current->cred->user);
63724+ if (user) {
63725+ user->banned = 1;
63726+ user->ban_expires = ~0UL;
63727+ }
63728+
63729+ read_lock(&tasklist_lock);
63730+ do_each_thread(tsk2, tsk) {
63731+ cred = __task_cred(tsk);
63732+ if (cred->uid == uid)
63733+ gr_fake_force_sig(SIGKILL, tsk);
63734+ } while_each_thread(tsk2, tsk);
63735+ read_unlock(&tasklist_lock);
63736+ }
63737+#endif
63738+}
63739+
63740+int __gr_process_user_ban(struct user_struct *user)
63741+{
63742+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63743+ if (unlikely(user->banned)) {
63744+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
63745+ user->banned = 0;
63746+ user->ban_expires = 0;
63747+ free_uid(user);
63748+ } else
63749+ return -EPERM;
63750+ }
63751+#endif
63752+ return 0;
63753+}
63754+
63755+int gr_process_user_ban(void)
63756+{
63757+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63758+ return __gr_process_user_ban(current->cred->user);
63759+#endif
63760+ return 0;
63761+}
63762diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
63763new file mode 100644
63764index 0000000..7512ea9
63765--- /dev/null
63766+++ b/grsecurity/grsec_sock.c
63767@@ -0,0 +1,275 @@
63768+#include <linux/kernel.h>
63769+#include <linux/module.h>
63770+#include <linux/sched.h>
63771+#include <linux/file.h>
63772+#include <linux/net.h>
63773+#include <linux/in.h>
63774+#include <linux/ip.h>
63775+#include <net/sock.h>
63776+#include <net/inet_sock.h>
63777+#include <linux/grsecurity.h>
63778+#include <linux/grinternal.h>
63779+#include <linux/gracl.h>
63780+
63781+kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
63782+EXPORT_SYMBOL(gr_cap_rtnetlink);
63783+
63784+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
63785+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
63786+
63787+EXPORT_SYMBOL(gr_search_udp_recvmsg);
63788+EXPORT_SYMBOL(gr_search_udp_sendmsg);
63789+
63790+#ifdef CONFIG_UNIX_MODULE
63791+EXPORT_SYMBOL(gr_acl_handle_unix);
63792+EXPORT_SYMBOL(gr_acl_handle_mknod);
63793+EXPORT_SYMBOL(gr_handle_chroot_unix);
63794+EXPORT_SYMBOL(gr_handle_create);
63795+#endif
63796+
63797+#ifdef CONFIG_GRKERNSEC
63798+#define gr_conn_table_size 32749
63799+struct conn_table_entry {
63800+ struct conn_table_entry *next;
63801+ struct signal_struct *sig;
63802+};
63803+
63804+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
63805+DEFINE_SPINLOCK(gr_conn_table_lock);
63806+
63807+extern const char * gr_socktype_to_name(unsigned char type);
63808+extern const char * gr_proto_to_name(unsigned char proto);
63809+extern const char * gr_sockfamily_to_name(unsigned char family);
63810+
63811+static __inline__ int
63812+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
63813+{
63814+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
63815+}
63816+
63817+static __inline__ int
63818+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
63819+ __u16 sport, __u16 dport)
63820+{
63821+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
63822+ sig->gr_sport == sport && sig->gr_dport == dport))
63823+ return 1;
63824+ else
63825+ return 0;
63826+}
63827+
63828+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
63829+{
63830+ struct conn_table_entry **match;
63831+ unsigned int index;
63832+
63833+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
63834+ sig->gr_sport, sig->gr_dport,
63835+ gr_conn_table_size);
63836+
63837+ newent->sig = sig;
63838+
63839+ match = &gr_conn_table[index];
63840+ newent->next = *match;
63841+ *match = newent;
63842+
63843+ return;
63844+}
63845+
63846+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
63847+{
63848+ struct conn_table_entry *match, *last = NULL;
63849+ unsigned int index;
63850+
63851+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
63852+ sig->gr_sport, sig->gr_dport,
63853+ gr_conn_table_size);
63854+
63855+ match = gr_conn_table[index];
63856+ while (match && !conn_match(match->sig,
63857+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
63858+ sig->gr_dport)) {
63859+ last = match;
63860+ match = match->next;
63861+ }
63862+
63863+ if (match) {
63864+ if (last)
63865+ last->next = match->next;
63866+ else
63867+ gr_conn_table[index] = NULL;
63868+ kfree(match);
63869+ }
63870+
63871+ return;
63872+}
63873+
63874+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
63875+ __u16 sport, __u16 dport)
63876+{
63877+ struct conn_table_entry *match;
63878+ unsigned int index;
63879+
63880+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
63881+
63882+ match = gr_conn_table[index];
63883+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
63884+ match = match->next;
63885+
63886+ if (match)
63887+ return match->sig;
63888+ else
63889+ return NULL;
63890+}
63891+
63892+#endif
63893+
63894+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
63895+{
63896+#ifdef CONFIG_GRKERNSEC
63897+ struct signal_struct *sig = task->signal;
63898+ struct conn_table_entry *newent;
63899+
63900+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
63901+ if (newent == NULL)
63902+ return;
63903+ /* no bh lock needed since we are called with bh disabled */
63904+ spin_lock(&gr_conn_table_lock);
63905+ gr_del_task_from_ip_table_nolock(sig);
63906+ sig->gr_saddr = inet->rcv_saddr;
63907+ sig->gr_daddr = inet->daddr;
63908+ sig->gr_sport = inet->sport;
63909+ sig->gr_dport = inet->dport;
63910+ gr_add_to_task_ip_table_nolock(sig, newent);
63911+ spin_unlock(&gr_conn_table_lock);
63912+#endif
63913+ return;
63914+}
63915+
63916+void gr_del_task_from_ip_table(struct task_struct *task)
63917+{
63918+#ifdef CONFIG_GRKERNSEC
63919+ spin_lock_bh(&gr_conn_table_lock);
63920+ gr_del_task_from_ip_table_nolock(task->signal);
63921+ spin_unlock_bh(&gr_conn_table_lock);
63922+#endif
63923+ return;
63924+}
63925+
63926+void
63927+gr_attach_curr_ip(const struct sock *sk)
63928+{
63929+#ifdef CONFIG_GRKERNSEC
63930+ struct signal_struct *p, *set;
63931+ const struct inet_sock *inet = inet_sk(sk);
63932+
63933+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
63934+ return;
63935+
63936+ set = current->signal;
63937+
63938+ spin_lock_bh(&gr_conn_table_lock);
63939+ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
63940+ inet->dport, inet->sport);
63941+ if (unlikely(p != NULL)) {
63942+ set->curr_ip = p->curr_ip;
63943+ set->used_accept = 1;
63944+ gr_del_task_from_ip_table_nolock(p);
63945+ spin_unlock_bh(&gr_conn_table_lock);
63946+ return;
63947+ }
63948+ spin_unlock_bh(&gr_conn_table_lock);
63949+
63950+ set->curr_ip = inet->daddr;
63951+ set->used_accept = 1;
63952+#endif
63953+ return;
63954+}
63955+
63956+int
63957+gr_handle_sock_all(const int family, const int type, const int protocol)
63958+{
63959+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63960+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
63961+ (family != AF_UNIX)) {
63962+ if (family == AF_INET)
63963+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
63964+ else
63965+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
63966+ return -EACCES;
63967+ }
63968+#endif
63969+ return 0;
63970+}
63971+
63972+int
63973+gr_handle_sock_server(const struct sockaddr *sck)
63974+{
63975+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63976+ if (grsec_enable_socket_server &&
63977+ in_group_p(grsec_socket_server_gid) &&
63978+ sck && (sck->sa_family != AF_UNIX) &&
63979+ (sck->sa_family != AF_LOCAL)) {
63980+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
63981+ return -EACCES;
63982+ }
63983+#endif
63984+ return 0;
63985+}
63986+
63987+int
63988+gr_handle_sock_server_other(const struct sock *sck)
63989+{
63990+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63991+ if (grsec_enable_socket_server &&
63992+ in_group_p(grsec_socket_server_gid) &&
63993+ sck && (sck->sk_family != AF_UNIX) &&
63994+ (sck->sk_family != AF_LOCAL)) {
63995+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
63996+ return -EACCES;
63997+ }
63998+#endif
63999+ return 0;
64000+}
64001+
64002+int
64003+gr_handle_sock_client(const struct sockaddr *sck)
64004+{
64005+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64006+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
64007+ sck && (sck->sa_family != AF_UNIX) &&
64008+ (sck->sa_family != AF_LOCAL)) {
64009+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
64010+ return -EACCES;
64011+ }
64012+#endif
64013+ return 0;
64014+}
64015+
64016+kernel_cap_t
64017+gr_cap_rtnetlink(struct sock *sock)
64018+{
64019+#ifdef CONFIG_GRKERNSEC
64020+ if (!gr_acl_is_enabled())
64021+ return current_cap();
64022+ else if (sock->sk_protocol == NETLINK_ISCSI &&
64023+ cap_raised(current_cap(), CAP_SYS_ADMIN) &&
64024+ gr_is_capable(CAP_SYS_ADMIN))
64025+ return current_cap();
64026+ else if (sock->sk_protocol == NETLINK_AUDIT &&
64027+ cap_raised(current_cap(), CAP_AUDIT_WRITE) &&
64028+ gr_is_capable(CAP_AUDIT_WRITE) &&
64029+ cap_raised(current_cap(), CAP_AUDIT_CONTROL) &&
64030+ gr_is_capable(CAP_AUDIT_CONTROL))
64031+ return current_cap();
64032+ else if (cap_raised(current_cap(), CAP_NET_ADMIN) &&
64033+ ((sock->sk_protocol == NETLINK_ROUTE) ?
64034+ gr_is_capable_nolog(CAP_NET_ADMIN) :
64035+ gr_is_capable(CAP_NET_ADMIN)))
64036+ return current_cap();
64037+ else
64038+ return __cap_empty_set;
64039+#else
64040+ return current_cap();
64041+#endif
64042+}
64043diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
64044new file mode 100644
64045index 0000000..2753505
64046--- /dev/null
64047+++ b/grsecurity/grsec_sysctl.c
64048@@ -0,0 +1,479 @@
64049+#include <linux/kernel.h>
64050+#include <linux/sched.h>
64051+#include <linux/sysctl.h>
64052+#include <linux/grsecurity.h>
64053+#include <linux/grinternal.h>
64054+
64055+int
64056+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
64057+{
64058+#ifdef CONFIG_GRKERNSEC_SYSCTL
64059+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
64060+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
64061+ return -EACCES;
64062+ }
64063+#endif
64064+ return 0;
64065+}
64066+
64067+#ifdef CONFIG_GRKERNSEC_ROFS
64068+static int __maybe_unused one = 1;
64069+#endif
64070+
64071+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
64072+ctl_table grsecurity_table[] = {
64073+#ifdef CONFIG_GRKERNSEC_SYSCTL
64074+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
64075+#ifdef CONFIG_GRKERNSEC_IO
64076+ {
64077+ .ctl_name = CTL_UNNUMBERED,
64078+ .procname = "disable_priv_io",
64079+ .data = &grsec_disable_privio,
64080+ .maxlen = sizeof(int),
64081+ .mode = 0600,
64082+ .proc_handler = &proc_dointvec,
64083+ },
64084+#endif
64085+#endif
64086+#ifdef CONFIG_GRKERNSEC_LINK
64087+ {
64088+ .ctl_name = CTL_UNNUMBERED,
64089+ .procname = "linking_restrictions",
64090+ .data = &grsec_enable_link,
64091+ .maxlen = sizeof(int),
64092+ .mode = 0600,
64093+ .proc_handler = &proc_dointvec,
64094+ },
64095+#endif
64096+#ifdef CONFIG_GRKERNSEC_BRUTE
64097+ {
64098+ .ctl_name = CTL_UNNUMBERED,
64099+ .procname = "deter_bruteforce",
64100+ .data = &grsec_enable_brute,
64101+ .maxlen = sizeof(int),
64102+ .mode = 0600,
64103+ .proc_handler = &proc_dointvec,
64104+ },
64105+#endif
64106+#ifdef CONFIG_GRKERNSEC_FIFO
64107+ {
64108+ .ctl_name = CTL_UNNUMBERED,
64109+ .procname = "fifo_restrictions",
64110+ .data = &grsec_enable_fifo,
64111+ .maxlen = sizeof(int),
64112+ .mode = 0600,
64113+ .proc_handler = &proc_dointvec,
64114+ },
64115+#endif
64116+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
64117+ {
64118+ .ctl_name = CTL_UNNUMBERED,
64119+ .procname = "ip_blackhole",
64120+ .data = &grsec_enable_blackhole,
64121+ .maxlen = sizeof(int),
64122+ .mode = 0600,
64123+ .proc_handler = &proc_dointvec,
64124+ },
64125+ {
64126+ .ctl_name = CTL_UNNUMBERED,
64127+ .procname = "lastack_retries",
64128+ .data = &grsec_lastack_retries,
64129+ .maxlen = sizeof(int),
64130+ .mode = 0600,
64131+ .proc_handler = &proc_dointvec,
64132+ },
64133+#endif
64134+#ifdef CONFIG_GRKERNSEC_EXECLOG
64135+ {
64136+ .ctl_name = CTL_UNNUMBERED,
64137+ .procname = "exec_logging",
64138+ .data = &grsec_enable_execlog,
64139+ .maxlen = sizeof(int),
64140+ .mode = 0600,
64141+ .proc_handler = &proc_dointvec,
64142+ },
64143+#endif
64144+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64145+ {
64146+ .ctl_name = CTL_UNNUMBERED,
64147+ .procname = "rwxmap_logging",
64148+ .data = &grsec_enable_log_rwxmaps,
64149+ .maxlen = sizeof(int),
64150+ .mode = 0600,
64151+ .proc_handler = &proc_dointvec,
64152+ },
64153+#endif
64154+#ifdef CONFIG_GRKERNSEC_SIGNAL
64155+ {
64156+ .ctl_name = CTL_UNNUMBERED,
64157+ .procname = "signal_logging",
64158+ .data = &grsec_enable_signal,
64159+ .maxlen = sizeof(int),
64160+ .mode = 0600,
64161+ .proc_handler = &proc_dointvec,
64162+ },
64163+#endif
64164+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64165+ {
64166+ .ctl_name = CTL_UNNUMBERED,
64167+ .procname = "forkfail_logging",
64168+ .data = &grsec_enable_forkfail,
64169+ .maxlen = sizeof(int),
64170+ .mode = 0600,
64171+ .proc_handler = &proc_dointvec,
64172+ },
64173+#endif
64174+#ifdef CONFIG_GRKERNSEC_TIME
64175+ {
64176+ .ctl_name = CTL_UNNUMBERED,
64177+ .procname = "timechange_logging",
64178+ .data = &grsec_enable_time,
64179+ .maxlen = sizeof(int),
64180+ .mode = 0600,
64181+ .proc_handler = &proc_dointvec,
64182+ },
64183+#endif
64184+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64185+ {
64186+ .ctl_name = CTL_UNNUMBERED,
64187+ .procname = "chroot_deny_shmat",
64188+ .data = &grsec_enable_chroot_shmat,
64189+ .maxlen = sizeof(int),
64190+ .mode = 0600,
64191+ .proc_handler = &proc_dointvec,
64192+ },
64193+#endif
64194+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64195+ {
64196+ .ctl_name = CTL_UNNUMBERED,
64197+ .procname = "chroot_deny_unix",
64198+ .data = &grsec_enable_chroot_unix,
64199+ .maxlen = sizeof(int),
64200+ .mode = 0600,
64201+ .proc_handler = &proc_dointvec,
64202+ },
64203+#endif
64204+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64205+ {
64206+ .ctl_name = CTL_UNNUMBERED,
64207+ .procname = "chroot_deny_mount",
64208+ .data = &grsec_enable_chroot_mount,
64209+ .maxlen = sizeof(int),
64210+ .mode = 0600,
64211+ .proc_handler = &proc_dointvec,
64212+ },
64213+#endif
64214+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64215+ {
64216+ .ctl_name = CTL_UNNUMBERED,
64217+ .procname = "chroot_deny_fchdir",
64218+ .data = &grsec_enable_chroot_fchdir,
64219+ .maxlen = sizeof(int),
64220+ .mode = 0600,
64221+ .proc_handler = &proc_dointvec,
64222+ },
64223+#endif
64224+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64225+ {
64226+ .ctl_name = CTL_UNNUMBERED,
64227+ .procname = "chroot_deny_chroot",
64228+ .data = &grsec_enable_chroot_double,
64229+ .maxlen = sizeof(int),
64230+ .mode = 0600,
64231+ .proc_handler = &proc_dointvec,
64232+ },
64233+#endif
64234+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64235+ {
64236+ .ctl_name = CTL_UNNUMBERED,
64237+ .procname = "chroot_deny_pivot",
64238+ .data = &grsec_enable_chroot_pivot,
64239+ .maxlen = sizeof(int),
64240+ .mode = 0600,
64241+ .proc_handler = &proc_dointvec,
64242+ },
64243+#endif
64244+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64245+ {
64246+ .ctl_name = CTL_UNNUMBERED,
64247+ .procname = "chroot_enforce_chdir",
64248+ .data = &grsec_enable_chroot_chdir,
64249+ .maxlen = sizeof(int),
64250+ .mode = 0600,
64251+ .proc_handler = &proc_dointvec,
64252+ },
64253+#endif
64254+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64255+ {
64256+ .ctl_name = CTL_UNNUMBERED,
64257+ .procname = "chroot_deny_chmod",
64258+ .data = &grsec_enable_chroot_chmod,
64259+ .maxlen = sizeof(int),
64260+ .mode = 0600,
64261+ .proc_handler = &proc_dointvec,
64262+ },
64263+#endif
64264+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64265+ {
64266+ .ctl_name = CTL_UNNUMBERED,
64267+ .procname = "chroot_deny_mknod",
64268+ .data = &grsec_enable_chroot_mknod,
64269+ .maxlen = sizeof(int),
64270+ .mode = 0600,
64271+ .proc_handler = &proc_dointvec,
64272+ },
64273+#endif
64274+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64275+ {
64276+ .ctl_name = CTL_UNNUMBERED,
64277+ .procname = "chroot_restrict_nice",
64278+ .data = &grsec_enable_chroot_nice,
64279+ .maxlen = sizeof(int),
64280+ .mode = 0600,
64281+ .proc_handler = &proc_dointvec,
64282+ },
64283+#endif
64284+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64285+ {
64286+ .ctl_name = CTL_UNNUMBERED,
64287+ .procname = "chroot_execlog",
64288+ .data = &grsec_enable_chroot_execlog,
64289+ .maxlen = sizeof(int),
64290+ .mode = 0600,
64291+ .proc_handler = &proc_dointvec,
64292+ },
64293+#endif
64294+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64295+ {
64296+ .ctl_name = CTL_UNNUMBERED,
64297+ .procname = "chroot_caps",
64298+ .data = &grsec_enable_chroot_caps,
64299+ .maxlen = sizeof(int),
64300+ .mode = 0600,
64301+ .proc_handler = &proc_dointvec,
64302+ },
64303+#endif
64304+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64305+ {
64306+ .ctl_name = CTL_UNNUMBERED,
64307+ .procname = "chroot_deny_sysctl",
64308+ .data = &grsec_enable_chroot_sysctl,
64309+ .maxlen = sizeof(int),
64310+ .mode = 0600,
64311+ .proc_handler = &proc_dointvec,
64312+ },
64313+#endif
64314+#ifdef CONFIG_GRKERNSEC_TPE
64315+ {
64316+ .ctl_name = CTL_UNNUMBERED,
64317+ .procname = "tpe",
64318+ .data = &grsec_enable_tpe,
64319+ .maxlen = sizeof(int),
64320+ .mode = 0600,
64321+ .proc_handler = &proc_dointvec,
64322+ },
64323+ {
64324+ .ctl_name = CTL_UNNUMBERED,
64325+ .procname = "tpe_gid",
64326+ .data = &grsec_tpe_gid,
64327+ .maxlen = sizeof(int),
64328+ .mode = 0600,
64329+ .proc_handler = &proc_dointvec,
64330+ },
64331+#endif
64332+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64333+ {
64334+ .ctl_name = CTL_UNNUMBERED,
64335+ .procname = "tpe_invert",
64336+ .data = &grsec_enable_tpe_invert,
64337+ .maxlen = sizeof(int),
64338+ .mode = 0600,
64339+ .proc_handler = &proc_dointvec,
64340+ },
64341+#endif
64342+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64343+ {
64344+ .ctl_name = CTL_UNNUMBERED,
64345+ .procname = "tpe_restrict_all",
64346+ .data = &grsec_enable_tpe_all,
64347+ .maxlen = sizeof(int),
64348+ .mode = 0600,
64349+ .proc_handler = &proc_dointvec,
64350+ },
64351+#endif
64352+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64353+ {
64354+ .ctl_name = CTL_UNNUMBERED,
64355+ .procname = "socket_all",
64356+ .data = &grsec_enable_socket_all,
64357+ .maxlen = sizeof(int),
64358+ .mode = 0600,
64359+ .proc_handler = &proc_dointvec,
64360+ },
64361+ {
64362+ .ctl_name = CTL_UNNUMBERED,
64363+ .procname = "socket_all_gid",
64364+ .data = &grsec_socket_all_gid,
64365+ .maxlen = sizeof(int),
64366+ .mode = 0600,
64367+ .proc_handler = &proc_dointvec,
64368+ },
64369+#endif
64370+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64371+ {
64372+ .ctl_name = CTL_UNNUMBERED,
64373+ .procname = "socket_client",
64374+ .data = &grsec_enable_socket_client,
64375+ .maxlen = sizeof(int),
64376+ .mode = 0600,
64377+ .proc_handler = &proc_dointvec,
64378+ },
64379+ {
64380+ .ctl_name = CTL_UNNUMBERED,
64381+ .procname = "socket_client_gid",
64382+ .data = &grsec_socket_client_gid,
64383+ .maxlen = sizeof(int),
64384+ .mode = 0600,
64385+ .proc_handler = &proc_dointvec,
64386+ },
64387+#endif
64388+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64389+ {
64390+ .ctl_name = CTL_UNNUMBERED,
64391+ .procname = "socket_server",
64392+ .data = &grsec_enable_socket_server,
64393+ .maxlen = sizeof(int),
64394+ .mode = 0600,
64395+ .proc_handler = &proc_dointvec,
64396+ },
64397+ {
64398+ .ctl_name = CTL_UNNUMBERED,
64399+ .procname = "socket_server_gid",
64400+ .data = &grsec_socket_server_gid,
64401+ .maxlen = sizeof(int),
64402+ .mode = 0600,
64403+ .proc_handler = &proc_dointvec,
64404+ },
64405+#endif
64406+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
64407+ {
64408+ .ctl_name = CTL_UNNUMBERED,
64409+ .procname = "audit_group",
64410+ .data = &grsec_enable_group,
64411+ .maxlen = sizeof(int),
64412+ .mode = 0600,
64413+ .proc_handler = &proc_dointvec,
64414+ },
64415+ {
64416+ .ctl_name = CTL_UNNUMBERED,
64417+ .procname = "audit_gid",
64418+ .data = &grsec_audit_gid,
64419+ .maxlen = sizeof(int),
64420+ .mode = 0600,
64421+ .proc_handler = &proc_dointvec,
64422+ },
64423+#endif
64424+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64425+ {
64426+ .ctl_name = CTL_UNNUMBERED,
64427+ .procname = "audit_chdir",
64428+ .data = &grsec_enable_chdir,
64429+ .maxlen = sizeof(int),
64430+ .mode = 0600,
64431+ .proc_handler = &proc_dointvec,
64432+ },
64433+#endif
64434+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64435+ {
64436+ .ctl_name = CTL_UNNUMBERED,
64437+ .procname = "audit_mount",
64438+ .data = &grsec_enable_mount,
64439+ .maxlen = sizeof(int),
64440+ .mode = 0600,
64441+ .proc_handler = &proc_dointvec,
64442+ },
64443+#endif
64444+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64445+ {
64446+ .ctl_name = CTL_UNNUMBERED,
64447+ .procname = "audit_textrel",
64448+ .data = &grsec_enable_audit_textrel,
64449+ .maxlen = sizeof(int),
64450+ .mode = 0600,
64451+ .proc_handler = &proc_dointvec,
64452+ },
64453+#endif
64454+#ifdef CONFIG_GRKERNSEC_DMESG
64455+ {
64456+ .ctl_name = CTL_UNNUMBERED,
64457+ .procname = "dmesg",
64458+ .data = &grsec_enable_dmesg,
64459+ .maxlen = sizeof(int),
64460+ .mode = 0600,
64461+ .proc_handler = &proc_dointvec,
64462+ },
64463+#endif
64464+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64465+ {
64466+ .ctl_name = CTL_UNNUMBERED,
64467+ .procname = "chroot_findtask",
64468+ .data = &grsec_enable_chroot_findtask,
64469+ .maxlen = sizeof(int),
64470+ .mode = 0600,
64471+ .proc_handler = &proc_dointvec,
64472+ },
64473+#endif
64474+#ifdef CONFIG_GRKERNSEC_RESLOG
64475+ {
64476+ .ctl_name = CTL_UNNUMBERED,
64477+ .procname = "resource_logging",
64478+ .data = &grsec_resource_logging,
64479+ .maxlen = sizeof(int),
64480+ .mode = 0600,
64481+ .proc_handler = &proc_dointvec,
64482+ },
64483+#endif
64484+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64485+ {
64486+ .ctl_name = CTL_UNNUMBERED,
64487+ .procname = "audit_ptrace",
64488+ .data = &grsec_enable_audit_ptrace,
64489+ .maxlen = sizeof(int),
64490+ .mode = 0600,
64491+ .proc_handler = &proc_dointvec,
64492+ },
64493+#endif
64494+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64495+ {
64496+ .ctl_name = CTL_UNNUMBERED,
64497+ .procname = "harden_ptrace",
64498+ .data = &grsec_enable_harden_ptrace,
64499+ .maxlen = sizeof(int),
64500+ .mode = 0600,
64501+ .proc_handler = &proc_dointvec,
64502+ },
64503+#endif
64504+ {
64505+ .ctl_name = CTL_UNNUMBERED,
64506+ .procname = "grsec_lock",
64507+ .data = &grsec_lock,
64508+ .maxlen = sizeof(int),
64509+ .mode = 0600,
64510+ .proc_handler = &proc_dointvec,
64511+ },
64512+#endif
64513+#ifdef CONFIG_GRKERNSEC_ROFS
64514+ {
64515+ .ctl_name = CTL_UNNUMBERED,
64516+ .procname = "romount_protect",
64517+ .data = &grsec_enable_rofs,
64518+ .maxlen = sizeof(int),
64519+ .mode = 0600,
64520+ .proc_handler = &proc_dointvec_minmax,
64521+ .extra1 = &one,
64522+ .extra2 = &one,
64523+ },
64524+#endif
64525+ { .ctl_name = 0 }
64526+};
64527+#endif
64528diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
64529new file mode 100644
64530index 0000000..0dc13c3
64531--- /dev/null
64532+++ b/grsecurity/grsec_time.c
64533@@ -0,0 +1,16 @@
64534+#include <linux/kernel.h>
64535+#include <linux/sched.h>
64536+#include <linux/grinternal.h>
64537+#include <linux/module.h>
64538+
64539+void
64540+gr_log_timechange(void)
64541+{
64542+#ifdef CONFIG_GRKERNSEC_TIME
64543+ if (grsec_enable_time)
64544+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
64545+#endif
64546+ return;
64547+}
64548+
64549+EXPORT_SYMBOL(gr_log_timechange);
64550diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
64551new file mode 100644
64552index 0000000..4a78774
64553--- /dev/null
64554+++ b/grsecurity/grsec_tpe.c
64555@@ -0,0 +1,39 @@
64556+#include <linux/kernel.h>
64557+#include <linux/sched.h>
64558+#include <linux/file.h>
64559+#include <linux/fs.h>
64560+#include <linux/grinternal.h>
64561+
64562+extern int gr_acl_tpe_check(void);
64563+
64564+int
64565+gr_tpe_allow(const struct file *file)
64566+{
64567+#ifdef CONFIG_GRKERNSEC
64568+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
64569+ const struct cred *cred = current_cred();
64570+
64571+ if (cred->uid && ((grsec_enable_tpe &&
64572+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64573+ ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
64574+ (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
64575+#else
64576+ in_group_p(grsec_tpe_gid)
64577+#endif
64578+ ) || gr_acl_tpe_check()) &&
64579+ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
64580+ (inode->i_mode & S_IWOTH))))) {
64581+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
64582+ return 0;
64583+ }
64584+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64585+ if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
64586+ ((inode->i_uid && (inode->i_uid != cred->uid)) ||
64587+ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
64588+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
64589+ return 0;
64590+ }
64591+#endif
64592+#endif
64593+ return 1;
64594+}
64595diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
64596new file mode 100644
64597index 0000000..9f7b1ac
64598--- /dev/null
64599+++ b/grsecurity/grsum.c
64600@@ -0,0 +1,61 @@
64601+#include <linux/err.h>
64602+#include <linux/kernel.h>
64603+#include <linux/sched.h>
64604+#include <linux/mm.h>
64605+#include <linux/scatterlist.h>
64606+#include <linux/crypto.h>
64607+#include <linux/gracl.h>
64608+
64609+
64610+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
64611+#error "crypto and sha256 must be built into the kernel"
64612+#endif
64613+
64614+int
64615+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
64616+{
64617+ char *p;
64618+ struct crypto_hash *tfm;
64619+ struct hash_desc desc;
64620+ struct scatterlist sg;
64621+ unsigned char temp_sum[GR_SHA_LEN];
64622+ volatile int retval = 0;
64623+ volatile int dummy = 0;
64624+ unsigned int i;
64625+
64626+ sg_init_table(&sg, 1);
64627+
64628+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
64629+ if (IS_ERR(tfm)) {
64630+ /* should never happen, since sha256 should be built in */
64631+ return 1;
64632+ }
64633+
64634+ desc.tfm = tfm;
64635+ desc.flags = 0;
64636+
64637+ crypto_hash_init(&desc);
64638+
64639+ p = salt;
64640+ sg_set_buf(&sg, p, GR_SALT_LEN);
64641+ crypto_hash_update(&desc, &sg, sg.length);
64642+
64643+ p = entry->pw;
64644+ sg_set_buf(&sg, p, strlen(p));
64645+
64646+ crypto_hash_update(&desc, &sg, sg.length);
64647+
64648+ crypto_hash_final(&desc, temp_sum);
64649+
64650+ memset(entry->pw, 0, GR_PW_LEN);
64651+
64652+ for (i = 0; i < GR_SHA_LEN; i++)
64653+ if (sum[i] != temp_sum[i])
64654+ retval = 1;
64655+ else
64656+ dummy = 1; // waste a cycle
64657+
64658+ crypto_free_hash(tfm);
64659+
64660+ return retval;
64661+}
64662diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
64663index 3cd9ccd..fe16d47 100644
64664--- a/include/acpi/acpi_bus.h
64665+++ b/include/acpi/acpi_bus.h
64666@@ -107,7 +107,7 @@ struct acpi_device_ops {
64667 acpi_op_bind bind;
64668 acpi_op_unbind unbind;
64669 acpi_op_notify notify;
64670-};
64671+} __no_const;
64672
64673 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
64674
64675diff --git a/include/acpi/acpi_drivers.h b/include/acpi/acpi_drivers.h
64676index f4906f6..71feb73 100644
64677--- a/include/acpi/acpi_drivers.h
64678+++ b/include/acpi/acpi_drivers.h
64679@@ -119,8 +119,8 @@ int acpi_processor_set_thermal_limit(acpi_handle handle, int type);
64680 Dock Station
64681 -------------------------------------------------------------------------- */
64682 struct acpi_dock_ops {
64683- acpi_notify_handler handler;
64684- acpi_notify_handler uevent;
64685+ const acpi_notify_handler handler;
64686+ const acpi_notify_handler uevent;
64687 };
64688
64689 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
64690@@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle handle);
64691 extern int register_dock_notifier(struct notifier_block *nb);
64692 extern void unregister_dock_notifier(struct notifier_block *nb);
64693 extern int register_hotplug_dock_device(acpi_handle handle,
64694- struct acpi_dock_ops *ops,
64695+ const struct acpi_dock_ops *ops,
64696 void *context);
64697 extern void unregister_hotplug_dock_device(acpi_handle handle);
64698 #else
64699@@ -144,7 +144,7 @@ static inline void unregister_dock_notifier(struct notifier_block *nb)
64700 {
64701 }
64702 static inline int register_hotplug_dock_device(acpi_handle handle,
64703- struct acpi_dock_ops *ops,
64704+ const struct acpi_dock_ops *ops,
64705 void *context)
64706 {
64707 return -ENODEV;
64708diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
64709index b7babf0..a9ac9fc 100644
64710--- a/include/asm-generic/atomic-long.h
64711+++ b/include/asm-generic/atomic-long.h
64712@@ -22,6 +22,12 @@
64713
64714 typedef atomic64_t atomic_long_t;
64715
64716+#ifdef CONFIG_PAX_REFCOUNT
64717+typedef atomic64_unchecked_t atomic_long_unchecked_t;
64718+#else
64719+typedef atomic64_t atomic_long_unchecked_t;
64720+#endif
64721+
64722 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
64723
64724 static inline long atomic_long_read(atomic_long_t *l)
64725@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
64726 return (long)atomic64_read(v);
64727 }
64728
64729+#ifdef CONFIG_PAX_REFCOUNT
64730+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
64731+{
64732+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64733+
64734+ return (long)atomic64_read_unchecked(v);
64735+}
64736+#endif
64737+
64738 static inline void atomic_long_set(atomic_long_t *l, long i)
64739 {
64740 atomic64_t *v = (atomic64_t *)l;
64741@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
64742 atomic64_set(v, i);
64743 }
64744
64745+#ifdef CONFIG_PAX_REFCOUNT
64746+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
64747+{
64748+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64749+
64750+ atomic64_set_unchecked(v, i);
64751+}
64752+#endif
64753+
64754 static inline void atomic_long_inc(atomic_long_t *l)
64755 {
64756 atomic64_t *v = (atomic64_t *)l;
64757@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
64758 atomic64_inc(v);
64759 }
64760
64761+#ifdef CONFIG_PAX_REFCOUNT
64762+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
64763+{
64764+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64765+
64766+ atomic64_inc_unchecked(v);
64767+}
64768+#endif
64769+
64770 static inline void atomic_long_dec(atomic_long_t *l)
64771 {
64772 atomic64_t *v = (atomic64_t *)l;
64773@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
64774 atomic64_dec(v);
64775 }
64776
64777+#ifdef CONFIG_PAX_REFCOUNT
64778+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
64779+{
64780+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64781+
64782+ atomic64_dec_unchecked(v);
64783+}
64784+#endif
64785+
64786 static inline void atomic_long_add(long i, atomic_long_t *l)
64787 {
64788 atomic64_t *v = (atomic64_t *)l;
64789@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
64790 atomic64_add(i, v);
64791 }
64792
64793+#ifdef CONFIG_PAX_REFCOUNT
64794+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
64795+{
64796+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64797+
64798+ atomic64_add_unchecked(i, v);
64799+}
64800+#endif
64801+
64802 static inline void atomic_long_sub(long i, atomic_long_t *l)
64803 {
64804 atomic64_t *v = (atomic64_t *)l;
64805@@ -115,6 +166,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
64806 return (long)atomic64_inc_return(v);
64807 }
64808
64809+#ifdef CONFIG_PAX_REFCOUNT
64810+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
64811+{
64812+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64813+
64814+ return (long)atomic64_inc_return_unchecked(v);
64815+}
64816+#endif
64817+
64818 static inline long atomic_long_dec_return(atomic_long_t *l)
64819 {
64820 atomic64_t *v = (atomic64_t *)l;
64821@@ -140,6 +200,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
64822
64823 typedef atomic_t atomic_long_t;
64824
64825+#ifdef CONFIG_PAX_REFCOUNT
64826+typedef atomic_unchecked_t atomic_long_unchecked_t;
64827+#else
64828+typedef atomic_t atomic_long_unchecked_t;
64829+#endif
64830+
64831 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
64832 static inline long atomic_long_read(atomic_long_t *l)
64833 {
64834@@ -148,6 +214,15 @@ static inline long atomic_long_read(atomic_long_t *l)
64835 return (long)atomic_read(v);
64836 }
64837
64838+#ifdef CONFIG_PAX_REFCOUNT
64839+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
64840+{
64841+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64842+
64843+ return (long)atomic_read_unchecked(v);
64844+}
64845+#endif
64846+
64847 static inline void atomic_long_set(atomic_long_t *l, long i)
64848 {
64849 atomic_t *v = (atomic_t *)l;
64850@@ -155,6 +230,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
64851 atomic_set(v, i);
64852 }
64853
64854+#ifdef CONFIG_PAX_REFCOUNT
64855+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
64856+{
64857+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64858+
64859+ atomic_set_unchecked(v, i);
64860+}
64861+#endif
64862+
64863 static inline void atomic_long_inc(atomic_long_t *l)
64864 {
64865 atomic_t *v = (atomic_t *)l;
64866@@ -162,6 +246,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
64867 atomic_inc(v);
64868 }
64869
64870+#ifdef CONFIG_PAX_REFCOUNT
64871+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
64872+{
64873+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64874+
64875+ atomic_inc_unchecked(v);
64876+}
64877+#endif
64878+
64879 static inline void atomic_long_dec(atomic_long_t *l)
64880 {
64881 atomic_t *v = (atomic_t *)l;
64882@@ -169,6 +262,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
64883 atomic_dec(v);
64884 }
64885
64886+#ifdef CONFIG_PAX_REFCOUNT
64887+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
64888+{
64889+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64890+
64891+ atomic_dec_unchecked(v);
64892+}
64893+#endif
64894+
64895 static inline void atomic_long_add(long i, atomic_long_t *l)
64896 {
64897 atomic_t *v = (atomic_t *)l;
64898@@ -176,6 +278,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
64899 atomic_add(i, v);
64900 }
64901
64902+#ifdef CONFIG_PAX_REFCOUNT
64903+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
64904+{
64905+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64906+
64907+ atomic_add_unchecked(i, v);
64908+}
64909+#endif
64910+
64911 static inline void atomic_long_sub(long i, atomic_long_t *l)
64912 {
64913 atomic_t *v = (atomic_t *)l;
64914@@ -232,6 +343,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
64915 return (long)atomic_inc_return(v);
64916 }
64917
64918+#ifdef CONFIG_PAX_REFCOUNT
64919+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
64920+{
64921+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64922+
64923+ return (long)atomic_inc_return_unchecked(v);
64924+}
64925+#endif
64926+
64927 static inline long atomic_long_dec_return(atomic_long_t *l)
64928 {
64929 atomic_t *v = (atomic_t *)l;
64930@@ -255,4 +375,47 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
64931
64932 #endif /* BITS_PER_LONG == 64 */
64933
64934+#ifdef CONFIG_PAX_REFCOUNT
64935+static inline void pax_refcount_needs_these_functions(void)
64936+{
64937+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
64938+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
64939+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
64940+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
64941+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
64942+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
64943+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
64944+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
64945+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
64946+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
64947+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
64948+
64949+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
64950+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
64951+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
64952+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
64953+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
64954+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
64955+}
64956+#else
64957+#define atomic_read_unchecked(v) atomic_read(v)
64958+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
64959+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
64960+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
64961+#define atomic_inc_unchecked(v) atomic_inc(v)
64962+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
64963+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
64964+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
64965+#define atomic_dec_unchecked(v) atomic_dec(v)
64966+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
64967+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
64968+
64969+#define atomic_long_read_unchecked(v) atomic_long_read(v)
64970+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
64971+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
64972+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
64973+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
64974+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
64975+#endif
64976+
64977 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
64978diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
64979index b18ce4f..2ee2843 100644
64980--- a/include/asm-generic/atomic64.h
64981+++ b/include/asm-generic/atomic64.h
64982@@ -16,6 +16,8 @@ typedef struct {
64983 long long counter;
64984 } atomic64_t;
64985
64986+typedef atomic64_t atomic64_unchecked_t;
64987+
64988 #define ATOMIC64_INIT(i) { (i) }
64989
64990 extern long long atomic64_read(const atomic64_t *v);
64991@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
64992 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
64993 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
64994
64995+#define atomic64_read_unchecked(v) atomic64_read(v)
64996+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
64997+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
64998+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
64999+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
65000+#define atomic64_inc_unchecked(v) atomic64_inc(v)
65001+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
65002+#define atomic64_dec_unchecked(v) atomic64_dec(v)
65003+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
65004+
65005 #endif /* _ASM_GENERIC_ATOMIC64_H */
65006diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
65007index d48ddf0..656a0ac 100644
65008--- a/include/asm-generic/bug.h
65009+++ b/include/asm-generic/bug.h
65010@@ -105,11 +105,11 @@ extern void warn_slowpath_null(const char *file, const int line);
65011
65012 #else /* !CONFIG_BUG */
65013 #ifndef HAVE_ARCH_BUG
65014-#define BUG() do {} while(0)
65015+#define BUG() do { for (;;) ; } while(0)
65016 #endif
65017
65018 #ifndef HAVE_ARCH_BUG_ON
65019-#define BUG_ON(condition) do { if (condition) ; } while(0)
65020+#define BUG_ON(condition) do { if (condition) for (;;) ; } while(0)
65021 #endif
65022
65023 #ifndef HAVE_ARCH_WARN_ON
65024diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
65025index 1bfcfe5..e04c5c9 100644
65026--- a/include/asm-generic/cache.h
65027+++ b/include/asm-generic/cache.h
65028@@ -6,7 +6,7 @@
65029 * cache lines need to provide their own cache.h.
65030 */
65031
65032-#define L1_CACHE_SHIFT 5
65033-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
65034+#define L1_CACHE_SHIFT 5UL
65035+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
65036
65037 #endif /* __ASM_GENERIC_CACHE_H */
65038diff --git a/include/asm-generic/dma-mapping-common.h b/include/asm-generic/dma-mapping-common.h
65039index 6920695..41038bc 100644
65040--- a/include/asm-generic/dma-mapping-common.h
65041+++ b/include/asm-generic/dma-mapping-common.h
65042@@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
65043 enum dma_data_direction dir,
65044 struct dma_attrs *attrs)
65045 {
65046- struct dma_map_ops *ops = get_dma_ops(dev);
65047+ const struct dma_map_ops *ops = get_dma_ops(dev);
65048 dma_addr_t addr;
65049
65050 kmemcheck_mark_initialized(ptr, size);
65051@@ -30,7 +30,7 @@ static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr,
65052 enum dma_data_direction dir,
65053 struct dma_attrs *attrs)
65054 {
65055- struct dma_map_ops *ops = get_dma_ops(dev);
65056+ const struct dma_map_ops *ops = get_dma_ops(dev);
65057
65058 BUG_ON(!valid_dma_direction(dir));
65059 if (ops->unmap_page)
65060@@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
65061 int nents, enum dma_data_direction dir,
65062 struct dma_attrs *attrs)
65063 {
65064- struct dma_map_ops *ops = get_dma_ops(dev);
65065+ const struct dma_map_ops *ops = get_dma_ops(dev);
65066 int i, ents;
65067 struct scatterlist *s;
65068
65069@@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg
65070 int nents, enum dma_data_direction dir,
65071 struct dma_attrs *attrs)
65072 {
65073- struct dma_map_ops *ops = get_dma_ops(dev);
65074+ const struct dma_map_ops *ops = get_dma_ops(dev);
65075
65076 BUG_ON(!valid_dma_direction(dir));
65077 debug_dma_unmap_sg(dev, sg, nents, dir);
65078@@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
65079 size_t offset, size_t size,
65080 enum dma_data_direction dir)
65081 {
65082- struct dma_map_ops *ops = get_dma_ops(dev);
65083+ const struct dma_map_ops *ops = get_dma_ops(dev);
65084 dma_addr_t addr;
65085
65086 kmemcheck_mark_initialized(page_address(page) + offset, size);
65087@@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
65088 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
65089 size_t size, enum dma_data_direction dir)
65090 {
65091- struct dma_map_ops *ops = get_dma_ops(dev);
65092+ const struct dma_map_ops *ops = get_dma_ops(dev);
65093
65094 BUG_ON(!valid_dma_direction(dir));
65095 if (ops->unmap_page)
65096@@ -97,7 +97,7 @@ static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
65097 size_t size,
65098 enum dma_data_direction dir)
65099 {
65100- struct dma_map_ops *ops = get_dma_ops(dev);
65101+ const struct dma_map_ops *ops = get_dma_ops(dev);
65102
65103 BUG_ON(!valid_dma_direction(dir));
65104 if (ops->sync_single_for_cpu)
65105@@ -109,7 +109,7 @@ static inline void dma_sync_single_for_device(struct device *dev,
65106 dma_addr_t addr, size_t size,
65107 enum dma_data_direction dir)
65108 {
65109- struct dma_map_ops *ops = get_dma_ops(dev);
65110+ const struct dma_map_ops *ops = get_dma_ops(dev);
65111
65112 BUG_ON(!valid_dma_direction(dir));
65113 if (ops->sync_single_for_device)
65114@@ -123,7 +123,7 @@ static inline void dma_sync_single_range_for_cpu(struct device *dev,
65115 size_t size,
65116 enum dma_data_direction dir)
65117 {
65118- struct dma_map_ops *ops = get_dma_ops(dev);
65119+ const struct dma_map_ops *ops = get_dma_ops(dev);
65120
65121 BUG_ON(!valid_dma_direction(dir));
65122 if (ops->sync_single_range_for_cpu) {
65123@@ -140,7 +140,7 @@ static inline void dma_sync_single_range_for_device(struct device *dev,
65124 size_t size,
65125 enum dma_data_direction dir)
65126 {
65127- struct dma_map_ops *ops = get_dma_ops(dev);
65128+ const struct dma_map_ops *ops = get_dma_ops(dev);
65129
65130 BUG_ON(!valid_dma_direction(dir));
65131 if (ops->sync_single_range_for_device) {
65132@@ -155,7 +155,7 @@ static inline void
65133 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
65134 int nelems, enum dma_data_direction dir)
65135 {
65136- struct dma_map_ops *ops = get_dma_ops(dev);
65137+ const struct dma_map_ops *ops = get_dma_ops(dev);
65138
65139 BUG_ON(!valid_dma_direction(dir));
65140 if (ops->sync_sg_for_cpu)
65141@@ -167,7 +167,7 @@ static inline void
65142 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
65143 int nelems, enum dma_data_direction dir)
65144 {
65145- struct dma_map_ops *ops = get_dma_ops(dev);
65146+ const struct dma_map_ops *ops = get_dma_ops(dev);
65147
65148 BUG_ON(!valid_dma_direction(dir));
65149 if (ops->sync_sg_for_device)
65150diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
65151index 0d68a1e..b74a761 100644
65152--- a/include/asm-generic/emergency-restart.h
65153+++ b/include/asm-generic/emergency-restart.h
65154@@ -1,7 +1,7 @@
65155 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
65156 #define _ASM_GENERIC_EMERGENCY_RESTART_H
65157
65158-static inline void machine_emergency_restart(void)
65159+static inline __noreturn void machine_emergency_restart(void)
65160 {
65161 machine_restart(NULL);
65162 }
65163diff --git a/include/asm-generic/futex.h b/include/asm-generic/futex.h
65164index 3c2344f..4590a7d 100644
65165--- a/include/asm-generic/futex.h
65166+++ b/include/asm-generic/futex.h
65167@@ -6,7 +6,7 @@
65168 #include <asm/errno.h>
65169
65170 static inline int
65171-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
65172+futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
65173 {
65174 int op = (encoded_op >> 28) & 7;
65175 int cmp = (encoded_op >> 24) & 15;
65176@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
65177 }
65178
65179 static inline int
65180-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
65181+futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
65182 {
65183 return -ENOSYS;
65184 }
65185diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
65186index 1ca3efc..e3dc852 100644
65187--- a/include/asm-generic/int-l64.h
65188+++ b/include/asm-generic/int-l64.h
65189@@ -46,6 +46,8 @@ typedef unsigned int u32;
65190 typedef signed long s64;
65191 typedef unsigned long u64;
65192
65193+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
65194+
65195 #define S8_C(x) x
65196 #define U8_C(x) x ## U
65197 #define S16_C(x) x
65198diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
65199index f394147..b6152b9 100644
65200--- a/include/asm-generic/int-ll64.h
65201+++ b/include/asm-generic/int-ll64.h
65202@@ -51,6 +51,8 @@ typedef unsigned int u32;
65203 typedef signed long long s64;
65204 typedef unsigned long long u64;
65205
65206+typedef unsigned long long intoverflow_t;
65207+
65208 #define S8_C(x) x
65209 #define U8_C(x) x ## U
65210 #define S16_C(x) x
65211diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
65212index e5f234a..cdb16b3 100644
65213--- a/include/asm-generic/kmap_types.h
65214+++ b/include/asm-generic/kmap_types.h
65215@@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY,
65216 KMAP_D(16) KM_IRQ_PTE,
65217 KMAP_D(17) KM_NMI,
65218 KMAP_D(18) KM_NMI_PTE,
65219-KMAP_D(19) KM_TYPE_NR
65220+KMAP_D(19) KM_CLEARPAGE,
65221+KMAP_D(20) KM_TYPE_NR
65222 };
65223
65224 #undef KMAP_D
65225diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
65226index 725612b..9cc513a 100644
65227--- a/include/asm-generic/pgtable-nopmd.h
65228+++ b/include/asm-generic/pgtable-nopmd.h
65229@@ -1,14 +1,19 @@
65230 #ifndef _PGTABLE_NOPMD_H
65231 #define _PGTABLE_NOPMD_H
65232
65233-#ifndef __ASSEMBLY__
65234-
65235 #include <asm-generic/pgtable-nopud.h>
65236
65237-struct mm_struct;
65238-
65239 #define __PAGETABLE_PMD_FOLDED
65240
65241+#define PMD_SHIFT PUD_SHIFT
65242+#define PTRS_PER_PMD 1
65243+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
65244+#define PMD_MASK (~(PMD_SIZE-1))
65245+
65246+#ifndef __ASSEMBLY__
65247+
65248+struct mm_struct;
65249+
65250 /*
65251 * Having the pmd type consist of a pud gets the size right, and allows
65252 * us to conceptually access the pud entry that this pmd is folded into
65253@@ -16,11 +21,6 @@ struct mm_struct;
65254 */
65255 typedef struct { pud_t pud; } pmd_t;
65256
65257-#define PMD_SHIFT PUD_SHIFT
65258-#define PTRS_PER_PMD 1
65259-#define PMD_SIZE (1UL << PMD_SHIFT)
65260-#define PMD_MASK (~(PMD_SIZE-1))
65261-
65262 /*
65263 * The "pud_xxx()" functions here are trivial for a folded two-level
65264 * setup: the pmd is never bad, and a pmd always exists (as it's folded
65265diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
65266index 810431d..ccc3638 100644
65267--- a/include/asm-generic/pgtable-nopud.h
65268+++ b/include/asm-generic/pgtable-nopud.h
65269@@ -1,10 +1,15 @@
65270 #ifndef _PGTABLE_NOPUD_H
65271 #define _PGTABLE_NOPUD_H
65272
65273-#ifndef __ASSEMBLY__
65274-
65275 #define __PAGETABLE_PUD_FOLDED
65276
65277+#define PUD_SHIFT PGDIR_SHIFT
65278+#define PTRS_PER_PUD 1
65279+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
65280+#define PUD_MASK (~(PUD_SIZE-1))
65281+
65282+#ifndef __ASSEMBLY__
65283+
65284 /*
65285 * Having the pud type consist of a pgd gets the size right, and allows
65286 * us to conceptually access the pgd entry that this pud is folded into
65287@@ -12,11 +17,6 @@
65288 */
65289 typedef struct { pgd_t pgd; } pud_t;
65290
65291-#define PUD_SHIFT PGDIR_SHIFT
65292-#define PTRS_PER_PUD 1
65293-#define PUD_SIZE (1UL << PUD_SHIFT)
65294-#define PUD_MASK (~(PUD_SIZE-1))
65295-
65296 /*
65297 * The "pgd_xxx()" functions here are trivial for a folded two-level
65298 * setup: the pud is never bad, and a pud always exists (as it's folded
65299diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
65300index e2bd73e..fea8ed3 100644
65301--- a/include/asm-generic/pgtable.h
65302+++ b/include/asm-generic/pgtable.h
65303@@ -344,6 +344,14 @@ extern void untrack_pfn_vma(struct vm_area_struct *vma, unsigned long pfn,
65304 unsigned long size);
65305 #endif
65306
65307+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
65308+static inline unsigned long pax_open_kernel(void) { return 0; }
65309+#endif
65310+
65311+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
65312+static inline unsigned long pax_close_kernel(void) { return 0; }
65313+#endif
65314+
65315 #endif /* !__ASSEMBLY__ */
65316
65317 #endif /* _ASM_GENERIC_PGTABLE_H */
65318diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
65319index b6e818f..21aa58a 100644
65320--- a/include/asm-generic/vmlinux.lds.h
65321+++ b/include/asm-generic/vmlinux.lds.h
65322@@ -199,6 +199,7 @@
65323 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
65324 VMLINUX_SYMBOL(__start_rodata) = .; \
65325 *(.rodata) *(.rodata.*) \
65326+ *(.data.read_only) \
65327 *(__vermagic) /* Kernel version magic */ \
65328 *(__markers_strings) /* Markers: strings */ \
65329 *(__tracepoints_strings)/* Tracepoints: strings */ \
65330@@ -656,22 +657,24 @@
65331 * section in the linker script will go there too. @phdr should have
65332 * a leading colon.
65333 *
65334- * Note that this macros defines __per_cpu_load as an absolute symbol.
65335+ * Note that this macros defines per_cpu_load as an absolute symbol.
65336 * If there is no need to put the percpu section at a predetermined
65337 * address, use PERCPU().
65338 */
65339 #define PERCPU_VADDR(vaddr, phdr) \
65340- VMLINUX_SYMBOL(__per_cpu_load) = .; \
65341- .data.percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
65342+ per_cpu_load = .; \
65343+ .data.percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
65344 - LOAD_OFFSET) { \
65345+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
65346 VMLINUX_SYMBOL(__per_cpu_start) = .; \
65347 *(.data.percpu.first) \
65348- *(.data.percpu.page_aligned) \
65349 *(.data.percpu) \
65350+ . = ALIGN(PAGE_SIZE); \
65351+ *(.data.percpu.page_aligned) \
65352 *(.data.percpu.shared_aligned) \
65353 VMLINUX_SYMBOL(__per_cpu_end) = .; \
65354 } phdr \
65355- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data.percpu);
65356+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data.percpu);
65357
65358 /**
65359 * PERCPU - define output section for percpu area, simple version
65360diff --git a/include/drm/drmP.h b/include/drm/drmP.h
65361index 66713c6..98c0460 100644
65362--- a/include/drm/drmP.h
65363+++ b/include/drm/drmP.h
65364@@ -71,6 +71,7 @@
65365 #include <linux/workqueue.h>
65366 #include <linux/poll.h>
65367 #include <asm/pgalloc.h>
65368+#include <asm/local.h>
65369 #include "drm.h"
65370
65371 #include <linux/idr.h>
65372@@ -814,7 +815,7 @@ struct drm_driver {
65373 void (*vgaarb_irq)(struct drm_device *dev, bool state);
65374
65375 /* Driver private ops for this object */
65376- struct vm_operations_struct *gem_vm_ops;
65377+ const struct vm_operations_struct *gem_vm_ops;
65378
65379 int major;
65380 int minor;
65381@@ -917,7 +918,7 @@ struct drm_device {
65382
65383 /** \name Usage Counters */
65384 /*@{ */
65385- int open_count; /**< Outstanding files open */
65386+ local_t open_count; /**< Outstanding files open */
65387 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
65388 atomic_t vma_count; /**< Outstanding vma areas open */
65389 int buf_use; /**< Buffers in use -- cannot alloc */
65390@@ -928,7 +929,7 @@ struct drm_device {
65391 /*@{ */
65392 unsigned long counters;
65393 enum drm_stat_type types[15];
65394- atomic_t counts[15];
65395+ atomic_unchecked_t counts[15];
65396 /*@} */
65397
65398 struct list_head filelist;
65399@@ -1016,7 +1017,7 @@ struct drm_device {
65400 struct pci_controller *hose;
65401 #endif
65402 struct drm_sg_mem *sg; /**< Scatter gather memory */
65403- unsigned int num_crtcs; /**< Number of CRTCs on this device */
65404+ unsigned int num_crtcs; /**< Number of CRTCs on this device */
65405 void *dev_private; /**< device private data */
65406 void *mm_private;
65407 struct address_space *dev_mapping;
65408@@ -1042,11 +1043,11 @@ struct drm_device {
65409 spinlock_t object_name_lock;
65410 struct idr object_name_idr;
65411 atomic_t object_count;
65412- atomic_t object_memory;
65413+ atomic_unchecked_t object_memory;
65414 atomic_t pin_count;
65415- atomic_t pin_memory;
65416+ atomic_unchecked_t pin_memory;
65417 atomic_t gtt_count;
65418- atomic_t gtt_memory;
65419+ atomic_unchecked_t gtt_memory;
65420 uint32_t gtt_total;
65421 uint32_t invalidate_domains; /* domains pending invalidation */
65422 uint32_t flush_domains; /* domains pending flush */
65423diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
65424index b29e201..3413cc9 100644
65425--- a/include/drm/drm_crtc_helper.h
65426+++ b/include/drm/drm_crtc_helper.h
65427@@ -64,7 +64,7 @@ struct drm_crtc_helper_funcs {
65428
65429 /* reload the current crtc LUT */
65430 void (*load_lut)(struct drm_crtc *crtc);
65431-};
65432+} __no_const;
65433
65434 struct drm_encoder_helper_funcs {
65435 void (*dpms)(struct drm_encoder *encoder, int mode);
65436@@ -85,7 +85,7 @@ struct drm_encoder_helper_funcs {
65437 struct drm_connector *connector);
65438 /* disable encoder when not in use - more explicit than dpms off */
65439 void (*disable)(struct drm_encoder *encoder);
65440-};
65441+} __no_const;
65442
65443 struct drm_connector_helper_funcs {
65444 int (*get_modes)(struct drm_connector *connector);
65445diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
65446index b199170..6f9e64c 100644
65447--- a/include/drm/ttm/ttm_memory.h
65448+++ b/include/drm/ttm/ttm_memory.h
65449@@ -47,7 +47,7 @@
65450
65451 struct ttm_mem_shrink {
65452 int (*do_shrink) (struct ttm_mem_shrink *);
65453-};
65454+} __no_const;
65455
65456 /**
65457 * struct ttm_mem_global - Global memory accounting structure.
65458diff --git a/include/linux/a.out.h b/include/linux/a.out.h
65459index e86dfca..40cc55f 100644
65460--- a/include/linux/a.out.h
65461+++ b/include/linux/a.out.h
65462@@ -39,6 +39,14 @@ enum machine_type {
65463 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
65464 };
65465
65466+/* Constants for the N_FLAGS field */
65467+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65468+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
65469+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
65470+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
65471+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65472+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65473+
65474 #if !defined (N_MAGIC)
65475 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
65476 #endif
65477diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
65478index 817b237..62c10bc 100644
65479--- a/include/linux/atmdev.h
65480+++ b/include/linux/atmdev.h
65481@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
65482 #endif
65483
65484 struct k_atm_aal_stats {
65485-#define __HANDLE_ITEM(i) atomic_t i
65486+#define __HANDLE_ITEM(i) atomic_unchecked_t i
65487 __AAL_STAT_ITEMS
65488 #undef __HANDLE_ITEM
65489 };
65490diff --git a/include/linux/backlight.h b/include/linux/backlight.h
65491index 0f5f578..8c4f884 100644
65492--- a/include/linux/backlight.h
65493+++ b/include/linux/backlight.h
65494@@ -36,18 +36,18 @@ struct backlight_device;
65495 struct fb_info;
65496
65497 struct backlight_ops {
65498- unsigned int options;
65499+ const unsigned int options;
65500
65501 #define BL_CORE_SUSPENDRESUME (1 << 0)
65502
65503 /* Notify the backlight driver some property has changed */
65504- int (*update_status)(struct backlight_device *);
65505+ int (* const update_status)(struct backlight_device *);
65506 /* Return the current backlight brightness (accounting for power,
65507 fb_blank etc.) */
65508- int (*get_brightness)(struct backlight_device *);
65509+ int (* const get_brightness)(struct backlight_device *);
65510 /* Check if given framebuffer device is the one bound to this backlight;
65511 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
65512- int (*check_fb)(struct fb_info *);
65513+ int (* const check_fb)(struct fb_info *);
65514 };
65515
65516 /* This structure defines all the properties of a backlight */
65517@@ -86,7 +86,7 @@ struct backlight_device {
65518 registered this device has been unloaded, and if class_get_devdata()
65519 points to something in the body of that driver, it is also invalid. */
65520 struct mutex ops_lock;
65521- struct backlight_ops *ops;
65522+ const struct backlight_ops *ops;
65523
65524 /* The framebuffer notifier block */
65525 struct notifier_block fb_notif;
65526@@ -103,7 +103,7 @@ static inline void backlight_update_status(struct backlight_device *bd)
65527 }
65528
65529 extern struct backlight_device *backlight_device_register(const char *name,
65530- struct device *dev, void *devdata, struct backlight_ops *ops);
65531+ struct device *dev, void *devdata, const struct backlight_ops *ops);
65532 extern void backlight_device_unregister(struct backlight_device *bd);
65533 extern void backlight_force_update(struct backlight_device *bd,
65534 enum backlight_update_reason reason);
65535diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
65536index a3d802e..482f69c 100644
65537--- a/include/linux/binfmts.h
65538+++ b/include/linux/binfmts.h
65539@@ -83,6 +83,7 @@ struct linux_binfmt {
65540 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
65541 int (*load_shlib)(struct file *);
65542 int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
65543+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
65544 unsigned long min_coredump; /* minimal dump size */
65545 int hasvdso;
65546 };
65547diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
65548index 63070ad..a2906d2 100644
65549--- a/include/linux/blkdev.h
65550+++ b/include/linux/blkdev.h
65551@@ -777,6 +777,7 @@ extern void blk_plug_device(struct request_queue *);
65552 extern void blk_plug_device_unlocked(struct request_queue *);
65553 extern int blk_remove_plug(struct request_queue *);
65554 extern void blk_recount_segments(struct request_queue *, struct bio *);
65555+extern int scsi_verify_blk_ioctl(struct block_device *, unsigned int);
65556 extern int scsi_cmd_blk_ioctl(struct block_device *, fmode_t,
65557 unsigned int, void __user *);
65558 extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
65559@@ -1280,7 +1281,7 @@ struct block_device_operations {
65560 int (*revalidate_disk) (struct gendisk *);
65561 int (*getgeo)(struct block_device *, struct hd_geometry *);
65562 struct module *owner;
65563-};
65564+} __do_const;
65565
65566 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
65567 unsigned long);
65568diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
65569index 3b73b99..629d21b 100644
65570--- a/include/linux/blktrace_api.h
65571+++ b/include/linux/blktrace_api.h
65572@@ -160,7 +160,7 @@ struct blk_trace {
65573 struct dentry *dir;
65574 struct dentry *dropped_file;
65575 struct dentry *msg_file;
65576- atomic_t dropped;
65577+ atomic_unchecked_t dropped;
65578 };
65579
65580 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
65581diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
65582index 83195fb..0b0f77d 100644
65583--- a/include/linux/byteorder/little_endian.h
65584+++ b/include/linux/byteorder/little_endian.h
65585@@ -42,51 +42,51 @@
65586
65587 static inline __le64 __cpu_to_le64p(const __u64 *p)
65588 {
65589- return (__force __le64)*p;
65590+ return (__force const __le64)*p;
65591 }
65592 static inline __u64 __le64_to_cpup(const __le64 *p)
65593 {
65594- return (__force __u64)*p;
65595+ return (__force const __u64)*p;
65596 }
65597 static inline __le32 __cpu_to_le32p(const __u32 *p)
65598 {
65599- return (__force __le32)*p;
65600+ return (__force const __le32)*p;
65601 }
65602 static inline __u32 __le32_to_cpup(const __le32 *p)
65603 {
65604- return (__force __u32)*p;
65605+ return (__force const __u32)*p;
65606 }
65607 static inline __le16 __cpu_to_le16p(const __u16 *p)
65608 {
65609- return (__force __le16)*p;
65610+ return (__force const __le16)*p;
65611 }
65612 static inline __u16 __le16_to_cpup(const __le16 *p)
65613 {
65614- return (__force __u16)*p;
65615+ return (__force const __u16)*p;
65616 }
65617 static inline __be64 __cpu_to_be64p(const __u64 *p)
65618 {
65619- return (__force __be64)__swab64p(p);
65620+ return (__force const __be64)__swab64p(p);
65621 }
65622 static inline __u64 __be64_to_cpup(const __be64 *p)
65623 {
65624- return __swab64p((__u64 *)p);
65625+ return __swab64p((const __u64 *)p);
65626 }
65627 static inline __be32 __cpu_to_be32p(const __u32 *p)
65628 {
65629- return (__force __be32)__swab32p(p);
65630+ return (__force const __be32)__swab32p(p);
65631 }
65632 static inline __u32 __be32_to_cpup(const __be32 *p)
65633 {
65634- return __swab32p((__u32 *)p);
65635+ return __swab32p((const __u32 *)p);
65636 }
65637 static inline __be16 __cpu_to_be16p(const __u16 *p)
65638 {
65639- return (__force __be16)__swab16p(p);
65640+ return (__force const __be16)__swab16p(p);
65641 }
65642 static inline __u16 __be16_to_cpup(const __be16 *p)
65643 {
65644- return __swab16p((__u16 *)p);
65645+ return __swab16p((const __u16 *)p);
65646 }
65647 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
65648 #define __le64_to_cpus(x) do { (void)(x); } while (0)
65649diff --git a/include/linux/cache.h b/include/linux/cache.h
65650index 97e2488..e7576b9 100644
65651--- a/include/linux/cache.h
65652+++ b/include/linux/cache.h
65653@@ -16,6 +16,10 @@
65654 #define __read_mostly
65655 #endif
65656
65657+#ifndef __read_only
65658+#define __read_only __read_mostly
65659+#endif
65660+
65661 #ifndef ____cacheline_aligned
65662 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
65663 #endif
65664diff --git a/include/linux/capability.h b/include/linux/capability.h
65665index c8f2a5f7..1618a5c 100644
65666--- a/include/linux/capability.h
65667+++ b/include/linux/capability.h
65668@@ -563,6 +563,7 @@ extern const kernel_cap_t __cap_init_eff_set;
65669 (security_real_capable_noaudit((t), (cap)) == 0)
65670
65671 extern int capable(int cap);
65672+int capable_nolog(int cap);
65673
65674 /* audit system wants to get cap info from files as well */
65675 struct dentry;
65676diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
65677index 450fa59..86019fb 100644
65678--- a/include/linux/compiler-gcc4.h
65679+++ b/include/linux/compiler-gcc4.h
65680@@ -36,4 +36,16 @@
65681 the kernel context */
65682 #define __cold __attribute__((__cold__))
65683
65684+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
65685+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
65686+#define __bos0(ptr) __bos((ptr), 0)
65687+#define __bos1(ptr) __bos((ptr), 1)
65688+
65689+#if __GNUC_MINOR__ >= 5
65690+#ifdef CONSTIFY_PLUGIN
65691+#define __no_const __attribute__((no_const))
65692+#define __do_const __attribute__((do_const))
65693+#endif
65694+#endif
65695+
65696 #endif
65697diff --git a/include/linux/compiler.h b/include/linux/compiler.h
65698index 04fb513..fd6477b 100644
65699--- a/include/linux/compiler.h
65700+++ b/include/linux/compiler.h
65701@@ -5,11 +5,14 @@
65702
65703 #ifdef __CHECKER__
65704 # define __user __attribute__((noderef, address_space(1)))
65705+# define __force_user __force __user
65706 # define __kernel /* default address space */
65707+# define __force_kernel __force __kernel
65708 # define __safe __attribute__((safe))
65709 # define __force __attribute__((force))
65710 # define __nocast __attribute__((nocast))
65711 # define __iomem __attribute__((noderef, address_space(2)))
65712+# define __force_iomem __force __iomem
65713 # define __acquires(x) __attribute__((context(x,0,1)))
65714 # define __releases(x) __attribute__((context(x,1,0)))
65715 # define __acquire(x) __context__(x,1)
65716@@ -17,13 +20,34 @@
65717 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
65718 extern void __chk_user_ptr(const volatile void __user *);
65719 extern void __chk_io_ptr(const volatile void __iomem *);
65720+#elif defined(CHECKER_PLUGIN)
65721+//# define __user
65722+//# define __force_user
65723+//# define __kernel
65724+//# define __force_kernel
65725+# define __safe
65726+# define __force
65727+# define __nocast
65728+# define __iomem
65729+# define __force_iomem
65730+# define __chk_user_ptr(x) (void)0
65731+# define __chk_io_ptr(x) (void)0
65732+# define __builtin_warning(x, y...) (1)
65733+# define __acquires(x)
65734+# define __releases(x)
65735+# define __acquire(x) (void)0
65736+# define __release(x) (void)0
65737+# define __cond_lock(x,c) (c)
65738 #else
65739 # define __user
65740+# define __force_user
65741 # define __kernel
65742+# define __force_kernel
65743 # define __safe
65744 # define __force
65745 # define __nocast
65746 # define __iomem
65747+# define __force_iomem
65748 # define __chk_user_ptr(x) (void)0
65749 # define __chk_io_ptr(x) (void)0
65750 # define __builtin_warning(x, y...) (1)
65751@@ -247,6 +271,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65752 # define __attribute_const__ /* unimplemented */
65753 #endif
65754
65755+#ifndef __no_const
65756+# define __no_const
65757+#endif
65758+
65759+#ifndef __do_const
65760+# define __do_const
65761+#endif
65762+
65763 /*
65764 * Tell gcc if a function is cold. The compiler will assume any path
65765 * directly leading to the call is unlikely.
65766@@ -256,6 +288,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65767 #define __cold
65768 #endif
65769
65770+#ifndef __alloc_size
65771+#define __alloc_size(...)
65772+#endif
65773+
65774+#ifndef __bos
65775+#define __bos(ptr, arg)
65776+#endif
65777+
65778+#ifndef __bos0
65779+#define __bos0(ptr)
65780+#endif
65781+
65782+#ifndef __bos1
65783+#define __bos1(ptr)
65784+#endif
65785+
65786 /* Simple shorthand for a section definition */
65787 #ifndef __section
65788 # define __section(S) __attribute__ ((__section__(#S)))
65789@@ -278,6 +326,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65790 * use is to mediate communication between process-level code and irq/NMI
65791 * handlers, all running on the same CPU.
65792 */
65793-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
65794+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
65795+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
65796
65797 #endif /* __LINUX_COMPILER_H */
65798diff --git a/include/linux/crypto.h b/include/linux/crypto.h
65799index fd92988..a3164bd 100644
65800--- a/include/linux/crypto.h
65801+++ b/include/linux/crypto.h
65802@@ -394,7 +394,7 @@ struct cipher_tfm {
65803 const u8 *key, unsigned int keylen);
65804 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
65805 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
65806-};
65807+} __no_const;
65808
65809 struct hash_tfm {
65810 int (*init)(struct hash_desc *desc);
65811@@ -415,13 +415,13 @@ struct compress_tfm {
65812 int (*cot_decompress)(struct crypto_tfm *tfm,
65813 const u8 *src, unsigned int slen,
65814 u8 *dst, unsigned int *dlen);
65815-};
65816+} __no_const;
65817
65818 struct rng_tfm {
65819 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
65820 unsigned int dlen);
65821 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
65822-};
65823+} __no_const;
65824
65825 #define crt_ablkcipher crt_u.ablkcipher
65826 #define crt_aead crt_u.aead
65827diff --git a/include/linux/dcache.h b/include/linux/dcache.h
65828index 30b93b2..cd7a8db 100644
65829--- a/include/linux/dcache.h
65830+++ b/include/linux/dcache.h
65831@@ -119,6 +119,8 @@ struct dentry {
65832 unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
65833 };
65834
65835+#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
65836+
65837 /*
65838 * dentry->d_lock spinlock nesting subclasses:
65839 *
65840diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
65841index 3e9bd6a..f4e1aa0 100644
65842--- a/include/linux/decompress/mm.h
65843+++ b/include/linux/decompress/mm.h
65844@@ -78,7 +78,7 @@ static void free(void *where)
65845 * warnings when not needed (indeed large_malloc / large_free are not
65846 * needed by inflate */
65847
65848-#define malloc(a) kmalloc(a, GFP_KERNEL)
65849+#define malloc(a) kmalloc((a), GFP_KERNEL)
65850 #define free(a) kfree(a)
65851
65852 #define large_malloc(a) vmalloc(a)
65853diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
65854index 91b7618..92a93d32 100644
65855--- a/include/linux/dma-mapping.h
65856+++ b/include/linux/dma-mapping.h
65857@@ -16,51 +16,51 @@ enum dma_data_direction {
65858 };
65859
65860 struct dma_map_ops {
65861- void* (*alloc_coherent)(struct device *dev, size_t size,
65862+ void* (* const alloc_coherent)(struct device *dev, size_t size,
65863 dma_addr_t *dma_handle, gfp_t gfp);
65864- void (*free_coherent)(struct device *dev, size_t size,
65865+ void (* const free_coherent)(struct device *dev, size_t size,
65866 void *vaddr, dma_addr_t dma_handle);
65867- dma_addr_t (*map_page)(struct device *dev, struct page *page,
65868+ dma_addr_t (* const map_page)(struct device *dev, struct page *page,
65869 unsigned long offset, size_t size,
65870 enum dma_data_direction dir,
65871 struct dma_attrs *attrs);
65872- void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
65873+ void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
65874 size_t size, enum dma_data_direction dir,
65875 struct dma_attrs *attrs);
65876- int (*map_sg)(struct device *dev, struct scatterlist *sg,
65877+ int (* const map_sg)(struct device *dev, struct scatterlist *sg,
65878 int nents, enum dma_data_direction dir,
65879 struct dma_attrs *attrs);
65880- void (*unmap_sg)(struct device *dev,
65881+ void (* const unmap_sg)(struct device *dev,
65882 struct scatterlist *sg, int nents,
65883 enum dma_data_direction dir,
65884 struct dma_attrs *attrs);
65885- void (*sync_single_for_cpu)(struct device *dev,
65886+ void (* const sync_single_for_cpu)(struct device *dev,
65887 dma_addr_t dma_handle, size_t size,
65888 enum dma_data_direction dir);
65889- void (*sync_single_for_device)(struct device *dev,
65890+ void (* const sync_single_for_device)(struct device *dev,
65891 dma_addr_t dma_handle, size_t size,
65892 enum dma_data_direction dir);
65893- void (*sync_single_range_for_cpu)(struct device *dev,
65894+ void (* const sync_single_range_for_cpu)(struct device *dev,
65895 dma_addr_t dma_handle,
65896 unsigned long offset,
65897 size_t size,
65898 enum dma_data_direction dir);
65899- void (*sync_single_range_for_device)(struct device *dev,
65900+ void (* const sync_single_range_for_device)(struct device *dev,
65901 dma_addr_t dma_handle,
65902 unsigned long offset,
65903 size_t size,
65904 enum dma_data_direction dir);
65905- void (*sync_sg_for_cpu)(struct device *dev,
65906+ void (* const sync_sg_for_cpu)(struct device *dev,
65907 struct scatterlist *sg, int nents,
65908 enum dma_data_direction dir);
65909- void (*sync_sg_for_device)(struct device *dev,
65910+ void (* const sync_sg_for_device)(struct device *dev,
65911 struct scatterlist *sg, int nents,
65912 enum dma_data_direction dir);
65913- int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
65914- int (*dma_supported)(struct device *dev, u64 mask);
65915+ int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
65916+ int (* const dma_supported)(struct device *dev, u64 mask);
65917 int (*set_dma_mask)(struct device *dev, u64 mask);
65918 int is_phys;
65919-};
65920+} __do_const;
65921
65922 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
65923
65924diff --git a/include/linux/dst.h b/include/linux/dst.h
65925index e26fed8..b976d9f 100644
65926--- a/include/linux/dst.h
65927+++ b/include/linux/dst.h
65928@@ -380,7 +380,7 @@ struct dst_node
65929 struct thread_pool *pool;
65930
65931 /* Transaction IDs live here */
65932- atomic_long_t gen;
65933+ atomic_long_unchecked_t gen;
65934
65935 /*
65936 * How frequently and how many times transaction
65937diff --git a/include/linux/elf.h b/include/linux/elf.h
65938index 90a4ed0..d652617 100644
65939--- a/include/linux/elf.h
65940+++ b/include/linux/elf.h
65941@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
65942 #define PT_GNU_EH_FRAME 0x6474e550
65943
65944 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
65945+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
65946+
65947+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
65948+
65949+/* Constants for the e_flags field */
65950+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65951+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
65952+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
65953+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
65954+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65955+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65956
65957 /* These constants define the different elf file types */
65958 #define ET_NONE 0
65959@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
65960 #define DT_DEBUG 21
65961 #define DT_TEXTREL 22
65962 #define DT_JMPREL 23
65963+#define DT_FLAGS 30
65964+ #define DF_TEXTREL 0x00000004
65965 #define DT_ENCODING 32
65966 #define OLD_DT_LOOS 0x60000000
65967 #define DT_LOOS 0x6000000d
65968@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
65969 #define PF_W 0x2
65970 #define PF_X 0x1
65971
65972+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
65973+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
65974+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
65975+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
65976+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
65977+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
65978+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
65979+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
65980+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
65981+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
65982+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
65983+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
65984+
65985 typedef struct elf32_phdr{
65986 Elf32_Word p_type;
65987 Elf32_Off p_offset;
65988@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
65989 #define EI_OSABI 7
65990 #define EI_PAD 8
65991
65992+#define EI_PAX 14
65993+
65994 #define ELFMAG0 0x7f /* EI_MAG */
65995 #define ELFMAG1 'E'
65996 #define ELFMAG2 'L'
65997@@ -386,6 +414,7 @@ extern Elf32_Dyn _DYNAMIC [];
65998 #define elf_phdr elf32_phdr
65999 #define elf_note elf32_note
66000 #define elf_addr_t Elf32_Off
66001+#define elf_dyn Elf32_Dyn
66002
66003 #else
66004
66005@@ -394,6 +423,7 @@ extern Elf64_Dyn _DYNAMIC [];
66006 #define elf_phdr elf64_phdr
66007 #define elf_note elf64_note
66008 #define elf_addr_t Elf64_Off
66009+#define elf_dyn Elf64_Dyn
66010
66011 #endif
66012
66013diff --git a/include/linux/fs.h b/include/linux/fs.h
66014index 1b9a47a..6fe2934 100644
66015--- a/include/linux/fs.h
66016+++ b/include/linux/fs.h
66017@@ -568,41 +568,41 @@ typedef int (*read_actor_t)(read_descriptor_t *, struct page *,
66018 unsigned long, unsigned long);
66019
66020 struct address_space_operations {
66021- int (*writepage)(struct page *page, struct writeback_control *wbc);
66022- int (*readpage)(struct file *, struct page *);
66023- void (*sync_page)(struct page *);
66024+ int (* const writepage)(struct page *page, struct writeback_control *wbc);
66025+ int (* const readpage)(struct file *, struct page *);
66026+ void (* const sync_page)(struct page *);
66027
66028 /* Write back some dirty pages from this mapping. */
66029- int (*writepages)(struct address_space *, struct writeback_control *);
66030+ int (* const writepages)(struct address_space *, struct writeback_control *);
66031
66032 /* Set a page dirty. Return true if this dirtied it */
66033- int (*set_page_dirty)(struct page *page);
66034+ int (* const set_page_dirty)(struct page *page);
66035
66036- int (*readpages)(struct file *filp, struct address_space *mapping,
66037+ int (* const readpages)(struct file *filp, struct address_space *mapping,
66038 struct list_head *pages, unsigned nr_pages);
66039
66040- int (*write_begin)(struct file *, struct address_space *mapping,
66041+ int (* const write_begin)(struct file *, struct address_space *mapping,
66042 loff_t pos, unsigned len, unsigned flags,
66043 struct page **pagep, void **fsdata);
66044- int (*write_end)(struct file *, struct address_space *mapping,
66045+ int (* const write_end)(struct file *, struct address_space *mapping,
66046 loff_t pos, unsigned len, unsigned copied,
66047 struct page *page, void *fsdata);
66048
66049 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
66050- sector_t (*bmap)(struct address_space *, sector_t);
66051- void (*invalidatepage) (struct page *, unsigned long);
66052- int (*releasepage) (struct page *, gfp_t);
66053- ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
66054+ sector_t (* const bmap)(struct address_space *, sector_t);
66055+ void (* const invalidatepage) (struct page *, unsigned long);
66056+ int (* const releasepage) (struct page *, gfp_t);
66057+ ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
66058 loff_t offset, unsigned long nr_segs);
66059- int (*get_xip_mem)(struct address_space *, pgoff_t, int,
66060+ int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
66061 void **, unsigned long *);
66062 /* migrate the contents of a page to the specified target */
66063- int (*migratepage) (struct address_space *,
66064+ int (* const migratepage) (struct address_space *,
66065 struct page *, struct page *);
66066- int (*launder_page) (struct page *);
66067- int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
66068+ int (* const launder_page) (struct page *);
66069+ int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
66070 unsigned long);
66071- int (*error_remove_page)(struct address_space *, struct page *);
66072+ int (* const error_remove_page)(struct address_space *, struct page *);
66073 };
66074
66075 /*
66076@@ -1031,19 +1031,19 @@ static inline int file_check_writeable(struct file *filp)
66077 typedef struct files_struct *fl_owner_t;
66078
66079 struct file_lock_operations {
66080- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
66081- void (*fl_release_private)(struct file_lock *);
66082+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
66083+ void (* const fl_release_private)(struct file_lock *);
66084 };
66085
66086 struct lock_manager_operations {
66087- int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
66088- void (*fl_notify)(struct file_lock *); /* unblock callback */
66089- int (*fl_grant)(struct file_lock *, struct file_lock *, int);
66090- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
66091- void (*fl_release_private)(struct file_lock *);
66092- void (*fl_break)(struct file_lock *);
66093- int (*fl_mylease)(struct file_lock *, struct file_lock *);
66094- int (*fl_change)(struct file_lock **, int);
66095+ int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
66096+ void (* const fl_notify)(struct file_lock *); /* unblock callback */
66097+ int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
66098+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
66099+ void (* const fl_release_private)(struct file_lock *);
66100+ void (* const fl_break)(struct file_lock *);
66101+ int (* const fl_mylease)(struct file_lock *, struct file_lock *);
66102+ int (* const fl_change)(struct file_lock **, int);
66103 };
66104
66105 struct lock_manager {
66106@@ -1442,7 +1442,7 @@ struct fiemap_extent_info {
66107 unsigned int fi_flags; /* Flags as passed from user */
66108 unsigned int fi_extents_mapped; /* Number of mapped extents */
66109 unsigned int fi_extents_max; /* Size of fiemap_extent array */
66110- struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
66111+ struct fiemap_extent __user *fi_extents_start; /* Start of fiemap_extent
66112 * array */
66113 };
66114 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
66115@@ -1512,7 +1512,8 @@ struct file_operations {
66116 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
66117 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
66118 int (*setlease)(struct file *, long, struct file_lock **);
66119-};
66120+} __do_const;
66121+typedef struct file_operations __no_const file_operations_no_const;
66122
66123 struct inode_operations {
66124 int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
66125@@ -1559,30 +1560,30 @@ extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
66126 unsigned long, loff_t *);
66127
66128 struct super_operations {
66129- struct inode *(*alloc_inode)(struct super_block *sb);
66130- void (*destroy_inode)(struct inode *);
66131+ struct inode *(* const alloc_inode)(struct super_block *sb);
66132+ void (* const destroy_inode)(struct inode *);
66133
66134- void (*dirty_inode) (struct inode *);
66135- int (*write_inode) (struct inode *, int);
66136- void (*drop_inode) (struct inode *);
66137- void (*delete_inode) (struct inode *);
66138- void (*put_super) (struct super_block *);
66139- void (*write_super) (struct super_block *);
66140- int (*sync_fs)(struct super_block *sb, int wait);
66141- int (*freeze_fs) (struct super_block *);
66142- int (*unfreeze_fs) (struct super_block *);
66143- int (*statfs) (struct dentry *, struct kstatfs *);
66144- int (*remount_fs) (struct super_block *, int *, char *);
66145- void (*clear_inode) (struct inode *);
66146- void (*umount_begin) (struct super_block *);
66147+ void (* const dirty_inode) (struct inode *);
66148+ int (* const write_inode) (struct inode *, int);
66149+ void (* const drop_inode) (struct inode *);
66150+ void (* const delete_inode) (struct inode *);
66151+ void (* const put_super) (struct super_block *);
66152+ void (* const write_super) (struct super_block *);
66153+ int (* const sync_fs)(struct super_block *sb, int wait);
66154+ int (* const freeze_fs) (struct super_block *);
66155+ int (* const unfreeze_fs) (struct super_block *);
66156+ int (* const statfs) (struct dentry *, struct kstatfs *);
66157+ int (* const remount_fs) (struct super_block *, int *, char *);
66158+ void (* const clear_inode) (struct inode *);
66159+ void (* const umount_begin) (struct super_block *);
66160
66161- int (*show_options)(struct seq_file *, struct vfsmount *);
66162- int (*show_stats)(struct seq_file *, struct vfsmount *);
66163+ int (* const show_options)(struct seq_file *, struct vfsmount *);
66164+ int (* const show_stats)(struct seq_file *, struct vfsmount *);
66165 #ifdef CONFIG_QUOTA
66166- ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
66167- ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
66168+ ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
66169+ ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
66170 #endif
66171- int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
66172+ int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
66173 };
66174
66175 /*
66176diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
66177index 78a05bf..2a7d3e1 100644
66178--- a/include/linux/fs_struct.h
66179+++ b/include/linux/fs_struct.h
66180@@ -4,7 +4,7 @@
66181 #include <linux/path.h>
66182
66183 struct fs_struct {
66184- int users;
66185+ atomic_t users;
66186 rwlock_t lock;
66187 int umask;
66188 int in_exec;
66189diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
66190index 7be0c6f..2f63a2b 100644
66191--- a/include/linux/fscache-cache.h
66192+++ b/include/linux/fscache-cache.h
66193@@ -116,7 +116,7 @@ struct fscache_operation {
66194 #endif
66195 };
66196
66197-extern atomic_t fscache_op_debug_id;
66198+extern atomic_unchecked_t fscache_op_debug_id;
66199 extern const struct slow_work_ops fscache_op_slow_work_ops;
66200
66201 extern void fscache_enqueue_operation(struct fscache_operation *);
66202@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
66203 fscache_operation_release_t release)
66204 {
66205 atomic_set(&op->usage, 1);
66206- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
66207+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
66208 op->release = release;
66209 INIT_LIST_HEAD(&op->pend_link);
66210 fscache_set_op_state(op, "Init");
66211diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
66212index 4d6f47b..00bcedb 100644
66213--- a/include/linux/fsnotify_backend.h
66214+++ b/include/linux/fsnotify_backend.h
66215@@ -86,6 +86,7 @@ struct fsnotify_ops {
66216 void (*freeing_mark)(struct fsnotify_mark_entry *entry, struct fsnotify_group *group);
66217 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
66218 };
66219+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
66220
66221 /*
66222 * A group is a "thing" that wants to receive notification about filesystem
66223diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
66224index 4ec5e67..42f1eb9 100644
66225--- a/include/linux/ftrace_event.h
66226+++ b/include/linux/ftrace_event.h
66227@@ -163,7 +163,7 @@ extern int trace_define_field(struct ftrace_event_call *call,
66228 int filter_type);
66229 extern int trace_define_common_fields(struct ftrace_event_call *call);
66230
66231-#define is_signed_type(type) (((type)(-1)) < 0)
66232+#define is_signed_type(type) (((type)(-1)) < (type)1)
66233
66234 int trace_set_clr_event(const char *system, const char *event, int set);
66235
66236diff --git a/include/linux/genhd.h b/include/linux/genhd.h
66237index 297df45..b6a74ff 100644
66238--- a/include/linux/genhd.h
66239+++ b/include/linux/genhd.h
66240@@ -161,7 +161,7 @@ struct gendisk {
66241
66242 struct timer_rand_state *random;
66243
66244- atomic_t sync_io; /* RAID */
66245+ atomic_unchecked_t sync_io; /* RAID */
66246 struct work_struct async_notify;
66247 #ifdef CONFIG_BLK_DEV_INTEGRITY
66248 struct blk_integrity *integrity;
66249diff --git a/include/linux/gracl.h b/include/linux/gracl.h
66250new file mode 100644
66251index 0000000..0dc3943
66252--- /dev/null
66253+++ b/include/linux/gracl.h
66254@@ -0,0 +1,317 @@
66255+#ifndef GR_ACL_H
66256+#define GR_ACL_H
66257+
66258+#include <linux/grdefs.h>
66259+#include <linux/resource.h>
66260+#include <linux/capability.h>
66261+#include <linux/dcache.h>
66262+#include <asm/resource.h>
66263+
66264+/* Major status information */
66265+
66266+#define GR_VERSION "grsecurity 2.2.2"
66267+#define GRSECURITY_VERSION 0x2202
66268+
66269+enum {
66270+ GR_SHUTDOWN = 0,
66271+ GR_ENABLE = 1,
66272+ GR_SPROLE = 2,
66273+ GR_RELOAD = 3,
66274+ GR_SEGVMOD = 4,
66275+ GR_STATUS = 5,
66276+ GR_UNSPROLE = 6,
66277+ GR_PASSSET = 7,
66278+ GR_SPROLEPAM = 8,
66279+};
66280+
66281+/* Password setup definitions
66282+ * kernel/grhash.c */
66283+enum {
66284+ GR_PW_LEN = 128,
66285+ GR_SALT_LEN = 16,
66286+ GR_SHA_LEN = 32,
66287+};
66288+
66289+enum {
66290+ GR_SPROLE_LEN = 64,
66291+};
66292+
66293+enum {
66294+ GR_NO_GLOB = 0,
66295+ GR_REG_GLOB,
66296+ GR_CREATE_GLOB
66297+};
66298+
66299+#define GR_NLIMITS 32
66300+
66301+/* Begin Data Structures */
66302+
66303+struct sprole_pw {
66304+ unsigned char *rolename;
66305+ unsigned char salt[GR_SALT_LEN];
66306+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
66307+};
66308+
66309+struct name_entry {
66310+ __u32 key;
66311+ ino_t inode;
66312+ dev_t device;
66313+ char *name;
66314+ __u16 len;
66315+ __u8 deleted;
66316+ struct name_entry *prev;
66317+ struct name_entry *next;
66318+};
66319+
66320+struct inodev_entry {
66321+ struct name_entry *nentry;
66322+ struct inodev_entry *prev;
66323+ struct inodev_entry *next;
66324+};
66325+
66326+struct acl_role_db {
66327+ struct acl_role_label **r_hash;
66328+ __u32 r_size;
66329+};
66330+
66331+struct inodev_db {
66332+ struct inodev_entry **i_hash;
66333+ __u32 i_size;
66334+};
66335+
66336+struct name_db {
66337+ struct name_entry **n_hash;
66338+ __u32 n_size;
66339+};
66340+
66341+struct crash_uid {
66342+ uid_t uid;
66343+ unsigned long expires;
66344+};
66345+
66346+struct gr_hash_struct {
66347+ void **table;
66348+ void **nametable;
66349+ void *first;
66350+ __u32 table_size;
66351+ __u32 used_size;
66352+ int type;
66353+};
66354+
66355+/* Userspace Grsecurity ACL data structures */
66356+
66357+struct acl_subject_label {
66358+ char *filename;
66359+ ino_t inode;
66360+ dev_t device;
66361+ __u32 mode;
66362+ kernel_cap_t cap_mask;
66363+ kernel_cap_t cap_lower;
66364+ kernel_cap_t cap_invert_audit;
66365+
66366+ struct rlimit res[GR_NLIMITS];
66367+ __u32 resmask;
66368+
66369+ __u8 user_trans_type;
66370+ __u8 group_trans_type;
66371+ uid_t *user_transitions;
66372+ gid_t *group_transitions;
66373+ __u16 user_trans_num;
66374+ __u16 group_trans_num;
66375+
66376+ __u32 sock_families[2];
66377+ __u32 ip_proto[8];
66378+ __u32 ip_type;
66379+ struct acl_ip_label **ips;
66380+ __u32 ip_num;
66381+ __u32 inaddr_any_override;
66382+
66383+ __u32 crashes;
66384+ unsigned long expires;
66385+
66386+ struct acl_subject_label *parent_subject;
66387+ struct gr_hash_struct *hash;
66388+ struct acl_subject_label *prev;
66389+ struct acl_subject_label *next;
66390+
66391+ struct acl_object_label **obj_hash;
66392+ __u32 obj_hash_size;
66393+ __u16 pax_flags;
66394+};
66395+
66396+struct role_allowed_ip {
66397+ __u32 addr;
66398+ __u32 netmask;
66399+
66400+ struct role_allowed_ip *prev;
66401+ struct role_allowed_ip *next;
66402+};
66403+
66404+struct role_transition {
66405+ char *rolename;
66406+
66407+ struct role_transition *prev;
66408+ struct role_transition *next;
66409+};
66410+
66411+struct acl_role_label {
66412+ char *rolename;
66413+ uid_t uidgid;
66414+ __u16 roletype;
66415+
66416+ __u16 auth_attempts;
66417+ unsigned long expires;
66418+
66419+ struct acl_subject_label *root_label;
66420+ struct gr_hash_struct *hash;
66421+
66422+ struct acl_role_label *prev;
66423+ struct acl_role_label *next;
66424+
66425+ struct role_transition *transitions;
66426+ struct role_allowed_ip *allowed_ips;
66427+ uid_t *domain_children;
66428+ __u16 domain_child_num;
66429+
66430+ struct acl_subject_label **subj_hash;
66431+ __u32 subj_hash_size;
66432+};
66433+
66434+struct user_acl_role_db {
66435+ struct acl_role_label **r_table;
66436+ __u32 num_pointers; /* Number of allocations to track */
66437+ __u32 num_roles; /* Number of roles */
66438+ __u32 num_domain_children; /* Number of domain children */
66439+ __u32 num_subjects; /* Number of subjects */
66440+ __u32 num_objects; /* Number of objects */
66441+};
66442+
66443+struct acl_object_label {
66444+ char *filename;
66445+ ino_t inode;
66446+ dev_t device;
66447+ __u32 mode;
66448+
66449+ struct acl_subject_label *nested;
66450+ struct acl_object_label *globbed;
66451+
66452+ /* next two structures not used */
66453+
66454+ struct acl_object_label *prev;
66455+ struct acl_object_label *next;
66456+};
66457+
66458+struct acl_ip_label {
66459+ char *iface;
66460+ __u32 addr;
66461+ __u32 netmask;
66462+ __u16 low, high;
66463+ __u8 mode;
66464+ __u32 type;
66465+ __u32 proto[8];
66466+
66467+ /* next two structures not used */
66468+
66469+ struct acl_ip_label *prev;
66470+ struct acl_ip_label *next;
66471+};
66472+
66473+struct gr_arg {
66474+ struct user_acl_role_db role_db;
66475+ unsigned char pw[GR_PW_LEN];
66476+ unsigned char salt[GR_SALT_LEN];
66477+ unsigned char sum[GR_SHA_LEN];
66478+ unsigned char sp_role[GR_SPROLE_LEN];
66479+ struct sprole_pw *sprole_pws;
66480+ dev_t segv_device;
66481+ ino_t segv_inode;
66482+ uid_t segv_uid;
66483+ __u16 num_sprole_pws;
66484+ __u16 mode;
66485+};
66486+
66487+struct gr_arg_wrapper {
66488+ struct gr_arg *arg;
66489+ __u32 version;
66490+ __u32 size;
66491+};
66492+
66493+struct subject_map {
66494+ struct acl_subject_label *user;
66495+ struct acl_subject_label *kernel;
66496+ struct subject_map *prev;
66497+ struct subject_map *next;
66498+};
66499+
66500+struct acl_subj_map_db {
66501+ struct subject_map **s_hash;
66502+ __u32 s_size;
66503+};
66504+
66505+/* End Data Structures Section */
66506+
66507+/* Hash functions generated by empirical testing by Brad Spengler
66508+ Makes good use of the low bits of the inode. Generally 0-1 times
66509+ in loop for successful match. 0-3 for unsuccessful match.
66510+ Shift/add algorithm with modulus of table size and an XOR*/
66511+
66512+static __inline__ unsigned int
66513+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
66514+{
66515+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
66516+}
66517+
66518+ static __inline__ unsigned int
66519+shash(const struct acl_subject_label *userp, const unsigned int sz)
66520+{
66521+ return ((const unsigned long)userp % sz);
66522+}
66523+
66524+static __inline__ unsigned int
66525+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
66526+{
66527+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
66528+}
66529+
66530+static __inline__ unsigned int
66531+nhash(const char *name, const __u16 len, const unsigned int sz)
66532+{
66533+ return full_name_hash((const unsigned char *)name, len) % sz;
66534+}
66535+
66536+#define FOR_EACH_ROLE_START(role) \
66537+ role = role_list; \
66538+ while (role) {
66539+
66540+#define FOR_EACH_ROLE_END(role) \
66541+ role = role->prev; \
66542+ }
66543+
66544+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
66545+ subj = NULL; \
66546+ iter = 0; \
66547+ while (iter < role->subj_hash_size) { \
66548+ if (subj == NULL) \
66549+ subj = role->subj_hash[iter]; \
66550+ if (subj == NULL) { \
66551+ iter++; \
66552+ continue; \
66553+ }
66554+
66555+#define FOR_EACH_SUBJECT_END(subj,iter) \
66556+ subj = subj->next; \
66557+ if (subj == NULL) \
66558+ iter++; \
66559+ }
66560+
66561+
66562+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
66563+ subj = role->hash->first; \
66564+ while (subj != NULL) {
66565+
66566+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
66567+ subj = subj->next; \
66568+ }
66569+
66570+#endif
66571+
66572diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
66573new file mode 100644
66574index 0000000..323ecf2
66575--- /dev/null
66576+++ b/include/linux/gralloc.h
66577@@ -0,0 +1,9 @@
66578+#ifndef __GRALLOC_H
66579+#define __GRALLOC_H
66580+
66581+void acl_free_all(void);
66582+int acl_alloc_stack_init(unsigned long size);
66583+void *acl_alloc(unsigned long len);
66584+void *acl_alloc_num(unsigned long num, unsigned long len);
66585+
66586+#endif
66587diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
66588new file mode 100644
66589index 0000000..70d6cd5
66590--- /dev/null
66591+++ b/include/linux/grdefs.h
66592@@ -0,0 +1,140 @@
66593+#ifndef GRDEFS_H
66594+#define GRDEFS_H
66595+
66596+/* Begin grsecurity status declarations */
66597+
66598+enum {
66599+ GR_READY = 0x01,
66600+ GR_STATUS_INIT = 0x00 // disabled state
66601+};
66602+
66603+/* Begin ACL declarations */
66604+
66605+/* Role flags */
66606+
66607+enum {
66608+ GR_ROLE_USER = 0x0001,
66609+ GR_ROLE_GROUP = 0x0002,
66610+ GR_ROLE_DEFAULT = 0x0004,
66611+ GR_ROLE_SPECIAL = 0x0008,
66612+ GR_ROLE_AUTH = 0x0010,
66613+ GR_ROLE_NOPW = 0x0020,
66614+ GR_ROLE_GOD = 0x0040,
66615+ GR_ROLE_LEARN = 0x0080,
66616+ GR_ROLE_TPE = 0x0100,
66617+ GR_ROLE_DOMAIN = 0x0200,
66618+ GR_ROLE_PAM = 0x0400,
66619+ GR_ROLE_PERSIST = 0x800
66620+};
66621+
66622+/* ACL Subject and Object mode flags */
66623+enum {
66624+ GR_DELETED = 0x80000000
66625+};
66626+
66627+/* ACL Object-only mode flags */
66628+enum {
66629+ GR_READ = 0x00000001,
66630+ GR_APPEND = 0x00000002,
66631+ GR_WRITE = 0x00000004,
66632+ GR_EXEC = 0x00000008,
66633+ GR_FIND = 0x00000010,
66634+ GR_INHERIT = 0x00000020,
66635+ GR_SETID = 0x00000040,
66636+ GR_CREATE = 0x00000080,
66637+ GR_DELETE = 0x00000100,
66638+ GR_LINK = 0x00000200,
66639+ GR_AUDIT_READ = 0x00000400,
66640+ GR_AUDIT_APPEND = 0x00000800,
66641+ GR_AUDIT_WRITE = 0x00001000,
66642+ GR_AUDIT_EXEC = 0x00002000,
66643+ GR_AUDIT_FIND = 0x00004000,
66644+ GR_AUDIT_INHERIT= 0x00008000,
66645+ GR_AUDIT_SETID = 0x00010000,
66646+ GR_AUDIT_CREATE = 0x00020000,
66647+ GR_AUDIT_DELETE = 0x00040000,
66648+ GR_AUDIT_LINK = 0x00080000,
66649+ GR_PTRACERD = 0x00100000,
66650+ GR_NOPTRACE = 0x00200000,
66651+ GR_SUPPRESS = 0x00400000,
66652+ GR_NOLEARN = 0x00800000,
66653+ GR_INIT_TRANSFER= 0x01000000
66654+};
66655+
66656+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
66657+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
66658+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
66659+
66660+/* ACL subject-only mode flags */
66661+enum {
66662+ GR_KILL = 0x00000001,
66663+ GR_VIEW = 0x00000002,
66664+ GR_PROTECTED = 0x00000004,
66665+ GR_LEARN = 0x00000008,
66666+ GR_OVERRIDE = 0x00000010,
66667+ /* just a placeholder, this mode is only used in userspace */
66668+ GR_DUMMY = 0x00000020,
66669+ GR_PROTSHM = 0x00000040,
66670+ GR_KILLPROC = 0x00000080,
66671+ GR_KILLIPPROC = 0x00000100,
66672+ /* just a placeholder, this mode is only used in userspace */
66673+ GR_NOTROJAN = 0x00000200,
66674+ GR_PROTPROCFD = 0x00000400,
66675+ GR_PROCACCT = 0x00000800,
66676+ GR_RELAXPTRACE = 0x00001000,
66677+ GR_NESTED = 0x00002000,
66678+ GR_INHERITLEARN = 0x00004000,
66679+ GR_PROCFIND = 0x00008000,
66680+ GR_POVERRIDE = 0x00010000,
66681+ GR_KERNELAUTH = 0x00020000,
66682+ GR_ATSECURE = 0x00040000,
66683+ GR_SHMEXEC = 0x00080000
66684+};
66685+
66686+enum {
66687+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
66688+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
66689+ GR_PAX_ENABLE_MPROTECT = 0x0004,
66690+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
66691+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
66692+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
66693+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
66694+ GR_PAX_DISABLE_MPROTECT = 0x0400,
66695+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
66696+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
66697+};
66698+
66699+enum {
66700+ GR_ID_USER = 0x01,
66701+ GR_ID_GROUP = 0x02,
66702+};
66703+
66704+enum {
66705+ GR_ID_ALLOW = 0x01,
66706+ GR_ID_DENY = 0x02,
66707+};
66708+
66709+#define GR_CRASH_RES 31
66710+#define GR_UIDTABLE_MAX 500
66711+
66712+/* begin resource learning section */
66713+enum {
66714+ GR_RLIM_CPU_BUMP = 60,
66715+ GR_RLIM_FSIZE_BUMP = 50000,
66716+ GR_RLIM_DATA_BUMP = 10000,
66717+ GR_RLIM_STACK_BUMP = 1000,
66718+ GR_RLIM_CORE_BUMP = 10000,
66719+ GR_RLIM_RSS_BUMP = 500000,
66720+ GR_RLIM_NPROC_BUMP = 1,
66721+ GR_RLIM_NOFILE_BUMP = 5,
66722+ GR_RLIM_MEMLOCK_BUMP = 50000,
66723+ GR_RLIM_AS_BUMP = 500000,
66724+ GR_RLIM_LOCKS_BUMP = 2,
66725+ GR_RLIM_SIGPENDING_BUMP = 5,
66726+ GR_RLIM_MSGQUEUE_BUMP = 10000,
66727+ GR_RLIM_NICE_BUMP = 1,
66728+ GR_RLIM_RTPRIO_BUMP = 1,
66729+ GR_RLIM_RTTIME_BUMP = 1000000
66730+};
66731+
66732+#endif
66733diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
66734new file mode 100644
66735index 0000000..e5817d7
66736--- /dev/null
66737+++ b/include/linux/grinternal.h
66738@@ -0,0 +1,218 @@
66739+#ifndef __GRINTERNAL_H
66740+#define __GRINTERNAL_H
66741+
66742+#ifdef CONFIG_GRKERNSEC
66743+
66744+#include <linux/fs.h>
66745+#include <linux/mnt_namespace.h>
66746+#include <linux/nsproxy.h>
66747+#include <linux/gracl.h>
66748+#include <linux/grdefs.h>
66749+#include <linux/grmsg.h>
66750+
66751+void gr_add_learn_entry(const char *fmt, ...)
66752+ __attribute__ ((format (printf, 1, 2)));
66753+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
66754+ const struct vfsmount *mnt);
66755+__u32 gr_check_create(const struct dentry *new_dentry,
66756+ const struct dentry *parent,
66757+ const struct vfsmount *mnt, const __u32 mode);
66758+int gr_check_protected_task(const struct task_struct *task);
66759+__u32 to_gr_audit(const __u32 reqmode);
66760+int gr_set_acls(const int type);
66761+int gr_apply_subject_to_task(struct task_struct *task);
66762+int gr_acl_is_enabled(void);
66763+char gr_roletype_to_char(void);
66764+
66765+void gr_handle_alertkill(struct task_struct *task);
66766+char *gr_to_filename(const struct dentry *dentry,
66767+ const struct vfsmount *mnt);
66768+char *gr_to_filename1(const struct dentry *dentry,
66769+ const struct vfsmount *mnt);
66770+char *gr_to_filename2(const struct dentry *dentry,
66771+ const struct vfsmount *mnt);
66772+char *gr_to_filename3(const struct dentry *dentry,
66773+ const struct vfsmount *mnt);
66774+
66775+extern int grsec_enable_harden_ptrace;
66776+extern int grsec_enable_link;
66777+extern int grsec_enable_fifo;
66778+extern int grsec_enable_shm;
66779+extern int grsec_enable_execlog;
66780+extern int grsec_enable_signal;
66781+extern int grsec_enable_audit_ptrace;
66782+extern int grsec_enable_forkfail;
66783+extern int grsec_enable_time;
66784+extern int grsec_enable_rofs;
66785+extern int grsec_enable_chroot_shmat;
66786+extern int grsec_enable_chroot_mount;
66787+extern int grsec_enable_chroot_double;
66788+extern int grsec_enable_chroot_pivot;
66789+extern int grsec_enable_chroot_chdir;
66790+extern int grsec_enable_chroot_chmod;
66791+extern int grsec_enable_chroot_mknod;
66792+extern int grsec_enable_chroot_fchdir;
66793+extern int grsec_enable_chroot_nice;
66794+extern int grsec_enable_chroot_execlog;
66795+extern int grsec_enable_chroot_caps;
66796+extern int grsec_enable_chroot_sysctl;
66797+extern int grsec_enable_chroot_unix;
66798+extern int grsec_enable_tpe;
66799+extern int grsec_tpe_gid;
66800+extern int grsec_enable_tpe_all;
66801+extern int grsec_enable_tpe_invert;
66802+extern int grsec_enable_socket_all;
66803+extern int grsec_socket_all_gid;
66804+extern int grsec_enable_socket_client;
66805+extern int grsec_socket_client_gid;
66806+extern int grsec_enable_socket_server;
66807+extern int grsec_socket_server_gid;
66808+extern int grsec_audit_gid;
66809+extern int grsec_enable_group;
66810+extern int grsec_enable_audit_textrel;
66811+extern int grsec_enable_log_rwxmaps;
66812+extern int grsec_enable_mount;
66813+extern int grsec_enable_chdir;
66814+extern int grsec_resource_logging;
66815+extern int grsec_enable_blackhole;
66816+extern int grsec_lastack_retries;
66817+extern int grsec_enable_brute;
66818+extern int grsec_lock;
66819+
66820+extern spinlock_t grsec_alert_lock;
66821+extern unsigned long grsec_alert_wtime;
66822+extern unsigned long grsec_alert_fyet;
66823+
66824+extern spinlock_t grsec_audit_lock;
66825+
66826+extern rwlock_t grsec_exec_file_lock;
66827+
66828+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
66829+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
66830+ (tsk)->exec_file->f_vfsmnt) : "/")
66831+
66832+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
66833+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
66834+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
66835+
66836+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
66837+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
66838+ (tsk)->exec_file->f_vfsmnt) : "/")
66839+
66840+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
66841+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
66842+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
66843+
66844+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
66845+
66846+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
66847+
66848+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
66849+ (task)->pid, (cred)->uid, \
66850+ (cred)->euid, (cred)->gid, (cred)->egid, \
66851+ gr_parent_task_fullpath(task), \
66852+ (task)->real_parent->comm, (task)->real_parent->pid, \
66853+ (pcred)->uid, (pcred)->euid, \
66854+ (pcred)->gid, (pcred)->egid
66855+
66856+#define GR_CHROOT_CAPS {{ \
66857+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
66858+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
66859+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
66860+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
66861+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
66862+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
66863+ CAP_TO_MASK(CAP_MAC_ADMIN) }}
66864+
66865+#define security_learn(normal_msg,args...) \
66866+({ \
66867+ read_lock(&grsec_exec_file_lock); \
66868+ gr_add_learn_entry(normal_msg "\n", ## args); \
66869+ read_unlock(&grsec_exec_file_lock); \
66870+})
66871+
66872+enum {
66873+ GR_DO_AUDIT,
66874+ GR_DONT_AUDIT,
66875+ GR_DONT_AUDIT_GOOD
66876+};
66877+
66878+enum {
66879+ GR_TTYSNIFF,
66880+ GR_RBAC,
66881+ GR_RBAC_STR,
66882+ GR_STR_RBAC,
66883+ GR_RBAC_MODE2,
66884+ GR_RBAC_MODE3,
66885+ GR_FILENAME,
66886+ GR_SYSCTL_HIDDEN,
66887+ GR_NOARGS,
66888+ GR_ONE_INT,
66889+ GR_ONE_INT_TWO_STR,
66890+ GR_ONE_STR,
66891+ GR_STR_INT,
66892+ GR_TWO_STR_INT,
66893+ GR_TWO_INT,
66894+ GR_TWO_U64,
66895+ GR_THREE_INT,
66896+ GR_FIVE_INT_TWO_STR,
66897+ GR_TWO_STR,
66898+ GR_THREE_STR,
66899+ GR_FOUR_STR,
66900+ GR_STR_FILENAME,
66901+ GR_FILENAME_STR,
66902+ GR_FILENAME_TWO_INT,
66903+ GR_FILENAME_TWO_INT_STR,
66904+ GR_TEXTREL,
66905+ GR_PTRACE,
66906+ GR_RESOURCE,
66907+ GR_CAP,
66908+ GR_SIG,
66909+ GR_SIG2,
66910+ GR_CRASH1,
66911+ GR_CRASH2,
66912+ GR_PSACCT,
66913+ GR_RWXMAP
66914+};
66915+
66916+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
66917+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
66918+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
66919+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
66920+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
66921+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
66922+#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)
66923+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
66924+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
66925+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
66926+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
66927+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
66928+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
66929+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
66930+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
66931+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
66932+#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)
66933+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
66934+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
66935+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
66936+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
66937+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
66938+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
66939+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
66940+#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)
66941+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
66942+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
66943+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
66944+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
66945+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
66946+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
66947+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
66948+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
66949+#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)
66950+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
66951+
66952+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
66953+
66954+#endif
66955+
66956+#endif
66957diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
66958new file mode 100644
66959index 0000000..9d5fd4a
66960--- /dev/null
66961+++ b/include/linux/grmsg.h
66962@@ -0,0 +1,108 @@
66963+#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"
66964+#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"
66965+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
66966+#define GR_STOPMOD_MSG "denied modification of module state by "
66967+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
66968+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
66969+#define GR_IOPERM_MSG "denied use of ioperm() by "
66970+#define GR_IOPL_MSG "denied use of iopl() by "
66971+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
66972+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
66973+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
66974+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
66975+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
66976+#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"
66977+#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"
66978+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
66979+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
66980+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
66981+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
66982+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
66983+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
66984+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
66985+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
66986+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
66987+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
66988+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
66989+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
66990+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
66991+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
66992+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
66993+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
66994+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
66995+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
66996+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
66997+#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
66998+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
66999+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
67000+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
67001+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
67002+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
67003+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
67004+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
67005+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
67006+#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
67007+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
67008+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
67009+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
67010+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
67011+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
67012+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
67013+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
67014+#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"
67015+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
67016+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
67017+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
67018+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
67019+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
67020+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
67021+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
67022+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
67023+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
67024+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
67025+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
67026+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
67027+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
67028+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
67029+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
67030+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
67031+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
67032+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
67033+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
67034+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
67035+#define GR_FAILFORK_MSG "failed fork with errno %s by "
67036+#define GR_NICE_CHROOT_MSG "denied priority change by "
67037+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
67038+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
67039+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
67040+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
67041+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
67042+#define GR_TIME_MSG "time set by "
67043+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
67044+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
67045+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
67046+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
67047+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
67048+#define GR_BIND_MSG "denied bind() by "
67049+#define GR_CONNECT_MSG "denied connect() by "
67050+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
67051+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
67052+#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"
67053+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
67054+#define GR_CAP_ACL_MSG "use of %s denied for "
67055+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
67056+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
67057+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
67058+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
67059+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
67060+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
67061+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
67062+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
67063+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
67064+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
67065+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
67066+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
67067+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
67068+#define GR_VM86_MSG "denied use of vm86 by "
67069+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
67070+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
67071diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
67072new file mode 100644
67073index 0000000..24676f4
67074--- /dev/null
67075+++ b/include/linux/grsecurity.h
67076@@ -0,0 +1,218 @@
67077+#ifndef GR_SECURITY_H
67078+#define GR_SECURITY_H
67079+#include <linux/fs.h>
67080+#include <linux/fs_struct.h>
67081+#include <linux/binfmts.h>
67082+#include <linux/gracl.h>
67083+#include <linux/compat.h>
67084+
67085+/* notify of brain-dead configs */
67086+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67087+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
67088+#endif
67089+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
67090+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
67091+#endif
67092+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
67093+#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
67094+#endif
67095+#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
67096+#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
67097+#endif
67098+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
67099+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
67100+#endif
67101+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
67102+#error "CONFIG_PAX enabled, but no PaX options are enabled."
67103+#endif
67104+
67105+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
67106+void gr_handle_brute_check(void);
67107+void gr_handle_kernel_exploit(void);
67108+int gr_process_user_ban(void);
67109+
67110+char gr_roletype_to_char(void);
67111+
67112+int gr_acl_enable_at_secure(void);
67113+
67114+int gr_check_user_change(int real, int effective, int fs);
67115+int gr_check_group_change(int real, int effective, int fs);
67116+
67117+void gr_del_task_from_ip_table(struct task_struct *p);
67118+
67119+int gr_pid_is_chrooted(struct task_struct *p);
67120+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
67121+int gr_handle_chroot_nice(void);
67122+int gr_handle_chroot_sysctl(const int op);
67123+int gr_handle_chroot_setpriority(struct task_struct *p,
67124+ const int niceval);
67125+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
67126+int gr_handle_chroot_chroot(const struct dentry *dentry,
67127+ const struct vfsmount *mnt);
67128+void gr_handle_chroot_chdir(struct path *path);
67129+int gr_handle_chroot_chmod(const struct dentry *dentry,
67130+ const struct vfsmount *mnt, const int mode);
67131+int gr_handle_chroot_mknod(const struct dentry *dentry,
67132+ const struct vfsmount *mnt, const int mode);
67133+int gr_handle_chroot_mount(const struct dentry *dentry,
67134+ const struct vfsmount *mnt,
67135+ const char *dev_name);
67136+int gr_handle_chroot_pivot(void);
67137+int gr_handle_chroot_unix(const pid_t pid);
67138+
67139+int gr_handle_rawio(const struct inode *inode);
67140+
67141+void gr_handle_ioperm(void);
67142+void gr_handle_iopl(void);
67143+
67144+int gr_tpe_allow(const struct file *file);
67145+
67146+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
67147+void gr_clear_chroot_entries(struct task_struct *task);
67148+
67149+void gr_log_forkfail(const int retval);
67150+void gr_log_timechange(void);
67151+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
67152+void gr_log_chdir(const struct dentry *dentry,
67153+ const struct vfsmount *mnt);
67154+void gr_log_chroot_exec(const struct dentry *dentry,
67155+ const struct vfsmount *mnt);
67156+void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
67157+#ifdef CONFIG_COMPAT
67158+void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
67159+#endif
67160+void gr_log_remount(const char *devname, const int retval);
67161+void gr_log_unmount(const char *devname, const int retval);
67162+void gr_log_mount(const char *from, const char *to, const int retval);
67163+void gr_log_textrel(struct vm_area_struct *vma);
67164+void gr_log_rwxmmap(struct file *file);
67165+void gr_log_rwxmprotect(struct file *file);
67166+
67167+int gr_handle_follow_link(const struct inode *parent,
67168+ const struct inode *inode,
67169+ const struct dentry *dentry,
67170+ const struct vfsmount *mnt);
67171+int gr_handle_fifo(const struct dentry *dentry,
67172+ const struct vfsmount *mnt,
67173+ const struct dentry *dir, const int flag,
67174+ const int acc_mode);
67175+int gr_handle_hardlink(const struct dentry *dentry,
67176+ const struct vfsmount *mnt,
67177+ struct inode *inode,
67178+ const int mode, const char *to);
67179+
67180+int gr_is_capable(const int cap);
67181+int gr_is_capable_nolog(const int cap);
67182+void gr_learn_resource(const struct task_struct *task, const int limit,
67183+ const unsigned long wanted, const int gt);
67184+void gr_copy_label(struct task_struct *tsk);
67185+void gr_handle_crash(struct task_struct *task, const int sig);
67186+int gr_handle_signal(const struct task_struct *p, const int sig);
67187+int gr_check_crash_uid(const uid_t uid);
67188+int gr_check_protected_task(const struct task_struct *task);
67189+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
67190+int gr_acl_handle_mmap(const struct file *file,
67191+ const unsigned long prot);
67192+int gr_acl_handle_mprotect(const struct file *file,
67193+ const unsigned long prot);
67194+int gr_check_hidden_task(const struct task_struct *tsk);
67195+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
67196+ const struct vfsmount *mnt);
67197+__u32 gr_acl_handle_utime(const struct dentry *dentry,
67198+ const struct vfsmount *mnt);
67199+__u32 gr_acl_handle_access(const struct dentry *dentry,
67200+ const struct vfsmount *mnt, const int fmode);
67201+__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
67202+ const struct vfsmount *mnt, mode_t mode);
67203+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
67204+ const struct vfsmount *mnt, mode_t mode);
67205+__u32 gr_acl_handle_chown(const struct dentry *dentry,
67206+ const struct vfsmount *mnt);
67207+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
67208+ const struct vfsmount *mnt);
67209+int gr_handle_ptrace(struct task_struct *task, const long request);
67210+int gr_handle_proc_ptrace(struct task_struct *task);
67211+__u32 gr_acl_handle_execve(const struct dentry *dentry,
67212+ const struct vfsmount *mnt);
67213+int gr_check_crash_exec(const struct file *filp);
67214+int gr_acl_is_enabled(void);
67215+void gr_set_kernel_label(struct task_struct *task);
67216+void gr_set_role_label(struct task_struct *task, const uid_t uid,
67217+ const gid_t gid);
67218+int gr_set_proc_label(const struct dentry *dentry,
67219+ const struct vfsmount *mnt,
67220+ const int unsafe_share);
67221+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
67222+ const struct vfsmount *mnt);
67223+__u32 gr_acl_handle_open(const struct dentry *dentry,
67224+ const struct vfsmount *mnt, int acc_mode);
67225+__u32 gr_acl_handle_creat(const struct dentry *dentry,
67226+ const struct dentry *p_dentry,
67227+ const struct vfsmount *p_mnt,
67228+ int open_flags, int acc_mode, const int imode);
67229+void gr_handle_create(const struct dentry *dentry,
67230+ const struct vfsmount *mnt);
67231+void gr_handle_proc_create(const struct dentry *dentry,
67232+ const struct inode *inode);
67233+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
67234+ const struct dentry *parent_dentry,
67235+ const struct vfsmount *parent_mnt,
67236+ const int mode);
67237+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
67238+ const struct dentry *parent_dentry,
67239+ const struct vfsmount *parent_mnt);
67240+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
67241+ const struct vfsmount *mnt);
67242+void gr_handle_delete(const ino_t ino, const dev_t dev);
67243+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
67244+ const struct vfsmount *mnt);
67245+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
67246+ const struct dentry *parent_dentry,
67247+ const struct vfsmount *parent_mnt,
67248+ const char *from);
67249+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
67250+ const struct dentry *parent_dentry,
67251+ const struct vfsmount *parent_mnt,
67252+ const struct dentry *old_dentry,
67253+ const struct vfsmount *old_mnt, const char *to);
67254+int gr_acl_handle_rename(struct dentry *new_dentry,
67255+ struct dentry *parent_dentry,
67256+ const struct vfsmount *parent_mnt,
67257+ struct dentry *old_dentry,
67258+ struct inode *old_parent_inode,
67259+ struct vfsmount *old_mnt, const char *newname);
67260+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
67261+ struct dentry *old_dentry,
67262+ struct dentry *new_dentry,
67263+ struct vfsmount *mnt, const __u8 replace);
67264+__u32 gr_check_link(const struct dentry *new_dentry,
67265+ const struct dentry *parent_dentry,
67266+ const struct vfsmount *parent_mnt,
67267+ const struct dentry *old_dentry,
67268+ const struct vfsmount *old_mnt);
67269+int gr_acl_handle_filldir(const struct file *file, const char *name,
67270+ const unsigned int namelen, const ino_t ino);
67271+
67272+__u32 gr_acl_handle_unix(const struct dentry *dentry,
67273+ const struct vfsmount *mnt);
67274+void gr_acl_handle_exit(void);
67275+void gr_acl_handle_psacct(struct task_struct *task, const long code);
67276+int gr_acl_handle_procpidmem(const struct task_struct *task);
67277+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
67278+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
67279+void gr_audit_ptrace(struct task_struct *task);
67280+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
67281+
67282+#ifdef CONFIG_GRKERNSEC
67283+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
67284+void gr_handle_vm86(void);
67285+void gr_handle_mem_readwrite(u64 from, u64 to);
67286+
67287+extern int grsec_enable_dmesg;
67288+extern int grsec_disable_privio;
67289+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
67290+extern int grsec_enable_chroot_findtask;
67291+#endif
67292+#endif
67293+
67294+#endif
67295diff --git a/include/linux/hdpu_features.h b/include/linux/hdpu_features.h
67296index 6a87154..a3ce57b 100644
67297--- a/include/linux/hdpu_features.h
67298+++ b/include/linux/hdpu_features.h
67299@@ -3,7 +3,7 @@
67300 struct cpustate_t {
67301 spinlock_t lock;
67302 int excl;
67303- int open_count;
67304+ atomic_t open_count;
67305 unsigned char cached_val;
67306 int inited;
67307 unsigned long *set_addr;
67308diff --git a/include/linux/highmem.h b/include/linux/highmem.h
67309index 211ff44..00ab6d7 100644
67310--- a/include/linux/highmem.h
67311+++ b/include/linux/highmem.h
67312@@ -137,6 +137,18 @@ static inline void clear_highpage(struct page *page)
67313 kunmap_atomic(kaddr, KM_USER0);
67314 }
67315
67316+static inline void sanitize_highpage(struct page *page)
67317+{
67318+ void *kaddr;
67319+ unsigned long flags;
67320+
67321+ local_irq_save(flags);
67322+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
67323+ clear_page(kaddr);
67324+ kunmap_atomic(kaddr, KM_CLEARPAGE);
67325+ local_irq_restore(flags);
67326+}
67327+
67328 static inline void zero_user_segments(struct page *page,
67329 unsigned start1, unsigned end1,
67330 unsigned start2, unsigned end2)
67331diff --git a/include/linux/i2c.h b/include/linux/i2c.h
67332index 7b40cda..24eb44e 100644
67333--- a/include/linux/i2c.h
67334+++ b/include/linux/i2c.h
67335@@ -325,6 +325,7 @@ struct i2c_algorithm {
67336 /* To determine what the adapter supports */
67337 u32 (*functionality) (struct i2c_adapter *);
67338 };
67339+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
67340
67341 /*
67342 * i2c_adapter is the structure used to identify a physical i2c bus along
67343diff --git a/include/linux/i2o.h b/include/linux/i2o.h
67344index 4c4e57d..f3c5303 100644
67345--- a/include/linux/i2o.h
67346+++ b/include/linux/i2o.h
67347@@ -564,7 +564,7 @@ struct i2o_controller {
67348 struct i2o_device *exec; /* Executive */
67349 #if BITS_PER_LONG == 64
67350 spinlock_t context_list_lock; /* lock for context_list */
67351- atomic_t context_list_counter; /* needed for unique contexts */
67352+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
67353 struct list_head context_list; /* list of context id's
67354 and pointers */
67355 #endif
67356diff --git a/include/linux/init_task.h b/include/linux/init_task.h
67357index 21a6f5d..dc42eab 100644
67358--- a/include/linux/init_task.h
67359+++ b/include/linux/init_task.h
67360@@ -83,6 +83,12 @@ extern struct group_info init_groups;
67361 #define INIT_IDS
67362 #endif
67363
67364+#ifdef CONFIG_X86
67365+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
67366+#else
67367+#define INIT_TASK_THREAD_INFO
67368+#endif
67369+
67370 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
67371 /*
67372 * Because of the reduced scope of CAP_SETPCAP when filesystem
67373@@ -156,6 +162,7 @@ extern struct cred init_cred;
67374 __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
67375 .comm = "swapper", \
67376 .thread = INIT_THREAD, \
67377+ INIT_TASK_THREAD_INFO \
67378 .fs = &init_fs, \
67379 .files = &init_files, \
67380 .signal = &init_signals, \
67381diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
67382index 4f0a72a..a849599 100644
67383--- a/include/linux/intel-iommu.h
67384+++ b/include/linux/intel-iommu.h
67385@@ -296,7 +296,7 @@ struct iommu_flush {
67386 u8 fm, u64 type);
67387 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
67388 unsigned int size_order, u64 type);
67389-};
67390+} __no_const;
67391
67392 enum {
67393 SR_DMAR_FECTL_REG,
67394diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
67395index c739150..be577b5 100644
67396--- a/include/linux/interrupt.h
67397+++ b/include/linux/interrupt.h
67398@@ -369,7 +369,7 @@ enum
67399 /* map softirq index to softirq name. update 'softirq_to_name' in
67400 * kernel/softirq.c when adding a new softirq.
67401 */
67402-extern char *softirq_to_name[NR_SOFTIRQS];
67403+extern const char * const softirq_to_name[NR_SOFTIRQS];
67404
67405 /* softirq mask and active fields moved to irq_cpustat_t in
67406 * asm/hardirq.h to get better cache usage. KAO
67407@@ -377,12 +377,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
67408
67409 struct softirq_action
67410 {
67411- void (*action)(struct softirq_action *);
67412+ void (*action)(void);
67413 };
67414
67415 asmlinkage void do_softirq(void);
67416 asmlinkage void __do_softirq(void);
67417-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
67418+extern void open_softirq(int nr, void (*action)(void));
67419 extern void softirq_init(void);
67420 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
67421 extern void raise_softirq_irqoff(unsigned int nr);
67422diff --git a/include/linux/irq.h b/include/linux/irq.h
67423index 9e5f45a..025865b 100644
67424--- a/include/linux/irq.h
67425+++ b/include/linux/irq.h
67426@@ -438,12 +438,12 @@ extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
67427 static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
67428 bool boot)
67429 {
67430+#ifdef CONFIG_CPUMASK_OFFSTACK
67431 gfp_t gfp = GFP_ATOMIC;
67432
67433 if (boot)
67434 gfp = GFP_NOWAIT;
67435
67436-#ifdef CONFIG_CPUMASK_OFFSTACK
67437 if (!alloc_cpumask_var_node(&desc->affinity, gfp, node))
67438 return false;
67439
67440diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
67441index 7922742..27306a2 100644
67442--- a/include/linux/kallsyms.h
67443+++ b/include/linux/kallsyms.h
67444@@ -15,7 +15,8 @@
67445
67446 struct module;
67447
67448-#ifdef CONFIG_KALLSYMS
67449+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
67450+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67451 /* Lookup the address for a symbol. Returns 0 if not found. */
67452 unsigned long kallsyms_lookup_name(const char *name);
67453
67454@@ -92,6 +93,15 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
67455 /* Stupid that this does nothing, but I didn't create this mess. */
67456 #define __print_symbol(fmt, addr)
67457 #endif /*CONFIG_KALLSYMS*/
67458+#else /* when included by kallsyms.c, vsnprintf.c, or
67459+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
67460+extern void __print_symbol(const char *fmt, unsigned long address);
67461+extern int sprint_symbol(char *buffer, unsigned long address);
67462+const char *kallsyms_lookup(unsigned long addr,
67463+ unsigned long *symbolsize,
67464+ unsigned long *offset,
67465+ char **modname, char *namebuf);
67466+#endif
67467
67468 /* This macro allows us to keep printk typechecking */
67469 static void __check_printsym_format(const char *fmt, ...)
67470diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
67471index 6adcc29..13369e8 100644
67472--- a/include/linux/kgdb.h
67473+++ b/include/linux/kgdb.h
67474@@ -74,8 +74,8 @@ void kgdb_breakpoint(void);
67475
67476 extern int kgdb_connected;
67477
67478-extern atomic_t kgdb_setting_breakpoint;
67479-extern atomic_t kgdb_cpu_doing_single_step;
67480+extern atomic_unchecked_t kgdb_setting_breakpoint;
67481+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
67482
67483 extern struct task_struct *kgdb_usethread;
67484 extern struct task_struct *kgdb_contthread;
67485@@ -235,7 +235,7 @@ struct kgdb_arch {
67486 int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
67487 void (*remove_all_hw_break)(void);
67488 void (*correct_hw_break)(void);
67489-};
67490+} __do_const;
67491
67492 /**
67493 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
67494@@ -257,14 +257,14 @@ struct kgdb_io {
67495 int (*init) (void);
67496 void (*pre_exception) (void);
67497 void (*post_exception) (void);
67498-};
67499+} __do_const;
67500
67501-extern struct kgdb_arch arch_kgdb_ops;
67502+extern const struct kgdb_arch arch_kgdb_ops;
67503
67504 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
67505
67506-extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
67507-extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
67508+extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
67509+extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
67510
67511 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
67512 extern int kgdb_mem2hex(char *mem, char *buf, int count);
67513diff --git a/include/linux/kmod.h b/include/linux/kmod.h
67514index 384ca8b..83dd97d 100644
67515--- a/include/linux/kmod.h
67516+++ b/include/linux/kmod.h
67517@@ -31,6 +31,8 @@
67518 * usually useless though. */
67519 extern int __request_module(bool wait, const char *name, ...) \
67520 __attribute__((format(printf, 2, 3)));
67521+extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
67522+ __attribute__((format(printf, 3, 4)));
67523 #define request_module(mod...) __request_module(true, mod)
67524 #define request_module_nowait(mod...) __request_module(false, mod)
67525 #define try_then_request_module(x, mod...) \
67526diff --git a/include/linux/kobject.h b/include/linux/kobject.h
67527index 58ae8e0..3950d3c 100644
67528--- a/include/linux/kobject.h
67529+++ b/include/linux/kobject.h
67530@@ -106,7 +106,7 @@ extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);
67531
67532 struct kobj_type {
67533 void (*release)(struct kobject *kobj);
67534- struct sysfs_ops *sysfs_ops;
67535+ const struct sysfs_ops *sysfs_ops;
67536 struct attribute **default_attrs;
67537 };
67538
67539@@ -118,9 +118,9 @@ struct kobj_uevent_env {
67540 };
67541
67542 struct kset_uevent_ops {
67543- int (*filter)(struct kset *kset, struct kobject *kobj);
67544- const char *(*name)(struct kset *kset, struct kobject *kobj);
67545- int (*uevent)(struct kset *kset, struct kobject *kobj,
67546+ int (* const filter)(struct kset *kset, struct kobject *kobj);
67547+ const char *(* const name)(struct kset *kset, struct kobject *kobj);
67548+ int (* const uevent)(struct kset *kset, struct kobject *kobj,
67549 struct kobj_uevent_env *env);
67550 };
67551
67552@@ -132,7 +132,7 @@ struct kobj_attribute {
67553 const char *buf, size_t count);
67554 };
67555
67556-extern struct sysfs_ops kobj_sysfs_ops;
67557+extern const struct sysfs_ops kobj_sysfs_ops;
67558
67559 /**
67560 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
67561@@ -155,14 +155,14 @@ struct kset {
67562 struct list_head list;
67563 spinlock_t list_lock;
67564 struct kobject kobj;
67565- struct kset_uevent_ops *uevent_ops;
67566+ const struct kset_uevent_ops *uevent_ops;
67567 };
67568
67569 extern void kset_init(struct kset *kset);
67570 extern int __must_check kset_register(struct kset *kset);
67571 extern void kset_unregister(struct kset *kset);
67572 extern struct kset * __must_check kset_create_and_add(const char *name,
67573- struct kset_uevent_ops *u,
67574+ const struct kset_uevent_ops *u,
67575 struct kobject *parent_kobj);
67576
67577 static inline struct kset *to_kset(struct kobject *kobj)
67578diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
67579index c728a50..752d821 100644
67580--- a/include/linux/kvm_host.h
67581+++ b/include/linux/kvm_host.h
67582@@ -210,7 +210,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
67583 void vcpu_load(struct kvm_vcpu *vcpu);
67584 void vcpu_put(struct kvm_vcpu *vcpu);
67585
67586-int kvm_init(void *opaque, unsigned int vcpu_size,
67587+int kvm_init(const void *opaque, unsigned int vcpu_size,
67588 struct module *module);
67589 void kvm_exit(void);
67590
67591@@ -316,7 +316,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
67592 struct kvm_guest_debug *dbg);
67593 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
67594
67595-int kvm_arch_init(void *opaque);
67596+int kvm_arch_init(const void *opaque);
67597 void kvm_arch_exit(void);
67598
67599 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
67600diff --git a/include/linux/libata.h b/include/linux/libata.h
67601index a069916..223edde 100644
67602--- a/include/linux/libata.h
67603+++ b/include/linux/libata.h
67604@@ -525,11 +525,11 @@ struct ata_ioports {
67605
67606 struct ata_host {
67607 spinlock_t lock;
67608- struct device *dev;
67609+ struct device *dev;
67610 void __iomem * const *iomap;
67611 unsigned int n_ports;
67612 void *private_data;
67613- struct ata_port_operations *ops;
67614+ const struct ata_port_operations *ops;
67615 unsigned long flags;
67616 #ifdef CONFIG_ATA_ACPI
67617 acpi_handle acpi_handle;
67618@@ -710,7 +710,7 @@ struct ata_link {
67619
67620 struct ata_port {
67621 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
67622- struct ata_port_operations *ops;
67623+ const struct ata_port_operations *ops;
67624 spinlock_t *lock;
67625 /* Flags owned by the EH context. Only EH should touch these once the
67626 port is active */
67627@@ -884,7 +884,7 @@ struct ata_port_operations {
67628 * fields must be pointers.
67629 */
67630 const struct ata_port_operations *inherits;
67631-};
67632+} __do_const;
67633
67634 struct ata_port_info {
67635 unsigned long flags;
67636@@ -892,7 +892,7 @@ struct ata_port_info {
67637 unsigned long pio_mask;
67638 unsigned long mwdma_mask;
67639 unsigned long udma_mask;
67640- struct ata_port_operations *port_ops;
67641+ const struct ata_port_operations *port_ops;
67642 void *private_data;
67643 };
67644
67645@@ -916,7 +916,7 @@ extern const unsigned long sata_deb_timing_normal[];
67646 extern const unsigned long sata_deb_timing_hotplug[];
67647 extern const unsigned long sata_deb_timing_long[];
67648
67649-extern struct ata_port_operations ata_dummy_port_ops;
67650+extern const struct ata_port_operations ata_dummy_port_ops;
67651 extern const struct ata_port_info ata_dummy_port_info;
67652
67653 static inline const unsigned long *
67654@@ -962,7 +962,7 @@ extern int ata_host_activate(struct ata_host *host, int irq,
67655 struct scsi_host_template *sht);
67656 extern void ata_host_detach(struct ata_host *host);
67657 extern void ata_host_init(struct ata_host *, struct device *,
67658- unsigned long, struct ata_port_operations *);
67659+ unsigned long, const struct ata_port_operations *);
67660 extern int ata_scsi_detect(struct scsi_host_template *sht);
67661 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
67662 extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
67663diff --git a/include/linux/lockd/bind.h b/include/linux/lockd/bind.h
67664index fbc48f8..0886e57 100644
67665--- a/include/linux/lockd/bind.h
67666+++ b/include/linux/lockd/bind.h
67667@@ -23,13 +23,13 @@ struct svc_rqst;
67668 * This is the set of functions for lockd->nfsd communication
67669 */
67670 struct nlmsvc_binding {
67671- __be32 (*fopen)(struct svc_rqst *,
67672+ __be32 (* const fopen)(struct svc_rqst *,
67673 struct nfs_fh *,
67674 struct file **);
67675- void (*fclose)(struct file *);
67676+ void (* const fclose)(struct file *);
67677 };
67678
67679-extern struct nlmsvc_binding * nlmsvc_ops;
67680+extern const struct nlmsvc_binding * nlmsvc_ops;
67681
67682 /*
67683 * Similar to nfs_client_initdata, but without the NFS-specific
67684diff --git a/include/linux/mca.h b/include/linux/mca.h
67685index 3797270..7765ede 100644
67686--- a/include/linux/mca.h
67687+++ b/include/linux/mca.h
67688@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
67689 int region);
67690 void * (*mca_transform_memory)(struct mca_device *,
67691 void *memory);
67692-};
67693+} __no_const;
67694
67695 struct mca_bus {
67696 u64 default_dma_mask;
67697diff --git a/include/linux/memory.h b/include/linux/memory.h
67698index 37fa19b..b597c85 100644
67699--- a/include/linux/memory.h
67700+++ b/include/linux/memory.h
67701@@ -108,7 +108,7 @@ struct memory_accessor {
67702 size_t count);
67703 ssize_t (*write)(struct memory_accessor *, const char *buf,
67704 off_t offset, size_t count);
67705-};
67706+} __no_const;
67707
67708 /*
67709 * Kernel text modification mutex, used for code patching. Users of this lock
67710diff --git a/include/linux/mm.h b/include/linux/mm.h
67711index 11e5be6..1ff2423 100644
67712--- a/include/linux/mm.h
67713+++ b/include/linux/mm.h
67714@@ -106,7 +106,14 @@ extern unsigned int kobjsize(const void *objp);
67715
67716 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
67717 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
67718+
67719+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
67720+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
67721+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
67722+#else
67723 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
67724+#endif
67725+
67726 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
67727 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
67728
67729@@ -841,12 +848,6 @@ int set_page_dirty(struct page *page);
67730 int set_page_dirty_lock(struct page *page);
67731 int clear_page_dirty_for_io(struct page *page);
67732
67733-/* Is the vma a continuation of the stack vma above it? */
67734-static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
67735-{
67736- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
67737-}
67738-
67739 extern unsigned long move_page_tables(struct vm_area_struct *vma,
67740 unsigned long old_addr, struct vm_area_struct *new_vma,
67741 unsigned long new_addr, unsigned long len);
67742@@ -890,6 +891,8 @@ struct shrinker {
67743 extern void register_shrinker(struct shrinker *);
67744 extern void unregister_shrinker(struct shrinker *);
67745
67746+pgprot_t vm_get_page_prot(unsigned long vm_flags);
67747+
67748 int vma_wants_writenotify(struct vm_area_struct *vma);
67749
67750 extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
67751@@ -1162,6 +1165,7 @@ out:
67752 }
67753
67754 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
67755+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
67756
67757 extern unsigned long do_brk(unsigned long, unsigned long);
67758
67759@@ -1218,6 +1222,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
67760 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
67761 struct vm_area_struct **pprev);
67762
67763+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
67764+extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
67765+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
67766+
67767 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
67768 NULL if none. Assume start_addr < end_addr. */
67769 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
67770@@ -1234,7 +1242,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
67771 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
67772 }
67773
67774-pgprot_t vm_get_page_prot(unsigned long vm_flags);
67775 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
67776 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
67777 unsigned long pfn, unsigned long size, pgprot_t);
67778@@ -1332,7 +1339,13 @@ extern void memory_failure(unsigned long pfn, int trapno);
67779 extern int __memory_failure(unsigned long pfn, int trapno, int ref);
67780 extern int sysctl_memory_failure_early_kill;
67781 extern int sysctl_memory_failure_recovery;
67782-extern atomic_long_t mce_bad_pages;
67783+extern atomic_long_unchecked_t mce_bad_pages;
67784+
67785+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67786+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
67787+#else
67788+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
67789+#endif
67790
67791 #endif /* __KERNEL__ */
67792 #endif /* _LINUX_MM_H */
67793diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
67794index 9d12ed5..6d9707a 100644
67795--- a/include/linux/mm_types.h
67796+++ b/include/linux/mm_types.h
67797@@ -186,6 +186,8 @@ struct vm_area_struct {
67798 #ifdef CONFIG_NUMA
67799 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
67800 #endif
67801+
67802+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
67803 };
67804
67805 struct core_thread {
67806@@ -287,6 +289,24 @@ struct mm_struct {
67807 #ifdef CONFIG_MMU_NOTIFIER
67808 struct mmu_notifier_mm *mmu_notifier_mm;
67809 #endif
67810+
67811+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
67812+ unsigned long pax_flags;
67813+#endif
67814+
67815+#ifdef CONFIG_PAX_DLRESOLVE
67816+ unsigned long call_dl_resolve;
67817+#endif
67818+
67819+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
67820+ unsigned long call_syscall;
67821+#endif
67822+
67823+#ifdef CONFIG_PAX_ASLR
67824+ unsigned long delta_mmap; /* randomized offset */
67825+ unsigned long delta_stack; /* randomized offset */
67826+#endif
67827+
67828 };
67829
67830 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
67831diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
67832index 4e02ee2..afb159e 100644
67833--- a/include/linux/mmu_notifier.h
67834+++ b/include/linux/mmu_notifier.h
67835@@ -235,12 +235,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
67836 */
67837 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
67838 ({ \
67839- pte_t __pte; \
67840+ pte_t ___pte; \
67841 struct vm_area_struct *___vma = __vma; \
67842 unsigned long ___address = __address; \
67843- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
67844+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
67845 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
67846- __pte; \
67847+ ___pte; \
67848 })
67849
67850 #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
67851diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
67852index 6c31a2a..4b0e930 100644
67853--- a/include/linux/mmzone.h
67854+++ b/include/linux/mmzone.h
67855@@ -350,7 +350,7 @@ struct zone {
67856 unsigned long flags; /* zone flags, see below */
67857
67858 /* Zone statistics */
67859- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67860+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67861
67862 /*
67863 * prev_priority holds the scanning priority for this zone. It is
67864diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
67865index f58e9d8..3503935 100644
67866--- a/include/linux/mod_devicetable.h
67867+++ b/include/linux/mod_devicetable.h
67868@@ -12,7 +12,7 @@
67869 typedef unsigned long kernel_ulong_t;
67870 #endif
67871
67872-#define PCI_ANY_ID (~0)
67873+#define PCI_ANY_ID ((__u16)~0)
67874
67875 struct pci_device_id {
67876 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
67877@@ -131,7 +131,7 @@ struct usb_device_id {
67878 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
67879 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
67880
67881-#define HID_ANY_ID (~0)
67882+#define HID_ANY_ID (~0U)
67883
67884 struct hid_device_id {
67885 __u16 bus;
67886diff --git a/include/linux/module.h b/include/linux/module.h
67887index 482efc8..642032b 100644
67888--- a/include/linux/module.h
67889+++ b/include/linux/module.h
67890@@ -16,6 +16,7 @@
67891 #include <linux/kobject.h>
67892 #include <linux/moduleparam.h>
67893 #include <linux/tracepoint.h>
67894+#include <linux/fs.h>
67895
67896 #include <asm/local.h>
67897 #include <asm/module.h>
67898@@ -287,16 +288,16 @@ struct module
67899 int (*init)(void);
67900
67901 /* If this is non-NULL, vfree after init() returns */
67902- void *module_init;
67903+ void *module_init_rx, *module_init_rw;
67904
67905 /* Here is the actual code + data, vfree'd on unload. */
67906- void *module_core;
67907+ void *module_core_rx, *module_core_rw;
67908
67909 /* Here are the sizes of the init and core sections */
67910- unsigned int init_size, core_size;
67911+ unsigned int init_size_rw, core_size_rw;
67912
67913 /* The size of the executable code in each section. */
67914- unsigned int init_text_size, core_text_size;
67915+ unsigned int init_size_rx, core_size_rx;
67916
67917 /* Arch-specific module values */
67918 struct mod_arch_specific arch;
67919@@ -345,6 +346,10 @@ struct module
67920 #ifdef CONFIG_EVENT_TRACING
67921 struct ftrace_event_call *trace_events;
67922 unsigned int num_trace_events;
67923+ struct file_operations trace_id;
67924+ struct file_operations trace_enable;
67925+ struct file_operations trace_format;
67926+ struct file_operations trace_filter;
67927 #endif
67928 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
67929 unsigned long *ftrace_callsites;
67930@@ -393,16 +398,46 @@ struct module *__module_address(unsigned long addr);
67931 bool is_module_address(unsigned long addr);
67932 bool is_module_text_address(unsigned long addr);
67933
67934+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
67935+{
67936+
67937+#ifdef CONFIG_PAX_KERNEXEC
67938+ if (ktla_ktva(addr) >= (unsigned long)start &&
67939+ ktla_ktva(addr) < (unsigned long)start + size)
67940+ return 1;
67941+#endif
67942+
67943+ return ((void *)addr >= start && (void *)addr < start + size);
67944+}
67945+
67946+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
67947+{
67948+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
67949+}
67950+
67951+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
67952+{
67953+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
67954+}
67955+
67956+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
67957+{
67958+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
67959+}
67960+
67961+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
67962+{
67963+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
67964+}
67965+
67966 static inline int within_module_core(unsigned long addr, struct module *mod)
67967 {
67968- return (unsigned long)mod->module_core <= addr &&
67969- addr < (unsigned long)mod->module_core + mod->core_size;
67970+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
67971 }
67972
67973 static inline int within_module_init(unsigned long addr, struct module *mod)
67974 {
67975- return (unsigned long)mod->module_init <= addr &&
67976- addr < (unsigned long)mod->module_init + mod->init_size;
67977+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
67978 }
67979
67980 /* Search for module by name: must hold module_mutex. */
67981diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
67982index c1f40c2..682ca53 100644
67983--- a/include/linux/moduleloader.h
67984+++ b/include/linux/moduleloader.h
67985@@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
67986 sections. Returns NULL on failure. */
67987 void *module_alloc(unsigned long size);
67988
67989+#ifdef CONFIG_PAX_KERNEXEC
67990+void *module_alloc_exec(unsigned long size);
67991+#else
67992+#define module_alloc_exec(x) module_alloc(x)
67993+#endif
67994+
67995 /* Free memory returned from module_alloc. */
67996 void module_free(struct module *mod, void *module_region);
67997
67998+#ifdef CONFIG_PAX_KERNEXEC
67999+void module_free_exec(struct module *mod, void *module_region);
68000+#else
68001+#define module_free_exec(x, y) module_free((x), (y))
68002+#endif
68003+
68004 /* Apply the given relocation to the (simplified) ELF. Return -error
68005 or 0. */
68006 int apply_relocate(Elf_Shdr *sechdrs,
68007diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
68008index 82a9124..8a5f622 100644
68009--- a/include/linux/moduleparam.h
68010+++ b/include/linux/moduleparam.h
68011@@ -132,7 +132,7 @@ struct kparam_array
68012
68013 /* Actually copy string: maxlen param is usually sizeof(string). */
68014 #define module_param_string(name, string, len, perm) \
68015- static const struct kparam_string __param_string_##name \
68016+ static const struct kparam_string __param_string_##name __used \
68017 = { len, string }; \
68018 __module_param_call(MODULE_PARAM_PREFIX, name, \
68019 param_set_copystring, param_get_string, \
68020@@ -211,7 +211,7 @@ extern int param_get_invbool(char *buffer, struct kernel_param *kp);
68021
68022 /* Comma-separated array: *nump is set to number they actually specified. */
68023 #define module_param_array_named(name, array, type, nump, perm) \
68024- static const struct kparam_array __param_arr_##name \
68025+ static const struct kparam_array __param_arr_##name __used \
68026 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
68027 sizeof(array[0]), array }; \
68028 __module_param_call(MODULE_PARAM_PREFIX, name, \
68029diff --git a/include/linux/mutex.h b/include/linux/mutex.h
68030index 878cab4..c92cb3e 100644
68031--- a/include/linux/mutex.h
68032+++ b/include/linux/mutex.h
68033@@ -51,7 +51,7 @@ struct mutex {
68034 spinlock_t wait_lock;
68035 struct list_head wait_list;
68036 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
68037- struct thread_info *owner;
68038+ struct task_struct *owner;
68039 #endif
68040 #ifdef CONFIG_DEBUG_MUTEXES
68041 const char *name;
68042diff --git a/include/linux/namei.h b/include/linux/namei.h
68043index ec0f607..d19e675 100644
68044--- a/include/linux/namei.h
68045+++ b/include/linux/namei.h
68046@@ -22,7 +22,7 @@ struct nameidata {
68047 unsigned int flags;
68048 int last_type;
68049 unsigned depth;
68050- char *saved_names[MAX_NESTED_LINKS + 1];
68051+ const char *saved_names[MAX_NESTED_LINKS + 1];
68052
68053 /* Intent data */
68054 union {
68055@@ -84,12 +84,12 @@ extern int follow_up(struct path *);
68056 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
68057 extern void unlock_rename(struct dentry *, struct dentry *);
68058
68059-static inline void nd_set_link(struct nameidata *nd, char *path)
68060+static inline void nd_set_link(struct nameidata *nd, const char *path)
68061 {
68062 nd->saved_names[nd->depth] = path;
68063 }
68064
68065-static inline char *nd_get_link(struct nameidata *nd)
68066+static inline const char *nd_get_link(const struct nameidata *nd)
68067 {
68068 return nd->saved_names[nd->depth];
68069 }
68070diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
68071index 9d7e8f7..04428c5 100644
68072--- a/include/linux/netdevice.h
68073+++ b/include/linux/netdevice.h
68074@@ -637,6 +637,7 @@ struct net_device_ops {
68075 u16 xid);
68076 #endif
68077 };
68078+typedef struct net_device_ops __no_const net_device_ops_no_const;
68079
68080 /*
68081 * The DEVICE structure.
68082diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
68083new file mode 100644
68084index 0000000..33f4af8
68085--- /dev/null
68086+++ b/include/linux/netfilter/xt_gradm.h
68087@@ -0,0 +1,9 @@
68088+#ifndef _LINUX_NETFILTER_XT_GRADM_H
68089+#define _LINUX_NETFILTER_XT_GRADM_H 1
68090+
68091+struct xt_gradm_mtinfo {
68092+ __u16 flags;
68093+ __u16 invflags;
68094+};
68095+
68096+#endif
68097diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
68098index b359c4a..c08b334 100644
68099--- a/include/linux/nodemask.h
68100+++ b/include/linux/nodemask.h
68101@@ -464,11 +464,11 @@ static inline int num_node_state(enum node_states state)
68102
68103 #define any_online_node(mask) \
68104 ({ \
68105- int node; \
68106- for_each_node_mask(node, (mask)) \
68107- if (node_online(node)) \
68108+ int __node; \
68109+ for_each_node_mask(__node, (mask)) \
68110+ if (node_online(__node)) \
68111 break; \
68112- node; \
68113+ __node; \
68114 })
68115
68116 #define num_online_nodes() num_node_state(N_ONLINE)
68117diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
68118index 5171639..7cf4235 100644
68119--- a/include/linux/oprofile.h
68120+++ b/include/linux/oprofile.h
68121@@ -129,9 +129,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
68122 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
68123 char const * name, ulong * val);
68124
68125-/** Create a file for read-only access to an atomic_t. */
68126+/** Create a file for read-only access to an atomic_unchecked_t. */
68127 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
68128- char const * name, atomic_t * val);
68129+ char const * name, atomic_unchecked_t * val);
68130
68131 /** create a directory */
68132 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
68133diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
68134index 3c62ed4..8924c7c 100644
68135--- a/include/linux/pagemap.h
68136+++ b/include/linux/pagemap.h
68137@@ -425,7 +425,9 @@ static inline int fault_in_pages_readable(const char __user *uaddr, int size)
68138 if (((unsigned long)uaddr & PAGE_MASK) !=
68139 ((unsigned long)end & PAGE_MASK))
68140 ret = __get_user(c, end);
68141+ (void)c;
68142 }
68143+ (void)c;
68144 return ret;
68145 }
68146
68147diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
68148index 81c9689..a567a55 100644
68149--- a/include/linux/perf_event.h
68150+++ b/include/linux/perf_event.h
68151@@ -476,7 +476,7 @@ struct hw_perf_event {
68152 struct hrtimer hrtimer;
68153 };
68154 };
68155- atomic64_t prev_count;
68156+ atomic64_unchecked_t prev_count;
68157 u64 sample_period;
68158 u64 last_period;
68159 atomic64_t period_left;
68160@@ -557,7 +557,7 @@ struct perf_event {
68161 const struct pmu *pmu;
68162
68163 enum perf_event_active_state state;
68164- atomic64_t count;
68165+ atomic64_unchecked_t count;
68166
68167 /*
68168 * These are the total time in nanoseconds that the event
68169@@ -595,8 +595,8 @@ struct perf_event {
68170 * These accumulate total time (in nanoseconds) that children
68171 * events have been enabled and running, respectively.
68172 */
68173- atomic64_t child_total_time_enabled;
68174- atomic64_t child_total_time_running;
68175+ atomic64_unchecked_t child_total_time_enabled;
68176+ atomic64_unchecked_t child_total_time_running;
68177
68178 /*
68179 * Protect attach/detach and child_list:
68180diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
68181index b43a9e0..b77d869 100644
68182--- a/include/linux/pipe_fs_i.h
68183+++ b/include/linux/pipe_fs_i.h
68184@@ -46,9 +46,9 @@ struct pipe_inode_info {
68185 wait_queue_head_t wait;
68186 unsigned int nrbufs, curbuf;
68187 struct page *tmp_page;
68188- unsigned int readers;
68189- unsigned int writers;
68190- unsigned int waiting_writers;
68191+ atomic_t readers;
68192+ atomic_t writers;
68193+ atomic_t waiting_writers;
68194 unsigned int r_counter;
68195 unsigned int w_counter;
68196 struct fasync_struct *fasync_readers;
68197diff --git a/include/linux/poison.h b/include/linux/poison.h
68198index 34066ff..e95d744 100644
68199--- a/include/linux/poison.h
68200+++ b/include/linux/poison.h
68201@@ -19,8 +19,8 @@
68202 * under normal circumstances, used to verify that nobody uses
68203 * non-initialized list entries.
68204 */
68205-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
68206-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
68207+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
68208+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
68209
68210 /********** include/linux/timer.h **********/
68211 /*
68212diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
68213index 4f71bf4..77ffa64 100644
68214--- a/include/linux/posix-timers.h
68215+++ b/include/linux/posix-timers.h
68216@@ -67,7 +67,7 @@ struct k_itimer {
68217 };
68218
68219 struct k_clock {
68220- int res; /* in nanoseconds */
68221+ const int res; /* in nanoseconds */
68222 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
68223 int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
68224 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
68225diff --git a/include/linux/preempt.h b/include/linux/preempt.h
68226index 72b1a10..13303a9 100644
68227--- a/include/linux/preempt.h
68228+++ b/include/linux/preempt.h
68229@@ -110,7 +110,7 @@ struct preempt_ops {
68230 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
68231 void (*sched_out)(struct preempt_notifier *notifier,
68232 struct task_struct *next);
68233-};
68234+} __no_const;
68235
68236 /**
68237 * preempt_notifier - key for installing preemption notifiers
68238diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
68239index 379eaed..1bf73e3 100644
68240--- a/include/linux/proc_fs.h
68241+++ b/include/linux/proc_fs.h
68242@@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
68243 return proc_create_data(name, mode, parent, proc_fops, NULL);
68244 }
68245
68246+static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
68247+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
68248+{
68249+#ifdef CONFIG_GRKERNSEC_PROC_USER
68250+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
68251+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68252+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
68253+#else
68254+ return proc_create_data(name, mode, parent, proc_fops, NULL);
68255+#endif
68256+}
68257+
68258+
68259 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
68260 mode_t mode, struct proc_dir_entry *base,
68261 read_proc_t *read_proc, void * data)
68262@@ -256,7 +269,7 @@ union proc_op {
68263 int (*proc_show)(struct seq_file *m,
68264 struct pid_namespace *ns, struct pid *pid,
68265 struct task_struct *task);
68266-};
68267+} __no_const;
68268
68269 struct ctl_table_header;
68270 struct ctl_table;
68271diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
68272index 7456d7d..6c1cfc9 100644
68273--- a/include/linux/ptrace.h
68274+++ b/include/linux/ptrace.h
68275@@ -96,10 +96,10 @@ extern void __ptrace_unlink(struct task_struct *child);
68276 extern void exit_ptrace(struct task_struct *tracer);
68277 #define PTRACE_MODE_READ 1
68278 #define PTRACE_MODE_ATTACH 2
68279-/* Returns 0 on success, -errno on denial. */
68280-extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
68281 /* Returns true on success, false on denial. */
68282 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
68283+/* Returns true on success, false on denial. */
68284+extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
68285
68286 static inline int ptrace_reparented(struct task_struct *child)
68287 {
68288diff --git a/include/linux/random.h b/include/linux/random.h
68289index 2948046..3262567 100644
68290--- a/include/linux/random.h
68291+++ b/include/linux/random.h
68292@@ -63,6 +63,11 @@ unsigned long randomize_range(unsigned long start, unsigned long end, unsigned l
68293 u32 random32(void);
68294 void srandom32(u32 seed);
68295
68296+static inline unsigned long pax_get_random_long(void)
68297+{
68298+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
68299+}
68300+
68301 #endif /* __KERNEL___ */
68302
68303 #endif /* _LINUX_RANDOM_H */
68304diff --git a/include/linux/reboot.h b/include/linux/reboot.h
68305index 988e55f..17cb4ef 100644
68306--- a/include/linux/reboot.h
68307+++ b/include/linux/reboot.h
68308@@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
68309 * Architecture-specific implementations of sys_reboot commands.
68310 */
68311
68312-extern void machine_restart(char *cmd);
68313-extern void machine_halt(void);
68314-extern void machine_power_off(void);
68315+extern void machine_restart(char *cmd) __noreturn;
68316+extern void machine_halt(void) __noreturn;
68317+extern void machine_power_off(void) __noreturn;
68318
68319 extern void machine_shutdown(void);
68320 struct pt_regs;
68321@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
68322 */
68323
68324 extern void kernel_restart_prepare(char *cmd);
68325-extern void kernel_restart(char *cmd);
68326-extern void kernel_halt(void);
68327-extern void kernel_power_off(void);
68328+extern void kernel_restart(char *cmd) __noreturn;
68329+extern void kernel_halt(void) __noreturn;
68330+extern void kernel_power_off(void) __noreturn;
68331
68332 void ctrl_alt_del(void);
68333
68334@@ -75,7 +75,7 @@ extern int orderly_poweroff(bool force);
68335 * Emergency restart, callable from an interrupt handler.
68336 */
68337
68338-extern void emergency_restart(void);
68339+extern void emergency_restart(void) __noreturn;
68340 #include <asm/emergency-restart.h>
68341
68342 #endif
68343diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
68344index dd31e7b..5b03c5c 100644
68345--- a/include/linux/reiserfs_fs.h
68346+++ b/include/linux/reiserfs_fs.h
68347@@ -1326,7 +1326,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
68348 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
68349
68350 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
68351-#define get_generation(s) atomic_read (&fs_generation(s))
68352+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
68353 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
68354 #define __fs_changed(gen,s) (gen != get_generation (s))
68355 #define fs_changed(gen,s) ({cond_resched(); __fs_changed(gen, s);})
68356@@ -1534,24 +1534,24 @@ static inline struct super_block *sb_from_bi(struct buffer_info *bi)
68357 */
68358
68359 struct item_operations {
68360- int (*bytes_number) (struct item_head * ih, int block_size);
68361- void (*decrement_key) (struct cpu_key *);
68362- int (*is_left_mergeable) (struct reiserfs_key * ih,
68363+ int (* const bytes_number) (struct item_head * ih, int block_size);
68364+ void (* const decrement_key) (struct cpu_key *);
68365+ int (* const is_left_mergeable) (struct reiserfs_key * ih,
68366 unsigned long bsize);
68367- void (*print_item) (struct item_head *, char *item);
68368- void (*check_item) (struct item_head *, char *item);
68369+ void (* const print_item) (struct item_head *, char *item);
68370+ void (* const check_item) (struct item_head *, char *item);
68371
68372- int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
68373+ int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
68374 int is_affected, int insert_size);
68375- int (*check_left) (struct virtual_item * vi, int free,
68376+ int (* const check_left) (struct virtual_item * vi, int free,
68377 int start_skip, int end_skip);
68378- int (*check_right) (struct virtual_item * vi, int free);
68379- int (*part_size) (struct virtual_item * vi, int from, int to);
68380- int (*unit_num) (struct virtual_item * vi);
68381- void (*print_vi) (struct virtual_item * vi);
68382+ int (* const check_right) (struct virtual_item * vi, int free);
68383+ int (* const part_size) (struct virtual_item * vi, int from, int to);
68384+ int (* const unit_num) (struct virtual_item * vi);
68385+ void (* const print_vi) (struct virtual_item * vi);
68386 };
68387
68388-extern struct item_operations *item_ops[TYPE_ANY + 1];
68389+extern const struct item_operations * const item_ops[TYPE_ANY + 1];
68390
68391 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
68392 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
68393diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
68394index dab68bb..0688727 100644
68395--- a/include/linux/reiserfs_fs_sb.h
68396+++ b/include/linux/reiserfs_fs_sb.h
68397@@ -377,7 +377,7 @@ struct reiserfs_sb_info {
68398 /* Comment? -Hans */
68399 wait_queue_head_t s_wait;
68400 /* To be obsoleted soon by per buffer seals.. -Hans */
68401- atomic_t s_generation_counter; // increased by one every time the
68402+ atomic_unchecked_t s_generation_counter; // increased by one every time the
68403 // tree gets re-balanced
68404 unsigned long s_properties; /* File system properties. Currently holds
68405 on-disk FS format */
68406diff --git a/include/linux/relay.h b/include/linux/relay.h
68407index 14a86bc..17d0700 100644
68408--- a/include/linux/relay.h
68409+++ b/include/linux/relay.h
68410@@ -159,7 +159,7 @@ struct rchan_callbacks
68411 * The callback should return 0 if successful, negative if not.
68412 */
68413 int (*remove_buf_file)(struct dentry *dentry);
68414-};
68415+} __no_const;
68416
68417 /*
68418 * CONFIG_RELAY kernel API, kernel/relay.c
68419diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
68420index 3392c59..a746428 100644
68421--- a/include/linux/rfkill.h
68422+++ b/include/linux/rfkill.h
68423@@ -144,6 +144,7 @@ struct rfkill_ops {
68424 void (*query)(struct rfkill *rfkill, void *data);
68425 int (*set_block)(void *data, bool blocked);
68426 };
68427+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
68428
68429 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
68430 /**
68431diff --git a/include/linux/sched.h b/include/linux/sched.h
68432index 71849bf..40217dc 100644
68433--- a/include/linux/sched.h
68434+++ b/include/linux/sched.h
68435@@ -101,6 +101,7 @@ struct bio;
68436 struct fs_struct;
68437 struct bts_context;
68438 struct perf_event_context;
68439+struct linux_binprm;
68440
68441 /*
68442 * List of flags we want to share for kernel threads,
68443@@ -350,7 +351,7 @@ extern signed long schedule_timeout_killable(signed long timeout);
68444 extern signed long schedule_timeout_uninterruptible(signed long timeout);
68445 asmlinkage void __schedule(void);
68446 asmlinkage void schedule(void);
68447-extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
68448+extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
68449
68450 struct nsproxy;
68451 struct user_namespace;
68452@@ -371,9 +372,12 @@ struct user_namespace;
68453 #define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
68454
68455 extern int sysctl_max_map_count;
68456+extern unsigned long sysctl_heap_stack_gap;
68457
68458 #include <linux/aio.h>
68459
68460+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
68461+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
68462 extern unsigned long
68463 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
68464 unsigned long, unsigned long);
68465@@ -666,6 +670,16 @@ struct signal_struct {
68466 struct tty_audit_buf *tty_audit_buf;
68467 #endif
68468
68469+#ifdef CONFIG_GRKERNSEC
68470+ u32 curr_ip;
68471+ u32 saved_ip;
68472+ u32 gr_saddr;
68473+ u32 gr_daddr;
68474+ u16 gr_sport;
68475+ u16 gr_dport;
68476+ u8 used_accept:1;
68477+#endif
68478+
68479 int oom_adj; /* OOM kill score adjustment (bit shift) */
68480 };
68481
68482@@ -723,6 +737,11 @@ struct user_struct {
68483 struct key *session_keyring; /* UID's default session keyring */
68484 #endif
68485
68486+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
68487+ unsigned int banned;
68488+ unsigned long ban_expires;
68489+#endif
68490+
68491 /* Hash table maintenance information */
68492 struct hlist_node uidhash_node;
68493 uid_t uid;
68494@@ -1328,8 +1347,8 @@ struct task_struct {
68495 struct list_head thread_group;
68496
68497 struct completion *vfork_done; /* for vfork() */
68498- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
68499- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
68500+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
68501+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
68502
68503 cputime_t utime, stime, utimescaled, stimescaled;
68504 cputime_t gtime;
68505@@ -1343,16 +1362,6 @@ struct task_struct {
68506 struct task_cputime cputime_expires;
68507 struct list_head cpu_timers[3];
68508
68509-/* process credentials */
68510- const struct cred *real_cred; /* objective and real subjective task
68511- * credentials (COW) */
68512- const struct cred *cred; /* effective (overridable) subjective task
68513- * credentials (COW) */
68514- struct mutex cred_guard_mutex; /* guard against foreign influences on
68515- * credential calculations
68516- * (notably. ptrace) */
68517- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
68518-
68519 char comm[TASK_COMM_LEN]; /* executable name excluding path
68520 - access with [gs]et_task_comm (which lock
68521 it with task_lock())
68522@@ -1369,6 +1378,10 @@ struct task_struct {
68523 #endif
68524 /* CPU-specific state of this task */
68525 struct thread_struct thread;
68526+/* thread_info moved to task_struct */
68527+#ifdef CONFIG_X86
68528+ struct thread_info tinfo;
68529+#endif
68530 /* filesystem information */
68531 struct fs_struct *fs;
68532 /* open file information */
68533@@ -1436,6 +1449,15 @@ struct task_struct {
68534 int hardirq_context;
68535 int softirq_context;
68536 #endif
68537+
68538+/* process credentials */
68539+ const struct cred *real_cred; /* objective and real subjective task
68540+ * credentials (COW) */
68541+ struct mutex cred_guard_mutex; /* guard against foreign influences on
68542+ * credential calculations
68543+ * (notably. ptrace) */
68544+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
68545+
68546 #ifdef CONFIG_LOCKDEP
68547 # define MAX_LOCK_DEPTH 48UL
68548 u64 curr_chain_key;
68549@@ -1456,6 +1478,9 @@ struct task_struct {
68550
68551 struct backing_dev_info *backing_dev_info;
68552
68553+ const struct cred *cred; /* effective (overridable) subjective task
68554+ * credentials (COW) */
68555+
68556 struct io_context *io_context;
68557
68558 unsigned long ptrace_message;
68559@@ -1519,6 +1544,21 @@ struct task_struct {
68560 unsigned long default_timer_slack_ns;
68561
68562 struct list_head *scm_work_list;
68563+
68564+#ifdef CONFIG_GRKERNSEC
68565+ /* grsecurity */
68566+ struct dentry *gr_chroot_dentry;
68567+ struct acl_subject_label *acl;
68568+ struct acl_role_label *role;
68569+ struct file *exec_file;
68570+ u16 acl_role_id;
68571+ /* is this the task that authenticated to the special role */
68572+ u8 acl_sp_role;
68573+ u8 is_writable;
68574+ u8 brute;
68575+ u8 gr_is_chrooted;
68576+#endif
68577+
68578 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
68579 /* Index of current stored adress in ret_stack */
68580 int curr_ret_stack;
68581@@ -1542,6 +1582,57 @@ struct task_struct {
68582 #endif /* CONFIG_TRACING */
68583 };
68584
68585+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
68586+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
68587+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
68588+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
68589+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
68590+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
68591+
68592+#ifdef CONFIG_PAX_SOFTMODE
68593+extern int pax_softmode;
68594+#endif
68595+
68596+extern int pax_check_flags(unsigned long *);
68597+
68598+/* if tsk != current then task_lock must be held on it */
68599+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
68600+static inline unsigned long pax_get_flags(struct task_struct *tsk)
68601+{
68602+ if (likely(tsk->mm))
68603+ return tsk->mm->pax_flags;
68604+ else
68605+ return 0UL;
68606+}
68607+
68608+/* if tsk != current then task_lock must be held on it */
68609+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
68610+{
68611+ if (likely(tsk->mm)) {
68612+ tsk->mm->pax_flags = flags;
68613+ return 0;
68614+ }
68615+ return -EINVAL;
68616+}
68617+#endif
68618+
68619+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68620+extern void pax_set_initial_flags(struct linux_binprm *bprm);
68621+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
68622+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
68623+#endif
68624+
68625+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
68626+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
68627+extern void pax_report_refcount_overflow(struct pt_regs *regs);
68628+extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
68629+
68630+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
68631+extern void pax_track_stack(void);
68632+#else
68633+static inline void pax_track_stack(void) {}
68634+#endif
68635+
68636 /* Future-safe accessor for struct task_struct's cpus_allowed. */
68637 #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed)
68638
68639@@ -1740,7 +1831,7 @@ extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *
68640 #define PF_DUMPCORE 0x00000200 /* dumped core */
68641 #define PF_SIGNALED 0x00000400 /* killed by a signal */
68642 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
68643-#define PF_FLUSHER 0x00001000 /* responsible for disk writeback */
68644+#define PF_NPROC_EXCEEDED 0x00001000 /* set_user noticed that RLIMIT_NPROC was exceeded */
68645 #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
68646 #define PF_FREEZING 0x00004000 /* freeze in progress. do not account to load */
68647 #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */
68648@@ -1978,7 +2069,9 @@ void yield(void);
68649 extern struct exec_domain default_exec_domain;
68650
68651 union thread_union {
68652+#ifndef CONFIG_X86
68653 struct thread_info thread_info;
68654+#endif
68655 unsigned long stack[THREAD_SIZE/sizeof(long)];
68656 };
68657
68658@@ -2011,6 +2104,7 @@ extern struct pid_namespace init_pid_ns;
68659 */
68660
68661 extern struct task_struct *find_task_by_vpid(pid_t nr);
68662+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
68663 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
68664 struct pid_namespace *ns);
68665
68666@@ -2155,7 +2249,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
68667 extern void exit_itimers(struct signal_struct *);
68668 extern void flush_itimer_signals(void);
68669
68670-extern NORET_TYPE void do_group_exit(int);
68671+extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
68672
68673 extern void daemonize(const char *, ...);
68674 extern int allow_signal(int);
68675@@ -2284,13 +2378,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
68676
68677 #endif
68678
68679-static inline int object_is_on_stack(void *obj)
68680+static inline int object_starts_on_stack(void *obj)
68681 {
68682- void *stack = task_stack_page(current);
68683+ const void *stack = task_stack_page(current);
68684
68685 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
68686 }
68687
68688+#ifdef CONFIG_PAX_USERCOPY
68689+extern int object_is_on_stack(const void *obj, unsigned long len);
68690+#endif
68691+
68692 extern void thread_info_cache_init(void);
68693
68694 #ifdef CONFIG_DEBUG_STACK_USAGE
68695diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
68696index 1ee2c05..81b7ec4 100644
68697--- a/include/linux/screen_info.h
68698+++ b/include/linux/screen_info.h
68699@@ -42,7 +42,8 @@ struct screen_info {
68700 __u16 pages; /* 0x32 */
68701 __u16 vesa_attributes; /* 0x34 */
68702 __u32 capabilities; /* 0x36 */
68703- __u8 _reserved[6]; /* 0x3a */
68704+ __u16 vesapm_size; /* 0x3a */
68705+ __u8 _reserved[4]; /* 0x3c */
68706 } __attribute__((packed));
68707
68708 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68709diff --git a/include/linux/security.h b/include/linux/security.h
68710index d40d23f..d739b08 100644
68711--- a/include/linux/security.h
68712+++ b/include/linux/security.h
68713@@ -34,6 +34,7 @@
68714 #include <linux/key.h>
68715 #include <linux/xfrm.h>
68716 #include <linux/gfp.h>
68717+#include <linux/grsecurity.h>
68718 #include <net/flow.h>
68719
68720 /* Maximum number of letters for an LSM name string */
68721@@ -76,7 +77,7 @@ extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
68722 extern int cap_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp);
68723 extern int cap_task_setioprio(struct task_struct *p, int ioprio);
68724 extern int cap_task_setnice(struct task_struct *p, int nice);
68725-extern int cap_syslog(int type);
68726+extern int cap_syslog(int type, bool from_file);
68727 extern int cap_vm_enough_memory(struct mm_struct *mm, long pages);
68728
68729 struct msghdr;
68730@@ -1331,6 +1332,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
68731 * logging to the console.
68732 * See the syslog(2) manual page for an explanation of the @type values.
68733 * @type contains the type of action.
68734+ * @from_file indicates the context of action (if it came from /proc).
68735 * Return 0 if permission is granted.
68736 * @settime:
68737 * Check permission to change the system time.
68738@@ -1445,7 +1447,7 @@ struct security_operations {
68739 int (*sysctl) (struct ctl_table *table, int op);
68740 int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
68741 int (*quota_on) (struct dentry *dentry);
68742- int (*syslog) (int type);
68743+ int (*syslog) (int type, bool from_file);
68744 int (*settime) (struct timespec *ts, struct timezone *tz);
68745 int (*vm_enough_memory) (struct mm_struct *mm, long pages);
68746
68747@@ -1740,7 +1742,7 @@ int security_acct(struct file *file);
68748 int security_sysctl(struct ctl_table *table, int op);
68749 int security_quotactl(int cmds, int type, int id, struct super_block *sb);
68750 int security_quota_on(struct dentry *dentry);
68751-int security_syslog(int type);
68752+int security_syslog(int type, bool from_file);
68753 int security_settime(struct timespec *ts, struct timezone *tz);
68754 int security_vm_enough_memory(long pages);
68755 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
68756@@ -1986,9 +1988,9 @@ static inline int security_quota_on(struct dentry *dentry)
68757 return 0;
68758 }
68759
68760-static inline int security_syslog(int type)
68761+static inline int security_syslog(int type, bool from_file)
68762 {
68763- return cap_syslog(type);
68764+ return cap_syslog(type, from_file);
68765 }
68766
68767 static inline int security_settime(struct timespec *ts, struct timezone *tz)
68768diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
68769index 8366d8f..2307490 100644
68770--- a/include/linux/seq_file.h
68771+++ b/include/linux/seq_file.h
68772@@ -32,6 +32,7 @@ struct seq_operations {
68773 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
68774 int (*show) (struct seq_file *m, void *v);
68775 };
68776+typedef struct seq_operations __no_const seq_operations_no_const;
68777
68778 #define SEQ_SKIP 1
68779
68780diff --git a/include/linux/shm.h b/include/linux/shm.h
68781index eca6235..c7417ed 100644
68782--- a/include/linux/shm.h
68783+++ b/include/linux/shm.h
68784@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the kernel */
68785 pid_t shm_cprid;
68786 pid_t shm_lprid;
68787 struct user_struct *mlock_user;
68788+#ifdef CONFIG_GRKERNSEC
68789+ time_t shm_createtime;
68790+ pid_t shm_lapid;
68791+#endif
68792 };
68793
68794 /* shm_mode upper byte flags */
68795diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
68796index bcdd660..6e12e11 100644
68797--- a/include/linux/skbuff.h
68798+++ b/include/linux/skbuff.h
68799@@ -14,6 +14,7 @@
68800 #ifndef _LINUX_SKBUFF_H
68801 #define _LINUX_SKBUFF_H
68802
68803+#include <linux/const.h>
68804 #include <linux/kernel.h>
68805 #include <linux/kmemcheck.h>
68806 #include <linux/compiler.h>
68807@@ -544,7 +545,7 @@ static inline union skb_shared_tx *skb_tx(struct sk_buff *skb)
68808 */
68809 static inline int skb_queue_empty(const struct sk_buff_head *list)
68810 {
68811- return list->next == (struct sk_buff *)list;
68812+ return list->next == (const struct sk_buff *)list;
68813 }
68814
68815 /**
68816@@ -557,7 +558,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
68817 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
68818 const struct sk_buff *skb)
68819 {
68820- return (skb->next == (struct sk_buff *) list);
68821+ return (skb->next == (const struct sk_buff *) list);
68822 }
68823
68824 /**
68825@@ -570,7 +571,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
68826 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
68827 const struct sk_buff *skb)
68828 {
68829- return (skb->prev == (struct sk_buff *) list);
68830+ return (skb->prev == (const struct sk_buff *) list);
68831 }
68832
68833 /**
68834@@ -1367,7 +1368,7 @@ static inline int skb_network_offset(const struct sk_buff *skb)
68835 * headroom, you should not reduce this.
68836 */
68837 #ifndef NET_SKB_PAD
68838-#define NET_SKB_PAD 32
68839+#define NET_SKB_PAD (_AC(32,UL))
68840 #endif
68841
68842 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
68843diff --git a/include/linux/slab.h b/include/linux/slab.h
68844index 2da8372..a3be824 100644
68845--- a/include/linux/slab.h
68846+++ b/include/linux/slab.h
68847@@ -11,12 +11,20 @@
68848
68849 #include <linux/gfp.h>
68850 #include <linux/types.h>
68851+#include <linux/err.h>
68852
68853 /*
68854 * Flags to pass to kmem_cache_create().
68855 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
68856 */
68857 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
68858+
68859+#ifdef CONFIG_PAX_USERCOPY
68860+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
68861+#else
68862+#define SLAB_USERCOPY 0x00000000UL
68863+#endif
68864+
68865 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
68866 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
68867 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
68868@@ -82,10 +90,13 @@
68869 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
68870 * Both make kfree a no-op.
68871 */
68872-#define ZERO_SIZE_PTR ((void *)16)
68873+#define ZERO_SIZE_PTR \
68874+({ \
68875+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
68876+ (void *)(-MAX_ERRNO-1L); \
68877+})
68878
68879-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
68880- (unsigned long)ZERO_SIZE_PTR)
68881+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
68882
68883 /*
68884 * struct kmem_cache related prototypes
68885@@ -138,6 +149,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
68886 void kfree(const void *);
68887 void kzfree(const void *);
68888 size_t ksize(const void *);
68889+void check_object_size(const void *ptr, unsigned long n, bool to);
68890
68891 /*
68892 * Allocator specific definitions. These are mainly used to establish optimized
68893@@ -328,4 +340,37 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
68894
68895 void __init kmem_cache_init_late(void);
68896
68897+#define kmalloc(x, y) \
68898+({ \
68899+ void *___retval; \
68900+ intoverflow_t ___x = (intoverflow_t)x; \
68901+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n"))\
68902+ ___retval = NULL; \
68903+ else \
68904+ ___retval = kmalloc((size_t)___x, (y)); \
68905+ ___retval; \
68906+})
68907+
68908+#define kmalloc_node(x, y, z) \
68909+({ \
68910+ void *___retval; \
68911+ intoverflow_t ___x = (intoverflow_t)x; \
68912+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
68913+ ___retval = NULL; \
68914+ else \
68915+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
68916+ ___retval; \
68917+})
68918+
68919+#define kzalloc(x, y) \
68920+({ \
68921+ void *___retval; \
68922+ intoverflow_t ___x = (intoverflow_t)x; \
68923+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n"))\
68924+ ___retval = NULL; \
68925+ else \
68926+ ___retval = kzalloc((size_t)___x, (y)); \
68927+ ___retval; \
68928+})
68929+
68930 #endif /* _LINUX_SLAB_H */
68931diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
68932index 850d057..d9dfe3c 100644
68933--- a/include/linux/slab_def.h
68934+++ b/include/linux/slab_def.h
68935@@ -69,10 +69,10 @@ struct kmem_cache {
68936 unsigned long node_allocs;
68937 unsigned long node_frees;
68938 unsigned long node_overflow;
68939- atomic_t allochit;
68940- atomic_t allocmiss;
68941- atomic_t freehit;
68942- atomic_t freemiss;
68943+ atomic_unchecked_t allochit;
68944+ atomic_unchecked_t allocmiss;
68945+ atomic_unchecked_t freehit;
68946+ atomic_unchecked_t freemiss;
68947
68948 /*
68949 * If debugging is enabled, then the allocator can add additional
68950diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
68951index 5ad70a6..57f9f65 100644
68952--- a/include/linux/slub_def.h
68953+++ b/include/linux/slub_def.h
68954@@ -86,7 +86,7 @@ struct kmem_cache {
68955 struct kmem_cache_order_objects max;
68956 struct kmem_cache_order_objects min;
68957 gfp_t allocflags; /* gfp flags to use on each alloc */
68958- int refcount; /* Refcount for slab cache destroy */
68959+ atomic_t refcount; /* Refcount for slab cache destroy */
68960 void (*ctor)(void *);
68961 int inuse; /* Offset to metadata */
68962 int align; /* Alignment */
68963@@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
68964 #endif
68965
68966 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
68967-void *__kmalloc(size_t size, gfp_t flags);
68968+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
68969
68970 #ifdef CONFIG_KMEMTRACE
68971 extern void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags);
68972diff --git a/include/linux/sonet.h b/include/linux/sonet.h
68973index 67ad11f..0bbd8af 100644
68974--- a/include/linux/sonet.h
68975+++ b/include/linux/sonet.h
68976@@ -61,7 +61,7 @@ struct sonet_stats {
68977 #include <asm/atomic.h>
68978
68979 struct k_sonet_stats {
68980-#define __HANDLE_ITEM(i) atomic_t i
68981+#define __HANDLE_ITEM(i) atomic_unchecked_t i
68982 __SONET_ITEMS
68983 #undef __HANDLE_ITEM
68984 };
68985diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
68986index 6f52b4d..5500323 100644
68987--- a/include/linux/sunrpc/cache.h
68988+++ b/include/linux/sunrpc/cache.h
68989@@ -125,7 +125,7 @@ struct cache_detail {
68990 */
68991 struct cache_req {
68992 struct cache_deferred_req *(*defer)(struct cache_req *req);
68993-};
68994+} __no_const;
68995 /* this must be embedded in a deferred_request that is being
68996 * delayed awaiting cache-fill
68997 */
68998diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
68999index 8ed9642..101ceab 100644
69000--- a/include/linux/sunrpc/clnt.h
69001+++ b/include/linux/sunrpc/clnt.h
69002@@ -167,9 +167,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
69003 {
69004 switch (sap->sa_family) {
69005 case AF_INET:
69006- return ntohs(((struct sockaddr_in *)sap)->sin_port);
69007+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
69008 case AF_INET6:
69009- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
69010+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
69011 }
69012 return 0;
69013 }
69014@@ -202,7 +202,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
69015 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
69016 const struct sockaddr *src)
69017 {
69018- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
69019+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
69020 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
69021
69022 dsin->sin_family = ssin->sin_family;
69023@@ -299,7 +299,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
69024 if (sa->sa_family != AF_INET6)
69025 return 0;
69026
69027- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
69028+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
69029 }
69030
69031 #endif /* __KERNEL__ */
69032diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
69033index c14fe86..393245e 100644
69034--- a/include/linux/sunrpc/svc_rdma.h
69035+++ b/include/linux/sunrpc/svc_rdma.h
69036@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
69037 extern unsigned int svcrdma_max_requests;
69038 extern unsigned int svcrdma_max_req_size;
69039
69040-extern atomic_t rdma_stat_recv;
69041-extern atomic_t rdma_stat_read;
69042-extern atomic_t rdma_stat_write;
69043-extern atomic_t rdma_stat_sq_starve;
69044-extern atomic_t rdma_stat_rq_starve;
69045-extern atomic_t rdma_stat_rq_poll;
69046-extern atomic_t rdma_stat_rq_prod;
69047-extern atomic_t rdma_stat_sq_poll;
69048-extern atomic_t rdma_stat_sq_prod;
69049+extern atomic_unchecked_t rdma_stat_recv;
69050+extern atomic_unchecked_t rdma_stat_read;
69051+extern atomic_unchecked_t rdma_stat_write;
69052+extern atomic_unchecked_t rdma_stat_sq_starve;
69053+extern atomic_unchecked_t rdma_stat_rq_starve;
69054+extern atomic_unchecked_t rdma_stat_rq_poll;
69055+extern atomic_unchecked_t rdma_stat_rq_prod;
69056+extern atomic_unchecked_t rdma_stat_sq_poll;
69057+extern atomic_unchecked_t rdma_stat_sq_prod;
69058
69059 #define RPCRDMA_VERSION 1
69060
69061diff --git a/include/linux/suspend.h b/include/linux/suspend.h
69062index 5e781d8..1e62818 100644
69063--- a/include/linux/suspend.h
69064+++ b/include/linux/suspend.h
69065@@ -104,15 +104,15 @@ typedef int __bitwise suspend_state_t;
69066 * which require special recovery actions in that situation.
69067 */
69068 struct platform_suspend_ops {
69069- int (*valid)(suspend_state_t state);
69070- int (*begin)(suspend_state_t state);
69071- int (*prepare)(void);
69072- int (*prepare_late)(void);
69073- int (*enter)(suspend_state_t state);
69074- void (*wake)(void);
69075- void (*finish)(void);
69076- void (*end)(void);
69077- void (*recover)(void);
69078+ int (* const valid)(suspend_state_t state);
69079+ int (* const begin)(suspend_state_t state);
69080+ int (* const prepare)(void);
69081+ int (* const prepare_late)(void);
69082+ int (* const enter)(suspend_state_t state);
69083+ void (* const wake)(void);
69084+ void (* const finish)(void);
69085+ void (* const end)(void);
69086+ void (* const recover)(void);
69087 };
69088
69089 #ifdef CONFIG_SUSPEND
69090@@ -120,7 +120,7 @@ struct platform_suspend_ops {
69091 * suspend_set_ops - set platform dependent suspend operations
69092 * @ops: The new suspend operations to set.
69093 */
69094-extern void suspend_set_ops(struct platform_suspend_ops *ops);
69095+extern void suspend_set_ops(const struct platform_suspend_ops *ops);
69096 extern int suspend_valid_only_mem(suspend_state_t state);
69097
69098 /**
69099@@ -145,7 +145,7 @@ extern int pm_suspend(suspend_state_t state);
69100 #else /* !CONFIG_SUSPEND */
69101 #define suspend_valid_only_mem NULL
69102
69103-static inline void suspend_set_ops(struct platform_suspend_ops *ops) {}
69104+static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
69105 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
69106 #endif /* !CONFIG_SUSPEND */
69107
69108@@ -215,16 +215,16 @@ extern void mark_free_pages(struct zone *zone);
69109 * platforms which require special recovery actions in that situation.
69110 */
69111 struct platform_hibernation_ops {
69112- int (*begin)(void);
69113- void (*end)(void);
69114- int (*pre_snapshot)(void);
69115- void (*finish)(void);
69116- int (*prepare)(void);
69117- int (*enter)(void);
69118- void (*leave)(void);
69119- int (*pre_restore)(void);
69120- void (*restore_cleanup)(void);
69121- void (*recover)(void);
69122+ int (* const begin)(void);
69123+ void (* const end)(void);
69124+ int (* const pre_snapshot)(void);
69125+ void (* const finish)(void);
69126+ int (* const prepare)(void);
69127+ int (* const enter)(void);
69128+ void (* const leave)(void);
69129+ int (* const pre_restore)(void);
69130+ void (* const restore_cleanup)(void);
69131+ void (* const recover)(void);
69132 };
69133
69134 #ifdef CONFIG_HIBERNATION
69135@@ -243,7 +243,7 @@ extern void swsusp_set_page_free(struct page *);
69136 extern void swsusp_unset_page_free(struct page *);
69137 extern unsigned long get_safe_page(gfp_t gfp_mask);
69138
69139-extern void hibernation_set_ops(struct platform_hibernation_ops *ops);
69140+extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
69141 extern int hibernate(void);
69142 extern bool system_entering_hibernation(void);
69143 #else /* CONFIG_HIBERNATION */
69144@@ -251,7 +251,7 @@ static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
69145 static inline void swsusp_set_page_free(struct page *p) {}
69146 static inline void swsusp_unset_page_free(struct page *p) {}
69147
69148-static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {}
69149+static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
69150 static inline int hibernate(void) { return -ENOSYS; }
69151 static inline bool system_entering_hibernation(void) { return false; }
69152 #endif /* CONFIG_HIBERNATION */
69153diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
69154index 0eb6942..a805cb6 100644
69155--- a/include/linux/sysctl.h
69156+++ b/include/linux/sysctl.h
69157@@ -164,7 +164,11 @@ enum
69158 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
69159 };
69160
69161-
69162+#ifdef CONFIG_PAX_SOFTMODE
69163+enum {
69164+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
69165+};
69166+#endif
69167
69168 /* CTL_VM names: */
69169 enum
69170@@ -982,6 +986,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
69171
69172 extern int proc_dostring(struct ctl_table *, int,
69173 void __user *, size_t *, loff_t *);
69174+extern int proc_dostring_modpriv(struct ctl_table *, int,
69175+ void __user *, size_t *, loff_t *);
69176 extern int proc_dointvec(struct ctl_table *, int,
69177 void __user *, size_t *, loff_t *);
69178 extern int proc_dointvec_minmax(struct ctl_table *, int,
69179@@ -1003,6 +1009,7 @@ extern int do_sysctl (int __user *name, int nlen,
69180
69181 extern ctl_handler sysctl_data;
69182 extern ctl_handler sysctl_string;
69183+extern ctl_handler sysctl_string_modpriv;
69184 extern ctl_handler sysctl_intvec;
69185 extern ctl_handler sysctl_jiffies;
69186 extern ctl_handler sysctl_ms_jiffies;
69187diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
69188index 9d68fed..71f02cc 100644
69189--- a/include/linux/sysfs.h
69190+++ b/include/linux/sysfs.h
69191@@ -75,8 +75,8 @@ struct bin_attribute {
69192 };
69193
69194 struct sysfs_ops {
69195- ssize_t (*show)(struct kobject *, struct attribute *,char *);
69196- ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
69197+ ssize_t (* const show)(struct kobject *, struct attribute *,char *);
69198+ ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
69199 };
69200
69201 struct sysfs_dirent;
69202diff --git a/include/linux/syslog.h b/include/linux/syslog.h
69203new file mode 100644
69204index 0000000..3891139
69205--- /dev/null
69206+++ b/include/linux/syslog.h
69207@@ -0,0 +1,52 @@
69208+/* Syslog internals
69209+ *
69210+ * Copyright 2010 Canonical, Ltd.
69211+ * Author: Kees Cook <kees.cook@canonical.com>
69212+ *
69213+ * This program is free software; you can redistribute it and/or modify
69214+ * it under the terms of the GNU General Public License as published by
69215+ * the Free Software Foundation; either version 2, or (at your option)
69216+ * any later version.
69217+ *
69218+ * This program is distributed in the hope that it will be useful,
69219+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
69220+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69221+ * GNU General Public License for more details.
69222+ *
69223+ * You should have received a copy of the GNU General Public License
69224+ * along with this program; see the file COPYING. If not, write to
69225+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
69226+ */
69227+
69228+#ifndef _LINUX_SYSLOG_H
69229+#define _LINUX_SYSLOG_H
69230+
69231+/* Close the log. Currently a NOP. */
69232+#define SYSLOG_ACTION_CLOSE 0
69233+/* Open the log. Currently a NOP. */
69234+#define SYSLOG_ACTION_OPEN 1
69235+/* Read from the log. */
69236+#define SYSLOG_ACTION_READ 2
69237+/* Read all messages remaining in the ring buffer. */
69238+#define SYSLOG_ACTION_READ_ALL 3
69239+/* Read and clear all messages remaining in the ring buffer */
69240+#define SYSLOG_ACTION_READ_CLEAR 4
69241+/* Clear ring buffer. */
69242+#define SYSLOG_ACTION_CLEAR 5
69243+/* Disable printk's to console */
69244+#define SYSLOG_ACTION_CONSOLE_OFF 6
69245+/* Enable printk's to console */
69246+#define SYSLOG_ACTION_CONSOLE_ON 7
69247+/* Set level of messages printed to console */
69248+#define SYSLOG_ACTION_CONSOLE_LEVEL 8
69249+/* Return number of unread characters in the log buffer */
69250+#define SYSLOG_ACTION_SIZE_UNREAD 9
69251+/* Return size of the log buffer */
69252+#define SYSLOG_ACTION_SIZE_BUFFER 10
69253+
69254+#define SYSLOG_FROM_CALL 0
69255+#define SYSLOG_FROM_FILE 1
69256+
69257+int do_syslog(int type, char __user *buf, int count, bool from_file);
69258+
69259+#endif /* _LINUX_SYSLOG_H */
69260diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
69261index a8cc4e1..98d3b85 100644
69262--- a/include/linux/thread_info.h
69263+++ b/include/linux/thread_info.h
69264@@ -23,7 +23,7 @@ struct restart_block {
69265 };
69266 /* For futex_wait and futex_wait_requeue_pi */
69267 struct {
69268- u32 *uaddr;
69269+ u32 __user *uaddr;
69270 u32 val;
69271 u32 flags;
69272 u32 bitset;
69273diff --git a/include/linux/tty.h b/include/linux/tty.h
69274index e9c57e9..ee6d489 100644
69275--- a/include/linux/tty.h
69276+++ b/include/linux/tty.h
69277@@ -493,7 +493,6 @@ extern void tty_ldisc_begin(void);
69278 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
69279 extern void tty_ldisc_enable(struct tty_struct *tty);
69280
69281-
69282 /* n_tty.c */
69283 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
69284
69285diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
69286index 0c4ee9b..9f7c426 100644
69287--- a/include/linux/tty_ldisc.h
69288+++ b/include/linux/tty_ldisc.h
69289@@ -139,7 +139,7 @@ struct tty_ldisc_ops {
69290
69291 struct module *owner;
69292
69293- int refcount;
69294+ atomic_t refcount;
69295 };
69296
69297 struct tty_ldisc {
69298diff --git a/include/linux/types.h b/include/linux/types.h
69299index c42724f..d190eee 100644
69300--- a/include/linux/types.h
69301+++ b/include/linux/types.h
69302@@ -191,10 +191,26 @@ typedef struct {
69303 volatile int counter;
69304 } atomic_t;
69305
69306+#ifdef CONFIG_PAX_REFCOUNT
69307+typedef struct {
69308+ volatile int counter;
69309+} atomic_unchecked_t;
69310+#else
69311+typedef atomic_t atomic_unchecked_t;
69312+#endif
69313+
69314 #ifdef CONFIG_64BIT
69315 typedef struct {
69316 volatile long counter;
69317 } atomic64_t;
69318+
69319+#ifdef CONFIG_PAX_REFCOUNT
69320+typedef struct {
69321+ volatile long counter;
69322+} atomic64_unchecked_t;
69323+#else
69324+typedef atomic64_t atomic64_unchecked_t;
69325+#endif
69326 #endif
69327
69328 struct ustat {
69329diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
69330index 6b58367..53a3e8e 100644
69331--- a/include/linux/uaccess.h
69332+++ b/include/linux/uaccess.h
69333@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
69334 long ret; \
69335 mm_segment_t old_fs = get_fs(); \
69336 \
69337- set_fs(KERNEL_DS); \
69338 pagefault_disable(); \
69339- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
69340- pagefault_enable(); \
69341+ set_fs(KERNEL_DS); \
69342+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
69343 set_fs(old_fs); \
69344+ pagefault_enable(); \
69345 ret; \
69346 })
69347
69348@@ -93,7 +93,7 @@ static inline unsigned long __copy_from_user_nocache(void *to,
69349 * Safely read from address @src to the buffer at @dst. If a kernel fault
69350 * happens, handle that and return -EFAULT.
69351 */
69352-extern long probe_kernel_read(void *dst, void *src, size_t size);
69353+extern long probe_kernel_read(void *dst, const void *src, size_t size);
69354
69355 /*
69356 * probe_kernel_write(): safely attempt to write to a location
69357@@ -104,6 +104,6 @@ extern long probe_kernel_read(void *dst, void *src, size_t size);
69358 * Safely write to address @dst from the buffer at @src. If a kernel fault
69359 * happens, handle that and return -EFAULT.
69360 */
69361-extern long probe_kernel_write(void *dst, void *src, size_t size);
69362+extern long probe_kernel_write(void *dst, const void *src, size_t size);
69363
69364 #endif /* __LINUX_UACCESS_H__ */
69365diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
69366index 99c1b4d..bb94261 100644
69367--- a/include/linux/unaligned/access_ok.h
69368+++ b/include/linux/unaligned/access_ok.h
69369@@ -6,32 +6,32 @@
69370
69371 static inline u16 get_unaligned_le16(const void *p)
69372 {
69373- return le16_to_cpup((__le16 *)p);
69374+ return le16_to_cpup((const __le16 *)p);
69375 }
69376
69377 static inline u32 get_unaligned_le32(const void *p)
69378 {
69379- return le32_to_cpup((__le32 *)p);
69380+ return le32_to_cpup((const __le32 *)p);
69381 }
69382
69383 static inline u64 get_unaligned_le64(const void *p)
69384 {
69385- return le64_to_cpup((__le64 *)p);
69386+ return le64_to_cpup((const __le64 *)p);
69387 }
69388
69389 static inline u16 get_unaligned_be16(const void *p)
69390 {
69391- return be16_to_cpup((__be16 *)p);
69392+ return be16_to_cpup((const __be16 *)p);
69393 }
69394
69395 static inline u32 get_unaligned_be32(const void *p)
69396 {
69397- return be32_to_cpup((__be32 *)p);
69398+ return be32_to_cpup((const __be32 *)p);
69399 }
69400
69401 static inline u64 get_unaligned_be64(const void *p)
69402 {
69403- return be64_to_cpup((__be64 *)p);
69404+ return be64_to_cpup((const __be64 *)p);
69405 }
69406
69407 static inline void put_unaligned_le16(u16 val, void *p)
69408diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
69409index 79b9837..b5a56f9 100644
69410--- a/include/linux/vermagic.h
69411+++ b/include/linux/vermagic.h
69412@@ -26,9 +26,35 @@
69413 #define MODULE_ARCH_VERMAGIC ""
69414 #endif
69415
69416+#ifdef CONFIG_PAX_REFCOUNT
69417+#define MODULE_PAX_REFCOUNT "REFCOUNT "
69418+#else
69419+#define MODULE_PAX_REFCOUNT ""
69420+#endif
69421+
69422+#ifdef CONSTIFY_PLUGIN
69423+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
69424+#else
69425+#define MODULE_CONSTIFY_PLUGIN ""
69426+#endif
69427+
69428+#ifdef STACKLEAK_PLUGIN
69429+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
69430+#else
69431+#define MODULE_STACKLEAK_PLUGIN ""
69432+#endif
69433+
69434+#ifdef CONFIG_GRKERNSEC
69435+#define MODULE_GRSEC "GRSEC "
69436+#else
69437+#define MODULE_GRSEC ""
69438+#endif
69439+
69440 #define VERMAGIC_STRING \
69441 UTS_RELEASE " " \
69442 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
69443 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
69444- MODULE_ARCH_VERMAGIC
69445+ MODULE_ARCH_VERMAGIC \
69446+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
69447+ MODULE_GRSEC
69448
69449diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
69450index 819a634..462ac12 100644
69451--- a/include/linux/vmalloc.h
69452+++ b/include/linux/vmalloc.h
69453@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
69454 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
69455 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
69456 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
69457+
69458+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
69459+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
69460+#endif
69461+
69462 /* bits [20..32] reserved for arch specific ioremap internals */
69463
69464 /*
69465@@ -124,4 +129,81 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
69466
69467 void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
69468
69469+#define vmalloc(x) \
69470+({ \
69471+ void *___retval; \
69472+ intoverflow_t ___x = (intoverflow_t)x; \
69473+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
69474+ ___retval = NULL; \
69475+ else \
69476+ ___retval = vmalloc((unsigned long)___x); \
69477+ ___retval; \
69478+})
69479+
69480+#define __vmalloc(x, y, z) \
69481+({ \
69482+ void *___retval; \
69483+ intoverflow_t ___x = (intoverflow_t)x; \
69484+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
69485+ ___retval = NULL; \
69486+ else \
69487+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
69488+ ___retval; \
69489+})
69490+
69491+#define vmalloc_user(x) \
69492+({ \
69493+ void *___retval; \
69494+ intoverflow_t ___x = (intoverflow_t)x; \
69495+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
69496+ ___retval = NULL; \
69497+ else \
69498+ ___retval = vmalloc_user((unsigned long)___x); \
69499+ ___retval; \
69500+})
69501+
69502+#define vmalloc_exec(x) \
69503+({ \
69504+ void *___retval; \
69505+ intoverflow_t ___x = (intoverflow_t)x; \
69506+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
69507+ ___retval = NULL; \
69508+ else \
69509+ ___retval = vmalloc_exec((unsigned long)___x); \
69510+ ___retval; \
69511+})
69512+
69513+#define vmalloc_node(x, y) \
69514+({ \
69515+ void *___retval; \
69516+ intoverflow_t ___x = (intoverflow_t)x; \
69517+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
69518+ ___retval = NULL; \
69519+ else \
69520+ ___retval = vmalloc_node((unsigned long)___x, (y));\
69521+ ___retval; \
69522+})
69523+
69524+#define vmalloc_32(x) \
69525+({ \
69526+ void *___retval; \
69527+ intoverflow_t ___x = (intoverflow_t)x; \
69528+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
69529+ ___retval = NULL; \
69530+ else \
69531+ ___retval = vmalloc_32((unsigned long)___x); \
69532+ ___retval; \
69533+})
69534+
69535+#define vmalloc_32_user(x) \
69536+({ \
69537+ void *___retval; \
69538+ intoverflow_t ___x = (intoverflow_t)x; \
69539+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
69540+ ___retval = NULL; \
69541+ else \
69542+ ___retval = vmalloc_32_user((unsigned long)___x);\
69543+ ___retval; \
69544+})
69545+
69546 #endif /* _LINUX_VMALLOC_H */
69547diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
69548index 13070d6..aa4159a 100644
69549--- a/include/linux/vmstat.h
69550+++ b/include/linux/vmstat.h
69551@@ -136,18 +136,18 @@ static inline void vm_events_fold_cpu(int cpu)
69552 /*
69553 * Zone based page accounting with per cpu differentials.
69554 */
69555-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69556+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69557
69558 static inline void zone_page_state_add(long x, struct zone *zone,
69559 enum zone_stat_item item)
69560 {
69561- atomic_long_add(x, &zone->vm_stat[item]);
69562- atomic_long_add(x, &vm_stat[item]);
69563+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
69564+ atomic_long_add_unchecked(x, &vm_stat[item]);
69565 }
69566
69567 static inline unsigned long global_page_state(enum zone_stat_item item)
69568 {
69569- long x = atomic_long_read(&vm_stat[item]);
69570+ long x = atomic_long_read_unchecked(&vm_stat[item]);
69571 #ifdef CONFIG_SMP
69572 if (x < 0)
69573 x = 0;
69574@@ -158,7 +158,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
69575 static inline unsigned long zone_page_state(struct zone *zone,
69576 enum zone_stat_item item)
69577 {
69578- long x = atomic_long_read(&zone->vm_stat[item]);
69579+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
69580 #ifdef CONFIG_SMP
69581 if (x < 0)
69582 x = 0;
69583@@ -175,7 +175,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
69584 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
69585 enum zone_stat_item item)
69586 {
69587- long x = atomic_long_read(&zone->vm_stat[item]);
69588+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
69589
69590 #ifdef CONFIG_SMP
69591 int cpu;
69592@@ -264,8 +264,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
69593
69594 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
69595 {
69596- atomic_long_inc(&zone->vm_stat[item]);
69597- atomic_long_inc(&vm_stat[item]);
69598+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
69599+ atomic_long_inc_unchecked(&vm_stat[item]);
69600 }
69601
69602 static inline void __inc_zone_page_state(struct page *page,
69603@@ -276,8 +276,8 @@ static inline void __inc_zone_page_state(struct page *page,
69604
69605 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
69606 {
69607- atomic_long_dec(&zone->vm_stat[item]);
69608- atomic_long_dec(&vm_stat[item]);
69609+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
69610+ atomic_long_dec_unchecked(&vm_stat[item]);
69611 }
69612
69613 static inline void __dec_zone_page_state(struct page *page,
69614diff --git a/include/linux/xattr.h b/include/linux/xattr.h
69615index 5c84af8..1a3b6e2 100644
69616--- a/include/linux/xattr.h
69617+++ b/include/linux/xattr.h
69618@@ -33,6 +33,11 @@
69619 #define XATTR_USER_PREFIX "user."
69620 #define XATTR_USER_PREFIX_LEN (sizeof (XATTR_USER_PREFIX) - 1)
69621
69622+/* User namespace */
69623+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
69624+#define XATTR_PAX_FLAGS_SUFFIX "flags"
69625+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
69626+
69627 struct inode;
69628 struct dentry;
69629
69630diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
69631index eed5fcc..5080d24 100644
69632--- a/include/media/saa7146_vv.h
69633+++ b/include/media/saa7146_vv.h
69634@@ -167,7 +167,7 @@ struct saa7146_ext_vv
69635 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
69636
69637 /* the extension can override this */
69638- struct v4l2_ioctl_ops ops;
69639+ v4l2_ioctl_ops_no_const ops;
69640 /* pointer to the saa7146 core ops */
69641 const struct v4l2_ioctl_ops *core_ops;
69642
69643diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
69644index 73c9867..2da8837 100644
69645--- a/include/media/v4l2-dev.h
69646+++ b/include/media/v4l2-dev.h
69647@@ -34,7 +34,7 @@ struct v4l2_device;
69648 #define V4L2_FL_UNREGISTERED (0)
69649
69650 struct v4l2_file_operations {
69651- struct module *owner;
69652+ struct module * const owner;
69653 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
69654 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
69655 unsigned int (*poll) (struct file *, struct poll_table_struct *);
69656@@ -46,6 +46,7 @@ struct v4l2_file_operations {
69657 int (*open) (struct file *);
69658 int (*release) (struct file *);
69659 };
69660+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
69661
69662 /*
69663 * Newer version of video_device, handled by videodev2.c
69664diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
69665index 5d5d550..f559ef1 100644
69666--- a/include/media/v4l2-device.h
69667+++ b/include/media/v4l2-device.h
69668@@ -71,7 +71,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
69669 this function returns 0. If the name ends with a digit (e.g. cx18),
69670 then the name will be set to cx18-0 since cx180 looks really odd. */
69671 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
69672- atomic_t *instance);
69673+ atomic_unchecked_t *instance);
69674
69675 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
69676 Since the parent disappears this ensures that v4l2_dev doesn't have an
69677diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
69678index 7a4529d..7244290 100644
69679--- a/include/media/v4l2-ioctl.h
69680+++ b/include/media/v4l2-ioctl.h
69681@@ -243,6 +243,7 @@ struct v4l2_ioctl_ops {
69682 long (*vidioc_default) (struct file *file, void *fh,
69683 int cmd, void *arg);
69684 };
69685+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
69686
69687
69688 /* v4l debugging and diagnostics */
69689diff --git a/include/net/flow.h b/include/net/flow.h
69690index 809970b..c3df4f3 100644
69691--- a/include/net/flow.h
69692+++ b/include/net/flow.h
69693@@ -92,7 +92,7 @@ typedef int (*flow_resolve_t)(struct net *net, struct flowi *key, u16 family,
69694 extern void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family,
69695 u8 dir, flow_resolve_t resolver);
69696 extern void flow_cache_flush(void);
69697-extern atomic_t flow_cache_genid;
69698+extern atomic_unchecked_t flow_cache_genid;
69699
69700 static inline int flow_cache_uli_match(struct flowi *fl1, struct flowi *fl2)
69701 {
69702diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
69703index 15e1f8fe..668837c 100644
69704--- a/include/net/inetpeer.h
69705+++ b/include/net/inetpeer.h
69706@@ -24,7 +24,7 @@ struct inet_peer
69707 __u32 dtime; /* the time of last use of not
69708 * referenced entries */
69709 atomic_t refcnt;
69710- atomic_t rid; /* Frag reception counter */
69711+ atomic_unchecked_t rid; /* Frag reception counter */
69712 __u32 tcp_ts;
69713 unsigned long tcp_ts_stamp;
69714 };
69715diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
69716index 98978e7..2243a3d 100644
69717--- a/include/net/ip_vs.h
69718+++ b/include/net/ip_vs.h
69719@@ -365,7 +365,7 @@ struct ip_vs_conn {
69720 struct ip_vs_conn *control; /* Master control connection */
69721 atomic_t n_control; /* Number of controlled ones */
69722 struct ip_vs_dest *dest; /* real server */
69723- atomic_t in_pkts; /* incoming packet counter */
69724+ atomic_unchecked_t in_pkts; /* incoming packet counter */
69725
69726 /* packet transmitter for different forwarding methods. If it
69727 mangles the packet, it must return NF_DROP or better NF_STOLEN,
69728@@ -466,7 +466,7 @@ struct ip_vs_dest {
69729 union nf_inet_addr addr; /* IP address of the server */
69730 __be16 port; /* port number of the server */
69731 volatile unsigned flags; /* dest status flags */
69732- atomic_t conn_flags; /* flags to copy to conn */
69733+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
69734 atomic_t weight; /* server weight */
69735
69736 atomic_t refcnt; /* reference counter */
69737diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
69738index 69b610a..fe3962c 100644
69739--- a/include/net/irda/ircomm_core.h
69740+++ b/include/net/irda/ircomm_core.h
69741@@ -51,7 +51,7 @@ typedef struct {
69742 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
69743 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
69744 struct ircomm_info *);
69745-} call_t;
69746+} __no_const call_t;
69747
69748 struct ircomm_cb {
69749 irda_queue_t queue;
69750diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
69751index eea2e61..08c692d 100644
69752--- a/include/net/irda/ircomm_tty.h
69753+++ b/include/net/irda/ircomm_tty.h
69754@@ -35,6 +35,7 @@
69755 #include <linux/termios.h>
69756 #include <linux/timer.h>
69757 #include <linux/tty.h> /* struct tty_struct */
69758+#include <asm/local.h>
69759
69760 #include <net/irda/irias_object.h>
69761 #include <net/irda/ircomm_core.h>
69762@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
69763 unsigned short close_delay;
69764 unsigned short closing_wait; /* time to wait before closing */
69765
69766- int open_count;
69767- int blocked_open; /* # of blocked opens */
69768+ local_t open_count;
69769+ local_t blocked_open; /* # of blocked opens */
69770
69771 /* Protect concurent access to :
69772 * o self->open_count
69773diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
69774index f82a1e8..82d81e8 100644
69775--- a/include/net/iucv/af_iucv.h
69776+++ b/include/net/iucv/af_iucv.h
69777@@ -87,7 +87,7 @@ struct iucv_sock {
69778 struct iucv_sock_list {
69779 struct hlist_head head;
69780 rwlock_t lock;
69781- atomic_t autobind_name;
69782+ atomic_unchecked_t autobind_name;
69783 };
69784
69785 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
69786diff --git a/include/net/lapb.h b/include/net/lapb.h
69787index 96cb5dd..25e8d4f 100644
69788--- a/include/net/lapb.h
69789+++ b/include/net/lapb.h
69790@@ -95,7 +95,7 @@ struct lapb_cb {
69791 struct sk_buff_head write_queue;
69792 struct sk_buff_head ack_queue;
69793 unsigned char window;
69794- struct lapb_register_struct callbacks;
69795+ struct lapb_register_struct *callbacks;
69796
69797 /* FRMR control information */
69798 struct lapb_frame frmr_data;
69799diff --git a/include/net/neighbour.h b/include/net/neighbour.h
69800index 3817fda..cdb2343 100644
69801--- a/include/net/neighbour.h
69802+++ b/include/net/neighbour.h
69803@@ -131,7 +131,7 @@ struct neigh_ops
69804 int (*connected_output)(struct sk_buff*);
69805 int (*hh_output)(struct sk_buff*);
69806 int (*queue_xmit)(struct sk_buff*);
69807-};
69808+} __do_const;
69809
69810 struct pneigh_entry
69811 {
69812diff --git a/include/net/netlink.h b/include/net/netlink.h
69813index c344646..4778c71 100644
69814--- a/include/net/netlink.h
69815+++ b/include/net/netlink.h
69816@@ -335,7 +335,7 @@ static inline int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
69817 {
69818 return (remaining >= (int) sizeof(struct nlmsghdr) &&
69819 nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
69820- nlh->nlmsg_len <= remaining);
69821+ nlh->nlmsg_len <= (unsigned int)remaining);
69822 }
69823
69824 /**
69825@@ -558,7 +558,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
69826 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
69827 {
69828 if (mark)
69829- skb_trim(skb, (unsigned char *) mark - skb->data);
69830+ skb_trim(skb, (const unsigned char *) mark - skb->data);
69831 }
69832
69833 /**
69834diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
69835index 9a4b8b7..e49e077 100644
69836--- a/include/net/netns/ipv4.h
69837+++ b/include/net/netns/ipv4.h
69838@@ -54,7 +54,7 @@ struct netns_ipv4 {
69839 int current_rt_cache_rebuild_count;
69840
69841 struct timer_list rt_secret_timer;
69842- atomic_t rt_genid;
69843+ atomic_unchecked_t rt_genid;
69844
69845 #ifdef CONFIG_IP_MROUTE
69846 struct sock *mroute_sk;
69847diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
69848index 8a6d529..171f401 100644
69849--- a/include/net/sctp/sctp.h
69850+++ b/include/net/sctp/sctp.h
69851@@ -305,8 +305,8 @@ extern int sctp_debug_flag;
69852
69853 #else /* SCTP_DEBUG */
69854
69855-#define SCTP_DEBUG_PRINTK(whatever...)
69856-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
69857+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
69858+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
69859 #define SCTP_ENABLE_DEBUG
69860 #define SCTP_DISABLE_DEBUG
69861 #define SCTP_ASSERT(expr, str, func)
69862diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
69863index d97f689..f3b90ab 100644
69864--- a/include/net/secure_seq.h
69865+++ b/include/net/secure_seq.h
69866@@ -7,14 +7,14 @@ extern __u32 secure_ip_id(__be32 daddr);
69867 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
69868 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
69869 extern u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
69870- __be16 dport);
69871+ __be16 dport);
69872 extern __u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
69873 __be16 sport, __be16 dport);
69874 extern __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
69875- __be16 sport, __be16 dport);
69876+ __be16 sport, __be16 dport);
69877 extern u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
69878- __be16 sport, __be16 dport);
69879+ __be16 sport, __be16 dport);
69880 extern u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
69881- __be16 sport, __be16 dport);
69882+ __be16 sport, __be16 dport);
69883
69884 #endif /* _NET_SECURE_SEQ */
69885diff --git a/include/net/sock.h b/include/net/sock.h
69886index 9f96394..76fc9c7 100644
69887--- a/include/net/sock.h
69888+++ b/include/net/sock.h
69889@@ -272,7 +272,7 @@ struct sock {
69890 rwlock_t sk_callback_lock;
69891 int sk_err,
69892 sk_err_soft;
69893- atomic_t sk_drops;
69894+ atomic_unchecked_t sk_drops;
69895 unsigned short sk_ack_backlog;
69896 unsigned short sk_max_ack_backlog;
69897 __u32 sk_priority;
69898@@ -737,7 +737,7 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
69899 extern void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc);
69900 extern int sock_prot_inuse_get(struct net *net, struct proto *proto);
69901 #else
69902-static void inline sock_prot_inuse_add(struct net *net, struct proto *prot,
69903+static inline void sock_prot_inuse_add(struct net *net, struct proto *prot,
69904 int inc)
69905 {
69906 }
69907diff --git a/include/net/tcp.h b/include/net/tcp.h
69908index 6cfe18b..dd21acb 100644
69909--- a/include/net/tcp.h
69910+++ b/include/net/tcp.h
69911@@ -1444,8 +1444,8 @@ enum tcp_seq_states {
69912 struct tcp_seq_afinfo {
69913 char *name;
69914 sa_family_t family;
69915- struct file_operations seq_fops;
69916- struct seq_operations seq_ops;
69917+ file_operations_no_const seq_fops;
69918+ seq_operations_no_const seq_ops;
69919 };
69920
69921 struct tcp_iter_state {
69922diff --git a/include/net/udp.h b/include/net/udp.h
69923index f98abd2..b4b042f 100644
69924--- a/include/net/udp.h
69925+++ b/include/net/udp.h
69926@@ -187,8 +187,8 @@ struct udp_seq_afinfo {
69927 char *name;
69928 sa_family_t family;
69929 struct udp_table *udp_table;
69930- struct file_operations seq_fops;
69931- struct seq_operations seq_ops;
69932+ file_operations_no_const seq_fops;
69933+ seq_operations_no_const seq_ops;
69934 };
69935
69936 struct udp_iter_state {
69937diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
69938index cbb822e..e9c1cbe 100644
69939--- a/include/rdma/iw_cm.h
69940+++ b/include/rdma/iw_cm.h
69941@@ -129,7 +129,7 @@ struct iw_cm_verbs {
69942 int backlog);
69943
69944 int (*destroy_listen)(struct iw_cm_id *cm_id);
69945-};
69946+} __no_const;
69947
69948 /**
69949 * iw_create_cm_id - Create an IW CM identifier.
69950diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
69951index 09a124b..caa8ca8 100644
69952--- a/include/scsi/libfc.h
69953+++ b/include/scsi/libfc.h
69954@@ -675,6 +675,7 @@ struct libfc_function_template {
69955 */
69956 void (*disc_stop_final) (struct fc_lport *);
69957 };
69958+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
69959
69960 /* information used by the discovery layer */
69961 struct fc_disc {
69962@@ -707,7 +708,7 @@ struct fc_lport {
69963 struct fc_disc disc;
69964
69965 /* Operational Information */
69966- struct libfc_function_template tt;
69967+ libfc_function_template_no_const tt;
69968 u8 link_up;
69969 u8 qfull;
69970 enum fc_lport_state state;
69971diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
69972index de8e180..f15e0d7 100644
69973--- a/include/scsi/scsi_device.h
69974+++ b/include/scsi/scsi_device.h
69975@@ -156,9 +156,9 @@ struct scsi_device {
69976 unsigned int max_device_blocked; /* what device_blocked counts down from */
69977 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
69978
69979- atomic_t iorequest_cnt;
69980- atomic_t iodone_cnt;
69981- atomic_t ioerr_cnt;
69982+ atomic_unchecked_t iorequest_cnt;
69983+ atomic_unchecked_t iodone_cnt;
69984+ atomic_unchecked_t ioerr_cnt;
69985
69986 struct device sdev_gendev,
69987 sdev_dev;
69988diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
69989index fc50bd6..81ba9cb 100644
69990--- a/include/scsi/scsi_transport_fc.h
69991+++ b/include/scsi/scsi_transport_fc.h
69992@@ -708,7 +708,7 @@ struct fc_function_template {
69993 unsigned long show_host_system_hostname:1;
69994
69995 unsigned long disable_target_scan:1;
69996-};
69997+} __do_const;
69998
69999
70000 /**
70001diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
70002index 3dae3f7..8440d6f 100644
70003--- a/include/sound/ac97_codec.h
70004+++ b/include/sound/ac97_codec.h
70005@@ -419,15 +419,15 @@
70006 struct snd_ac97;
70007
70008 struct snd_ac97_build_ops {
70009- int (*build_3d) (struct snd_ac97 *ac97);
70010- int (*build_specific) (struct snd_ac97 *ac97);
70011- int (*build_spdif) (struct snd_ac97 *ac97);
70012- int (*build_post_spdif) (struct snd_ac97 *ac97);
70013+ int (* const build_3d) (struct snd_ac97 *ac97);
70014+ int (* const build_specific) (struct snd_ac97 *ac97);
70015+ int (* const build_spdif) (struct snd_ac97 *ac97);
70016+ int (* const build_post_spdif) (struct snd_ac97 *ac97);
70017 #ifdef CONFIG_PM
70018- void (*suspend) (struct snd_ac97 *ac97);
70019- void (*resume) (struct snd_ac97 *ac97);
70020+ void (* const suspend) (struct snd_ac97 *ac97);
70021+ void (* const resume) (struct snd_ac97 *ac97);
70022 #endif
70023- void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
70024+ void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
70025 };
70026
70027 struct snd_ac97_bus_ops {
70028@@ -477,7 +477,7 @@ struct snd_ac97_template {
70029
70030 struct snd_ac97 {
70031 /* -- lowlevel (hardware) driver specific -- */
70032- struct snd_ac97_build_ops * build_ops;
70033+ const struct snd_ac97_build_ops * build_ops;
70034 void *private_data;
70035 void (*private_free) (struct snd_ac97 *ac97);
70036 /* --- */
70037diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
70038index 891cf1a..a94ba2b 100644
70039--- a/include/sound/ak4xxx-adda.h
70040+++ b/include/sound/ak4xxx-adda.h
70041@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
70042 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
70043 unsigned char val);
70044 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
70045-};
70046+} __no_const;
70047
70048 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
70049
70050diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
70051index 8c05e47..2b5df97 100644
70052--- a/include/sound/hwdep.h
70053+++ b/include/sound/hwdep.h
70054@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
70055 struct snd_hwdep_dsp_status *status);
70056 int (*dsp_load)(struct snd_hwdep *hw,
70057 struct snd_hwdep_dsp_image *image);
70058-};
70059+} __no_const;
70060
70061 struct snd_hwdep {
70062 struct snd_card *card;
70063diff --git a/include/sound/info.h b/include/sound/info.h
70064index 112e894..6fda5b5 100644
70065--- a/include/sound/info.h
70066+++ b/include/sound/info.h
70067@@ -44,7 +44,7 @@ struct snd_info_entry_text {
70068 struct snd_info_buffer *buffer);
70069 void (*write)(struct snd_info_entry *entry,
70070 struct snd_info_buffer *buffer);
70071-};
70072+} __no_const;
70073
70074 struct snd_info_entry_ops {
70075 int (*open)(struct snd_info_entry *entry,
70076diff --git a/include/sound/pcm.h b/include/sound/pcm.h
70077index de6d981..590a550 100644
70078--- a/include/sound/pcm.h
70079+++ b/include/sound/pcm.h
70080@@ -80,6 +80,7 @@ struct snd_pcm_ops {
70081 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
70082 int (*ack)(struct snd_pcm_substream *substream);
70083 };
70084+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
70085
70086 /*
70087 *
70088diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
70089index 736eac7..fe8a80f 100644
70090--- a/include/sound/sb16_csp.h
70091+++ b/include/sound/sb16_csp.h
70092@@ -139,7 +139,7 @@ struct snd_sb_csp_ops {
70093 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
70094 int (*csp_stop) (struct snd_sb_csp * p);
70095 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
70096-};
70097+} __no_const;
70098
70099 /*
70100 * CSP private data
70101diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
70102index 444cd6b..3327cc5 100644
70103--- a/include/sound/ymfpci.h
70104+++ b/include/sound/ymfpci.h
70105@@ -358,7 +358,7 @@ struct snd_ymfpci {
70106 spinlock_t reg_lock;
70107 spinlock_t voice_lock;
70108 wait_queue_head_t interrupt_sleep;
70109- atomic_t interrupt_sleep_count;
70110+ atomic_unchecked_t interrupt_sleep_count;
70111 struct snd_info_entry *proc_entry;
70112 const struct firmware *dsp_microcode;
70113 const struct firmware *controller_microcode;
70114diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
70115index b89f9db..f097b38 100644
70116--- a/include/trace/events/irq.h
70117+++ b/include/trace/events/irq.h
70118@@ -34,7 +34,7 @@
70119 */
70120 TRACE_EVENT(irq_handler_entry,
70121
70122- TP_PROTO(int irq, struct irqaction *action),
70123+ TP_PROTO(int irq, const struct irqaction *action),
70124
70125 TP_ARGS(irq, action),
70126
70127@@ -64,7 +64,7 @@ TRACE_EVENT(irq_handler_entry,
70128 */
70129 TRACE_EVENT(irq_handler_exit,
70130
70131- TP_PROTO(int irq, struct irqaction *action, int ret),
70132+ TP_PROTO(int irq, const struct irqaction *action, int ret),
70133
70134 TP_ARGS(irq, action, ret),
70135
70136@@ -95,7 +95,7 @@ TRACE_EVENT(irq_handler_exit,
70137 */
70138 TRACE_EVENT(softirq_entry,
70139
70140- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
70141+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
70142
70143 TP_ARGS(h, vec),
70144
70145@@ -124,7 +124,7 @@ TRACE_EVENT(softirq_entry,
70146 */
70147 TRACE_EVENT(softirq_exit,
70148
70149- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
70150+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
70151
70152 TP_ARGS(h, vec),
70153
70154diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
70155index 0993a22..32ba2fe 100644
70156--- a/include/video/uvesafb.h
70157+++ b/include/video/uvesafb.h
70158@@ -177,6 +177,7 @@ struct uvesafb_par {
70159 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
70160 u8 pmi_setpal; /* PMI for palette changes */
70161 u16 *pmi_base; /* protected mode interface location */
70162+ u8 *pmi_code; /* protected mode code location */
70163 void *pmi_start;
70164 void *pmi_pal;
70165 u8 *vbe_state_orig; /*
70166diff --git a/init/Kconfig b/init/Kconfig
70167index d72691b..3996e54 100644
70168--- a/init/Kconfig
70169+++ b/init/Kconfig
70170@@ -1004,7 +1004,7 @@ config SLUB_DEBUG
70171
70172 config COMPAT_BRK
70173 bool "Disable heap randomization"
70174- default y
70175+ default n
70176 help
70177 Randomizing heap placement makes heap exploits harder, but it
70178 also breaks ancient binaries (including anything libc5 based).
70179diff --git a/init/do_mounts.c b/init/do_mounts.c
70180index bb008d0..4fa3933 100644
70181--- a/init/do_mounts.c
70182+++ b/init/do_mounts.c
70183@@ -216,11 +216,11 @@ static void __init get_fs_names(char *page)
70184
70185 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
70186 {
70187- int err = sys_mount(name, "/root", fs, flags, data);
70188+ int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
70189 if (err)
70190 return err;
70191
70192- sys_chdir("/root");
70193+ sys_chdir((__force const char __user *)"/root");
70194 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
70195 printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
70196 current->fs->pwd.mnt->mnt_sb->s_type->name,
70197@@ -311,18 +311,18 @@ void __init change_floppy(char *fmt, ...)
70198 va_start(args, fmt);
70199 vsprintf(buf, fmt, args);
70200 va_end(args);
70201- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
70202+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
70203 if (fd >= 0) {
70204 sys_ioctl(fd, FDEJECT, 0);
70205 sys_close(fd);
70206 }
70207 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
70208- fd = sys_open("/dev/console", O_RDWR, 0);
70209+ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
70210 if (fd >= 0) {
70211 sys_ioctl(fd, TCGETS, (long)&termios);
70212 termios.c_lflag &= ~ICANON;
70213 sys_ioctl(fd, TCSETSF, (long)&termios);
70214- sys_read(fd, &c, 1);
70215+ sys_read(fd, (char __user *)&c, 1);
70216 termios.c_lflag |= ICANON;
70217 sys_ioctl(fd, TCSETSF, (long)&termios);
70218 sys_close(fd);
70219@@ -416,6 +416,6 @@ void __init prepare_namespace(void)
70220 mount_root();
70221 out:
70222 devtmpfs_mount("dev");
70223- sys_mount(".", "/", NULL, MS_MOVE, NULL);
70224- sys_chroot(".");
70225+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
70226+ sys_chroot((__force char __user *)".");
70227 }
70228diff --git a/init/do_mounts.h b/init/do_mounts.h
70229index f5b978a..69dbfe8 100644
70230--- a/init/do_mounts.h
70231+++ b/init/do_mounts.h
70232@@ -15,15 +15,15 @@ extern int root_mountflags;
70233
70234 static inline int create_dev(char *name, dev_t dev)
70235 {
70236- sys_unlink(name);
70237- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
70238+ sys_unlink((char __force_user *)name);
70239+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
70240 }
70241
70242 #if BITS_PER_LONG == 32
70243 static inline u32 bstat(char *name)
70244 {
70245 struct stat64 stat;
70246- if (sys_stat64(name, &stat) != 0)
70247+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
70248 return 0;
70249 if (!S_ISBLK(stat.st_mode))
70250 return 0;
70251@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
70252 static inline u32 bstat(char *name)
70253 {
70254 struct stat stat;
70255- if (sys_newstat(name, &stat) != 0)
70256+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
70257 return 0;
70258 if (!S_ISBLK(stat.st_mode))
70259 return 0;
70260diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
70261index 614241b..4da046b 100644
70262--- a/init/do_mounts_initrd.c
70263+++ b/init/do_mounts_initrd.c
70264@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shell)
70265 sys_close(old_fd);sys_close(root_fd);
70266 sys_close(0);sys_close(1);sys_close(2);
70267 sys_setsid();
70268- (void) sys_open("/dev/console",O_RDWR,0);
70269+ (void) sys_open((__force const char __user *)"/dev/console",O_RDWR,0);
70270 (void) sys_dup(0);
70271 (void) sys_dup(0);
70272 return kernel_execve(shell, argv, envp_init);
70273@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
70274 create_dev("/dev/root.old", Root_RAM0);
70275 /* mount initrd on rootfs' /root */
70276 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
70277- sys_mkdir("/old", 0700);
70278- root_fd = sys_open("/", 0, 0);
70279- old_fd = sys_open("/old", 0, 0);
70280+ sys_mkdir((const char __force_user *)"/old", 0700);
70281+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
70282+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
70283 /* move initrd over / and chdir/chroot in initrd root */
70284- sys_chdir("/root");
70285- sys_mount(".", "/", NULL, MS_MOVE, NULL);
70286- sys_chroot(".");
70287+ sys_chdir((const char __force_user *)"/root");
70288+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
70289+ sys_chroot((const char __force_user *)".");
70290
70291 /*
70292 * In case that a resume from disk is carried out by linuxrc or one of
70293@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
70294
70295 /* move initrd to rootfs' /old */
70296 sys_fchdir(old_fd);
70297- sys_mount("/", ".", NULL, MS_MOVE, NULL);
70298+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
70299 /* switch root and cwd back to / of rootfs */
70300 sys_fchdir(root_fd);
70301- sys_chroot(".");
70302+ sys_chroot((const char __force_user *)".");
70303 sys_close(old_fd);
70304 sys_close(root_fd);
70305
70306 if (new_decode_dev(real_root_dev) == Root_RAM0) {
70307- sys_chdir("/old");
70308+ sys_chdir((const char __force_user *)"/old");
70309 return;
70310 }
70311
70312@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
70313 mount_root();
70314
70315 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
70316- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
70317+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
70318 if (!error)
70319 printk("okay\n");
70320 else {
70321- int fd = sys_open("/dev/root.old", O_RDWR, 0);
70322+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
70323 if (error == -ENOENT)
70324 printk("/initrd does not exist. Ignored.\n");
70325 else
70326 printk("failed\n");
70327 printk(KERN_NOTICE "Unmounting old root\n");
70328- sys_umount("/old", MNT_DETACH);
70329+ sys_umount((char __force_user *)"/old", MNT_DETACH);
70330 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
70331 if (fd < 0) {
70332 error = fd;
70333@@ -119,11 +119,11 @@ int __init initrd_load(void)
70334 * mounted in the normal path.
70335 */
70336 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
70337- sys_unlink("/initrd.image");
70338+ sys_unlink((const char __force_user *)"/initrd.image");
70339 handle_initrd();
70340 return 1;
70341 }
70342 }
70343- sys_unlink("/initrd.image");
70344+ sys_unlink((const char __force_user *)"/initrd.image");
70345 return 0;
70346 }
70347diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
70348index 69aebbf..c0bf6a7 100644
70349--- a/init/do_mounts_md.c
70350+++ b/init/do_mounts_md.c
70351@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
70352 partitioned ? "_d" : "", minor,
70353 md_setup_args[ent].device_names);
70354
70355- fd = sys_open(name, 0, 0);
70356+ fd = sys_open((char __force_user *)name, 0, 0);
70357 if (fd < 0) {
70358 printk(KERN_ERR "md: open failed - cannot start "
70359 "array %s\n", name);
70360@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
70361 * array without it
70362 */
70363 sys_close(fd);
70364- fd = sys_open(name, 0, 0);
70365+ fd = sys_open((char __force_user *)name, 0, 0);
70366 sys_ioctl(fd, BLKRRPART, 0);
70367 }
70368 sys_close(fd);
70369@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
70370
70371 wait_for_device_probe();
70372
70373- fd = sys_open("/dev/md0", 0, 0);
70374+ fd = sys_open((__force char __user *)"/dev/md0", 0, 0);
70375 if (fd >= 0) {
70376 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
70377 sys_close(fd);
70378diff --git a/init/initramfs.c b/init/initramfs.c
70379index 1fd59b8..a01b079 100644
70380--- a/init/initramfs.c
70381+++ b/init/initramfs.c
70382@@ -74,7 +74,7 @@ static void __init free_hash(void)
70383 }
70384 }
70385
70386-static long __init do_utime(char __user *filename, time_t mtime)
70387+static long __init do_utime(__force char __user *filename, time_t mtime)
70388 {
70389 struct timespec t[2];
70390
70391@@ -109,7 +109,7 @@ static void __init dir_utime(void)
70392 struct dir_entry *de, *tmp;
70393 list_for_each_entry_safe(de, tmp, &dir_list, list) {
70394 list_del(&de->list);
70395- do_utime(de->name, de->mtime);
70396+ do_utime((char __force_user *)de->name, de->mtime);
70397 kfree(de->name);
70398 kfree(de);
70399 }
70400@@ -271,7 +271,7 @@ static int __init maybe_link(void)
70401 if (nlink >= 2) {
70402 char *old = find_link(major, minor, ino, mode, collected);
70403 if (old)
70404- return (sys_link(old, collected) < 0) ? -1 : 1;
70405+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
70406 }
70407 return 0;
70408 }
70409@@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
70410 {
70411 struct stat st;
70412
70413- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
70414+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
70415 if (S_ISDIR(st.st_mode))
70416- sys_rmdir(path);
70417+ sys_rmdir((char __force_user *)path);
70418 else
70419- sys_unlink(path);
70420+ sys_unlink((char __force_user *)path);
70421 }
70422 }
70423
70424@@ -305,7 +305,7 @@ static int __init do_name(void)
70425 int openflags = O_WRONLY|O_CREAT;
70426 if (ml != 1)
70427 openflags |= O_TRUNC;
70428- wfd = sys_open(collected, openflags, mode);
70429+ wfd = sys_open((char __force_user *)collected, openflags, mode);
70430
70431 if (wfd >= 0) {
70432 sys_fchown(wfd, uid, gid);
70433@@ -317,17 +317,17 @@ static int __init do_name(void)
70434 }
70435 }
70436 } else if (S_ISDIR(mode)) {
70437- sys_mkdir(collected, mode);
70438- sys_chown(collected, uid, gid);
70439- sys_chmod(collected, mode);
70440+ sys_mkdir((char __force_user *)collected, mode);
70441+ sys_chown((char __force_user *)collected, uid, gid);
70442+ sys_chmod((char __force_user *)collected, mode);
70443 dir_add(collected, mtime);
70444 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
70445 S_ISFIFO(mode) || S_ISSOCK(mode)) {
70446 if (maybe_link() == 0) {
70447- sys_mknod(collected, mode, rdev);
70448- sys_chown(collected, uid, gid);
70449- sys_chmod(collected, mode);
70450- do_utime(collected, mtime);
70451+ sys_mknod((char __force_user *)collected, mode, rdev);
70452+ sys_chown((char __force_user *)collected, uid, gid);
70453+ sys_chmod((char __force_user *)collected, mode);
70454+ do_utime((char __force_user *)collected, mtime);
70455 }
70456 }
70457 return 0;
70458@@ -336,15 +336,15 @@ static int __init do_name(void)
70459 static int __init do_copy(void)
70460 {
70461 if (count >= body_len) {
70462- sys_write(wfd, victim, body_len);
70463+ sys_write(wfd, (char __force_user *)victim, body_len);
70464 sys_close(wfd);
70465- do_utime(vcollected, mtime);
70466+ do_utime((char __force_user *)vcollected, mtime);
70467 kfree(vcollected);
70468 eat(body_len);
70469 state = SkipIt;
70470 return 0;
70471 } else {
70472- sys_write(wfd, victim, count);
70473+ sys_write(wfd, (char __force_user *)victim, count);
70474 body_len -= count;
70475 eat(count);
70476 return 1;
70477@@ -355,9 +355,9 @@ static int __init do_symlink(void)
70478 {
70479 collected[N_ALIGN(name_len) + body_len] = '\0';
70480 clean_path(collected, 0);
70481- sys_symlink(collected + N_ALIGN(name_len), collected);
70482- sys_lchown(collected, uid, gid);
70483- do_utime(collected, mtime);
70484+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
70485+ sys_lchown((char __force_user *)collected, uid, gid);
70486+ do_utime((char __force_user *)collected, mtime);
70487 state = SkipIt;
70488 next_state = Reset;
70489 return 0;
70490diff --git a/init/main.c b/init/main.c
70491index 1eb4bd5..da8c6f5 100644
70492--- a/init/main.c
70493+++ b/init/main.c
70494@@ -97,6 +97,7 @@ static inline void mark_rodata_ro(void) { }
70495 #ifdef CONFIG_TC
70496 extern void tc_init(void);
70497 #endif
70498+extern void grsecurity_init(void);
70499
70500 enum system_states system_state __read_mostly;
70501 EXPORT_SYMBOL(system_state);
70502@@ -183,6 +184,49 @@ static int __init set_reset_devices(char *str)
70503
70504 __setup("reset_devices", set_reset_devices);
70505
70506+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
70507+extern char pax_enter_kernel_user[];
70508+extern char pax_exit_kernel_user[];
70509+extern pgdval_t clone_pgd_mask;
70510+#endif
70511+
70512+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
70513+static int __init setup_pax_nouderef(char *str)
70514+{
70515+#ifdef CONFIG_X86_32
70516+ unsigned int cpu;
70517+ struct desc_struct *gdt;
70518+
70519+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
70520+ gdt = get_cpu_gdt_table(cpu);
70521+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
70522+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
70523+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
70524+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
70525+ }
70526+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
70527+#else
70528+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
70529+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
70530+ clone_pgd_mask = ~(pgdval_t)0UL;
70531+#endif
70532+
70533+ return 0;
70534+}
70535+early_param("pax_nouderef", setup_pax_nouderef);
70536+#endif
70537+
70538+#ifdef CONFIG_PAX_SOFTMODE
70539+int pax_softmode;
70540+
70541+static int __init setup_pax_softmode(char *str)
70542+{
70543+ get_option(&str, &pax_softmode);
70544+ return 1;
70545+}
70546+__setup("pax_softmode=", setup_pax_softmode);
70547+#endif
70548+
70549 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
70550 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
70551 static const char *panic_later, *panic_param;
70552@@ -705,52 +749,53 @@ int initcall_debug;
70553 core_param(initcall_debug, initcall_debug, bool, 0644);
70554
70555 static char msgbuf[64];
70556-static struct boot_trace_call call;
70557-static struct boot_trace_ret ret;
70558+static struct boot_trace_call trace_call;
70559+static struct boot_trace_ret trace_ret;
70560
70561 int do_one_initcall(initcall_t fn)
70562 {
70563 int count = preempt_count();
70564 ktime_t calltime, delta, rettime;
70565+ const char *msg1 = "", *msg2 = "";
70566
70567 if (initcall_debug) {
70568- call.caller = task_pid_nr(current);
70569- printk("calling %pF @ %i\n", fn, call.caller);
70570+ trace_call.caller = task_pid_nr(current);
70571+ printk("calling %pF @ %i\n", fn, trace_call.caller);
70572 calltime = ktime_get();
70573- trace_boot_call(&call, fn);
70574+ trace_boot_call(&trace_call, fn);
70575 enable_boot_trace();
70576 }
70577
70578- ret.result = fn();
70579+ trace_ret.result = fn();
70580
70581 if (initcall_debug) {
70582 disable_boot_trace();
70583 rettime = ktime_get();
70584 delta = ktime_sub(rettime, calltime);
70585- ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
70586- trace_boot_ret(&ret, fn);
70587+ trace_ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
70588+ trace_boot_ret(&trace_ret, fn);
70589 printk("initcall %pF returned %d after %Ld usecs\n", fn,
70590- ret.result, ret.duration);
70591+ trace_ret.result, trace_ret.duration);
70592 }
70593
70594 msgbuf[0] = 0;
70595
70596- if (ret.result && ret.result != -ENODEV && initcall_debug)
70597- sprintf(msgbuf, "error code %d ", ret.result);
70598+ if (trace_ret.result && trace_ret.result != -ENODEV && initcall_debug)
70599+ sprintf(msgbuf, "error code %d ", trace_ret.result);
70600
70601 if (preempt_count() != count) {
70602- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
70603+ msg1 = " preemption imbalance";
70604 preempt_count() = count;
70605 }
70606 if (irqs_disabled()) {
70607- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
70608+ msg2 = " disabled interrupts";
70609 local_irq_enable();
70610 }
70611- if (msgbuf[0]) {
70612- printk("initcall %pF returned with %s\n", fn, msgbuf);
70613+ if (msgbuf[0] || *msg1 || *msg2) {
70614+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
70615 }
70616
70617- return ret.result;
70618+ return trace_ret.result;
70619 }
70620
70621
70622@@ -893,11 +938,13 @@ static int __init kernel_init(void * unused)
70623 if (!ramdisk_execute_command)
70624 ramdisk_execute_command = "/init";
70625
70626- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
70627+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
70628 ramdisk_execute_command = NULL;
70629 prepare_namespace();
70630 }
70631
70632+ grsecurity_init();
70633+
70634 /*
70635 * Ok, we have completed the initial bootup, and
70636 * we're essentially up and running. Get rid of the
70637diff --git a/init/noinitramfs.c b/init/noinitramfs.c
70638index f4c1a3a..96c19bd 100644
70639--- a/init/noinitramfs.c
70640+++ b/init/noinitramfs.c
70641@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
70642 {
70643 int err;
70644
70645- err = sys_mkdir("/dev", 0755);
70646+ err = sys_mkdir((const char __user *)"/dev", 0755);
70647 if (err < 0)
70648 goto out;
70649
70650@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
70651 if (err < 0)
70652 goto out;
70653
70654- err = sys_mkdir("/root", 0700);
70655+ err = sys_mkdir((const char __user *)"/root", 0700);
70656 if (err < 0)
70657 goto out;
70658
70659diff --git a/ipc/mqueue.c b/ipc/mqueue.c
70660index d01bc14..8df81db 100644
70661--- a/ipc/mqueue.c
70662+++ b/ipc/mqueue.c
70663@@ -150,6 +150,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
70664 mq_bytes = (mq_msg_tblsz +
70665 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
70666
70667+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
70668 spin_lock(&mq_lock);
70669 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
70670 u->mq_bytes + mq_bytes >
70671diff --git a/ipc/msg.c b/ipc/msg.c
70672index 779f762..4af9e36 100644
70673--- a/ipc/msg.c
70674+++ b/ipc/msg.c
70675@@ -310,18 +310,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
70676 return security_msg_queue_associate(msq, msgflg);
70677 }
70678
70679+static struct ipc_ops msg_ops = {
70680+ .getnew = newque,
70681+ .associate = msg_security,
70682+ .more_checks = NULL
70683+};
70684+
70685 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
70686 {
70687 struct ipc_namespace *ns;
70688- struct ipc_ops msg_ops;
70689 struct ipc_params msg_params;
70690
70691 ns = current->nsproxy->ipc_ns;
70692
70693- msg_ops.getnew = newque;
70694- msg_ops.associate = msg_security;
70695- msg_ops.more_checks = NULL;
70696-
70697 msg_params.key = key;
70698 msg_params.flg = msgflg;
70699
70700diff --git a/ipc/sem.c b/ipc/sem.c
70701index b781007..f738b04 100644
70702--- a/ipc/sem.c
70703+++ b/ipc/sem.c
70704@@ -309,10 +309,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
70705 return 0;
70706 }
70707
70708+static struct ipc_ops sem_ops = {
70709+ .getnew = newary,
70710+ .associate = sem_security,
70711+ .more_checks = sem_more_checks
70712+};
70713+
70714 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
70715 {
70716 struct ipc_namespace *ns;
70717- struct ipc_ops sem_ops;
70718 struct ipc_params sem_params;
70719
70720 ns = current->nsproxy->ipc_ns;
70721@@ -320,10 +325,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
70722 if (nsems < 0 || nsems > ns->sc_semmsl)
70723 return -EINVAL;
70724
70725- sem_ops.getnew = newary;
70726- sem_ops.associate = sem_security;
70727- sem_ops.more_checks = sem_more_checks;
70728-
70729 sem_params.key = key;
70730 sem_params.flg = semflg;
70731 sem_params.u.nsems = nsems;
70732@@ -671,6 +672,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
70733 ushort* sem_io = fast_sem_io;
70734 int nsems;
70735
70736+ pax_track_stack();
70737+
70738 sma = sem_lock_check(ns, semid);
70739 if (IS_ERR(sma))
70740 return PTR_ERR(sma);
70741@@ -1071,6 +1074,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
70742 unsigned long jiffies_left = 0;
70743 struct ipc_namespace *ns;
70744
70745+ pax_track_stack();
70746+
70747 ns = current->nsproxy->ipc_ns;
70748
70749 if (nsops < 1 || semid < 0)
70750diff --git a/ipc/shm.c b/ipc/shm.c
70751index d30732c..e4992cd 100644
70752--- a/ipc/shm.c
70753+++ b/ipc/shm.c
70754@@ -70,6 +70,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
70755 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
70756 #endif
70757
70758+#ifdef CONFIG_GRKERNSEC
70759+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70760+ const time_t shm_createtime, const uid_t cuid,
70761+ const int shmid);
70762+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70763+ const time_t shm_createtime);
70764+#endif
70765+
70766 void shm_init_ns(struct ipc_namespace *ns)
70767 {
70768 ns->shm_ctlmax = SHMMAX;
70769@@ -396,6 +404,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
70770 shp->shm_lprid = 0;
70771 shp->shm_atim = shp->shm_dtim = 0;
70772 shp->shm_ctim = get_seconds();
70773+#ifdef CONFIG_GRKERNSEC
70774+ {
70775+ struct timespec timeval;
70776+ do_posix_clock_monotonic_gettime(&timeval);
70777+
70778+ shp->shm_createtime = timeval.tv_sec;
70779+ }
70780+#endif
70781 shp->shm_segsz = size;
70782 shp->shm_nattch = 0;
70783 shp->shm_file = file;
70784@@ -446,18 +462,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
70785 return 0;
70786 }
70787
70788+static struct ipc_ops shm_ops = {
70789+ .getnew = newseg,
70790+ .associate = shm_security,
70791+ .more_checks = shm_more_checks
70792+};
70793+
70794 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
70795 {
70796 struct ipc_namespace *ns;
70797- struct ipc_ops shm_ops;
70798 struct ipc_params shm_params;
70799
70800 ns = current->nsproxy->ipc_ns;
70801
70802- shm_ops.getnew = newseg;
70803- shm_ops.associate = shm_security;
70804- shm_ops.more_checks = shm_more_checks;
70805-
70806 shm_params.key = key;
70807 shm_params.flg = shmflg;
70808 shm_params.u.size = size;
70809@@ -857,6 +874,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
70810 f_mode = FMODE_READ | FMODE_WRITE;
70811 }
70812 if (shmflg & SHM_EXEC) {
70813+
70814+#ifdef CONFIG_PAX_MPROTECT
70815+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
70816+ goto out;
70817+#endif
70818+
70819 prot |= PROT_EXEC;
70820 acc_mode |= S_IXUGO;
70821 }
70822@@ -880,9 +903,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
70823 if (err)
70824 goto out_unlock;
70825
70826+#ifdef CONFIG_GRKERNSEC
70827+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
70828+ shp->shm_perm.cuid, shmid) ||
70829+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
70830+ err = -EACCES;
70831+ goto out_unlock;
70832+ }
70833+#endif
70834+
70835 path.dentry = dget(shp->shm_file->f_path.dentry);
70836 path.mnt = shp->shm_file->f_path.mnt;
70837 shp->shm_nattch++;
70838+#ifdef CONFIG_GRKERNSEC
70839+ shp->shm_lapid = current->pid;
70840+#endif
70841 size = i_size_read(path.dentry->d_inode);
70842 shm_unlock(shp);
70843
70844diff --git a/kernel/acct.c b/kernel/acct.c
70845index a6605ca..ca91111 100644
70846--- a/kernel/acct.c
70847+++ b/kernel/acct.c
70848@@ -579,7 +579,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
70849 */
70850 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
70851 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
70852- file->f_op->write(file, (char *)&ac,
70853+ file->f_op->write(file, (char __force_user *)&ac,
70854 sizeof(acct_t), &file->f_pos);
70855 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
70856 set_fs(fs);
70857diff --git a/kernel/audit.c b/kernel/audit.c
70858index 5feed23..48415fd 100644
70859--- a/kernel/audit.c
70860+++ b/kernel/audit.c
70861@@ -110,7 +110,7 @@ u32 audit_sig_sid = 0;
70862 3) suppressed due to audit_rate_limit
70863 4) suppressed due to audit_backlog_limit
70864 */
70865-static atomic_t audit_lost = ATOMIC_INIT(0);
70866+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
70867
70868 /* The netlink socket. */
70869 static struct sock *audit_sock;
70870@@ -232,7 +232,7 @@ void audit_log_lost(const char *message)
70871 unsigned long now;
70872 int print;
70873
70874- atomic_inc(&audit_lost);
70875+ atomic_inc_unchecked(&audit_lost);
70876
70877 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
70878
70879@@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
70880 printk(KERN_WARNING
70881 "audit: audit_lost=%d audit_rate_limit=%d "
70882 "audit_backlog_limit=%d\n",
70883- atomic_read(&audit_lost),
70884+ atomic_read_unchecked(&audit_lost),
70885 audit_rate_limit,
70886 audit_backlog_limit);
70887 audit_panic(message);
70888@@ -691,7 +691,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
70889 status_set.pid = audit_pid;
70890 status_set.rate_limit = audit_rate_limit;
70891 status_set.backlog_limit = audit_backlog_limit;
70892- status_set.lost = atomic_read(&audit_lost);
70893+ status_set.lost = atomic_read_unchecked(&audit_lost);
70894 status_set.backlog = skb_queue_len(&audit_skb_queue);
70895 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
70896 &status_set, sizeof(status_set));
70897@@ -891,8 +891,10 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
70898 spin_unlock_irq(&tsk->sighand->siglock);
70899 }
70900 read_unlock(&tasklist_lock);
70901- audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_TTY_GET, 0, 0,
70902- &s, sizeof(s));
70903+
70904+ if (!err)
70905+ audit_send_reply(NETLINK_CB(skb).pid, seq,
70906+ AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
70907 break;
70908 }
70909 case AUDIT_TTY_SET: {
70910@@ -1262,12 +1264,13 @@ static void audit_log_vformat(struct audit_buffer *ab, const char *fmt,
70911 avail = audit_expand(ab,
70912 max_t(unsigned, AUDIT_BUFSIZ, 1+len-avail));
70913 if (!avail)
70914- goto out;
70915+ goto out_va_end;
70916 len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args2);
70917 }
70918- va_end(args2);
70919 if (len > 0)
70920 skb_put(skb, len);
70921+out_va_end:
70922+ va_end(args2);
70923 out:
70924 return;
70925 }
70926diff --git a/kernel/auditsc.c b/kernel/auditsc.c
70927index 267e484..ac41bc3 100644
70928--- a/kernel/auditsc.c
70929+++ b/kernel/auditsc.c
70930@@ -1157,8 +1157,8 @@ static void audit_log_execve_info(struct audit_context *context,
70931 struct audit_buffer **ab,
70932 struct audit_aux_data_execve *axi)
70933 {
70934- int i;
70935- size_t len, len_sent = 0;
70936+ int i, len;
70937+ size_t len_sent = 0;
70938 const char __user *p;
70939 char *buf;
70940
70941@@ -2113,7 +2113,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
70942 }
70943
70944 /* global counter which is incremented every time something logs in */
70945-static atomic_t session_id = ATOMIC_INIT(0);
70946+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
70947
70948 /**
70949 * audit_set_loginuid - set a task's audit_context loginuid
70950@@ -2126,7 +2126,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
70951 */
70952 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
70953 {
70954- unsigned int sessionid = atomic_inc_return(&session_id);
70955+ unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
70956 struct audit_context *context = task->audit_context;
70957
70958 if (context && context->in_syscall) {
70959diff --git a/kernel/capability.c b/kernel/capability.c
70960index 8a944f5..db5001e 100644
70961--- a/kernel/capability.c
70962+++ b/kernel/capability.c
70963@@ -305,10 +305,26 @@ int capable(int cap)
70964 BUG();
70965 }
70966
70967- if (security_capable(cap) == 0) {
70968+ if (security_capable(cap) == 0 && gr_is_capable(cap)) {
70969 current->flags |= PF_SUPERPRIV;
70970 return 1;
70971 }
70972 return 0;
70973 }
70974+
70975+int capable_nolog(int cap)
70976+{
70977+ if (unlikely(!cap_valid(cap))) {
70978+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
70979+ BUG();
70980+ }
70981+
70982+ if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) {
70983+ current->flags |= PF_SUPERPRIV;
70984+ return 1;
70985+ }
70986+ return 0;
70987+}
70988+
70989 EXPORT_SYMBOL(capable);
70990+EXPORT_SYMBOL(capable_nolog);
70991diff --git a/kernel/cgroup.c b/kernel/cgroup.c
70992index 1fbcc74..7000012 100644
70993--- a/kernel/cgroup.c
70994+++ b/kernel/cgroup.c
70995@@ -536,6 +536,8 @@ static struct css_set *find_css_set(
70996 struct hlist_head *hhead;
70997 struct cg_cgroup_link *link;
70998
70999+ pax_track_stack();
71000+
71001 /* First see if we already have a cgroup group that matches
71002 * the desired set */
71003 read_lock(&css_set_lock);
71004diff --git a/kernel/compat.c b/kernel/compat.c
71005index 8bc5578..186e44a 100644
71006--- a/kernel/compat.c
71007+++ b/kernel/compat.c
71008@@ -108,7 +108,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
71009 mm_segment_t oldfs;
71010 long ret;
71011
71012- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
71013+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
71014 oldfs = get_fs();
71015 set_fs(KERNEL_DS);
71016 ret = hrtimer_nanosleep_restart(restart);
71017@@ -140,7 +140,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
71018 oldfs = get_fs();
71019 set_fs(KERNEL_DS);
71020 ret = hrtimer_nanosleep(&tu,
71021- rmtp ? (struct timespec __user *)&rmt : NULL,
71022+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
71023 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
71024 set_fs(oldfs);
71025
71026@@ -247,7 +247,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
71027 mm_segment_t old_fs = get_fs();
71028
71029 set_fs(KERNEL_DS);
71030- ret = sys_sigpending((old_sigset_t __user *) &s);
71031+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
71032 set_fs(old_fs);
71033 if (ret == 0)
71034 ret = put_user(s, set);
71035@@ -266,8 +266,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
71036 old_fs = get_fs();
71037 set_fs(KERNEL_DS);
71038 ret = sys_sigprocmask(how,
71039- set ? (old_sigset_t __user *) &s : NULL,
71040- oset ? (old_sigset_t __user *) &s : NULL);
71041+ set ? (old_sigset_t __force_user *) &s : NULL,
71042+ oset ? (old_sigset_t __force_user *) &s : NULL);
71043 set_fs(old_fs);
71044 if (ret == 0)
71045 if (oset)
71046@@ -310,7 +310,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
71047 mm_segment_t old_fs = get_fs();
71048
71049 set_fs(KERNEL_DS);
71050- ret = sys_old_getrlimit(resource, &r);
71051+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
71052 set_fs(old_fs);
71053
71054 if (!ret) {
71055@@ -385,7 +385,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
71056 mm_segment_t old_fs = get_fs();
71057
71058 set_fs(KERNEL_DS);
71059- ret = sys_getrusage(who, (struct rusage __user *) &r);
71060+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
71061 set_fs(old_fs);
71062
71063 if (ret)
71064@@ -412,8 +412,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
71065 set_fs (KERNEL_DS);
71066 ret = sys_wait4(pid,
71067 (stat_addr ?
71068- (unsigned int __user *) &status : NULL),
71069- options, (struct rusage __user *) &r);
71070+ (unsigned int __force_user *) &status : NULL),
71071+ options, (struct rusage __force_user *) &r);
71072 set_fs (old_fs);
71073
71074 if (ret > 0) {
71075@@ -438,8 +438,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
71076 memset(&info, 0, sizeof(info));
71077
71078 set_fs(KERNEL_DS);
71079- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
71080- uru ? (struct rusage __user *)&ru : NULL);
71081+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
71082+ uru ? (struct rusage __force_user *)&ru : NULL);
71083 set_fs(old_fs);
71084
71085 if ((ret < 0) || (info.si_signo == 0))
71086@@ -569,8 +569,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
71087 oldfs = get_fs();
71088 set_fs(KERNEL_DS);
71089 err = sys_timer_settime(timer_id, flags,
71090- (struct itimerspec __user *) &newts,
71091- (struct itimerspec __user *) &oldts);
71092+ (struct itimerspec __force_user *) &newts,
71093+ (struct itimerspec __force_user *) &oldts);
71094 set_fs(oldfs);
71095 if (!err && old && put_compat_itimerspec(old, &oldts))
71096 return -EFAULT;
71097@@ -587,7 +587,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
71098 oldfs = get_fs();
71099 set_fs(KERNEL_DS);
71100 err = sys_timer_gettime(timer_id,
71101- (struct itimerspec __user *) &ts);
71102+ (struct itimerspec __force_user *) &ts);
71103 set_fs(oldfs);
71104 if (!err && put_compat_itimerspec(setting, &ts))
71105 return -EFAULT;
71106@@ -606,7 +606,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
71107 oldfs = get_fs();
71108 set_fs(KERNEL_DS);
71109 err = sys_clock_settime(which_clock,
71110- (struct timespec __user *) &ts);
71111+ (struct timespec __force_user *) &ts);
71112 set_fs(oldfs);
71113 return err;
71114 }
71115@@ -621,7 +621,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
71116 oldfs = get_fs();
71117 set_fs(KERNEL_DS);
71118 err = sys_clock_gettime(which_clock,
71119- (struct timespec __user *) &ts);
71120+ (struct timespec __force_user *) &ts);
71121 set_fs(oldfs);
71122 if (!err && put_compat_timespec(&ts, tp))
71123 return -EFAULT;
71124@@ -638,7 +638,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
71125 oldfs = get_fs();
71126 set_fs(KERNEL_DS);
71127 err = sys_clock_getres(which_clock,
71128- (struct timespec __user *) &ts);
71129+ (struct timespec __force_user *) &ts);
71130 set_fs(oldfs);
71131 if (!err && tp && put_compat_timespec(&ts, tp))
71132 return -EFAULT;
71133@@ -650,9 +650,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
71134 long err;
71135 mm_segment_t oldfs;
71136 struct timespec tu;
71137- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
71138+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
71139
71140- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
71141+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
71142 oldfs = get_fs();
71143 set_fs(KERNEL_DS);
71144 err = clock_nanosleep_restart(restart);
71145@@ -684,8 +684,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
71146 oldfs = get_fs();
71147 set_fs(KERNEL_DS);
71148 err = sys_clock_nanosleep(which_clock, flags,
71149- (struct timespec __user *) &in,
71150- (struct timespec __user *) &out);
71151+ (struct timespec __force_user *) &in,
71152+ (struct timespec __force_user *) &out);
71153 set_fs(oldfs);
71154
71155 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
71156diff --git a/kernel/configs.c b/kernel/configs.c
71157index abaee68..047facd 100644
71158--- a/kernel/configs.c
71159+++ b/kernel/configs.c
71160@@ -73,8 +73,19 @@ static int __init ikconfig_init(void)
71161 struct proc_dir_entry *entry;
71162
71163 /* create the current config file */
71164+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
71165+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
71166+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
71167+ &ikconfig_file_ops);
71168+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71169+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
71170+ &ikconfig_file_ops);
71171+#endif
71172+#else
71173 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
71174 &ikconfig_file_ops);
71175+#endif
71176+
71177 if (!entry)
71178 return -ENOMEM;
71179
71180diff --git a/kernel/cpu.c b/kernel/cpu.c
71181index 3f2f04f..4e53ded 100644
71182--- a/kernel/cpu.c
71183+++ b/kernel/cpu.c
71184@@ -20,7 +20,7 @@
71185 /* Serializes the updates to cpu_online_mask, cpu_present_mask */
71186 static DEFINE_MUTEX(cpu_add_remove_lock);
71187
71188-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
71189+static RAW_NOTIFIER_HEAD(cpu_chain);
71190
71191 /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
71192 * Should always be manipulated under cpu_add_remove_lock
71193diff --git a/kernel/cred.c b/kernel/cred.c
71194index 0b5b5fc..419b86a 100644
71195--- a/kernel/cred.c
71196+++ b/kernel/cred.c
71197@@ -160,6 +160,8 @@ static void put_cred_rcu(struct rcu_head *rcu)
71198 */
71199 void __put_cred(struct cred *cred)
71200 {
71201+ pax_track_stack();
71202+
71203 kdebug("__put_cred(%p{%d,%d})", cred,
71204 atomic_read(&cred->usage),
71205 read_cred_subscribers(cred));
71206@@ -184,6 +186,8 @@ void exit_creds(struct task_struct *tsk)
71207 {
71208 struct cred *cred;
71209
71210+ pax_track_stack();
71211+
71212 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
71213 atomic_read(&tsk->cred->usage),
71214 read_cred_subscribers(tsk->cred));
71215@@ -222,6 +226,8 @@ const struct cred *get_task_cred(struct task_struct *task)
71216 {
71217 const struct cred *cred;
71218
71219+ pax_track_stack();
71220+
71221 rcu_read_lock();
71222
71223 do {
71224@@ -241,6 +247,8 @@ struct cred *cred_alloc_blank(void)
71225 {
71226 struct cred *new;
71227
71228+ pax_track_stack();
71229+
71230 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
71231 if (!new)
71232 return NULL;
71233@@ -289,6 +297,8 @@ struct cred *prepare_creds(void)
71234 const struct cred *old;
71235 struct cred *new;
71236
71237+ pax_track_stack();
71238+
71239 validate_process_creds();
71240
71241 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
71242@@ -335,6 +345,8 @@ struct cred *prepare_exec_creds(void)
71243 struct thread_group_cred *tgcred = NULL;
71244 struct cred *new;
71245
71246+ pax_track_stack();
71247+
71248 #ifdef CONFIG_KEYS
71249 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
71250 if (!tgcred)
71251@@ -441,6 +453,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
71252 struct cred *new;
71253 int ret;
71254
71255+ pax_track_stack();
71256+
71257 mutex_init(&p->cred_guard_mutex);
71258
71259 if (
71260@@ -528,6 +542,8 @@ int commit_creds(struct cred *new)
71261 struct task_struct *task = current;
71262 const struct cred *old = task->real_cred;
71263
71264+ pax_track_stack();
71265+
71266 kdebug("commit_creds(%p{%d,%d})", new,
71267 atomic_read(&new->usage),
71268 read_cred_subscribers(new));
71269@@ -544,6 +560,8 @@ int commit_creds(struct cred *new)
71270
71271 get_cred(new); /* we will require a ref for the subj creds too */
71272
71273+ gr_set_role_label(task, new->uid, new->gid);
71274+
71275 /* dumpability changes */
71276 if (old->euid != new->euid ||
71277 old->egid != new->egid ||
71278@@ -563,10 +581,8 @@ int commit_creds(struct cred *new)
71279 key_fsgid_changed(task);
71280
71281 /* do it
71282- * - What if a process setreuid()'s and this brings the
71283- * new uid over his NPROC rlimit? We can check this now
71284- * cheaply with the new uid cache, so if it matters
71285- * we should be checking for it. -DaveM
71286+ * RLIMIT_NPROC limits on user->processes have already been checked
71287+ * in set_user().
71288 */
71289 alter_cred_subscribers(new, 2);
71290 if (new->user != old->user)
71291@@ -606,6 +622,8 @@ EXPORT_SYMBOL(commit_creds);
71292 */
71293 void abort_creds(struct cred *new)
71294 {
71295+ pax_track_stack();
71296+
71297 kdebug("abort_creds(%p{%d,%d})", new,
71298 atomic_read(&new->usage),
71299 read_cred_subscribers(new));
71300@@ -629,6 +647,8 @@ const struct cred *override_creds(const struct cred *new)
71301 {
71302 const struct cred *old = current->cred;
71303
71304+ pax_track_stack();
71305+
71306 kdebug("override_creds(%p{%d,%d})", new,
71307 atomic_read(&new->usage),
71308 read_cred_subscribers(new));
71309@@ -658,6 +678,8 @@ void revert_creds(const struct cred *old)
71310 {
71311 const struct cred *override = current->cred;
71312
71313+ pax_track_stack();
71314+
71315 kdebug("revert_creds(%p{%d,%d})", old,
71316 atomic_read(&old->usage),
71317 read_cred_subscribers(old));
71318@@ -704,6 +726,8 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
71319 const struct cred *old;
71320 struct cred *new;
71321
71322+ pax_track_stack();
71323+
71324 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
71325 if (!new)
71326 return NULL;
71327@@ -758,6 +782,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
71328 */
71329 int set_security_override(struct cred *new, u32 secid)
71330 {
71331+ pax_track_stack();
71332+
71333 return security_kernel_act_as(new, secid);
71334 }
71335 EXPORT_SYMBOL(set_security_override);
71336@@ -777,6 +803,8 @@ int set_security_override_from_ctx(struct cred *new, const char *secctx)
71337 u32 secid;
71338 int ret;
71339
71340+ pax_track_stack();
71341+
71342 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
71343 if (ret < 0)
71344 return ret;
71345diff --git a/kernel/exit.c b/kernel/exit.c
71346index 0f8fae3..9344a56 100644
71347--- a/kernel/exit.c
71348+++ b/kernel/exit.c
71349@@ -55,6 +55,10 @@
71350 #include <asm/pgtable.h>
71351 #include <asm/mmu_context.h>
71352
71353+#ifdef CONFIG_GRKERNSEC
71354+extern rwlock_t grsec_exec_file_lock;
71355+#endif
71356+
71357 static void exit_mm(struct task_struct * tsk);
71358
71359 static void __unhash_process(struct task_struct *p)
71360@@ -174,6 +178,10 @@ void release_task(struct task_struct * p)
71361 struct task_struct *leader;
71362 int zap_leader;
71363 repeat:
71364+#ifdef CONFIG_NET
71365+ gr_del_task_from_ip_table(p);
71366+#endif
71367+
71368 tracehook_prepare_release_task(p);
71369 /* don't need to get the RCU readlock here - the process is dead and
71370 * can't be modifying its own credentials */
71371@@ -397,7 +405,7 @@ int allow_signal(int sig)
71372 * know it'll be handled, so that they don't get converted to
71373 * SIGKILL or just silently dropped.
71374 */
71375- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
71376+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
71377 recalc_sigpending();
71378 spin_unlock_irq(&current->sighand->siglock);
71379 return 0;
71380@@ -433,6 +441,17 @@ void daemonize(const char *name, ...)
71381 vsnprintf(current->comm, sizeof(current->comm), name, args);
71382 va_end(args);
71383
71384+#ifdef CONFIG_GRKERNSEC
71385+ write_lock(&grsec_exec_file_lock);
71386+ if (current->exec_file) {
71387+ fput(current->exec_file);
71388+ current->exec_file = NULL;
71389+ }
71390+ write_unlock(&grsec_exec_file_lock);
71391+#endif
71392+
71393+ gr_set_kernel_label(current);
71394+
71395 /*
71396 * If we were started as result of loading a module, close all of the
71397 * user space pages. We don't need them, and if we didn't close them
71398@@ -897,17 +916,17 @@ NORET_TYPE void do_exit(long code)
71399 struct task_struct *tsk = current;
71400 int group_dead;
71401
71402- profile_task_exit(tsk);
71403-
71404- WARN_ON(atomic_read(&tsk->fs_excl));
71405-
71406+ /*
71407+ * Check this first since set_fs() below depends on
71408+ * current_thread_info(), which we better not access when we're in
71409+ * interrupt context. Other than that, we want to do the set_fs()
71410+ * as early as possible.
71411+ */
71412 if (unlikely(in_interrupt()))
71413 panic("Aiee, killing interrupt handler!");
71414- if (unlikely(!tsk->pid))
71415- panic("Attempted to kill the idle task!");
71416
71417 /*
71418- * If do_exit is called because this processes oopsed, it's possible
71419+ * If do_exit is called because this processes Oops'ed, it's possible
71420 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
71421 * continuing. Amongst other possible reasons, this is to prevent
71422 * mm_release()->clear_child_tid() from writing to a user-controlled
71423@@ -915,6 +934,13 @@ NORET_TYPE void do_exit(long code)
71424 */
71425 set_fs(USER_DS);
71426
71427+ profile_task_exit(tsk);
71428+
71429+ WARN_ON(atomic_read(&tsk->fs_excl));
71430+
71431+ if (unlikely(!tsk->pid))
71432+ panic("Attempted to kill the idle task!");
71433+
71434 tracehook_report_exit(&code);
71435
71436 validate_creds_for_do_exit(tsk);
71437@@ -973,6 +999,9 @@ NORET_TYPE void do_exit(long code)
71438 tsk->exit_code = code;
71439 taskstats_exit(tsk, group_dead);
71440
71441+ gr_acl_handle_psacct(tsk, code);
71442+ gr_acl_handle_exit();
71443+
71444 exit_mm(tsk);
71445
71446 if (group_dead)
71447@@ -1188,7 +1217,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
71448
71449 if (unlikely(wo->wo_flags & WNOWAIT)) {
71450 int exit_code = p->exit_code;
71451- int why, status;
71452+ int why;
71453
71454 get_task_struct(p);
71455 read_unlock(&tasklist_lock);
71456diff --git a/kernel/fork.c b/kernel/fork.c
71457index 4bde56f..29a9bab 100644
71458--- a/kernel/fork.c
71459+++ b/kernel/fork.c
71460@@ -253,7 +253,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
71461 *stackend = STACK_END_MAGIC; /* for overflow detection */
71462
71463 #ifdef CONFIG_CC_STACKPROTECTOR
71464- tsk->stack_canary = get_random_int();
71465+ tsk->stack_canary = pax_get_random_long();
71466 #endif
71467
71468 /* One for us, one for whoever does the "release_task()" (usually parent) */
71469@@ -293,8 +293,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
71470 mm->locked_vm = 0;
71471 mm->mmap = NULL;
71472 mm->mmap_cache = NULL;
71473- mm->free_area_cache = oldmm->mmap_base;
71474- mm->cached_hole_size = ~0UL;
71475+ mm->free_area_cache = oldmm->free_area_cache;
71476+ mm->cached_hole_size = oldmm->cached_hole_size;
71477 mm->map_count = 0;
71478 cpumask_clear(mm_cpumask(mm));
71479 mm->mm_rb = RB_ROOT;
71480@@ -335,6 +335,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
71481 tmp->vm_flags &= ~VM_LOCKED;
71482 tmp->vm_mm = mm;
71483 tmp->vm_next = tmp->vm_prev = NULL;
71484+ tmp->vm_mirror = NULL;
71485 anon_vma_link(tmp);
71486 file = tmp->vm_file;
71487 if (file) {
71488@@ -384,6 +385,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
71489 if (retval)
71490 goto out;
71491 }
71492+
71493+#ifdef CONFIG_PAX_SEGMEXEC
71494+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
71495+ struct vm_area_struct *mpnt_m;
71496+
71497+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
71498+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
71499+
71500+ if (!mpnt->vm_mirror)
71501+ continue;
71502+
71503+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
71504+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
71505+ mpnt->vm_mirror = mpnt_m;
71506+ } else {
71507+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
71508+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
71509+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
71510+ mpnt->vm_mirror->vm_mirror = mpnt;
71511+ }
71512+ }
71513+ BUG_ON(mpnt_m);
71514+ }
71515+#endif
71516+
71517 /* a new mm has just been created */
71518 arch_dup_mmap(oldmm, mm);
71519 retval = 0;
71520@@ -734,13 +760,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
71521 write_unlock(&fs->lock);
71522 return -EAGAIN;
71523 }
71524- fs->users++;
71525+ atomic_inc(&fs->users);
71526 write_unlock(&fs->lock);
71527 return 0;
71528 }
71529 tsk->fs = copy_fs_struct(fs);
71530 if (!tsk->fs)
71531 return -ENOMEM;
71532+ gr_set_chroot_entries(tsk, &tsk->fs->root);
71533 return 0;
71534 }
71535
71536@@ -1033,12 +1060,16 @@ static struct task_struct *copy_process(unsigned long clone_flags,
71537 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
71538 #endif
71539 retval = -EAGAIN;
71540+
71541+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
71542+
71543 if (atomic_read(&p->real_cred->user->processes) >=
71544 p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
71545- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
71546- p->real_cred->user != INIT_USER)
71547+ if (p->real_cred->user != INIT_USER &&
71548+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
71549 goto bad_fork_free;
71550 }
71551+ current->flags &= ~PF_NPROC_EXCEEDED;
71552
71553 retval = copy_creds(p, clone_flags);
71554 if (retval < 0)
71555@@ -1183,6 +1214,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
71556 goto bad_fork_free_pid;
71557 }
71558
71559+ gr_copy_label(p);
71560+
71561 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
71562 /*
71563 * Clear TID on mm_release()?
71564@@ -1333,6 +1366,8 @@ bad_fork_cleanup_count:
71565 bad_fork_free:
71566 free_task(p);
71567 fork_out:
71568+ gr_log_forkfail(retval);
71569+
71570 return ERR_PTR(retval);
71571 }
71572
71573@@ -1426,6 +1461,8 @@ long do_fork(unsigned long clone_flags,
71574 if (clone_flags & CLONE_PARENT_SETTID)
71575 put_user(nr, parent_tidptr);
71576
71577+ gr_handle_brute_check();
71578+
71579 if (clone_flags & CLONE_VFORK) {
71580 p->vfork_done = &vfork;
71581 init_completion(&vfork);
71582@@ -1558,7 +1595,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
71583 return 0;
71584
71585 /* don't need lock here; in the worst case we'll do useless copy */
71586- if (fs->users == 1)
71587+ if (atomic_read(&fs->users) == 1)
71588 return 0;
71589
71590 *new_fsp = copy_fs_struct(fs);
71591@@ -1681,7 +1718,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
71592 fs = current->fs;
71593 write_lock(&fs->lock);
71594 current->fs = new_fs;
71595- if (--fs->users)
71596+ gr_set_chroot_entries(current, &current->fs->root);
71597+ if (atomic_dec_return(&fs->users))
71598 new_fs = NULL;
71599 else
71600 new_fs = fs;
71601diff --git a/kernel/futex.c b/kernel/futex.c
71602index fb98c9f..333faec 100644
71603--- a/kernel/futex.c
71604+++ b/kernel/futex.c
71605@@ -54,6 +54,7 @@
71606 #include <linux/mount.h>
71607 #include <linux/pagemap.h>
71608 #include <linux/syscalls.h>
71609+#include <linux/ptrace.h>
71610 #include <linux/signal.h>
71611 #include <linux/module.h>
71612 #include <linux/magic.h>
71613@@ -223,6 +224,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
71614 struct page *page;
71615 int err, ro = 0;
71616
71617+#ifdef CONFIG_PAX_SEGMEXEC
71618+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
71619+ return -EFAULT;
71620+#endif
71621+
71622 /*
71623 * The futex address must be "naturally" aligned.
71624 */
71625@@ -1819,6 +1825,8 @@ static int futex_wait(u32 __user *uaddr, int fshared,
71626 struct futex_q q;
71627 int ret;
71628
71629+ pax_track_stack();
71630+
71631 if (!bitset)
71632 return -EINVAL;
71633
71634@@ -1871,7 +1879,7 @@ retry:
71635
71636 restart = &current_thread_info()->restart_block;
71637 restart->fn = futex_wait_restart;
71638- restart->futex.uaddr = (u32 *)uaddr;
71639+ restart->futex.uaddr = uaddr;
71640 restart->futex.val = val;
71641 restart->futex.time = abs_time->tv64;
71642 restart->futex.bitset = bitset;
71643@@ -2233,6 +2241,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, int fshared,
71644 struct futex_q q;
71645 int res, ret;
71646
71647+ pax_track_stack();
71648+
71649 if (!bitset)
71650 return -EINVAL;
71651
71652@@ -2423,6 +2433,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
71653 if (!p)
71654 goto err_unlock;
71655 ret = -EPERM;
71656+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71657+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
71658+ goto err_unlock;
71659+#endif
71660 pcred = __task_cred(p);
71661 if (cred->euid != pcred->euid &&
71662 cred->euid != pcred->uid &&
71663@@ -2489,7 +2503,7 @@ retry:
71664 */
71665 static inline int fetch_robust_entry(struct robust_list __user **entry,
71666 struct robust_list __user * __user *head,
71667- int *pi)
71668+ unsigned int *pi)
71669 {
71670 unsigned long uentry;
71671
71672@@ -2670,6 +2684,7 @@ static int __init futex_init(void)
71673 {
71674 u32 curval;
71675 int i;
71676+ mm_segment_t oldfs;
71677
71678 /*
71679 * This will fail and we want it. Some arch implementations do
71680@@ -2681,7 +2696,10 @@ static int __init futex_init(void)
71681 * implementation, the non functional ones will return
71682 * -ENOSYS.
71683 */
71684+ oldfs = get_fs();
71685+ set_fs(USER_DS);
71686 curval = cmpxchg_futex_value_locked(NULL, 0, 0);
71687+ set_fs(oldfs);
71688 if (curval == -EFAULT)
71689 futex_cmpxchg_enabled = 1;
71690
71691diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
71692index 2357165..eb25501 100644
71693--- a/kernel/futex_compat.c
71694+++ b/kernel/futex_compat.c
71695@@ -10,6 +10,7 @@
71696 #include <linux/compat.h>
71697 #include <linux/nsproxy.h>
71698 #include <linux/futex.h>
71699+#include <linux/ptrace.h>
71700
71701 #include <asm/uaccess.h>
71702
71703@@ -135,7 +136,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
71704 {
71705 struct compat_robust_list_head __user *head;
71706 unsigned long ret;
71707- const struct cred *cred = current_cred(), *pcred;
71708+ const struct cred *cred = current_cred();
71709+ const struct cred *pcred;
71710
71711 if (!futex_cmpxchg_enabled)
71712 return -ENOSYS;
71713@@ -151,6 +153,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
71714 if (!p)
71715 goto err_unlock;
71716 ret = -EPERM;
71717+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71718+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
71719+ goto err_unlock;
71720+#endif
71721 pcred = __task_cred(p);
71722 if (cred->euid != pcred->euid &&
71723 cred->euid != pcred->uid &&
71724diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
71725index 9b22d03..6295b62 100644
71726--- a/kernel/gcov/base.c
71727+++ b/kernel/gcov/base.c
71728@@ -102,11 +102,6 @@ void gcov_enable_events(void)
71729 }
71730
71731 #ifdef CONFIG_MODULES
71732-static inline int within(void *addr, void *start, unsigned long size)
71733-{
71734- return ((addr >= start) && (addr < start + size));
71735-}
71736-
71737 /* Update list and generate events when modules are unloaded. */
71738 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
71739 void *data)
71740@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
71741 prev = NULL;
71742 /* Remove entries located in module from linked list. */
71743 for (info = gcov_info_head; info; info = info->next) {
71744- if (within(info, mod->module_core, mod->core_size)) {
71745+ if (within_module_core_rw((unsigned long)info, mod)) {
71746 if (prev)
71747 prev->next = info->next;
71748 else
71749diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
71750index a6e9d00..a0da4f9 100644
71751--- a/kernel/hrtimer.c
71752+++ b/kernel/hrtimer.c
71753@@ -1391,7 +1391,7 @@ void hrtimer_peek_ahead_timers(void)
71754 local_irq_restore(flags);
71755 }
71756
71757-static void run_hrtimer_softirq(struct softirq_action *h)
71758+static void run_hrtimer_softirq(void)
71759 {
71760 hrtimer_peek_ahead_timers();
71761 }
71762diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
71763index 8b6b8b6..6bc87df 100644
71764--- a/kernel/kallsyms.c
71765+++ b/kernel/kallsyms.c
71766@@ -11,6 +11,9 @@
71767 * Changed the compression method from stem compression to "table lookup"
71768 * compression (see scripts/kallsyms.c for a more complete description)
71769 */
71770+#ifdef CONFIG_GRKERNSEC_HIDESYM
71771+#define __INCLUDED_BY_HIDESYM 1
71772+#endif
71773 #include <linux/kallsyms.h>
71774 #include <linux/module.h>
71775 #include <linux/init.h>
71776@@ -51,12 +54,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
71777
71778 static inline int is_kernel_inittext(unsigned long addr)
71779 {
71780+ if (system_state != SYSTEM_BOOTING)
71781+ return 0;
71782+
71783 if (addr >= (unsigned long)_sinittext
71784 && addr <= (unsigned long)_einittext)
71785 return 1;
71786 return 0;
71787 }
71788
71789+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71790+#ifdef CONFIG_MODULES
71791+static inline int is_module_text(unsigned long addr)
71792+{
71793+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
71794+ return 1;
71795+
71796+ addr = ktla_ktva(addr);
71797+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
71798+}
71799+#else
71800+static inline int is_module_text(unsigned long addr)
71801+{
71802+ return 0;
71803+}
71804+#endif
71805+#endif
71806+
71807 static inline int is_kernel_text(unsigned long addr)
71808 {
71809 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
71810@@ -67,13 +91,28 @@ static inline int is_kernel_text(unsigned long addr)
71811
71812 static inline int is_kernel(unsigned long addr)
71813 {
71814+
71815+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71816+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
71817+ return 1;
71818+
71819+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
71820+#else
71821 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
71822+#endif
71823+
71824 return 1;
71825 return in_gate_area_no_task(addr);
71826 }
71827
71828 static int is_ksym_addr(unsigned long addr)
71829 {
71830+
71831+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71832+ if (is_module_text(addr))
71833+ return 0;
71834+#endif
71835+
71836 if (all_var)
71837 return is_kernel(addr);
71838
71839@@ -413,7 +452,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
71840
71841 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
71842 {
71843- iter->name[0] = '\0';
71844 iter->nameoff = get_symbol_offset(new_pos);
71845 iter->pos = new_pos;
71846 }
71847@@ -461,6 +499,11 @@ static int s_show(struct seq_file *m, void *p)
71848 {
71849 struct kallsym_iter *iter = m->private;
71850
71851+#ifdef CONFIG_GRKERNSEC_HIDESYM
71852+ if (current_uid())
71853+ return 0;
71854+#endif
71855+
71856 /* Some debugging symbols have no name. Ignore them. */
71857 if (!iter->name[0])
71858 return 0;
71859@@ -501,7 +544,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
71860 struct kallsym_iter *iter;
71861 int ret;
71862
71863- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
71864+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
71865 if (!iter)
71866 return -ENOMEM;
71867 reset_iter(iter, 0);
71868diff --git a/kernel/kexec.c b/kernel/kexec.c
71869index f336e21..9c1c20b 100644
71870--- a/kernel/kexec.c
71871+++ b/kernel/kexec.c
71872@@ -1028,7 +1028,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
71873 unsigned long flags)
71874 {
71875 struct compat_kexec_segment in;
71876- struct kexec_segment out, __user *ksegments;
71877+ struct kexec_segment out;
71878+ struct kexec_segment __user *ksegments;
71879 unsigned long i, result;
71880
71881 /* Don't allow clients that don't understand the native
71882diff --git a/kernel/kgdb.c b/kernel/kgdb.c
71883index 53dae4b..9ba3743 100644
71884--- a/kernel/kgdb.c
71885+++ b/kernel/kgdb.c
71886@@ -86,7 +86,7 @@ static int kgdb_io_module_registered;
71887 /* Guard for recursive entry */
71888 static int exception_level;
71889
71890-static struct kgdb_io *kgdb_io_ops;
71891+static const struct kgdb_io *kgdb_io_ops;
71892 static DEFINE_SPINLOCK(kgdb_registration_lock);
71893
71894 /* kgdb console driver is loaded */
71895@@ -123,7 +123,7 @@ atomic_t kgdb_active = ATOMIC_INIT(-1);
71896 */
71897 static atomic_t passive_cpu_wait[NR_CPUS];
71898 static atomic_t cpu_in_kgdb[NR_CPUS];
71899-atomic_t kgdb_setting_breakpoint;
71900+atomic_unchecked_t kgdb_setting_breakpoint;
71901
71902 struct task_struct *kgdb_usethread;
71903 struct task_struct *kgdb_contthread;
71904@@ -140,7 +140,7 @@ static unsigned long gdb_regs[(NUMREGBYTES +
71905 sizeof(unsigned long)];
71906
71907 /* to keep track of the CPU which is doing the single stepping*/
71908-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
71909+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
71910
71911 /*
71912 * If you are debugging a problem where roundup (the collection of
71913@@ -815,7 +815,7 @@ static int kgdb_io_ready(int print_wait)
71914 return 0;
71915 if (kgdb_connected)
71916 return 1;
71917- if (atomic_read(&kgdb_setting_breakpoint))
71918+ if (atomic_read_unchecked(&kgdb_setting_breakpoint))
71919 return 1;
71920 if (print_wait)
71921 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
71922@@ -1426,8 +1426,8 @@ acquirelock:
71923 * instance of the exception handler wanted to come into the
71924 * debugger on a different CPU via a single step
71925 */
71926- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
71927- atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
71928+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
71929+ atomic_read_unchecked(&kgdb_cpu_doing_single_step) != cpu) {
71930
71931 atomic_set(&kgdb_active, -1);
71932 touch_softlockup_watchdog();
71933@@ -1634,7 +1634,7 @@ static void kgdb_initial_breakpoint(void)
71934 *
71935 * Register it with the KGDB core.
71936 */
71937-int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
71938+int kgdb_register_io_module(const struct kgdb_io *new_kgdb_io_ops)
71939 {
71940 int err;
71941
71942@@ -1679,7 +1679,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_module);
71943 *
71944 * Unregister it with the KGDB core.
71945 */
71946-void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
71947+void kgdb_unregister_io_module(const struct kgdb_io *old_kgdb_io_ops)
71948 {
71949 BUG_ON(kgdb_connected);
71950
71951@@ -1712,11 +1712,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);
71952 */
71953 void kgdb_breakpoint(void)
71954 {
71955- atomic_set(&kgdb_setting_breakpoint, 1);
71956+ atomic_set_unchecked(&kgdb_setting_breakpoint, 1);
71957 wmb(); /* Sync point before breakpoint */
71958 arch_kgdb_breakpoint();
71959 wmb(); /* Sync point after breakpoint */
71960- atomic_set(&kgdb_setting_breakpoint, 0);
71961+ atomic_set_unchecked(&kgdb_setting_breakpoint, 0);
71962 }
71963 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
71964
71965diff --git a/kernel/kmod.c b/kernel/kmod.c
71966index d206078..e27ba6a 100644
71967--- a/kernel/kmod.c
71968+++ b/kernel/kmod.c
71969@@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
71970 * If module auto-loading support is disabled then this function
71971 * becomes a no-operation.
71972 */
71973-int __request_module(bool wait, const char *fmt, ...)
71974+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
71975 {
71976- va_list args;
71977 char module_name[MODULE_NAME_LEN];
71978 unsigned int max_modprobes;
71979 int ret;
71980- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
71981+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
71982 static char *envp[] = { "HOME=/",
71983 "TERM=linux",
71984 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
71985@@ -84,12 +83,24 @@ int __request_module(bool wait, const char *fmt, ...)
71986 if (ret)
71987 return ret;
71988
71989- va_start(args, fmt);
71990- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
71991- va_end(args);
71992+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
71993 if (ret >= MODULE_NAME_LEN)
71994 return -ENAMETOOLONG;
71995
71996+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71997+ if (!current_uid()) {
71998+ /* hack to workaround consolekit/udisks stupidity */
71999+ read_lock(&tasklist_lock);
72000+ if (!strcmp(current->comm, "mount") &&
72001+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
72002+ read_unlock(&tasklist_lock);
72003+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
72004+ return -EPERM;
72005+ }
72006+ read_unlock(&tasklist_lock);
72007+ }
72008+#endif
72009+
72010 /* If modprobe needs a service that is in a module, we get a recursive
72011 * loop. Limit the number of running kmod threads to max_threads/2 or
72012 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
72013@@ -123,6 +134,48 @@ int __request_module(bool wait, const char *fmt, ...)
72014 atomic_dec(&kmod_concurrent);
72015 return ret;
72016 }
72017+
72018+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
72019+{
72020+ va_list args;
72021+ int ret;
72022+
72023+ va_start(args, fmt);
72024+ ret = ____request_module(wait, module_param, fmt, args);
72025+ va_end(args);
72026+
72027+ return ret;
72028+}
72029+
72030+int __request_module(bool wait, const char *fmt, ...)
72031+{
72032+ va_list args;
72033+ int ret;
72034+
72035+#ifdef CONFIG_GRKERNSEC_MODHARDEN
72036+ if (current_uid()) {
72037+ char module_param[MODULE_NAME_LEN];
72038+
72039+ memset(module_param, 0, sizeof(module_param));
72040+
72041+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
72042+
72043+ va_start(args, fmt);
72044+ ret = ____request_module(wait, module_param, fmt, args);
72045+ va_end(args);
72046+
72047+ return ret;
72048+ }
72049+#endif
72050+
72051+ va_start(args, fmt);
72052+ ret = ____request_module(wait, NULL, fmt, args);
72053+ va_end(args);
72054+
72055+ return ret;
72056+}
72057+
72058+
72059 EXPORT_SYMBOL(__request_module);
72060 #endif /* CONFIG_MODULES */
72061
72062@@ -228,7 +281,7 @@ static int wait_for_helper(void *data)
72063 *
72064 * Thus the __user pointer cast is valid here.
72065 */
72066- sys_wait4(pid, (int __user *)&ret, 0, NULL);
72067+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
72068
72069 /*
72070 * If ret is 0, either ____call_usermodehelper failed and the
72071diff --git a/kernel/kprobes.c b/kernel/kprobes.c
72072index 176d825..77fa8ea 100644
72073--- a/kernel/kprobes.c
72074+++ b/kernel/kprobes.c
72075@@ -183,7 +183,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(void)
72076 * kernel image and loaded module images reside. This is required
72077 * so x86_64 can correctly handle the %rip-relative fixups.
72078 */
72079- kip->insns = module_alloc(PAGE_SIZE);
72080+ kip->insns = module_alloc_exec(PAGE_SIZE);
72081 if (!kip->insns) {
72082 kfree(kip);
72083 return NULL;
72084@@ -220,7 +220,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
72085 */
72086 if (!list_is_singular(&kprobe_insn_pages)) {
72087 list_del(&kip->list);
72088- module_free(NULL, kip->insns);
72089+ module_free_exec(NULL, kip->insns);
72090 kfree(kip);
72091 }
72092 return 1;
72093@@ -1189,7 +1189,7 @@ static int __init init_kprobes(void)
72094 {
72095 int i, err = 0;
72096 unsigned long offset = 0, size = 0;
72097- char *modname, namebuf[128];
72098+ char *modname, namebuf[KSYM_NAME_LEN];
72099 const char *symbol_name;
72100 void *addr;
72101 struct kprobe_blackpoint *kb;
72102@@ -1304,7 +1304,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
72103 const char *sym = NULL;
72104 unsigned int i = *(loff_t *) v;
72105 unsigned long offset = 0;
72106- char *modname, namebuf[128];
72107+ char *modname, namebuf[KSYM_NAME_LEN];
72108
72109 head = &kprobe_table[i];
72110 preempt_disable();
72111diff --git a/kernel/lockdep.c b/kernel/lockdep.c
72112index d86fe89..d12fc66 100644
72113--- a/kernel/lockdep.c
72114+++ b/kernel/lockdep.c
72115@@ -421,20 +421,20 @@ static struct stack_trace lockdep_init_trace = {
72116 /*
72117 * Various lockdep statistics:
72118 */
72119-atomic_t chain_lookup_hits;
72120-atomic_t chain_lookup_misses;
72121-atomic_t hardirqs_on_events;
72122-atomic_t hardirqs_off_events;
72123-atomic_t redundant_hardirqs_on;
72124-atomic_t redundant_hardirqs_off;
72125-atomic_t softirqs_on_events;
72126-atomic_t softirqs_off_events;
72127-atomic_t redundant_softirqs_on;
72128-atomic_t redundant_softirqs_off;
72129-atomic_t nr_unused_locks;
72130-atomic_t nr_cyclic_checks;
72131-atomic_t nr_find_usage_forwards_checks;
72132-atomic_t nr_find_usage_backwards_checks;
72133+atomic_unchecked_t chain_lookup_hits;
72134+atomic_unchecked_t chain_lookup_misses;
72135+atomic_unchecked_t hardirqs_on_events;
72136+atomic_unchecked_t hardirqs_off_events;
72137+atomic_unchecked_t redundant_hardirqs_on;
72138+atomic_unchecked_t redundant_hardirqs_off;
72139+atomic_unchecked_t softirqs_on_events;
72140+atomic_unchecked_t softirqs_off_events;
72141+atomic_unchecked_t redundant_softirqs_on;
72142+atomic_unchecked_t redundant_softirqs_off;
72143+atomic_unchecked_t nr_unused_locks;
72144+atomic_unchecked_t nr_cyclic_checks;
72145+atomic_unchecked_t nr_find_usage_forwards_checks;
72146+atomic_unchecked_t nr_find_usage_backwards_checks;
72147 #endif
72148
72149 /*
72150@@ -577,6 +577,10 @@ static int static_obj(void *obj)
72151 int i;
72152 #endif
72153
72154+#ifdef CONFIG_PAX_KERNEXEC
72155+ start = ktla_ktva(start);
72156+#endif
72157+
72158 /*
72159 * static variable?
72160 */
72161@@ -592,8 +596,7 @@ static int static_obj(void *obj)
72162 */
72163 for_each_possible_cpu(i) {
72164 start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
72165- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
72166- + per_cpu_offset(i);
72167+ end = start + PERCPU_ENOUGH_ROOM;
72168
72169 if ((addr >= start) && (addr < end))
72170 return 1;
72171@@ -710,6 +713,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
72172 if (!static_obj(lock->key)) {
72173 debug_locks_off();
72174 printk("INFO: trying to register non-static key.\n");
72175+ printk("lock:%pS key:%pS.\n", lock, lock->key);
72176 printk("the code is fine but needs lockdep annotation.\n");
72177 printk("turning off the locking correctness validator.\n");
72178 dump_stack();
72179@@ -2751,7 +2755,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
72180 if (!class)
72181 return 0;
72182 }
72183- debug_atomic_inc((atomic_t *)&class->ops);
72184+ debug_atomic_inc((atomic_unchecked_t *)&class->ops);
72185 if (very_verbose(class)) {
72186 printk("\nacquire class [%p] %s", class->key, class->name);
72187 if (class->name_version > 1)
72188diff --git a/kernel/lockdep_internals.h b/kernel/lockdep_internals.h
72189index a2ee95a..092f0f2 100644
72190--- a/kernel/lockdep_internals.h
72191+++ b/kernel/lockdep_internals.h
72192@@ -113,26 +113,26 @@ lockdep_count_backward_deps(struct lock_class *class)
72193 /*
72194 * Various lockdep statistics:
72195 */
72196-extern atomic_t chain_lookup_hits;
72197-extern atomic_t chain_lookup_misses;
72198-extern atomic_t hardirqs_on_events;
72199-extern atomic_t hardirqs_off_events;
72200-extern atomic_t redundant_hardirqs_on;
72201-extern atomic_t redundant_hardirqs_off;
72202-extern atomic_t softirqs_on_events;
72203-extern atomic_t softirqs_off_events;
72204-extern atomic_t redundant_softirqs_on;
72205-extern atomic_t redundant_softirqs_off;
72206-extern atomic_t nr_unused_locks;
72207-extern atomic_t nr_cyclic_checks;
72208-extern atomic_t nr_cyclic_check_recursions;
72209-extern atomic_t nr_find_usage_forwards_checks;
72210-extern atomic_t nr_find_usage_forwards_recursions;
72211-extern atomic_t nr_find_usage_backwards_checks;
72212-extern atomic_t nr_find_usage_backwards_recursions;
72213-# define debug_atomic_inc(ptr) atomic_inc(ptr)
72214-# define debug_atomic_dec(ptr) atomic_dec(ptr)
72215-# define debug_atomic_read(ptr) atomic_read(ptr)
72216+extern atomic_unchecked_t chain_lookup_hits;
72217+extern atomic_unchecked_t chain_lookup_misses;
72218+extern atomic_unchecked_t hardirqs_on_events;
72219+extern atomic_unchecked_t hardirqs_off_events;
72220+extern atomic_unchecked_t redundant_hardirqs_on;
72221+extern atomic_unchecked_t redundant_hardirqs_off;
72222+extern atomic_unchecked_t softirqs_on_events;
72223+extern atomic_unchecked_t softirqs_off_events;
72224+extern atomic_unchecked_t redundant_softirqs_on;
72225+extern atomic_unchecked_t redundant_softirqs_off;
72226+extern atomic_unchecked_t nr_unused_locks;
72227+extern atomic_unchecked_t nr_cyclic_checks;
72228+extern atomic_unchecked_t nr_cyclic_check_recursions;
72229+extern atomic_unchecked_t nr_find_usage_forwards_checks;
72230+extern atomic_unchecked_t nr_find_usage_forwards_recursions;
72231+extern atomic_unchecked_t nr_find_usage_backwards_checks;
72232+extern atomic_unchecked_t nr_find_usage_backwards_recursions;
72233+# define debug_atomic_inc(ptr) atomic_inc_unchecked(ptr)
72234+# define debug_atomic_dec(ptr) atomic_dec_unchecked(ptr)
72235+# define debug_atomic_read(ptr) atomic_read_unchecked(ptr)
72236 #else
72237 # define debug_atomic_inc(ptr) do { } while (0)
72238 # define debug_atomic_dec(ptr) do { } while (0)
72239diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
72240index d4aba4f..02a353f 100644
72241--- a/kernel/lockdep_proc.c
72242+++ b/kernel/lockdep_proc.c
72243@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
72244
72245 static void print_name(struct seq_file *m, struct lock_class *class)
72246 {
72247- char str[128];
72248+ char str[KSYM_NAME_LEN];
72249 const char *name = class->name;
72250
72251 if (!name) {
72252diff --git a/kernel/module.c b/kernel/module.c
72253index 4b270e6..2226274 100644
72254--- a/kernel/module.c
72255+++ b/kernel/module.c
72256@@ -55,6 +55,7 @@
72257 #include <linux/async.h>
72258 #include <linux/percpu.h>
72259 #include <linux/kmemleak.h>
72260+#include <linux/grsecurity.h>
72261
72262 #define CREATE_TRACE_POINTS
72263 #include <trace/events/module.h>
72264@@ -89,7 +90,8 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq);
72265 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
72266
72267 /* Bounds of module allocation, for speeding __module_address */
72268-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
72269+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
72270+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
72271
72272 int register_module_notifier(struct notifier_block * nb)
72273 {
72274@@ -245,7 +247,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
72275 return true;
72276
72277 list_for_each_entry_rcu(mod, &modules, list) {
72278- struct symsearch arr[] = {
72279+ struct symsearch modarr[] = {
72280 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
72281 NOT_GPL_ONLY, false },
72282 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
72283@@ -267,7 +269,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
72284 #endif
72285 };
72286
72287- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
72288+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
72289 return true;
72290 }
72291 return false;
72292@@ -442,7 +444,7 @@ static void *percpu_modalloc(unsigned long size, unsigned long align,
72293 void *ptr;
72294 int cpu;
72295
72296- if (align > PAGE_SIZE) {
72297+ if (align-1 >= PAGE_SIZE) {
72298 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
72299 name, align, PAGE_SIZE);
72300 align = PAGE_SIZE;
72301@@ -1158,7 +1160,7 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
72302 * /sys/module/foo/sections stuff
72303 * J. Corbet <corbet@lwn.net>
72304 */
72305-#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
72306+#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
72307
72308 static inline bool sect_empty(const Elf_Shdr *sect)
72309 {
72310@@ -1545,7 +1547,8 @@ static void free_module(struct module *mod)
72311 destroy_params(mod->kp, mod->num_kp);
72312
72313 /* This may be NULL, but that's OK */
72314- module_free(mod, mod->module_init);
72315+ module_free(mod, mod->module_init_rw);
72316+ module_free_exec(mod, mod->module_init_rx);
72317 kfree(mod->args);
72318 if (mod->percpu)
72319 percpu_modfree(mod->percpu);
72320@@ -1554,10 +1557,12 @@ static void free_module(struct module *mod)
72321 percpu_modfree(mod->refptr);
72322 #endif
72323 /* Free lock-classes: */
72324- lockdep_free_key_range(mod->module_core, mod->core_size);
72325+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
72326+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
72327
72328 /* Finally, free the core (containing the module structure) */
72329- module_free(mod, mod->module_core);
72330+ module_free_exec(mod, mod->module_core_rx);
72331+ module_free(mod, mod->module_core_rw);
72332
72333 #ifdef CONFIG_MPU
72334 update_protections(current->mm);
72335@@ -1628,8 +1633,32 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
72336 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
72337 int ret = 0;
72338 const struct kernel_symbol *ksym;
72339+#ifdef CONFIG_GRKERNSEC_MODHARDEN
72340+ int is_fs_load = 0;
72341+ int register_filesystem_found = 0;
72342+ char *p;
72343+
72344+ p = strstr(mod->args, "grsec_modharden_fs");
72345+
72346+ if (p) {
72347+ char *endptr = p + strlen("grsec_modharden_fs");
72348+ /* copy \0 as well */
72349+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
72350+ is_fs_load = 1;
72351+ }
72352+#endif
72353+
72354
72355 for (i = 1; i < n; i++) {
72356+#ifdef CONFIG_GRKERNSEC_MODHARDEN
72357+ const char *name = strtab + sym[i].st_name;
72358+
72359+ /* it's a real shame this will never get ripped and copied
72360+ upstream! ;(
72361+ */
72362+ if (is_fs_load && !strcmp(name, "register_filesystem"))
72363+ register_filesystem_found = 1;
72364+#endif
72365 switch (sym[i].st_shndx) {
72366 case SHN_COMMON:
72367 /* We compiled with -fno-common. These are not
72368@@ -1651,7 +1680,9 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
72369 strtab + sym[i].st_name, mod);
72370 /* Ok if resolved. */
72371 if (ksym) {
72372+ pax_open_kernel();
72373 sym[i].st_value = ksym->value;
72374+ pax_close_kernel();
72375 break;
72376 }
72377
72378@@ -1670,11 +1701,20 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
72379 secbase = (unsigned long)mod->percpu;
72380 else
72381 secbase = sechdrs[sym[i].st_shndx].sh_addr;
72382+ pax_open_kernel();
72383 sym[i].st_value += secbase;
72384+ pax_close_kernel();
72385 break;
72386 }
72387 }
72388
72389+#ifdef CONFIG_GRKERNSEC_MODHARDEN
72390+ if (is_fs_load && !register_filesystem_found) {
72391+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
72392+ ret = -EPERM;
72393+ }
72394+#endif
72395+
72396 return ret;
72397 }
72398
72399@@ -1731,11 +1771,12 @@ static void layout_sections(struct module *mod,
72400 || s->sh_entsize != ~0UL
72401 || strstarts(secstrings + s->sh_name, ".init"))
72402 continue;
72403- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
72404+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
72405+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
72406+ else
72407+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
72408 DEBUGP("\t%s\n", secstrings + s->sh_name);
72409 }
72410- if (m == 0)
72411- mod->core_text_size = mod->core_size;
72412 }
72413
72414 DEBUGP("Init section allocation order:\n");
72415@@ -1748,12 +1789,13 @@ static void layout_sections(struct module *mod,
72416 || s->sh_entsize != ~0UL
72417 || !strstarts(secstrings + s->sh_name, ".init"))
72418 continue;
72419- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
72420- | INIT_OFFSET_MASK);
72421+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
72422+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
72423+ else
72424+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
72425+ s->sh_entsize |= INIT_OFFSET_MASK;
72426 DEBUGP("\t%s\n", secstrings + s->sh_name);
72427 }
72428- if (m == 0)
72429- mod->init_text_size = mod->init_size;
72430 }
72431 }
72432
72433@@ -1857,9 +1899,8 @@ static int is_exported(const char *name, unsigned long value,
72434
72435 /* As per nm */
72436 static char elf_type(const Elf_Sym *sym,
72437- Elf_Shdr *sechdrs,
72438- const char *secstrings,
72439- struct module *mod)
72440+ const Elf_Shdr *sechdrs,
72441+ const char *secstrings)
72442 {
72443 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
72444 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
72445@@ -1934,7 +1975,7 @@ static unsigned long layout_symtab(struct module *mod,
72446
72447 /* Put symbol section at end of init part of module. */
72448 symsect->sh_flags |= SHF_ALLOC;
72449- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
72450+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
72451 symindex) | INIT_OFFSET_MASK;
72452 DEBUGP("\t%s\n", secstrings + symsect->sh_name);
72453
72454@@ -1951,19 +1992,19 @@ static unsigned long layout_symtab(struct module *mod,
72455 }
72456
72457 /* Append room for core symbols at end of core part. */
72458- symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
72459- mod->core_size = symoffs + ndst * sizeof(Elf_Sym);
72460+ symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
72461+ mod->core_size_rx = symoffs + ndst * sizeof(Elf_Sym);
72462
72463 /* Put string table section at end of init part of module. */
72464 strsect->sh_flags |= SHF_ALLOC;
72465- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
72466+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
72467 strindex) | INIT_OFFSET_MASK;
72468 DEBUGP("\t%s\n", secstrings + strsect->sh_name);
72469
72470 /* Append room for core symbols' strings at end of core part. */
72471- *pstroffs = mod->core_size;
72472+ *pstroffs = mod->core_size_rx;
72473 __set_bit(0, strmap);
72474- mod->core_size += bitmap_weight(strmap, strsect->sh_size);
72475+ mod->core_size_rx += bitmap_weight(strmap, strsect->sh_size);
72476
72477 return symoffs;
72478 }
72479@@ -1987,12 +2028,14 @@ static void add_kallsyms(struct module *mod,
72480 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
72481 mod->strtab = (void *)sechdrs[strindex].sh_addr;
72482
72483+ pax_open_kernel();
72484+
72485 /* Set types up while we still have access to sections. */
72486 for (i = 0; i < mod->num_symtab; i++)
72487 mod->symtab[i].st_info
72488- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
72489+ = elf_type(&mod->symtab[i], sechdrs, secstrings);
72490
72491- mod->core_symtab = dst = mod->module_core + symoffs;
72492+ mod->core_symtab = dst = mod->module_core_rx + symoffs;
72493 src = mod->symtab;
72494 *dst = *src;
72495 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
72496@@ -2004,10 +2047,12 @@ static void add_kallsyms(struct module *mod,
72497 }
72498 mod->core_num_syms = ndst;
72499
72500- mod->core_strtab = s = mod->module_core + stroffs;
72501+ mod->core_strtab = s = mod->module_core_rx + stroffs;
72502 for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i)
72503 if (test_bit(i, strmap))
72504 *++s = mod->strtab[i];
72505+
72506+ pax_close_kernel();
72507 }
72508 #else
72509 static inline unsigned long layout_symtab(struct module *mod,
72510@@ -2044,16 +2089,30 @@ static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
72511 #endif
72512 }
72513
72514-static void *module_alloc_update_bounds(unsigned long size)
72515+static void *module_alloc_update_bounds_rw(unsigned long size)
72516 {
72517 void *ret = module_alloc(size);
72518
72519 if (ret) {
72520 /* Update module bounds. */
72521- if ((unsigned long)ret < module_addr_min)
72522- module_addr_min = (unsigned long)ret;
72523- if ((unsigned long)ret + size > module_addr_max)
72524- module_addr_max = (unsigned long)ret + size;
72525+ if ((unsigned long)ret < module_addr_min_rw)
72526+ module_addr_min_rw = (unsigned long)ret;
72527+ if ((unsigned long)ret + size > module_addr_max_rw)
72528+ module_addr_max_rw = (unsigned long)ret + size;
72529+ }
72530+ return ret;
72531+}
72532+
72533+static void *module_alloc_update_bounds_rx(unsigned long size)
72534+{
72535+ void *ret = module_alloc_exec(size);
72536+
72537+ if (ret) {
72538+ /* Update module bounds. */
72539+ if ((unsigned long)ret < module_addr_min_rx)
72540+ module_addr_min_rx = (unsigned long)ret;
72541+ if ((unsigned long)ret + size > module_addr_max_rx)
72542+ module_addr_max_rx = (unsigned long)ret + size;
72543 }
72544 return ret;
72545 }
72546@@ -2065,8 +2124,8 @@ static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
72547 unsigned int i;
72548
72549 /* only scan the sections containing data */
72550- kmemleak_scan_area(mod->module_core, (unsigned long)mod -
72551- (unsigned long)mod->module_core,
72552+ kmemleak_scan_area(mod->module_core_rw, (unsigned long)mod -
72553+ (unsigned long)mod->module_core_rw,
72554 sizeof(struct module), GFP_KERNEL);
72555
72556 for (i = 1; i < hdr->e_shnum; i++) {
72557@@ -2076,8 +2135,8 @@ static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
72558 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0)
72559 continue;
72560
72561- kmemleak_scan_area(mod->module_core, sechdrs[i].sh_addr -
72562- (unsigned long)mod->module_core,
72563+ kmemleak_scan_area(mod->module_core_rw, sechdrs[i].sh_addr -
72564+ (unsigned long)mod->module_core_rw,
72565 sechdrs[i].sh_size, GFP_KERNEL);
72566 }
72567 }
72568@@ -2097,7 +2156,7 @@ static noinline struct module *load_module(void __user *umod,
72569 Elf_Ehdr *hdr;
72570 Elf_Shdr *sechdrs;
72571 char *secstrings, *args, *modmagic, *strtab = NULL;
72572- char *staging;
72573+ char *staging, *license;
72574 unsigned int i;
72575 unsigned int symindex = 0;
72576 unsigned int strindex = 0;
72577@@ -2195,6 +2254,14 @@ static noinline struct module *load_module(void __user *umod,
72578 goto free_hdr;
72579 }
72580
72581+ license = get_modinfo(sechdrs, infoindex, "license");
72582+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
72583+ if (!license || !license_is_gpl_compatible(license)) {
72584+ err -ENOEXEC;
72585+ goto free_hdr;
72586+ }
72587+#endif
72588+
72589 modmagic = get_modinfo(sechdrs, infoindex, "vermagic");
72590 /* This is allowed: modprobe --force will invalidate it. */
72591 if (!modmagic) {
72592@@ -2263,7 +2330,7 @@ static noinline struct module *load_module(void __user *umod,
72593 secstrings, &stroffs, strmap);
72594
72595 /* Do the allocs. */
72596- ptr = module_alloc_update_bounds(mod->core_size);
72597+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
72598 /*
72599 * The pointer to this block is stored in the module structure
72600 * which is inside the block. Just mark it as not being a
72601@@ -2274,23 +2341,47 @@ static noinline struct module *load_module(void __user *umod,
72602 err = -ENOMEM;
72603 goto free_percpu;
72604 }
72605- memset(ptr, 0, mod->core_size);
72606- mod->module_core = ptr;
72607+ memset(ptr, 0, mod->core_size_rw);
72608+ mod->module_core_rw = ptr;
72609
72610- ptr = module_alloc_update_bounds(mod->init_size);
72611+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
72612 /*
72613 * The pointer to this block is stored in the module structure
72614 * which is inside the block. This block doesn't need to be
72615 * scanned as it contains data and code that will be freed
72616 * after the module is initialized.
72617 */
72618- kmemleak_ignore(ptr);
72619- if (!ptr && mod->init_size) {
72620+ kmemleak_not_leak(ptr);
72621+ if (!ptr && mod->init_size_rw) {
72622 err = -ENOMEM;
72623- goto free_core;
72624+ goto free_core_rw;
72625 }
72626- memset(ptr, 0, mod->init_size);
72627- mod->module_init = ptr;
72628+ memset(ptr, 0, mod->init_size_rw);
72629+ mod->module_init_rw = ptr;
72630+
72631+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
72632+ kmemleak_not_leak(ptr);
72633+ if (!ptr) {
72634+ err = -ENOMEM;
72635+ goto free_init_rw;
72636+ }
72637+
72638+ pax_open_kernel();
72639+ memset(ptr, 0, mod->core_size_rx);
72640+ pax_close_kernel();
72641+ mod->module_core_rx = ptr;
72642+
72643+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
72644+ kmemleak_not_leak(ptr);
72645+ if (!ptr && mod->init_size_rx) {
72646+ err = -ENOMEM;
72647+ goto free_core_rx;
72648+ }
72649+
72650+ pax_open_kernel();
72651+ memset(ptr, 0, mod->init_size_rx);
72652+ pax_close_kernel();
72653+ mod->module_init_rx = ptr;
72654
72655 /* Transfer each section which specifies SHF_ALLOC */
72656 DEBUGP("final section addresses:\n");
72657@@ -2300,17 +2391,45 @@ static noinline struct module *load_module(void __user *umod,
72658 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
72659 continue;
72660
72661- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
72662- dest = mod->module_init
72663- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72664- else
72665- dest = mod->module_core + sechdrs[i].sh_entsize;
72666+ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
72667+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
72668+ dest = mod->module_init_rw
72669+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72670+ else
72671+ dest = mod->module_init_rx
72672+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72673+ } else {
72674+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
72675+ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
72676+ else
72677+ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
72678+ }
72679
72680- if (sechdrs[i].sh_type != SHT_NOBITS)
72681- memcpy(dest, (void *)sechdrs[i].sh_addr,
72682- sechdrs[i].sh_size);
72683+ if (sechdrs[i].sh_type != SHT_NOBITS) {
72684+
72685+#ifdef CONFIG_PAX_KERNEXEC
72686+#ifdef CONFIG_X86_64
72687+ if ((sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_EXECINSTR))
72688+ set_memory_x((unsigned long)dest, (sechdrs[i].sh_size + PAGE_SIZE) >> PAGE_SHIFT);
72689+#endif
72690+ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
72691+ pax_open_kernel();
72692+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
72693+ pax_close_kernel();
72694+ } else
72695+#endif
72696+
72697+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
72698+ }
72699 /* Update sh_addr to point to copy in image. */
72700- sechdrs[i].sh_addr = (unsigned long)dest;
72701+
72702+#ifdef CONFIG_PAX_KERNEXEC
72703+ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
72704+ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
72705+ else
72706+#endif
72707+
72708+ sechdrs[i].sh_addr = (unsigned long)dest;
72709 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
72710 }
72711 /* Module has been moved. */
72712@@ -2322,7 +2441,7 @@ static noinline struct module *load_module(void __user *umod,
72713 mod->name);
72714 if (!mod->refptr) {
72715 err = -ENOMEM;
72716- goto free_init;
72717+ goto free_init_rx;
72718 }
72719 #endif
72720 /* Now we've moved module, initialize linked lists, etc. */
72721@@ -2334,7 +2453,7 @@ static noinline struct module *load_module(void __user *umod,
72722 goto free_unload;
72723
72724 /* Set up license info based on the info section */
72725- set_license(mod, get_modinfo(sechdrs, infoindex, "license"));
72726+ set_license(mod, license);
72727
72728 /*
72729 * ndiswrapper is under GPL by itself, but loads proprietary modules.
72730@@ -2351,6 +2470,31 @@ static noinline struct module *load_module(void __user *umod,
72731 /* Set up MODINFO_ATTR fields */
72732 setup_modinfo(mod, sechdrs, infoindex);
72733
72734+ mod->args = args;
72735+
72736+#ifdef CONFIG_GRKERNSEC_MODHARDEN
72737+ {
72738+ char *p, *p2;
72739+
72740+ if (strstr(mod->args, "grsec_modharden_netdev")) {
72741+ 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);
72742+ err = -EPERM;
72743+ goto cleanup;
72744+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
72745+ p += strlen("grsec_modharden_normal");
72746+ p2 = strstr(p, "_");
72747+ if (p2) {
72748+ *p2 = '\0';
72749+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
72750+ *p2 = '_';
72751+ }
72752+ err = -EPERM;
72753+ goto cleanup;
72754+ }
72755+ }
72756+#endif
72757+
72758+
72759 /* Fix up syms, so that st_value is a pointer to location. */
72760 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
72761 mod);
72762@@ -2431,8 +2575,8 @@ static noinline struct module *load_module(void __user *umod,
72763
72764 /* Now do relocations. */
72765 for (i = 1; i < hdr->e_shnum; i++) {
72766- const char *strtab = (char *)sechdrs[strindex].sh_addr;
72767 unsigned int info = sechdrs[i].sh_info;
72768+ strtab = (char *)sechdrs[strindex].sh_addr;
72769
72770 /* Not a valid relocation section? */
72771 if (info >= hdr->e_shnum)
72772@@ -2493,16 +2637,15 @@ static noinline struct module *load_module(void __user *umod,
72773 * Do it before processing of module parameters, so the module
72774 * can provide parameter accessor functions of its own.
72775 */
72776- if (mod->module_init)
72777- flush_icache_range((unsigned long)mod->module_init,
72778- (unsigned long)mod->module_init
72779- + mod->init_size);
72780- flush_icache_range((unsigned long)mod->module_core,
72781- (unsigned long)mod->module_core + mod->core_size);
72782+ if (mod->module_init_rx)
72783+ flush_icache_range((unsigned long)mod->module_init_rx,
72784+ (unsigned long)mod->module_init_rx
72785+ + mod->init_size_rx);
72786+ flush_icache_range((unsigned long)mod->module_core_rx,
72787+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
72788
72789 set_fs(old_fs);
72790
72791- mod->args = args;
72792 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
72793 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
72794 mod->name);
72795@@ -2546,12 +2689,16 @@ static noinline struct module *load_module(void __user *umod,
72796 free_unload:
72797 module_unload_free(mod);
72798 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
72799+ free_init_rx:
72800 percpu_modfree(mod->refptr);
72801- free_init:
72802 #endif
72803- module_free(mod, mod->module_init);
72804- free_core:
72805- module_free(mod, mod->module_core);
72806+ module_free_exec(mod, mod->module_init_rx);
72807+ free_core_rx:
72808+ module_free_exec(mod, mod->module_core_rx);
72809+ free_init_rw:
72810+ module_free(mod, mod->module_init_rw);
72811+ free_core_rw:
72812+ module_free(mod, mod->module_core_rw);
72813 /* mod will be freed with core. Don't access it beyond this line! */
72814 free_percpu:
72815 if (percpu)
72816@@ -2653,10 +2800,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
72817 mod->symtab = mod->core_symtab;
72818 mod->strtab = mod->core_strtab;
72819 #endif
72820- module_free(mod, mod->module_init);
72821- mod->module_init = NULL;
72822- mod->init_size = 0;
72823- mod->init_text_size = 0;
72824+ module_free(mod, mod->module_init_rw);
72825+ module_free_exec(mod, mod->module_init_rx);
72826+ mod->module_init_rw = NULL;
72827+ mod->module_init_rx = NULL;
72828+ mod->init_size_rw = 0;
72829+ mod->init_size_rx = 0;
72830 mutex_unlock(&module_mutex);
72831
72832 return 0;
72833@@ -2687,10 +2836,16 @@ static const char *get_ksymbol(struct module *mod,
72834 unsigned long nextval;
72835
72836 /* At worse, next value is at end of module */
72837- if (within_module_init(addr, mod))
72838- nextval = (unsigned long)mod->module_init+mod->init_text_size;
72839+ if (within_module_init_rx(addr, mod))
72840+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
72841+ else if (within_module_init_rw(addr, mod))
72842+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
72843+ else if (within_module_core_rx(addr, mod))
72844+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
72845+ else if (within_module_core_rw(addr, mod))
72846+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
72847 else
72848- nextval = (unsigned long)mod->module_core+mod->core_text_size;
72849+ return NULL;
72850
72851 /* Scan for closest preceeding symbol, and next symbol. (ELF
72852 starts real symbols at 1). */
72853@@ -2936,7 +3091,7 @@ static int m_show(struct seq_file *m, void *p)
72854 char buf[8];
72855
72856 seq_printf(m, "%s %u",
72857- mod->name, mod->init_size + mod->core_size);
72858+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
72859 print_unload_info(m, mod);
72860
72861 /* Informative for users. */
72862@@ -2945,7 +3100,7 @@ static int m_show(struct seq_file *m, void *p)
72863 mod->state == MODULE_STATE_COMING ? "Loading":
72864 "Live");
72865 /* Used by oprofile and other similar tools. */
72866- seq_printf(m, " 0x%p", mod->module_core);
72867+ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
72868
72869 /* Taints info */
72870 if (mod->taints)
72871@@ -2981,7 +3136,17 @@ static const struct file_operations proc_modules_operations = {
72872
72873 static int __init proc_modules_init(void)
72874 {
72875+#ifndef CONFIG_GRKERNSEC_HIDESYM
72876+#ifdef CONFIG_GRKERNSEC_PROC_USER
72877+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
72878+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72879+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
72880+#else
72881 proc_create("modules", 0, NULL, &proc_modules_operations);
72882+#endif
72883+#else
72884+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
72885+#endif
72886 return 0;
72887 }
72888 module_init(proc_modules_init);
72889@@ -3040,12 +3205,12 @@ struct module *__module_address(unsigned long addr)
72890 {
72891 struct module *mod;
72892
72893- if (addr < module_addr_min || addr > module_addr_max)
72894+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
72895+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
72896 return NULL;
72897
72898 list_for_each_entry_rcu(mod, &modules, list)
72899- if (within_module_core(addr, mod)
72900- || within_module_init(addr, mod))
72901+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
72902 return mod;
72903 return NULL;
72904 }
72905@@ -3079,11 +3244,20 @@ bool is_module_text_address(unsigned long addr)
72906 */
72907 struct module *__module_text_address(unsigned long addr)
72908 {
72909- struct module *mod = __module_address(addr);
72910+ struct module *mod;
72911+
72912+#ifdef CONFIG_X86_32
72913+ addr = ktla_ktva(addr);
72914+#endif
72915+
72916+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
72917+ return NULL;
72918+
72919+ mod = __module_address(addr);
72920+
72921 if (mod) {
72922 /* Make sure it's within the text section. */
72923- if (!within(addr, mod->module_init, mod->init_text_size)
72924- && !within(addr, mod->module_core, mod->core_text_size))
72925+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
72926 mod = NULL;
72927 }
72928 return mod;
72929diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
72930index ec815a9..fe46e99 100644
72931--- a/kernel/mutex-debug.c
72932+++ b/kernel/mutex-debug.c
72933@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
72934 }
72935
72936 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72937- struct thread_info *ti)
72938+ struct task_struct *task)
72939 {
72940 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
72941
72942 /* Mark the current thread as blocked on the lock: */
72943- ti->task->blocked_on = waiter;
72944+ task->blocked_on = waiter;
72945 }
72946
72947 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72948- struct thread_info *ti)
72949+ struct task_struct *task)
72950 {
72951 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
72952- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
72953- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
72954- ti->task->blocked_on = NULL;
72955+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
72956+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
72957+ task->blocked_on = NULL;
72958
72959 list_del_init(&waiter->list);
72960 waiter->task = NULL;
72961@@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lock)
72962 return;
72963
72964 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
72965- DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
72966+ DEBUG_LOCKS_WARN_ON(lock->owner != current);
72967 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
72968 mutex_clear_owner(lock);
72969 }
72970diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
72971index 6b2d735..372d3c4 100644
72972--- a/kernel/mutex-debug.h
72973+++ b/kernel/mutex-debug.h
72974@@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
72975 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
72976 extern void debug_mutex_add_waiter(struct mutex *lock,
72977 struct mutex_waiter *waiter,
72978- struct thread_info *ti);
72979+ struct task_struct *task);
72980 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72981- struct thread_info *ti);
72982+ struct task_struct *task);
72983 extern void debug_mutex_unlock(struct mutex *lock);
72984 extern void debug_mutex_init(struct mutex *lock, const char *name,
72985 struct lock_class_key *key);
72986
72987 static inline void mutex_set_owner(struct mutex *lock)
72988 {
72989- lock->owner = current_thread_info();
72990+ lock->owner = current;
72991 }
72992
72993 static inline void mutex_clear_owner(struct mutex *lock)
72994diff --git a/kernel/mutex.c b/kernel/mutex.c
72995index f85644c..5ee9f77 100644
72996--- a/kernel/mutex.c
72997+++ b/kernel/mutex.c
72998@@ -169,7 +169,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72999 */
73000
73001 for (;;) {
73002- struct thread_info *owner;
73003+ struct task_struct *owner;
73004
73005 /*
73006 * If we own the BKL, then don't spin. The owner of
73007@@ -214,7 +214,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
73008 spin_lock_mutex(&lock->wait_lock, flags);
73009
73010 debug_mutex_lock_common(lock, &waiter);
73011- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
73012+ debug_mutex_add_waiter(lock, &waiter, task);
73013
73014 /* add waiting tasks to the end of the waitqueue (FIFO): */
73015 list_add_tail(&waiter.list, &lock->wait_list);
73016@@ -243,8 +243,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
73017 * TASK_UNINTERRUPTIBLE case.)
73018 */
73019 if (unlikely(signal_pending_state(state, task))) {
73020- mutex_remove_waiter(lock, &waiter,
73021- task_thread_info(task));
73022+ mutex_remove_waiter(lock, &waiter, task);
73023 mutex_release(&lock->dep_map, 1, ip);
73024 spin_unlock_mutex(&lock->wait_lock, flags);
73025
73026@@ -265,7 +264,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
73027 done:
73028 lock_acquired(&lock->dep_map, ip);
73029 /* got the lock - rejoice! */
73030- mutex_remove_waiter(lock, &waiter, current_thread_info());
73031+ mutex_remove_waiter(lock, &waiter, task);
73032 mutex_set_owner(lock);
73033
73034 /* set it to 0 if there are no waiters left: */
73035diff --git a/kernel/mutex.h b/kernel/mutex.h
73036index 67578ca..4115fbf 100644
73037--- a/kernel/mutex.h
73038+++ b/kernel/mutex.h
73039@@ -19,7 +19,7 @@
73040 #ifdef CONFIG_SMP
73041 static inline void mutex_set_owner(struct mutex *lock)
73042 {
73043- lock->owner = current_thread_info();
73044+ lock->owner = current;
73045 }
73046
73047 static inline void mutex_clear_owner(struct mutex *lock)
73048diff --git a/kernel/panic.c b/kernel/panic.c
73049index 96b45d0..ff70a46 100644
73050--- a/kernel/panic.c
73051+++ b/kernel/panic.c
73052@@ -71,7 +71,11 @@ NORET_TYPE void panic(const char * fmt, ...)
73053 va_end(args);
73054 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
73055 #ifdef CONFIG_DEBUG_BUGVERBOSE
73056- dump_stack();
73057+ /*
73058+ * Avoid nested stack-dumping if a panic occurs during oops processing
73059+ */
73060+ if (!oops_in_progress)
73061+ dump_stack();
73062 #endif
73063
73064 /*
73065@@ -352,7 +356,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller, struc
73066 const char *board;
73067
73068 printk(KERN_WARNING "------------[ cut here ]------------\n");
73069- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
73070+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
73071 board = dmi_get_system_info(DMI_PRODUCT_NAME);
73072 if (board)
73073 printk(KERN_WARNING "Hardware name: %s\n", board);
73074@@ -392,7 +396,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
73075 */
73076 void __stack_chk_fail(void)
73077 {
73078- panic("stack-protector: Kernel stack is corrupted in: %p\n",
73079+ dump_stack();
73080+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
73081 __builtin_return_address(0));
73082 }
73083 EXPORT_SYMBOL(__stack_chk_fail);
73084diff --git a/kernel/params.c b/kernel/params.c
73085index d656c27..21e452c 100644
73086--- a/kernel/params.c
73087+++ b/kernel/params.c
73088@@ -725,7 +725,7 @@ static ssize_t module_attr_store(struct kobject *kobj,
73089 return ret;
73090 }
73091
73092-static struct sysfs_ops module_sysfs_ops = {
73093+static const struct sysfs_ops module_sysfs_ops = {
73094 .show = module_attr_show,
73095 .store = module_attr_store,
73096 };
73097@@ -739,7 +739,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
73098 return 0;
73099 }
73100
73101-static struct kset_uevent_ops module_uevent_ops = {
73102+static const struct kset_uevent_ops module_uevent_ops = {
73103 .filter = uevent_filter,
73104 };
73105
73106diff --git a/kernel/perf_event.c b/kernel/perf_event.c
73107index 37ebc14..9c121d9 100644
73108--- a/kernel/perf_event.c
73109+++ b/kernel/perf_event.c
73110@@ -77,7 +77,7 @@ int sysctl_perf_event_mlock __read_mostly = 516; /* 'free' kb per user */
73111 */
73112 int sysctl_perf_event_sample_rate __read_mostly = 100000;
73113
73114-static atomic64_t perf_event_id;
73115+static atomic64_unchecked_t perf_event_id;
73116
73117 /*
73118 * Lock for (sysadmin-configurable) event reservations:
73119@@ -1094,9 +1094,9 @@ static void __perf_event_sync_stat(struct perf_event *event,
73120 * In order to keep per-task stats reliable we need to flip the event
73121 * values when we flip the contexts.
73122 */
73123- value = atomic64_read(&next_event->count);
73124- value = atomic64_xchg(&event->count, value);
73125- atomic64_set(&next_event->count, value);
73126+ value = atomic64_read_unchecked(&next_event->count);
73127+ value = atomic64_xchg_unchecked(&event->count, value);
73128+ atomic64_set_unchecked(&next_event->count, value);
73129
73130 swap(event->total_time_enabled, next_event->total_time_enabled);
73131 swap(event->total_time_running, next_event->total_time_running);
73132@@ -1552,7 +1552,7 @@ static u64 perf_event_read(struct perf_event *event)
73133 update_event_times(event);
73134 }
73135
73136- return atomic64_read(&event->count);
73137+ return atomic64_read_unchecked(&event->count);
73138 }
73139
73140 /*
73141@@ -1790,11 +1790,11 @@ static int perf_event_read_group(struct perf_event *event,
73142 values[n++] = 1 + leader->nr_siblings;
73143 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
73144 values[n++] = leader->total_time_enabled +
73145- atomic64_read(&leader->child_total_time_enabled);
73146+ atomic64_read_unchecked(&leader->child_total_time_enabled);
73147 }
73148 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
73149 values[n++] = leader->total_time_running +
73150- atomic64_read(&leader->child_total_time_running);
73151+ atomic64_read_unchecked(&leader->child_total_time_running);
73152 }
73153
73154 size = n * sizeof(u64);
73155@@ -1829,11 +1829,11 @@ static int perf_event_read_one(struct perf_event *event,
73156 values[n++] = perf_event_read_value(event);
73157 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
73158 values[n++] = event->total_time_enabled +
73159- atomic64_read(&event->child_total_time_enabled);
73160+ atomic64_read_unchecked(&event->child_total_time_enabled);
73161 }
73162 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
73163 values[n++] = event->total_time_running +
73164- atomic64_read(&event->child_total_time_running);
73165+ atomic64_read_unchecked(&event->child_total_time_running);
73166 }
73167 if (read_format & PERF_FORMAT_ID)
73168 values[n++] = primary_event_id(event);
73169@@ -1903,7 +1903,7 @@ static unsigned int perf_poll(struct file *file, poll_table *wait)
73170 static void perf_event_reset(struct perf_event *event)
73171 {
73172 (void)perf_event_read(event);
73173- atomic64_set(&event->count, 0);
73174+ atomic64_set_unchecked(&event->count, 0);
73175 perf_event_update_userpage(event);
73176 }
73177
73178@@ -2079,15 +2079,15 @@ void perf_event_update_userpage(struct perf_event *event)
73179 ++userpg->lock;
73180 barrier();
73181 userpg->index = perf_event_index(event);
73182- userpg->offset = atomic64_read(&event->count);
73183+ userpg->offset = atomic64_read_unchecked(&event->count);
73184 if (event->state == PERF_EVENT_STATE_ACTIVE)
73185- userpg->offset -= atomic64_read(&event->hw.prev_count);
73186+ userpg->offset -= atomic64_read_unchecked(&event->hw.prev_count);
73187
73188 userpg->time_enabled = event->total_time_enabled +
73189- atomic64_read(&event->child_total_time_enabled);
73190+ atomic64_read_unchecked(&event->child_total_time_enabled);
73191
73192 userpg->time_running = event->total_time_running +
73193- atomic64_read(&event->child_total_time_running);
73194+ atomic64_read_unchecked(&event->child_total_time_running);
73195
73196 barrier();
73197 ++userpg->lock;
73198@@ -2903,14 +2903,14 @@ static void perf_output_read_one(struct perf_output_handle *handle,
73199 u64 values[4];
73200 int n = 0;
73201
73202- values[n++] = atomic64_read(&event->count);
73203+ values[n++] = atomic64_read_unchecked(&event->count);
73204 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
73205 values[n++] = event->total_time_enabled +
73206- atomic64_read(&event->child_total_time_enabled);
73207+ atomic64_read_unchecked(&event->child_total_time_enabled);
73208 }
73209 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
73210 values[n++] = event->total_time_running +
73211- atomic64_read(&event->child_total_time_running);
73212+ atomic64_read_unchecked(&event->child_total_time_running);
73213 }
73214 if (read_format & PERF_FORMAT_ID)
73215 values[n++] = primary_event_id(event);
73216@@ -2940,7 +2940,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
73217 if (leader != event)
73218 leader->pmu->read(leader);
73219
73220- values[n++] = atomic64_read(&leader->count);
73221+ values[n++] = atomic64_read_unchecked(&leader->count);
73222 if (read_format & PERF_FORMAT_ID)
73223 values[n++] = primary_event_id(leader);
73224
73225@@ -2952,7 +2952,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
73226 if (sub != event)
73227 sub->pmu->read(sub);
73228
73229- values[n++] = atomic64_read(&sub->count);
73230+ values[n++] = atomic64_read_unchecked(&sub->count);
73231 if (read_format & PERF_FORMAT_ID)
73232 values[n++] = primary_event_id(sub);
73233
73234@@ -3525,12 +3525,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
73235 * need to add enough zero bytes after the string to handle
73236 * the 64bit alignment we do later.
73237 */
73238- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
73239+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
73240 if (!buf) {
73241 name = strncpy(tmp, "//enomem", sizeof(tmp));
73242 goto got_name;
73243 }
73244- name = d_path(&file->f_path, buf, PATH_MAX);
73245+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
73246 if (IS_ERR(name)) {
73247 name = strncpy(tmp, "//toolong", sizeof(tmp));
73248 goto got_name;
73249@@ -3783,7 +3783,7 @@ static void perf_swevent_add(struct perf_event *event, u64 nr,
73250 {
73251 struct hw_perf_event *hwc = &event->hw;
73252
73253- atomic64_add(nr, &event->count);
73254+ atomic64_add_unchecked(nr, &event->count);
73255
73256 if (!hwc->sample_period)
73257 return;
73258@@ -4040,9 +4040,9 @@ static void cpu_clock_perf_event_update(struct perf_event *event)
73259 u64 now;
73260
73261 now = cpu_clock(cpu);
73262- prev = atomic64_read(&event->hw.prev_count);
73263- atomic64_set(&event->hw.prev_count, now);
73264- atomic64_add(now - prev, &event->count);
73265+ prev = atomic64_read_unchecked(&event->hw.prev_count);
73266+ atomic64_set_unchecked(&event->hw.prev_count, now);
73267+ atomic64_add_unchecked(now - prev, &event->count);
73268 }
73269
73270 static int cpu_clock_perf_event_enable(struct perf_event *event)
73271@@ -4050,7 +4050,7 @@ static int cpu_clock_perf_event_enable(struct perf_event *event)
73272 struct hw_perf_event *hwc = &event->hw;
73273 int cpu = raw_smp_processor_id();
73274
73275- atomic64_set(&hwc->prev_count, cpu_clock(cpu));
73276+ atomic64_set_unchecked(&hwc->prev_count, cpu_clock(cpu));
73277 perf_swevent_start_hrtimer(event);
73278
73279 return 0;
73280@@ -4082,9 +4082,9 @@ static void task_clock_perf_event_update(struct perf_event *event, u64 now)
73281 u64 prev;
73282 s64 delta;
73283
73284- prev = atomic64_xchg(&event->hw.prev_count, now);
73285+ prev = atomic64_xchg_unchecked(&event->hw.prev_count, now);
73286 delta = now - prev;
73287- atomic64_add(delta, &event->count);
73288+ atomic64_add_unchecked(delta, &event->count);
73289 }
73290
73291 static int task_clock_perf_event_enable(struct perf_event *event)
73292@@ -4094,7 +4094,7 @@ static int task_clock_perf_event_enable(struct perf_event *event)
73293
73294 now = event->ctx->time;
73295
73296- atomic64_set(&hwc->prev_count, now);
73297+ atomic64_set_unchecked(&hwc->prev_count, now);
73298
73299 perf_swevent_start_hrtimer(event);
73300
73301@@ -4289,7 +4289,7 @@ perf_event_alloc(struct perf_event_attr *attr,
73302 event->parent = parent_event;
73303
73304 event->ns = get_pid_ns(current->nsproxy->pid_ns);
73305- event->id = atomic64_inc_return(&perf_event_id);
73306+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
73307
73308 event->state = PERF_EVENT_STATE_INACTIVE;
73309
73310@@ -4720,15 +4720,15 @@ static void sync_child_event(struct perf_event *child_event,
73311 if (child_event->attr.inherit_stat)
73312 perf_event_read_event(child_event, child);
73313
73314- child_val = atomic64_read(&child_event->count);
73315+ child_val = atomic64_read_unchecked(&child_event->count);
73316
73317 /*
73318 * Add back the child's count to the parent's count:
73319 */
73320- atomic64_add(child_val, &parent_event->count);
73321- atomic64_add(child_event->total_time_enabled,
73322+ atomic64_add_unchecked(child_val, &parent_event->count);
73323+ atomic64_add_unchecked(child_event->total_time_enabled,
73324 &parent_event->child_total_time_enabled);
73325- atomic64_add(child_event->total_time_running,
73326+ atomic64_add_unchecked(child_event->total_time_running,
73327 &parent_event->child_total_time_running);
73328
73329 /*
73330diff --git a/kernel/pid.c b/kernel/pid.c
73331index fce7198..4f23a7e 100644
73332--- a/kernel/pid.c
73333+++ b/kernel/pid.c
73334@@ -33,6 +33,7 @@
73335 #include <linux/rculist.h>
73336 #include <linux/bootmem.h>
73337 #include <linux/hash.h>
73338+#include <linux/security.h>
73339 #include <linux/pid_namespace.h>
73340 #include <linux/init_task.h>
73341 #include <linux/syscalls.h>
73342@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
73343
73344 int pid_max = PID_MAX_DEFAULT;
73345
73346-#define RESERVED_PIDS 300
73347+#define RESERVED_PIDS 500
73348
73349 int pid_max_min = RESERVED_PIDS + 1;
73350 int pid_max_max = PID_MAX_LIMIT;
73351@@ -383,7 +384,14 @@ EXPORT_SYMBOL(pid_task);
73352 */
73353 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
73354 {
73355- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
73356+ struct task_struct *task;
73357+
73358+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
73359+
73360+ if (gr_pid_is_chrooted(task))
73361+ return NULL;
73362+
73363+ return task;
73364 }
73365
73366 struct task_struct *find_task_by_vpid(pid_t vnr)
73367@@ -391,6 +399,11 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
73368 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
73369 }
73370
73371+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
73372+{
73373+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
73374+}
73375+
73376 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
73377 {
73378 struct pid *pid;
73379diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
73380index 5c9dc22..d271117 100644
73381--- a/kernel/posix-cpu-timers.c
73382+++ b/kernel/posix-cpu-timers.c
73383@@ -6,6 +6,7 @@
73384 #include <linux/posix-timers.h>
73385 #include <linux/errno.h>
73386 #include <linux/math64.h>
73387+#include <linux/security.h>
73388 #include <asm/uaccess.h>
73389 #include <linux/kernel_stat.h>
73390 #include <trace/events/timer.h>
73391@@ -1697,7 +1698,7 @@ static long thread_cpu_nsleep_restart(struct restart_block *restart_block)
73392
73393 static __init int init_posix_cpu_timers(void)
73394 {
73395- struct k_clock process = {
73396+ static struct k_clock process = {
73397 .clock_getres = process_cpu_clock_getres,
73398 .clock_get = process_cpu_clock_get,
73399 .clock_set = do_posix_clock_nosettime,
73400@@ -1705,7 +1706,7 @@ static __init int init_posix_cpu_timers(void)
73401 .nsleep = process_cpu_nsleep,
73402 .nsleep_restart = process_cpu_nsleep_restart,
73403 };
73404- struct k_clock thread = {
73405+ static struct k_clock thread = {
73406 .clock_getres = thread_cpu_clock_getres,
73407 .clock_get = thread_cpu_clock_get,
73408 .clock_set = do_posix_clock_nosettime,
73409diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
73410index 5e76d22..cf1baeb 100644
73411--- a/kernel/posix-timers.c
73412+++ b/kernel/posix-timers.c
73413@@ -42,6 +42,7 @@
73414 #include <linux/compiler.h>
73415 #include <linux/idr.h>
73416 #include <linux/posix-timers.h>
73417+#include <linux/grsecurity.h>
73418 #include <linux/syscalls.h>
73419 #include <linux/wait.h>
73420 #include <linux/workqueue.h>
73421@@ -131,7 +132,7 @@ static DEFINE_SPINLOCK(idr_lock);
73422 * which we beg off on and pass to do_sys_settimeofday().
73423 */
73424
73425-static struct k_clock posix_clocks[MAX_CLOCKS];
73426+static struct k_clock *posix_clocks[MAX_CLOCKS];
73427
73428 /*
73429 * These ones are defined below.
73430@@ -157,8 +158,8 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
73431 */
73432 #define CLOCK_DISPATCH(clock, call, arglist) \
73433 ((clock) < 0 ? posix_cpu_##call arglist : \
73434- (posix_clocks[clock].call != NULL \
73435- ? (*posix_clocks[clock].call) arglist : common_##call arglist))
73436+ (posix_clocks[clock]->call != NULL \
73437+ ? (*posix_clocks[clock]->call) arglist : common_##call arglist))
73438
73439 /*
73440 * Default clock hook functions when the struct k_clock passed
73441@@ -172,7 +173,7 @@ static inline int common_clock_getres(const clockid_t which_clock,
73442 struct timespec *tp)
73443 {
73444 tp->tv_sec = 0;
73445- tp->tv_nsec = posix_clocks[which_clock].res;
73446+ tp->tv_nsec = posix_clocks[which_clock]->res;
73447 return 0;
73448 }
73449
73450@@ -217,9 +218,11 @@ static inline int invalid_clockid(const clockid_t which_clock)
73451 return 0;
73452 if ((unsigned) which_clock >= MAX_CLOCKS)
73453 return 1;
73454- if (posix_clocks[which_clock].clock_getres != NULL)
73455+ if (posix_clocks[which_clock] == NULL)
73456 return 0;
73457- if (posix_clocks[which_clock].res != 0)
73458+ if (posix_clocks[which_clock]->clock_getres != NULL)
73459+ return 0;
73460+ if (posix_clocks[which_clock]->res != 0)
73461 return 0;
73462 return 1;
73463 }
73464@@ -266,29 +269,29 @@ int posix_get_coarse_res(const clockid_t which_clock, struct timespec *tp)
73465 */
73466 static __init int init_posix_timers(void)
73467 {
73468- struct k_clock clock_realtime = {
73469+ static struct k_clock clock_realtime = {
73470 .clock_getres = hrtimer_get_res,
73471 };
73472- struct k_clock clock_monotonic = {
73473+ static struct k_clock clock_monotonic = {
73474 .clock_getres = hrtimer_get_res,
73475 .clock_get = posix_ktime_get_ts,
73476 .clock_set = do_posix_clock_nosettime,
73477 };
73478- struct k_clock clock_monotonic_raw = {
73479+ static struct k_clock clock_monotonic_raw = {
73480 .clock_getres = hrtimer_get_res,
73481 .clock_get = posix_get_monotonic_raw,
73482 .clock_set = do_posix_clock_nosettime,
73483 .timer_create = no_timer_create,
73484 .nsleep = no_nsleep,
73485 };
73486- struct k_clock clock_realtime_coarse = {
73487+ static struct k_clock clock_realtime_coarse = {
73488 .clock_getres = posix_get_coarse_res,
73489 .clock_get = posix_get_realtime_coarse,
73490 .clock_set = do_posix_clock_nosettime,
73491 .timer_create = no_timer_create,
73492 .nsleep = no_nsleep,
73493 };
73494- struct k_clock clock_monotonic_coarse = {
73495+ static struct k_clock clock_monotonic_coarse = {
73496 .clock_getres = posix_get_coarse_res,
73497 .clock_get = posix_get_monotonic_coarse,
73498 .clock_set = do_posix_clock_nosettime,
73499@@ -296,6 +299,8 @@ static __init int init_posix_timers(void)
73500 .nsleep = no_nsleep,
73501 };
73502
73503+ pax_track_stack();
73504+
73505 register_posix_clock(CLOCK_REALTIME, &clock_realtime);
73506 register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
73507 register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
73508@@ -484,7 +489,7 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
73509 return;
73510 }
73511
73512- posix_clocks[clock_id] = *new_clock;
73513+ posix_clocks[clock_id] = new_clock;
73514 }
73515 EXPORT_SYMBOL_GPL(register_posix_clock);
73516
73517@@ -948,6 +953,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
73518 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
73519 return -EFAULT;
73520
73521+ /* only the CLOCK_REALTIME clock can be set, all other clocks
73522+ have their clock_set fptr set to a nosettime dummy function
73523+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
73524+ call common_clock_set, which calls do_sys_settimeofday, which
73525+ we hook
73526+ */
73527+
73528 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
73529 }
73530
73531diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
73532index 04a9e90..bc355aa 100644
73533--- a/kernel/power/hibernate.c
73534+++ b/kernel/power/hibernate.c
73535@@ -48,14 +48,14 @@ enum {
73536
73537 static int hibernation_mode = HIBERNATION_SHUTDOWN;
73538
73539-static struct platform_hibernation_ops *hibernation_ops;
73540+static const struct platform_hibernation_ops *hibernation_ops;
73541
73542 /**
73543 * hibernation_set_ops - set the global hibernate operations
73544 * @ops: the hibernation operations to use in subsequent hibernation transitions
73545 */
73546
73547-void hibernation_set_ops(struct platform_hibernation_ops *ops)
73548+void hibernation_set_ops(const struct platform_hibernation_ops *ops)
73549 {
73550 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
73551 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
73552diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
73553index e8b3370..484c2e4 100644
73554--- a/kernel/power/poweroff.c
73555+++ b/kernel/power/poweroff.c
73556@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
73557 .enable_mask = SYSRQ_ENABLE_BOOT,
73558 };
73559
73560-static int pm_sysrq_init(void)
73561+static int __init pm_sysrq_init(void)
73562 {
73563 register_sysrq_key('o', &sysrq_poweroff_op);
73564 return 0;
73565diff --git a/kernel/power/process.c b/kernel/power/process.c
73566index e7cd671..56d5f459 100644
73567--- a/kernel/power/process.c
73568+++ b/kernel/power/process.c
73569@@ -37,12 +37,15 @@ static int try_to_freeze_tasks(bool sig_only)
73570 struct timeval start, end;
73571 u64 elapsed_csecs64;
73572 unsigned int elapsed_csecs;
73573+ bool timedout = false;
73574
73575 do_gettimeofday(&start);
73576
73577 end_time = jiffies + TIMEOUT;
73578 do {
73579 todo = 0;
73580+ if (time_after(jiffies, end_time))
73581+ timedout = true;
73582 read_lock(&tasklist_lock);
73583 do_each_thread(g, p) {
73584 if (frozen(p) || !freezeable(p))
73585@@ -57,15 +60,17 @@ static int try_to_freeze_tasks(bool sig_only)
73586 * It is "frozen enough". If the task does wake
73587 * up, it will immediately call try_to_freeze.
73588 */
73589- if (!task_is_stopped_or_traced(p) &&
73590- !freezer_should_skip(p))
73591+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
73592 todo++;
73593+ if (timedout) {
73594+ printk(KERN_ERR "Task refusing to freeze:\n");
73595+ sched_show_task(p);
73596+ }
73597+ }
73598 } while_each_thread(g, p);
73599 read_unlock(&tasklist_lock);
73600 yield(); /* Yield is okay here */
73601- if (time_after(jiffies, end_time))
73602- break;
73603- } while (todo);
73604+ } while (todo && !timedout);
73605
73606 do_gettimeofday(&end);
73607 elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
73608diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
73609index 40dd021..fb30ceb 100644
73610--- a/kernel/power/suspend.c
73611+++ b/kernel/power/suspend.c
73612@@ -23,13 +23,13 @@ const char *const pm_states[PM_SUSPEND_MAX] = {
73613 [PM_SUSPEND_MEM] = "mem",
73614 };
73615
73616-static struct platform_suspend_ops *suspend_ops;
73617+static const struct platform_suspend_ops *suspend_ops;
73618
73619 /**
73620 * suspend_set_ops - Set the global suspend method table.
73621 * @ops: Pointer to ops structure.
73622 */
73623-void suspend_set_ops(struct platform_suspend_ops *ops)
73624+void suspend_set_ops(const struct platform_suspend_ops *ops)
73625 {
73626 mutex_lock(&pm_mutex);
73627 suspend_ops = ops;
73628diff --git a/kernel/printk.c b/kernel/printk.c
73629index 4cade47..4d17900 100644
73630--- a/kernel/printk.c
73631+++ b/kernel/printk.c
73632@@ -33,6 +33,7 @@
73633 #include <linux/bootmem.h>
73634 #include <linux/syscalls.h>
73635 #include <linux/kexec.h>
73636+#include <linux/syslog.h>
73637
73638 #include <asm/uaccess.h>
73639
73640@@ -256,38 +257,30 @@ static inline void boot_delay_msec(void)
73641 }
73642 #endif
73643
73644-/*
73645- * Commands to do_syslog:
73646- *
73647- * 0 -- Close the log. Currently a NOP.
73648- * 1 -- Open the log. Currently a NOP.
73649- * 2 -- Read from the log.
73650- * 3 -- Read all messages remaining in the ring buffer.
73651- * 4 -- Read and clear all messages remaining in the ring buffer
73652- * 5 -- Clear ring buffer.
73653- * 6 -- Disable printk's to console
73654- * 7 -- Enable printk's to console
73655- * 8 -- Set level of messages printed to console
73656- * 9 -- Return number of unread characters in the log buffer
73657- * 10 -- Return size of the log buffer
73658- */
73659-int do_syslog(int type, char __user *buf, int len)
73660+int do_syslog(int type, char __user *buf, int len, bool from_file)
73661 {
73662 unsigned i, j, limit, count;
73663 int do_clear = 0;
73664 char c;
73665 int error = 0;
73666
73667- error = security_syslog(type);
73668+#ifdef CONFIG_GRKERNSEC_DMESG
73669+ if (grsec_enable_dmesg &&
73670+ (!from_file || (from_file && type == SYSLOG_ACTION_OPEN)) &&
73671+ !capable(CAP_SYS_ADMIN))
73672+ return -EPERM;
73673+#endif
73674+
73675+ error = security_syslog(type, from_file);
73676 if (error)
73677 return error;
73678
73679 switch (type) {
73680- case 0: /* Close log */
73681+ case SYSLOG_ACTION_CLOSE: /* Close log */
73682 break;
73683- case 1: /* Open log */
73684+ case SYSLOG_ACTION_OPEN: /* Open log */
73685 break;
73686- case 2: /* Read from log */
73687+ case SYSLOG_ACTION_READ: /* Read from log */
73688 error = -EINVAL;
73689 if (!buf || len < 0)
73690 goto out;
73691@@ -318,10 +311,12 @@ int do_syslog(int type, char __user *buf, int len)
73692 if (!error)
73693 error = i;
73694 break;
73695- case 4: /* Read/clear last kernel messages */
73696+ /* Read/clear last kernel messages */
73697+ case SYSLOG_ACTION_READ_CLEAR:
73698 do_clear = 1;
73699 /* FALL THRU */
73700- case 3: /* Read last kernel messages */
73701+ /* Read last kernel messages */
73702+ case SYSLOG_ACTION_READ_ALL:
73703 error = -EINVAL;
73704 if (!buf || len < 0)
73705 goto out;
73706@@ -374,21 +369,25 @@ int do_syslog(int type, char __user *buf, int len)
73707 }
73708 }
73709 break;
73710- case 5: /* Clear ring buffer */
73711+ /* Clear ring buffer */
73712+ case SYSLOG_ACTION_CLEAR:
73713 logged_chars = 0;
73714 break;
73715- case 6: /* Disable logging to console */
73716+ /* Disable logging to console */
73717+ case SYSLOG_ACTION_CONSOLE_OFF:
73718 if (saved_console_loglevel == -1)
73719 saved_console_loglevel = console_loglevel;
73720 console_loglevel = minimum_console_loglevel;
73721 break;
73722- case 7: /* Enable logging to console */
73723+ /* Enable logging to console */
73724+ case SYSLOG_ACTION_CONSOLE_ON:
73725 if (saved_console_loglevel != -1) {
73726 console_loglevel = saved_console_loglevel;
73727 saved_console_loglevel = -1;
73728 }
73729 break;
73730- case 8: /* Set level of messages printed to console */
73731+ /* Set level of messages printed to console */
73732+ case SYSLOG_ACTION_CONSOLE_LEVEL:
73733 error = -EINVAL;
73734 if (len < 1 || len > 8)
73735 goto out;
73736@@ -399,10 +398,12 @@ int do_syslog(int type, char __user *buf, int len)
73737 saved_console_loglevel = -1;
73738 error = 0;
73739 break;
73740- case 9: /* Number of chars in the log buffer */
73741+ /* Number of chars in the log buffer */
73742+ case SYSLOG_ACTION_SIZE_UNREAD:
73743 error = log_end - log_start;
73744 break;
73745- case 10: /* Size of the log buffer */
73746+ /* Size of the log buffer */
73747+ case SYSLOG_ACTION_SIZE_BUFFER:
73748 error = log_buf_len;
73749 break;
73750 default:
73751@@ -415,7 +416,7 @@ out:
73752
73753 SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
73754 {
73755- return do_syslog(type, buf, len);
73756+ return do_syslog(type, buf, len, SYSLOG_FROM_CALL);
73757 }
73758
73759 /*
73760diff --git a/kernel/profile.c b/kernel/profile.c
73761index dfadc5b..7f59404 100644
73762--- a/kernel/profile.c
73763+++ b/kernel/profile.c
73764@@ -39,7 +39,7 @@ struct profile_hit {
73765 /* Oprofile timer tick hook */
73766 static int (*timer_hook)(struct pt_regs *) __read_mostly;
73767
73768-static atomic_t *prof_buffer;
73769+static atomic_unchecked_t *prof_buffer;
73770 static unsigned long prof_len, prof_shift;
73771
73772 int prof_on __read_mostly;
73773@@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
73774 hits[i].pc = 0;
73775 continue;
73776 }
73777- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
73778+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
73779 hits[i].hits = hits[i].pc = 0;
73780 }
73781 }
73782@@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits)
73783 * Add the current hit(s) and flush the write-queue out
73784 * to the global buffer:
73785 */
73786- atomic_add(nr_hits, &prof_buffer[pc]);
73787+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
73788 for (i = 0; i < NR_PROFILE_HIT; ++i) {
73789- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
73790+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
73791 hits[i].pc = hits[i].hits = 0;
73792 }
73793 out:
73794@@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits)
73795 if (prof_on != type || !prof_buffer)
73796 return;
73797 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
73798- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
73799+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
73800 }
73801 #endif /* !CONFIG_SMP */
73802 EXPORT_SYMBOL_GPL(profile_hits);
73803@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
73804 return -EFAULT;
73805 buf++; p++; count--; read++;
73806 }
73807- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
73808+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
73809 if (copy_to_user(buf, (void *)pnt, count))
73810 return -EFAULT;
73811 read += count;
73812@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
73813 }
73814 #endif
73815 profile_discard_flip_buffers();
73816- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
73817+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
73818 return count;
73819 }
73820
73821diff --git a/kernel/ptrace.c b/kernel/ptrace.c
73822index 05625f6..733bf70 100644
73823--- a/kernel/ptrace.c
73824+++ b/kernel/ptrace.c
73825@@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_struct *child, int kill)
73826 return ret;
73827 }
73828
73829-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73830+static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
73831+ unsigned int log)
73832 {
73833 const struct cred *cred = current_cred(), *tcred;
73834
73835@@ -141,7 +142,9 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73836 cred->gid != tcred->egid ||
73837 cred->gid != tcred->sgid ||
73838 cred->gid != tcred->gid) &&
73839- !capable(CAP_SYS_PTRACE)) {
73840+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
73841+ (log && !capable(CAP_SYS_PTRACE)))
73842+ ) {
73843 rcu_read_unlock();
73844 return -EPERM;
73845 }
73846@@ -149,7 +152,9 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73847 smp_rmb();
73848 if (task->mm)
73849 dumpable = get_dumpable(task->mm);
73850- if (!dumpable && !capable(CAP_SYS_PTRACE))
73851+ if (!dumpable &&
73852+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
73853+ (log && !capable(CAP_SYS_PTRACE))))
73854 return -EPERM;
73855
73856 return security_ptrace_access_check(task, mode);
73857@@ -159,7 +164,16 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
73858 {
73859 int err;
73860 task_lock(task);
73861- err = __ptrace_may_access(task, mode);
73862+ err = __ptrace_may_access(task, mode, 0);
73863+ task_unlock(task);
73864+ return !err;
73865+}
73866+
73867+bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
73868+{
73869+ int err;
73870+ task_lock(task);
73871+ err = __ptrace_may_access(task, mode, 1);
73872 task_unlock(task);
73873 return !err;
73874 }
73875@@ -186,7 +200,7 @@ int ptrace_attach(struct task_struct *task)
73876 goto out;
73877
73878 task_lock(task);
73879- retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
73880+ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
73881 task_unlock(task);
73882 if (retval)
73883 goto unlock_creds;
73884@@ -199,7 +213,7 @@ int ptrace_attach(struct task_struct *task)
73885 goto unlock_tasklist;
73886
73887 task->ptrace = PT_PTRACED;
73888- if (capable(CAP_SYS_PTRACE))
73889+ if (capable_nolog(CAP_SYS_PTRACE))
73890 task->ptrace |= PT_PTRACE_CAP;
73891
73892 __ptrace_link(task, current);
73893@@ -351,6 +365,8 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
73894 {
73895 int copied = 0;
73896
73897+ pax_track_stack();
73898+
73899 while (len > 0) {
73900 char buf[128];
73901 int this_len, retval;
73902@@ -376,6 +392,8 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
73903 {
73904 int copied = 0;
73905
73906+ pax_track_stack();
73907+
73908 while (len > 0) {
73909 char buf[128];
73910 int this_len, retval;
73911@@ -517,6 +535,8 @@ int ptrace_request(struct task_struct *child, long request,
73912 int ret = -EIO;
73913 siginfo_t siginfo;
73914
73915+ pax_track_stack();
73916+
73917 switch (request) {
73918 case PTRACE_PEEKTEXT:
73919 case PTRACE_PEEKDATA:
73920@@ -532,18 +552,18 @@ int ptrace_request(struct task_struct *child, long request,
73921 ret = ptrace_setoptions(child, data);
73922 break;
73923 case PTRACE_GETEVENTMSG:
73924- ret = put_user(child->ptrace_message, (unsigned long __user *) data);
73925+ ret = put_user(child->ptrace_message, (__force unsigned long __user *) data);
73926 break;
73927
73928 case PTRACE_GETSIGINFO:
73929 ret = ptrace_getsiginfo(child, &siginfo);
73930 if (!ret)
73931- ret = copy_siginfo_to_user((siginfo_t __user *) data,
73932+ ret = copy_siginfo_to_user((__force siginfo_t __user *) data,
73933 &siginfo);
73934 break;
73935
73936 case PTRACE_SETSIGINFO:
73937- if (copy_from_user(&siginfo, (siginfo_t __user *) data,
73938+ if (copy_from_user(&siginfo, (__force siginfo_t __user *) data,
73939 sizeof siginfo))
73940 ret = -EFAULT;
73941 else
73942@@ -621,14 +641,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
73943 goto out;
73944 }
73945
73946+ if (gr_handle_ptrace(child, request)) {
73947+ ret = -EPERM;
73948+ goto out_put_task_struct;
73949+ }
73950+
73951 if (request == PTRACE_ATTACH) {
73952 ret = ptrace_attach(child);
73953 /*
73954 * Some architectures need to do book-keeping after
73955 * a ptrace attach.
73956 */
73957- if (!ret)
73958+ if (!ret) {
73959 arch_ptrace_attach(child);
73960+ gr_audit_ptrace(child);
73961+ }
73962 goto out_put_task_struct;
73963 }
73964
73965@@ -653,7 +680,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
73966 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
73967 if (copied != sizeof(tmp))
73968 return -EIO;
73969- return put_user(tmp, (unsigned long __user *)data);
73970+ return put_user(tmp, (__force unsigned long __user *)data);
73971 }
73972
73973 int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
73974@@ -675,6 +702,8 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
73975 siginfo_t siginfo;
73976 int ret;
73977
73978+ pax_track_stack();
73979+
73980 switch (request) {
73981 case PTRACE_PEEKTEXT:
73982 case PTRACE_PEEKDATA:
73983@@ -740,14 +769,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
73984 goto out;
73985 }
73986
73987+ if (gr_handle_ptrace(child, request)) {
73988+ ret = -EPERM;
73989+ goto out_put_task_struct;
73990+ }
73991+
73992 if (request == PTRACE_ATTACH) {
73993 ret = ptrace_attach(child);
73994 /*
73995 * Some architectures need to do book-keeping after
73996 * a ptrace attach.
73997 */
73998- if (!ret)
73999+ if (!ret) {
74000 arch_ptrace_attach(child);
74001+ gr_audit_ptrace(child);
74002+ }
74003 goto out_put_task_struct;
74004 }
74005
74006diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
74007index 697c0a0..2402696 100644
74008--- a/kernel/rcutorture.c
74009+++ b/kernel/rcutorture.c
74010@@ -118,12 +118,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
74011 { 0 };
74012 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
74013 { 0 };
74014-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
74015-static atomic_t n_rcu_torture_alloc;
74016-static atomic_t n_rcu_torture_alloc_fail;
74017-static atomic_t n_rcu_torture_free;
74018-static atomic_t n_rcu_torture_mberror;
74019-static atomic_t n_rcu_torture_error;
74020+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
74021+static atomic_unchecked_t n_rcu_torture_alloc;
74022+static atomic_unchecked_t n_rcu_torture_alloc_fail;
74023+static atomic_unchecked_t n_rcu_torture_free;
74024+static atomic_unchecked_t n_rcu_torture_mberror;
74025+static atomic_unchecked_t n_rcu_torture_error;
74026 static long n_rcu_torture_timers;
74027 static struct list_head rcu_torture_removed;
74028 static cpumask_var_t shuffle_tmp_mask;
74029@@ -187,11 +187,11 @@ rcu_torture_alloc(void)
74030
74031 spin_lock_bh(&rcu_torture_lock);
74032 if (list_empty(&rcu_torture_freelist)) {
74033- atomic_inc(&n_rcu_torture_alloc_fail);
74034+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
74035 spin_unlock_bh(&rcu_torture_lock);
74036 return NULL;
74037 }
74038- atomic_inc(&n_rcu_torture_alloc);
74039+ atomic_inc_unchecked(&n_rcu_torture_alloc);
74040 p = rcu_torture_freelist.next;
74041 list_del_init(p);
74042 spin_unlock_bh(&rcu_torture_lock);
74043@@ -204,7 +204,7 @@ rcu_torture_alloc(void)
74044 static void
74045 rcu_torture_free(struct rcu_torture *p)
74046 {
74047- atomic_inc(&n_rcu_torture_free);
74048+ atomic_inc_unchecked(&n_rcu_torture_free);
74049 spin_lock_bh(&rcu_torture_lock);
74050 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
74051 spin_unlock_bh(&rcu_torture_lock);
74052@@ -319,7 +319,7 @@ rcu_torture_cb(struct rcu_head *p)
74053 i = rp->rtort_pipe_count;
74054 if (i > RCU_TORTURE_PIPE_LEN)
74055 i = RCU_TORTURE_PIPE_LEN;
74056- atomic_inc(&rcu_torture_wcount[i]);
74057+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
74058 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
74059 rp->rtort_mbtest = 0;
74060 rcu_torture_free(rp);
74061@@ -359,7 +359,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
74062 i = rp->rtort_pipe_count;
74063 if (i > RCU_TORTURE_PIPE_LEN)
74064 i = RCU_TORTURE_PIPE_LEN;
74065- atomic_inc(&rcu_torture_wcount[i]);
74066+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
74067 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
74068 rp->rtort_mbtest = 0;
74069 list_del(&rp->rtort_free);
74070@@ -653,7 +653,7 @@ rcu_torture_writer(void *arg)
74071 i = old_rp->rtort_pipe_count;
74072 if (i > RCU_TORTURE_PIPE_LEN)
74073 i = RCU_TORTURE_PIPE_LEN;
74074- atomic_inc(&rcu_torture_wcount[i]);
74075+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
74076 old_rp->rtort_pipe_count++;
74077 cur_ops->deferred_free(old_rp);
74078 }
74079@@ -718,7 +718,7 @@ static void rcu_torture_timer(unsigned long unused)
74080 return;
74081 }
74082 if (p->rtort_mbtest == 0)
74083- atomic_inc(&n_rcu_torture_mberror);
74084+ atomic_inc_unchecked(&n_rcu_torture_mberror);
74085 spin_lock(&rand_lock);
74086 cur_ops->read_delay(&rand);
74087 n_rcu_torture_timers++;
74088@@ -776,7 +776,7 @@ rcu_torture_reader(void *arg)
74089 continue;
74090 }
74091 if (p->rtort_mbtest == 0)
74092- atomic_inc(&n_rcu_torture_mberror);
74093+ atomic_inc_unchecked(&n_rcu_torture_mberror);
74094 cur_ops->read_delay(&rand);
74095 preempt_disable();
74096 pipe_count = p->rtort_pipe_count;
74097@@ -834,17 +834,17 @@ rcu_torture_printk(char *page)
74098 rcu_torture_current,
74099 rcu_torture_current_version,
74100 list_empty(&rcu_torture_freelist),
74101- atomic_read(&n_rcu_torture_alloc),
74102- atomic_read(&n_rcu_torture_alloc_fail),
74103- atomic_read(&n_rcu_torture_free),
74104- atomic_read(&n_rcu_torture_mberror),
74105+ atomic_read_unchecked(&n_rcu_torture_alloc),
74106+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
74107+ atomic_read_unchecked(&n_rcu_torture_free),
74108+ atomic_read_unchecked(&n_rcu_torture_mberror),
74109 n_rcu_torture_timers);
74110- if (atomic_read(&n_rcu_torture_mberror) != 0)
74111+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0)
74112 cnt += sprintf(&page[cnt], " !!!");
74113 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
74114 if (i > 1) {
74115 cnt += sprintf(&page[cnt], "!!! ");
74116- atomic_inc(&n_rcu_torture_error);
74117+ atomic_inc_unchecked(&n_rcu_torture_error);
74118 WARN_ON_ONCE(1);
74119 }
74120 cnt += sprintf(&page[cnt], "Reader Pipe: ");
74121@@ -858,7 +858,7 @@ rcu_torture_printk(char *page)
74122 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
74123 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
74124 cnt += sprintf(&page[cnt], " %d",
74125- atomic_read(&rcu_torture_wcount[i]));
74126+ atomic_read_unchecked(&rcu_torture_wcount[i]));
74127 }
74128 cnt += sprintf(&page[cnt], "\n");
74129 if (cur_ops->stats)
74130@@ -1084,7 +1084,7 @@ rcu_torture_cleanup(void)
74131
74132 if (cur_ops->cleanup)
74133 cur_ops->cleanup();
74134- if (atomic_read(&n_rcu_torture_error))
74135+ if (atomic_read_unchecked(&n_rcu_torture_error))
74136 rcu_torture_print_module_parms("End of test: FAILURE");
74137 else
74138 rcu_torture_print_module_parms("End of test: SUCCESS");
74139@@ -1138,13 +1138,13 @@ rcu_torture_init(void)
74140
74141 rcu_torture_current = NULL;
74142 rcu_torture_current_version = 0;
74143- atomic_set(&n_rcu_torture_alloc, 0);
74144- atomic_set(&n_rcu_torture_alloc_fail, 0);
74145- atomic_set(&n_rcu_torture_free, 0);
74146- atomic_set(&n_rcu_torture_mberror, 0);
74147- atomic_set(&n_rcu_torture_error, 0);
74148+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
74149+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
74150+ atomic_set_unchecked(&n_rcu_torture_free, 0);
74151+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
74152+ atomic_set_unchecked(&n_rcu_torture_error, 0);
74153 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
74154- atomic_set(&rcu_torture_wcount[i], 0);
74155+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
74156 for_each_possible_cpu(cpu) {
74157 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
74158 per_cpu(rcu_torture_count, cpu)[i] = 0;
74159diff --git a/kernel/rcutree.c b/kernel/rcutree.c
74160index 683c4f3..97f54c6 100644
74161--- a/kernel/rcutree.c
74162+++ b/kernel/rcutree.c
74163@@ -1303,7 +1303,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
74164 /*
74165 * Do softirq processing for the current CPU.
74166 */
74167-static void rcu_process_callbacks(struct softirq_action *unused)
74168+static void rcu_process_callbacks(void)
74169 {
74170 /*
74171 * Memory references from any prior RCU read-side critical sections
74172diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
74173index c03edf7..ac1b341 100644
74174--- a/kernel/rcutree_plugin.h
74175+++ b/kernel/rcutree_plugin.h
74176@@ -145,7 +145,7 @@ static void rcu_preempt_note_context_switch(int cpu)
74177 */
74178 void __rcu_read_lock(void)
74179 {
74180- ACCESS_ONCE(current->rcu_read_lock_nesting)++;
74181+ ACCESS_ONCE_RW(current->rcu_read_lock_nesting)++;
74182 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
74183 }
74184 EXPORT_SYMBOL_GPL(__rcu_read_lock);
74185@@ -251,7 +251,7 @@ void __rcu_read_unlock(void)
74186 struct task_struct *t = current;
74187
74188 barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
74189- if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
74190+ if (--ACCESS_ONCE_RW(t->rcu_read_lock_nesting) == 0 &&
74191 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
74192 rcu_read_unlock_special(t);
74193 }
74194diff --git a/kernel/relay.c b/kernel/relay.c
74195index 760c262..a9fd241 100644
74196--- a/kernel/relay.c
74197+++ b/kernel/relay.c
74198@@ -1222,7 +1222,7 @@ static int subbuf_splice_actor(struct file *in,
74199 unsigned int flags,
74200 int *nonpad_ret)
74201 {
74202- unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret;
74203+ unsigned int pidx, poff, total_len, subbuf_pages, nr_pages;
74204 struct rchan_buf *rbuf = in->private_data;
74205 unsigned int subbuf_size = rbuf->chan->subbuf_size;
74206 uint64_t pos = (uint64_t) *ppos;
74207@@ -1241,6 +1241,9 @@ static int subbuf_splice_actor(struct file *in,
74208 .ops = &relay_pipe_buf_ops,
74209 .spd_release = relay_page_release,
74210 };
74211+ ssize_t ret;
74212+
74213+ pax_track_stack();
74214
74215 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
74216 return 0;
74217diff --git a/kernel/resource.c b/kernel/resource.c
74218index fb11a58..4e61ae1 100644
74219--- a/kernel/resource.c
74220+++ b/kernel/resource.c
74221@@ -132,8 +132,18 @@ static const struct file_operations proc_iomem_operations = {
74222
74223 static int __init ioresources_init(void)
74224 {
74225+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74226+#ifdef CONFIG_GRKERNSEC_PROC_USER
74227+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
74228+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
74229+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74230+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
74231+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
74232+#endif
74233+#else
74234 proc_create("ioports", 0, NULL, &proc_ioports_operations);
74235 proc_create("iomem", 0, NULL, &proc_iomem_operations);
74236+#endif
74237 return 0;
74238 }
74239 __initcall(ioresources_init);
74240diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
74241index a56f629..1fc4989 100644
74242--- a/kernel/rtmutex-tester.c
74243+++ b/kernel/rtmutex-tester.c
74244@@ -21,7 +21,7 @@
74245 #define MAX_RT_TEST_MUTEXES 8
74246
74247 static spinlock_t rttest_lock;
74248-static atomic_t rttest_event;
74249+static atomic_unchecked_t rttest_event;
74250
74251 struct test_thread_data {
74252 int opcode;
74253@@ -64,7 +64,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
74254
74255 case RTTEST_LOCKCONT:
74256 td->mutexes[td->opdata] = 1;
74257- td->event = atomic_add_return(1, &rttest_event);
74258+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74259 return 0;
74260
74261 case RTTEST_RESET:
74262@@ -82,7 +82,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
74263 return 0;
74264
74265 case RTTEST_RESETEVENT:
74266- atomic_set(&rttest_event, 0);
74267+ atomic_set_unchecked(&rttest_event, 0);
74268 return 0;
74269
74270 default:
74271@@ -99,9 +99,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
74272 return ret;
74273
74274 td->mutexes[id] = 1;
74275- td->event = atomic_add_return(1, &rttest_event);
74276+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74277 rt_mutex_lock(&mutexes[id]);
74278- td->event = atomic_add_return(1, &rttest_event);
74279+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74280 td->mutexes[id] = 4;
74281 return 0;
74282
74283@@ -112,9 +112,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
74284 return ret;
74285
74286 td->mutexes[id] = 1;
74287- td->event = atomic_add_return(1, &rttest_event);
74288+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74289 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
74290- td->event = atomic_add_return(1, &rttest_event);
74291+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74292 td->mutexes[id] = ret ? 0 : 4;
74293 return ret ? -EINTR : 0;
74294
74295@@ -123,9 +123,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
74296 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
74297 return ret;
74298
74299- td->event = atomic_add_return(1, &rttest_event);
74300+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74301 rt_mutex_unlock(&mutexes[id]);
74302- td->event = atomic_add_return(1, &rttest_event);
74303+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74304 td->mutexes[id] = 0;
74305 return 0;
74306
74307@@ -187,7 +187,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
74308 break;
74309
74310 td->mutexes[dat] = 2;
74311- td->event = atomic_add_return(1, &rttest_event);
74312+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74313 break;
74314
74315 case RTTEST_LOCKBKL:
74316@@ -208,7 +208,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
74317 return;
74318
74319 td->mutexes[dat] = 3;
74320- td->event = atomic_add_return(1, &rttest_event);
74321+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74322 break;
74323
74324 case RTTEST_LOCKNOWAIT:
74325@@ -220,7 +220,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
74326 return;
74327
74328 td->mutexes[dat] = 1;
74329- td->event = atomic_add_return(1, &rttest_event);
74330+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74331 return;
74332
74333 case RTTEST_LOCKBKL:
74334diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
74335index 29bd4ba..8c5de90 100644
74336--- a/kernel/rtmutex.c
74337+++ b/kernel/rtmutex.c
74338@@ -511,7 +511,7 @@ static void wakeup_next_waiter(struct rt_mutex *lock)
74339 */
74340 spin_lock_irqsave(&pendowner->pi_lock, flags);
74341
74342- WARN_ON(!pendowner->pi_blocked_on);
74343+ BUG_ON(!pendowner->pi_blocked_on);
74344 WARN_ON(pendowner->pi_blocked_on != waiter);
74345 WARN_ON(pendowner->pi_blocked_on->lock != lock);
74346
74347diff --git a/kernel/sched.c b/kernel/sched.c
74348index 0591df8..db35e3d 100644
74349--- a/kernel/sched.c
74350+++ b/kernel/sched.c
74351@@ -5043,7 +5043,7 @@ out:
74352 * In CONFIG_NO_HZ case, the idle load balance owner will do the
74353 * rebalancing for all the cpus for whom scheduler ticks are stopped.
74354 */
74355-static void run_rebalance_domains(struct softirq_action *h)
74356+static void run_rebalance_domains(void)
74357 {
74358 int this_cpu = smp_processor_id();
74359 struct rq *this_rq = cpu_rq(this_cpu);
74360@@ -5700,6 +5700,8 @@ asmlinkage void __sched schedule(void)
74361 struct rq *rq;
74362 int cpu;
74363
74364+ pax_track_stack();
74365+
74366 need_resched:
74367 preempt_disable();
74368 cpu = smp_processor_id();
74369@@ -5770,7 +5772,7 @@ EXPORT_SYMBOL(schedule);
74370 * Look out! "owner" is an entirely speculative pointer
74371 * access and not reliable.
74372 */
74373-int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
74374+int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
74375 {
74376 unsigned int cpu;
74377 struct rq *rq;
74378@@ -5784,10 +5786,10 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
74379 * DEBUG_PAGEALLOC could have unmapped it if
74380 * the mutex owner just released it and exited.
74381 */
74382- if (probe_kernel_address(&owner->cpu, cpu))
74383+ if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
74384 return 0;
74385 #else
74386- cpu = owner->cpu;
74387+ cpu = task_thread_info(owner)->cpu;
74388 #endif
74389
74390 /*
74391@@ -5816,7 +5818,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
74392 /*
74393 * Is that owner really running on that cpu?
74394 */
74395- if (task_thread_info(rq->curr) != owner || need_resched())
74396+ if (rq->curr != owner || need_resched())
74397 return 0;
74398
74399 cpu_relax();
74400@@ -6359,6 +6361,8 @@ int can_nice(const struct task_struct *p, const int nice)
74401 /* convert nice value [19,-20] to rlimit style value [1,40] */
74402 int nice_rlim = 20 - nice;
74403
74404+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
74405+
74406 return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur ||
74407 capable(CAP_SYS_NICE));
74408 }
74409@@ -6392,7 +6396,8 @@ SYSCALL_DEFINE1(nice, int, increment)
74410 if (nice > 19)
74411 nice = 19;
74412
74413- if (increment < 0 && !can_nice(current, nice))
74414+ if (increment < 0 && (!can_nice(current, nice) ||
74415+ gr_handle_chroot_nice()))
74416 return -EPERM;
74417
74418 retval = security_task_setnice(current, nice);
74419@@ -8774,7 +8779,7 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd)
74420 long power;
74421 int weight;
74422
74423- WARN_ON(!sd || !sd->groups);
74424+ BUG_ON(!sd || !sd->groups);
74425
74426 if (cpu != group_first_cpu(sd->groups))
74427 return;
74428diff --git a/kernel/signal.c b/kernel/signal.c
74429index 2494827..cda80a0 100644
74430--- a/kernel/signal.c
74431+++ b/kernel/signal.c
74432@@ -41,12 +41,12 @@
74433
74434 static struct kmem_cache *sigqueue_cachep;
74435
74436-static void __user *sig_handler(struct task_struct *t, int sig)
74437+static __sighandler_t sig_handler(struct task_struct *t, int sig)
74438 {
74439 return t->sighand->action[sig - 1].sa.sa_handler;
74440 }
74441
74442-static int sig_handler_ignored(void __user *handler, int sig)
74443+static int sig_handler_ignored(__sighandler_t handler, int sig)
74444 {
74445 /* Is it explicitly or implicitly ignored? */
74446 return handler == SIG_IGN ||
74447@@ -56,7 +56,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
74448 static int sig_task_ignored(struct task_struct *t, int sig,
74449 int from_ancestor_ns)
74450 {
74451- void __user *handler;
74452+ __sighandler_t handler;
74453
74454 handler = sig_handler(t, sig);
74455
74456@@ -207,6 +207,9 @@ static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags,
74457 */
74458 user = get_uid(__task_cred(t)->user);
74459 atomic_inc(&user->sigpending);
74460+
74461+ if (!override_rlimit)
74462+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
74463 if (override_rlimit ||
74464 atomic_read(&user->sigpending) <=
74465 t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
74466@@ -327,7 +330,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
74467
74468 int unhandled_signal(struct task_struct *tsk, int sig)
74469 {
74470- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
74471+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
74472 if (is_global_init(tsk))
74473 return 1;
74474 if (handler != SIG_IGN && handler != SIG_DFL)
74475@@ -627,6 +630,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
74476 }
74477 }
74478
74479+ /* allow glibc communication via tgkill to other threads in our
74480+ thread group */
74481+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
74482+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
74483+ && gr_handle_signal(t, sig))
74484+ return -EPERM;
74485+
74486 return security_task_kill(t, info, sig, 0);
74487 }
74488
74489@@ -968,7 +978,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
74490 return send_signal(sig, info, p, 1);
74491 }
74492
74493-static int
74494+int
74495 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
74496 {
74497 return send_signal(sig, info, t, 0);
74498@@ -1005,6 +1015,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
74499 unsigned long int flags;
74500 int ret, blocked, ignored;
74501 struct k_sigaction *action;
74502+ int is_unhandled = 0;
74503
74504 spin_lock_irqsave(&t->sighand->siglock, flags);
74505 action = &t->sighand->action[sig-1];
74506@@ -1019,9 +1030,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
74507 }
74508 if (action->sa.sa_handler == SIG_DFL)
74509 t->signal->flags &= ~SIGNAL_UNKILLABLE;
74510+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
74511+ is_unhandled = 1;
74512 ret = specific_send_sig_info(sig, info, t);
74513 spin_unlock_irqrestore(&t->sighand->siglock, flags);
74514
74515+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
74516+ normal operation */
74517+ if (is_unhandled) {
74518+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
74519+ gr_handle_crash(t, sig);
74520+ }
74521+
74522 return ret;
74523 }
74524
74525@@ -1081,8 +1101,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
74526 {
74527 int ret = check_kill_permission(sig, info, p);
74528
74529- if (!ret && sig)
74530+ if (!ret && sig) {
74531 ret = do_send_sig_info(sig, info, p, true);
74532+ if (!ret)
74533+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
74534+ }
74535
74536 return ret;
74537 }
74538@@ -1644,6 +1667,8 @@ void ptrace_notify(int exit_code)
74539 {
74540 siginfo_t info;
74541
74542+ pax_track_stack();
74543+
74544 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
74545
74546 memset(&info, 0, sizeof info);
74547@@ -2275,7 +2300,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
74548 int error = -ESRCH;
74549
74550 rcu_read_lock();
74551- p = find_task_by_vpid(pid);
74552+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74553+ /* allow glibc communication via tgkill to other threads in our
74554+ thread group */
74555+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
74556+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
74557+ p = find_task_by_vpid_unrestricted(pid);
74558+ else
74559+#endif
74560+ p = find_task_by_vpid(pid);
74561 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
74562 error = check_kill_permission(sig, info, p);
74563 /*
74564diff --git a/kernel/smp.c b/kernel/smp.c
74565index aa9cff3..631a0de 100644
74566--- a/kernel/smp.c
74567+++ b/kernel/smp.c
74568@@ -522,22 +522,22 @@ int smp_call_function(void (*func)(void *), void *info, int wait)
74569 }
74570 EXPORT_SYMBOL(smp_call_function);
74571
74572-void ipi_call_lock(void)
74573+void ipi_call_lock(void) __acquires(call_function.lock)
74574 {
74575 spin_lock(&call_function.lock);
74576 }
74577
74578-void ipi_call_unlock(void)
74579+void ipi_call_unlock(void) __releases(call_function.lock)
74580 {
74581 spin_unlock(&call_function.lock);
74582 }
74583
74584-void ipi_call_lock_irq(void)
74585+void ipi_call_lock_irq(void) __acquires(call_function.lock)
74586 {
74587 spin_lock_irq(&call_function.lock);
74588 }
74589
74590-void ipi_call_unlock_irq(void)
74591+void ipi_call_unlock_irq(void) __releases(call_function.lock)
74592 {
74593 spin_unlock_irq(&call_function.lock);
74594 }
74595diff --git a/kernel/softirq.c b/kernel/softirq.c
74596index 04a0252..580c512 100644
74597--- a/kernel/softirq.c
74598+++ b/kernel/softirq.c
74599@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
74600
74601 static DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
74602
74603-char *softirq_to_name[NR_SOFTIRQS] = {
74604+const char * const softirq_to_name[NR_SOFTIRQS] = {
74605 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
74606 "TASKLET", "SCHED", "HRTIMER", "RCU"
74607 };
74608@@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
74609
74610 asmlinkage void __do_softirq(void)
74611 {
74612- struct softirq_action *h;
74613+ const struct softirq_action *h;
74614 __u32 pending;
74615 int max_restart = MAX_SOFTIRQ_RESTART;
74616 int cpu;
74617@@ -233,7 +233,7 @@ restart:
74618 kstat_incr_softirqs_this_cpu(h - softirq_vec);
74619
74620 trace_softirq_entry(h, softirq_vec);
74621- h->action(h);
74622+ h->action();
74623 trace_softirq_exit(h, softirq_vec);
74624 if (unlikely(prev_count != preempt_count())) {
74625 printk(KERN_ERR "huh, entered softirq %td %s %p"
74626@@ -363,9 +363,11 @@ void raise_softirq(unsigned int nr)
74627 local_irq_restore(flags);
74628 }
74629
74630-void open_softirq(int nr, void (*action)(struct softirq_action *))
74631+void open_softirq(int nr, void (*action)(void))
74632 {
74633- softirq_vec[nr].action = action;
74634+ pax_open_kernel();
74635+ *(void **)&softirq_vec[nr].action = action;
74636+ pax_close_kernel();
74637 }
74638
74639 /*
74640@@ -419,7 +421,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
74641
74642 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
74643
74644-static void tasklet_action(struct softirq_action *a)
74645+static void tasklet_action(void)
74646 {
74647 struct tasklet_struct *list;
74648
74649@@ -454,7 +456,7 @@ static void tasklet_action(struct softirq_action *a)
74650 }
74651 }
74652
74653-static void tasklet_hi_action(struct softirq_action *a)
74654+static void tasklet_hi_action(void)
74655 {
74656 struct tasklet_struct *list;
74657
74658diff --git a/kernel/sys.c b/kernel/sys.c
74659index e9512b1..3c265de 100644
74660--- a/kernel/sys.c
74661+++ b/kernel/sys.c
74662@@ -133,6 +133,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
74663 error = -EACCES;
74664 goto out;
74665 }
74666+
74667+ if (gr_handle_chroot_setpriority(p, niceval)) {
74668+ error = -EACCES;
74669+ goto out;
74670+ }
74671+
74672 no_nice = security_task_setnice(p, niceval);
74673 if (no_nice) {
74674 error = no_nice;
74675@@ -190,10 +196,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
74676 !(user = find_user(who)))
74677 goto out_unlock; /* No processes for this user */
74678
74679- do_each_thread(g, p)
74680+ do_each_thread(g, p) {
74681 if (__task_cred(p)->uid == who)
74682 error = set_one_prio(p, niceval, error);
74683- while_each_thread(g, p);
74684+ } while_each_thread(g, p);
74685 if (who != cred->uid)
74686 free_uid(user); /* For find_user() */
74687 break;
74688@@ -253,13 +259,13 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
74689 !(user = find_user(who)))
74690 goto out_unlock; /* No processes for this user */
74691
74692- do_each_thread(g, p)
74693+ do_each_thread(g, p) {
74694 if (__task_cred(p)->uid == who) {
74695 niceval = 20 - task_nice(p);
74696 if (niceval > retval)
74697 retval = niceval;
74698 }
74699- while_each_thread(g, p);
74700+ } while_each_thread(g, p);
74701 if (who != cred->uid)
74702 free_uid(user); /* for find_user() */
74703 break;
74704@@ -509,6 +515,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
74705 goto error;
74706 }
74707
74708+ if (gr_check_group_change(new->gid, new->egid, -1))
74709+ goto error;
74710+
74711 if (rgid != (gid_t) -1 ||
74712 (egid != (gid_t) -1 && egid != old->gid))
74713 new->sgid = new->egid;
74714@@ -542,6 +551,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
74715 goto error;
74716
74717 retval = -EPERM;
74718+
74719+ if (gr_check_group_change(gid, gid, gid))
74720+ goto error;
74721+
74722 if (capable(CAP_SETGID))
74723 new->gid = new->egid = new->sgid = new->fsgid = gid;
74724 else if (gid == old->gid || gid == old->sgid)
74725@@ -567,12 +580,19 @@ static int set_user(struct cred *new)
74726 if (!new_user)
74727 return -EAGAIN;
74728
74729+ /*
74730+ * We don't fail in case of NPROC limit excess here because too many
74731+ * poorly written programs don't check set*uid() return code, assuming
74732+ * it never fails if called by root. We may still enforce NPROC limit
74733+ * for programs doing set*uid()+execve() by harmlessly deferring the
74734+ * failure to the execve() stage.
74735+ */
74736 if (atomic_read(&new_user->processes) >=
74737 current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
74738- new_user != INIT_USER) {
74739- free_uid(new_user);
74740- return -EAGAIN;
74741- }
74742+ new_user != INIT_USER)
74743+ current->flags |= PF_NPROC_EXCEEDED;
74744+ else
74745+ current->flags &= ~PF_NPROC_EXCEEDED;
74746
74747 free_uid(new->user);
74748 new->user = new_user;
74749@@ -627,6 +647,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
74750 goto error;
74751 }
74752
74753+ if (gr_check_user_change(new->uid, new->euid, -1))
74754+ goto error;
74755+
74756 if (new->uid != old->uid) {
74757 retval = set_user(new);
74758 if (retval < 0)
74759@@ -675,6 +698,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
74760 goto error;
74761
74762 retval = -EPERM;
74763+
74764+ if (gr_check_crash_uid(uid))
74765+ goto error;
74766+ if (gr_check_user_change(uid, uid, uid))
74767+ goto error;
74768+
74769 if (capable(CAP_SETUID)) {
74770 new->suid = new->uid = uid;
74771 if (uid != old->uid) {
74772@@ -732,6 +761,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
74773 goto error;
74774 }
74775
74776+ if (gr_check_user_change(ruid, euid, -1))
74777+ goto error;
74778+
74779 if (ruid != (uid_t) -1) {
74780 new->uid = ruid;
74781 if (ruid != old->uid) {
74782@@ -800,6 +832,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
74783 goto error;
74784 }
74785
74786+ if (gr_check_group_change(rgid, egid, -1))
74787+ goto error;
74788+
74789 if (rgid != (gid_t) -1)
74790 new->gid = rgid;
74791 if (egid != (gid_t) -1)
74792@@ -849,6 +884,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
74793 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS) < 0)
74794 goto error;
74795
74796+ if (gr_check_user_change(-1, -1, uid))
74797+ goto error;
74798+
74799 if (uid == old->uid || uid == old->euid ||
74800 uid == old->suid || uid == old->fsuid ||
74801 capable(CAP_SETUID)) {
74802@@ -889,6 +927,9 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
74803 if (gid == old->gid || gid == old->egid ||
74804 gid == old->sgid || gid == old->fsgid ||
74805 capable(CAP_SETGID)) {
74806+ if (gr_check_group_change(-1, -1, gid))
74807+ goto error;
74808+
74809 if (gid != old_fsgid) {
74810 new->fsgid = gid;
74811 goto change_okay;
74812@@ -1454,7 +1495,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
74813 error = get_dumpable(me->mm);
74814 break;
74815 case PR_SET_DUMPABLE:
74816- if (arg2 < 0 || arg2 > 1) {
74817+ if (arg2 > 1) {
74818 error = -EINVAL;
74819 break;
74820 }
74821diff --git a/kernel/sysctl.c b/kernel/sysctl.c
74822index b8bd058..ab6a76be 100644
74823--- a/kernel/sysctl.c
74824+++ b/kernel/sysctl.c
74825@@ -63,6 +63,13 @@
74826 static int deprecated_sysctl_warning(struct __sysctl_args *args);
74827
74828 #if defined(CONFIG_SYSCTL)
74829+#include <linux/grsecurity.h>
74830+#include <linux/grinternal.h>
74831+
74832+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
74833+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
74834+ const int op);
74835+extern int gr_handle_chroot_sysctl(const int op);
74836
74837 /* External variables not in a header file. */
74838 extern int C_A_D;
74839@@ -168,6 +175,7 @@ static int proc_do_cad_pid(struct ctl_table *table, int write,
74840 static int proc_taint(struct ctl_table *table, int write,
74841 void __user *buffer, size_t *lenp, loff_t *ppos);
74842 #endif
74843+extern ctl_table grsecurity_table[];
74844
74845 static struct ctl_table root_table[];
74846 static struct ctl_table_root sysctl_table_root;
74847@@ -200,6 +208,21 @@ extern struct ctl_table epoll_table[];
74848 int sysctl_legacy_va_layout;
74849 #endif
74850
74851+#ifdef CONFIG_PAX_SOFTMODE
74852+static ctl_table pax_table[] = {
74853+ {
74854+ .ctl_name = CTL_UNNUMBERED,
74855+ .procname = "softmode",
74856+ .data = &pax_softmode,
74857+ .maxlen = sizeof(unsigned int),
74858+ .mode = 0600,
74859+ .proc_handler = &proc_dointvec,
74860+ },
74861+
74862+ { .ctl_name = 0 }
74863+};
74864+#endif
74865+
74866 extern int prove_locking;
74867 extern int lock_stat;
74868
74869@@ -251,6 +274,24 @@ static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
74870 #endif
74871
74872 static struct ctl_table kern_table[] = {
74873+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
74874+ {
74875+ .ctl_name = CTL_UNNUMBERED,
74876+ .procname = "grsecurity",
74877+ .mode = 0500,
74878+ .child = grsecurity_table,
74879+ },
74880+#endif
74881+
74882+#ifdef CONFIG_PAX_SOFTMODE
74883+ {
74884+ .ctl_name = CTL_UNNUMBERED,
74885+ .procname = "pax",
74886+ .mode = 0500,
74887+ .child = pax_table,
74888+ },
74889+#endif
74890+
74891 {
74892 .ctl_name = CTL_UNNUMBERED,
74893 .procname = "sched_child_runs_first",
74894@@ -567,8 +608,8 @@ static struct ctl_table kern_table[] = {
74895 .data = &modprobe_path,
74896 .maxlen = KMOD_PATH_LEN,
74897 .mode = 0644,
74898- .proc_handler = &proc_dostring,
74899- .strategy = &sysctl_string,
74900+ .proc_handler = &proc_dostring_modpriv,
74901+ .strategy = &sysctl_string_modpriv,
74902 },
74903 {
74904 .ctl_name = CTL_UNNUMBERED,
74905@@ -1247,6 +1288,13 @@ static struct ctl_table vm_table[] = {
74906 .mode = 0644,
74907 .proc_handler = &proc_dointvec
74908 },
74909+ {
74910+ .procname = "heap_stack_gap",
74911+ .data = &sysctl_heap_stack_gap,
74912+ .maxlen = sizeof(sysctl_heap_stack_gap),
74913+ .mode = 0644,
74914+ .proc_handler = proc_doulongvec_minmax,
74915+ },
74916 #else
74917 {
74918 .ctl_name = CTL_UNNUMBERED,
74919@@ -1803,6 +1851,8 @@ static int do_sysctl_strategy(struct ctl_table_root *root,
74920 return 0;
74921 }
74922
74923+static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
74924+
74925 static int parse_table(int __user *name, int nlen,
74926 void __user *oldval, size_t __user *oldlenp,
74927 void __user *newval, size_t newlen,
74928@@ -1821,7 +1871,7 @@ repeat:
74929 if (n == table->ctl_name) {
74930 int error;
74931 if (table->child) {
74932- if (sysctl_perm(root, table, MAY_EXEC))
74933+ if (sysctl_perm_nochk(root, table, MAY_EXEC))
74934 return -EPERM;
74935 name++;
74936 nlen--;
74937@@ -1906,6 +1956,33 @@ int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
74938 int error;
74939 int mode;
74940
74941+ if (table->parent != NULL && table->parent->procname != NULL &&
74942+ table->procname != NULL &&
74943+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
74944+ return -EACCES;
74945+ if (gr_handle_chroot_sysctl(op))
74946+ return -EACCES;
74947+ error = gr_handle_sysctl(table, op);
74948+ if (error)
74949+ return error;
74950+
74951+ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
74952+ if (error)
74953+ return error;
74954+
74955+ if (root->permissions)
74956+ mode = root->permissions(root, current->nsproxy, table);
74957+ else
74958+ mode = table->mode;
74959+
74960+ return test_perm(mode, op);
74961+}
74962+
74963+int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
74964+{
74965+ int error;
74966+ int mode;
74967+
74968 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
74969 if (error)
74970 return error;
74971@@ -2335,6 +2412,16 @@ int proc_dostring(struct ctl_table *table, int write,
74972 buffer, lenp, ppos);
74973 }
74974
74975+int proc_dostring_modpriv(struct ctl_table *table, int write,
74976+ void __user *buffer, size_t *lenp, loff_t *ppos)
74977+{
74978+ if (write && !capable(CAP_SYS_MODULE))
74979+ return -EPERM;
74980+
74981+ return _proc_do_string(table->data, table->maxlen, write,
74982+ buffer, lenp, ppos);
74983+}
74984+
74985
74986 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
74987 int *valp,
74988@@ -2609,7 +2696,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
74989 vleft = table->maxlen / sizeof(unsigned long);
74990 left = *lenp;
74991
74992- for (; left && vleft--; i++, min++, max++, first=0) {
74993+ for (; left && vleft--; i++, first=0) {
74994 if (write) {
74995 while (left) {
74996 char c;
74997@@ -2910,6 +2997,12 @@ int proc_dostring(struct ctl_table *table, int write,
74998 return -ENOSYS;
74999 }
75000
75001+int proc_dostring_modpriv(struct ctl_table *table, int write,
75002+ void __user *buffer, size_t *lenp, loff_t *ppos)
75003+{
75004+ return -ENOSYS;
75005+}
75006+
75007 int proc_dointvec(struct ctl_table *table, int write,
75008 void __user *buffer, size_t *lenp, loff_t *ppos)
75009 {
75010@@ -3038,6 +3131,16 @@ int sysctl_string(struct ctl_table *table,
75011 return 1;
75012 }
75013
75014+int sysctl_string_modpriv(struct ctl_table *table,
75015+ void __user *oldval, size_t __user *oldlenp,
75016+ void __user *newval, size_t newlen)
75017+{
75018+ if (newval && newlen && !capable(CAP_SYS_MODULE))
75019+ return -EPERM;
75020+
75021+ return sysctl_string(table, oldval, oldlenp, newval, newlen);
75022+}
75023+
75024 /*
75025 * This function makes sure that all of the integers in the vector
75026 * are between the minimum and maximum values given in the arrays
75027@@ -3182,6 +3285,13 @@ int sysctl_string(struct ctl_table *table,
75028 return -ENOSYS;
75029 }
75030
75031+int sysctl_string_modpriv(struct ctl_table *table,
75032+ void __user *oldval, size_t __user *oldlenp,
75033+ void __user *newval, size_t newlen)
75034+{
75035+ return -ENOSYS;
75036+}
75037+
75038 int sysctl_intvec(struct ctl_table *table,
75039 void __user *oldval, size_t __user *oldlenp,
75040 void __user *newval, size_t newlen)
75041@@ -3246,6 +3356,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
75042 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
75043 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
75044 EXPORT_SYMBOL(proc_dostring);
75045+EXPORT_SYMBOL(proc_dostring_modpriv);
75046 EXPORT_SYMBOL(proc_doulongvec_minmax);
75047 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
75048 EXPORT_SYMBOL(register_sysctl_table);
75049@@ -3254,5 +3365,6 @@ EXPORT_SYMBOL(sysctl_intvec);
75050 EXPORT_SYMBOL(sysctl_jiffies);
75051 EXPORT_SYMBOL(sysctl_ms_jiffies);
75052 EXPORT_SYMBOL(sysctl_string);
75053+EXPORT_SYMBOL(sysctl_string_modpriv);
75054 EXPORT_SYMBOL(sysctl_data);
75055 EXPORT_SYMBOL(unregister_sysctl_table);
75056diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
75057index 469193c..ea3ecb2 100644
75058--- a/kernel/sysctl_check.c
75059+++ b/kernel/sysctl_check.c
75060@@ -1489,10 +1489,12 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
75061 } else {
75062 if ((table->strategy == sysctl_data) ||
75063 (table->strategy == sysctl_string) ||
75064+ (table->strategy == sysctl_string_modpriv) ||
75065 (table->strategy == sysctl_intvec) ||
75066 (table->strategy == sysctl_jiffies) ||
75067 (table->strategy == sysctl_ms_jiffies) ||
75068 (table->proc_handler == proc_dostring) ||
75069+ (table->proc_handler == proc_dostring_modpriv) ||
75070 (table->proc_handler == proc_dointvec) ||
75071 (table->proc_handler == proc_dointvec_minmax) ||
75072 (table->proc_handler == proc_dointvec_jiffies) ||
75073diff --git a/kernel/taskstats.c b/kernel/taskstats.c
75074index a4ef542..798bcd7 100644
75075--- a/kernel/taskstats.c
75076+++ b/kernel/taskstats.c
75077@@ -26,9 +26,12 @@
75078 #include <linux/cgroup.h>
75079 #include <linux/fs.h>
75080 #include <linux/file.h>
75081+#include <linux/grsecurity.h>
75082 #include <net/genetlink.h>
75083 #include <asm/atomic.h>
75084
75085+extern int gr_is_taskstats_denied(int pid);
75086+
75087 /*
75088 * Maximum length of a cpumask that can be specified in
75089 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
75090@@ -442,6 +445,9 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
75091 size_t size;
75092 cpumask_var_t mask;
75093
75094+ if (gr_is_taskstats_denied(current->pid))
75095+ return -EACCES;
75096+
75097 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
75098 return -ENOMEM;
75099
75100diff --git a/kernel/time.c b/kernel/time.c
75101index 33df60e..ca768bd 100644
75102--- a/kernel/time.c
75103+++ b/kernel/time.c
75104@@ -165,6 +165,11 @@ int do_sys_settimeofday(struct timespec *tv, struct timezone *tz)
75105 return error;
75106
75107 if (tz) {
75108+ /* we log in do_settimeofday called below, so don't log twice
75109+ */
75110+ if (!tv)
75111+ gr_log_timechange();
75112+
75113 /* SMP safe, global irq locking makes it work. */
75114 sys_tz = *tz;
75115 update_vsyscall_tz();
75116@@ -240,7 +245,7 @@ EXPORT_SYMBOL(current_fs_time);
75117 * Avoid unnecessary multiplications/divisions in the
75118 * two most common HZ cases:
75119 */
75120-unsigned int inline jiffies_to_msecs(const unsigned long j)
75121+inline unsigned int jiffies_to_msecs(const unsigned long j)
75122 {
75123 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
75124 return (MSEC_PER_SEC / HZ) * j;
75125@@ -256,7 +261,7 @@ unsigned int inline jiffies_to_msecs(const unsigned long j)
75126 }
75127 EXPORT_SYMBOL(jiffies_to_msecs);
75128
75129-unsigned int inline jiffies_to_usecs(const unsigned long j)
75130+inline unsigned int jiffies_to_usecs(const unsigned long j)
75131 {
75132 #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
75133 return (USEC_PER_SEC / HZ) * j;
75134diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
75135index 57b953f..06f149f 100644
75136--- a/kernel/time/tick-broadcast.c
75137+++ b/kernel/time/tick-broadcast.c
75138@@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
75139 * then clear the broadcast bit.
75140 */
75141 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
75142- int cpu = smp_processor_id();
75143+ cpu = smp_processor_id();
75144
75145 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
75146 tick_broadcast_clear_oneshot(cpu);
75147diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
75148index 4a71cff..ffb5548 100644
75149--- a/kernel/time/timekeeping.c
75150+++ b/kernel/time/timekeeping.c
75151@@ -14,6 +14,7 @@
75152 #include <linux/init.h>
75153 #include <linux/mm.h>
75154 #include <linux/sched.h>
75155+#include <linux/grsecurity.h>
75156 #include <linux/sysdev.h>
75157 #include <linux/clocksource.h>
75158 #include <linux/jiffies.h>
75159@@ -180,7 +181,7 @@ void update_xtime_cache(u64 nsec)
75160 */
75161 struct timespec ts = xtime;
75162 timespec_add_ns(&ts, nsec);
75163- ACCESS_ONCE(xtime_cache) = ts;
75164+ ACCESS_ONCE_RW(xtime_cache) = ts;
75165 }
75166
75167 /* must hold xtime_lock */
75168@@ -337,6 +338,8 @@ int do_settimeofday(struct timespec *tv)
75169 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
75170 return -EINVAL;
75171
75172+ gr_log_timechange();
75173+
75174 write_seqlock_irqsave(&xtime_lock, flags);
75175
75176 timekeeping_forward_now();
75177diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
75178index 54c0dda..e9095d9 100644
75179--- a/kernel/time/timer_list.c
75180+++ b/kernel/time/timer_list.c
75181@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
75182
75183 static void print_name_offset(struct seq_file *m, void *sym)
75184 {
75185+#ifdef CONFIG_GRKERNSEC_HIDESYM
75186+ SEQ_printf(m, "<%p>", NULL);
75187+#else
75188 char symname[KSYM_NAME_LEN];
75189
75190 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
75191 SEQ_printf(m, "<%p>", sym);
75192 else
75193 SEQ_printf(m, "%s", symname);
75194+#endif
75195 }
75196
75197 static void
75198@@ -112,7 +116,11 @@ next_one:
75199 static void
75200 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
75201 {
75202+#ifdef CONFIG_GRKERNSEC_HIDESYM
75203+ SEQ_printf(m, " .base: %p\n", NULL);
75204+#else
75205 SEQ_printf(m, " .base: %p\n", base);
75206+#endif
75207 SEQ_printf(m, " .index: %d\n",
75208 base->index);
75209 SEQ_printf(m, " .resolution: %Lu nsecs\n",
75210@@ -289,7 +297,11 @@ static int __init init_timer_list_procfs(void)
75211 {
75212 struct proc_dir_entry *pe;
75213
75214+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75215+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
75216+#else
75217 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
75218+#endif
75219 if (!pe)
75220 return -ENOMEM;
75221 return 0;
75222diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
75223index ee5681f..634089b 100644
75224--- a/kernel/time/timer_stats.c
75225+++ b/kernel/time/timer_stats.c
75226@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
75227 static unsigned long nr_entries;
75228 static struct entry entries[MAX_ENTRIES];
75229
75230-static atomic_t overflow_count;
75231+static atomic_unchecked_t overflow_count;
75232
75233 /*
75234 * The entries are in a hash-table, for fast lookup:
75235@@ -140,7 +140,7 @@ static void reset_entries(void)
75236 nr_entries = 0;
75237 memset(entries, 0, sizeof(entries));
75238 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
75239- atomic_set(&overflow_count, 0);
75240+ atomic_set_unchecked(&overflow_count, 0);
75241 }
75242
75243 static struct entry *alloc_entry(void)
75244@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
75245 if (likely(entry))
75246 entry->count++;
75247 else
75248- atomic_inc(&overflow_count);
75249+ atomic_inc_unchecked(&overflow_count);
75250
75251 out_unlock:
75252 spin_unlock_irqrestore(lock, flags);
75253@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
75254
75255 static void print_name_offset(struct seq_file *m, unsigned long addr)
75256 {
75257+#ifdef CONFIG_GRKERNSEC_HIDESYM
75258+ seq_printf(m, "<%p>", NULL);
75259+#else
75260 char symname[KSYM_NAME_LEN];
75261
75262 if (lookup_symbol_name(addr, symname) < 0)
75263 seq_printf(m, "<%p>", (void *)addr);
75264 else
75265 seq_printf(m, "%s", symname);
75266+#endif
75267 }
75268
75269 static int tstats_show(struct seq_file *m, void *v)
75270@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
75271
75272 seq_puts(m, "Timer Stats Version: v0.2\n");
75273 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
75274- if (atomic_read(&overflow_count))
75275+ if (atomic_read_unchecked(&overflow_count))
75276 seq_printf(m, "Overflow: %d entries\n",
75277- atomic_read(&overflow_count));
75278+ atomic_read_unchecked(&overflow_count));
75279
75280 for (i = 0; i < nr_entries; i++) {
75281 entry = entries + i;
75282@@ -415,7 +419,11 @@ static int __init init_tstats_procfs(void)
75283 {
75284 struct proc_dir_entry *pe;
75285
75286+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75287+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
75288+#else
75289 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
75290+#endif
75291 if (!pe)
75292 return -ENOMEM;
75293 return 0;
75294diff --git a/kernel/timer.c b/kernel/timer.c
75295index cb3c1f1..8bf5526 100644
75296--- a/kernel/timer.c
75297+++ b/kernel/timer.c
75298@@ -1213,7 +1213,7 @@ void update_process_times(int user_tick)
75299 /*
75300 * This function runs timers and the timer-tq in bottom half context.
75301 */
75302-static void run_timer_softirq(struct softirq_action *h)
75303+static void run_timer_softirq(void)
75304 {
75305 struct tvec_base *base = __get_cpu_var(tvec_bases);
75306
75307diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
75308index d9d6206..f19467e 100644
75309--- a/kernel/trace/blktrace.c
75310+++ b/kernel/trace/blktrace.c
75311@@ -313,7 +313,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
75312 struct blk_trace *bt = filp->private_data;
75313 char buf[16];
75314
75315- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
75316+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
75317
75318 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
75319 }
75320@@ -376,7 +376,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
75321 return 1;
75322
75323 bt = buf->chan->private_data;
75324- atomic_inc(&bt->dropped);
75325+ atomic_inc_unchecked(&bt->dropped);
75326 return 0;
75327 }
75328
75329@@ -477,7 +477,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
75330
75331 bt->dir = dir;
75332 bt->dev = dev;
75333- atomic_set(&bt->dropped, 0);
75334+ atomic_set_unchecked(&bt->dropped, 0);
75335
75336 ret = -EIO;
75337 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
75338diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
75339index 4872937..c794d40 100644
75340--- a/kernel/trace/ftrace.c
75341+++ b/kernel/trace/ftrace.c
75342@@ -1100,13 +1100,18 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
75343
75344 ip = rec->ip;
75345
75346+ ret = ftrace_arch_code_modify_prepare();
75347+ FTRACE_WARN_ON(ret);
75348+ if (ret)
75349+ return 0;
75350+
75351 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
75352+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
75353 if (ret) {
75354 ftrace_bug(ret, ip);
75355 rec->flags |= FTRACE_FL_FAILED;
75356- return 0;
75357 }
75358- return 1;
75359+ return ret ? 0 : 1;
75360 }
75361
75362 /*
75363diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
75364index e749a05..19c6e94 100644
75365--- a/kernel/trace/ring_buffer.c
75366+++ b/kernel/trace/ring_buffer.c
75367@@ -606,7 +606,7 @@ static struct list_head *rb_list_head(struct list_head *list)
75368 * the reader page). But if the next page is a header page,
75369 * its flags will be non zero.
75370 */
75371-static int inline
75372+static inline int
75373 rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
75374 struct buffer_page *page, struct list_head *list)
75375 {
75376diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
75377index a2a2d1f..7f32b09 100644
75378--- a/kernel/trace/trace.c
75379+++ b/kernel/trace/trace.c
75380@@ -3193,6 +3193,8 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
75381 size_t rem;
75382 unsigned int i;
75383
75384+ pax_track_stack();
75385+
75386 /* copy the tracer to avoid using a global lock all around */
75387 mutex_lock(&trace_types_lock);
75388 if (unlikely(old_tracer != current_trace && current_trace)) {
75389@@ -3659,6 +3661,8 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
75390 int entries, size, i;
75391 size_t ret;
75392
75393+ pax_track_stack();
75394+
75395 if (*ppos & (PAGE_SIZE - 1)) {
75396 WARN_ONCE(1, "Ftrace: previous read must page-align\n");
75397 return -EINVAL;
75398@@ -3816,10 +3820,9 @@ static const struct file_operations tracing_dyn_info_fops = {
75399 };
75400 #endif
75401
75402-static struct dentry *d_tracer;
75403-
75404 struct dentry *tracing_init_dentry(void)
75405 {
75406+ static struct dentry *d_tracer;
75407 static int once;
75408
75409 if (d_tracer)
75410@@ -3839,10 +3842,9 @@ struct dentry *tracing_init_dentry(void)
75411 return d_tracer;
75412 }
75413
75414-static struct dentry *d_percpu;
75415-
75416 struct dentry *tracing_dentry_percpu(void)
75417 {
75418+ static struct dentry *d_percpu;
75419 static int once;
75420 struct dentry *d_tracer;
75421
75422diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
75423index d128f65..f37b4af 100644
75424--- a/kernel/trace/trace_events.c
75425+++ b/kernel/trace/trace_events.c
75426@@ -951,13 +951,10 @@ static LIST_HEAD(ftrace_module_file_list);
75427 * Modules must own their file_operations to keep up with
75428 * reference counting.
75429 */
75430+
75431 struct ftrace_module_file_ops {
75432 struct list_head list;
75433 struct module *mod;
75434- struct file_operations id;
75435- struct file_operations enable;
75436- struct file_operations format;
75437- struct file_operations filter;
75438 };
75439
75440 static void remove_subsystem_dir(const char *name)
75441@@ -1004,17 +1001,12 @@ trace_create_file_ops(struct module *mod)
75442
75443 file_ops->mod = mod;
75444
75445- file_ops->id = ftrace_event_id_fops;
75446- file_ops->id.owner = mod;
75447-
75448- file_ops->enable = ftrace_enable_fops;
75449- file_ops->enable.owner = mod;
75450-
75451- file_ops->filter = ftrace_event_filter_fops;
75452- file_ops->filter.owner = mod;
75453-
75454- file_ops->format = ftrace_event_format_fops;
75455- file_ops->format.owner = mod;
75456+ pax_open_kernel();
75457+ *(void **)&mod->trace_id.owner = mod;
75458+ *(void **)&mod->trace_enable.owner = mod;
75459+ *(void **)&mod->trace_filter.owner = mod;
75460+ *(void **)&mod->trace_format.owner = mod;
75461+ pax_close_kernel();
75462
75463 list_add(&file_ops->list, &ftrace_module_file_list);
75464
75465@@ -1063,8 +1055,8 @@ static void trace_module_add_events(struct module *mod)
75466 call->mod = mod;
75467 list_add(&call->list, &ftrace_events);
75468 event_create_dir(call, d_events,
75469- &file_ops->id, &file_ops->enable,
75470- &file_ops->filter, &file_ops->format);
75471+ &mod->trace_id, &mod->trace_enable,
75472+ &mod->trace_filter, &mod->trace_format);
75473 }
75474 }
75475
75476diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
75477index 0acd834..b800b56 100644
75478--- a/kernel/trace/trace_mmiotrace.c
75479+++ b/kernel/trace/trace_mmiotrace.c
75480@@ -23,7 +23,7 @@ struct header_iter {
75481 static struct trace_array *mmio_trace_array;
75482 static bool overrun_detected;
75483 static unsigned long prev_overruns;
75484-static atomic_t dropped_count;
75485+static atomic_unchecked_t dropped_count;
75486
75487 static void mmio_reset_data(struct trace_array *tr)
75488 {
75489@@ -126,7 +126,7 @@ static void mmio_close(struct trace_iterator *iter)
75490
75491 static unsigned long count_overruns(struct trace_iterator *iter)
75492 {
75493- unsigned long cnt = atomic_xchg(&dropped_count, 0);
75494+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
75495 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
75496
75497 if (over > prev_overruns)
75498@@ -316,7 +316,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
75499 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
75500 sizeof(*entry), 0, pc);
75501 if (!event) {
75502- atomic_inc(&dropped_count);
75503+ atomic_inc_unchecked(&dropped_count);
75504 return;
75505 }
75506 entry = ring_buffer_event_data(event);
75507@@ -346,7 +346,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
75508 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
75509 sizeof(*entry), 0, pc);
75510 if (!event) {
75511- atomic_inc(&dropped_count);
75512+ atomic_inc_unchecked(&dropped_count);
75513 return;
75514 }
75515 entry = ring_buffer_event_data(event);
75516diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
75517index b6c12c6..41fdc53 100644
75518--- a/kernel/trace/trace_output.c
75519+++ b/kernel/trace/trace_output.c
75520@@ -237,7 +237,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
75521 return 0;
75522 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
75523 if (!IS_ERR(p)) {
75524- p = mangle_path(s->buffer + s->len, p, "\n");
75525+ p = mangle_path(s->buffer + s->len, p, "\n\\");
75526 if (p) {
75527 s->len = p - s->buffer;
75528 return 1;
75529diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
75530index 8504ac7..ecf0adb 100644
75531--- a/kernel/trace/trace_stack.c
75532+++ b/kernel/trace/trace_stack.c
75533@@ -50,7 +50,7 @@ static inline void check_stack(void)
75534 return;
75535
75536 /* we do not handle interrupt stacks yet */
75537- if (!object_is_on_stack(&this_size))
75538+ if (!object_starts_on_stack(&this_size))
75539 return;
75540
75541 local_irq_save(flags);
75542diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
75543index 40cafb0..d5ead43 100644
75544--- a/kernel/trace/trace_workqueue.c
75545+++ b/kernel/trace/trace_workqueue.c
75546@@ -21,7 +21,7 @@ struct cpu_workqueue_stats {
75547 int cpu;
75548 pid_t pid;
75549 /* Can be inserted from interrupt or user context, need to be atomic */
75550- atomic_t inserted;
75551+ atomic_unchecked_t inserted;
75552 /*
75553 * Don't need to be atomic, works are serialized in a single workqueue thread
75554 * on a single CPU.
75555@@ -58,7 +58,7 @@ probe_workqueue_insertion(struct task_struct *wq_thread,
75556 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
75557 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
75558 if (node->pid == wq_thread->pid) {
75559- atomic_inc(&node->inserted);
75560+ atomic_inc_unchecked(&node->inserted);
75561 goto found;
75562 }
75563 }
75564@@ -205,7 +205,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
75565 tsk = get_pid_task(pid, PIDTYPE_PID);
75566 if (tsk) {
75567 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
75568- atomic_read(&cws->inserted), cws->executed,
75569+ atomic_read_unchecked(&cws->inserted), cws->executed,
75570 tsk->comm);
75571 put_task_struct(tsk);
75572 }
75573diff --git a/kernel/user.c b/kernel/user.c
75574index 1b91701..8795237 100644
75575--- a/kernel/user.c
75576+++ b/kernel/user.c
75577@@ -159,6 +159,7 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
75578 spin_lock_irq(&uidhash_lock);
75579 up = uid_hash_find(uid, hashent);
75580 if (up) {
75581+ put_user_ns(ns);
75582 key_put(new->uid_keyring);
75583 key_put(new->session_keyring);
75584 kmem_cache_free(uid_cachep, new);
75585diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
75586index 234ceb1..ad74049 100644
75587--- a/lib/Kconfig.debug
75588+++ b/lib/Kconfig.debug
75589@@ -905,7 +905,7 @@ config LATENCYTOP
75590 select STACKTRACE
75591 select SCHEDSTATS
75592 select SCHED_DEBUG
75593- depends on HAVE_LATENCYTOP_SUPPORT
75594+ depends on HAVE_LATENCYTOP_SUPPORT && !GRKERNSEC_HIDESYM
75595 help
75596 Enable this option if you want to use the LatencyTOP tool
75597 to find out which userspace is blocking on what kernel operations.
75598diff --git a/lib/bitmap.c b/lib/bitmap.c
75599index 7025658..8d14cab 100644
75600--- a/lib/bitmap.c
75601+++ b/lib/bitmap.c
75602@@ -341,7 +341,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
75603 {
75604 int c, old_c, totaldigits, ndigits, nchunks, nbits;
75605 u32 chunk;
75606- const char __user *ubuf = buf;
75607+ const char __user *ubuf = (const char __force_user *)buf;
75608
75609 bitmap_zero(maskp, nmaskbits);
75610
75611@@ -426,7 +426,7 @@ int bitmap_parse_user(const char __user *ubuf,
75612 {
75613 if (!access_ok(VERIFY_READ, ubuf, ulen))
75614 return -EFAULT;
75615- return __bitmap_parse((const char *)ubuf, ulen, 1, maskp, nmaskbits);
75616+ return __bitmap_parse((const char __force_kernel *)ubuf, ulen, 1, maskp, nmaskbits);
75617 }
75618 EXPORT_SYMBOL(bitmap_parse_user);
75619
75620diff --git a/lib/bug.c b/lib/bug.c
75621index 300e41a..2779eb0 100644
75622--- a/lib/bug.c
75623+++ b/lib/bug.c
75624@@ -135,6 +135,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
75625 return BUG_TRAP_TYPE_NONE;
75626
75627 bug = find_bug(bugaddr);
75628+ if (!bug)
75629+ return BUG_TRAP_TYPE_NONE;
75630
75631 printk(KERN_EMERG "------------[ cut here ]------------\n");
75632
75633diff --git a/lib/debugobjects.c b/lib/debugobjects.c
75634index 2b413db..e21d207 100644
75635--- a/lib/debugobjects.c
75636+++ b/lib/debugobjects.c
75637@@ -277,7 +277,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
75638 if (limit > 4)
75639 return;
75640
75641- is_on_stack = object_is_on_stack(addr);
75642+ is_on_stack = object_starts_on_stack(addr);
75643 if (is_on_stack == onstack)
75644 return;
75645
75646diff --git a/lib/devres.c b/lib/devres.c
75647index 72c8909..7543868 100644
75648--- a/lib/devres.c
75649+++ b/lib/devres.c
75650@@ -80,7 +80,7 @@ void devm_iounmap(struct device *dev, void __iomem *addr)
75651 {
75652 iounmap(addr);
75653 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
75654- (void *)addr));
75655+ (void __force *)addr));
75656 }
75657 EXPORT_SYMBOL(devm_iounmap);
75658
75659@@ -140,7 +140,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
75660 {
75661 ioport_unmap(addr);
75662 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
75663- devm_ioport_map_match, (void *)addr));
75664+ devm_ioport_map_match, (void __force *)addr));
75665 }
75666 EXPORT_SYMBOL(devm_ioport_unmap);
75667
75668diff --git a/lib/dma-debug.c b/lib/dma-debug.c
75669index 084e879..0674448 100644
75670--- a/lib/dma-debug.c
75671+++ b/lib/dma-debug.c
75672@@ -861,7 +861,7 @@ out:
75673
75674 static void check_for_stack(struct device *dev, void *addr)
75675 {
75676- if (object_is_on_stack(addr))
75677+ if (object_starts_on_stack(addr))
75678 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
75679 "stack [addr=%p]\n", addr);
75680 }
75681diff --git a/lib/idr.c b/lib/idr.c
75682index eda7ba3..915dfae 100644
75683--- a/lib/idr.c
75684+++ b/lib/idr.c
75685@@ -156,7 +156,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa)
75686 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
75687
75688 /* if already at the top layer, we need to grow */
75689- if (id >= 1 << (idp->layers * IDR_BITS)) {
75690+ if (id >= (1 << (idp->layers * IDR_BITS))) {
75691 *starting_id = id;
75692 return IDR_NEED_TO_GROW;
75693 }
75694diff --git a/lib/inflate.c b/lib/inflate.c
75695index d102559..4215f31 100644
75696--- a/lib/inflate.c
75697+++ b/lib/inflate.c
75698@@ -266,7 +266,7 @@ static void free(void *where)
75699 malloc_ptr = free_mem_ptr;
75700 }
75701 #else
75702-#define malloc(a) kmalloc(a, GFP_KERNEL)
75703+#define malloc(a) kmalloc((a), GFP_KERNEL)
75704 #define free(a) kfree(a)
75705 #endif
75706
75707diff --git a/lib/kobject.c b/lib/kobject.c
75708index b512b74..8115eb1 100644
75709--- a/lib/kobject.c
75710+++ b/lib/kobject.c
75711@@ -700,7 +700,7 @@ static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
75712 return ret;
75713 }
75714
75715-struct sysfs_ops kobj_sysfs_ops = {
75716+const struct sysfs_ops kobj_sysfs_ops = {
75717 .show = kobj_attr_show,
75718 .store = kobj_attr_store,
75719 };
75720@@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
75721 * If the kset was not able to be created, NULL will be returned.
75722 */
75723 static struct kset *kset_create(const char *name,
75724- struct kset_uevent_ops *uevent_ops,
75725+ const struct kset_uevent_ops *uevent_ops,
75726 struct kobject *parent_kobj)
75727 {
75728 struct kset *kset;
75729@@ -832,7 +832,7 @@ static struct kset *kset_create(const char *name,
75730 * If the kset was not able to be created, NULL will be returned.
75731 */
75732 struct kset *kset_create_and_add(const char *name,
75733- struct kset_uevent_ops *uevent_ops,
75734+ const struct kset_uevent_ops *uevent_ops,
75735 struct kobject *parent_kobj)
75736 {
75737 struct kset *kset;
75738diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
75739index 507b821..0bf8ed0 100644
75740--- a/lib/kobject_uevent.c
75741+++ b/lib/kobject_uevent.c
75742@@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
75743 const char *subsystem;
75744 struct kobject *top_kobj;
75745 struct kset *kset;
75746- struct kset_uevent_ops *uevent_ops;
75747+ const struct kset_uevent_ops *uevent_ops;
75748 u64 seq;
75749 int i = 0;
75750 int retval = 0;
75751diff --git a/lib/kref.c b/lib/kref.c
75752index 9ecd6e8..12c94c1 100644
75753--- a/lib/kref.c
75754+++ b/lib/kref.c
75755@@ -61,7 +61,7 @@ void kref_get(struct kref *kref)
75756 */
75757 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
75758 {
75759- WARN_ON(release == NULL);
75760+ BUG_ON(release == NULL);
75761 WARN_ON(release == (void (*)(struct kref *))kfree);
75762
75763 if (atomic_dec_and_test(&kref->refcount)) {
75764diff --git a/lib/parser.c b/lib/parser.c
75765index b00d020..1b34325 100644
75766--- a/lib/parser.c
75767+++ b/lib/parser.c
75768@@ -126,7 +126,7 @@ static int match_number(substring_t *s, int *result, int base)
75769 char *buf;
75770 int ret;
75771
75772- buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
75773+ buf = kmalloc((s->to - s->from) + 1, GFP_KERNEL);
75774 if (!buf)
75775 return -ENOMEM;
75776 memcpy(buf, s->from, s->to - s->from);
75777diff --git a/lib/radix-tree.c b/lib/radix-tree.c
75778index 92cdd99..a8149d7 100644
75779--- a/lib/radix-tree.c
75780+++ b/lib/radix-tree.c
75781@@ -81,7 +81,7 @@ struct radix_tree_preload {
75782 int nr;
75783 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
75784 };
75785-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
75786+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
75787
75788 static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
75789 {
75790diff --git a/lib/random32.c b/lib/random32.c
75791index 217d5c4..45aba8a 100644
75792--- a/lib/random32.c
75793+++ b/lib/random32.c
75794@@ -61,7 +61,7 @@ static u32 __random32(struct rnd_state *state)
75795 */
75796 static inline u32 __seed(u32 x, u32 m)
75797 {
75798- return (x < m) ? x + m : x;
75799+ return (x <= m) ? x + m + 1 : x;
75800 }
75801
75802 /**
75803diff --git a/lib/vsprintf.c b/lib/vsprintf.c
75804index 33bed5e..1477e46 100644
75805--- a/lib/vsprintf.c
75806+++ b/lib/vsprintf.c
75807@@ -16,6 +16,9 @@
75808 * - scnprintf and vscnprintf
75809 */
75810
75811+#ifdef CONFIG_GRKERNSEC_HIDESYM
75812+#define __INCLUDED_BY_HIDESYM 1
75813+#endif
75814 #include <stdarg.h>
75815 #include <linux/module.h>
75816 #include <linux/types.h>
75817@@ -546,12 +549,12 @@ static char *number(char *buf, char *end, unsigned long long num,
75818 return buf;
75819 }
75820
75821-static char *string(char *buf, char *end, char *s, struct printf_spec spec)
75822+static char *string(char *buf, char *end, const char *s, struct printf_spec spec)
75823 {
75824 int len, i;
75825
75826 if ((unsigned long)s < PAGE_SIZE)
75827- s = "<NULL>";
75828+ s = "(null)";
75829
75830 len = strnlen(s, spec.precision);
75831
75832@@ -581,7 +584,7 @@ static char *symbol_string(char *buf, char *end, void *ptr,
75833 unsigned long value = (unsigned long) ptr;
75834 #ifdef CONFIG_KALLSYMS
75835 char sym[KSYM_SYMBOL_LEN];
75836- if (ext != 'f' && ext != 's')
75837+ if (ext != 'f' && ext != 's' && ext != 'a')
75838 sprint_symbol(sym, value);
75839 else
75840 kallsyms_lookup(value, NULL, NULL, NULL, sym);
75841@@ -801,6 +804,8 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr,
75842 * - 'f' For simple symbolic function names without offset
75843 * - 'S' For symbolic direct pointers with offset
75844 * - 's' For symbolic direct pointers without offset
75845+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
75846+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
75847 * - 'R' For a struct resource pointer, it prints the range of
75848 * addresses (not the name nor the flags)
75849 * - 'M' For a 6-byte MAC address, it prints the address in the
75850@@ -822,7 +827,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75851 struct printf_spec spec)
75852 {
75853 if (!ptr)
75854- return string(buf, end, "(null)", spec);
75855+ return string(buf, end, "(nil)", spec);
75856
75857 switch (*fmt) {
75858 case 'F':
75859@@ -831,6 +836,14 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75860 case 's':
75861 /* Fallthrough */
75862 case 'S':
75863+#ifdef CONFIG_GRKERNSEC_HIDESYM
75864+ break;
75865+#else
75866+ return symbol_string(buf, end, ptr, spec, *fmt);
75867+#endif
75868+ case 'a':
75869+ /* Fallthrough */
75870+ case 'A':
75871 return symbol_string(buf, end, ptr, spec, *fmt);
75872 case 'R':
75873 return resource_string(buf, end, ptr, spec);
75874@@ -1445,7 +1458,7 @@ do { \
75875 size_t len;
75876 if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
75877 || (unsigned long)save_str < PAGE_SIZE)
75878- save_str = "<NULL>";
75879+ save_str = "(null)";
75880 len = strlen(save_str);
75881 if (str + len + 1 < end)
75882 memcpy(str, save_str, len + 1);
75883@@ -1555,11 +1568,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75884 typeof(type) value; \
75885 if (sizeof(type) == 8) { \
75886 args = PTR_ALIGN(args, sizeof(u32)); \
75887- *(u32 *)&value = *(u32 *)args; \
75888- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75889+ *(u32 *)&value = *(const u32 *)args; \
75890+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75891 } else { \
75892 args = PTR_ALIGN(args, sizeof(type)); \
75893- value = *(typeof(type) *)args; \
75894+ value = *(const typeof(type) *)args; \
75895 } \
75896 args += sizeof(type); \
75897 value; \
75898@@ -1622,7 +1635,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75899 const char *str_arg = args;
75900 size_t len = strlen(str_arg);
75901 args += len + 1;
75902- str = string(str, end, (char *)str_arg, spec);
75903+ str = string(str, end, str_arg, spec);
75904 break;
75905 }
75906
75907diff --git a/localversion-grsec b/localversion-grsec
75908new file mode 100644
75909index 0000000..7cd6065
75910--- /dev/null
75911+++ b/localversion-grsec
75912@@ -0,0 +1 @@
75913+-grsec
75914diff --git a/mm/Kconfig b/mm/Kconfig
75915index 2c19c0b..f3c3f83 100644
75916--- a/mm/Kconfig
75917+++ b/mm/Kconfig
75918@@ -228,7 +228,7 @@ config KSM
75919 config DEFAULT_MMAP_MIN_ADDR
75920 int "Low address space to protect from user allocation"
75921 depends on MMU
75922- default 4096
75923+ default 65536
75924 help
75925 This is the portion of low virtual memory which should be protected
75926 from userspace allocation. Keeping a user from writing to low pages
75927diff --git a/mm/backing-dev.c b/mm/backing-dev.c
75928index 67a33a5..094dcf1 100644
75929--- a/mm/backing-dev.c
75930+++ b/mm/backing-dev.c
75931@@ -272,7 +272,7 @@ static void bdi_task_init(struct backing_dev_info *bdi,
75932 list_add_tail_rcu(&wb->list, &bdi->wb_list);
75933 spin_unlock(&bdi->wb_lock);
75934
75935- tsk->flags |= PF_FLUSHER | PF_SWAPWRITE;
75936+ tsk->flags |= PF_SWAPWRITE;
75937 set_freezable();
75938
75939 /*
75940@@ -484,7 +484,7 @@ static void bdi_add_to_pending(struct rcu_head *head)
75941 * Add the default flusher task that gets created for any bdi
75942 * that has dirty data pending writeout
75943 */
75944-void static bdi_add_default_flusher_task(struct backing_dev_info *bdi)
75945+static void bdi_add_default_flusher_task(struct backing_dev_info *bdi)
75946 {
75947 if (!bdi_cap_writeback_dirty(bdi))
75948 return;
75949diff --git a/mm/filemap.c b/mm/filemap.c
75950index a1fe378..e26702f 100644
75951--- a/mm/filemap.c
75952+++ b/mm/filemap.c
75953@@ -1631,7 +1631,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75954 struct address_space *mapping = file->f_mapping;
75955
75956 if (!mapping->a_ops->readpage)
75957- return -ENOEXEC;
75958+ return -ENODEV;
75959 file_accessed(file);
75960 vma->vm_ops = &generic_file_vm_ops;
75961 vma->vm_flags |= VM_CAN_NONLINEAR;
75962@@ -2024,6 +2024,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75963 *pos = i_size_read(inode);
75964
75965 if (limit != RLIM_INFINITY) {
75966+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75967 if (*pos >= limit) {
75968 send_sig(SIGXFSZ, current, 0);
75969 return -EFBIG;
75970diff --git a/mm/fremap.c b/mm/fremap.c
75971index b6ec85a..a24ac22 100644
75972--- a/mm/fremap.c
75973+++ b/mm/fremap.c
75974@@ -153,6 +153,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75975 retry:
75976 vma = find_vma(mm, start);
75977
75978+#ifdef CONFIG_PAX_SEGMEXEC
75979+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75980+ goto out;
75981+#endif
75982+
75983 /*
75984 * Make sure the vma is shared, that it supports prefaulting,
75985 * and that the remapped range is valid and fully within
75986@@ -221,7 +226,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75987 /*
75988 * drop PG_Mlocked flag for over-mapped range
75989 */
75990- unsigned int saved_flags = vma->vm_flags;
75991+ unsigned long saved_flags = vma->vm_flags;
75992 munlock_vma_pages_range(vma, start, start + size);
75993 vma->vm_flags = saved_flags;
75994 }
75995diff --git a/mm/highmem.c b/mm/highmem.c
75996index 9c1e627..5ca9447 100644
75997--- a/mm/highmem.c
75998+++ b/mm/highmem.c
75999@@ -116,9 +116,10 @@ static void flush_all_zero_pkmaps(void)
76000 * So no dangers, even with speculative execution.
76001 */
76002 page = pte_page(pkmap_page_table[i]);
76003+ pax_open_kernel();
76004 pte_clear(&init_mm, (unsigned long)page_address(page),
76005 &pkmap_page_table[i]);
76006-
76007+ pax_close_kernel();
76008 set_page_address(page, NULL);
76009 need_flush = 1;
76010 }
76011@@ -177,9 +178,11 @@ start:
76012 }
76013 }
76014 vaddr = PKMAP_ADDR(last_pkmap_nr);
76015+
76016+ pax_open_kernel();
76017 set_pte_at(&init_mm, vaddr,
76018 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
76019-
76020+ pax_close_kernel();
76021 pkmap_count[last_pkmap_nr] = 1;
76022 set_page_address(page, (void *)vaddr);
76023
76024diff --git a/mm/hugetlb.c b/mm/hugetlb.c
76025index 5e1e508..ac70275 100644
76026--- a/mm/hugetlb.c
76027+++ b/mm/hugetlb.c
76028@@ -869,6 +869,7 @@ free:
76029 list_del(&page->lru);
76030 enqueue_huge_page(h, page);
76031 }
76032+ spin_unlock(&hugetlb_lock);
76033
76034 /* Free unnecessary surplus pages to the buddy allocator */
76035 if (!list_empty(&surplus_list)) {
76036@@ -1933,6 +1934,26 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
76037 return 1;
76038 }
76039
76040+#ifdef CONFIG_PAX_SEGMEXEC
76041+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
76042+{
76043+ struct mm_struct *mm = vma->vm_mm;
76044+ struct vm_area_struct *vma_m;
76045+ unsigned long address_m;
76046+ pte_t *ptep_m;
76047+
76048+ vma_m = pax_find_mirror_vma(vma);
76049+ if (!vma_m)
76050+ return;
76051+
76052+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
76053+ address_m = address + SEGMEXEC_TASK_SIZE;
76054+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
76055+ get_page(page_m);
76056+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
76057+}
76058+#endif
76059+
76060 static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
76061 unsigned long address, pte_t *ptep, pte_t pte,
76062 struct page *pagecache_page)
76063@@ -2004,6 +2025,11 @@ retry_avoidcopy:
76064 huge_ptep_clear_flush(vma, address, ptep);
76065 set_huge_pte_at(mm, address, ptep,
76066 make_huge_pte(vma, new_page, 1));
76067+
76068+#ifdef CONFIG_PAX_SEGMEXEC
76069+ pax_mirror_huge_pte(vma, address, new_page);
76070+#endif
76071+
76072 /* Make the old page be freed below */
76073 new_page = old_page;
76074 }
76075@@ -2135,6 +2161,10 @@ retry:
76076 && (vma->vm_flags & VM_SHARED)));
76077 set_huge_pte_at(mm, address, ptep, new_pte);
76078
76079+#ifdef CONFIG_PAX_SEGMEXEC
76080+ pax_mirror_huge_pte(vma, address, page);
76081+#endif
76082+
76083 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
76084 /* Optimization, do the COW without a second fault */
76085 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
76086@@ -2163,6 +2193,28 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76087 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
76088 struct hstate *h = hstate_vma(vma);
76089
76090+#ifdef CONFIG_PAX_SEGMEXEC
76091+ struct vm_area_struct *vma_m;
76092+
76093+ vma_m = pax_find_mirror_vma(vma);
76094+ if (vma_m) {
76095+ unsigned long address_m;
76096+
76097+ if (vma->vm_start > vma_m->vm_start) {
76098+ address_m = address;
76099+ address -= SEGMEXEC_TASK_SIZE;
76100+ vma = vma_m;
76101+ h = hstate_vma(vma);
76102+ } else
76103+ address_m = address + SEGMEXEC_TASK_SIZE;
76104+
76105+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
76106+ return VM_FAULT_OOM;
76107+ address_m &= HPAGE_MASK;
76108+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
76109+ }
76110+#endif
76111+
76112 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
76113 if (!ptep)
76114 return VM_FAULT_OOM;
76115diff --git a/mm/internal.h b/mm/internal.h
76116index f03e8e2..7354343 100644
76117--- a/mm/internal.h
76118+++ b/mm/internal.h
76119@@ -49,6 +49,7 @@ extern void putback_lru_page(struct page *page);
76120 * in mm/page_alloc.c
76121 */
76122 extern void __free_pages_bootmem(struct page *page, unsigned int order);
76123+extern void free_compound_page(struct page *page);
76124 extern void prep_compound_page(struct page *page, unsigned long order);
76125
76126
76127diff --git a/mm/kmemleak.c b/mm/kmemleak.c
76128index c346660..b47382f 100644
76129--- a/mm/kmemleak.c
76130+++ b/mm/kmemleak.c
76131@@ -358,7 +358,7 @@ static void print_unreferenced(struct seq_file *seq,
76132
76133 for (i = 0; i < object->trace_len; i++) {
76134 void *ptr = (void *)object->trace[i];
76135- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
76136+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
76137 }
76138 }
76139
76140diff --git a/mm/maccess.c b/mm/maccess.c
76141index 9073695..1127f348 100644
76142--- a/mm/maccess.c
76143+++ b/mm/maccess.c
76144@@ -14,7 +14,7 @@
76145 * Safely read from address @src to the buffer at @dst. If a kernel fault
76146 * happens, handle that and return -EFAULT.
76147 */
76148-long probe_kernel_read(void *dst, void *src, size_t size)
76149+long probe_kernel_read(void *dst, const void *src, size_t size)
76150 {
76151 long ret;
76152 mm_segment_t old_fs = get_fs();
76153@@ -22,7 +22,7 @@ long probe_kernel_read(void *dst, void *src, size_t size)
76154 set_fs(KERNEL_DS);
76155 pagefault_disable();
76156 ret = __copy_from_user_inatomic(dst,
76157- (__force const void __user *)src, size);
76158+ (const void __force_user *)src, size);
76159 pagefault_enable();
76160 set_fs(old_fs);
76161
76162@@ -39,14 +39,14 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
76163 * Safely write to address @dst from the buffer at @src. If a kernel fault
76164 * happens, handle that and return -EFAULT.
76165 */
76166-long notrace __weak probe_kernel_write(void *dst, void *src, size_t size)
76167+long notrace __weak probe_kernel_write(void *dst, const void *src, size_t size)
76168 {
76169 long ret;
76170 mm_segment_t old_fs = get_fs();
76171
76172 set_fs(KERNEL_DS);
76173 pagefault_disable();
76174- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
76175+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
76176 pagefault_enable();
76177 set_fs(old_fs);
76178
76179diff --git a/mm/madvise.c b/mm/madvise.c
76180index 35b1479..499f7d4 100644
76181--- a/mm/madvise.c
76182+++ b/mm/madvise.c
76183@@ -44,6 +44,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
76184 pgoff_t pgoff;
76185 unsigned long new_flags = vma->vm_flags;
76186
76187+#ifdef CONFIG_PAX_SEGMEXEC
76188+ struct vm_area_struct *vma_m;
76189+#endif
76190+
76191 switch (behavior) {
76192 case MADV_NORMAL:
76193 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
76194@@ -103,6 +107,13 @@ success:
76195 /*
76196 * vm_flags is protected by the mmap_sem held in write mode.
76197 */
76198+
76199+#ifdef CONFIG_PAX_SEGMEXEC
76200+ vma_m = pax_find_mirror_vma(vma);
76201+ if (vma_m)
76202+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
76203+#endif
76204+
76205 vma->vm_flags = new_flags;
76206
76207 out:
76208@@ -161,6 +172,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
76209 struct vm_area_struct ** prev,
76210 unsigned long start, unsigned long end)
76211 {
76212+
76213+#ifdef CONFIG_PAX_SEGMEXEC
76214+ struct vm_area_struct *vma_m;
76215+#endif
76216+
76217 *prev = vma;
76218 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
76219 return -EINVAL;
76220@@ -173,6 +189,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
76221 zap_page_range(vma, start, end - start, &details);
76222 } else
76223 zap_page_range(vma, start, end - start, NULL);
76224+
76225+#ifdef CONFIG_PAX_SEGMEXEC
76226+ vma_m = pax_find_mirror_vma(vma);
76227+ if (vma_m) {
76228+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
76229+ struct zap_details details = {
76230+ .nonlinear_vma = vma_m,
76231+ .last_index = ULONG_MAX,
76232+ };
76233+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
76234+ } else
76235+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
76236+ }
76237+#endif
76238+
76239 return 0;
76240 }
76241
76242@@ -359,6 +390,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
76243 if (end < start)
76244 goto out;
76245
76246+#ifdef CONFIG_PAX_SEGMEXEC
76247+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
76248+ if (end > SEGMEXEC_TASK_SIZE)
76249+ goto out;
76250+ } else
76251+#endif
76252+
76253+ if (end > TASK_SIZE)
76254+ goto out;
76255+
76256 error = 0;
76257 if (end == start)
76258 goto out;
76259diff --git a/mm/memory-failure.c b/mm/memory-failure.c
76260index 8aeba53..b4a4198 100644
76261--- a/mm/memory-failure.c
76262+++ b/mm/memory-failure.c
76263@@ -46,7 +46,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
76264
76265 int sysctl_memory_failure_recovery __read_mostly = 1;
76266
76267-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
76268+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
76269
76270 /*
76271 * Send all the processes who have the page mapped an ``action optional''
76272@@ -64,7 +64,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
76273 si.si_signo = SIGBUS;
76274 si.si_errno = 0;
76275 si.si_code = BUS_MCEERR_AO;
76276- si.si_addr = (void *)addr;
76277+ si.si_addr = (void __user *)addr;
76278 #ifdef __ARCH_SI_TRAPNO
76279 si.si_trapno = trapno;
76280 #endif
76281@@ -745,7 +745,7 @@ int __memory_failure(unsigned long pfn, int trapno, int ref)
76282 return 0;
76283 }
76284
76285- atomic_long_add(1, &mce_bad_pages);
76286+ atomic_long_add_unchecked(1, &mce_bad_pages);
76287
76288 /*
76289 * We need/can do nothing about count=0 pages.
76290diff --git a/mm/memory.c b/mm/memory.c
76291index 6c836d3..48f3264 100644
76292--- a/mm/memory.c
76293+++ b/mm/memory.c
76294@@ -187,8 +187,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
76295 return;
76296
76297 pmd = pmd_offset(pud, start);
76298+
76299+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
76300 pud_clear(pud);
76301 pmd_free_tlb(tlb, pmd, start);
76302+#endif
76303+
76304 }
76305
76306 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
76307@@ -219,9 +223,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
76308 if (end - 1 > ceiling - 1)
76309 return;
76310
76311+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
76312 pud = pud_offset(pgd, start);
76313 pgd_clear(pgd);
76314 pud_free_tlb(tlb, pud, start);
76315+#endif
76316+
76317 }
76318
76319 /*
76320@@ -1251,10 +1258,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
76321 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
76322 i = 0;
76323
76324- do {
76325+ while (nr_pages) {
76326 struct vm_area_struct *vma;
76327
76328- vma = find_extend_vma(mm, start);
76329+ vma = find_vma(mm, start);
76330 if (!vma && in_gate_area(tsk, start)) {
76331 unsigned long pg = start & PAGE_MASK;
76332 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
76333@@ -1306,7 +1313,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
76334 continue;
76335 }
76336
76337- if (!vma ||
76338+ if (!vma || start < vma->vm_start ||
76339 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
76340 !(vm_flags & vma->vm_flags))
76341 return i ? : -EFAULT;
76342@@ -1381,7 +1388,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
76343 start += PAGE_SIZE;
76344 nr_pages--;
76345 } while (nr_pages && start < vma->vm_end);
76346- } while (nr_pages);
76347+ }
76348 return i;
76349 }
76350
76351@@ -1526,6 +1533,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
76352 page_add_file_rmap(page);
76353 set_pte_at(mm, addr, pte, mk_pte(page, prot));
76354
76355+#ifdef CONFIG_PAX_SEGMEXEC
76356+ pax_mirror_file_pte(vma, addr, page, ptl);
76357+#endif
76358+
76359 retval = 0;
76360 pte_unmap_unlock(pte, ptl);
76361 return retval;
76362@@ -1560,10 +1571,22 @@ out:
76363 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
76364 struct page *page)
76365 {
76366+
76367+#ifdef CONFIG_PAX_SEGMEXEC
76368+ struct vm_area_struct *vma_m;
76369+#endif
76370+
76371 if (addr < vma->vm_start || addr >= vma->vm_end)
76372 return -EFAULT;
76373 if (!page_count(page))
76374 return -EINVAL;
76375+
76376+#ifdef CONFIG_PAX_SEGMEXEC
76377+ vma_m = pax_find_mirror_vma(vma);
76378+ if (vma_m)
76379+ vma_m->vm_flags |= VM_INSERTPAGE;
76380+#endif
76381+
76382 vma->vm_flags |= VM_INSERTPAGE;
76383 return insert_page(vma, addr, page, vma->vm_page_prot);
76384 }
76385@@ -1649,6 +1672,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
76386 unsigned long pfn)
76387 {
76388 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
76389+ BUG_ON(vma->vm_mirror);
76390
76391 if (addr < vma->vm_start || addr >= vma->vm_end)
76392 return -EFAULT;
76393@@ -1977,6 +2001,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
76394 copy_user_highpage(dst, src, va, vma);
76395 }
76396
76397+#ifdef CONFIG_PAX_SEGMEXEC
76398+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
76399+{
76400+ struct mm_struct *mm = vma->vm_mm;
76401+ spinlock_t *ptl;
76402+ pte_t *pte, entry;
76403+
76404+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
76405+ entry = *pte;
76406+ if (!pte_present(entry)) {
76407+ if (!pte_none(entry)) {
76408+ BUG_ON(pte_file(entry));
76409+ free_swap_and_cache(pte_to_swp_entry(entry));
76410+ pte_clear_not_present_full(mm, address, pte, 0);
76411+ }
76412+ } else {
76413+ struct page *page;
76414+
76415+ flush_cache_page(vma, address, pte_pfn(entry));
76416+ entry = ptep_clear_flush(vma, address, pte);
76417+ BUG_ON(pte_dirty(entry));
76418+ page = vm_normal_page(vma, address, entry);
76419+ if (page) {
76420+ update_hiwater_rss(mm);
76421+ if (PageAnon(page))
76422+ dec_mm_counter(mm, anon_rss);
76423+ else
76424+ dec_mm_counter(mm, file_rss);
76425+ page_remove_rmap(page);
76426+ page_cache_release(page);
76427+ }
76428+ }
76429+ pte_unmap_unlock(pte, ptl);
76430+}
76431+
76432+/* PaX: if vma is mirrored, synchronize the mirror's PTE
76433+ *
76434+ * the ptl of the lower mapped page is held on entry and is not released on exit
76435+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
76436+ */
76437+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
76438+{
76439+ struct mm_struct *mm = vma->vm_mm;
76440+ unsigned long address_m;
76441+ spinlock_t *ptl_m;
76442+ struct vm_area_struct *vma_m;
76443+ pmd_t *pmd_m;
76444+ pte_t *pte_m, entry_m;
76445+
76446+ BUG_ON(!page_m || !PageAnon(page_m));
76447+
76448+ vma_m = pax_find_mirror_vma(vma);
76449+ if (!vma_m)
76450+ return;
76451+
76452+ BUG_ON(!PageLocked(page_m));
76453+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
76454+ address_m = address + SEGMEXEC_TASK_SIZE;
76455+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
76456+ pte_m = pte_offset_map_nested(pmd_m, address_m);
76457+ ptl_m = pte_lockptr(mm, pmd_m);
76458+ if (ptl != ptl_m) {
76459+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
76460+ if (!pte_none(*pte_m))
76461+ goto out;
76462+ }
76463+
76464+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
76465+ page_cache_get(page_m);
76466+ page_add_anon_rmap(page_m, vma_m, address_m);
76467+ inc_mm_counter(mm, anon_rss);
76468+ set_pte_at(mm, address_m, pte_m, entry_m);
76469+ update_mmu_cache(vma_m, address_m, entry_m);
76470+out:
76471+ if (ptl != ptl_m)
76472+ spin_unlock(ptl_m);
76473+ pte_unmap_nested(pte_m);
76474+ unlock_page(page_m);
76475+}
76476+
76477+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
76478+{
76479+ struct mm_struct *mm = vma->vm_mm;
76480+ unsigned long address_m;
76481+ spinlock_t *ptl_m;
76482+ struct vm_area_struct *vma_m;
76483+ pmd_t *pmd_m;
76484+ pte_t *pte_m, entry_m;
76485+
76486+ BUG_ON(!page_m || PageAnon(page_m));
76487+
76488+ vma_m = pax_find_mirror_vma(vma);
76489+ if (!vma_m)
76490+ return;
76491+
76492+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
76493+ address_m = address + SEGMEXEC_TASK_SIZE;
76494+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
76495+ pte_m = pte_offset_map_nested(pmd_m, address_m);
76496+ ptl_m = pte_lockptr(mm, pmd_m);
76497+ if (ptl != ptl_m) {
76498+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
76499+ if (!pte_none(*pte_m))
76500+ goto out;
76501+ }
76502+
76503+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
76504+ page_cache_get(page_m);
76505+ page_add_file_rmap(page_m);
76506+ inc_mm_counter(mm, file_rss);
76507+ set_pte_at(mm, address_m, pte_m, entry_m);
76508+ update_mmu_cache(vma_m, address_m, entry_m);
76509+out:
76510+ if (ptl != ptl_m)
76511+ spin_unlock(ptl_m);
76512+ pte_unmap_nested(pte_m);
76513+}
76514+
76515+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
76516+{
76517+ struct mm_struct *mm = vma->vm_mm;
76518+ unsigned long address_m;
76519+ spinlock_t *ptl_m;
76520+ struct vm_area_struct *vma_m;
76521+ pmd_t *pmd_m;
76522+ pte_t *pte_m, entry_m;
76523+
76524+ vma_m = pax_find_mirror_vma(vma);
76525+ if (!vma_m)
76526+ return;
76527+
76528+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
76529+ address_m = address + SEGMEXEC_TASK_SIZE;
76530+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
76531+ pte_m = pte_offset_map_nested(pmd_m, address_m);
76532+ ptl_m = pte_lockptr(mm, pmd_m);
76533+ if (ptl != ptl_m) {
76534+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
76535+ if (!pte_none(*pte_m))
76536+ goto out;
76537+ }
76538+
76539+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
76540+ set_pte_at(mm, address_m, pte_m, entry_m);
76541+out:
76542+ if (ptl != ptl_m)
76543+ spin_unlock(ptl_m);
76544+ pte_unmap_nested(pte_m);
76545+}
76546+
76547+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
76548+{
76549+ struct page *page_m;
76550+ pte_t entry;
76551+
76552+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
76553+ goto out;
76554+
76555+ entry = *pte;
76556+ page_m = vm_normal_page(vma, address, entry);
76557+ if (!page_m)
76558+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
76559+ else if (PageAnon(page_m)) {
76560+ if (pax_find_mirror_vma(vma)) {
76561+ pte_unmap_unlock(pte, ptl);
76562+ lock_page(page_m);
76563+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
76564+ if (pte_same(entry, *pte))
76565+ pax_mirror_anon_pte(vma, address, page_m, ptl);
76566+ else
76567+ unlock_page(page_m);
76568+ }
76569+ } else
76570+ pax_mirror_file_pte(vma, address, page_m, ptl);
76571+
76572+out:
76573+ pte_unmap_unlock(pte, ptl);
76574+}
76575+#endif
76576+
76577 /*
76578 * This routine handles present pages, when users try to write
76579 * to a shared page. It is done by copying the page to a new address
76580@@ -2156,6 +2360,12 @@ gotten:
76581 */
76582 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76583 if (likely(pte_same(*page_table, orig_pte))) {
76584+
76585+#ifdef CONFIG_PAX_SEGMEXEC
76586+ if (pax_find_mirror_vma(vma))
76587+ BUG_ON(!trylock_page(new_page));
76588+#endif
76589+
76590 if (old_page) {
76591 if (!PageAnon(old_page)) {
76592 dec_mm_counter(mm, file_rss);
76593@@ -2207,6 +2417,10 @@ gotten:
76594 page_remove_rmap(old_page);
76595 }
76596
76597+#ifdef CONFIG_PAX_SEGMEXEC
76598+ pax_mirror_anon_pte(vma, address, new_page, ptl);
76599+#endif
76600+
76601 /* Free the old page.. */
76602 new_page = old_page;
76603 ret |= VM_FAULT_WRITE;
76604@@ -2606,6 +2820,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76605 swap_free(entry);
76606 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
76607 try_to_free_swap(page);
76608+
76609+#ifdef CONFIG_PAX_SEGMEXEC
76610+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
76611+#endif
76612+
76613 unlock_page(page);
76614
76615 if (flags & FAULT_FLAG_WRITE) {
76616@@ -2617,6 +2836,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76617
76618 /* No need to invalidate - it was non-present before */
76619 update_mmu_cache(vma, address, pte);
76620+
76621+#ifdef CONFIG_PAX_SEGMEXEC
76622+ pax_mirror_anon_pte(vma, address, page, ptl);
76623+#endif
76624+
76625 unlock:
76626 pte_unmap_unlock(page_table, ptl);
76627 out:
76628@@ -2632,40 +2856,6 @@ out_release:
76629 }
76630
76631 /*
76632- * This is like a special single-page "expand_{down|up}wards()",
76633- * except we must first make sure that 'address{-|+}PAGE_SIZE'
76634- * doesn't hit another vma.
76635- */
76636-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
76637-{
76638- address &= PAGE_MASK;
76639- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
76640- struct vm_area_struct *prev = vma->vm_prev;
76641-
76642- /*
76643- * Is there a mapping abutting this one below?
76644- *
76645- * That's only ok if it's the same stack mapping
76646- * that has gotten split..
76647- */
76648- if (prev && prev->vm_end == address)
76649- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
76650-
76651- expand_stack(vma, address - PAGE_SIZE);
76652- }
76653- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
76654- struct vm_area_struct *next = vma->vm_next;
76655-
76656- /* As VM_GROWSDOWN but s/below/above/ */
76657- if (next && next->vm_start == address + PAGE_SIZE)
76658- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
76659-
76660- expand_upwards(vma, address + PAGE_SIZE);
76661- }
76662- return 0;
76663-}
76664-
76665-/*
76666 * We enter with non-exclusive mmap_sem (to exclude vma changes,
76667 * but allow concurrent faults), and pte mapped but not yet locked.
76668 * We return with mmap_sem still held, but pte unmapped and unlocked.
76669@@ -2674,27 +2864,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76670 unsigned long address, pte_t *page_table, pmd_t *pmd,
76671 unsigned int flags)
76672 {
76673- struct page *page;
76674+ struct page *page = NULL;
76675 spinlock_t *ptl;
76676 pte_t entry;
76677
76678- pte_unmap(page_table);
76679-
76680- /* Check if we need to add a guard page to the stack */
76681- if (check_stack_guard_page(vma, address) < 0)
76682- return VM_FAULT_SIGBUS;
76683-
76684- /* Use the zero-page for reads */
76685 if (!(flags & FAULT_FLAG_WRITE)) {
76686 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
76687 vma->vm_page_prot));
76688- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76689+ ptl = pte_lockptr(mm, pmd);
76690+ spin_lock(ptl);
76691 if (!pte_none(*page_table))
76692 goto unlock;
76693 goto setpte;
76694 }
76695
76696 /* Allocate our own private page. */
76697+ pte_unmap(page_table);
76698+
76699 if (unlikely(anon_vma_prepare(vma)))
76700 goto oom;
76701 page = alloc_zeroed_user_highpage_movable(vma, address);
76702@@ -2713,6 +2899,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76703 if (!pte_none(*page_table))
76704 goto release;
76705
76706+#ifdef CONFIG_PAX_SEGMEXEC
76707+ if (pax_find_mirror_vma(vma))
76708+ BUG_ON(!trylock_page(page));
76709+#endif
76710+
76711 inc_mm_counter(mm, anon_rss);
76712 page_add_new_anon_rmap(page, vma, address);
76713 setpte:
76714@@ -2720,6 +2911,12 @@ setpte:
76715
76716 /* No need to invalidate - it was non-present before */
76717 update_mmu_cache(vma, address, entry);
76718+
76719+#ifdef CONFIG_PAX_SEGMEXEC
76720+ if (page)
76721+ pax_mirror_anon_pte(vma, address, page, ptl);
76722+#endif
76723+
76724 unlock:
76725 pte_unmap_unlock(page_table, ptl);
76726 return 0;
76727@@ -2862,6 +3059,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76728 */
76729 /* Only go through if we didn't race with anybody else... */
76730 if (likely(pte_same(*page_table, orig_pte))) {
76731+
76732+#ifdef CONFIG_PAX_SEGMEXEC
76733+ if (anon && pax_find_mirror_vma(vma))
76734+ BUG_ON(!trylock_page(page));
76735+#endif
76736+
76737 flush_icache_page(vma, page);
76738 entry = mk_pte(page, vma->vm_page_prot);
76739 if (flags & FAULT_FLAG_WRITE)
76740@@ -2881,6 +3084,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76741
76742 /* no need to invalidate: a not-present page won't be cached */
76743 update_mmu_cache(vma, address, entry);
76744+
76745+#ifdef CONFIG_PAX_SEGMEXEC
76746+ if (anon)
76747+ pax_mirror_anon_pte(vma, address, page, ptl);
76748+ else
76749+ pax_mirror_file_pte(vma, address, page, ptl);
76750+#endif
76751+
76752 } else {
76753 if (charged)
76754 mem_cgroup_uncharge_page(page);
76755@@ -3028,6 +3239,12 @@ static inline int handle_pte_fault(struct mm_struct *mm,
76756 if (flags & FAULT_FLAG_WRITE)
76757 flush_tlb_page(vma, address);
76758 }
76759+
76760+#ifdef CONFIG_PAX_SEGMEXEC
76761+ pax_mirror_pte(vma, address, pte, pmd, ptl);
76762+ return 0;
76763+#endif
76764+
76765 unlock:
76766 pte_unmap_unlock(pte, ptl);
76767 return 0;
76768@@ -3044,6 +3261,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76769 pmd_t *pmd;
76770 pte_t *pte;
76771
76772+#ifdef CONFIG_PAX_SEGMEXEC
76773+ struct vm_area_struct *vma_m;
76774+#endif
76775+
76776 __set_current_state(TASK_RUNNING);
76777
76778 count_vm_event(PGFAULT);
76779@@ -3051,6 +3272,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76780 if (unlikely(is_vm_hugetlb_page(vma)))
76781 return hugetlb_fault(mm, vma, address, flags);
76782
76783+#ifdef CONFIG_PAX_SEGMEXEC
76784+ vma_m = pax_find_mirror_vma(vma);
76785+ if (vma_m) {
76786+ unsigned long address_m;
76787+ pgd_t *pgd_m;
76788+ pud_t *pud_m;
76789+ pmd_t *pmd_m;
76790+
76791+ if (vma->vm_start > vma_m->vm_start) {
76792+ address_m = address;
76793+ address -= SEGMEXEC_TASK_SIZE;
76794+ vma = vma_m;
76795+ } else
76796+ address_m = address + SEGMEXEC_TASK_SIZE;
76797+
76798+ pgd_m = pgd_offset(mm, address_m);
76799+ pud_m = pud_alloc(mm, pgd_m, address_m);
76800+ if (!pud_m)
76801+ return VM_FAULT_OOM;
76802+ pmd_m = pmd_alloc(mm, pud_m, address_m);
76803+ if (!pmd_m)
76804+ return VM_FAULT_OOM;
76805+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
76806+ return VM_FAULT_OOM;
76807+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76808+ }
76809+#endif
76810+
76811 pgd = pgd_offset(mm, address);
76812 pud = pud_alloc(mm, pgd, address);
76813 if (!pud)
76814@@ -3148,7 +3397,7 @@ static int __init gate_vma_init(void)
76815 gate_vma.vm_start = FIXADDR_USER_START;
76816 gate_vma.vm_end = FIXADDR_USER_END;
76817 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76818- gate_vma.vm_page_prot = __P101;
76819+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76820 /*
76821 * Make sure the vDSO gets into every core dump.
76822 * Dumping its contents makes post-mortem fully interpretable later
76823diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76824index 3c6e3e2..ad9871c 100644
76825--- a/mm/mempolicy.c
76826+++ b/mm/mempolicy.c
76827@@ -573,6 +573,10 @@ static int mbind_range(struct vm_area_struct *vma, unsigned long start,
76828 struct vm_area_struct *next;
76829 int err;
76830
76831+#ifdef CONFIG_PAX_SEGMEXEC
76832+ struct vm_area_struct *vma_m;
76833+#endif
76834+
76835 err = 0;
76836 for (; vma && vma->vm_start < end; vma = next) {
76837 next = vma->vm_next;
76838@@ -584,6 +588,16 @@ static int mbind_range(struct vm_area_struct *vma, unsigned long start,
76839 err = policy_vma(vma, new);
76840 if (err)
76841 break;
76842+
76843+#ifdef CONFIG_PAX_SEGMEXEC
76844+ vma_m = pax_find_mirror_vma(vma);
76845+ if (vma_m) {
76846+ err = policy_vma(vma_m, new);
76847+ if (err)
76848+ break;
76849+ }
76850+#endif
76851+
76852 }
76853 return err;
76854 }
76855@@ -1002,6 +1016,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76856
76857 if (end < start)
76858 return -EINVAL;
76859+
76860+#ifdef CONFIG_PAX_SEGMEXEC
76861+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76862+ if (end > SEGMEXEC_TASK_SIZE)
76863+ return -EINVAL;
76864+ } else
76865+#endif
76866+
76867+ if (end > TASK_SIZE)
76868+ return -EINVAL;
76869+
76870 if (end == start)
76871 return 0;
76872
76873@@ -1207,6 +1232,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76874 if (!mm)
76875 return -EINVAL;
76876
76877+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76878+ if (mm != current->mm &&
76879+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76880+ err = -EPERM;
76881+ goto out;
76882+ }
76883+#endif
76884+
76885 /*
76886 * Check if this process has the right to modify the specified
76887 * process. The right exists if the process has administrative
76888@@ -1216,8 +1249,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76889 rcu_read_lock();
76890 tcred = __task_cred(task);
76891 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
76892- cred->uid != tcred->suid && cred->uid != tcred->uid &&
76893- !capable(CAP_SYS_NICE)) {
76894+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
76895 rcu_read_unlock();
76896 err = -EPERM;
76897 goto out;
76898@@ -2396,7 +2428,7 @@ int show_numa_map(struct seq_file *m, void *v)
76899
76900 if (file) {
76901 seq_printf(m, " file=");
76902- seq_path(m, &file->f_path, "\n\t= ");
76903+ seq_path(m, &file->f_path, "\n\t\\= ");
76904 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
76905 seq_printf(m, " heap");
76906 } else if (vma->vm_start <= mm->start_stack &&
76907diff --git a/mm/migrate.c b/mm/migrate.c
76908index aaca868..2ebecdc 100644
76909--- a/mm/migrate.c
76910+++ b/mm/migrate.c
76911@@ -916,6 +916,8 @@ static int do_pages_move(struct mm_struct *mm, struct task_struct *task,
76912 unsigned long chunk_start;
76913 int err;
76914
76915+ pax_track_stack();
76916+
76917 task_nodes = cpuset_mems_allowed(task);
76918
76919 err = -ENOMEM;
76920@@ -1106,6 +1108,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76921 if (!mm)
76922 return -EINVAL;
76923
76924+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76925+ if (mm != current->mm &&
76926+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76927+ err = -EPERM;
76928+ goto out;
76929+ }
76930+#endif
76931+
76932 /*
76933 * Check if this process has the right to modify the specified
76934 * process. The right exists if the process has administrative
76935@@ -1115,8 +1125,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76936 rcu_read_lock();
76937 tcred = __task_cred(task);
76938 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
76939- cred->uid != tcred->suid && cred->uid != tcred->uid &&
76940- !capable(CAP_SYS_NICE)) {
76941+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
76942 rcu_read_unlock();
76943 err = -EPERM;
76944 goto out;
76945diff --git a/mm/mlock.c b/mm/mlock.c
76946index 2d846cf..98134d2 100644
76947--- a/mm/mlock.c
76948+++ b/mm/mlock.c
76949@@ -13,6 +13,7 @@
76950 #include <linux/pagemap.h>
76951 #include <linux/mempolicy.h>
76952 #include <linux/syscalls.h>
76953+#include <linux/security.h>
76954 #include <linux/sched.h>
76955 #include <linux/module.h>
76956 #include <linux/rmap.h>
76957@@ -138,13 +139,6 @@ void munlock_vma_page(struct page *page)
76958 }
76959 }
76960
76961-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
76962-{
76963- return (vma->vm_flags & VM_GROWSDOWN) &&
76964- (vma->vm_start == addr) &&
76965- !vma_stack_continue(vma->vm_prev, addr);
76966-}
76967-
76968 /**
76969 * __mlock_vma_pages_range() - mlock a range of pages in the vma.
76970 * @vma: target vma
76971@@ -177,12 +171,6 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
76972 if (vma->vm_flags & VM_WRITE)
76973 gup_flags |= FOLL_WRITE;
76974
76975- /* We don't try to access the guard page of a stack vma */
76976- if (stack_guard_page(vma, start)) {
76977- addr += PAGE_SIZE;
76978- nr_pages--;
76979- }
76980-
76981 while (nr_pages > 0) {
76982 int i;
76983
76984@@ -440,7 +428,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76985 {
76986 unsigned long nstart, end, tmp;
76987 struct vm_area_struct * vma, * prev;
76988- int error;
76989+ int error = -EINVAL;
76990
76991 len = PAGE_ALIGN(len);
76992 end = start + len;
76993@@ -448,6 +436,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76994 return -EINVAL;
76995 if (end == start)
76996 return 0;
76997+ if (end > TASK_SIZE)
76998+ return -EINVAL;
76999+
77000 vma = find_vma_prev(current->mm, start, &prev);
77001 if (!vma || vma->vm_start > start)
77002 return -ENOMEM;
77003@@ -458,6 +449,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
77004 for (nstart = start ; ; ) {
77005 unsigned int newflags;
77006
77007+#ifdef CONFIG_PAX_SEGMEXEC
77008+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
77009+ break;
77010+#endif
77011+
77012 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
77013
77014 newflags = vma->vm_flags | VM_LOCKED;
77015@@ -507,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
77016 lock_limit >>= PAGE_SHIFT;
77017
77018 /* check against resource limits */
77019+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
77020 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
77021 error = do_mlock(start, len, 1);
77022 up_write(&current->mm->mmap_sem);
77023@@ -528,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
77024 static int do_mlockall(int flags)
77025 {
77026 struct vm_area_struct * vma, * prev = NULL;
77027- unsigned int def_flags = 0;
77028
77029 if (flags & MCL_FUTURE)
77030- def_flags = VM_LOCKED;
77031- current->mm->def_flags = def_flags;
77032+ current->mm->def_flags |= VM_LOCKED;
77033+ else
77034+ current->mm->def_flags &= ~VM_LOCKED;
77035 if (flags == MCL_FUTURE)
77036 goto out;
77037
77038 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
77039- unsigned int newflags;
77040+ unsigned long newflags;
77041
77042+#ifdef CONFIG_PAX_SEGMEXEC
77043+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
77044+ break;
77045+#endif
77046+
77047+ BUG_ON(vma->vm_end > TASK_SIZE);
77048 newflags = vma->vm_flags | VM_LOCKED;
77049 if (!(flags & MCL_CURRENT))
77050 newflags &= ~VM_LOCKED;
77051@@ -570,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
77052 lock_limit >>= PAGE_SHIFT;
77053
77054 ret = -ENOMEM;
77055+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
77056 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
77057 capable(CAP_IPC_LOCK))
77058 ret = do_mlockall(flags);
77059diff --git a/mm/mmap.c b/mm/mmap.c
77060index 4b80cbf..c5ce1df 100644
77061--- a/mm/mmap.c
77062+++ b/mm/mmap.c
77063@@ -45,6 +45,16 @@
77064 #define arch_rebalance_pgtables(addr, len) (addr)
77065 #endif
77066
77067+static inline void verify_mm_writelocked(struct mm_struct *mm)
77068+{
77069+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
77070+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77071+ up_read(&mm->mmap_sem);
77072+ BUG();
77073+ }
77074+#endif
77075+}
77076+
77077 static void unmap_region(struct mm_struct *mm,
77078 struct vm_area_struct *vma, struct vm_area_struct *prev,
77079 unsigned long start, unsigned long end);
77080@@ -70,22 +80,32 @@ static void unmap_region(struct mm_struct *mm,
77081 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
77082 *
77083 */
77084-pgprot_t protection_map[16] = {
77085+pgprot_t protection_map[16] __read_only = {
77086 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
77087 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
77088 };
77089
77090 pgprot_t vm_get_page_prot(unsigned long vm_flags)
77091 {
77092- return __pgprot(pgprot_val(protection_map[vm_flags &
77093+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
77094 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
77095 pgprot_val(arch_vm_get_page_prot(vm_flags)));
77096+
77097+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
77098+ if (!nx_enabled &&
77099+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
77100+ (vm_flags & (VM_READ | VM_WRITE)))
77101+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
77102+#endif
77103+
77104+ return prot;
77105 }
77106 EXPORT_SYMBOL(vm_get_page_prot);
77107
77108 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
77109 int sysctl_overcommit_ratio = 50; /* default is 50% */
77110 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
77111+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
77112 struct percpu_counter vm_committed_as;
77113
77114 /*
77115@@ -231,6 +251,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
77116 struct vm_area_struct *next = vma->vm_next;
77117
77118 might_sleep();
77119+ BUG_ON(vma->vm_mirror);
77120 if (vma->vm_ops && vma->vm_ops->close)
77121 vma->vm_ops->close(vma);
77122 if (vma->vm_file) {
77123@@ -267,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
77124 * not page aligned -Ram Gupta
77125 */
77126 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
77127+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
77128 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
77129 (mm->end_data - mm->start_data) > rlim)
77130 goto out;
77131@@ -704,6 +726,12 @@ static int
77132 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
77133 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
77134 {
77135+
77136+#ifdef CONFIG_PAX_SEGMEXEC
77137+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
77138+ return 0;
77139+#endif
77140+
77141 if (is_mergeable_vma(vma, file, vm_flags) &&
77142 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
77143 if (vma->vm_pgoff == vm_pgoff)
77144@@ -723,6 +751,12 @@ static int
77145 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
77146 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
77147 {
77148+
77149+#ifdef CONFIG_PAX_SEGMEXEC
77150+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
77151+ return 0;
77152+#endif
77153+
77154 if (is_mergeable_vma(vma, file, vm_flags) &&
77155 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
77156 pgoff_t vm_pglen;
77157@@ -765,12 +799,19 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
77158 struct vm_area_struct *vma_merge(struct mm_struct *mm,
77159 struct vm_area_struct *prev, unsigned long addr,
77160 unsigned long end, unsigned long vm_flags,
77161- struct anon_vma *anon_vma, struct file *file,
77162+ struct anon_vma *anon_vma, struct file *file,
77163 pgoff_t pgoff, struct mempolicy *policy)
77164 {
77165 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
77166 struct vm_area_struct *area, *next;
77167
77168+#ifdef CONFIG_PAX_SEGMEXEC
77169+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
77170+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
77171+
77172+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
77173+#endif
77174+
77175 /*
77176 * We later require that vma->vm_flags == vm_flags,
77177 * so this tests vma->vm_flags & VM_SPECIAL, too.
77178@@ -786,6 +827,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
77179 if (next && next->vm_end == end) /* cases 6, 7, 8 */
77180 next = next->vm_next;
77181
77182+#ifdef CONFIG_PAX_SEGMEXEC
77183+ if (prev)
77184+ prev_m = pax_find_mirror_vma(prev);
77185+ if (area)
77186+ area_m = pax_find_mirror_vma(area);
77187+ if (next)
77188+ next_m = pax_find_mirror_vma(next);
77189+#endif
77190+
77191 /*
77192 * Can it merge with the predecessor?
77193 */
77194@@ -805,9 +855,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
77195 /* cases 1, 6 */
77196 vma_adjust(prev, prev->vm_start,
77197 next->vm_end, prev->vm_pgoff, NULL);
77198- } else /* cases 2, 5, 7 */
77199+
77200+#ifdef CONFIG_PAX_SEGMEXEC
77201+ if (prev_m)
77202+ vma_adjust(prev_m, prev_m->vm_start,
77203+ next_m->vm_end, prev_m->vm_pgoff, NULL);
77204+#endif
77205+
77206+ } else { /* cases 2, 5, 7 */
77207 vma_adjust(prev, prev->vm_start,
77208 end, prev->vm_pgoff, NULL);
77209+
77210+#ifdef CONFIG_PAX_SEGMEXEC
77211+ if (prev_m)
77212+ vma_adjust(prev_m, prev_m->vm_start,
77213+ end_m, prev_m->vm_pgoff, NULL);
77214+#endif
77215+
77216+ }
77217 return prev;
77218 }
77219
77220@@ -818,12 +883,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
77221 mpol_equal(policy, vma_policy(next)) &&
77222 can_vma_merge_before(next, vm_flags,
77223 anon_vma, file, pgoff+pglen)) {
77224- if (prev && addr < prev->vm_end) /* case 4 */
77225+ if (prev && addr < prev->vm_end) { /* case 4 */
77226 vma_adjust(prev, prev->vm_start,
77227 addr, prev->vm_pgoff, NULL);
77228- else /* cases 3, 8 */
77229+
77230+#ifdef CONFIG_PAX_SEGMEXEC
77231+ if (prev_m)
77232+ vma_adjust(prev_m, prev_m->vm_start,
77233+ addr_m, prev_m->vm_pgoff, NULL);
77234+#endif
77235+
77236+ } else { /* cases 3, 8 */
77237 vma_adjust(area, addr, next->vm_end,
77238 next->vm_pgoff - pglen, NULL);
77239+
77240+#ifdef CONFIG_PAX_SEGMEXEC
77241+ if (area_m)
77242+ vma_adjust(area_m, addr_m, next_m->vm_end,
77243+ next_m->vm_pgoff - pglen, NULL);
77244+#endif
77245+
77246+ }
77247 return area;
77248 }
77249
77250@@ -898,14 +978,11 @@ none:
77251 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
77252 struct file *file, long pages)
77253 {
77254- const unsigned long stack_flags
77255- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
77256-
77257 if (file) {
77258 mm->shared_vm += pages;
77259 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
77260 mm->exec_vm += pages;
77261- } else if (flags & stack_flags)
77262+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
77263 mm->stack_vm += pages;
77264 if (flags & (VM_RESERVED|VM_IO))
77265 mm->reserved_vm += pages;
77266@@ -932,7 +1009,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77267 * (the exception is when the underlying filesystem is noexec
77268 * mounted, in which case we dont add PROT_EXEC.)
77269 */
77270- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
77271+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
77272 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
77273 prot |= PROT_EXEC;
77274
77275@@ -958,7 +1035,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77276 /* Obtain the address to map to. we verify (or select) it and ensure
77277 * that it represents a valid section of the address space.
77278 */
77279- addr = get_unmapped_area(file, addr, len, pgoff, flags);
77280+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
77281 if (addr & ~PAGE_MASK)
77282 return addr;
77283
77284@@ -969,6 +1046,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77285 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
77286 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
77287
77288+#ifdef CONFIG_PAX_MPROTECT
77289+ if (mm->pax_flags & MF_PAX_MPROTECT) {
77290+#ifndef CONFIG_PAX_MPROTECT_COMPAT
77291+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
77292+ gr_log_rwxmmap(file);
77293+
77294+#ifdef CONFIG_PAX_EMUPLT
77295+ vm_flags &= ~VM_EXEC;
77296+#else
77297+ return -EPERM;
77298+#endif
77299+
77300+ }
77301+
77302+ if (!(vm_flags & VM_EXEC))
77303+ vm_flags &= ~VM_MAYEXEC;
77304+#else
77305+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77306+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77307+#endif
77308+ else
77309+ vm_flags &= ~VM_MAYWRITE;
77310+ }
77311+#endif
77312+
77313+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
77314+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
77315+ vm_flags &= ~VM_PAGEEXEC;
77316+#endif
77317+
77318 if (flags & MAP_LOCKED)
77319 if (!can_do_mlock())
77320 return -EPERM;
77321@@ -980,6 +1087,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77322 locked += mm->locked_vm;
77323 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
77324 lock_limit >>= PAGE_SHIFT;
77325+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
77326 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
77327 return -EAGAIN;
77328 }
77329@@ -1053,6 +1161,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77330 if (error)
77331 return error;
77332
77333+ if (!gr_acl_handle_mmap(file, prot))
77334+ return -EACCES;
77335+
77336 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
77337 }
77338 EXPORT_SYMBOL(do_mmap_pgoff);
77339@@ -1065,10 +1176,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
77340 */
77341 int vma_wants_writenotify(struct vm_area_struct *vma)
77342 {
77343- unsigned int vm_flags = vma->vm_flags;
77344+ unsigned long vm_flags = vma->vm_flags;
77345
77346 /* If it was private or non-writable, the write bit is already clear */
77347- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
77348+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
77349 return 0;
77350
77351 /* The backer wishes to know when pages are first written to? */
77352@@ -1117,14 +1228,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
77353 unsigned long charged = 0;
77354 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
77355
77356+#ifdef CONFIG_PAX_SEGMEXEC
77357+ struct vm_area_struct *vma_m = NULL;
77358+#endif
77359+
77360+ /*
77361+ * mm->mmap_sem is required to protect against another thread
77362+ * changing the mappings in case we sleep.
77363+ */
77364+ verify_mm_writelocked(mm);
77365+
77366 /* Clear old maps */
77367 error = -ENOMEM;
77368-munmap_back:
77369 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77370 if (vma && vma->vm_start < addr + len) {
77371 if (do_munmap(mm, addr, len))
77372 return -ENOMEM;
77373- goto munmap_back;
77374+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77375+ BUG_ON(vma && vma->vm_start < addr + len);
77376 }
77377
77378 /* Check against address space limit. */
77379@@ -1173,6 +1294,16 @@ munmap_back:
77380 goto unacct_error;
77381 }
77382
77383+#ifdef CONFIG_PAX_SEGMEXEC
77384+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
77385+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77386+ if (!vma_m) {
77387+ error = -ENOMEM;
77388+ goto free_vma;
77389+ }
77390+ }
77391+#endif
77392+
77393 vma->vm_mm = mm;
77394 vma->vm_start = addr;
77395 vma->vm_end = addr + len;
77396@@ -1195,6 +1326,19 @@ munmap_back:
77397 error = file->f_op->mmap(file, vma);
77398 if (error)
77399 goto unmap_and_free_vma;
77400+
77401+#ifdef CONFIG_PAX_SEGMEXEC
77402+ if (vma_m && (vm_flags & VM_EXECUTABLE))
77403+ added_exe_file_vma(mm);
77404+#endif
77405+
77406+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
77407+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
77408+ vma->vm_flags |= VM_PAGEEXEC;
77409+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77410+ }
77411+#endif
77412+
77413 if (vm_flags & VM_EXECUTABLE)
77414 added_exe_file_vma(mm);
77415
77416@@ -1218,6 +1362,11 @@ munmap_back:
77417 vma_link(mm, vma, prev, rb_link, rb_parent);
77418 file = vma->vm_file;
77419
77420+#ifdef CONFIG_PAX_SEGMEXEC
77421+ if (vma_m)
77422+ pax_mirror_vma(vma_m, vma);
77423+#endif
77424+
77425 /* Once vma denies write, undo our temporary denial count */
77426 if (correct_wcount)
77427 atomic_inc(&inode->i_writecount);
77428@@ -1226,6 +1375,7 @@ out:
77429
77430 mm->total_vm += len >> PAGE_SHIFT;
77431 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
77432+ track_exec_limit(mm, addr, addr + len, vm_flags);
77433 if (vm_flags & VM_LOCKED) {
77434 /*
77435 * makes pages present; downgrades, drops, reacquires mmap_sem
77436@@ -1248,6 +1398,12 @@ unmap_and_free_vma:
77437 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
77438 charged = 0;
77439 free_vma:
77440+
77441+#ifdef CONFIG_PAX_SEGMEXEC
77442+ if (vma_m)
77443+ kmem_cache_free(vm_area_cachep, vma_m);
77444+#endif
77445+
77446 kmem_cache_free(vm_area_cachep, vma);
77447 unacct_error:
77448 if (charged)
77449@@ -1255,6 +1411,44 @@ unacct_error:
77450 return error;
77451 }
77452
77453+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
77454+{
77455+ if (!vma) {
77456+#ifdef CONFIG_STACK_GROWSUP
77457+ if (addr > sysctl_heap_stack_gap)
77458+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
77459+ else
77460+ vma = find_vma(current->mm, 0);
77461+ if (vma && (vma->vm_flags & VM_GROWSUP))
77462+ return false;
77463+#endif
77464+ return true;
77465+ }
77466+
77467+ if (addr + len > vma->vm_start)
77468+ return false;
77469+
77470+ if (vma->vm_flags & VM_GROWSDOWN)
77471+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
77472+#ifdef CONFIG_STACK_GROWSUP
77473+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
77474+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
77475+#endif
77476+
77477+ return true;
77478+}
77479+
77480+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
77481+{
77482+ if (vma->vm_start < len)
77483+ return -ENOMEM;
77484+ if (!(vma->vm_flags & VM_GROWSDOWN))
77485+ return vma->vm_start - len;
77486+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
77487+ return vma->vm_start - len - sysctl_heap_stack_gap;
77488+ return -ENOMEM;
77489+}
77490+
77491 /* Get an address range which is currently unmapped.
77492 * For shmat() with addr=0.
77493 *
77494@@ -1281,18 +1475,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
77495 if (flags & MAP_FIXED)
77496 return addr;
77497
77498+#ifdef CONFIG_PAX_RANDMMAP
77499+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
77500+#endif
77501+
77502 if (addr) {
77503 addr = PAGE_ALIGN(addr);
77504- vma = find_vma(mm, addr);
77505- if (TASK_SIZE - len >= addr &&
77506- (!vma || addr + len <= vma->vm_start))
77507- return addr;
77508+ if (TASK_SIZE - len >= addr) {
77509+ vma = find_vma(mm, addr);
77510+ if (check_heap_stack_gap(vma, addr, len))
77511+ return addr;
77512+ }
77513 }
77514 if (len > mm->cached_hole_size) {
77515- start_addr = addr = mm->free_area_cache;
77516+ start_addr = addr = mm->free_area_cache;
77517 } else {
77518- start_addr = addr = TASK_UNMAPPED_BASE;
77519- mm->cached_hole_size = 0;
77520+ start_addr = addr = mm->mmap_base;
77521+ mm->cached_hole_size = 0;
77522 }
77523
77524 full_search:
77525@@ -1303,34 +1502,40 @@ full_search:
77526 * Start a new search - just in case we missed
77527 * some holes.
77528 */
77529- if (start_addr != TASK_UNMAPPED_BASE) {
77530- addr = TASK_UNMAPPED_BASE;
77531- start_addr = addr;
77532+ if (start_addr != mm->mmap_base) {
77533+ start_addr = addr = mm->mmap_base;
77534 mm->cached_hole_size = 0;
77535 goto full_search;
77536 }
77537 return -ENOMEM;
77538 }
77539- if (!vma || addr + len <= vma->vm_start) {
77540- /*
77541- * Remember the place where we stopped the search:
77542- */
77543- mm->free_area_cache = addr + len;
77544- return addr;
77545- }
77546+ if (check_heap_stack_gap(vma, addr, len))
77547+ break;
77548 if (addr + mm->cached_hole_size < vma->vm_start)
77549 mm->cached_hole_size = vma->vm_start - addr;
77550 addr = vma->vm_end;
77551 }
77552+
77553+ /*
77554+ * Remember the place where we stopped the search:
77555+ */
77556+ mm->free_area_cache = addr + len;
77557+ return addr;
77558 }
77559 #endif
77560
77561 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
77562 {
77563+
77564+#ifdef CONFIG_PAX_SEGMEXEC
77565+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77566+ return;
77567+#endif
77568+
77569 /*
77570 * Is this a new hole at the lowest possible address?
77571 */
77572- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
77573+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
77574 mm->free_area_cache = addr;
77575 mm->cached_hole_size = ~0UL;
77576 }
77577@@ -1348,7 +1553,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77578 {
77579 struct vm_area_struct *vma;
77580 struct mm_struct *mm = current->mm;
77581- unsigned long addr = addr0;
77582+ unsigned long base = mm->mmap_base, addr = addr0;
77583
77584 /* requested length too big for entire address space */
77585 if (len > TASK_SIZE)
77586@@ -1357,13 +1562,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77587 if (flags & MAP_FIXED)
77588 return addr;
77589
77590+#ifdef CONFIG_PAX_RANDMMAP
77591+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
77592+#endif
77593+
77594 /* requesting a specific address */
77595 if (addr) {
77596 addr = PAGE_ALIGN(addr);
77597- vma = find_vma(mm, addr);
77598- if (TASK_SIZE - len >= addr &&
77599- (!vma || addr + len <= vma->vm_start))
77600- return addr;
77601+ if (TASK_SIZE - len >= addr) {
77602+ vma = find_vma(mm, addr);
77603+ if (check_heap_stack_gap(vma, addr, len))
77604+ return addr;
77605+ }
77606 }
77607
77608 /* check if free_area_cache is useful for us */
77609@@ -1378,7 +1588,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77610 /* make sure it can fit in the remaining address space */
77611 if (addr > len) {
77612 vma = find_vma(mm, addr-len);
77613- if (!vma || addr <= vma->vm_start)
77614+ if (check_heap_stack_gap(vma, addr - len, len))
77615 /* remember the address as a hint for next time */
77616 return (mm->free_area_cache = addr-len);
77617 }
77618@@ -1395,7 +1605,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77619 * return with success:
77620 */
77621 vma = find_vma(mm, addr);
77622- if (!vma || addr+len <= vma->vm_start)
77623+ if (check_heap_stack_gap(vma, addr, len))
77624 /* remember the address as a hint for next time */
77625 return (mm->free_area_cache = addr);
77626
77627@@ -1404,8 +1614,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77628 mm->cached_hole_size = vma->vm_start - addr;
77629
77630 /* try just below the current vma->vm_start */
77631- addr = vma->vm_start-len;
77632- } while (len < vma->vm_start);
77633+ addr = skip_heap_stack_gap(vma, len);
77634+ } while (!IS_ERR_VALUE(addr));
77635
77636 bottomup:
77637 /*
77638@@ -1414,13 +1624,21 @@ bottomup:
77639 * can happen with large stack limits and large mmap()
77640 * allocations.
77641 */
77642+ mm->mmap_base = TASK_UNMAPPED_BASE;
77643+
77644+#ifdef CONFIG_PAX_RANDMMAP
77645+ if (mm->pax_flags & MF_PAX_RANDMMAP)
77646+ mm->mmap_base += mm->delta_mmap;
77647+#endif
77648+
77649+ mm->free_area_cache = mm->mmap_base;
77650 mm->cached_hole_size = ~0UL;
77651- mm->free_area_cache = TASK_UNMAPPED_BASE;
77652 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
77653 /*
77654 * Restore the topdown base:
77655 */
77656- mm->free_area_cache = mm->mmap_base;
77657+ mm->mmap_base = base;
77658+ mm->free_area_cache = base;
77659 mm->cached_hole_size = ~0UL;
77660
77661 return addr;
77662@@ -1429,6 +1647,12 @@ bottomup:
77663
77664 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77665 {
77666+
77667+#ifdef CONFIG_PAX_SEGMEXEC
77668+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77669+ return;
77670+#endif
77671+
77672 /*
77673 * Is this a new hole at the highest possible address?
77674 */
77675@@ -1436,8 +1660,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77676 mm->free_area_cache = addr;
77677
77678 /* dont allow allocations above current base */
77679- if (mm->free_area_cache > mm->mmap_base)
77680+ if (mm->free_area_cache > mm->mmap_base) {
77681 mm->free_area_cache = mm->mmap_base;
77682+ mm->cached_hole_size = ~0UL;
77683+ }
77684 }
77685
77686 unsigned long
77687@@ -1545,6 +1771,27 @@ out:
77688 return prev ? prev->vm_next : vma;
77689 }
77690
77691+#ifdef CONFIG_PAX_SEGMEXEC
77692+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
77693+{
77694+ struct vm_area_struct *vma_m;
77695+
77696+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
77697+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
77698+ BUG_ON(vma->vm_mirror);
77699+ return NULL;
77700+ }
77701+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
77702+ vma_m = vma->vm_mirror;
77703+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
77704+ BUG_ON(vma->vm_file != vma_m->vm_file);
77705+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
77706+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
77707+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
77708+ return vma_m;
77709+}
77710+#endif
77711+
77712 /*
77713 * Verify that the stack growth is acceptable and
77714 * update accounting. This is shared with both the
77715@@ -1561,6 +1808,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77716 return -ENOMEM;
77717
77718 /* Stack limit test */
77719+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
77720 if (size > rlim[RLIMIT_STACK].rlim_cur)
77721 return -ENOMEM;
77722
77723@@ -1570,6 +1818,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77724 unsigned long limit;
77725 locked = mm->locked_vm + grow;
77726 limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
77727+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
77728 if (locked > limit && !capable(CAP_IPC_LOCK))
77729 return -ENOMEM;
77730 }
77731@@ -1600,37 +1849,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77732 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
77733 * vma is the last one with address > vma->vm_end. Have to extend vma.
77734 */
77735+#ifndef CONFIG_IA64
77736+static
77737+#endif
77738 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77739 {
77740 int error;
77741+ bool locknext;
77742
77743 if (!(vma->vm_flags & VM_GROWSUP))
77744 return -EFAULT;
77745
77746+ /* Also guard against wrapping around to address 0. */
77747+ if (address < PAGE_ALIGN(address+1))
77748+ address = PAGE_ALIGN(address+1);
77749+ else
77750+ return -ENOMEM;
77751+
77752 /*
77753 * We must make sure the anon_vma is allocated
77754 * so that the anon_vma locking is not a noop.
77755 */
77756 if (unlikely(anon_vma_prepare(vma)))
77757 return -ENOMEM;
77758+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
77759+ if (locknext && anon_vma_prepare(vma->vm_next))
77760+ return -ENOMEM;
77761 anon_vma_lock(vma);
77762+ if (locknext)
77763+ anon_vma_lock(vma->vm_next);
77764
77765 /*
77766 * vma->vm_start/vm_end cannot change under us because the caller
77767 * is required to hold the mmap_sem in read mode. We need the
77768- * anon_vma lock to serialize against concurrent expand_stacks.
77769- * Also guard against wrapping around to address 0.
77770+ * anon_vma locks to serialize against concurrent expand_stacks
77771+ * and expand_upwards.
77772 */
77773- if (address < PAGE_ALIGN(address+4))
77774- address = PAGE_ALIGN(address+4);
77775- else {
77776- anon_vma_unlock(vma);
77777- return -ENOMEM;
77778- }
77779 error = 0;
77780
77781 /* Somebody else might have raced and expanded it already */
77782- if (address > vma->vm_end) {
77783+ 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)
77784+ error = -ENOMEM;
77785+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
77786 unsigned long size, grow;
77787
77788 size = address - vma->vm_start;
77789@@ -1643,6 +1903,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77790 vma->vm_end = address;
77791 }
77792 }
77793+ if (locknext)
77794+ anon_vma_unlock(vma->vm_next);
77795 anon_vma_unlock(vma);
77796 return error;
77797 }
77798@@ -1655,6 +1917,8 @@ static int expand_downwards(struct vm_area_struct *vma,
77799 unsigned long address)
77800 {
77801 int error;
77802+ bool lockprev = false;
77803+ struct vm_area_struct *prev;
77804
77805 /*
77806 * We must make sure the anon_vma is allocated
77807@@ -1668,6 +1932,15 @@ static int expand_downwards(struct vm_area_struct *vma,
77808 if (error)
77809 return error;
77810
77811+ prev = vma->vm_prev;
77812+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
77813+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
77814+#endif
77815+ if (lockprev && anon_vma_prepare(prev))
77816+ return -ENOMEM;
77817+ if (lockprev)
77818+ anon_vma_lock(prev);
77819+
77820 anon_vma_lock(vma);
77821
77822 /*
77823@@ -1677,9 +1950,17 @@ static int expand_downwards(struct vm_area_struct *vma,
77824 */
77825
77826 /* Somebody else might have raced and expanded it already */
77827- if (address < vma->vm_start) {
77828+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
77829+ error = -ENOMEM;
77830+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
77831 unsigned long size, grow;
77832
77833+#ifdef CONFIG_PAX_SEGMEXEC
77834+ struct vm_area_struct *vma_m;
77835+
77836+ vma_m = pax_find_mirror_vma(vma);
77837+#endif
77838+
77839 size = vma->vm_end - address;
77840 grow = (vma->vm_start - address) >> PAGE_SHIFT;
77841
77842@@ -1689,10 +1970,22 @@ static int expand_downwards(struct vm_area_struct *vma,
77843 if (!error) {
77844 vma->vm_start = address;
77845 vma->vm_pgoff -= grow;
77846+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
77847+
77848+#ifdef CONFIG_PAX_SEGMEXEC
77849+ if (vma_m) {
77850+ vma_m->vm_start -= grow << PAGE_SHIFT;
77851+ vma_m->vm_pgoff -= grow;
77852+ }
77853+#endif
77854+
77855+
77856 }
77857 }
77858 }
77859 anon_vma_unlock(vma);
77860+ if (lockprev)
77861+ anon_vma_unlock(prev);
77862 return error;
77863 }
77864
77865@@ -1768,6 +2061,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
77866 do {
77867 long nrpages = vma_pages(vma);
77868
77869+#ifdef CONFIG_PAX_SEGMEXEC
77870+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
77871+ vma = remove_vma(vma);
77872+ continue;
77873+ }
77874+#endif
77875+
77876 mm->total_vm -= nrpages;
77877 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77878 vma = remove_vma(vma);
77879@@ -1813,6 +2113,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77880 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77881 vma->vm_prev = NULL;
77882 do {
77883+
77884+#ifdef CONFIG_PAX_SEGMEXEC
77885+ if (vma->vm_mirror) {
77886+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77887+ vma->vm_mirror->vm_mirror = NULL;
77888+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
77889+ vma->vm_mirror = NULL;
77890+ }
77891+#endif
77892+
77893 rb_erase(&vma->vm_rb, &mm->mm_rb);
77894 mm->map_count--;
77895 tail_vma = vma;
77896@@ -1840,10 +2150,25 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77897 struct mempolicy *pol;
77898 struct vm_area_struct *new;
77899
77900+#ifdef CONFIG_PAX_SEGMEXEC
77901+ struct vm_area_struct *vma_m, *new_m = NULL;
77902+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77903+#endif
77904+
77905 if (is_vm_hugetlb_page(vma) && (addr &
77906 ~(huge_page_mask(hstate_vma(vma)))))
77907 return -EINVAL;
77908
77909+#ifdef CONFIG_PAX_SEGMEXEC
77910+ vma_m = pax_find_mirror_vma(vma);
77911+
77912+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77913+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77914+ if (mm->map_count >= sysctl_max_map_count-1)
77915+ return -ENOMEM;
77916+ } else
77917+#endif
77918+
77919 if (mm->map_count >= sysctl_max_map_count)
77920 return -ENOMEM;
77921
77922@@ -1851,6 +2176,16 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77923 if (!new)
77924 return -ENOMEM;
77925
77926+#ifdef CONFIG_PAX_SEGMEXEC
77927+ if (vma_m) {
77928+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77929+ if (!new_m) {
77930+ kmem_cache_free(vm_area_cachep, new);
77931+ return -ENOMEM;
77932+ }
77933+ }
77934+#endif
77935+
77936 /* most fields are the same, copy all, and then fixup */
77937 *new = *vma;
77938
77939@@ -1861,8 +2196,29 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77940 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77941 }
77942
77943+#ifdef CONFIG_PAX_SEGMEXEC
77944+ if (vma_m) {
77945+ *new_m = *vma_m;
77946+ new_m->vm_mirror = new;
77947+ new->vm_mirror = new_m;
77948+
77949+ if (new_below)
77950+ new_m->vm_end = addr_m;
77951+ else {
77952+ new_m->vm_start = addr_m;
77953+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77954+ }
77955+ }
77956+#endif
77957+
77958 pol = mpol_dup(vma_policy(vma));
77959 if (IS_ERR(pol)) {
77960+
77961+#ifdef CONFIG_PAX_SEGMEXEC
77962+ if (new_m)
77963+ kmem_cache_free(vm_area_cachep, new_m);
77964+#endif
77965+
77966 kmem_cache_free(vm_area_cachep, new);
77967 return PTR_ERR(pol);
77968 }
77969@@ -1883,6 +2239,28 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77970 else
77971 vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77972
77973+#ifdef CONFIG_PAX_SEGMEXEC
77974+ if (vma_m) {
77975+ mpol_get(pol);
77976+ vma_set_policy(new_m, pol);
77977+
77978+ if (new_m->vm_file) {
77979+ get_file(new_m->vm_file);
77980+ if (vma_m->vm_flags & VM_EXECUTABLE)
77981+ added_exe_file_vma(mm);
77982+ }
77983+
77984+ if (new_m->vm_ops && new_m->vm_ops->open)
77985+ new_m->vm_ops->open(new_m);
77986+
77987+ if (new_below)
77988+ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77989+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77990+ else
77991+ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77992+ }
77993+#endif
77994+
77995 return 0;
77996 }
77997
77998@@ -1891,11 +2269,30 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77999 * work. This now handles partial unmappings.
78000 * Jeremy Fitzhardinge <jeremy@goop.org>
78001 */
78002+#ifdef CONFIG_PAX_SEGMEXEC
78003 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
78004 {
78005+ int ret = __do_munmap(mm, start, len);
78006+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
78007+ return ret;
78008+
78009+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
78010+}
78011+
78012+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
78013+#else
78014+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
78015+#endif
78016+{
78017 unsigned long end;
78018 struct vm_area_struct *vma, *prev, *last;
78019
78020+ /*
78021+ * mm->mmap_sem is required to protect against another thread
78022+ * changing the mappings in case we sleep.
78023+ */
78024+ verify_mm_writelocked(mm);
78025+
78026 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
78027 return -EINVAL;
78028
78029@@ -1959,6 +2356,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
78030 /* Fix up all other VM information */
78031 remove_vma_list(mm, vma);
78032
78033+ track_exec_limit(mm, start, end, 0UL);
78034+
78035 return 0;
78036 }
78037
78038@@ -1971,22 +2370,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
78039
78040 profile_munmap(addr);
78041
78042+#ifdef CONFIG_PAX_SEGMEXEC
78043+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
78044+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
78045+ return -EINVAL;
78046+#endif
78047+
78048 down_write(&mm->mmap_sem);
78049 ret = do_munmap(mm, addr, len);
78050 up_write(&mm->mmap_sem);
78051 return ret;
78052 }
78053
78054-static inline void verify_mm_writelocked(struct mm_struct *mm)
78055-{
78056-#ifdef CONFIG_DEBUG_VM
78057- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
78058- WARN_ON(1);
78059- up_read(&mm->mmap_sem);
78060- }
78061-#endif
78062-}
78063-
78064 /*
78065 * this is really a simplified "do_mmap". it only handles
78066 * anonymous maps. eventually we may be able to do some
78067@@ -2000,6 +2395,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
78068 struct rb_node ** rb_link, * rb_parent;
78069 pgoff_t pgoff = addr >> PAGE_SHIFT;
78070 int error;
78071+ unsigned long charged;
78072
78073 len = PAGE_ALIGN(len);
78074 if (!len)
78075@@ -2011,16 +2407,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
78076
78077 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
78078
78079+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
78080+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
78081+ flags &= ~VM_EXEC;
78082+
78083+#ifdef CONFIG_PAX_MPROTECT
78084+ if (mm->pax_flags & MF_PAX_MPROTECT)
78085+ flags &= ~VM_MAYEXEC;
78086+#endif
78087+
78088+ }
78089+#endif
78090+
78091 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
78092 if (error & ~PAGE_MASK)
78093 return error;
78094
78095+ charged = len >> PAGE_SHIFT;
78096+
78097 /*
78098 * mlock MCL_FUTURE?
78099 */
78100 if (mm->def_flags & VM_LOCKED) {
78101 unsigned long locked, lock_limit;
78102- locked = len >> PAGE_SHIFT;
78103+ locked = charged;
78104 locked += mm->locked_vm;
78105 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
78106 lock_limit >>= PAGE_SHIFT;
78107@@ -2037,22 +2447,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
78108 /*
78109 * Clear old maps. this also does some error checking for us
78110 */
78111- munmap_back:
78112 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
78113 if (vma && vma->vm_start < addr + len) {
78114 if (do_munmap(mm, addr, len))
78115 return -ENOMEM;
78116- goto munmap_back;
78117+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
78118+ BUG_ON(vma && vma->vm_start < addr + len);
78119 }
78120
78121 /* Check against address space limits *after* clearing old maps... */
78122- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
78123+ if (!may_expand_vm(mm, charged))
78124 return -ENOMEM;
78125
78126 if (mm->map_count > sysctl_max_map_count)
78127 return -ENOMEM;
78128
78129- if (security_vm_enough_memory(len >> PAGE_SHIFT))
78130+ if (security_vm_enough_memory(charged))
78131 return -ENOMEM;
78132
78133 /* Can we just expand an old private anonymous mapping? */
78134@@ -2066,7 +2476,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
78135 */
78136 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
78137 if (!vma) {
78138- vm_unacct_memory(len >> PAGE_SHIFT);
78139+ vm_unacct_memory(charged);
78140 return -ENOMEM;
78141 }
78142
78143@@ -2078,11 +2488,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
78144 vma->vm_page_prot = vm_get_page_prot(flags);
78145 vma_link(mm, vma, prev, rb_link, rb_parent);
78146 out:
78147- mm->total_vm += len >> PAGE_SHIFT;
78148+ mm->total_vm += charged;
78149 if (flags & VM_LOCKED) {
78150 if (!mlock_vma_pages_range(vma, addr, addr + len))
78151- mm->locked_vm += (len >> PAGE_SHIFT);
78152+ mm->locked_vm += charged;
78153 }
78154+ track_exec_limit(mm, addr, addr + len, flags);
78155 return addr;
78156 }
78157
78158@@ -2129,8 +2540,10 @@ void exit_mmap(struct mm_struct *mm)
78159 * Walk the list again, actually closing and freeing it,
78160 * with preemption enabled, without holding any MM locks.
78161 */
78162- while (vma)
78163+ while (vma) {
78164+ vma->vm_mirror = NULL;
78165 vma = remove_vma(vma);
78166+ }
78167
78168 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
78169 }
78170@@ -2144,6 +2557,10 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
78171 struct vm_area_struct * __vma, * prev;
78172 struct rb_node ** rb_link, * rb_parent;
78173
78174+#ifdef CONFIG_PAX_SEGMEXEC
78175+ struct vm_area_struct *vma_m = NULL;
78176+#endif
78177+
78178 /*
78179 * The vm_pgoff of a purely anonymous vma should be irrelevant
78180 * until its first write fault, when page's anon_vma and index
78181@@ -2166,7 +2583,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
78182 if ((vma->vm_flags & VM_ACCOUNT) &&
78183 security_vm_enough_memory_mm(mm, vma_pages(vma)))
78184 return -ENOMEM;
78185+
78186+#ifdef CONFIG_PAX_SEGMEXEC
78187+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
78188+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
78189+ if (!vma_m)
78190+ return -ENOMEM;
78191+ }
78192+#endif
78193+
78194 vma_link(mm, vma, prev, rb_link, rb_parent);
78195+
78196+#ifdef CONFIG_PAX_SEGMEXEC
78197+ if (vma_m)
78198+ pax_mirror_vma(vma_m, vma);
78199+#endif
78200+
78201 return 0;
78202 }
78203
78204@@ -2184,6 +2616,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
78205 struct rb_node **rb_link, *rb_parent;
78206 struct mempolicy *pol;
78207
78208+ BUG_ON(vma->vm_mirror);
78209+
78210 /*
78211 * If anonymous vma has not yet been faulted, update new pgoff
78212 * to match new location, to increase its chance of merging.
78213@@ -2227,6 +2661,35 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
78214 return new_vma;
78215 }
78216
78217+#ifdef CONFIG_PAX_SEGMEXEC
78218+void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
78219+{
78220+ struct vm_area_struct *prev_m;
78221+ struct rb_node **rb_link_m, *rb_parent_m;
78222+ struct mempolicy *pol_m;
78223+
78224+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
78225+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
78226+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
78227+ *vma_m = *vma;
78228+ pol_m = vma_policy(vma_m);
78229+ mpol_get(pol_m);
78230+ vma_set_policy(vma_m, pol_m);
78231+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
78232+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
78233+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
78234+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
78235+ if (vma_m->vm_file)
78236+ get_file(vma_m->vm_file);
78237+ if (vma_m->vm_ops && vma_m->vm_ops->open)
78238+ vma_m->vm_ops->open(vma_m);
78239+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
78240+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
78241+ vma_m->vm_mirror = vma;
78242+ vma->vm_mirror = vma_m;
78243+}
78244+#endif
78245+
78246 /*
78247 * Return true if the calling process may expand its vm space by the passed
78248 * number of pages
78249@@ -2237,7 +2700,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
78250 unsigned long lim;
78251
78252 lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
78253-
78254+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
78255 if (cur + npages > lim)
78256 return 0;
78257 return 1;
78258@@ -2307,6 +2770,22 @@ int install_special_mapping(struct mm_struct *mm,
78259 vma->vm_start = addr;
78260 vma->vm_end = addr + len;
78261
78262+#ifdef CONFIG_PAX_MPROTECT
78263+ if (mm->pax_flags & MF_PAX_MPROTECT) {
78264+#ifndef CONFIG_PAX_MPROTECT_COMPAT
78265+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
78266+ return -EPERM;
78267+ if (!(vm_flags & VM_EXEC))
78268+ vm_flags &= ~VM_MAYEXEC;
78269+#else
78270+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
78271+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
78272+#endif
78273+ else
78274+ vm_flags &= ~VM_MAYWRITE;
78275+ }
78276+#endif
78277+
78278 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
78279 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
78280
78281diff --git a/mm/mprotect.c b/mm/mprotect.c
78282index 1737c7e..c7faeb4 100644
78283--- a/mm/mprotect.c
78284+++ b/mm/mprotect.c
78285@@ -24,10 +24,16 @@
78286 #include <linux/mmu_notifier.h>
78287 #include <linux/migrate.h>
78288 #include <linux/perf_event.h>
78289+
78290+#ifdef CONFIG_PAX_MPROTECT
78291+#include <linux/elf.h>
78292+#endif
78293+
78294 #include <asm/uaccess.h>
78295 #include <asm/pgtable.h>
78296 #include <asm/cacheflush.h>
78297 #include <asm/tlbflush.h>
78298+#include <asm/mmu_context.h>
78299
78300 #ifndef pgprot_modify
78301 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
78302@@ -132,6 +138,48 @@ static void change_protection(struct vm_area_struct *vma,
78303 flush_tlb_range(vma, start, end);
78304 }
78305
78306+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
78307+/* called while holding the mmap semaphor for writing except stack expansion */
78308+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
78309+{
78310+ unsigned long oldlimit, newlimit = 0UL;
78311+
78312+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
78313+ return;
78314+
78315+ spin_lock(&mm->page_table_lock);
78316+ oldlimit = mm->context.user_cs_limit;
78317+ if ((prot & VM_EXEC) && oldlimit < end)
78318+ /* USER_CS limit moved up */
78319+ newlimit = end;
78320+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
78321+ /* USER_CS limit moved down */
78322+ newlimit = start;
78323+
78324+ if (newlimit) {
78325+ mm->context.user_cs_limit = newlimit;
78326+
78327+#ifdef CONFIG_SMP
78328+ wmb();
78329+ cpus_clear(mm->context.cpu_user_cs_mask);
78330+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
78331+#endif
78332+
78333+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
78334+ }
78335+ spin_unlock(&mm->page_table_lock);
78336+ if (newlimit == end) {
78337+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
78338+
78339+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
78340+ if (is_vm_hugetlb_page(vma))
78341+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
78342+ else
78343+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
78344+ }
78345+}
78346+#endif
78347+
78348 int
78349 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
78350 unsigned long start, unsigned long end, unsigned long newflags)
78351@@ -144,11 +192,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
78352 int error;
78353 int dirty_accountable = 0;
78354
78355+#ifdef CONFIG_PAX_SEGMEXEC
78356+ struct vm_area_struct *vma_m = NULL;
78357+ unsigned long start_m, end_m;
78358+
78359+ start_m = start + SEGMEXEC_TASK_SIZE;
78360+ end_m = end + SEGMEXEC_TASK_SIZE;
78361+#endif
78362+
78363 if (newflags == oldflags) {
78364 *pprev = vma;
78365 return 0;
78366 }
78367
78368+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
78369+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
78370+
78371+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
78372+ return -ENOMEM;
78373+
78374+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
78375+ return -ENOMEM;
78376+ }
78377+
78378 /*
78379 * If we make a private mapping writable we increase our commit;
78380 * but (without finer accounting) cannot reduce our commit if we
78381@@ -165,6 +231,38 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
78382 }
78383 }
78384
78385+#ifdef CONFIG_PAX_SEGMEXEC
78386+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
78387+ if (start != vma->vm_start) {
78388+ error = split_vma(mm, vma, start, 1);
78389+ if (error)
78390+ goto fail;
78391+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
78392+ *pprev = (*pprev)->vm_next;
78393+ }
78394+
78395+ if (end != vma->vm_end) {
78396+ error = split_vma(mm, vma, end, 0);
78397+ if (error)
78398+ goto fail;
78399+ }
78400+
78401+ if (pax_find_mirror_vma(vma)) {
78402+ error = __do_munmap(mm, start_m, end_m - start_m);
78403+ if (error)
78404+ goto fail;
78405+ } else {
78406+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
78407+ if (!vma_m) {
78408+ error = -ENOMEM;
78409+ goto fail;
78410+ }
78411+ vma->vm_flags = newflags;
78412+ pax_mirror_vma(vma_m, vma);
78413+ }
78414+ }
78415+#endif
78416+
78417 /*
78418 * First try to merge with previous and/or next vma.
78419 */
78420@@ -195,9 +293,21 @@ success:
78421 * vm_flags and vm_page_prot are protected by the mmap_sem
78422 * held in write mode.
78423 */
78424+
78425+#ifdef CONFIG_PAX_SEGMEXEC
78426+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
78427+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
78428+#endif
78429+
78430 vma->vm_flags = newflags;
78431+
78432+#ifdef CONFIG_PAX_MPROTECT
78433+ if (mm->binfmt && mm->binfmt->handle_mprotect)
78434+ mm->binfmt->handle_mprotect(vma, newflags);
78435+#endif
78436+
78437 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
78438- vm_get_page_prot(newflags));
78439+ vm_get_page_prot(vma->vm_flags));
78440
78441 if (vma_wants_writenotify(vma)) {
78442 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
78443@@ -239,6 +349,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78444 end = start + len;
78445 if (end <= start)
78446 return -ENOMEM;
78447+
78448+#ifdef CONFIG_PAX_SEGMEXEC
78449+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
78450+ if (end > SEGMEXEC_TASK_SIZE)
78451+ return -EINVAL;
78452+ } else
78453+#endif
78454+
78455+ if (end > TASK_SIZE)
78456+ return -EINVAL;
78457+
78458 if (!arch_validate_prot(prot))
78459 return -EINVAL;
78460
78461@@ -246,7 +367,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78462 /*
78463 * Does the application expect PROT_READ to imply PROT_EXEC:
78464 */
78465- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
78466+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
78467 prot |= PROT_EXEC;
78468
78469 vm_flags = calc_vm_prot_bits(prot);
78470@@ -278,6 +399,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78471 if (start > vma->vm_start)
78472 prev = vma;
78473
78474+#ifdef CONFIG_PAX_MPROTECT
78475+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
78476+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
78477+#endif
78478+
78479 for (nstart = start ; ; ) {
78480 unsigned long newflags;
78481
78482@@ -287,6 +413,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78483
78484 /* newflags >> 4 shift VM_MAY% in place of VM_% */
78485 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
78486+ if (prot & (PROT_WRITE | PROT_EXEC))
78487+ gr_log_rwxmprotect(vma->vm_file);
78488+
78489+ error = -EACCES;
78490+ goto out;
78491+ }
78492+
78493+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
78494 error = -EACCES;
78495 goto out;
78496 }
78497@@ -301,6 +435,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78498 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
78499 if (error)
78500 goto out;
78501+
78502+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
78503+
78504 nstart = tmp;
78505
78506 if (nstart < prev->vm_end)
78507diff --git a/mm/mremap.c b/mm/mremap.c
78508index 3e98d79..1706cec 100644
78509--- a/mm/mremap.c
78510+++ b/mm/mremap.c
78511@@ -112,6 +112,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
78512 continue;
78513 pte = ptep_clear_flush(vma, old_addr, old_pte);
78514 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
78515+
78516+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
78517+ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
78518+ pte = pte_exprotect(pte);
78519+#endif
78520+
78521 set_pte_at(mm, new_addr, new_pte, pte);
78522 }
78523
78524@@ -271,6 +277,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
78525 if (is_vm_hugetlb_page(vma))
78526 goto Einval;
78527
78528+#ifdef CONFIG_PAX_SEGMEXEC
78529+ if (pax_find_mirror_vma(vma))
78530+ goto Einval;
78531+#endif
78532+
78533 /* We can't remap across vm area boundaries */
78534 if (old_len > vma->vm_end - addr)
78535 goto Efault;
78536@@ -327,20 +338,25 @@ static unsigned long mremap_to(unsigned long addr,
78537 unsigned long ret = -EINVAL;
78538 unsigned long charged = 0;
78539 unsigned long map_flags;
78540+ unsigned long pax_task_size = TASK_SIZE;
78541
78542 if (new_addr & ~PAGE_MASK)
78543 goto out;
78544
78545- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
78546+#ifdef CONFIG_PAX_SEGMEXEC
78547+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
78548+ pax_task_size = SEGMEXEC_TASK_SIZE;
78549+#endif
78550+
78551+ pax_task_size -= PAGE_SIZE;
78552+
78553+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
78554 goto out;
78555
78556 /* Check if the location we're moving into overlaps the
78557 * old location at all, and fail if it does.
78558 */
78559- if ((new_addr <= addr) && (new_addr+new_len) > addr)
78560- goto out;
78561-
78562- if ((addr <= new_addr) && (addr+old_len) > new_addr)
78563+ if (addr + old_len > new_addr && new_addr + new_len > addr)
78564 goto out;
78565
78566 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
78567@@ -412,6 +428,7 @@ unsigned long do_mremap(unsigned long addr,
78568 struct vm_area_struct *vma;
78569 unsigned long ret = -EINVAL;
78570 unsigned long charged = 0;
78571+ unsigned long pax_task_size = TASK_SIZE;
78572
78573 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
78574 goto out;
78575@@ -430,6 +447,17 @@ unsigned long do_mremap(unsigned long addr,
78576 if (!new_len)
78577 goto out;
78578
78579+#ifdef CONFIG_PAX_SEGMEXEC
78580+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
78581+ pax_task_size = SEGMEXEC_TASK_SIZE;
78582+#endif
78583+
78584+ pax_task_size -= PAGE_SIZE;
78585+
78586+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
78587+ old_len > pax_task_size || addr > pax_task_size-old_len)
78588+ goto out;
78589+
78590 if (flags & MREMAP_FIXED) {
78591 if (flags & MREMAP_MAYMOVE)
78592 ret = mremap_to(addr, old_len, new_addr, new_len);
78593@@ -476,6 +504,7 @@ unsigned long do_mremap(unsigned long addr,
78594 addr + new_len);
78595 }
78596 ret = addr;
78597+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
78598 goto out;
78599 }
78600 }
78601@@ -502,7 +531,13 @@ unsigned long do_mremap(unsigned long addr,
78602 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
78603 if (ret)
78604 goto out;
78605+
78606+ map_flags = vma->vm_flags;
78607 ret = move_vma(vma, addr, old_len, new_len, new_addr);
78608+ if (!(ret & ~PAGE_MASK)) {
78609+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
78610+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
78611+ }
78612 }
78613 out:
78614 if (ret & ~PAGE_MASK)
78615diff --git a/mm/nommu.c b/mm/nommu.c
78616index 406e8d4..53970d3 100644
78617--- a/mm/nommu.c
78618+++ b/mm/nommu.c
78619@@ -67,7 +67,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
78620 int sysctl_overcommit_ratio = 50; /* default is 50% */
78621 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
78622 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
78623-int heap_stack_gap = 0;
78624
78625 atomic_long_t mmap_pages_allocated;
78626
78627@@ -761,15 +760,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
78628 EXPORT_SYMBOL(find_vma);
78629
78630 /*
78631- * find a VMA
78632- * - we don't extend stack VMAs under NOMMU conditions
78633- */
78634-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
78635-{
78636- return find_vma(mm, addr);
78637-}
78638-
78639-/*
78640 * expand a stack to a given address
78641 * - not supported under NOMMU conditions
78642 */
78643diff --git a/mm/page_alloc.c b/mm/page_alloc.c
78644index 3ecab7e..594a471 100644
78645--- a/mm/page_alloc.c
78646+++ b/mm/page_alloc.c
78647@@ -289,7 +289,7 @@ out:
78648 * This usage means that zero-order pages may not be compound.
78649 */
78650
78651-static void free_compound_page(struct page *page)
78652+void free_compound_page(struct page *page)
78653 {
78654 __free_pages_ok(page, compound_order(page));
78655 }
78656@@ -587,6 +587,10 @@ static void __free_pages_ok(struct page *page, unsigned int order)
78657 int bad = 0;
78658 int wasMlocked = __TestClearPageMlocked(page);
78659
78660+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78661+ unsigned long index = 1UL << order;
78662+#endif
78663+
78664 kmemcheck_free_shadow(page, order);
78665
78666 for (i = 0 ; i < (1 << order) ; ++i)
78667@@ -599,6 +603,12 @@ static void __free_pages_ok(struct page *page, unsigned int order)
78668 debug_check_no_obj_freed(page_address(page),
78669 PAGE_SIZE << order);
78670 }
78671+
78672+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78673+ for (; index; --index)
78674+ sanitize_highpage(page + index - 1);
78675+#endif
78676+
78677 arch_free_page(page, order);
78678 kernel_map_pages(page, 1 << order, 0);
78679
78680@@ -702,8 +712,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
78681 arch_alloc_page(page, order);
78682 kernel_map_pages(page, 1 << order, 1);
78683
78684+#ifndef CONFIG_PAX_MEMORY_SANITIZE
78685 if (gfp_flags & __GFP_ZERO)
78686 prep_zero_page(page, order, gfp_flags);
78687+#endif
78688
78689 if (order && (gfp_flags & __GFP_COMP))
78690 prep_compound_page(page, order);
78691@@ -1097,6 +1109,11 @@ static void free_hot_cold_page(struct page *page, int cold)
78692 debug_check_no_locks_freed(page_address(page), PAGE_SIZE);
78693 debug_check_no_obj_freed(page_address(page), PAGE_SIZE);
78694 }
78695+
78696+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78697+ sanitize_highpage(page);
78698+#endif
78699+
78700 arch_free_page(page, 0);
78701 kernel_map_pages(page, 1, 0);
78702
78703@@ -2179,6 +2196,8 @@ void show_free_areas(void)
78704 int cpu;
78705 struct zone *zone;
78706
78707+ pax_track_stack();
78708+
78709 for_each_populated_zone(zone) {
78710 show_node(zone);
78711 printk("%s per-cpu:\n", zone->name);
78712@@ -3736,7 +3755,7 @@ static void __init setup_usemap(struct pglist_data *pgdat,
78713 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
78714 }
78715 #else
78716-static void inline setup_usemap(struct pglist_data *pgdat,
78717+static inline void setup_usemap(struct pglist_data *pgdat,
78718 struct zone *zone, unsigned long zonesize) {}
78719 #endif /* CONFIG_SPARSEMEM */
78720
78721diff --git a/mm/percpu.c b/mm/percpu.c
78722index c90614a..5f7b7b8 100644
78723--- a/mm/percpu.c
78724+++ b/mm/percpu.c
78725@@ -115,7 +115,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
78726 static unsigned int pcpu_high_unit_cpu __read_mostly;
78727
78728 /* the address of the first chunk which starts with the kernel static area */
78729-void *pcpu_base_addr __read_mostly;
78730+void *pcpu_base_addr __read_only;
78731 EXPORT_SYMBOL_GPL(pcpu_base_addr);
78732
78733 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
78734diff --git a/mm/rmap.c b/mm/rmap.c
78735index dd43373..d848cd7 100644
78736--- a/mm/rmap.c
78737+++ b/mm/rmap.c
78738@@ -121,6 +121,17 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78739 /* page_table_lock to protect against threads */
78740 spin_lock(&mm->page_table_lock);
78741 if (likely(!vma->anon_vma)) {
78742+
78743+#ifdef CONFIG_PAX_SEGMEXEC
78744+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
78745+
78746+ if (vma_m) {
78747+ BUG_ON(vma_m->anon_vma);
78748+ vma_m->anon_vma = anon_vma;
78749+ list_add_tail(&vma_m->anon_vma_node, &anon_vma->head);
78750+ }
78751+#endif
78752+
78753 vma->anon_vma = anon_vma;
78754 list_add_tail(&vma->anon_vma_node, &anon_vma->head);
78755 allocated = NULL;
78756diff --git a/mm/shmem.c b/mm/shmem.c
78757index 3e0005b..1d659a8 100644
78758--- a/mm/shmem.c
78759+++ b/mm/shmem.c
78760@@ -31,7 +31,7 @@
78761 #include <linux/swap.h>
78762 #include <linux/ima.h>
78763
78764-static struct vfsmount *shm_mnt;
78765+struct vfsmount *shm_mnt;
78766
78767 #ifdef CONFIG_SHMEM
78768 /*
78769@@ -1061,6 +1061,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
78770 goto unlock;
78771 }
78772 entry = shmem_swp_entry(info, index, NULL);
78773+ if (!entry)
78774+ goto unlock;
78775 if (entry->val) {
78776 /*
78777 * The more uptodate page coming down from a stacked
78778@@ -1144,6 +1146,8 @@ static struct page *shmem_swapin(swp_entry_t entry, gfp_t gfp,
78779 struct vm_area_struct pvma;
78780 struct page *page;
78781
78782+ pax_track_stack();
78783+
78784 spol = mpol_cond_copy(&mpol,
78785 mpol_shared_policy_lookup(&info->policy, idx));
78786
78787@@ -1962,7 +1966,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
78788
78789 info = SHMEM_I(inode);
78790 inode->i_size = len-1;
78791- if (len <= (char *)inode - (char *)info) {
78792+ if (len <= (char *)inode - (char *)info && len <= 64) {
78793 /* do it inline */
78794 memcpy(info, symname, len);
78795 inode->i_op = &shmem_symlink_inline_operations;
78796@@ -2310,8 +2314,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78797 int err = -ENOMEM;
78798
78799 /* Round up to L1_CACHE_BYTES to resist false sharing */
78800- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78801- L1_CACHE_BYTES), GFP_KERNEL);
78802+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78803 if (!sbinfo)
78804 return -ENOMEM;
78805
78806diff --git a/mm/slab.c b/mm/slab.c
78807index c8d466a..909e01e 100644
78808--- a/mm/slab.c
78809+++ b/mm/slab.c
78810@@ -174,7 +174,7 @@
78811
78812 /* Legal flag mask for kmem_cache_create(). */
78813 #if DEBUG
78814-# define CREATE_MASK (SLAB_RED_ZONE | \
78815+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
78816 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
78817 SLAB_CACHE_DMA | \
78818 SLAB_STORE_USER | \
78819@@ -182,7 +182,7 @@
78820 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
78821 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
78822 #else
78823-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
78824+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
78825 SLAB_CACHE_DMA | \
78826 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
78827 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
78828@@ -308,7 +308,7 @@ struct kmem_list3 {
78829 * Need this for bootstrapping a per node allocator.
78830 */
78831 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78832-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78833+struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78834 #define CACHE_CACHE 0
78835 #define SIZE_AC MAX_NUMNODES
78836 #define SIZE_L3 (2 * MAX_NUMNODES)
78837@@ -409,10 +409,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78838 if ((x)->max_freeable < i) \
78839 (x)->max_freeable = i; \
78840 } while (0)
78841-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78842-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78843-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78844-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78845+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78846+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78847+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78848+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78849 #else
78850 #define STATS_INC_ACTIVE(x) do { } while (0)
78851 #define STATS_DEC_ACTIVE(x) do { } while (0)
78852@@ -558,7 +558,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78853 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78854 */
78855 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78856- const struct slab *slab, void *obj)
78857+ const struct slab *slab, const void *obj)
78858 {
78859 u32 offset = (obj - slab->s_mem);
78860 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78861@@ -1453,7 +1453,7 @@ void __init kmem_cache_init(void)
78862 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
78863 sizes[INDEX_AC].cs_size,
78864 ARCH_KMALLOC_MINALIGN,
78865- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78866+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78867 NULL);
78868
78869 if (INDEX_AC != INDEX_L3) {
78870@@ -1461,7 +1461,7 @@ void __init kmem_cache_init(void)
78871 kmem_cache_create(names[INDEX_L3].name,
78872 sizes[INDEX_L3].cs_size,
78873 ARCH_KMALLOC_MINALIGN,
78874- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78875+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78876 NULL);
78877 }
78878
78879@@ -1479,7 +1479,7 @@ void __init kmem_cache_init(void)
78880 sizes->cs_cachep = kmem_cache_create(names->name,
78881 sizes->cs_size,
78882 ARCH_KMALLOC_MINALIGN,
78883- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78884+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78885 NULL);
78886 }
78887 #ifdef CONFIG_ZONE_DMA
78888@@ -4211,10 +4211,10 @@ static int s_show(struct seq_file *m, void *p)
78889 }
78890 /* cpu stats */
78891 {
78892- unsigned long allochit = atomic_read(&cachep->allochit);
78893- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78894- unsigned long freehit = atomic_read(&cachep->freehit);
78895- unsigned long freemiss = atomic_read(&cachep->freemiss);
78896+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78897+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78898+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78899+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78900
78901 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78902 allochit, allocmiss, freehit, freemiss);
78903@@ -4471,15 +4471,70 @@ static const struct file_operations proc_slabstats_operations = {
78904
78905 static int __init slab_proc_init(void)
78906 {
78907- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
78908+ mode_t gr_mode = S_IRUGO;
78909+
78910+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78911+ gr_mode = S_IRUSR;
78912+#endif
78913+
78914+ proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
78915 #ifdef CONFIG_DEBUG_SLAB_LEAK
78916- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78917+ proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
78918 #endif
78919 return 0;
78920 }
78921 module_init(slab_proc_init);
78922 #endif
78923
78924+void check_object_size(const void *ptr, unsigned long n, bool to)
78925+{
78926+
78927+#ifdef CONFIG_PAX_USERCOPY
78928+ struct page *page;
78929+ struct kmem_cache *cachep = NULL;
78930+ struct slab *slabp;
78931+ unsigned int objnr;
78932+ unsigned long offset;
78933+ const char *type;
78934+
78935+ if (!n)
78936+ return;
78937+
78938+ type = "<null>";
78939+ if (ZERO_OR_NULL_PTR(ptr))
78940+ goto report;
78941+
78942+ if (!virt_addr_valid(ptr))
78943+ return;
78944+
78945+ page = virt_to_head_page(ptr);
78946+
78947+ type = "<process stack>";
78948+ if (!PageSlab(page)) {
78949+ if (object_is_on_stack(ptr, n) == -1)
78950+ goto report;
78951+ return;
78952+ }
78953+
78954+ cachep = page_get_cache(page);
78955+ type = cachep->name;
78956+ if (!(cachep->flags & SLAB_USERCOPY))
78957+ goto report;
78958+
78959+ slabp = page_get_slab(page);
78960+ objnr = obj_to_index(cachep, slabp, ptr);
78961+ BUG_ON(objnr >= cachep->num);
78962+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78963+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
78964+ return;
78965+
78966+report:
78967+ pax_report_usercopy(ptr, n, to, type);
78968+#endif
78969+
78970+}
78971+EXPORT_SYMBOL(check_object_size);
78972+
78973 /**
78974 * ksize - get the actual amount of memory allocated for a given object
78975 * @objp: Pointer to the object
78976diff --git a/mm/slob.c b/mm/slob.c
78977index 837ebd6..4712174 100644
78978--- a/mm/slob.c
78979+++ b/mm/slob.c
78980@@ -29,7 +29,7 @@
78981 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
78982 * alloc_pages() directly, allocating compound pages so the page order
78983 * does not have to be separately tracked, and also stores the exact
78984- * allocation size in page->private so that it can be used to accurately
78985+ * allocation size in slob_page->size so that it can be used to accurately
78986 * provide ksize(). These objects are detected in kfree() because slob_page()
78987 * is false for them.
78988 *
78989@@ -58,6 +58,7 @@
78990 */
78991
78992 #include <linux/kernel.h>
78993+#include <linux/sched.h>
78994 #include <linux/slab.h>
78995 #include <linux/mm.h>
78996 #include <linux/swap.h> /* struct reclaim_state */
78997@@ -100,7 +101,8 @@ struct slob_page {
78998 unsigned long flags; /* mandatory */
78999 atomic_t _count; /* mandatory */
79000 slobidx_t units; /* free units left in page */
79001- unsigned long pad[2];
79002+ unsigned long pad[1];
79003+ unsigned long size; /* size when >=PAGE_SIZE */
79004 slob_t *free; /* first free slob_t in page */
79005 struct list_head list; /* linked list of free pages */
79006 };
79007@@ -133,7 +135,7 @@ static LIST_HEAD(free_slob_large);
79008 */
79009 static inline int is_slob_page(struct slob_page *sp)
79010 {
79011- return PageSlab((struct page *)sp);
79012+ return PageSlab((struct page *)sp) && !sp->size;
79013 }
79014
79015 static inline void set_slob_page(struct slob_page *sp)
79016@@ -148,7 +150,7 @@ static inline void clear_slob_page(struct slob_page *sp)
79017
79018 static inline struct slob_page *slob_page(const void *addr)
79019 {
79020- return (struct slob_page *)virt_to_page(addr);
79021+ return (struct slob_page *)virt_to_head_page(addr);
79022 }
79023
79024 /*
79025@@ -208,7 +210,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
79026 /*
79027 * Return the size of a slob block.
79028 */
79029-static slobidx_t slob_units(slob_t *s)
79030+static slobidx_t slob_units(const slob_t *s)
79031 {
79032 if (s->units > 0)
79033 return s->units;
79034@@ -218,7 +220,7 @@ static slobidx_t slob_units(slob_t *s)
79035 /*
79036 * Return the next free slob block pointer after this one.
79037 */
79038-static slob_t *slob_next(slob_t *s)
79039+static slob_t *slob_next(const slob_t *s)
79040 {
79041 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
79042 slobidx_t next;
79043@@ -233,7 +235,7 @@ static slob_t *slob_next(slob_t *s)
79044 /*
79045 * Returns true if s is the last free block in its page.
79046 */
79047-static int slob_last(slob_t *s)
79048+static int slob_last(const slob_t *s)
79049 {
79050 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
79051 }
79052@@ -252,6 +254,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
79053 if (!page)
79054 return NULL;
79055
79056+ set_slob_page(page);
79057 return page_address(page);
79058 }
79059
79060@@ -368,11 +371,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
79061 if (!b)
79062 return NULL;
79063 sp = slob_page(b);
79064- set_slob_page(sp);
79065
79066 spin_lock_irqsave(&slob_lock, flags);
79067 sp->units = SLOB_UNITS(PAGE_SIZE);
79068 sp->free = b;
79069+ sp->size = 0;
79070 INIT_LIST_HEAD(&sp->list);
79071 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
79072 set_slob_page_free(sp, slob_list);
79073@@ -475,10 +478,9 @@ out:
79074 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long)
79075 #endif
79076
79077-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
79078+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
79079 {
79080- unsigned int *m;
79081- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
79082+ slob_t *m;
79083 void *ret;
79084
79085 lockdep_trace_alloc(gfp);
79086@@ -491,7 +493,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
79087
79088 if (!m)
79089 return NULL;
79090- *m = size;
79091+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
79092+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
79093+ m[0].units = size;
79094+ m[1].units = align;
79095 ret = (void *)m + align;
79096
79097 trace_kmalloc_node(_RET_IP_, ret,
79098@@ -501,16 +506,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
79099
79100 ret = slob_new_pages(gfp | __GFP_COMP, get_order(size), node);
79101 if (ret) {
79102- struct page *page;
79103- page = virt_to_page(ret);
79104- page->private = size;
79105+ struct slob_page *sp;
79106+ sp = slob_page(ret);
79107+ sp->size = size;
79108 }
79109
79110 trace_kmalloc_node(_RET_IP_, ret,
79111 size, PAGE_SIZE << order, gfp, node);
79112 }
79113
79114- kmemleak_alloc(ret, size, 1, gfp);
79115+ return ret;
79116+}
79117+
79118+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
79119+{
79120+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
79121+ void *ret = __kmalloc_node_align(size, gfp, node, align);
79122+
79123+ if (!ZERO_OR_NULL_PTR(ret))
79124+ kmemleak_alloc(ret, size, 1, gfp);
79125 return ret;
79126 }
79127 EXPORT_SYMBOL(__kmalloc_node);
79128@@ -528,13 +542,92 @@ void kfree(const void *block)
79129 sp = slob_page(block);
79130 if (is_slob_page(sp)) {
79131 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
79132- unsigned int *m = (unsigned int *)(block - align);
79133- slob_free(m, *m + align);
79134- } else
79135+ slob_t *m = (slob_t *)(block - align);
79136+ slob_free(m, m[0].units + align);
79137+ } else {
79138+ clear_slob_page(sp);
79139+ free_slob_page(sp);
79140+ sp->size = 0;
79141 put_page(&sp->page);
79142+ }
79143 }
79144 EXPORT_SYMBOL(kfree);
79145
79146+void check_object_size(const void *ptr, unsigned long n, bool to)
79147+{
79148+
79149+#ifdef CONFIG_PAX_USERCOPY
79150+ struct slob_page *sp;
79151+ const slob_t *free;
79152+ const void *base;
79153+ unsigned long flags;
79154+ const char *type;
79155+
79156+ if (!n)
79157+ return;
79158+
79159+ type = "<null>";
79160+ if (ZERO_OR_NULL_PTR(ptr))
79161+ goto report;
79162+
79163+ if (!virt_addr_valid(ptr))
79164+ return;
79165+
79166+ type = "<process stack>";
79167+ sp = slob_page(ptr);
79168+ if (!PageSlab((struct page*)sp)) {
79169+ if (object_is_on_stack(ptr, n) == -1)
79170+ goto report;
79171+ return;
79172+ }
79173+
79174+ type = "<slob>";
79175+ if (sp->size) {
79176+ base = page_address(&sp->page);
79177+ if (base <= ptr && n <= sp->size - (ptr - base))
79178+ return;
79179+ goto report;
79180+ }
79181+
79182+ /* some tricky double walking to find the chunk */
79183+ spin_lock_irqsave(&slob_lock, flags);
79184+ base = (void *)((unsigned long)ptr & PAGE_MASK);
79185+ free = sp->free;
79186+
79187+ while (!slob_last(free) && (void *)free <= ptr) {
79188+ base = free + slob_units(free);
79189+ free = slob_next(free);
79190+ }
79191+
79192+ while (base < (void *)free) {
79193+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
79194+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
79195+ int offset;
79196+
79197+ if (ptr < base + align)
79198+ break;
79199+
79200+ offset = ptr - base - align;
79201+ if (offset >= m) {
79202+ base += size;
79203+ continue;
79204+ }
79205+
79206+ if (n > m - offset)
79207+ break;
79208+
79209+ spin_unlock_irqrestore(&slob_lock, flags);
79210+ return;
79211+ }
79212+
79213+ spin_unlock_irqrestore(&slob_lock, flags);
79214+report:
79215+ pax_report_usercopy(ptr, n, to, type);
79216+#endif
79217+
79218+}
79219+EXPORT_SYMBOL(check_object_size);
79220+
79221 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
79222 size_t ksize(const void *block)
79223 {
79224@@ -547,10 +640,10 @@ size_t ksize(const void *block)
79225 sp = slob_page(block);
79226 if (is_slob_page(sp)) {
79227 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
79228- unsigned int *m = (unsigned int *)(block - align);
79229- return SLOB_UNITS(*m) * SLOB_UNIT;
79230+ slob_t *m = (slob_t *)(block - align);
79231+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
79232 } else
79233- return sp->page.private;
79234+ return sp->size;
79235 }
79236 EXPORT_SYMBOL(ksize);
79237
79238@@ -566,8 +659,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
79239 {
79240 struct kmem_cache *c;
79241
79242+#ifdef CONFIG_PAX_USERCOPY
79243+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
79244+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
79245+#else
79246 c = slob_alloc(sizeof(struct kmem_cache),
79247 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
79248+#endif
79249
79250 if (c) {
79251 c->name = name;
79252@@ -605,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
79253 {
79254 void *b;
79255
79256+#ifdef CONFIG_PAX_USERCOPY
79257+ b = __kmalloc_node_align(c->size, flags, node, c->align);
79258+#else
79259 if (c->size < PAGE_SIZE) {
79260 b = slob_alloc(c->size, flags, c->align, node);
79261 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
79262 SLOB_UNITS(c->size) * SLOB_UNIT,
79263 flags, node);
79264 } else {
79265+ struct slob_page *sp;
79266+
79267 b = slob_new_pages(flags, get_order(c->size), node);
79268+ sp = slob_page(b);
79269+ sp->size = c->size;
79270 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
79271 PAGE_SIZE << get_order(c->size),
79272 flags, node);
79273 }
79274+#endif
79275
79276 if (c->ctor)
79277 c->ctor(b);
79278@@ -627,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
79279
79280 static void __kmem_cache_free(void *b, int size)
79281 {
79282- if (size < PAGE_SIZE)
79283+ struct slob_page *sp = slob_page(b);
79284+
79285+ if (is_slob_page(sp))
79286 slob_free(b, size);
79287- else
79288+ else {
79289+ clear_slob_page(sp);
79290+ free_slob_page(sp);
79291+ sp->size = 0;
79292 slob_free_pages(b, get_order(size));
79293+ }
79294 }
79295
79296 static void kmem_rcu_free(struct rcu_head *head)
79297@@ -643,18 +755,32 @@ static void kmem_rcu_free(struct rcu_head *head)
79298
79299 void kmem_cache_free(struct kmem_cache *c, void *b)
79300 {
79301+ int size = c->size;
79302+
79303+#ifdef CONFIG_PAX_USERCOPY
79304+ if (size + c->align < PAGE_SIZE) {
79305+ size += c->align;
79306+ b -= c->align;
79307+ }
79308+#endif
79309+
79310 kmemleak_free_recursive(b, c->flags);
79311 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
79312 struct slob_rcu *slob_rcu;
79313- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
79314+ slob_rcu = b + (size - sizeof(struct slob_rcu));
79315 INIT_RCU_HEAD(&slob_rcu->head);
79316- slob_rcu->size = c->size;
79317+ slob_rcu->size = size;
79318 call_rcu(&slob_rcu->head, kmem_rcu_free);
79319 } else {
79320- __kmem_cache_free(b, c->size);
79321+ __kmem_cache_free(b, size);
79322 }
79323
79324+#ifdef CONFIG_PAX_USERCOPY
79325+ trace_kfree(_RET_IP_, b);
79326+#else
79327 trace_kmem_cache_free(_RET_IP_, b);
79328+#endif
79329+
79330 }
79331 EXPORT_SYMBOL(kmem_cache_free);
79332
79333diff --git a/mm/slub.c b/mm/slub.c
79334index 4996fc7..87e01d0 100644
79335--- a/mm/slub.c
79336+++ b/mm/slub.c
79337@@ -201,7 +201,7 @@ struct track {
79338
79339 enum track_item { TRACK_ALLOC, TRACK_FREE };
79340
79341-#ifdef CONFIG_SLUB_DEBUG
79342+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79343 static int sysfs_slab_add(struct kmem_cache *);
79344 static int sysfs_slab_alias(struct kmem_cache *, const char *);
79345 static void sysfs_slab_remove(struct kmem_cache *);
79346@@ -410,7 +410,7 @@ static void print_track(const char *s, struct track *t)
79347 if (!t->addr)
79348 return;
79349
79350- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
79351+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
79352 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
79353 }
79354
79355@@ -1893,6 +1893,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
79356
79357 page = virt_to_head_page(x);
79358
79359+ BUG_ON(!PageSlab(page));
79360+
79361 slab_free(s, page, x, _RET_IP_);
79362
79363 trace_kmem_cache_free(_RET_IP_, x);
79364@@ -1937,7 +1939,7 @@ static int slub_min_objects;
79365 * Merge control. If this is set then no merging of slab caches will occur.
79366 * (Could be removed. This was introduced to pacify the merge skeptics.)
79367 */
79368-static int slub_nomerge;
79369+static int slub_nomerge = 1;
79370
79371 /*
79372 * Calculate the order of allocation given an slab object size.
79373@@ -2493,7 +2495,7 @@ static int kmem_cache_open(struct kmem_cache *s, gfp_t gfpflags,
79374 * list to avoid pounding the page allocator excessively.
79375 */
79376 set_min_partial(s, ilog2(s->size));
79377- s->refcount = 1;
79378+ atomic_set(&s->refcount, 1);
79379 #ifdef CONFIG_NUMA
79380 s->remote_node_defrag_ratio = 1000;
79381 #endif
79382@@ -2630,8 +2632,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
79383 void kmem_cache_destroy(struct kmem_cache *s)
79384 {
79385 down_write(&slub_lock);
79386- s->refcount--;
79387- if (!s->refcount) {
79388+ if (atomic_dec_and_test(&s->refcount)) {
79389 list_del(&s->list);
79390 up_write(&slub_lock);
79391 if (kmem_cache_close(s)) {
79392@@ -2691,12 +2692,10 @@ static int __init setup_slub_nomerge(char *str)
79393 __setup("slub_nomerge", setup_slub_nomerge);
79394
79395 static struct kmem_cache *create_kmalloc_cache(struct kmem_cache *s,
79396- const char *name, int size, gfp_t gfp_flags)
79397+ const char *name, int size, gfp_t gfp_flags, unsigned int flags)
79398 {
79399- unsigned int flags = 0;
79400-
79401 if (gfp_flags & SLUB_DMA)
79402- flags = SLAB_CACHE_DMA;
79403+ flags |= SLAB_CACHE_DMA;
79404
79405 /*
79406 * This function is called with IRQs disabled during early-boot on
79407@@ -2915,6 +2914,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
79408 EXPORT_SYMBOL(__kmalloc_node);
79409 #endif
79410
79411+void check_object_size(const void *ptr, unsigned long n, bool to)
79412+{
79413+
79414+#ifdef CONFIG_PAX_USERCOPY
79415+ struct page *page;
79416+ struct kmem_cache *s = NULL;
79417+ unsigned long offset;
79418+ const char *type;
79419+
79420+ if (!n)
79421+ return;
79422+
79423+ type = "<null>";
79424+ if (ZERO_OR_NULL_PTR(ptr))
79425+ goto report;
79426+
79427+ if (!virt_addr_valid(ptr))
79428+ return;
79429+
79430+ page = get_object_page(ptr);
79431+
79432+ type = "<process stack>";
79433+ if (!page) {
79434+ if (object_is_on_stack(ptr, n) == -1)
79435+ goto report;
79436+ return;
79437+ }
79438+
79439+ s = page->slab;
79440+ type = s->name;
79441+ if (!(s->flags & SLAB_USERCOPY))
79442+ goto report;
79443+
79444+ offset = (ptr - page_address(page)) % s->size;
79445+ if (offset <= s->objsize && n <= s->objsize - offset)
79446+ return;
79447+
79448+report:
79449+ pax_report_usercopy(ptr, n, to, type);
79450+#endif
79451+
79452+}
79453+EXPORT_SYMBOL(check_object_size);
79454+
79455 size_t ksize(const void *object)
79456 {
79457 struct page *page;
79458@@ -3185,8 +3228,8 @@ void __init kmem_cache_init(void)
79459 * kmem_cache_open for slab_state == DOWN.
79460 */
79461 create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node",
79462- sizeof(struct kmem_cache_node), GFP_NOWAIT);
79463- kmalloc_caches[0].refcount = -1;
79464+ sizeof(struct kmem_cache_node), GFP_NOWAIT, 0);
79465+ atomic_set(&kmalloc_caches[0].refcount, -1);
79466 caches++;
79467
79468 hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
79469@@ -3198,18 +3241,18 @@ void __init kmem_cache_init(void)
79470 /* Caches that are not of the two-to-the-power-of size */
79471 if (KMALLOC_MIN_SIZE <= 32) {
79472 create_kmalloc_cache(&kmalloc_caches[1],
79473- "kmalloc-96", 96, GFP_NOWAIT);
79474+ "kmalloc-96", 96, GFP_NOWAIT, SLAB_USERCOPY);
79475 caches++;
79476 }
79477 if (KMALLOC_MIN_SIZE <= 64) {
79478 create_kmalloc_cache(&kmalloc_caches[2],
79479- "kmalloc-192", 192, GFP_NOWAIT);
79480+ "kmalloc-192", 192, GFP_NOWAIT, SLAB_USERCOPY);
79481 caches++;
79482 }
79483
79484 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
79485 create_kmalloc_cache(&kmalloc_caches[i],
79486- "kmalloc", 1 << i, GFP_NOWAIT);
79487+ "kmalloc", 1 << i, GFP_NOWAIT, SLAB_USERCOPY);
79488 caches++;
79489 }
79490
79491@@ -3293,7 +3336,7 @@ static int slab_unmergeable(struct kmem_cache *s)
79492 /*
79493 * We may have set a slab to be unmergeable during bootstrap.
79494 */
79495- if (s->refcount < 0)
79496+ if (atomic_read(&s->refcount) < 0)
79497 return 1;
79498
79499 return 0;
79500@@ -3353,7 +3396,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
79501 if (s) {
79502 int cpu;
79503
79504- s->refcount++;
79505+ atomic_inc(&s->refcount);
79506 /*
79507 * Adjust the object sizes so that we clear
79508 * the complete object on kzalloc.
79509@@ -3372,7 +3415,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
79510
79511 if (sysfs_slab_alias(s, name)) {
79512 down_write(&slub_lock);
79513- s->refcount--;
79514+ atomic_dec(&s->refcount);
79515 up_write(&slub_lock);
79516 goto err;
79517 }
79518@@ -4101,7 +4144,7 @@ SLAB_ATTR_RO(ctor);
79519
79520 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
79521 {
79522- return sprintf(buf, "%d\n", s->refcount - 1);
79523+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
79524 }
79525 SLAB_ATTR_RO(aliases);
79526
79527@@ -4503,7 +4546,7 @@ static void kmem_cache_release(struct kobject *kobj)
79528 kfree(s);
79529 }
79530
79531-static struct sysfs_ops slab_sysfs_ops = {
79532+static const struct sysfs_ops slab_sysfs_ops = {
79533 .show = slab_attr_show,
79534 .store = slab_attr_store,
79535 };
79536@@ -4522,7 +4565,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
79537 return 0;
79538 }
79539
79540-static struct kset_uevent_ops slab_uevent_ops = {
79541+static const struct kset_uevent_ops slab_uevent_ops = {
79542 .filter = uevent_filter,
79543 };
79544
79545@@ -4564,6 +4607,7 @@ static char *create_unique_id(struct kmem_cache *s)
79546 return name;
79547 }
79548
79549+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79550 static int sysfs_slab_add(struct kmem_cache *s)
79551 {
79552 int err;
79553@@ -4619,6 +4663,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
79554 kobject_del(&s->kobj);
79555 kobject_put(&s->kobj);
79556 }
79557+#endif
79558
79559 /*
79560 * Need to buffer aliases during bootup until sysfs becomes
79561@@ -4632,6 +4677,7 @@ struct saved_alias {
79562
79563 static struct saved_alias *alias_list;
79564
79565+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79566 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79567 {
79568 struct saved_alias *al;
79569@@ -4654,6 +4700,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79570 alias_list = al;
79571 return 0;
79572 }
79573+#endif
79574
79575 static int __init slab_sysfs_init(void)
79576 {
79577@@ -4785,7 +4832,13 @@ static const struct file_operations proc_slabinfo_operations = {
79578
79579 static int __init slab_proc_init(void)
79580 {
79581- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
79582+ mode_t gr_mode = S_IRUGO;
79583+
79584+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79585+ gr_mode = S_IRUSR;
79586+#endif
79587+
79588+ proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
79589 return 0;
79590 }
79591 module_init(slab_proc_init);
79592diff --git a/mm/swap.c b/mm/swap.c
79593index 308e57d..5de19c0 100644
79594--- a/mm/swap.c
79595+++ b/mm/swap.c
79596@@ -30,6 +30,7 @@
79597 #include <linux/notifier.h>
79598 #include <linux/backing-dev.h>
79599 #include <linux/memcontrol.h>
79600+#include <linux/hugetlb.h>
79601
79602 #include "internal.h"
79603
79604@@ -65,6 +66,8 @@ static void put_compound_page(struct page *page)
79605 compound_page_dtor *dtor;
79606
79607 dtor = get_compound_page_dtor(page);
79608+ if (!PageHuge(page))
79609+ BUG_ON(dtor != free_compound_page);
79610 (*dtor)(page);
79611 }
79612 }
79613diff --git a/mm/util.c b/mm/util.c
79614index e48b493..24a601d 100644
79615--- a/mm/util.c
79616+++ b/mm/util.c
79617@@ -228,6 +228,12 @@ EXPORT_SYMBOL(strndup_user);
79618 void arch_pick_mmap_layout(struct mm_struct *mm)
79619 {
79620 mm->mmap_base = TASK_UNMAPPED_BASE;
79621+
79622+#ifdef CONFIG_PAX_RANDMMAP
79623+ if (mm->pax_flags & MF_PAX_RANDMMAP)
79624+ mm->mmap_base += mm->delta_mmap;
79625+#endif
79626+
79627 mm->get_unmapped_area = arch_get_unmapped_area;
79628 mm->unmap_area = arch_unmap_area;
79629 }
79630diff --git a/mm/vmalloc.c b/mm/vmalloc.c
79631index f34ffd0..e60c44f 100644
79632--- a/mm/vmalloc.c
79633+++ b/mm/vmalloc.c
79634@@ -40,8 +40,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
79635
79636 pte = pte_offset_kernel(pmd, addr);
79637 do {
79638- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79639- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79640+
79641+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79642+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
79643+ BUG_ON(!pte_exec(*pte));
79644+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
79645+ continue;
79646+ }
79647+#endif
79648+
79649+ {
79650+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79651+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79652+ }
79653 } while (pte++, addr += PAGE_SIZE, addr != end);
79654 }
79655
79656@@ -92,6 +103,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79657 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
79658 {
79659 pte_t *pte;
79660+ int ret = -ENOMEM;
79661
79662 /*
79663 * nr is a running index into the array which helps higher level
79664@@ -101,17 +113,32 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79665 pte = pte_alloc_kernel(pmd, addr);
79666 if (!pte)
79667 return -ENOMEM;
79668+
79669+ pax_open_kernel();
79670 do {
79671 struct page *page = pages[*nr];
79672
79673- if (WARN_ON(!pte_none(*pte)))
79674- return -EBUSY;
79675- if (WARN_ON(!page))
79676- return -ENOMEM;
79677+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79678+ if (!(pgprot_val(prot) & _PAGE_NX))
79679+ BUG_ON(!pte_exec(*pte) || pte_pfn(*pte) != __pa(addr) >> PAGE_SHIFT);
79680+ else
79681+#endif
79682+
79683+ if (WARN_ON(!pte_none(*pte))) {
79684+ ret = -EBUSY;
79685+ goto out;
79686+ }
79687+ if (WARN_ON(!page)) {
79688+ ret = -ENOMEM;
79689+ goto out;
79690+ }
79691 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
79692 (*nr)++;
79693 } while (pte++, addr += PAGE_SIZE, addr != end);
79694- return 0;
79695+ ret = 0;
79696+out:
79697+ pax_close_kernel();
79698+ return ret;
79699 }
79700
79701 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
79702@@ -192,11 +219,20 @@ int is_vmalloc_or_module_addr(const void *x)
79703 * and fall back on vmalloc() if that fails. Others
79704 * just put it in the vmalloc space.
79705 */
79706-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
79707+#ifdef CONFIG_MODULES
79708+#ifdef MODULES_VADDR
79709 unsigned long addr = (unsigned long)x;
79710 if (addr >= MODULES_VADDR && addr < MODULES_END)
79711 return 1;
79712 #endif
79713+
79714+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79715+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
79716+ return 1;
79717+#endif
79718+
79719+#endif
79720+
79721 return is_vmalloc_addr(x);
79722 }
79723
79724@@ -217,8 +253,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
79725
79726 if (!pgd_none(*pgd)) {
79727 pud_t *pud = pud_offset(pgd, addr);
79728+#ifdef CONFIG_X86
79729+ if (!pud_large(*pud))
79730+#endif
79731 if (!pud_none(*pud)) {
79732 pmd_t *pmd = pmd_offset(pud, addr);
79733+#ifdef CONFIG_X86
79734+ if (!pmd_large(*pmd))
79735+#endif
79736 if (!pmd_none(*pmd)) {
79737 pte_t *ptep, pte;
79738
79739@@ -292,13 +334,13 @@ static void __insert_vmap_area(struct vmap_area *va)
79740 struct rb_node *tmp;
79741
79742 while (*p) {
79743- struct vmap_area *tmp;
79744+ struct vmap_area *varea;
79745
79746 parent = *p;
79747- tmp = rb_entry(parent, struct vmap_area, rb_node);
79748- if (va->va_start < tmp->va_end)
79749+ varea = rb_entry(parent, struct vmap_area, rb_node);
79750+ if (va->va_start < varea->va_end)
79751 p = &(*p)->rb_left;
79752- else if (va->va_end > tmp->va_start)
79753+ else if (va->va_end > varea->va_start)
79754 p = &(*p)->rb_right;
79755 else
79756 BUG();
79757@@ -1245,6 +1287,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79758 struct vm_struct *area;
79759
79760 BUG_ON(in_interrupt());
79761+
79762+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79763+ if (flags & VM_KERNEXEC) {
79764+ if (start != VMALLOC_START || end != VMALLOC_END)
79765+ return NULL;
79766+ start = (unsigned long)MODULES_EXEC_VADDR;
79767+ end = (unsigned long)MODULES_EXEC_END;
79768+ }
79769+#endif
79770+
79771 if (flags & VM_IOREMAP) {
79772 int bit = fls(size);
79773
79774@@ -1484,6 +1536,11 @@ void *vmap(struct page **pages, unsigned int count,
79775 if (count > totalram_pages)
79776 return NULL;
79777
79778+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79779+ if (!(pgprot_val(prot) & _PAGE_NX))
79780+ flags |= VM_KERNEXEC;
79781+#endif
79782+
79783 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79784 __builtin_return_address(0));
79785 if (!area)
79786@@ -1594,6 +1651,14 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
79787 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79788 return NULL;
79789
79790+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79791+ if (!(pgprot_val(prot) & _PAGE_NX))
79792+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79793+ VMALLOC_START, VMALLOC_END, node,
79794+ gfp_mask, caller);
79795+ else
79796+#endif
79797+
79798 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79799 VMALLOC_START, VMALLOC_END, node,
79800 gfp_mask, caller);
79801@@ -1619,6 +1684,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
79802 return addr;
79803 }
79804
79805+#undef __vmalloc
79806 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
79807 {
79808 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
79809@@ -1635,6 +1701,7 @@ EXPORT_SYMBOL(__vmalloc);
79810 * For tight control over page level allocator and protection flags
79811 * use __vmalloc() instead.
79812 */
79813+#undef vmalloc
79814 void *vmalloc(unsigned long size)
79815 {
79816 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
79817@@ -1649,6 +1716,7 @@ EXPORT_SYMBOL(vmalloc);
79818 * The resulting memory area is zeroed so it can be mapped to userspace
79819 * without leaking data.
79820 */
79821+#undef vmalloc_user
79822 void *vmalloc_user(unsigned long size)
79823 {
79824 struct vm_struct *area;
79825@@ -1676,6 +1744,7 @@ EXPORT_SYMBOL(vmalloc_user);
79826 * For tight control over page level allocator and protection flags
79827 * use __vmalloc() instead.
79828 */
79829+#undef vmalloc_node
79830 void *vmalloc_node(unsigned long size, int node)
79831 {
79832 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
79833@@ -1698,10 +1767,10 @@ EXPORT_SYMBOL(vmalloc_node);
79834 * For tight control over page level allocator and protection flags
79835 * use __vmalloc() instead.
79836 */
79837-
79838+#undef vmalloc_exec
79839 void *vmalloc_exec(unsigned long size)
79840 {
79841- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79842+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79843 -1, __builtin_return_address(0));
79844 }
79845
79846@@ -1720,6 +1789,7 @@ void *vmalloc_exec(unsigned long size)
79847 * Allocate enough 32bit PA addressable pages to cover @size from the
79848 * page level allocator and map them into contiguous kernel virtual space.
79849 */
79850+#undef vmalloc_32
79851 void *vmalloc_32(unsigned long size)
79852 {
79853 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
79854@@ -1734,6 +1804,7 @@ EXPORT_SYMBOL(vmalloc_32);
79855 * The resulting memory area is 32bit addressable and zeroed so it can be
79856 * mapped to userspace without leaking data.
79857 */
79858+#undef vmalloc_32_user
79859 void *vmalloc_32_user(unsigned long size)
79860 {
79861 struct vm_struct *area;
79862@@ -1998,6 +2069,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79863 unsigned long uaddr = vma->vm_start;
79864 unsigned long usize = vma->vm_end - vma->vm_start;
79865
79866+ BUG_ON(vma->vm_mirror);
79867+
79868 if ((PAGE_SIZE-1) & (unsigned long)addr)
79869 return -EINVAL;
79870
79871diff --git a/mm/vmstat.c b/mm/vmstat.c
79872index 42d76c6..5643dc4 100644
79873--- a/mm/vmstat.c
79874+++ b/mm/vmstat.c
79875@@ -74,7 +74,7 @@ void vm_events_fold_cpu(int cpu)
79876 *
79877 * vm_stat contains the global counters
79878 */
79879-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79880+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79881 EXPORT_SYMBOL(vm_stat);
79882
79883 #ifdef CONFIG_SMP
79884@@ -324,7 +324,7 @@ void refresh_cpu_vm_stats(int cpu)
79885 v = p->vm_stat_diff[i];
79886 p->vm_stat_diff[i] = 0;
79887 local_irq_restore(flags);
79888- atomic_long_add(v, &zone->vm_stat[i]);
79889+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79890 global_diff[i] += v;
79891 #ifdef CONFIG_NUMA
79892 /* 3 seconds idle till flush */
79893@@ -362,7 +362,7 @@ void refresh_cpu_vm_stats(int cpu)
79894
79895 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79896 if (global_diff[i])
79897- atomic_long_add(global_diff[i], &vm_stat[i]);
79898+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79899 }
79900
79901 #endif
79902@@ -953,10 +953,20 @@ static int __init setup_vmstat(void)
79903 start_cpu_timer(cpu);
79904 #endif
79905 #ifdef CONFIG_PROC_FS
79906- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79907- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79908- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79909- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79910+ {
79911+ mode_t gr_mode = S_IRUGO;
79912+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79913+ gr_mode = S_IRUSR;
79914+#endif
79915+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79916+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79917+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79918+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79919+#else
79920+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79921+#endif
79922+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79923+ }
79924 #endif
79925 return 0;
79926 }
79927diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79928index a29c5ab..6143f20 100644
79929--- a/net/8021q/vlan.c
79930+++ b/net/8021q/vlan.c
79931@@ -622,8 +622,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79932 err = -EPERM;
79933 if (!capable(CAP_NET_ADMIN))
79934 break;
79935- if ((args.u.name_type >= 0) &&
79936- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79937+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79938 struct vlan_net *vn;
79939
79940 vn = net_generic(net, vlan_net_id);
79941diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79942index a2d2984..f9eb711 100644
79943--- a/net/9p/trans_fd.c
79944+++ b/net/9p/trans_fd.c
79945@@ -419,7 +419,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79946 oldfs = get_fs();
79947 set_fs(get_ds());
79948 /* The cast to a user pointer is valid due to the set_fs() */
79949- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79950+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79951 set_fs(oldfs);
79952
79953 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79954diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79955index 02cc7e7..4514f1b 100644
79956--- a/net/atm/atm_misc.c
79957+++ b/net/atm/atm_misc.c
79958@@ -19,7 +19,7 @@ int atm_charge(struct atm_vcc *vcc,int truesize)
79959 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79960 return 1;
79961 atm_return(vcc,truesize);
79962- atomic_inc(&vcc->stats->rx_drop);
79963+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79964 return 0;
79965 }
79966
79967@@ -41,7 +41,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
79968 }
79969 }
79970 atm_return(vcc,guess);
79971- atomic_inc(&vcc->stats->rx_drop);
79972+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79973 return NULL;
79974 }
79975
79976@@ -88,7 +88,7 @@ int atm_pcr_goal(const struct atm_trafprm *tp)
79977
79978 void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79979 {
79980-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79981+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79982 __SONET_ITEMS
79983 #undef __HANDLE_ITEM
79984 }
79985@@ -96,7 +96,7 @@ void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79986
79987 void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79988 {
79989-#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i)
79990+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79991 __SONET_ITEMS
79992 #undef __HANDLE_ITEM
79993 }
79994diff --git a/net/atm/lec.h b/net/atm/lec.h
79995index 9d14d19..5c145f3 100644
79996--- a/net/atm/lec.h
79997+++ b/net/atm/lec.h
79998@@ -48,7 +48,7 @@ struct lane2_ops {
79999 const u8 *tlvs, u32 sizeoftlvs);
80000 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
80001 const u8 *tlvs, u32 sizeoftlvs);
80002-};
80003+} __no_const;
80004
80005 /*
80006 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
80007diff --git a/net/atm/mpc.h b/net/atm/mpc.h
80008index 0919a88..a23d54e 100644
80009--- a/net/atm/mpc.h
80010+++ b/net/atm/mpc.h
80011@@ -33,7 +33,7 @@ struct mpoa_client {
80012 struct mpc_parameters parameters; /* parameters for this client */
80013
80014 const struct net_device_ops *old_ops;
80015- struct net_device_ops new_ops;
80016+ net_device_ops_no_const new_ops;
80017 };
80018
80019
80020diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
80021index 4504a4b..1733f1e 100644
80022--- a/net/atm/mpoa_caches.c
80023+++ b/net/atm/mpoa_caches.c
80024@@ -498,6 +498,8 @@ static void clear_expired(struct mpoa_client *client)
80025 struct timeval now;
80026 struct k_message msg;
80027
80028+ pax_track_stack();
80029+
80030 do_gettimeofday(&now);
80031
80032 write_lock_irq(&client->egress_lock);
80033diff --git a/net/atm/proc.c b/net/atm/proc.c
80034index ab8419a..aa91497 100644
80035--- a/net/atm/proc.c
80036+++ b/net/atm/proc.c
80037@@ -43,9 +43,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
80038 const struct k_atm_aal_stats *stats)
80039 {
80040 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
80041- atomic_read(&stats->tx),atomic_read(&stats->tx_err),
80042- atomic_read(&stats->rx),atomic_read(&stats->rx_err),
80043- atomic_read(&stats->rx_drop));
80044+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
80045+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
80046+ atomic_read_unchecked(&stats->rx_drop));
80047 }
80048
80049 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
80050@@ -188,7 +188,12 @@ static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc)
80051 {
80052 struct sock *sk = sk_atm(vcc);
80053
80054+#ifdef CONFIG_GRKERNSEC_HIDESYM
80055+ seq_printf(seq, "%p ", NULL);
80056+#else
80057 seq_printf(seq, "%p ", vcc);
80058+#endif
80059+
80060 if (!vcc->dev)
80061 seq_printf(seq, "Unassigned ");
80062 else
80063@@ -214,7 +219,11 @@ static void svc_info(struct seq_file *seq, struct atm_vcc *vcc)
80064 {
80065 if (!vcc->dev)
80066 seq_printf(seq, sizeof(void *) == 4 ?
80067+#ifdef CONFIG_GRKERNSEC_HIDESYM
80068+ "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
80069+#else
80070 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
80071+#endif
80072 else
80073 seq_printf(seq, "%3d %3d %5d ",
80074 vcc->dev->number, vcc->vpi, vcc->vci);
80075diff --git a/net/atm/resources.c b/net/atm/resources.c
80076index 56b7322..c48b84e 100644
80077--- a/net/atm/resources.c
80078+++ b/net/atm/resources.c
80079@@ -161,7 +161,7 @@ void atm_dev_deregister(struct atm_dev *dev)
80080 static void copy_aal_stats(struct k_atm_aal_stats *from,
80081 struct atm_aal_stats *to)
80082 {
80083-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
80084+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
80085 __AAL_STAT_ITEMS
80086 #undef __HANDLE_ITEM
80087 }
80088@@ -170,7 +170,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
80089 static void subtract_aal_stats(struct k_atm_aal_stats *from,
80090 struct atm_aal_stats *to)
80091 {
80092-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
80093+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
80094 __AAL_STAT_ITEMS
80095 #undef __HANDLE_ITEM
80096 }
80097diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
80098index 8567d47..bba2292 100644
80099--- a/net/bridge/br_private.h
80100+++ b/net/bridge/br_private.h
80101@@ -255,7 +255,7 @@ extern void br_ifinfo_notify(int event, struct net_bridge_port *port);
80102
80103 #ifdef CONFIG_SYSFS
80104 /* br_sysfs_if.c */
80105-extern struct sysfs_ops brport_sysfs_ops;
80106+extern const struct sysfs_ops brport_sysfs_ops;
80107 extern int br_sysfs_addif(struct net_bridge_port *p);
80108
80109 /* br_sysfs_br.c */
80110diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c
80111index 9a52ac5..c97538e 100644
80112--- a/net/bridge/br_stp_if.c
80113+++ b/net/bridge/br_stp_if.c
80114@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridge *br)
80115 char *envp[] = { NULL };
80116
80117 if (br->stp_enabled == BR_USER_STP) {
80118- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
80119+ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
80120 printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
80121 br->dev->name, r);
80122
80123diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
80124index 820643a..ce77fb3 100644
80125--- a/net/bridge/br_sysfs_if.c
80126+++ b/net/bridge/br_sysfs_if.c
80127@@ -220,7 +220,7 @@ static ssize_t brport_store(struct kobject * kobj,
80128 return ret;
80129 }
80130
80131-struct sysfs_ops brport_sysfs_ops = {
80132+const struct sysfs_ops brport_sysfs_ops = {
80133 .show = brport_show,
80134 .store = brport_store,
80135 };
80136diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
80137index d73d47f..72df42a 100644
80138--- a/net/bridge/netfilter/ebtables.c
80139+++ b/net/bridge/netfilter/ebtables.c
80140@@ -1337,6 +1337,8 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
80141 unsigned int entries_size, nentries;
80142 char *entries;
80143
80144+ pax_track_stack();
80145+
80146 if (cmd == EBT_SO_GET_ENTRIES) {
80147 entries_size = t->private->entries_size;
80148 nentries = t->private->nentries;
80149diff --git a/net/can/bcm.c b/net/can/bcm.c
80150index 2ffd2e0..72a7486 100644
80151--- a/net/can/bcm.c
80152+++ b/net/can/bcm.c
80153@@ -164,9 +164,15 @@ static int bcm_proc_show(struct seq_file *m, void *v)
80154 struct bcm_sock *bo = bcm_sk(sk);
80155 struct bcm_op *op;
80156
80157+#ifdef CONFIG_GRKERNSEC_HIDESYM
80158+ seq_printf(m, ">>> socket %p", NULL);
80159+ seq_printf(m, " / sk %p", NULL);
80160+ seq_printf(m, " / bo %p", NULL);
80161+#else
80162 seq_printf(m, ">>> socket %p", sk->sk_socket);
80163 seq_printf(m, " / sk %p", sk);
80164 seq_printf(m, " / bo %p", bo);
80165+#endif
80166 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
80167 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
80168 seq_printf(m, " <<<\n");
80169diff --git a/net/compat.c b/net/compat.c
80170index 9559afc..ccd74e1 100644
80171--- a/net/compat.c
80172+++ b/net/compat.c
80173@@ -69,9 +69,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
80174 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
80175 __get_user(kmsg->msg_flags, &umsg->msg_flags))
80176 return -EFAULT;
80177- kmsg->msg_name = compat_ptr(tmp1);
80178- kmsg->msg_iov = compat_ptr(tmp2);
80179- kmsg->msg_control = compat_ptr(tmp3);
80180+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
80181+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
80182+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
80183 return 0;
80184 }
80185
80186@@ -94,7 +94,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80187 kern_msg->msg_name = NULL;
80188
80189 tot_len = iov_from_user_compat_to_kern(kern_iov,
80190- (struct compat_iovec __user *)kern_msg->msg_iov,
80191+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
80192 kern_msg->msg_iovlen);
80193 if (tot_len >= 0)
80194 kern_msg->msg_iov = kern_iov;
80195@@ -114,20 +114,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80196
80197 #define CMSG_COMPAT_FIRSTHDR(msg) \
80198 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
80199- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
80200+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
80201 (struct compat_cmsghdr __user *)NULL)
80202
80203 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
80204 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
80205 (ucmlen) <= (unsigned long) \
80206 ((mhdr)->msg_controllen - \
80207- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
80208+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
80209
80210 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
80211 struct compat_cmsghdr __user *cmsg, int cmsg_len)
80212 {
80213 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
80214- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
80215+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
80216 msg->msg_controllen)
80217 return NULL;
80218 return (struct compat_cmsghdr __user *)ptr;
80219@@ -219,7 +219,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
80220 {
80221 struct compat_timeval ctv;
80222 struct compat_timespec cts[3];
80223- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80224+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80225 struct compat_cmsghdr cmhdr;
80226 int cmlen;
80227
80228@@ -271,7 +271,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
80229
80230 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
80231 {
80232- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80233+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80234 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
80235 int fdnum = scm->fp->count;
80236 struct file **fp = scm->fp->fp;
80237@@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
80238 len = sizeof(ktime);
80239 old_fs = get_fs();
80240 set_fs(KERNEL_DS);
80241- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
80242+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
80243 set_fs(old_fs);
80244
80245 if (!err) {
80246@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80247 case MCAST_JOIN_GROUP:
80248 case MCAST_LEAVE_GROUP:
80249 {
80250- struct compat_group_req __user *gr32 = (void *)optval;
80251+ struct compat_group_req __user *gr32 = (void __user *)optval;
80252 struct group_req __user *kgr =
80253 compat_alloc_user_space(sizeof(struct group_req));
80254 u32 interface;
80255@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80256 case MCAST_BLOCK_SOURCE:
80257 case MCAST_UNBLOCK_SOURCE:
80258 {
80259- struct compat_group_source_req __user *gsr32 = (void *)optval;
80260+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
80261 struct group_source_req __user *kgsr = compat_alloc_user_space(
80262 sizeof(struct group_source_req));
80263 u32 interface;
80264@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80265 }
80266 case MCAST_MSFILTER:
80267 {
80268- struct compat_group_filter __user *gf32 = (void *)optval;
80269+ struct compat_group_filter __user *gf32 = (void __user *)optval;
80270 struct group_filter __user *kgf;
80271 u32 interface, fmode, numsrc;
80272
80273diff --git a/net/core/dev.c b/net/core/dev.c
80274index 84a0705..575db4c 100644
80275--- a/net/core/dev.c
80276+++ b/net/core/dev.c
80277@@ -1047,10 +1047,14 @@ void dev_load(struct net *net, const char *name)
80278 if (no_module && capable(CAP_NET_ADMIN))
80279 no_module = request_module("netdev-%s", name);
80280 if (no_module && capable(CAP_SYS_MODULE)) {
80281+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80282+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
80283+#else
80284 if (!request_module("%s", name))
80285 pr_err("Loading kernel module for a network device "
80286 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
80287 "instead\n", name);
80288+#endif
80289 }
80290 }
80291 EXPORT_SYMBOL(dev_load);
80292@@ -1654,7 +1658,7 @@ static inline int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
80293
80294 struct dev_gso_cb {
80295 void (*destructor)(struct sk_buff *skb);
80296-};
80297+} __no_const;
80298
80299 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
80300
80301@@ -2063,7 +2067,7 @@ int netif_rx_ni(struct sk_buff *skb)
80302 }
80303 EXPORT_SYMBOL(netif_rx_ni);
80304
80305-static void net_tx_action(struct softirq_action *h)
80306+static void net_tx_action(void)
80307 {
80308 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80309
80310@@ -2827,7 +2831,7 @@ void netif_napi_del(struct napi_struct *napi)
80311 EXPORT_SYMBOL(netif_napi_del);
80312
80313
80314-static void net_rx_action(struct softirq_action *h)
80315+static void net_rx_action(void)
80316 {
80317 struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
80318 unsigned long time_limit = jiffies + 2;
80319diff --git a/net/core/flow.c b/net/core/flow.c
80320index 9601587..8c4824e 100644
80321--- a/net/core/flow.c
80322+++ b/net/core/flow.c
80323@@ -35,11 +35,11 @@ struct flow_cache_entry {
80324 atomic_t *object_ref;
80325 };
80326
80327-atomic_t flow_cache_genid = ATOMIC_INIT(0);
80328+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
80329
80330 static u32 flow_hash_shift;
80331 #define flow_hash_size (1 << flow_hash_shift)
80332-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
80333+static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
80334
80335 #define flow_table(cpu) (per_cpu(flow_tables, cpu))
80336
80337@@ -52,7 +52,7 @@ struct flow_percpu_info {
80338 u32 hash_rnd;
80339 int count;
80340 };
80341-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
80342+static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
80343
80344 #define flow_hash_rnd_recalc(cpu) \
80345 (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
80346@@ -69,7 +69,7 @@ struct flow_flush_info {
80347 atomic_t cpuleft;
80348 struct completion completion;
80349 };
80350-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
80351+static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
80352
80353 #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
80354
80355@@ -190,7 +190,7 @@ void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family, u8 dir,
80356 if (fle->family == family &&
80357 fle->dir == dir &&
80358 flow_key_compare(key, &fle->key) == 0) {
80359- if (fle->genid == atomic_read(&flow_cache_genid)) {
80360+ if (fle->genid == atomic_read_unchecked(&flow_cache_genid)) {
80361 void *ret = fle->object;
80362
80363 if (ret)
80364@@ -228,7 +228,7 @@ nocache:
80365 err = resolver(net, key, family, dir, &obj, &obj_ref);
80366
80367 if (fle && !err) {
80368- fle->genid = atomic_read(&flow_cache_genid);
80369+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
80370
80371 if (fle->object)
80372 atomic_dec(fle->object_ref);
80373@@ -258,7 +258,7 @@ static void flow_cache_flush_tasklet(unsigned long data)
80374
80375 fle = flow_table(cpu)[i];
80376 for (; fle; fle = fle->next) {
80377- unsigned genid = atomic_read(&flow_cache_genid);
80378+ unsigned genid = atomic_read_unchecked(&flow_cache_genid);
80379
80380 if (!fle->object || fle->genid == genid)
80381 continue;
80382diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
80383index d4fd895..ac9b1e6 100644
80384--- a/net/core/rtnetlink.c
80385+++ b/net/core/rtnetlink.c
80386@@ -57,7 +57,7 @@ struct rtnl_link
80387 {
80388 rtnl_doit_func doit;
80389 rtnl_dumpit_func dumpit;
80390-};
80391+} __no_const;
80392
80393 static DEFINE_MUTEX(rtnl_mutex);
80394
80395diff --git a/net/core/scm.c b/net/core/scm.c
80396index d98eafc..1a190a9 100644
80397--- a/net/core/scm.c
80398+++ b/net/core/scm.c
80399@@ -191,7 +191,7 @@ error:
80400 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80401 {
80402 struct cmsghdr __user *cm
80403- = (__force struct cmsghdr __user *)msg->msg_control;
80404+ = (struct cmsghdr __force_user *)msg->msg_control;
80405 struct cmsghdr cmhdr;
80406 int cmlen = CMSG_LEN(len);
80407 int err;
80408@@ -214,7 +214,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80409 err = -EFAULT;
80410 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
80411 goto out;
80412- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
80413+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
80414 goto out;
80415 cmlen = CMSG_SPACE(len);
80416 if (msg->msg_controllen < cmlen)
80417@@ -229,7 +229,7 @@ out:
80418 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80419 {
80420 struct cmsghdr __user *cm
80421- = (__force struct cmsghdr __user*)msg->msg_control;
80422+ = (struct cmsghdr __force_user *)msg->msg_control;
80423
80424 int fdmax = 0;
80425 int fdnum = scm->fp->count;
80426@@ -249,7 +249,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80427 if (fdnum < fdmax)
80428 fdmax = fdnum;
80429
80430- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
80431+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
80432 i++, cmfptr++)
80433 {
80434 int new_fd;
80435diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
80436index 45329d7..626aaa6 100644
80437--- a/net/core/secure_seq.c
80438+++ b/net/core/secure_seq.c
80439@@ -57,7 +57,7 @@ __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
80440 EXPORT_SYMBOL(secure_tcpv6_sequence_number);
80441
80442 u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
80443- __be16 dport)
80444+ __be16 dport)
80445 {
80446 u32 secret[MD5_MESSAGE_BYTES / 4];
80447 u32 hash[MD5_DIGEST_WORDS];
80448@@ -71,7 +71,6 @@ u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
80449 secret[i] = net_secret[i];
80450
80451 md5_transform(hash, secret);
80452-
80453 return hash[0];
80454 }
80455 #endif
80456diff --git a/net/core/skbuff.c b/net/core/skbuff.c
80457index a807f8c..65f906f 100644
80458--- a/net/core/skbuff.c
80459+++ b/net/core/skbuff.c
80460@@ -1544,6 +1544,8 @@ int skb_splice_bits(struct sk_buff *skb, unsigned int offset,
80461 struct sk_buff *frag_iter;
80462 struct sock *sk = skb->sk;
80463
80464+ pax_track_stack();
80465+
80466 /*
80467 * __skb_splice_bits() only fails if the output has no room left,
80468 * so no point in going over the frag_list for the error case.
80469diff --git a/net/core/sock.c b/net/core/sock.c
80470index 6605e75..3acebda 100644
80471--- a/net/core/sock.c
80472+++ b/net/core/sock.c
80473@@ -864,11 +864,15 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80474 break;
80475
80476 case SO_PEERCRED:
80477+ {
80478+ struct ucred peercred;
80479 if (len > sizeof(sk->sk_peercred))
80480 len = sizeof(sk->sk_peercred);
80481- if (copy_to_user(optval, &sk->sk_peercred, len))
80482+ peercred = sk->sk_peercred;
80483+ if (copy_to_user(optval, &peercred, len))
80484 return -EFAULT;
80485 goto lenout;
80486+ }
80487
80488 case SO_PEERNAME:
80489 {
80490@@ -1892,7 +1896,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
80491 */
80492 smp_wmb();
80493 atomic_set(&sk->sk_refcnt, 1);
80494- atomic_set(&sk->sk_drops, 0);
80495+ atomic_set_unchecked(&sk->sk_drops, 0);
80496 }
80497 EXPORT_SYMBOL(sock_init_data);
80498
80499diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
80500index 2036568..c55883d 100644
80501--- a/net/decnet/sysctl_net_decnet.c
80502+++ b/net/decnet/sysctl_net_decnet.c
80503@@ -206,7 +206,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
80504
80505 if (len > *lenp) len = *lenp;
80506
80507- if (copy_to_user(buffer, addr, len))
80508+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
80509 return -EFAULT;
80510
80511 *lenp = len;
80512@@ -327,7 +327,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
80513
80514 if (len > *lenp) len = *lenp;
80515
80516- if (copy_to_user(buffer, devname, len))
80517+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
80518 return -EFAULT;
80519
80520 *lenp = len;
80521diff --git a/net/econet/Kconfig b/net/econet/Kconfig
80522index 39a2d29..f39c0fe 100644
80523--- a/net/econet/Kconfig
80524+++ b/net/econet/Kconfig
80525@@ -4,7 +4,7 @@
80526
80527 config ECONET
80528 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
80529- depends on EXPERIMENTAL && INET
80530+ depends on EXPERIMENTAL && INET && BROKEN
80531 ---help---
80532 Econet is a fairly old and slow networking protocol mainly used by
80533 Acorn computers to access file and print servers. It uses native
80534diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
80535index a413b1b..380849c 100644
80536--- a/net/ieee802154/dgram.c
80537+++ b/net/ieee802154/dgram.c
80538@@ -318,7 +318,7 @@ out:
80539 static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
80540 {
80541 if (sock_queue_rcv_skb(sk, skb) < 0) {
80542- atomic_inc(&sk->sk_drops);
80543+ atomic_inc_unchecked(&sk->sk_drops);
80544 kfree_skb(skb);
80545 return NET_RX_DROP;
80546 }
80547diff --git a/net/ieee802154/raw.c b/net/ieee802154/raw.c
80548index 30e74ee..bfc6ee0 100644
80549--- a/net/ieee802154/raw.c
80550+++ b/net/ieee802154/raw.c
80551@@ -206,7 +206,7 @@ out:
80552 static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
80553 {
80554 if (sock_queue_rcv_skb(sk, skb) < 0) {
80555- atomic_inc(&sk->sk_drops);
80556+ atomic_inc_unchecked(&sk->sk_drops);
80557 kfree_skb(skb);
80558 return NET_RX_DROP;
80559 }
80560diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
80561index dba56d2..acee5d6 100644
80562--- a/net/ipv4/inet_diag.c
80563+++ b/net/ipv4/inet_diag.c
80564@@ -113,8 +113,13 @@ static int inet_csk_diag_fill(struct sock *sk,
80565 r->idiag_retrans = 0;
80566
80567 r->id.idiag_if = sk->sk_bound_dev_if;
80568+#ifdef CONFIG_GRKERNSEC_HIDESYM
80569+ r->id.idiag_cookie[0] = 0;
80570+ r->id.idiag_cookie[1] = 0;
80571+#else
80572 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
80573 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
80574+#endif
80575
80576 r->id.idiag_sport = inet->sport;
80577 r->id.idiag_dport = inet->dport;
80578@@ -200,8 +205,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
80579 r->idiag_family = tw->tw_family;
80580 r->idiag_retrans = 0;
80581 r->id.idiag_if = tw->tw_bound_dev_if;
80582+
80583+#ifdef CONFIG_GRKERNSEC_HIDESYM
80584+ r->id.idiag_cookie[0] = 0;
80585+ r->id.idiag_cookie[1] = 0;
80586+#else
80587 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
80588 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
80589+#endif
80590+
80591 r->id.idiag_sport = tw->tw_sport;
80592 r->id.idiag_dport = tw->tw_dport;
80593 r->id.idiag_src[0] = tw->tw_rcv_saddr;
80594@@ -284,12 +296,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
80595 if (sk == NULL)
80596 goto unlock;
80597
80598+#ifndef CONFIG_GRKERNSEC_HIDESYM
80599 err = -ESTALE;
80600 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
80601 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
80602 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
80603 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
80604 goto out;
80605+#endif
80606
80607 err = -ENOMEM;
80608 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
80609@@ -579,8 +593,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
80610 r->idiag_retrans = req->retrans;
80611
80612 r->id.idiag_if = sk->sk_bound_dev_if;
80613+
80614+#ifdef CONFIG_GRKERNSEC_HIDESYM
80615+ r->id.idiag_cookie[0] = 0;
80616+ r->id.idiag_cookie[1] = 0;
80617+#else
80618 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
80619 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
80620+#endif
80621
80622 tmo = req->expires - jiffies;
80623 if (tmo < 0)
80624diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
80625index d717267..56de7e7 100644
80626--- a/net/ipv4/inet_hashtables.c
80627+++ b/net/ipv4/inet_hashtables.c
80628@@ -18,12 +18,15 @@
80629 #include <linux/sched.h>
80630 #include <linux/slab.h>
80631 #include <linux/wait.h>
80632+#include <linux/security.h>
80633
80634 #include <net/inet_connection_sock.h>
80635 #include <net/inet_hashtables.h>
80636 #include <net/secure_seq.h>
80637 #include <net/ip.h>
80638
80639+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
80640+
80641 /*
80642 * Allocate and initialize a new local port bind bucket.
80643 * The bindhash mutex for snum's hash chain must be held here.
80644@@ -491,6 +494,8 @@ ok:
80645 }
80646 spin_unlock(&head->lock);
80647
80648+ gr_update_task_in_ip_table(current, inet_sk(sk));
80649+
80650 if (tw) {
80651 inet_twsk_deschedule(tw, death_row);
80652 inet_twsk_put(tw);
80653diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
80654index 13b229f..6956484 100644
80655--- a/net/ipv4/inetpeer.c
80656+++ b/net/ipv4/inetpeer.c
80657@@ -367,6 +367,8 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
80658 struct inet_peer *p, *n;
80659 struct inet_peer **stack[PEER_MAXDEPTH], ***stackptr;
80660
80661+ pax_track_stack();
80662+
80663 /* Look up for the address quickly. */
80664 read_lock_bh(&peer_pool_lock);
80665 p = lookup(daddr, NULL);
80666@@ -390,7 +392,7 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
80667 return NULL;
80668 n->v4daddr = daddr;
80669 atomic_set(&n->refcnt, 1);
80670- atomic_set(&n->rid, 0);
80671+ atomic_set_unchecked(&n->rid, 0);
80672 n->ip_id_count = secure_ip_id(daddr);
80673 n->tcp_ts_stamp = 0;
80674
80675diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
80676index d3fe10b..feeafc9 100644
80677--- a/net/ipv4/ip_fragment.c
80678+++ b/net/ipv4/ip_fragment.c
80679@@ -255,7 +255,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
80680 return 0;
80681
80682 start = qp->rid;
80683- end = atomic_inc_return(&peer->rid);
80684+ end = atomic_inc_return_unchecked(&peer->rid);
80685 qp->rid = end;
80686
80687 rc = qp->q.fragments && (end - start) > max;
80688diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
80689index e982b5c..f079d75 100644
80690--- a/net/ipv4/ip_sockglue.c
80691+++ b/net/ipv4/ip_sockglue.c
80692@@ -1015,6 +1015,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80693 int val;
80694 int len;
80695
80696+ pax_track_stack();
80697+
80698 if (level != SOL_IP)
80699 return -EOPNOTSUPP;
80700
80701@@ -1173,7 +1175,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80702 if (sk->sk_type != SOCK_STREAM)
80703 return -ENOPROTOOPT;
80704
80705- msg.msg_control = optval;
80706+ msg.msg_control = (void __force_kernel *)optval;
80707 msg.msg_controllen = len;
80708 msg.msg_flags = 0;
80709
80710diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
80711index f8d04c2..c1188f2 100644
80712--- a/net/ipv4/ipconfig.c
80713+++ b/net/ipv4/ipconfig.c
80714@@ -295,7 +295,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
80715
80716 mm_segment_t oldfs = get_fs();
80717 set_fs(get_ds());
80718- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80719+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80720 set_fs(oldfs);
80721 return res;
80722 }
80723@@ -306,7 +306,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
80724
80725 mm_segment_t oldfs = get_fs();
80726 set_fs(get_ds());
80727- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80728+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80729 set_fs(oldfs);
80730 return res;
80731 }
80732@@ -317,7 +317,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
80733
80734 mm_segment_t oldfs = get_fs();
80735 set_fs(get_ds());
80736- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
80737+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
80738 set_fs(oldfs);
80739 return res;
80740 }
80741diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
80742index c8b0cc3..4da5ae2 100644
80743--- a/net/ipv4/netfilter/arp_tables.c
80744+++ b/net/ipv4/netfilter/arp_tables.c
80745@@ -934,6 +934,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80746 private = &tmp;
80747 }
80748 #endif
80749+ memset(&info, 0, sizeof(info));
80750 info.valid_hooks = t->valid_hooks;
80751 memcpy(info.hook_entry, private->hook_entry,
80752 sizeof(info.hook_entry));
80753diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c
80754index c156db2..e772975 100644
80755--- a/net/ipv4/netfilter/ip_queue.c
80756+++ b/net/ipv4/netfilter/ip_queue.c
80757@@ -286,6 +286,9 @@ ipq_mangle_ipv4(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
80758
80759 if (v->data_len < sizeof(*user_iph))
80760 return 0;
80761+ if (v->data_len > 65535)
80762+ return -EMSGSIZE;
80763+
80764 diff = v->data_len - e->skb->len;
80765 if (diff < 0) {
80766 if (pskb_trim(e->skb, v->data_len))
80767@@ -409,7 +412,8 @@ ipq_dev_drop(int ifindex)
80768 static inline void
80769 __ipq_rcv_skb(struct sk_buff *skb)
80770 {
80771- int status, type, pid, flags, nlmsglen, skblen;
80772+ int status, type, pid, flags;
80773+ unsigned int nlmsglen, skblen;
80774 struct nlmsghdr *nlh;
80775
80776 skblen = skb->len;
80777diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
80778index 0606db1..02e7e4c 100644
80779--- a/net/ipv4/netfilter/ip_tables.c
80780+++ b/net/ipv4/netfilter/ip_tables.c
80781@@ -1141,6 +1141,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80782 private = &tmp;
80783 }
80784 #endif
80785+ memset(&info, 0, sizeof(info));
80786 info.valid_hooks = t->valid_hooks;
80787 memcpy(info.hook_entry, private->hook_entry,
80788 sizeof(info.hook_entry));
80789diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
80790index d9521f6..3c3eb25 100644
80791--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
80792+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
80793@@ -397,7 +397,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
80794
80795 *len = 0;
80796
80797- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
80798+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
80799 if (*octets == NULL) {
80800 if (net_ratelimit())
80801 printk("OOM in bsalg (%d)\n", __LINE__);
80802diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
80803index ab996f9..3da5f96 100644
80804--- a/net/ipv4/raw.c
80805+++ b/net/ipv4/raw.c
80806@@ -292,7 +292,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
80807 /* Charge it to the socket. */
80808
80809 if (sock_queue_rcv_skb(sk, skb) < 0) {
80810- atomic_inc(&sk->sk_drops);
80811+ atomic_inc_unchecked(&sk->sk_drops);
80812 kfree_skb(skb);
80813 return NET_RX_DROP;
80814 }
80815@@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
80816 int raw_rcv(struct sock *sk, struct sk_buff *skb)
80817 {
80818 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
80819- atomic_inc(&sk->sk_drops);
80820+ atomic_inc_unchecked(&sk->sk_drops);
80821 kfree_skb(skb);
80822 return NET_RX_DROP;
80823 }
80824@@ -724,16 +724,23 @@ static int raw_init(struct sock *sk)
80825
80826 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
80827 {
80828+ struct icmp_filter filter;
80829+
80830+ if (optlen < 0)
80831+ return -EINVAL;
80832 if (optlen > sizeof(struct icmp_filter))
80833 optlen = sizeof(struct icmp_filter);
80834- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
80835+ if (copy_from_user(&filter, optval, optlen))
80836 return -EFAULT;
80837+ raw_sk(sk)->filter = filter;
80838+
80839 return 0;
80840 }
80841
80842 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
80843 {
80844 int len, ret = -EFAULT;
80845+ struct icmp_filter filter;
80846
80847 if (get_user(len, optlen))
80848 goto out;
80849@@ -743,8 +750,9 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
80850 if (len > sizeof(struct icmp_filter))
80851 len = sizeof(struct icmp_filter);
80852 ret = -EFAULT;
80853- if (put_user(len, optlen) ||
80854- copy_to_user(optval, &raw_sk(sk)->filter, len))
80855+ filter = raw_sk(sk)->filter;
80856+ if (put_user(len, optlen) || len > sizeof filter ||
80857+ copy_to_user(optval, &filter, len))
80858 goto out;
80859 ret = 0;
80860 out: return ret;
80861@@ -954,7 +962,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80862 sk_wmem_alloc_get(sp),
80863 sk_rmem_alloc_get(sp),
80864 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
80865- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80866+ atomic_read(&sp->sk_refcnt),
80867+#ifdef CONFIG_GRKERNSEC_HIDESYM
80868+ NULL,
80869+#else
80870+ sp,
80871+#endif
80872+ atomic_read_unchecked(&sp->sk_drops));
80873 }
80874
80875 static int raw_seq_show(struct seq_file *seq, void *v)
80876diff --git a/net/ipv4/route.c b/net/ipv4/route.c
80877index 58f141b..b759702 100644
80878--- a/net/ipv4/route.c
80879+++ b/net/ipv4/route.c
80880@@ -269,7 +269,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
80881
80882 static inline int rt_genid(struct net *net)
80883 {
80884- return atomic_read(&net->ipv4.rt_genid);
80885+ return atomic_read_unchecked(&net->ipv4.rt_genid);
80886 }
80887
80888 #ifdef CONFIG_PROC_FS
80889@@ -889,7 +889,7 @@ static void rt_cache_invalidate(struct net *net)
80890 unsigned char shuffle;
80891
80892 get_random_bytes(&shuffle, sizeof(shuffle));
80893- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
80894+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
80895 }
80896
80897 /*
80898@@ -3357,7 +3357,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
80899
80900 static __net_init int rt_secret_timer_init(struct net *net)
80901 {
80902- atomic_set(&net->ipv4.rt_genid,
80903+ atomic_set_unchecked(&net->ipv4.rt_genid,
80904 (int) ((num_physpages ^ (num_physpages>>8)) ^
80905 (jiffies ^ (jiffies >> 7))));
80906
80907diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
80908index f095659..adc892a 100644
80909--- a/net/ipv4/tcp.c
80910+++ b/net/ipv4/tcp.c
80911@@ -2085,6 +2085,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
80912 int val;
80913 int err = 0;
80914
80915+ pax_track_stack();
80916+
80917 /* This is a string value all the others are int's */
80918 if (optname == TCP_CONGESTION) {
80919 char name[TCP_CA_NAME_MAX];
80920@@ -2355,6 +2357,8 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
80921 struct tcp_sock *tp = tcp_sk(sk);
80922 int val, len;
80923
80924+ pax_track_stack();
80925+
80926 if (get_user(len, optlen))
80927 return -EFAULT;
80928
80929diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
80930index 6fc7961..33bad4a 100644
80931--- a/net/ipv4/tcp_ipv4.c
80932+++ b/net/ipv4/tcp_ipv4.c
80933@@ -85,6 +85,9 @@
80934 int sysctl_tcp_tw_reuse __read_mostly;
80935 int sysctl_tcp_low_latency __read_mostly;
80936
80937+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80938+extern int grsec_enable_blackhole;
80939+#endif
80940
80941 #ifdef CONFIG_TCP_MD5SIG
80942 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
80943@@ -1543,6 +1546,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
80944 return 0;
80945
80946 reset:
80947+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80948+ if (!grsec_enable_blackhole)
80949+#endif
80950 tcp_v4_send_reset(rsk, skb);
80951 discard:
80952 kfree_skb(skb);
80953@@ -1604,12 +1610,20 @@ int tcp_v4_rcv(struct sk_buff *skb)
80954 TCP_SKB_CB(skb)->sacked = 0;
80955
80956 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80957- if (!sk)
80958+ if (!sk) {
80959+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80960+ ret = 1;
80961+#endif
80962 goto no_tcp_socket;
80963+ }
80964
80965 process:
80966- if (sk->sk_state == TCP_TIME_WAIT)
80967+ if (sk->sk_state == TCP_TIME_WAIT) {
80968+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80969+ ret = 2;
80970+#endif
80971 goto do_time_wait;
80972+ }
80973
80974 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
80975 goto discard_and_relse;
80976@@ -1651,6 +1665,10 @@ no_tcp_socket:
80977 bad_packet:
80978 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80979 } else {
80980+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80981+ if (!grsec_enable_blackhole || (ret == 1 &&
80982+ (skb->dev->flags & IFF_LOOPBACK)))
80983+#endif
80984 tcp_v4_send_reset(NULL, skb);
80985 }
80986
80987@@ -2238,7 +2256,11 @@ static void get_openreq4(struct sock *sk, struct request_sock *req,
80988 0, /* non standard timer */
80989 0, /* open_requests have no inode */
80990 atomic_read(&sk->sk_refcnt),
80991+#ifdef CONFIG_GRKERNSEC_HIDESYM
80992+ NULL,
80993+#else
80994 req,
80995+#endif
80996 len);
80997 }
80998
80999@@ -2280,7 +2302,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
81000 sock_i_uid(sk),
81001 icsk->icsk_probes_out,
81002 sock_i_ino(sk),
81003- atomic_read(&sk->sk_refcnt), sk,
81004+ atomic_read(&sk->sk_refcnt),
81005+#ifdef CONFIG_GRKERNSEC_HIDESYM
81006+ NULL,
81007+#else
81008+ sk,
81009+#endif
81010 jiffies_to_clock_t(icsk->icsk_rto),
81011 jiffies_to_clock_t(icsk->icsk_ack.ato),
81012 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
81013@@ -2308,7 +2335,13 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
81014 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
81015 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
81016 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
81017- atomic_read(&tw->tw_refcnt), tw, len);
81018+ atomic_read(&tw->tw_refcnt),
81019+#ifdef CONFIG_GRKERNSEC_HIDESYM
81020+ NULL,
81021+#else
81022+ tw,
81023+#endif
81024+ len);
81025 }
81026
81027 #define TMPSZ 150
81028diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
81029index 4c03598..e09a8e8 100644
81030--- a/net/ipv4/tcp_minisocks.c
81031+++ b/net/ipv4/tcp_minisocks.c
81032@@ -26,6 +26,10 @@
81033 #include <net/inet_common.h>
81034 #include <net/xfrm.h>
81035
81036+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81037+extern int grsec_enable_blackhole;
81038+#endif
81039+
81040 #ifdef CONFIG_SYSCTL
81041 #define SYNC_INIT 0 /* let the user enable it */
81042 #else
81043@@ -672,6 +676,10 @@ listen_overflow:
81044
81045 embryonic_reset:
81046 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
81047+
81048+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81049+ if (!grsec_enable_blackhole)
81050+#endif
81051 if (!(flg & TCP_FLAG_RST))
81052 req->rsk_ops->send_reset(sk, skb);
81053
81054diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
81055index af83bdf..ec91cb2 100644
81056--- a/net/ipv4/tcp_output.c
81057+++ b/net/ipv4/tcp_output.c
81058@@ -2234,6 +2234,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
81059 __u8 *md5_hash_location;
81060 int mss;
81061
81062+ pax_track_stack();
81063+
81064 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC);
81065 if (skb == NULL)
81066 return NULL;
81067diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
81068index 59f5b5e..193860f 100644
81069--- a/net/ipv4/tcp_probe.c
81070+++ b/net/ipv4/tcp_probe.c
81071@@ -200,7 +200,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
81072 if (cnt + width >= len)
81073 break;
81074
81075- if (copy_to_user(buf + cnt, tbuf, width))
81076+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
81077 return -EFAULT;
81078 cnt += width;
81079 }
81080diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
81081index 57d5501..a9ed13a 100644
81082--- a/net/ipv4/tcp_timer.c
81083+++ b/net/ipv4/tcp_timer.c
81084@@ -21,6 +21,10 @@
81085 #include <linux/module.h>
81086 #include <net/tcp.h>
81087
81088+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81089+extern int grsec_lastack_retries;
81090+#endif
81091+
81092 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
81093 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
81094 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
81095@@ -164,6 +168,13 @@ static int tcp_write_timeout(struct sock *sk)
81096 }
81097 }
81098
81099+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81100+ if ((sk->sk_state == TCP_LAST_ACK) &&
81101+ (grsec_lastack_retries > 0) &&
81102+ (grsec_lastack_retries < retry_until))
81103+ retry_until = grsec_lastack_retries;
81104+#endif
81105+
81106 if (retransmits_timed_out(sk, retry_until)) {
81107 /* Has it gone just too far? */
81108 tcp_write_err(sk);
81109diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
81110index 0ac8833..58d8c43 100644
81111--- a/net/ipv4/udp.c
81112+++ b/net/ipv4/udp.c
81113@@ -86,6 +86,7 @@
81114 #include <linux/types.h>
81115 #include <linux/fcntl.h>
81116 #include <linux/module.h>
81117+#include <linux/security.h>
81118 #include <linux/socket.h>
81119 #include <linux/sockios.h>
81120 #include <linux/igmp.h>
81121@@ -106,6 +107,10 @@
81122 #include <net/xfrm.h>
81123 #include "udp_impl.h"
81124
81125+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81126+extern int grsec_enable_blackhole;
81127+#endif
81128+
81129 struct udp_table udp_table;
81130 EXPORT_SYMBOL(udp_table);
81131
81132@@ -371,6 +376,9 @@ found:
81133 return s;
81134 }
81135
81136+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
81137+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
81138+
81139 /*
81140 * This routine is called by the ICMP module when it gets some
81141 * sort of error condition. If err < 0 then the socket should
81142@@ -639,9 +647,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
81143 dport = usin->sin_port;
81144 if (dport == 0)
81145 return -EINVAL;
81146+
81147+ err = gr_search_udp_sendmsg(sk, usin);
81148+ if (err)
81149+ return err;
81150 } else {
81151 if (sk->sk_state != TCP_ESTABLISHED)
81152 return -EDESTADDRREQ;
81153+
81154+ err = gr_search_udp_sendmsg(sk, NULL);
81155+ if (err)
81156+ return err;
81157+
81158 daddr = inet->daddr;
81159 dport = inet->dport;
81160 /* Open fast path for connected socket.
81161@@ -945,6 +962,10 @@ try_again:
81162 if (!skb)
81163 goto out;
81164
81165+ err = gr_search_udp_recvmsg(sk, skb);
81166+ if (err)
81167+ goto out_free;
81168+
81169 ulen = skb->len - sizeof(struct udphdr);
81170 copied = len;
81171 if (copied > ulen)
81172@@ -1068,7 +1089,7 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81173 if (rc == -ENOMEM) {
81174 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81175 is_udplite);
81176- atomic_inc(&sk->sk_drops);
81177+ atomic_inc_unchecked(&sk->sk_drops);
81178 }
81179 goto drop;
81180 }
81181@@ -1338,6 +1359,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81182 goto csum_error;
81183
81184 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81185+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81186+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81187+#endif
81188 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
81189
81190 /*
81191@@ -1758,8 +1782,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
81192 sk_wmem_alloc_get(sp),
81193 sk_rmem_alloc_get(sp),
81194 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
81195- atomic_read(&sp->sk_refcnt), sp,
81196- atomic_read(&sp->sk_drops), len);
81197+ atomic_read(&sp->sk_refcnt),
81198+#ifdef CONFIG_GRKERNSEC_HIDESYM
81199+ NULL,
81200+#else
81201+ sp,
81202+#endif
81203+ atomic_read_unchecked(&sp->sk_drops), len);
81204 }
81205
81206 int udp4_seq_show(struct seq_file *seq, void *v)
81207diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
81208index 8ac3d09..fc58c5f 100644
81209--- a/net/ipv6/addrconf.c
81210+++ b/net/ipv6/addrconf.c
81211@@ -2053,7 +2053,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
81212 p.iph.ihl = 5;
81213 p.iph.protocol = IPPROTO_IPV6;
81214 p.iph.ttl = 64;
81215- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
81216+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
81217
81218 if (ops->ndo_do_ioctl) {
81219 mm_segment_t oldfs = get_fs();
81220diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
81221index cc4797d..7cfdfcc 100644
81222--- a/net/ipv6/inet6_connection_sock.c
81223+++ b/net/ipv6/inet6_connection_sock.c
81224@@ -152,7 +152,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
81225 #ifdef CONFIG_XFRM
81226 {
81227 struct rt6_info *rt = (struct rt6_info *)dst;
81228- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
81229+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
81230 }
81231 #endif
81232 }
81233@@ -167,7 +167,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
81234 #ifdef CONFIG_XFRM
81235 if (dst) {
81236 struct rt6_info *rt = (struct rt6_info *)dst;
81237- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
81238+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
81239 sk->sk_dst_cache = NULL;
81240 dst_release(dst);
81241 dst = NULL;
81242diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
81243index 093e9b2..f72cddb 100644
81244--- a/net/ipv6/inet6_hashtables.c
81245+++ b/net/ipv6/inet6_hashtables.c
81246@@ -119,7 +119,7 @@ out:
81247 }
81248 EXPORT_SYMBOL(__inet6_lookup_established);
81249
81250-static int inline compute_score(struct sock *sk, struct net *net,
81251+static inline int compute_score(struct sock *sk, struct net *net,
81252 const unsigned short hnum,
81253 const struct in6_addr *daddr,
81254 const int dif)
81255diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
81256index 4f7aaf6..f7acf45 100644
81257--- a/net/ipv6/ipv6_sockglue.c
81258+++ b/net/ipv6/ipv6_sockglue.c
81259@@ -130,6 +130,8 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
81260 int val, valbool;
81261 int retv = -ENOPROTOOPT;
81262
81263+ pax_track_stack();
81264+
81265 if (optval == NULL)
81266 val=0;
81267 else {
81268@@ -881,6 +883,8 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
81269 int len;
81270 int val;
81271
81272+ pax_track_stack();
81273+
81274 if (ip6_mroute_opt(optname))
81275 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
81276
81277@@ -922,7 +926,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
81278 if (sk->sk_type != SOCK_STREAM)
81279 return -ENOPROTOOPT;
81280
81281- msg.msg_control = optval;
81282+ msg.msg_control = (void __force_kernel *)optval;
81283 msg.msg_controllen = len;
81284 msg.msg_flags = 0;
81285
81286diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
81287index 1cf3f0c..1d4376f 100644
81288--- a/net/ipv6/netfilter/ip6_queue.c
81289+++ b/net/ipv6/netfilter/ip6_queue.c
81290@@ -287,6 +287,9 @@ ipq_mangle_ipv6(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
81291
81292 if (v->data_len < sizeof(*user_iph))
81293 return 0;
81294+ if (v->data_len > 65535)
81295+ return -EMSGSIZE;
81296+
81297 diff = v->data_len - e->skb->len;
81298 if (diff < 0) {
81299 if (pskb_trim(e->skb, v->data_len))
81300@@ -411,7 +414,8 @@ ipq_dev_drop(int ifindex)
81301 static inline void
81302 __ipq_rcv_skb(struct sk_buff *skb)
81303 {
81304- int status, type, pid, flags, nlmsglen, skblen;
81305+ int status, type, pid, flags;
81306+ unsigned int nlmsglen, skblen;
81307 struct nlmsghdr *nlh;
81308
81309 skblen = skb->len;
81310diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
81311index 78b5a36..7f37433 100644
81312--- a/net/ipv6/netfilter/ip6_tables.c
81313+++ b/net/ipv6/netfilter/ip6_tables.c
81314@@ -1173,6 +1173,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
81315 private = &tmp;
81316 }
81317 #endif
81318+ memset(&info, 0, sizeof(info));
81319 info.valid_hooks = t->valid_hooks;
81320 memcpy(info.hook_entry, private->hook_entry,
81321 sizeof(info.hook_entry));
81322diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
81323index 4f24570..b813b34 100644
81324--- a/net/ipv6/raw.c
81325+++ b/net/ipv6/raw.c
81326@@ -375,14 +375,14 @@ static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
81327 {
81328 if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
81329 skb_checksum_complete(skb)) {
81330- atomic_inc(&sk->sk_drops);
81331+ atomic_inc_unchecked(&sk->sk_drops);
81332 kfree_skb(skb);
81333 return NET_RX_DROP;
81334 }
81335
81336 /* Charge it to the socket. */
81337 if (sock_queue_rcv_skb(sk,skb)<0) {
81338- atomic_inc(&sk->sk_drops);
81339+ atomic_inc_unchecked(&sk->sk_drops);
81340 kfree_skb(skb);
81341 return NET_RX_DROP;
81342 }
81343@@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81344 struct raw6_sock *rp = raw6_sk(sk);
81345
81346 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
81347- atomic_inc(&sk->sk_drops);
81348+ atomic_inc_unchecked(&sk->sk_drops);
81349 kfree_skb(skb);
81350 return NET_RX_DROP;
81351 }
81352@@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81353
81354 if (inet->hdrincl) {
81355 if (skb_checksum_complete(skb)) {
81356- atomic_inc(&sk->sk_drops);
81357+ atomic_inc_unchecked(&sk->sk_drops);
81358 kfree_skb(skb);
81359 return NET_RX_DROP;
81360 }
81361@@ -518,7 +518,7 @@ csum_copy_err:
81362 as some normal condition.
81363 */
81364 err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
81365- atomic_inc(&sk->sk_drops);
81366+ atomic_inc_unchecked(&sk->sk_drops);
81367 goto out;
81368 }
81369
81370@@ -600,7 +600,7 @@ out:
81371 return err;
81372 }
81373
81374-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
81375+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
81376 struct flowi *fl, struct rt6_info *rt,
81377 unsigned int flags)
81378 {
81379@@ -738,6 +738,8 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
81380 u16 proto;
81381 int err;
81382
81383+ pax_track_stack();
81384+
81385 /* Rough check on arithmetic overflow,
81386 better check is made in ip6_append_data().
81387 */
81388@@ -916,12 +918,17 @@ do_confirm:
81389 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
81390 char __user *optval, int optlen)
81391 {
81392+ struct icmp6_filter filter;
81393+
81394 switch (optname) {
81395 case ICMPV6_FILTER:
81396+ if (optlen < 0)
81397+ return -EINVAL;
81398 if (optlen > sizeof(struct icmp6_filter))
81399 optlen = sizeof(struct icmp6_filter);
81400- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
81401+ if (copy_from_user(&filter, optval, optlen))
81402 return -EFAULT;
81403+ raw6_sk(sk)->filter = filter;
81404 return 0;
81405 default:
81406 return -ENOPROTOOPT;
81407@@ -934,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81408 char __user *optval, int __user *optlen)
81409 {
81410 int len;
81411+ struct icmp6_filter filter;
81412
81413 switch (optname) {
81414 case ICMPV6_FILTER:
81415@@ -945,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81416 len = sizeof(struct icmp6_filter);
81417 if (put_user(len, optlen))
81418 return -EFAULT;
81419- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
81420+ filter = raw6_sk(sk)->filter;
81421+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
81422 return -EFAULT;
81423 return 0;
81424 default:
81425@@ -1241,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81426 0, 0L, 0,
81427 sock_i_uid(sp), 0,
81428 sock_i_ino(sp),
81429- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81430+ atomic_read(&sp->sk_refcnt),
81431+#ifdef CONFIG_GRKERNSEC_HIDESYM
81432+ NULL,
81433+#else
81434+ sp,
81435+#endif
81436+ atomic_read_unchecked(&sp->sk_drops));
81437 }
81438
81439 static int raw6_seq_show(struct seq_file *seq, void *v)
81440diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
81441index faae6df..d4430c1 100644
81442--- a/net/ipv6/tcp_ipv6.c
81443+++ b/net/ipv6/tcp_ipv6.c
81444@@ -89,6 +89,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
81445 }
81446 #endif
81447
81448+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81449+extern int grsec_enable_blackhole;
81450+#endif
81451+
81452 static void tcp_v6_hash(struct sock *sk)
81453 {
81454 if (sk->sk_state != TCP_CLOSE) {
81455@@ -1579,6 +1583,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
81456 return 0;
81457
81458 reset:
81459+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81460+ if (!grsec_enable_blackhole)
81461+#endif
81462 tcp_v6_send_reset(sk, skb);
81463 discard:
81464 if (opt_skb)
81465@@ -1656,12 +1663,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
81466 TCP_SKB_CB(skb)->sacked = 0;
81467
81468 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81469- if (!sk)
81470+ if (!sk) {
81471+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81472+ ret = 1;
81473+#endif
81474 goto no_tcp_socket;
81475+ }
81476
81477 process:
81478- if (sk->sk_state == TCP_TIME_WAIT)
81479+ if (sk->sk_state == TCP_TIME_WAIT) {
81480+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81481+ ret = 2;
81482+#endif
81483 goto do_time_wait;
81484+ }
81485
81486 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
81487 goto discard_and_relse;
81488@@ -1701,6 +1716,10 @@ no_tcp_socket:
81489 bad_packet:
81490 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81491 } else {
81492+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81493+ if (!grsec_enable_blackhole || (ret == 1 &&
81494+ (skb->dev->flags & IFF_LOOPBACK)))
81495+#endif
81496 tcp_v6_send_reset(NULL, skb);
81497 }
81498
81499@@ -1916,7 +1935,13 @@ static void get_openreq6(struct seq_file *seq,
81500 uid,
81501 0, /* non standard timer */
81502 0, /* open_requests have no inode */
81503- 0, req);
81504+ 0,
81505+#ifdef CONFIG_GRKERNSEC_HIDESYM
81506+ NULL
81507+#else
81508+ req
81509+#endif
81510+ );
81511 }
81512
81513 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
81514@@ -1966,7 +1991,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
81515 sock_i_uid(sp),
81516 icsk->icsk_probes_out,
81517 sock_i_ino(sp),
81518- atomic_read(&sp->sk_refcnt), sp,
81519+ atomic_read(&sp->sk_refcnt),
81520+#ifdef CONFIG_GRKERNSEC_HIDESYM
81521+ NULL,
81522+#else
81523+ sp,
81524+#endif
81525 jiffies_to_clock_t(icsk->icsk_rto),
81526 jiffies_to_clock_t(icsk->icsk_ack.ato),
81527 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
81528@@ -2001,7 +2031,13 @@ static void get_timewait6_sock(struct seq_file *seq,
81529 dest->s6_addr32[2], dest->s6_addr32[3], destp,
81530 tw->tw_substate, 0, 0,
81531 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
81532- atomic_read(&tw->tw_refcnt), tw);
81533+ atomic_read(&tw->tw_refcnt),
81534+#ifdef CONFIG_GRKERNSEC_HIDESYM
81535+ NULL
81536+#else
81537+ tw
81538+#endif
81539+ );
81540 }
81541
81542 static int tcp6_seq_show(struct seq_file *seq, void *v)
81543diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
81544index 9cc6289..052c521 100644
81545--- a/net/ipv6/udp.c
81546+++ b/net/ipv6/udp.c
81547@@ -49,6 +49,10 @@
81548 #include <linux/seq_file.h>
81549 #include "udp_impl.h"
81550
81551+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81552+extern int grsec_enable_blackhole;
81553+#endif
81554+
81555 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
81556 {
81557 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
81558@@ -391,7 +395,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
81559 if (rc == -ENOMEM) {
81560 UDP6_INC_STATS_BH(sock_net(sk),
81561 UDP_MIB_RCVBUFERRORS, is_udplite);
81562- atomic_inc(&sk->sk_drops);
81563+ atomic_inc_unchecked(&sk->sk_drops);
81564 }
81565 goto drop;
81566 }
81567@@ -590,6 +594,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81568 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
81569 proto == IPPROTO_UDPLITE);
81570
81571+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81572+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81573+#endif
81574 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
81575
81576 kfree_skb(skb);
81577@@ -1209,8 +1216,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
81578 0, 0L, 0,
81579 sock_i_uid(sp), 0,
81580 sock_i_ino(sp),
81581- atomic_read(&sp->sk_refcnt), sp,
81582- atomic_read(&sp->sk_drops));
81583+ atomic_read(&sp->sk_refcnt),
81584+#ifdef CONFIG_GRKERNSEC_HIDESYM
81585+ NULL,
81586+#else
81587+ sp,
81588+#endif
81589+ atomic_read_unchecked(&sp->sk_drops));
81590 }
81591
81592 int udp6_seq_show(struct seq_file *seq, void *v)
81593diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
81594index 811984d..11f59b7 100644
81595--- a/net/irda/ircomm/ircomm_tty.c
81596+++ b/net/irda/ircomm/ircomm_tty.c
81597@@ -280,16 +280,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81598 add_wait_queue(&self->open_wait, &wait);
81599
81600 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
81601- __FILE__,__LINE__, tty->driver->name, self->open_count );
81602+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
81603
81604 /* As far as I can see, we protect open_count - Jean II */
81605 spin_lock_irqsave(&self->spinlock, flags);
81606 if (!tty_hung_up_p(filp)) {
81607 extra_count = 1;
81608- self->open_count--;
81609+ local_dec(&self->open_count);
81610 }
81611 spin_unlock_irqrestore(&self->spinlock, flags);
81612- self->blocked_open++;
81613+ local_inc(&self->blocked_open);
81614
81615 while (1) {
81616 if (tty->termios->c_cflag & CBAUD) {
81617@@ -329,7 +329,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81618 }
81619
81620 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
81621- __FILE__,__LINE__, tty->driver->name, self->open_count );
81622+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
81623
81624 schedule();
81625 }
81626@@ -340,13 +340,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81627 if (extra_count) {
81628 /* ++ is not atomic, so this should be protected - Jean II */
81629 spin_lock_irqsave(&self->spinlock, flags);
81630- self->open_count++;
81631+ local_inc(&self->open_count);
81632 spin_unlock_irqrestore(&self->spinlock, flags);
81633 }
81634- self->blocked_open--;
81635+ local_dec(&self->blocked_open);
81636
81637 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
81638- __FILE__,__LINE__, tty->driver->name, self->open_count);
81639+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
81640
81641 if (!retval)
81642 self->flags |= ASYNC_NORMAL_ACTIVE;
81643@@ -415,14 +415,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
81644 }
81645 /* ++ is not atomic, so this should be protected - Jean II */
81646 spin_lock_irqsave(&self->spinlock, flags);
81647- self->open_count++;
81648+ local_inc(&self->open_count);
81649
81650 tty->driver_data = self;
81651 self->tty = tty;
81652 spin_unlock_irqrestore(&self->spinlock, flags);
81653
81654 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
81655- self->line, self->open_count);
81656+ self->line, local_read(&self->open_count));
81657
81658 /* Not really used by us, but lets do it anyway */
81659 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
81660@@ -511,7 +511,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
81661 return;
81662 }
81663
81664- if ((tty->count == 1) && (self->open_count != 1)) {
81665+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
81666 /*
81667 * Uh, oh. tty->count is 1, which means that the tty
81668 * structure will be freed. state->count should always
81669@@ -521,16 +521,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
81670 */
81671 IRDA_DEBUG(0, "%s(), bad serial port count; "
81672 "tty->count is 1, state->count is %d\n", __func__ ,
81673- self->open_count);
81674- self->open_count = 1;
81675+ local_read(&self->open_count));
81676+ local_set(&self->open_count, 1);
81677 }
81678
81679- if (--self->open_count < 0) {
81680+ if (local_dec_return(&self->open_count) < 0) {
81681 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
81682- __func__, self->line, self->open_count);
81683- self->open_count = 0;
81684+ __func__, self->line, local_read(&self->open_count));
81685+ local_set(&self->open_count, 0);
81686 }
81687- if (self->open_count) {
81688+ if (local_read(&self->open_count)) {
81689 spin_unlock_irqrestore(&self->spinlock, flags);
81690
81691 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
81692@@ -562,7 +562,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
81693 tty->closing = 0;
81694 self->tty = NULL;
81695
81696- if (self->blocked_open) {
81697+ if (local_read(&self->blocked_open)) {
81698 if (self->close_delay)
81699 schedule_timeout_interruptible(self->close_delay);
81700 wake_up_interruptible(&self->open_wait);
81701@@ -1017,7 +1017,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
81702 spin_lock_irqsave(&self->spinlock, flags);
81703 self->flags &= ~ASYNC_NORMAL_ACTIVE;
81704 self->tty = NULL;
81705- self->open_count = 0;
81706+ local_set(&self->open_count, 0);
81707 spin_unlock_irqrestore(&self->spinlock, flags);
81708
81709 wake_up_interruptible(&self->open_wait);
81710@@ -1369,7 +1369,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
81711 seq_putc(m, '\n');
81712
81713 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
81714- seq_printf(m, "Open count: %d\n", self->open_count);
81715+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
81716 seq_printf(m, "Max data size: %d\n", self->max_data_size);
81717 seq_printf(m, "Max header size: %d\n", self->max_header_size);
81718
81719diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
81720index bada1b9..f325943 100644
81721--- a/net/iucv/af_iucv.c
81722+++ b/net/iucv/af_iucv.c
81723@@ -651,10 +651,10 @@ static int iucv_sock_autobind(struct sock *sk)
81724
81725 write_lock_bh(&iucv_sk_list.lock);
81726
81727- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
81728+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81729 while (__iucv_get_sock_by_name(name)) {
81730 sprintf(name, "%08x",
81731- atomic_inc_return(&iucv_sk_list.autobind_name));
81732+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81733 }
81734
81735 write_unlock_bh(&iucv_sk_list.lock);
81736diff --git a/net/key/af_key.c b/net/key/af_key.c
81737index 4e98193..439b449 100644
81738--- a/net/key/af_key.c
81739+++ b/net/key/af_key.c
81740@@ -2489,6 +2489,8 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
81741 struct xfrm_migrate m[XFRM_MAX_DEPTH];
81742 struct xfrm_kmaddress k;
81743
81744+ pax_track_stack();
81745+
81746 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
81747 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
81748 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
81749@@ -3660,7 +3662,11 @@ static int pfkey_seq_show(struct seq_file *f, void *v)
81750 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
81751 else
81752 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
81753+#ifdef CONFIG_GRKERNSEC_HIDESYM
81754+ NULL,
81755+#else
81756 s,
81757+#endif
81758 atomic_read(&s->sk_refcnt),
81759 sk_rmem_alloc_get(s),
81760 sk_wmem_alloc_get(s),
81761diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
81762index bda96d1..c038b72 100644
81763--- a/net/lapb/lapb_iface.c
81764+++ b/net/lapb/lapb_iface.c
81765@@ -157,7 +157,7 @@ int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks
81766 goto out;
81767
81768 lapb->dev = dev;
81769- lapb->callbacks = *callbacks;
81770+ lapb->callbacks = callbacks;
81771
81772 __lapb_insert_cb(lapb);
81773
81774@@ -379,32 +379,32 @@ int lapb_data_received(struct net_device *dev, struct sk_buff *skb)
81775
81776 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
81777 {
81778- if (lapb->callbacks.connect_confirmation)
81779- lapb->callbacks.connect_confirmation(lapb->dev, reason);
81780+ if (lapb->callbacks->connect_confirmation)
81781+ lapb->callbacks->connect_confirmation(lapb->dev, reason);
81782 }
81783
81784 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
81785 {
81786- if (lapb->callbacks.connect_indication)
81787- lapb->callbacks.connect_indication(lapb->dev, reason);
81788+ if (lapb->callbacks->connect_indication)
81789+ lapb->callbacks->connect_indication(lapb->dev, reason);
81790 }
81791
81792 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
81793 {
81794- if (lapb->callbacks.disconnect_confirmation)
81795- lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
81796+ if (lapb->callbacks->disconnect_confirmation)
81797+ lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
81798 }
81799
81800 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
81801 {
81802- if (lapb->callbacks.disconnect_indication)
81803- lapb->callbacks.disconnect_indication(lapb->dev, reason);
81804+ if (lapb->callbacks->disconnect_indication)
81805+ lapb->callbacks->disconnect_indication(lapb->dev, reason);
81806 }
81807
81808 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
81809 {
81810- if (lapb->callbacks.data_indication)
81811- return lapb->callbacks.data_indication(lapb->dev, skb);
81812+ if (lapb->callbacks->data_indication)
81813+ return lapb->callbacks->data_indication(lapb->dev, skb);
81814
81815 kfree_skb(skb);
81816 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
81817@@ -414,8 +414,8 @@ int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
81818 {
81819 int used = 0;
81820
81821- if (lapb->callbacks.data_transmit) {
81822- lapb->callbacks.data_transmit(lapb->dev, skb);
81823+ if (lapb->callbacks->data_transmit) {
81824+ lapb->callbacks->data_transmit(lapb->dev, skb);
81825 used = 1;
81826 }
81827
81828diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81829index fe2d3f8..e57f683 100644
81830--- a/net/mac80211/cfg.c
81831+++ b/net/mac80211/cfg.c
81832@@ -1369,7 +1369,7 @@ static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
81833 return err;
81834 }
81835
81836-struct cfg80211_ops mac80211_config_ops = {
81837+const struct cfg80211_ops mac80211_config_ops = {
81838 .add_virtual_intf = ieee80211_add_iface,
81839 .del_virtual_intf = ieee80211_del_iface,
81840 .change_virtual_intf = ieee80211_change_iface,
81841diff --git a/net/mac80211/cfg.h b/net/mac80211/cfg.h
81842index 7d7879f..2d51f62 100644
81843--- a/net/mac80211/cfg.h
81844+++ b/net/mac80211/cfg.h
81845@@ -4,6 +4,6 @@
81846 #ifndef __CFG_H
81847 #define __CFG_H
81848
81849-extern struct cfg80211_ops mac80211_config_ops;
81850+extern const struct cfg80211_ops mac80211_config_ops;
81851
81852 #endif /* __CFG_H */
81853diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
81854index 99c7525..9cb4937 100644
81855--- a/net/mac80211/debugfs_key.c
81856+++ b/net/mac80211/debugfs_key.c
81857@@ -211,9 +211,13 @@ static ssize_t key_key_read(struct file *file, char __user *userbuf,
81858 size_t count, loff_t *ppos)
81859 {
81860 struct ieee80211_key *key = file->private_data;
81861- int i, res, bufsize = 2 * key->conf.keylen + 2;
81862+ int i, bufsize = 2 * key->conf.keylen + 2;
81863 char *buf = kmalloc(bufsize, GFP_KERNEL);
81864 char *p = buf;
81865+ ssize_t res;
81866+
81867+ if (buf == NULL)
81868+ return -ENOMEM;
81869
81870 for (i = 0; i < key->conf.keylen; i++)
81871 p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
81872diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
81873index 33a2e89..08650c8 100644
81874--- a/net/mac80211/debugfs_sta.c
81875+++ b/net/mac80211/debugfs_sta.c
81876@@ -124,6 +124,8 @@ static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
81877 int i;
81878 struct sta_info *sta = file->private_data;
81879
81880+ pax_track_stack();
81881+
81882 spin_lock_bh(&sta->lock);
81883 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n",
81884 sta->ampdu_mlme.dialog_token_allocator + 1);
81885diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81886index ca62bfe..6657a03 100644
81887--- a/net/mac80211/ieee80211_i.h
81888+++ b/net/mac80211/ieee80211_i.h
81889@@ -25,6 +25,7 @@
81890 #include <linux/etherdevice.h>
81891 #include <net/cfg80211.h>
81892 #include <net/mac80211.h>
81893+#include <asm/local.h>
81894 #include "key.h"
81895 #include "sta_info.h"
81896
81897@@ -635,7 +636,7 @@ struct ieee80211_local {
81898 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81899 spinlock_t queue_stop_reason_lock;
81900
81901- int open_count;
81902+ local_t open_count;
81903 int monitors, cooked_mntrs;
81904 /* number of interfaces with corresponding FIF_ flags */
81905 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll;
81906diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
81907index 079c500..eb3c6d4 100644
81908--- a/net/mac80211/iface.c
81909+++ b/net/mac80211/iface.c
81910@@ -166,7 +166,7 @@ static int ieee80211_open(struct net_device *dev)
81911 break;
81912 }
81913
81914- if (local->open_count == 0) {
81915+ if (local_read(&local->open_count) == 0) {
81916 res = drv_start(local);
81917 if (res)
81918 goto err_del_bss;
81919@@ -196,7 +196,7 @@ static int ieee80211_open(struct net_device *dev)
81920 * Validate the MAC address for this device.
81921 */
81922 if (!is_valid_ether_addr(dev->dev_addr)) {
81923- if (!local->open_count)
81924+ if (!local_read(&local->open_count))
81925 drv_stop(local);
81926 return -EADDRNOTAVAIL;
81927 }
81928@@ -292,7 +292,7 @@ static int ieee80211_open(struct net_device *dev)
81929
81930 hw_reconf_flags |= __ieee80211_recalc_idle(local);
81931
81932- local->open_count++;
81933+ local_inc(&local->open_count);
81934 if (hw_reconf_flags) {
81935 ieee80211_hw_config(local, hw_reconf_flags);
81936 /*
81937@@ -320,7 +320,7 @@ static int ieee80211_open(struct net_device *dev)
81938 err_del_interface:
81939 drv_remove_interface(local, &conf);
81940 err_stop:
81941- if (!local->open_count)
81942+ if (!local_read(&local->open_count))
81943 drv_stop(local);
81944 err_del_bss:
81945 sdata->bss = NULL;
81946@@ -420,7 +420,7 @@ static int ieee80211_stop(struct net_device *dev)
81947 WARN_ON(!list_empty(&sdata->u.ap.vlans));
81948 }
81949
81950- local->open_count--;
81951+ local_dec(&local->open_count);
81952
81953 switch (sdata->vif.type) {
81954 case NL80211_IFTYPE_AP_VLAN:
81955@@ -526,7 +526,7 @@ static int ieee80211_stop(struct net_device *dev)
81956
81957 ieee80211_recalc_ps(local, -1);
81958
81959- if (local->open_count == 0) {
81960+ if (local_read(&local->open_count) == 0) {
81961 ieee80211_clear_tx_pending(local);
81962 ieee80211_stop_device(local);
81963
81964diff --git a/net/mac80211/main.c b/net/mac80211/main.c
81965index 2dfe176..74e4388 100644
81966--- a/net/mac80211/main.c
81967+++ b/net/mac80211/main.c
81968@@ -145,7 +145,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
81969 local->hw.conf.power_level = power;
81970 }
81971
81972- if (changed && local->open_count) {
81973+ if (changed && local_read(&local->open_count)) {
81974 ret = drv_config(local, changed);
81975 /*
81976 * Goal:
81977diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
81978index e67eea7..fcc227e 100644
81979--- a/net/mac80211/mlme.c
81980+++ b/net/mac80211/mlme.c
81981@@ -1438,6 +1438,8 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
81982 bool have_higher_than_11mbit = false, newsta = false;
81983 u16 ap_ht_cap_flags;
81984
81985+ pax_track_stack();
81986+
81987 /*
81988 * AssocResp and ReassocResp have identical structure, so process both
81989 * of them in this function.
81990diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
81991index e535f1c..4d733d1 100644
81992--- a/net/mac80211/pm.c
81993+++ b/net/mac80211/pm.c
81994@@ -107,7 +107,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
81995 }
81996
81997 /* stop hardware - this must stop RX */
81998- if (local->open_count)
81999+ if (local_read(&local->open_count))
82000 ieee80211_stop_device(local);
82001
82002 local->suspended = true;
82003diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
82004index b33efc4..0a2efb6 100644
82005--- a/net/mac80211/rate.c
82006+++ b/net/mac80211/rate.c
82007@@ -287,7 +287,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
82008 struct rate_control_ref *ref, *old;
82009
82010 ASSERT_RTNL();
82011- if (local->open_count)
82012+ if (local_read(&local->open_count))
82013 return -EBUSY;
82014
82015 ref = rate_control_alloc(name, local);
82016diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
82017index b1d7904..57e4da7 100644
82018--- a/net/mac80211/tx.c
82019+++ b/net/mac80211/tx.c
82020@@ -173,7 +173,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
82021 return cpu_to_le16(dur);
82022 }
82023
82024-static int inline is_ieee80211_device(struct ieee80211_local *local,
82025+static inline int is_ieee80211_device(struct ieee80211_local *local,
82026 struct net_device *dev)
82027 {
82028 return local == wdev_priv(dev->ieee80211_ptr);
82029diff --git a/net/mac80211/util.c b/net/mac80211/util.c
82030index 31b1085..48fb26d 100644
82031--- a/net/mac80211/util.c
82032+++ b/net/mac80211/util.c
82033@@ -1042,7 +1042,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
82034 local->resuming = true;
82035
82036 /* restart hardware */
82037- if (local->open_count) {
82038+ if (local_read(&local->open_count)) {
82039 /*
82040 * Upon resume hardware can sometimes be goofy due to
82041 * various platform / driver / bus issues, so restarting
82042diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
82043index 634d14a..b35a608 100644
82044--- a/net/netfilter/Kconfig
82045+++ b/net/netfilter/Kconfig
82046@@ -635,6 +635,16 @@ config NETFILTER_XT_MATCH_ESP
82047
82048 To compile it as a module, choose M here. If unsure, say N.
82049
82050+config NETFILTER_XT_MATCH_GRADM
82051+ tristate '"gradm" match support'
82052+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
82053+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
82054+ ---help---
82055+ The gradm match allows to match on grsecurity RBAC being enabled.
82056+ It is useful when iptables rules are applied early on bootup to
82057+ prevent connections to the machine (except from a trusted host)
82058+ while the RBAC system is disabled.
82059+
82060 config NETFILTER_XT_MATCH_HASHLIMIT
82061 tristate '"hashlimit" match support'
82062 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
82063diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
82064index 49f62ee..a17b2c6 100644
82065--- a/net/netfilter/Makefile
82066+++ b/net/netfilter/Makefile
82067@@ -68,6 +68,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRACK) += xt_conntrack.o
82068 obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
82069 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
82070 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
82071+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
82072 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
82073 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
82074 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
82075diff --git a/net/netfilter/ipvs/ip_vs_app.c b/net/netfilter/ipvs/ip_vs_app.c
82076index 3c7e427..724043c 100644
82077--- a/net/netfilter/ipvs/ip_vs_app.c
82078+++ b/net/netfilter/ipvs/ip_vs_app.c
82079@@ -564,7 +564,7 @@ static const struct file_operations ip_vs_app_fops = {
82080 .open = ip_vs_app_open,
82081 .read = seq_read,
82082 .llseek = seq_lseek,
82083- .release = seq_release,
82084+ .release = seq_release_net,
82085 };
82086 #endif
82087
82088diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
82089index 95682e5..457dbac 100644
82090--- a/net/netfilter/ipvs/ip_vs_conn.c
82091+++ b/net/netfilter/ipvs/ip_vs_conn.c
82092@@ -453,10 +453,10 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
82093 /* if the connection is not template and is created
82094 * by sync, preserve the activity flag.
82095 */
82096- cp->flags |= atomic_read(&dest->conn_flags) &
82097+ cp->flags |= atomic_read_unchecked(&dest->conn_flags) &
82098 (~IP_VS_CONN_F_INACTIVE);
82099 else
82100- cp->flags |= atomic_read(&dest->conn_flags);
82101+ cp->flags |= atomic_read_unchecked(&dest->conn_flags);
82102 cp->dest = dest;
82103
82104 IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
82105@@ -723,7 +723,7 @@ ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport,
82106 atomic_set(&cp->refcnt, 1);
82107
82108 atomic_set(&cp->n_control, 0);
82109- atomic_set(&cp->in_pkts, 0);
82110+ atomic_set_unchecked(&cp->in_pkts, 0);
82111
82112 atomic_inc(&ip_vs_conn_count);
82113 if (flags & IP_VS_CONN_F_NO_CPORT)
82114@@ -871,7 +871,7 @@ static const struct file_operations ip_vs_conn_fops = {
82115 .open = ip_vs_conn_open,
82116 .read = seq_read,
82117 .llseek = seq_lseek,
82118- .release = seq_release,
82119+ .release = seq_release_net,
82120 };
82121
82122 static const char *ip_vs_origin_name(unsigned flags)
82123@@ -934,7 +934,7 @@ static const struct file_operations ip_vs_conn_sync_fops = {
82124 .open = ip_vs_conn_sync_open,
82125 .read = seq_read,
82126 .llseek = seq_lseek,
82127- .release = seq_release,
82128+ .release = seq_release_net,
82129 };
82130
82131 #endif
82132@@ -961,7 +961,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
82133
82134 /* Don't drop the entry if its number of incoming packets is not
82135 located in [0, 8] */
82136- i = atomic_read(&cp->in_pkts);
82137+ i = atomic_read_unchecked(&cp->in_pkts);
82138 if (i > 8 || i < 0) return 0;
82139
82140 if (!todrop_rate[i]) return 0;
82141diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
82142index b95699f..5fee919 100644
82143--- a/net/netfilter/ipvs/ip_vs_core.c
82144+++ b/net/netfilter/ipvs/ip_vs_core.c
82145@@ -485,7 +485,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
82146 ret = cp->packet_xmit(skb, cp, pp);
82147 /* do not touch skb anymore */
82148
82149- atomic_inc(&cp->in_pkts);
82150+ atomic_inc_unchecked(&cp->in_pkts);
82151 ip_vs_conn_put(cp);
82152 return ret;
82153 }
82154@@ -1357,7 +1357,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb,
82155 * Sync connection if it is about to close to
82156 * encorage the standby servers to update the connections timeout
82157 */
82158- pkts = atomic_add_return(1, &cp->in_pkts);
82159+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82160 if (af == AF_INET &&
82161 (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
82162 (((cp->protocol != IPPROTO_TCP ||
82163diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
82164index 02b2610..2d89424 100644
82165--- a/net/netfilter/ipvs/ip_vs_ctl.c
82166+++ b/net/netfilter/ipvs/ip_vs_ctl.c
82167@@ -792,7 +792,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc,
82168 ip_vs_rs_hash(dest);
82169 write_unlock_bh(&__ip_vs_rs_lock);
82170 }
82171- atomic_set(&dest->conn_flags, conn_flags);
82172+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
82173
82174 /* bind the service */
82175 if (!dest->svc) {
82176@@ -1888,7 +1888,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
82177 " %-7s %-6d %-10d %-10d\n",
82178 &dest->addr.in6,
82179 ntohs(dest->port),
82180- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
82181+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
82182 atomic_read(&dest->weight),
82183 atomic_read(&dest->activeconns),
82184 atomic_read(&dest->inactconns));
82185@@ -1899,7 +1899,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
82186 "%-7s %-6d %-10d %-10d\n",
82187 ntohl(dest->addr.ip),
82188 ntohs(dest->port),
82189- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
82190+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
82191 atomic_read(&dest->weight),
82192 atomic_read(&dest->activeconns),
82193 atomic_read(&dest->inactconns));
82194@@ -1927,7 +1927,7 @@ static const struct file_operations ip_vs_info_fops = {
82195 .open = ip_vs_info_open,
82196 .read = seq_read,
82197 .llseek = seq_lseek,
82198- .release = seq_release_private,
82199+ .release = seq_release_net,
82200 };
82201
82202 #endif
82203@@ -1976,7 +1976,7 @@ static const struct file_operations ip_vs_stats_fops = {
82204 .open = ip_vs_stats_seq_open,
82205 .read = seq_read,
82206 .llseek = seq_lseek,
82207- .release = single_release,
82208+ .release = single_release_net,
82209 };
82210
82211 #endif
82212@@ -2292,7 +2292,7 @@ __ip_vs_get_dest_entries(const struct ip_vs_get_dests *get,
82213
82214 entry.addr = dest->addr.ip;
82215 entry.port = dest->port;
82216- entry.conn_flags = atomic_read(&dest->conn_flags);
82217+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
82218 entry.weight = atomic_read(&dest->weight);
82219 entry.u_threshold = dest->u_threshold;
82220 entry.l_threshold = dest->l_threshold;
82221@@ -2353,6 +2353,8 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
82222 unsigned char arg[128];
82223 int ret = 0;
82224
82225+ pax_track_stack();
82226+
82227 if (!capable(CAP_NET_ADMIN))
82228 return -EPERM;
82229
82230@@ -2802,7 +2804,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
82231 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
82232
82233 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
82234- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
82235+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
82236 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
82237 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
82238 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
82239diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
82240index e177f0d..55e8581 100644
82241--- a/net/netfilter/ipvs/ip_vs_sync.c
82242+++ b/net/netfilter/ipvs/ip_vs_sync.c
82243@@ -438,7 +438,7 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)
82244
82245 if (opt)
82246 memcpy(&cp->in_seq, opt, sizeof(*opt));
82247- atomic_set(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
82248+ atomic_set_unchecked(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
82249 cp->state = state;
82250 cp->old_state = cp->state;
82251 /*
82252diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
82253index 30b3189..e2e4b55 100644
82254--- a/net/netfilter/ipvs/ip_vs_xmit.c
82255+++ b/net/netfilter/ipvs/ip_vs_xmit.c
82256@@ -875,7 +875,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
82257 else
82258 rc = NF_ACCEPT;
82259 /* do not touch skb anymore */
82260- atomic_inc(&cp->in_pkts);
82261+ atomic_inc_unchecked(&cp->in_pkts);
82262 goto out;
82263 }
82264
82265@@ -949,7 +949,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
82266 else
82267 rc = NF_ACCEPT;
82268 /* do not touch skb anymore */
82269- atomic_inc(&cp->in_pkts);
82270+ atomic_inc_unchecked(&cp->in_pkts);
82271 goto out;
82272 }
82273
82274diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
82275index d521718..d0fd7a1 100644
82276--- a/net/netfilter/nf_conntrack_netlink.c
82277+++ b/net/netfilter/nf_conntrack_netlink.c
82278@@ -706,7 +706,7 @@ ctnetlink_parse_tuple_proto(struct nlattr *attr,
82279 static int
82280 ctnetlink_parse_tuple(const struct nlattr * const cda[],
82281 struct nf_conntrack_tuple *tuple,
82282- enum ctattr_tuple type, u_int8_t l3num)
82283+ enum ctattr_type type, u_int8_t l3num)
82284 {
82285 struct nlattr *tb[CTA_TUPLE_MAX+1];
82286 int err;
82287diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
82288index f900dc3..5e45346 100644
82289--- a/net/netfilter/nfnetlink_log.c
82290+++ b/net/netfilter/nfnetlink_log.c
82291@@ -68,7 +68,7 @@ struct nfulnl_instance {
82292 };
82293
82294 static DEFINE_RWLOCK(instances_lock);
82295-static atomic_t global_seq;
82296+static atomic_unchecked_t global_seq;
82297
82298 #define INSTANCE_BUCKETS 16
82299 static struct hlist_head instance_table[INSTANCE_BUCKETS];
82300@@ -493,7 +493,7 @@ __build_packet_message(struct nfulnl_instance *inst,
82301 /* global sequence number */
82302 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
82303 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
82304- htonl(atomic_inc_return(&global_seq)));
82305+ htonl(atomic_inc_return_unchecked(&global_seq)));
82306
82307 if (data_len) {
82308 struct nlattr *nla;
82309diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
82310new file mode 100644
82311index 0000000..b1bac76
82312--- /dev/null
82313+++ b/net/netfilter/xt_gradm.c
82314@@ -0,0 +1,51 @@
82315+/*
82316+ * gradm match for netfilter
82317