]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.2.2-2.6.32.53-201201101724.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.2.2-2.6.32.53-201201101724.patch
CommitLineData
5fa7f666
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 8472e43..c5792be 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..a558697 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,41 @@ 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+ GET_THREAD_INFO(%r11)
7917+ movl TI_sysenter_return(%r11), %r11d
7918+ CFI_REGISTER rip,r11
7919 pushq $__USER32_CS
7920 CFI_ADJUST_CFA_OFFSET 8
7921 /*CFI_REL_OFFSET cs,0*/
7922 movl %eax, %eax
7923- pushq %r10
7924+ pushq %r11
7925 CFI_ADJUST_CFA_OFFSET 8
7926 CFI_REL_OFFSET rip,0
7927 pushq %rax
7928 CFI_ADJUST_CFA_OFFSET 8
7929 cld
7930 SAVE_ARGS 0,0,1
7931+ pax_enter_kernel_user
7932+ /*
7933+ * No need to follow this irqs on/off section: the syscall
7934+ * disabled irqs, here we enable it straight after entry:
7935+ */
7936+ ENABLE_INTERRUPTS(CLBR_NONE)
7937 /* no need to do an access_ok check here because rbp has been
7938 32bit zero extended */
7939+
7940+#ifdef CONFIG_PAX_MEMORY_UDEREF
7941+ mov $PAX_USER_SHADOW_BASE,%r11
7942+ add %r11,%rbp
7943+#endif
7944+
7945 1: movl (%rbp),%ebp
7946 .section __ex_table,"a"
7947 .quad 1b,ia32_badarg
7948 .previous
7949- GET_THREAD_INFO(%r10)
7950- orl $TS_COMPAT,TI_status(%r10)
7951- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
7952+ GET_THREAD_INFO(%r11)
7953+ orl $TS_COMPAT,TI_status(%r11)
7954+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
7955 CFI_REMEMBER_STATE
7956 jnz sysenter_tracesys
7957 cmpq $(IA32_NR_syscalls-1),%rax
7958@@ -166,13 +201,15 @@ sysenter_do_call:
7959 sysenter_dispatch:
7960 call *ia32_sys_call_table(,%rax,8)
7961 movq %rax,RAX-ARGOFFSET(%rsp)
7962- GET_THREAD_INFO(%r10)
7963+ GET_THREAD_INFO(%r11)
7964 DISABLE_INTERRUPTS(CLBR_NONE)
7965 TRACE_IRQS_OFF
7966- testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
7967+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
7968 jnz sysexit_audit
7969 sysexit_from_sys_call:
7970- andl $~TS_COMPAT,TI_status(%r10)
7971+ pax_exit_kernel_user
7972+ pax_erase_kstack
7973+ andl $~TS_COMPAT,TI_status(%r11)
7974 /* clear IF, that popfq doesn't enable interrupts early */
7975 andl $~0x200,EFLAGS-R11(%rsp)
7976 movl RIP-R11(%rsp),%edx /* User %eip */
7977@@ -200,6 +237,9 @@ sysexit_from_sys_call:
7978 movl %eax,%esi /* 2nd arg: syscall number */
7979 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
7980 call audit_syscall_entry
7981+
7982+ pax_erase_kstack
7983+
7984 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
7985 cmpq $(IA32_NR_syscalls-1),%rax
7986 ja ia32_badsys
7987@@ -211,7 +251,7 @@ sysexit_from_sys_call:
7988 .endm
7989
7990 .macro auditsys_exit exit
7991- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
7992+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
7993 jnz ia32_ret_from_sys_call
7994 TRACE_IRQS_ON
7995 sti
7996@@ -221,12 +261,12 @@ sysexit_from_sys_call:
7997 movzbl %al,%edi /* zero-extend that into %edi */
7998 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
7999 call audit_syscall_exit
8000- GET_THREAD_INFO(%r10)
8001+ GET_THREAD_INFO(%r11)
8002 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
8003 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8004 cli
8005 TRACE_IRQS_OFF
8006- testl %edi,TI_flags(%r10)
8007+ testl %edi,TI_flags(%r11)
8008 jz \exit
8009 CLEAR_RREGS -ARGOFFSET
8010 jmp int_with_check
8011@@ -244,7 +284,7 @@ sysexit_audit:
8012
8013 sysenter_tracesys:
8014 #ifdef CONFIG_AUDITSYSCALL
8015- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8016+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8017 jz sysenter_auditsys
8018 #endif
8019 SAVE_REST
8020@@ -252,6 +292,9 @@ sysenter_tracesys:
8021 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8022 movq %rsp,%rdi /* &pt_regs -> arg1 */
8023 call syscall_trace_enter
8024+
8025+ pax_erase_kstack
8026+
8027 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8028 RESTORE_REST
8029 cmpq $(IA32_NR_syscalls-1),%rax
8030@@ -283,19 +326,20 @@ ENDPROC(ia32_sysenter_target)
8031 ENTRY(ia32_cstar_target)
8032 CFI_STARTPROC32 simple
8033 CFI_SIGNAL_FRAME
8034- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8035+ CFI_DEF_CFA rsp,0
8036 CFI_REGISTER rip,rcx
8037 /*CFI_REGISTER rflags,r11*/
8038 SWAPGS_UNSAFE_STACK
8039 movl %esp,%r8d
8040 CFI_REGISTER rsp,r8
8041 movq PER_CPU_VAR(kernel_stack),%rsp
8042+ SAVE_ARGS 8*6,1,1
8043+ pax_enter_kernel_user
8044 /*
8045 * No need to follow this irqs on/off section: the syscall
8046 * disabled irqs and here we enable it straight after entry:
8047 */
8048 ENABLE_INTERRUPTS(CLBR_NONE)
8049- SAVE_ARGS 8,1,1
8050 movl %eax,%eax /* zero extension */
8051 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8052 movq %rcx,RIP-ARGOFFSET(%rsp)
8053@@ -311,13 +355,19 @@ ENTRY(ia32_cstar_target)
8054 /* no need to do an access_ok check here because r8 has been
8055 32bit zero extended */
8056 /* hardware stack frame is complete now */
8057+
8058+#ifdef CONFIG_PAX_MEMORY_UDEREF
8059+ mov $PAX_USER_SHADOW_BASE,%r11
8060+ add %r11,%r8
8061+#endif
8062+
8063 1: movl (%r8),%r9d
8064 .section __ex_table,"a"
8065 .quad 1b,ia32_badarg
8066 .previous
8067- GET_THREAD_INFO(%r10)
8068- orl $TS_COMPAT,TI_status(%r10)
8069- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8070+ GET_THREAD_INFO(%r11)
8071+ orl $TS_COMPAT,TI_status(%r11)
8072+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8073 CFI_REMEMBER_STATE
8074 jnz cstar_tracesys
8075 cmpq $IA32_NR_syscalls-1,%rax
8076@@ -327,13 +377,15 @@ cstar_do_call:
8077 cstar_dispatch:
8078 call *ia32_sys_call_table(,%rax,8)
8079 movq %rax,RAX-ARGOFFSET(%rsp)
8080- GET_THREAD_INFO(%r10)
8081+ GET_THREAD_INFO(%r11)
8082 DISABLE_INTERRUPTS(CLBR_NONE)
8083 TRACE_IRQS_OFF
8084- testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
8085+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8086 jnz sysretl_audit
8087 sysretl_from_sys_call:
8088- andl $~TS_COMPAT,TI_status(%r10)
8089+ pax_exit_kernel_user
8090+ pax_erase_kstack
8091+ andl $~TS_COMPAT,TI_status(%r11)
8092 RESTORE_ARGS 1,-ARG_SKIP,1,1,1
8093 movl RIP-ARGOFFSET(%rsp),%ecx
8094 CFI_REGISTER rip,rcx
8095@@ -361,7 +413,7 @@ sysretl_audit:
8096
8097 cstar_tracesys:
8098 #ifdef CONFIG_AUDITSYSCALL
8099- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
8100+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8101 jz cstar_auditsys
8102 #endif
8103 xchgl %r9d,%ebp
8104@@ -370,6 +422,9 @@ cstar_tracesys:
8105 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8106 movq %rsp,%rdi /* &pt_regs -> arg1 */
8107 call syscall_trace_enter
8108+
8109+ pax_erase_kstack
8110+
8111 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8112 RESTORE_REST
8113 xchgl %ebp,%r9d
8114@@ -415,11 +470,6 @@ ENTRY(ia32_syscall)
8115 CFI_REL_OFFSET rip,RIP-RIP
8116 PARAVIRT_ADJUST_EXCEPTION_FRAME
8117 SWAPGS
8118- /*
8119- * No need to follow this irqs on/off section: the syscall
8120- * disabled irqs and here we enable it straight after entry:
8121- */
8122- ENABLE_INTERRUPTS(CLBR_NONE)
8123 movl %eax,%eax
8124 pushq %rax
8125 CFI_ADJUST_CFA_OFFSET 8
8126@@ -427,9 +477,15 @@ ENTRY(ia32_syscall)
8127 /* note the registers are not zero extended to the sf.
8128 this could be a problem. */
8129 SAVE_ARGS 0,0,1
8130- GET_THREAD_INFO(%r10)
8131- orl $TS_COMPAT,TI_status(%r10)
8132- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
8133+ pax_enter_kernel_user
8134+ /*
8135+ * No need to follow this irqs on/off section: the syscall
8136+ * disabled irqs and here we enable it straight after entry:
8137+ */
8138+ ENABLE_INTERRUPTS(CLBR_NONE)
8139+ GET_THREAD_INFO(%r11)
8140+ orl $TS_COMPAT,TI_status(%r11)
8141+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8142 jnz ia32_tracesys
8143 cmpq $(IA32_NR_syscalls-1),%rax
8144 ja ia32_badsys
8145@@ -448,6 +504,9 @@ ia32_tracesys:
8146 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8147 movq %rsp,%rdi /* &pt_regs -> arg1 */
8148 call syscall_trace_enter
8149+
8150+ pax_erase_kstack
8151+
8152 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8153 RESTORE_REST
8154 cmpq $(IA32_NR_syscalls-1),%rax
8155@@ -462,6 +521,7 @@ ia32_badsys:
8156
8157 quiet_ni_syscall:
8158 movq $-ENOSYS,%rax
8159+ pax_force_retaddr
8160 ret
8161 CFI_ENDPROC
8162
8163diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8164index 016218c..47ccbdd 100644
8165--- a/arch/x86/ia32/sys_ia32.c
8166+++ b/arch/x86/ia32/sys_ia32.c
8167@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8168 */
8169 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8170 {
8171- typeof(ubuf->st_uid) uid = 0;
8172- typeof(ubuf->st_gid) gid = 0;
8173+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8174+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8175 SET_UID(uid, stat->uid);
8176 SET_GID(gid, stat->gid);
8177 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8178@@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8179 }
8180 set_fs(KERNEL_DS);
8181 ret = sys_rt_sigprocmask(how,
8182- set ? (sigset_t __user *)&s : NULL,
8183- oset ? (sigset_t __user *)&s : NULL,
8184+ set ? (sigset_t __force_user *)&s : NULL,
8185+ oset ? (sigset_t __force_user *)&s : NULL,
8186 sigsetsize);
8187 set_fs(old_fs);
8188 if (ret)
8189@@ -371,7 +371,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8190 mm_segment_t old_fs = get_fs();
8191
8192 set_fs(KERNEL_DS);
8193- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8194+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8195 set_fs(old_fs);
8196 if (put_compat_timespec(&t, interval))
8197 return -EFAULT;
8198@@ -387,7 +387,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8199 mm_segment_t old_fs = get_fs();
8200
8201 set_fs(KERNEL_DS);
8202- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8203+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8204 set_fs(old_fs);
8205 if (!ret) {
8206 switch (_NSIG_WORDS) {
8207@@ -412,7 +412,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8208 if (copy_siginfo_from_user32(&info, uinfo))
8209 return -EFAULT;
8210 set_fs(KERNEL_DS);
8211- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8212+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8213 set_fs(old_fs);
8214 return ret;
8215 }
8216@@ -513,7 +513,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8217 return -EFAULT;
8218
8219 set_fs(KERNEL_DS);
8220- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8221+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8222 count);
8223 set_fs(old_fs);
8224
8225diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8226index e2077d3..b7a8919 100644
8227--- a/arch/x86/include/asm/alternative-asm.h
8228+++ b/arch/x86/include/asm/alternative-asm.h
8229@@ -8,10 +8,10 @@
8230
8231 #ifdef CONFIG_SMP
8232 .macro LOCK_PREFIX
8233-1: lock
8234+672: lock
8235 .section .smp_locks,"a"
8236 .align 4
8237- X86_ALIGN 1b
8238+ X86_ALIGN 672b
8239 .previous
8240 .endm
8241 #else
8242@@ -19,4 +19,43 @@
8243 .endm
8244 #endif
8245
8246+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
8247+ .macro pax_force_retaddr_bts rip=0
8248+ btsq $63,\rip(%rsp)
8249+ .endm
8250+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8251+ .macro pax_force_retaddr rip=0, reload=0
8252+ btsq $63,\rip(%rsp)
8253+ .endm
8254+ .macro pax_force_fptr ptr
8255+ btsq $63,\ptr
8256+ .endm
8257+ .macro pax_set_fptr_mask
8258+ .endm
8259+#endif
8260+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8261+ .macro pax_force_retaddr rip=0, reload=0
8262+ .if \reload
8263+ pax_set_fptr_mask
8264+ .endif
8265+ orq %r10,\rip(%rsp)
8266+ .endm
8267+ .macro pax_force_fptr ptr
8268+ orq %r10,\ptr
8269+ .endm
8270+ .macro pax_set_fptr_mask
8271+ movabs $0x8000000000000000,%r10
8272+ .endm
8273+#endif
8274+#else
8275+ .macro pax_force_retaddr rip=0, reload=0
8276+ .endm
8277+ .macro pax_force_fptr ptr
8278+ .endm
8279+ .macro pax_force_retaddr_bts rip=0
8280+ .endm
8281+ .macro pax_set_fptr_mask
8282+ .endm
8283+#endif
8284+
8285 #endif /* __ASSEMBLY__ */
8286diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8287index c240efc..fdfadf3 100644
8288--- a/arch/x86/include/asm/alternative.h
8289+++ b/arch/x86/include/asm/alternative.h
8290@@ -85,7 +85,7 @@ static inline void alternatives_smp_switch(int smp) {}
8291 " .byte 662b-661b\n" /* sourcelen */ \
8292 " .byte 664f-663f\n" /* replacementlen */ \
8293 ".previous\n" \
8294- ".section .altinstr_replacement, \"ax\"\n" \
8295+ ".section .altinstr_replacement, \"a\"\n" \
8296 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8297 ".previous"
8298
8299diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8300index 474d80d..1f97d58 100644
8301--- a/arch/x86/include/asm/apic.h
8302+++ b/arch/x86/include/asm/apic.h
8303@@ -46,7 +46,7 @@ static inline void generic_apic_probe(void)
8304
8305 #ifdef CONFIG_X86_LOCAL_APIC
8306
8307-extern unsigned int apic_verbosity;
8308+extern int apic_verbosity;
8309 extern int local_apic_timer_c2_ok;
8310
8311 extern int disable_apic;
8312diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
8313index 20370c6..a2eb9b0 100644
8314--- a/arch/x86/include/asm/apm.h
8315+++ b/arch/x86/include/asm/apm.h
8316@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
8317 __asm__ __volatile__(APM_DO_ZERO_SEGS
8318 "pushl %%edi\n\t"
8319 "pushl %%ebp\n\t"
8320- "lcall *%%cs:apm_bios_entry\n\t"
8321+ "lcall *%%ss:apm_bios_entry\n\t"
8322 "setc %%al\n\t"
8323 "popl %%ebp\n\t"
8324 "popl %%edi\n\t"
8325@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
8326 __asm__ __volatile__(APM_DO_ZERO_SEGS
8327 "pushl %%edi\n\t"
8328 "pushl %%ebp\n\t"
8329- "lcall *%%cs:apm_bios_entry\n\t"
8330+ "lcall *%%ss:apm_bios_entry\n\t"
8331 "setc %%bl\n\t"
8332 "popl %%ebp\n\t"
8333 "popl %%edi\n\t"
8334diff --git a/arch/x86/include/asm/atomic_32.h b/arch/x86/include/asm/atomic_32.h
8335index dc5a667..939040c 100644
8336--- a/arch/x86/include/asm/atomic_32.h
8337+++ b/arch/x86/include/asm/atomic_32.h
8338@@ -25,6 +25,17 @@ static inline int atomic_read(const atomic_t *v)
8339 }
8340
8341 /**
8342+ * atomic_read_unchecked - read atomic variable
8343+ * @v: pointer of type atomic_unchecked_t
8344+ *
8345+ * Atomically reads the value of @v.
8346+ */
8347+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8348+{
8349+ return v->counter;
8350+}
8351+
8352+/**
8353 * atomic_set - set atomic variable
8354 * @v: pointer of type atomic_t
8355 * @i: required value
8356@@ -37,6 +48,18 @@ static inline void atomic_set(atomic_t *v, int i)
8357 }
8358
8359 /**
8360+ * atomic_set_unchecked - set atomic variable
8361+ * @v: pointer of type atomic_unchecked_t
8362+ * @i: required value
8363+ *
8364+ * Atomically sets the value of @v to @i.
8365+ */
8366+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8367+{
8368+ v->counter = i;
8369+}
8370+
8371+/**
8372 * atomic_add - add integer to atomic variable
8373 * @i: integer value to add
8374 * @v: pointer of type atomic_t
8375@@ -45,7 +68,29 @@ static inline void atomic_set(atomic_t *v, int i)
8376 */
8377 static inline void atomic_add(int i, atomic_t *v)
8378 {
8379- asm volatile(LOCK_PREFIX "addl %1,%0"
8380+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8381+
8382+#ifdef CONFIG_PAX_REFCOUNT
8383+ "jno 0f\n"
8384+ LOCK_PREFIX "subl %1,%0\n"
8385+ "int $4\n0:\n"
8386+ _ASM_EXTABLE(0b, 0b)
8387+#endif
8388+
8389+ : "+m" (v->counter)
8390+ : "ir" (i));
8391+}
8392+
8393+/**
8394+ * atomic_add_unchecked - add integer to atomic variable
8395+ * @i: integer value to add
8396+ * @v: pointer of type atomic_unchecked_t
8397+ *
8398+ * Atomically adds @i to @v.
8399+ */
8400+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8401+{
8402+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8403 : "+m" (v->counter)
8404 : "ir" (i));
8405 }
8406@@ -59,7 +104,29 @@ static inline void atomic_add(int i, atomic_t *v)
8407 */
8408 static inline void atomic_sub(int i, atomic_t *v)
8409 {
8410- asm volatile(LOCK_PREFIX "subl %1,%0"
8411+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8412+
8413+#ifdef CONFIG_PAX_REFCOUNT
8414+ "jno 0f\n"
8415+ LOCK_PREFIX "addl %1,%0\n"
8416+ "int $4\n0:\n"
8417+ _ASM_EXTABLE(0b, 0b)
8418+#endif
8419+
8420+ : "+m" (v->counter)
8421+ : "ir" (i));
8422+}
8423+
8424+/**
8425+ * atomic_sub_unchecked - subtract integer from atomic variable
8426+ * @i: integer value to subtract
8427+ * @v: pointer of type atomic_unchecked_t
8428+ *
8429+ * Atomically subtracts @i from @v.
8430+ */
8431+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8432+{
8433+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8434 : "+m" (v->counter)
8435 : "ir" (i));
8436 }
8437@@ -77,7 +144,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8438 {
8439 unsigned char c;
8440
8441- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8442+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
8443+
8444+#ifdef CONFIG_PAX_REFCOUNT
8445+ "jno 0f\n"
8446+ LOCK_PREFIX "addl %2,%0\n"
8447+ "int $4\n0:\n"
8448+ _ASM_EXTABLE(0b, 0b)
8449+#endif
8450+
8451+ "sete %1\n"
8452 : "+m" (v->counter), "=qm" (c)
8453 : "ir" (i) : "memory");
8454 return c;
8455@@ -91,7 +167,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8456 */
8457 static inline void atomic_inc(atomic_t *v)
8458 {
8459- asm volatile(LOCK_PREFIX "incl %0"
8460+ asm volatile(LOCK_PREFIX "incl %0\n"
8461+
8462+#ifdef CONFIG_PAX_REFCOUNT
8463+ "jno 0f\n"
8464+ LOCK_PREFIX "decl %0\n"
8465+ "int $4\n0:\n"
8466+ _ASM_EXTABLE(0b, 0b)
8467+#endif
8468+
8469+ : "+m" (v->counter));
8470+}
8471+
8472+/**
8473+ * atomic_inc_unchecked - increment atomic variable
8474+ * @v: pointer of type atomic_unchecked_t
8475+ *
8476+ * Atomically increments @v by 1.
8477+ */
8478+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8479+{
8480+ asm volatile(LOCK_PREFIX "incl %0\n"
8481 : "+m" (v->counter));
8482 }
8483
8484@@ -103,7 +199,27 @@ static inline void atomic_inc(atomic_t *v)
8485 */
8486 static inline void atomic_dec(atomic_t *v)
8487 {
8488- asm volatile(LOCK_PREFIX "decl %0"
8489+ asm volatile(LOCK_PREFIX "decl %0\n"
8490+
8491+#ifdef CONFIG_PAX_REFCOUNT
8492+ "jno 0f\n"
8493+ LOCK_PREFIX "incl %0\n"
8494+ "int $4\n0:\n"
8495+ _ASM_EXTABLE(0b, 0b)
8496+#endif
8497+
8498+ : "+m" (v->counter));
8499+}
8500+
8501+/**
8502+ * atomic_dec_unchecked - decrement atomic variable
8503+ * @v: pointer of type atomic_unchecked_t
8504+ *
8505+ * Atomically decrements @v by 1.
8506+ */
8507+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8508+{
8509+ asm volatile(LOCK_PREFIX "decl %0\n"
8510 : "+m" (v->counter));
8511 }
8512
8513@@ -119,7 +235,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
8514 {
8515 unsigned char c;
8516
8517- asm volatile(LOCK_PREFIX "decl %0; sete %1"
8518+ asm volatile(LOCK_PREFIX "decl %0\n"
8519+
8520+#ifdef CONFIG_PAX_REFCOUNT
8521+ "jno 0f\n"
8522+ LOCK_PREFIX "incl %0\n"
8523+ "int $4\n0:\n"
8524+ _ASM_EXTABLE(0b, 0b)
8525+#endif
8526+
8527+ "sete %1\n"
8528 : "+m" (v->counter), "=qm" (c)
8529 : : "memory");
8530 return c != 0;
8531@@ -137,7 +262,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
8532 {
8533 unsigned char c;
8534
8535- asm volatile(LOCK_PREFIX "incl %0; sete %1"
8536+ asm volatile(LOCK_PREFIX "incl %0\n"
8537+
8538+#ifdef CONFIG_PAX_REFCOUNT
8539+ "jno 0f\n"
8540+ LOCK_PREFIX "decl %0\n"
8541+ "into\n0:\n"
8542+ _ASM_EXTABLE(0b, 0b)
8543+#endif
8544+
8545+ "sete %1\n"
8546+ : "+m" (v->counter), "=qm" (c)
8547+ : : "memory");
8548+ return c != 0;
8549+}
8550+
8551+/**
8552+ * atomic_inc_and_test_unchecked - increment and test
8553+ * @v: pointer of type atomic_unchecked_t
8554+ *
8555+ * Atomically increments @v by 1
8556+ * and returns true if the result is zero, or false for all
8557+ * other cases.
8558+ */
8559+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8560+{
8561+ unsigned char c;
8562+
8563+ asm volatile(LOCK_PREFIX "incl %0\n"
8564+ "sete %1\n"
8565 : "+m" (v->counter), "=qm" (c)
8566 : : "memory");
8567 return c != 0;
8568@@ -156,7 +309,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
8569 {
8570 unsigned char c;
8571
8572- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
8573+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
8574+
8575+#ifdef CONFIG_PAX_REFCOUNT
8576+ "jno 0f\n"
8577+ LOCK_PREFIX "subl %2,%0\n"
8578+ "int $4\n0:\n"
8579+ _ASM_EXTABLE(0b, 0b)
8580+#endif
8581+
8582+ "sets %1\n"
8583 : "+m" (v->counter), "=qm" (c)
8584 : "ir" (i) : "memory");
8585 return c;
8586@@ -179,7 +341,15 @@ static inline int atomic_add_return(int i, atomic_t *v)
8587 #endif
8588 /* Modern 486+ processor */
8589 __i = i;
8590- asm volatile(LOCK_PREFIX "xaddl %0, %1"
8591+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
8592+
8593+#ifdef CONFIG_PAX_REFCOUNT
8594+ "jno 0f\n"
8595+ "movl %0, %1\n"
8596+ "int $4\n0:\n"
8597+ _ASM_EXTABLE(0b, 0b)
8598+#endif
8599+
8600 : "+r" (i), "+m" (v->counter)
8601 : : "memory");
8602 return i + __i;
8603@@ -195,6 +365,38 @@ no_xadd: /* Legacy 386 processor */
8604 }
8605
8606 /**
8607+ * atomic_add_return_unchecked - add integer and return
8608+ * @v: pointer of type atomic_unchecked_t
8609+ * @i: integer value to add
8610+ *
8611+ * Atomically adds @i to @v and returns @i + @v
8612+ */
8613+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8614+{
8615+ int __i;
8616+#ifdef CONFIG_M386
8617+ unsigned long flags;
8618+ if (unlikely(boot_cpu_data.x86 <= 3))
8619+ goto no_xadd;
8620+#endif
8621+ /* Modern 486+ processor */
8622+ __i = i;
8623+ asm volatile(LOCK_PREFIX "xaddl %0, %1"
8624+ : "+r" (i), "+m" (v->counter)
8625+ : : "memory");
8626+ return i + __i;
8627+
8628+#ifdef CONFIG_M386
8629+no_xadd: /* Legacy 386 processor */
8630+ local_irq_save(flags);
8631+ __i = atomic_read_unchecked(v);
8632+ atomic_set_unchecked(v, i + __i);
8633+ local_irq_restore(flags);
8634+ return i + __i;
8635+#endif
8636+}
8637+
8638+/**
8639 * atomic_sub_return - subtract integer and return
8640 * @v: pointer of type atomic_t
8641 * @i: integer value to subtract
8642@@ -211,11 +413,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
8643 return cmpxchg(&v->counter, old, new);
8644 }
8645
8646+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8647+{
8648+ return cmpxchg(&v->counter, old, new);
8649+}
8650+
8651 static inline int atomic_xchg(atomic_t *v, int new)
8652 {
8653 return xchg(&v->counter, new);
8654 }
8655
8656+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8657+{
8658+ return xchg(&v->counter, new);
8659+}
8660+
8661 /**
8662 * atomic_add_unless - add unless the number is already a given value
8663 * @v: pointer of type atomic_t
8664@@ -227,22 +439,39 @@ static inline int atomic_xchg(atomic_t *v, int new)
8665 */
8666 static inline int atomic_add_unless(atomic_t *v, int a, int u)
8667 {
8668- int c, old;
8669+ int c, old, new;
8670 c = atomic_read(v);
8671 for (;;) {
8672- if (unlikely(c == (u)))
8673+ if (unlikely(c == u))
8674 break;
8675- old = atomic_cmpxchg((v), c, c + (a));
8676+
8677+ asm volatile("addl %2,%0\n"
8678+
8679+#ifdef CONFIG_PAX_REFCOUNT
8680+ "jno 0f\n"
8681+ "subl %2,%0\n"
8682+ "int $4\n0:\n"
8683+ _ASM_EXTABLE(0b, 0b)
8684+#endif
8685+
8686+ : "=r" (new)
8687+ : "0" (c), "ir" (a));
8688+
8689+ old = atomic_cmpxchg(v, c, new);
8690 if (likely(old == c))
8691 break;
8692 c = old;
8693 }
8694- return c != (u);
8695+ return c != u;
8696 }
8697
8698 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
8699
8700 #define atomic_inc_return(v) (atomic_add_return(1, v))
8701+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8702+{
8703+ return atomic_add_return_unchecked(1, v);
8704+}
8705 #define atomic_dec_return(v) (atomic_sub_return(1, v))
8706
8707 /* These are x86-specific, used by some header files */
8708@@ -266,9 +495,18 @@ typedef struct {
8709 u64 __aligned(8) counter;
8710 } atomic64_t;
8711
8712+#ifdef CONFIG_PAX_REFCOUNT
8713+typedef struct {
8714+ u64 __aligned(8) counter;
8715+} atomic64_unchecked_t;
8716+#else
8717+typedef atomic64_t atomic64_unchecked_t;
8718+#endif
8719+
8720 #define ATOMIC64_INIT(val) { (val) }
8721
8722 extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
8723+extern u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val);
8724
8725 /**
8726 * atomic64_xchg - xchg atomic64 variable
8727@@ -279,6 +517,7 @@ extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
8728 * the old value.
8729 */
8730 extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
8731+extern u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
8732
8733 /**
8734 * atomic64_set - set atomic64 variable
8735@@ -290,6 +529,15 @@ extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
8736 extern void atomic64_set(atomic64_t *ptr, u64 new_val);
8737
8738 /**
8739+ * atomic64_unchecked_set - set atomic64 variable
8740+ * @ptr: pointer to type atomic64_unchecked_t
8741+ * @new_val: value to assign
8742+ *
8743+ * Atomically sets the value of @ptr to @new_val.
8744+ */
8745+extern void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val);
8746+
8747+/**
8748 * atomic64_read - read atomic64 variable
8749 * @ptr: pointer to type atomic64_t
8750 *
8751@@ -317,7 +565,33 @@ static inline u64 atomic64_read(atomic64_t *ptr)
8752 return res;
8753 }
8754
8755-extern u64 atomic64_read(atomic64_t *ptr);
8756+/**
8757+ * atomic64_read_unchecked - read atomic64 variable
8758+ * @ptr: pointer to type atomic64_unchecked_t
8759+ *
8760+ * Atomically reads the value of @ptr and returns it.
8761+ */
8762+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *ptr)
8763+{
8764+ u64 res;
8765+
8766+ /*
8767+ * Note, we inline this atomic64_unchecked_t primitive because
8768+ * it only clobbers EAX/EDX and leaves the others
8769+ * untouched. We also (somewhat subtly) rely on the
8770+ * fact that cmpxchg8b returns the current 64-bit value
8771+ * of the memory location we are touching:
8772+ */
8773+ asm volatile(
8774+ "mov %%ebx, %%eax\n\t"
8775+ "mov %%ecx, %%edx\n\t"
8776+ LOCK_PREFIX "cmpxchg8b %1\n"
8777+ : "=&A" (res)
8778+ : "m" (*ptr)
8779+ );
8780+
8781+ return res;
8782+}
8783
8784 /**
8785 * atomic64_add_return - add and return
8786@@ -332,8 +606,11 @@ extern u64 atomic64_add_return(u64 delta, atomic64_t *ptr);
8787 * Other variants with different arithmetic operators:
8788 */
8789 extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr);
8790+extern u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8791 extern u64 atomic64_inc_return(atomic64_t *ptr);
8792+extern u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr);
8793 extern u64 atomic64_dec_return(atomic64_t *ptr);
8794+extern u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr);
8795
8796 /**
8797 * atomic64_add - add integer to atomic64 variable
8798@@ -345,6 +622,15 @@ extern u64 atomic64_dec_return(atomic64_t *ptr);
8799 extern void atomic64_add(u64 delta, atomic64_t *ptr);
8800
8801 /**
8802+ * atomic64_add_unchecked - add integer to atomic64 variable
8803+ * @delta: integer value to add
8804+ * @ptr: pointer to type atomic64_unchecked_t
8805+ *
8806+ * Atomically adds @delta to @ptr.
8807+ */
8808+extern void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8809+
8810+/**
8811 * atomic64_sub - subtract the atomic64 variable
8812 * @delta: integer value to subtract
8813 * @ptr: pointer to type atomic64_t
8814@@ -354,6 +640,15 @@ extern void atomic64_add(u64 delta, atomic64_t *ptr);
8815 extern void atomic64_sub(u64 delta, atomic64_t *ptr);
8816
8817 /**
8818+ * atomic64_sub_unchecked - subtract the atomic64 variable
8819+ * @delta: integer value to subtract
8820+ * @ptr: pointer to type atomic64_unchecked_t
8821+ *
8822+ * Atomically subtracts @delta from @ptr.
8823+ */
8824+extern void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr);
8825+
8826+/**
8827 * atomic64_sub_and_test - subtract value from variable and test result
8828 * @delta: integer value to subtract
8829 * @ptr: pointer to type atomic64_t
8830@@ -373,6 +668,14 @@ extern int atomic64_sub_and_test(u64 delta, atomic64_t *ptr);
8831 extern void atomic64_inc(atomic64_t *ptr);
8832
8833 /**
8834+ * atomic64_inc_unchecked - increment atomic64 variable
8835+ * @ptr: pointer to type atomic64_unchecked_t
8836+ *
8837+ * Atomically increments @ptr by 1.
8838+ */
8839+extern void atomic64_inc_unchecked(atomic64_unchecked_t *ptr);
8840+
8841+/**
8842 * atomic64_dec - decrement atomic64 variable
8843 * @ptr: pointer to type atomic64_t
8844 *
8845@@ -381,6 +684,14 @@ extern void atomic64_inc(atomic64_t *ptr);
8846 extern void atomic64_dec(atomic64_t *ptr);
8847
8848 /**
8849+ * atomic64_dec_unchecked - decrement atomic64 variable
8850+ * @ptr: pointer to type atomic64_unchecked_t
8851+ *
8852+ * Atomically decrements @ptr by 1.
8853+ */
8854+extern void atomic64_dec_unchecked(atomic64_unchecked_t *ptr);
8855+
8856+/**
8857 * atomic64_dec_and_test - decrement and test
8858 * @ptr: pointer to type atomic64_t
8859 *
8860diff --git a/arch/x86/include/asm/atomic_64.h b/arch/x86/include/asm/atomic_64.h
8861index d605dc2..fafd7bd 100644
8862--- a/arch/x86/include/asm/atomic_64.h
8863+++ b/arch/x86/include/asm/atomic_64.h
8864@@ -24,6 +24,17 @@ static inline int atomic_read(const atomic_t *v)
8865 }
8866
8867 /**
8868+ * atomic_read_unchecked - read atomic variable
8869+ * @v: pointer of type atomic_unchecked_t
8870+ *
8871+ * Atomically reads the value of @v.
8872+ */
8873+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8874+{
8875+ return v->counter;
8876+}
8877+
8878+/**
8879 * atomic_set - set atomic variable
8880 * @v: pointer of type atomic_t
8881 * @i: required value
8882@@ -36,6 +47,18 @@ static inline void atomic_set(atomic_t *v, int i)
8883 }
8884
8885 /**
8886+ * atomic_set_unchecked - set atomic variable
8887+ * @v: pointer of type atomic_unchecked_t
8888+ * @i: required value
8889+ *
8890+ * Atomically sets the value of @v to @i.
8891+ */
8892+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8893+{
8894+ v->counter = i;
8895+}
8896+
8897+/**
8898 * atomic_add - add integer to atomic variable
8899 * @i: integer value to add
8900 * @v: pointer of type atomic_t
8901@@ -44,7 +67,29 @@ static inline void atomic_set(atomic_t *v, int i)
8902 */
8903 static inline void atomic_add(int i, atomic_t *v)
8904 {
8905- asm volatile(LOCK_PREFIX "addl %1,%0"
8906+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8907+
8908+#ifdef CONFIG_PAX_REFCOUNT
8909+ "jno 0f\n"
8910+ LOCK_PREFIX "subl %1,%0\n"
8911+ "int $4\n0:\n"
8912+ _ASM_EXTABLE(0b, 0b)
8913+#endif
8914+
8915+ : "=m" (v->counter)
8916+ : "ir" (i), "m" (v->counter));
8917+}
8918+
8919+/**
8920+ * atomic_add_unchecked - add integer to atomic variable
8921+ * @i: integer value to add
8922+ * @v: pointer of type atomic_unchecked_t
8923+ *
8924+ * Atomically adds @i to @v.
8925+ */
8926+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
8927+{
8928+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
8929 : "=m" (v->counter)
8930 : "ir" (i), "m" (v->counter));
8931 }
8932@@ -58,7 +103,29 @@ static inline void atomic_add(int i, atomic_t *v)
8933 */
8934 static inline void atomic_sub(int i, atomic_t *v)
8935 {
8936- asm volatile(LOCK_PREFIX "subl %1,%0"
8937+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8938+
8939+#ifdef CONFIG_PAX_REFCOUNT
8940+ "jno 0f\n"
8941+ LOCK_PREFIX "addl %1,%0\n"
8942+ "int $4\n0:\n"
8943+ _ASM_EXTABLE(0b, 0b)
8944+#endif
8945+
8946+ : "=m" (v->counter)
8947+ : "ir" (i), "m" (v->counter));
8948+}
8949+
8950+/**
8951+ * atomic_sub_unchecked - subtract the atomic variable
8952+ * @i: integer value to subtract
8953+ * @v: pointer of type atomic_unchecked_t
8954+ *
8955+ * Atomically subtracts @i from @v.
8956+ */
8957+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
8958+{
8959+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
8960 : "=m" (v->counter)
8961 : "ir" (i), "m" (v->counter));
8962 }
8963@@ -76,7 +143,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8964 {
8965 unsigned char c;
8966
8967- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
8968+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
8969+
8970+#ifdef CONFIG_PAX_REFCOUNT
8971+ "jno 0f\n"
8972+ LOCK_PREFIX "addl %2,%0\n"
8973+ "int $4\n0:\n"
8974+ _ASM_EXTABLE(0b, 0b)
8975+#endif
8976+
8977+ "sete %1\n"
8978 : "=m" (v->counter), "=qm" (c)
8979 : "ir" (i), "m" (v->counter) : "memory");
8980 return c;
8981@@ -90,7 +166,28 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
8982 */
8983 static inline void atomic_inc(atomic_t *v)
8984 {
8985- asm volatile(LOCK_PREFIX "incl %0"
8986+ asm volatile(LOCK_PREFIX "incl %0\n"
8987+
8988+#ifdef CONFIG_PAX_REFCOUNT
8989+ "jno 0f\n"
8990+ LOCK_PREFIX "decl %0\n"
8991+ "int $4\n0:\n"
8992+ _ASM_EXTABLE(0b, 0b)
8993+#endif
8994+
8995+ : "=m" (v->counter)
8996+ : "m" (v->counter));
8997+}
8998+
8999+/**
9000+ * atomic_inc_unchecked - increment atomic variable
9001+ * @v: pointer of type atomic_unchecked_t
9002+ *
9003+ * Atomically increments @v by 1.
9004+ */
9005+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9006+{
9007+ asm volatile(LOCK_PREFIX "incl %0\n"
9008 : "=m" (v->counter)
9009 : "m" (v->counter));
9010 }
9011@@ -103,7 +200,28 @@ static inline void atomic_inc(atomic_t *v)
9012 */
9013 static inline void atomic_dec(atomic_t *v)
9014 {
9015- asm volatile(LOCK_PREFIX "decl %0"
9016+ asm volatile(LOCK_PREFIX "decl %0\n"
9017+
9018+#ifdef CONFIG_PAX_REFCOUNT
9019+ "jno 0f\n"
9020+ LOCK_PREFIX "incl %0\n"
9021+ "int $4\n0:\n"
9022+ _ASM_EXTABLE(0b, 0b)
9023+#endif
9024+
9025+ : "=m" (v->counter)
9026+ : "m" (v->counter));
9027+}
9028+
9029+/**
9030+ * atomic_dec_unchecked - decrement atomic variable
9031+ * @v: pointer of type atomic_unchecked_t
9032+ *
9033+ * Atomically decrements @v by 1.
9034+ */
9035+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9036+{
9037+ asm volatile(LOCK_PREFIX "decl %0\n"
9038 : "=m" (v->counter)
9039 : "m" (v->counter));
9040 }
9041@@ -120,7 +238,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9042 {
9043 unsigned char c;
9044
9045- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9046+ asm volatile(LOCK_PREFIX "decl %0\n"
9047+
9048+#ifdef CONFIG_PAX_REFCOUNT
9049+ "jno 0f\n"
9050+ LOCK_PREFIX "incl %0\n"
9051+ "int $4\n0:\n"
9052+ _ASM_EXTABLE(0b, 0b)
9053+#endif
9054+
9055+ "sete %1\n"
9056 : "=m" (v->counter), "=qm" (c)
9057 : "m" (v->counter) : "memory");
9058 return c != 0;
9059@@ -138,7 +265,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9060 {
9061 unsigned char c;
9062
9063- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9064+ asm volatile(LOCK_PREFIX "incl %0\n"
9065+
9066+#ifdef CONFIG_PAX_REFCOUNT
9067+ "jno 0f\n"
9068+ LOCK_PREFIX "decl %0\n"
9069+ "int $4\n0:\n"
9070+ _ASM_EXTABLE(0b, 0b)
9071+#endif
9072+
9073+ "sete %1\n"
9074+ : "=m" (v->counter), "=qm" (c)
9075+ : "m" (v->counter) : "memory");
9076+ return c != 0;
9077+}
9078+
9079+/**
9080+ * atomic_inc_and_test_unchecked - increment and test
9081+ * @v: pointer of type atomic_unchecked_t
9082+ *
9083+ * Atomically increments @v by 1
9084+ * and returns true if the result is zero, or false for all
9085+ * other cases.
9086+ */
9087+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9088+{
9089+ unsigned char c;
9090+
9091+ asm volatile(LOCK_PREFIX "incl %0\n"
9092+ "sete %1\n"
9093 : "=m" (v->counter), "=qm" (c)
9094 : "m" (v->counter) : "memory");
9095 return c != 0;
9096@@ -157,7 +312,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9097 {
9098 unsigned char c;
9099
9100- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9101+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9102+
9103+#ifdef CONFIG_PAX_REFCOUNT
9104+ "jno 0f\n"
9105+ LOCK_PREFIX "subl %2,%0\n"
9106+ "int $4\n0:\n"
9107+ _ASM_EXTABLE(0b, 0b)
9108+#endif
9109+
9110+ "sets %1\n"
9111 : "=m" (v->counter), "=qm" (c)
9112 : "ir" (i), "m" (v->counter) : "memory");
9113 return c;
9114@@ -173,7 +337,31 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9115 static inline int atomic_add_return(int i, atomic_t *v)
9116 {
9117 int __i = i;
9118- asm volatile(LOCK_PREFIX "xaddl %0, %1"
9119+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
9120+
9121+#ifdef CONFIG_PAX_REFCOUNT
9122+ "jno 0f\n"
9123+ "movl %0, %1\n"
9124+ "int $4\n0:\n"
9125+ _ASM_EXTABLE(0b, 0b)
9126+#endif
9127+
9128+ : "+r" (i), "+m" (v->counter)
9129+ : : "memory");
9130+ return i + __i;
9131+}
9132+
9133+/**
9134+ * atomic_add_return_unchecked - add and return
9135+ * @i: integer value to add
9136+ * @v: pointer of type atomic_unchecked_t
9137+ *
9138+ * Atomically adds @i to @v and returns @i + @v
9139+ */
9140+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9141+{
9142+ int __i = i;
9143+ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
9144 : "+r" (i), "+m" (v->counter)
9145 : : "memory");
9146 return i + __i;
9147@@ -185,6 +373,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9148 }
9149
9150 #define atomic_inc_return(v) (atomic_add_return(1, v))
9151+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9152+{
9153+ return atomic_add_return_unchecked(1, v);
9154+}
9155 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9156
9157 /* The 64-bit atomic type */
9158@@ -204,6 +396,18 @@ static inline long atomic64_read(const atomic64_t *v)
9159 }
9160
9161 /**
9162+ * atomic64_read_unchecked - read atomic64 variable
9163+ * @v: pointer of type atomic64_unchecked_t
9164+ *
9165+ * Atomically reads the value of @v.
9166+ * Doesn't imply a read memory barrier.
9167+ */
9168+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9169+{
9170+ return v->counter;
9171+}
9172+
9173+/**
9174 * atomic64_set - set atomic64 variable
9175 * @v: pointer to type atomic64_t
9176 * @i: required value
9177@@ -216,6 +420,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9178 }
9179
9180 /**
9181+ * atomic64_set_unchecked - set atomic64 variable
9182+ * @v: pointer to type atomic64_unchecked_t
9183+ * @i: required value
9184+ *
9185+ * Atomically sets the value of @v to @i.
9186+ */
9187+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9188+{
9189+ v->counter = i;
9190+}
9191+
9192+/**
9193 * atomic64_add - add integer to atomic64 variable
9194 * @i: integer value to add
9195 * @v: pointer to type atomic64_t
9196@@ -224,6 +440,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9197 */
9198 static inline void atomic64_add(long i, atomic64_t *v)
9199 {
9200+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9201+
9202+#ifdef CONFIG_PAX_REFCOUNT
9203+ "jno 0f\n"
9204+ LOCK_PREFIX "subq %1,%0\n"
9205+ "int $4\n0:\n"
9206+ _ASM_EXTABLE(0b, 0b)
9207+#endif
9208+
9209+ : "=m" (v->counter)
9210+ : "er" (i), "m" (v->counter));
9211+}
9212+
9213+/**
9214+ * atomic64_add_unchecked - add integer to atomic64 variable
9215+ * @i: integer value to add
9216+ * @v: pointer to type atomic64_unchecked_t
9217+ *
9218+ * Atomically adds @i to @v.
9219+ */
9220+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9221+{
9222 asm volatile(LOCK_PREFIX "addq %1,%0"
9223 : "=m" (v->counter)
9224 : "er" (i), "m" (v->counter));
9225@@ -238,7 +476,15 @@ static inline void atomic64_add(long i, atomic64_t *v)
9226 */
9227 static inline void atomic64_sub(long i, atomic64_t *v)
9228 {
9229- asm volatile(LOCK_PREFIX "subq %1,%0"
9230+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9231+
9232+#ifdef CONFIG_PAX_REFCOUNT
9233+ "jno 0f\n"
9234+ LOCK_PREFIX "addq %1,%0\n"
9235+ "int $4\n0:\n"
9236+ _ASM_EXTABLE(0b, 0b)
9237+#endif
9238+
9239 : "=m" (v->counter)
9240 : "er" (i), "m" (v->counter));
9241 }
9242@@ -256,7 +502,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9243 {
9244 unsigned char c;
9245
9246- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9247+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9248+
9249+#ifdef CONFIG_PAX_REFCOUNT
9250+ "jno 0f\n"
9251+ LOCK_PREFIX "addq %2,%0\n"
9252+ "int $4\n0:\n"
9253+ _ASM_EXTABLE(0b, 0b)
9254+#endif
9255+
9256+ "sete %1\n"
9257 : "=m" (v->counter), "=qm" (c)
9258 : "er" (i), "m" (v->counter) : "memory");
9259 return c;
9260@@ -270,6 +525,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9261 */
9262 static inline void atomic64_inc(atomic64_t *v)
9263 {
9264+ asm volatile(LOCK_PREFIX "incq %0\n"
9265+
9266+#ifdef CONFIG_PAX_REFCOUNT
9267+ "jno 0f\n"
9268+ LOCK_PREFIX "decq %0\n"
9269+ "int $4\n0:\n"
9270+ _ASM_EXTABLE(0b, 0b)
9271+#endif
9272+
9273+ : "=m" (v->counter)
9274+ : "m" (v->counter));
9275+}
9276+
9277+/**
9278+ * atomic64_inc_unchecked - increment atomic64 variable
9279+ * @v: pointer to type atomic64_unchecked_t
9280+ *
9281+ * Atomically increments @v by 1.
9282+ */
9283+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9284+{
9285 asm volatile(LOCK_PREFIX "incq %0"
9286 : "=m" (v->counter)
9287 : "m" (v->counter));
9288@@ -283,7 +559,28 @@ static inline void atomic64_inc(atomic64_t *v)
9289 */
9290 static inline void atomic64_dec(atomic64_t *v)
9291 {
9292- asm volatile(LOCK_PREFIX "decq %0"
9293+ asm volatile(LOCK_PREFIX "decq %0\n"
9294+
9295+#ifdef CONFIG_PAX_REFCOUNT
9296+ "jno 0f\n"
9297+ LOCK_PREFIX "incq %0\n"
9298+ "int $4\n0:\n"
9299+ _ASM_EXTABLE(0b, 0b)
9300+#endif
9301+
9302+ : "=m" (v->counter)
9303+ : "m" (v->counter));
9304+}
9305+
9306+/**
9307+ * atomic64_dec_unchecked - decrement atomic64 variable
9308+ * @v: pointer to type atomic64_t
9309+ *
9310+ * Atomically decrements @v by 1.
9311+ */
9312+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9313+{
9314+ asm volatile(LOCK_PREFIX "decq %0\n"
9315 : "=m" (v->counter)
9316 : "m" (v->counter));
9317 }
9318@@ -300,7 +597,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9319 {
9320 unsigned char c;
9321
9322- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9323+ asm volatile(LOCK_PREFIX "decq %0\n"
9324+
9325+#ifdef CONFIG_PAX_REFCOUNT
9326+ "jno 0f\n"
9327+ LOCK_PREFIX "incq %0\n"
9328+ "int $4\n0:\n"
9329+ _ASM_EXTABLE(0b, 0b)
9330+#endif
9331+
9332+ "sete %1\n"
9333 : "=m" (v->counter), "=qm" (c)
9334 : "m" (v->counter) : "memory");
9335 return c != 0;
9336@@ -318,7 +624,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9337 {
9338 unsigned char c;
9339
9340- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9341+ asm volatile(LOCK_PREFIX "incq %0\n"
9342+
9343+#ifdef CONFIG_PAX_REFCOUNT
9344+ "jno 0f\n"
9345+ LOCK_PREFIX "decq %0\n"
9346+ "int $4\n0:\n"
9347+ _ASM_EXTABLE(0b, 0b)
9348+#endif
9349+
9350+ "sete %1\n"
9351 : "=m" (v->counter), "=qm" (c)
9352 : "m" (v->counter) : "memory");
9353 return c != 0;
9354@@ -337,7 +652,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9355 {
9356 unsigned char c;
9357
9358- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9359+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9360+
9361+#ifdef CONFIG_PAX_REFCOUNT
9362+ "jno 0f\n"
9363+ LOCK_PREFIX "subq %2,%0\n"
9364+ "int $4\n0:\n"
9365+ _ASM_EXTABLE(0b, 0b)
9366+#endif
9367+
9368+ "sets %1\n"
9369 : "=m" (v->counter), "=qm" (c)
9370 : "er" (i), "m" (v->counter) : "memory");
9371 return c;
9372@@ -353,7 +677,31 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9373 static inline long atomic64_add_return(long i, atomic64_t *v)
9374 {
9375 long __i = i;
9376- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
9377+ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
9378+
9379+#ifdef CONFIG_PAX_REFCOUNT
9380+ "jno 0f\n"
9381+ "movq %0, %1\n"
9382+ "int $4\n0:\n"
9383+ _ASM_EXTABLE(0b, 0b)
9384+#endif
9385+
9386+ : "+r" (i), "+m" (v->counter)
9387+ : : "memory");
9388+ return i + __i;
9389+}
9390+
9391+/**
9392+ * atomic64_add_return_unchecked - add and return
9393+ * @i: integer value to add
9394+ * @v: pointer to type atomic64_unchecked_t
9395+ *
9396+ * Atomically adds @i to @v and returns @i + @v
9397+ */
9398+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9399+{
9400+ long __i = i;
9401+ asm volatile(LOCK_PREFIX "xaddq %0, %1"
9402 : "+r" (i), "+m" (v->counter)
9403 : : "memory");
9404 return i + __i;
9405@@ -365,6 +713,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9406 }
9407
9408 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9409+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9410+{
9411+ return atomic64_add_return_unchecked(1, v);
9412+}
9413 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9414
9415 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9416@@ -372,21 +724,41 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9417 return cmpxchg(&v->counter, old, new);
9418 }
9419
9420+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9421+{
9422+ return cmpxchg(&v->counter, old, new);
9423+}
9424+
9425 static inline long atomic64_xchg(atomic64_t *v, long new)
9426 {
9427 return xchg(&v->counter, new);
9428 }
9429
9430+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9431+{
9432+ return xchg(&v->counter, new);
9433+}
9434+
9435 static inline long atomic_cmpxchg(atomic_t *v, int old, int new)
9436 {
9437 return cmpxchg(&v->counter, old, new);
9438 }
9439
9440+static inline long atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9441+{
9442+ return cmpxchg(&v->counter, old, new);
9443+}
9444+
9445 static inline long atomic_xchg(atomic_t *v, int new)
9446 {
9447 return xchg(&v->counter, new);
9448 }
9449
9450+static inline long atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9451+{
9452+ return xchg(&v->counter, new);
9453+}
9454+
9455 /**
9456 * atomic_add_unless - add unless the number is a given value
9457 * @v: pointer of type atomic_t
9458@@ -398,17 +770,30 @@ static inline long atomic_xchg(atomic_t *v, int new)
9459 */
9460 static inline int atomic_add_unless(atomic_t *v, int a, int u)
9461 {
9462- int c, old;
9463+ int c, old, new;
9464 c = atomic_read(v);
9465 for (;;) {
9466- if (unlikely(c == (u)))
9467+ if (unlikely(c == u))
9468 break;
9469- old = atomic_cmpxchg((v), c, c + (a));
9470+
9471+ asm volatile("addl %2,%0\n"
9472+
9473+#ifdef CONFIG_PAX_REFCOUNT
9474+ "jno 0f\n"
9475+ "subl %2,%0\n"
9476+ "int $4\n0:\n"
9477+ _ASM_EXTABLE(0b, 0b)
9478+#endif
9479+
9480+ : "=r" (new)
9481+ : "0" (c), "ir" (a));
9482+
9483+ old = atomic_cmpxchg(v, c, new);
9484 if (likely(old == c))
9485 break;
9486 c = old;
9487 }
9488- return c != (u);
9489+ return c != u;
9490 }
9491
9492 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
9493@@ -424,17 +809,30 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
9494 */
9495 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9496 {
9497- long c, old;
9498+ long c, old, new;
9499 c = atomic64_read(v);
9500 for (;;) {
9501- if (unlikely(c == (u)))
9502+ if (unlikely(c == u))
9503 break;
9504- old = atomic64_cmpxchg((v), c, c + (a));
9505+
9506+ asm volatile("addq %2,%0\n"
9507+
9508+#ifdef CONFIG_PAX_REFCOUNT
9509+ "jno 0f\n"
9510+ "subq %2,%0\n"
9511+ "int $4\n0:\n"
9512+ _ASM_EXTABLE(0b, 0b)
9513+#endif
9514+
9515+ : "=r" (new)
9516+ : "0" (c), "er" (a));
9517+
9518+ old = atomic64_cmpxchg(v, c, new);
9519 if (likely(old == c))
9520 break;
9521 c = old;
9522 }
9523- return c != (u);
9524+ return c != u;
9525 }
9526
9527 /**
9528diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9529index 02b47a6..d5c4b15 100644
9530--- a/arch/x86/include/asm/bitops.h
9531+++ b/arch/x86/include/asm/bitops.h
9532@@ -38,7 +38,7 @@
9533 * a mask operation on a byte.
9534 */
9535 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9536-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9537+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9538 #define CONST_MASK(nr) (1 << ((nr) & 7))
9539
9540 /**
9541diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9542index 7a10659..8bbf355 100644
9543--- a/arch/x86/include/asm/boot.h
9544+++ b/arch/x86/include/asm/boot.h
9545@@ -11,10 +11,15 @@
9546 #include <asm/pgtable_types.h>
9547
9548 /* Physical address where kernel should be loaded. */
9549-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9550+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9551 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9552 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9553
9554+#ifndef __ASSEMBLY__
9555+extern unsigned char __LOAD_PHYSICAL_ADDR[];
9556+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9557+#endif
9558+
9559 /* Minimum kernel alignment, as a power of two */
9560 #ifdef CONFIG_X86_64
9561 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9562diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9563index 549860d..7d45f68 100644
9564--- a/arch/x86/include/asm/cache.h
9565+++ b/arch/x86/include/asm/cache.h
9566@@ -5,9 +5,10 @@
9567
9568 /* L1 cache line size */
9569 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9570-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9571+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9572
9573 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
9574+#define __read_only __attribute__((__section__(".data.read_only")))
9575
9576 #ifdef CONFIG_X86_VSMP
9577 /* vSMP Internode cacheline shift */
9578diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9579index b54f6af..5b376a6 100644
9580--- a/arch/x86/include/asm/cacheflush.h
9581+++ b/arch/x86/include/asm/cacheflush.h
9582@@ -60,7 +60,7 @@ PAGEFLAG(WC, WC)
9583 static inline unsigned long get_page_memtype(struct page *pg)
9584 {
9585 if (!PageUncached(pg) && !PageWC(pg))
9586- return -1;
9587+ return ~0UL;
9588 else if (!PageUncached(pg) && PageWC(pg))
9589 return _PAGE_CACHE_WC;
9590 else if (PageUncached(pg) && !PageWC(pg))
9591@@ -85,7 +85,7 @@ static inline void set_page_memtype(struct page *pg, unsigned long memtype)
9592 SetPageWC(pg);
9593 break;
9594 default:
9595- case -1:
9596+ case ~0UL:
9597 ClearPageUncached(pg);
9598 ClearPageWC(pg);
9599 break;
9600diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
9601index 0e63c9a..ab8d972 100644
9602--- a/arch/x86/include/asm/calling.h
9603+++ b/arch/x86/include/asm/calling.h
9604@@ -52,32 +52,32 @@ For 32-bit we have the following conventions - kernel is built with
9605 * for assembly code:
9606 */
9607
9608-#define R15 0
9609-#define R14 8
9610-#define R13 16
9611-#define R12 24
9612-#define RBP 32
9613-#define RBX 40
9614+#define R15 (0)
9615+#define R14 (8)
9616+#define R13 (16)
9617+#define R12 (24)
9618+#define RBP (32)
9619+#define RBX (40)
9620
9621 /* arguments: interrupts/non tracing syscalls only save up to here: */
9622-#define R11 48
9623-#define R10 56
9624-#define R9 64
9625-#define R8 72
9626-#define RAX 80
9627-#define RCX 88
9628-#define RDX 96
9629-#define RSI 104
9630-#define RDI 112
9631-#define ORIG_RAX 120 /* + error_code */
9632+#define R11 (48)
9633+#define R10 (56)
9634+#define R9 (64)
9635+#define R8 (72)
9636+#define RAX (80)
9637+#define RCX (88)
9638+#define RDX (96)
9639+#define RSI (104)
9640+#define RDI (112)
9641+#define ORIG_RAX (120) /* + error_code */
9642 /* end of arguments */
9643
9644 /* cpu exception frame or undefined in case of fast syscall: */
9645-#define RIP 128
9646-#define CS 136
9647-#define EFLAGS 144
9648-#define RSP 152
9649-#define SS 160
9650+#define RIP (128)
9651+#define CS (136)
9652+#define EFLAGS (144)
9653+#define RSP (152)
9654+#define SS (160)
9655
9656 #define ARGOFFSET R11
9657 #define SWFRAME ORIG_RAX
9658diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9659index 46fc474..b02b0f9 100644
9660--- a/arch/x86/include/asm/checksum_32.h
9661+++ b/arch/x86/include/asm/checksum_32.h
9662@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9663 int len, __wsum sum,
9664 int *src_err_ptr, int *dst_err_ptr);
9665
9666+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9667+ int len, __wsum sum,
9668+ int *src_err_ptr, int *dst_err_ptr);
9669+
9670+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9671+ int len, __wsum sum,
9672+ int *src_err_ptr, int *dst_err_ptr);
9673+
9674 /*
9675 * Note: when you get a NULL pointer exception here this means someone
9676 * passed in an incorrect kernel address to one of these functions.
9677@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9678 int *err_ptr)
9679 {
9680 might_sleep();
9681- return csum_partial_copy_generic((__force void *)src, dst,
9682+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
9683 len, sum, err_ptr, NULL);
9684 }
9685
9686@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9687 {
9688 might_sleep();
9689 if (access_ok(VERIFY_WRITE, dst, len))
9690- return csum_partial_copy_generic(src, (__force void *)dst,
9691+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
9692 len, sum, NULL, err_ptr);
9693
9694 if (len)
9695diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
9696index 617bd56..7b047a1 100644
9697--- a/arch/x86/include/asm/desc.h
9698+++ b/arch/x86/include/asm/desc.h
9699@@ -4,6 +4,7 @@
9700 #include <asm/desc_defs.h>
9701 #include <asm/ldt.h>
9702 #include <asm/mmu.h>
9703+#include <asm/pgtable.h>
9704 #include <linux/smp.h>
9705
9706 static inline void fill_ldt(struct desc_struct *desc,
9707@@ -15,6 +16,7 @@ static inline void fill_ldt(struct desc_struct *desc,
9708 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
9709 desc->type = (info->read_exec_only ^ 1) << 1;
9710 desc->type |= info->contents << 2;
9711+ desc->type |= info->seg_not_present ^ 1;
9712 desc->s = 1;
9713 desc->dpl = 0x3;
9714 desc->p = info->seg_not_present ^ 1;
9715@@ -31,16 +33,12 @@ static inline void fill_ldt(struct desc_struct *desc,
9716 }
9717
9718 extern struct desc_ptr idt_descr;
9719-extern gate_desc idt_table[];
9720-
9721-struct gdt_page {
9722- struct desc_struct gdt[GDT_ENTRIES];
9723-} __attribute__((aligned(PAGE_SIZE)));
9724-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
9725+extern gate_desc idt_table[256];
9726
9727+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
9728 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
9729 {
9730- return per_cpu(gdt_page, cpu).gdt;
9731+ return cpu_gdt_table[cpu];
9732 }
9733
9734 #ifdef CONFIG_X86_64
9735@@ -65,9 +63,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
9736 unsigned long base, unsigned dpl, unsigned flags,
9737 unsigned short seg)
9738 {
9739- gate->a = (seg << 16) | (base & 0xffff);
9740- gate->b = (base & 0xffff0000) |
9741- (((0x80 | type | (dpl << 5)) & 0xff) << 8);
9742+ gate->gate.offset_low = base;
9743+ gate->gate.seg = seg;
9744+ gate->gate.reserved = 0;
9745+ gate->gate.type = type;
9746+ gate->gate.s = 0;
9747+ gate->gate.dpl = dpl;
9748+ gate->gate.p = 1;
9749+ gate->gate.offset_high = base >> 16;
9750 }
9751
9752 #endif
9753@@ -115,13 +118,17 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
9754 static inline void native_write_idt_entry(gate_desc *idt, int entry,
9755 const gate_desc *gate)
9756 {
9757+ pax_open_kernel();
9758 memcpy(&idt[entry], gate, sizeof(*gate));
9759+ pax_close_kernel();
9760 }
9761
9762 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
9763 const void *desc)
9764 {
9765+ pax_open_kernel();
9766 memcpy(&ldt[entry], desc, 8);
9767+ pax_close_kernel();
9768 }
9769
9770 static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9771@@ -139,7 +146,10 @@ static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
9772 size = sizeof(struct desc_struct);
9773 break;
9774 }
9775+
9776+ pax_open_kernel();
9777 memcpy(&gdt[entry], desc, size);
9778+ pax_close_kernel();
9779 }
9780
9781 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
9782@@ -211,7 +221,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
9783
9784 static inline void native_load_tr_desc(void)
9785 {
9786+ pax_open_kernel();
9787 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
9788+ pax_close_kernel();
9789 }
9790
9791 static inline void native_load_gdt(const struct desc_ptr *dtr)
9792@@ -246,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
9793 unsigned int i;
9794 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
9795
9796+ pax_open_kernel();
9797 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
9798 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
9799+ pax_close_kernel();
9800 }
9801
9802 #define _LDT_empty(info) \
9803@@ -309,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
9804 desc->limit = (limit >> 16) & 0xf;
9805 }
9806
9807-static inline void _set_gate(int gate, unsigned type, void *addr,
9808+static inline void _set_gate(int gate, unsigned type, const void *addr,
9809 unsigned dpl, unsigned ist, unsigned seg)
9810 {
9811 gate_desc s;
9812@@ -327,7 +341,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
9813 * Pentium F0 0F bugfix can have resulted in the mapped
9814 * IDT being write-protected.
9815 */
9816-static inline void set_intr_gate(unsigned int n, void *addr)
9817+static inline void set_intr_gate(unsigned int n, const void *addr)
9818 {
9819 BUG_ON((unsigned)n > 0xFF);
9820 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
9821@@ -356,19 +370,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
9822 /*
9823 * This routine sets up an interrupt gate at directory privilege level 3.
9824 */
9825-static inline void set_system_intr_gate(unsigned int n, void *addr)
9826+static inline void set_system_intr_gate(unsigned int n, const void *addr)
9827 {
9828 BUG_ON((unsigned)n > 0xFF);
9829 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
9830 }
9831
9832-static inline void set_system_trap_gate(unsigned int n, void *addr)
9833+static inline void set_system_trap_gate(unsigned int n, const void *addr)
9834 {
9835 BUG_ON((unsigned)n > 0xFF);
9836 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
9837 }
9838
9839-static inline void set_trap_gate(unsigned int n, void *addr)
9840+static inline void set_trap_gate(unsigned int n, const void *addr)
9841 {
9842 BUG_ON((unsigned)n > 0xFF);
9843 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
9844@@ -377,19 +391,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
9845 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
9846 {
9847 BUG_ON((unsigned)n > 0xFF);
9848- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
9849+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
9850 }
9851
9852-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
9853+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
9854 {
9855 BUG_ON((unsigned)n > 0xFF);
9856 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
9857 }
9858
9859-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
9860+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
9861 {
9862 BUG_ON((unsigned)n > 0xFF);
9863 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
9864 }
9865
9866+#ifdef CONFIG_X86_32
9867+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
9868+{
9869+ struct desc_struct d;
9870+
9871+ if (likely(limit))
9872+ limit = (limit - 1UL) >> PAGE_SHIFT;
9873+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
9874+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
9875+}
9876+#endif
9877+
9878 #endif /* _ASM_X86_DESC_H */
9879diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
9880index 9d66848..6b4a691 100644
9881--- a/arch/x86/include/asm/desc_defs.h
9882+++ b/arch/x86/include/asm/desc_defs.h
9883@@ -31,6 +31,12 @@ struct desc_struct {
9884 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
9885 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
9886 };
9887+ struct {
9888+ u16 offset_low;
9889+ u16 seg;
9890+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
9891+ unsigned offset_high: 16;
9892+ } gate;
9893 };
9894 } __attribute__((packed));
9895
9896diff --git a/arch/x86/include/asm/device.h b/arch/x86/include/asm/device.h
9897index cee34e9..a7c3fa2 100644
9898--- a/arch/x86/include/asm/device.h
9899+++ b/arch/x86/include/asm/device.h
9900@@ -6,7 +6,7 @@ struct dev_archdata {
9901 void *acpi_handle;
9902 #endif
9903 #ifdef CONFIG_X86_64
9904-struct dma_map_ops *dma_ops;
9905+ const struct dma_map_ops *dma_ops;
9906 #endif
9907 #ifdef CONFIG_DMAR
9908 void *iommu; /* hook for IOMMU specific extension */
9909diff --git a/arch/x86/include/asm/dma-mapping.h b/arch/x86/include/asm/dma-mapping.h
9910index 6a25d5d..786b202 100644
9911--- a/arch/x86/include/asm/dma-mapping.h
9912+++ b/arch/x86/include/asm/dma-mapping.h
9913@@ -25,9 +25,9 @@ extern int iommu_merge;
9914 extern struct device x86_dma_fallback_dev;
9915 extern int panic_on_overflow;
9916
9917-extern struct dma_map_ops *dma_ops;
9918+extern const struct dma_map_ops *dma_ops;
9919
9920-static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9921+static inline const struct dma_map_ops *get_dma_ops(struct device *dev)
9922 {
9923 #ifdef CONFIG_X86_32
9924 return dma_ops;
9925@@ -44,7 +44,7 @@ static inline struct dma_map_ops *get_dma_ops(struct device *dev)
9926 /* Make sure we keep the same behaviour */
9927 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
9928 {
9929- struct dma_map_ops *ops = get_dma_ops(dev);
9930+ const struct dma_map_ops *ops = get_dma_ops(dev);
9931 if (ops->mapping_error)
9932 return ops->mapping_error(dev, dma_addr);
9933
9934@@ -122,7 +122,7 @@ static inline void *
9935 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9936 gfp_t gfp)
9937 {
9938- struct dma_map_ops *ops = get_dma_ops(dev);
9939+ const struct dma_map_ops *ops = get_dma_ops(dev);
9940 void *memory;
9941
9942 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
9943@@ -149,7 +149,7 @@ dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
9944 static inline void dma_free_coherent(struct device *dev, size_t size,
9945 void *vaddr, dma_addr_t bus)
9946 {
9947- struct dma_map_ops *ops = get_dma_ops(dev);
9948+ const struct dma_map_ops *ops = get_dma_ops(dev);
9949
9950 WARN_ON(irqs_disabled()); /* for portability */
9951
9952diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
9953index 40b4e61..40d8133 100644
9954--- a/arch/x86/include/asm/e820.h
9955+++ b/arch/x86/include/asm/e820.h
9956@@ -133,7 +133,7 @@ extern char *default_machine_specific_memory_setup(void);
9957 #define ISA_END_ADDRESS 0x100000
9958 #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
9959
9960-#define BIOS_BEGIN 0x000a0000
9961+#define BIOS_BEGIN 0x000c0000
9962 #define BIOS_END 0x00100000
9963
9964 #ifdef __KERNEL__
9965diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
9966index 8ac9d9a..0a6c96e 100644
9967--- a/arch/x86/include/asm/elf.h
9968+++ b/arch/x86/include/asm/elf.h
9969@@ -257,7 +257,25 @@ extern int force_personality32;
9970 the loader. We need to make sure that it is out of the way of the program
9971 that it will "exec", and that there is sufficient room for the brk. */
9972
9973+#ifdef CONFIG_PAX_SEGMEXEC
9974+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
9975+#else
9976 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
9977+#endif
9978+
9979+#ifdef CONFIG_PAX_ASLR
9980+#ifdef CONFIG_X86_32
9981+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
9982+
9983+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9984+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
9985+#else
9986+#define PAX_ELF_ET_DYN_BASE 0x400000UL
9987+
9988+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9989+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
9990+#endif
9991+#endif
9992
9993 /* This yields a mask that user programs can use to figure out what
9994 instruction set this CPU supports. This could be done in user space,
9995@@ -310,9 +328,7 @@ do { \
9996
9997 #define ARCH_DLINFO \
9998 do { \
9999- if (vdso_enabled) \
10000- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10001- (unsigned long)current->mm->context.vdso); \
10002+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10003 } while (0)
10004
10005 #define AT_SYSINFO 32
10006@@ -323,7 +339,7 @@ do { \
10007
10008 #endif /* !CONFIG_X86_32 */
10009
10010-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10011+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10012
10013 #define VDSO_ENTRY \
10014 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10015@@ -337,7 +353,4 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
10016 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10017 #define compat_arch_setup_additional_pages syscall32_setup_pages
10018
10019-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10020-#define arch_randomize_brk arch_randomize_brk
10021-
10022 #endif /* _ASM_X86_ELF_H */
10023diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10024index cc70c1c..d96d011 100644
10025--- a/arch/x86/include/asm/emergency-restart.h
10026+++ b/arch/x86/include/asm/emergency-restart.h
10027@@ -15,6 +15,6 @@ enum reboot_type {
10028
10029 extern enum reboot_type reboot_type;
10030
10031-extern void machine_emergency_restart(void);
10032+extern void machine_emergency_restart(void) __noreturn;
10033
10034 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10035diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10036index 1f11ce4..7caabd1 100644
10037--- a/arch/x86/include/asm/futex.h
10038+++ b/arch/x86/include/asm/futex.h
10039@@ -12,16 +12,18 @@
10040 #include <asm/system.h>
10041
10042 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10043+ typecheck(u32 __user *, uaddr); \
10044 asm volatile("1:\t" insn "\n" \
10045 "2:\t.section .fixup,\"ax\"\n" \
10046 "3:\tmov\t%3, %1\n" \
10047 "\tjmp\t2b\n" \
10048 "\t.previous\n" \
10049 _ASM_EXTABLE(1b, 3b) \
10050- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10051+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10052 : "i" (-EFAULT), "0" (oparg), "1" (0))
10053
10054 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10055+ typecheck(u32 __user *, uaddr); \
10056 asm volatile("1:\tmovl %2, %0\n" \
10057 "\tmovl\t%0, %3\n" \
10058 "\t" insn "\n" \
10059@@ -34,10 +36,10 @@
10060 _ASM_EXTABLE(1b, 4b) \
10061 _ASM_EXTABLE(2b, 4b) \
10062 : "=&a" (oldval), "=&r" (ret), \
10063- "+m" (*uaddr), "=&r" (tem) \
10064+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10065 : "r" (oparg), "i" (-EFAULT), "1" (0))
10066
10067-static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
10068+static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10069 {
10070 int op = (encoded_op >> 28) & 7;
10071 int cmp = (encoded_op >> 24) & 15;
10072@@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
10073
10074 switch (op) {
10075 case FUTEX_OP_SET:
10076- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10077+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10078 break;
10079 case FUTEX_OP_ADD:
10080- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10081+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10082 uaddr, oparg);
10083 break;
10084 case FUTEX_OP_OR:
10085@@ -109,7 +111,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
10086 return ret;
10087 }
10088
10089-static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
10090+static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
10091 int newval)
10092 {
10093
10094@@ -119,16 +121,16 @@ static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
10095 return -ENOSYS;
10096 #endif
10097
10098- if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
10099+ if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10100 return -EFAULT;
10101
10102- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n"
10103+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %1\n"
10104 "2:\t.section .fixup, \"ax\"\n"
10105 "3:\tmov %2, %0\n"
10106 "\tjmp 2b\n"
10107 "\t.previous\n"
10108 _ASM_EXTABLE(1b, 3b)
10109- : "=a" (oldval), "+m" (*uaddr)
10110+ : "=a" (oldval), "+m" (*(u32 *)____m(uaddr))
10111 : "i" (-EFAULT), "r" (newval), "0" (oldval)
10112 : "memory"
10113 );
10114diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10115index ba180d9..3bad351 100644
10116--- a/arch/x86/include/asm/hw_irq.h
10117+++ b/arch/x86/include/asm/hw_irq.h
10118@@ -92,8 +92,8 @@ extern void setup_ioapic_dest(void);
10119 extern void enable_IO_APIC(void);
10120
10121 /* Statistics */
10122-extern atomic_t irq_err_count;
10123-extern atomic_t irq_mis_count;
10124+extern atomic_unchecked_t irq_err_count;
10125+extern atomic_unchecked_t irq_mis_count;
10126
10127 /* EISA */
10128 extern void eisa_set_level_irq(unsigned int irq);
10129diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10130index 0b20bbb..4cb1396 100644
10131--- a/arch/x86/include/asm/i387.h
10132+++ b/arch/x86/include/asm/i387.h
10133@@ -60,6 +60,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10134 {
10135 int err;
10136
10137+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10138+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10139+ fx = (struct i387_fxsave_struct *)((void *)fx + PAX_USER_SHADOW_BASE);
10140+#endif
10141+
10142 asm volatile("1: rex64/fxrstor (%[fx])\n\t"
10143 "2:\n"
10144 ".section .fixup,\"ax\"\n"
10145@@ -105,6 +110,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10146 {
10147 int err;
10148
10149+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10150+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10151+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10152+#endif
10153+
10154 asm volatile("1: rex64/fxsave (%[fx])\n\t"
10155 "2:\n"
10156 ".section .fixup,\"ax\"\n"
10157@@ -195,13 +205,8 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10158 }
10159
10160 /* We need a safe address that is cheap to find and that is already
10161- in L1 during context switch. The best choices are unfortunately
10162- different for UP and SMP */
10163-#ifdef CONFIG_SMP
10164-#define safe_address (__per_cpu_offset[0])
10165-#else
10166-#define safe_address (kstat_cpu(0).cpustat.user)
10167-#endif
10168+ in L1 during context switch. */
10169+#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
10170
10171 /*
10172 * These must be called with preempt disabled
10173@@ -291,7 +296,7 @@ static inline void kernel_fpu_begin(void)
10174 struct thread_info *me = current_thread_info();
10175 preempt_disable();
10176 if (me->status & TS_USEDFPU)
10177- __save_init_fpu(me->task);
10178+ __save_init_fpu(current);
10179 else
10180 clts();
10181 }
10182diff --git a/arch/x86/include/asm/io_32.h b/arch/x86/include/asm/io_32.h
10183index a299900..15c5410 100644
10184--- a/arch/x86/include/asm/io_32.h
10185+++ b/arch/x86/include/asm/io_32.h
10186@@ -3,6 +3,7 @@
10187
10188 #include <linux/string.h>
10189 #include <linux/compiler.h>
10190+#include <asm/processor.h>
10191
10192 /*
10193 * This file contains the definitions for the x86 IO instructions
10194@@ -42,6 +43,17 @@
10195
10196 #ifdef __KERNEL__
10197
10198+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10199+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10200+{
10201+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10202+}
10203+
10204+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10205+{
10206+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10207+}
10208+
10209 #include <asm-generic/iomap.h>
10210
10211 #include <linux/vmalloc.h>
10212diff --git a/arch/x86/include/asm/io_64.h b/arch/x86/include/asm/io_64.h
10213index 2440678..c158b88 100644
10214--- a/arch/x86/include/asm/io_64.h
10215+++ b/arch/x86/include/asm/io_64.h
10216@@ -140,6 +140,17 @@ __OUTS(l)
10217
10218 #include <linux/vmalloc.h>
10219
10220+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10221+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10222+{
10223+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10224+}
10225+
10226+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10227+{
10228+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10229+}
10230+
10231 #include <asm-generic/iomap.h>
10232
10233 void __memcpy_fromio(void *, unsigned long, unsigned);
10234diff --git a/arch/x86/include/asm/iommu.h b/arch/x86/include/asm/iommu.h
10235index fd6d21b..8b13915 100644
10236--- a/arch/x86/include/asm/iommu.h
10237+++ b/arch/x86/include/asm/iommu.h
10238@@ -3,7 +3,7 @@
10239
10240 extern void pci_iommu_shutdown(void);
10241 extern void no_iommu_init(void);
10242-extern struct dma_map_ops nommu_dma_ops;
10243+extern const struct dma_map_ops nommu_dma_ops;
10244 extern int force_iommu, no_iommu;
10245 extern int iommu_detected;
10246 extern int iommu_pass_through;
10247diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10248index 9e2b952..557206e 100644
10249--- a/arch/x86/include/asm/irqflags.h
10250+++ b/arch/x86/include/asm/irqflags.h
10251@@ -142,6 +142,11 @@ static inline unsigned long __raw_local_irq_save(void)
10252 sti; \
10253 sysexit
10254
10255+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10256+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10257+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10258+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10259+
10260 #else
10261 #define INTERRUPT_RETURN iret
10262 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10263diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10264index 4fe681d..bb6d40c 100644
10265--- a/arch/x86/include/asm/kprobes.h
10266+++ b/arch/x86/include/asm/kprobes.h
10267@@ -34,13 +34,8 @@ typedef u8 kprobe_opcode_t;
10268 #define BREAKPOINT_INSTRUCTION 0xcc
10269 #define RELATIVEJUMP_INSTRUCTION 0xe9
10270 #define MAX_INSN_SIZE 16
10271-#define MAX_STACK_SIZE 64
10272-#define MIN_STACK_SIZE(ADDR) \
10273- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10274- THREAD_SIZE - (unsigned long)(ADDR))) \
10275- ? (MAX_STACK_SIZE) \
10276- : (((unsigned long)current_thread_info()) + \
10277- THREAD_SIZE - (unsigned long)(ADDR)))
10278+#define MAX_STACK_SIZE 64UL
10279+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10280
10281 #define flush_insn_slot(p) do { } while (0)
10282
10283diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10284index 08bc2ff..2e88d1f 100644
10285--- a/arch/x86/include/asm/kvm_host.h
10286+++ b/arch/x86/include/asm/kvm_host.h
10287@@ -534,9 +534,9 @@ struct kvm_x86_ops {
10288 bool (*gb_page_enable)(void);
10289
10290 const struct trace_print_flags *exit_reasons_str;
10291-};
10292+} __do_const;
10293
10294-extern struct kvm_x86_ops *kvm_x86_ops;
10295+extern const struct kvm_x86_ops *kvm_x86_ops;
10296
10297 int kvm_mmu_module_init(void);
10298 void kvm_mmu_module_exit(void);
10299diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10300index 47b9b6f..815aaa1 100644
10301--- a/arch/x86/include/asm/local.h
10302+++ b/arch/x86/include/asm/local.h
10303@@ -18,26 +18,58 @@ typedef struct {
10304
10305 static inline void local_inc(local_t *l)
10306 {
10307- asm volatile(_ASM_INC "%0"
10308+ asm volatile(_ASM_INC "%0\n"
10309+
10310+#ifdef CONFIG_PAX_REFCOUNT
10311+ "jno 0f\n"
10312+ _ASM_DEC "%0\n"
10313+ "int $4\n0:\n"
10314+ _ASM_EXTABLE(0b, 0b)
10315+#endif
10316+
10317 : "+m" (l->a.counter));
10318 }
10319
10320 static inline void local_dec(local_t *l)
10321 {
10322- asm volatile(_ASM_DEC "%0"
10323+ asm volatile(_ASM_DEC "%0\n"
10324+
10325+#ifdef CONFIG_PAX_REFCOUNT
10326+ "jno 0f\n"
10327+ _ASM_INC "%0\n"
10328+ "int $4\n0:\n"
10329+ _ASM_EXTABLE(0b, 0b)
10330+#endif
10331+
10332 : "+m" (l->a.counter));
10333 }
10334
10335 static inline void local_add(long i, local_t *l)
10336 {
10337- asm volatile(_ASM_ADD "%1,%0"
10338+ asm volatile(_ASM_ADD "%1,%0\n"
10339+
10340+#ifdef CONFIG_PAX_REFCOUNT
10341+ "jno 0f\n"
10342+ _ASM_SUB "%1,%0\n"
10343+ "int $4\n0:\n"
10344+ _ASM_EXTABLE(0b, 0b)
10345+#endif
10346+
10347 : "+m" (l->a.counter)
10348 : "ir" (i));
10349 }
10350
10351 static inline void local_sub(long i, local_t *l)
10352 {
10353- asm volatile(_ASM_SUB "%1,%0"
10354+ asm volatile(_ASM_SUB "%1,%0\n"
10355+
10356+#ifdef CONFIG_PAX_REFCOUNT
10357+ "jno 0f\n"
10358+ _ASM_ADD "%1,%0\n"
10359+ "int $4\n0:\n"
10360+ _ASM_EXTABLE(0b, 0b)
10361+#endif
10362+
10363 : "+m" (l->a.counter)
10364 : "ir" (i));
10365 }
10366@@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10367 {
10368 unsigned char c;
10369
10370- asm volatile(_ASM_SUB "%2,%0; sete %1"
10371+ asm volatile(_ASM_SUB "%2,%0\n"
10372+
10373+#ifdef CONFIG_PAX_REFCOUNT
10374+ "jno 0f\n"
10375+ _ASM_ADD "%2,%0\n"
10376+ "int $4\n0:\n"
10377+ _ASM_EXTABLE(0b, 0b)
10378+#endif
10379+
10380+ "sete %1\n"
10381 : "+m" (l->a.counter), "=qm" (c)
10382 : "ir" (i) : "memory");
10383 return c;
10384@@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10385 {
10386 unsigned char c;
10387
10388- asm volatile(_ASM_DEC "%0; sete %1"
10389+ asm volatile(_ASM_DEC "%0\n"
10390+
10391+#ifdef CONFIG_PAX_REFCOUNT
10392+ "jno 0f\n"
10393+ _ASM_INC "%0\n"
10394+ "int $4\n0:\n"
10395+ _ASM_EXTABLE(0b, 0b)
10396+#endif
10397+
10398+ "sete %1\n"
10399 : "+m" (l->a.counter), "=qm" (c)
10400 : : "memory");
10401 return c != 0;
10402@@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10403 {
10404 unsigned char c;
10405
10406- asm volatile(_ASM_INC "%0; sete %1"
10407+ asm volatile(_ASM_INC "%0\n"
10408+
10409+#ifdef CONFIG_PAX_REFCOUNT
10410+ "jno 0f\n"
10411+ _ASM_DEC "%0\n"
10412+ "int $4\n0:\n"
10413+ _ASM_EXTABLE(0b, 0b)
10414+#endif
10415+
10416+ "sete %1\n"
10417 : "+m" (l->a.counter), "=qm" (c)
10418 : : "memory");
10419 return c != 0;
10420@@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10421 {
10422 unsigned char c;
10423
10424- asm volatile(_ASM_ADD "%2,%0; sets %1"
10425+ asm volatile(_ASM_ADD "%2,%0\n"
10426+
10427+#ifdef CONFIG_PAX_REFCOUNT
10428+ "jno 0f\n"
10429+ _ASM_SUB "%2,%0\n"
10430+ "int $4\n0:\n"
10431+ _ASM_EXTABLE(0b, 0b)
10432+#endif
10433+
10434+ "sets %1\n"
10435 : "+m" (l->a.counter), "=qm" (c)
10436 : "ir" (i) : "memory");
10437 return c;
10438@@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10439 #endif
10440 /* Modern 486+ processor */
10441 __i = i;
10442- asm volatile(_ASM_XADD "%0, %1;"
10443+ asm volatile(_ASM_XADD "%0, %1\n"
10444+
10445+#ifdef CONFIG_PAX_REFCOUNT
10446+ "jno 0f\n"
10447+ _ASM_MOV "%0,%1\n"
10448+ "int $4\n0:\n"
10449+ _ASM_EXTABLE(0b, 0b)
10450+#endif
10451+
10452 : "+r" (i), "+m" (l->a.counter)
10453 : : "memory");
10454 return i + __i;
10455diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microcode.h
10456index ef51b50..514ba37 100644
10457--- a/arch/x86/include/asm/microcode.h
10458+++ b/arch/x86/include/asm/microcode.h
10459@@ -12,13 +12,13 @@ struct device;
10460 enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
10461
10462 struct microcode_ops {
10463- enum ucode_state (*request_microcode_user) (int cpu,
10464+ enum ucode_state (* const request_microcode_user) (int cpu,
10465 const void __user *buf, size_t size);
10466
10467- enum ucode_state (*request_microcode_fw) (int cpu,
10468+ enum ucode_state (* const request_microcode_fw) (int cpu,
10469 struct device *device);
10470
10471- void (*microcode_fini_cpu) (int cpu);
10472+ void (* const microcode_fini_cpu) (int cpu);
10473
10474 /*
10475 * The generic 'microcode_core' part guarantees that
10476@@ -38,18 +38,18 @@ struct ucode_cpu_info {
10477 extern struct ucode_cpu_info ucode_cpu_info[];
10478
10479 #ifdef CONFIG_MICROCODE_INTEL
10480-extern struct microcode_ops * __init init_intel_microcode(void);
10481+extern const struct microcode_ops * __init init_intel_microcode(void);
10482 #else
10483-static inline struct microcode_ops * __init init_intel_microcode(void)
10484+static inline const struct microcode_ops * __init init_intel_microcode(void)
10485 {
10486 return NULL;
10487 }
10488 #endif /* CONFIG_MICROCODE_INTEL */
10489
10490 #ifdef CONFIG_MICROCODE_AMD
10491-extern struct microcode_ops * __init init_amd_microcode(void);
10492+extern const struct microcode_ops * __init init_amd_microcode(void);
10493 #else
10494-static inline struct microcode_ops * __init init_amd_microcode(void)
10495+static inline const struct microcode_ops * __init init_amd_microcode(void)
10496 {
10497 return NULL;
10498 }
10499diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10500index 593e51d..fa69c9a 100644
10501--- a/arch/x86/include/asm/mman.h
10502+++ b/arch/x86/include/asm/mman.h
10503@@ -5,4 +5,14 @@
10504
10505 #include <asm-generic/mman.h>
10506
10507+#ifdef __KERNEL__
10508+#ifndef __ASSEMBLY__
10509+#ifdef CONFIG_X86_32
10510+#define arch_mmap_check i386_mmap_check
10511+int i386_mmap_check(unsigned long addr, unsigned long len,
10512+ unsigned long flags);
10513+#endif
10514+#endif
10515+#endif
10516+
10517 #endif /* _ASM_X86_MMAN_H */
10518diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10519index 80a1dee..239c67d 100644
10520--- a/arch/x86/include/asm/mmu.h
10521+++ b/arch/x86/include/asm/mmu.h
10522@@ -9,10 +9,23 @@
10523 * we put the segment information here.
10524 */
10525 typedef struct {
10526- void *ldt;
10527+ struct desc_struct *ldt;
10528 int size;
10529 struct mutex lock;
10530- void *vdso;
10531+ unsigned long vdso;
10532+
10533+#ifdef CONFIG_X86_32
10534+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10535+ unsigned long user_cs_base;
10536+ unsigned long user_cs_limit;
10537+
10538+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10539+ cpumask_t cpu_user_cs_mask;
10540+#endif
10541+
10542+#endif
10543+#endif
10544+
10545 } mm_context_t;
10546
10547 #ifdef CONFIG_SMP
10548diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10549index 8b5393e..8143173 100644
10550--- a/arch/x86/include/asm/mmu_context.h
10551+++ b/arch/x86/include/asm/mmu_context.h
10552@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10553
10554 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10555 {
10556+
10557+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10558+ unsigned int i;
10559+ pgd_t *pgd;
10560+
10561+ pax_open_kernel();
10562+ pgd = get_cpu_pgd(smp_processor_id());
10563+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10564+ set_pgd_batched(pgd+i, native_make_pgd(0));
10565+ pax_close_kernel();
10566+#endif
10567+
10568 #ifdef CONFIG_SMP
10569 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10570 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10571@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10572 struct task_struct *tsk)
10573 {
10574 unsigned cpu = smp_processor_id();
10575+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)) && defined(CONFIG_SMP)
10576+ int tlbstate = TLBSTATE_OK;
10577+#endif
10578
10579 if (likely(prev != next)) {
10580 #ifdef CONFIG_SMP
10581+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10582+ tlbstate = percpu_read(cpu_tlbstate.state);
10583+#endif
10584 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10585 percpu_write(cpu_tlbstate.active_mm, next);
10586 #endif
10587 cpumask_set_cpu(cpu, mm_cpumask(next));
10588
10589 /* Re-load page tables */
10590+#ifdef CONFIG_PAX_PER_CPU_PGD
10591+ pax_open_kernel();
10592+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10593+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10594+ pax_close_kernel();
10595+ load_cr3(get_cpu_pgd(cpu));
10596+#else
10597 load_cr3(next->pgd);
10598+#endif
10599
10600 /* stop flush ipis for the previous mm */
10601 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10602@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10603 */
10604 if (unlikely(prev->context.ldt != next->context.ldt))
10605 load_LDT_nolock(&next->context);
10606- }
10607+
10608+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10609+ if (!nx_enabled) {
10610+ smp_mb__before_clear_bit();
10611+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10612+ smp_mb__after_clear_bit();
10613+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10614+ }
10615+#endif
10616+
10617+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10618+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10619+ prev->context.user_cs_limit != next->context.user_cs_limit))
10620+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10621 #ifdef CONFIG_SMP
10622+ else if (unlikely(tlbstate != TLBSTATE_OK))
10623+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10624+#endif
10625+#endif
10626+
10627+ }
10628 else {
10629+
10630+#ifdef CONFIG_PAX_PER_CPU_PGD
10631+ pax_open_kernel();
10632+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
10633+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
10634+ pax_close_kernel();
10635+ load_cr3(get_cpu_pgd(cpu));
10636+#endif
10637+
10638+#ifdef CONFIG_SMP
10639 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10640 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10641
10642@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10643 * tlb flush IPI delivery. We must reload CR3
10644 * to make sure to use no freed page tables.
10645 */
10646+
10647+#ifndef CONFIG_PAX_PER_CPU_PGD
10648 load_cr3(next->pgd);
10649+#endif
10650+
10651 load_LDT_nolock(&next->context);
10652+
10653+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10654+ if (!nx_enabled)
10655+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10656+#endif
10657+
10658+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10659+#ifdef CONFIG_PAX_PAGEEXEC
10660+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
10661+#endif
10662+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10663+#endif
10664+
10665 }
10666+#endif
10667 }
10668-#endif
10669 }
10670
10671 #define activate_mm(prev, next) \
10672diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10673index 3e2ce58..caaf478 100644
10674--- a/arch/x86/include/asm/module.h
10675+++ b/arch/x86/include/asm/module.h
10676@@ -5,6 +5,7 @@
10677
10678 #ifdef CONFIG_X86_64
10679 /* X86_64 does not define MODULE_PROC_FAMILY */
10680+#define MODULE_PROC_FAMILY ""
10681 #elif defined CONFIG_M386
10682 #define MODULE_PROC_FAMILY "386 "
10683 #elif defined CONFIG_M486
10684@@ -59,13 +60,26 @@
10685 #error unknown processor family
10686 #endif
10687
10688-#ifdef CONFIG_X86_32
10689-# ifdef CONFIG_4KSTACKS
10690-# define MODULE_STACKSIZE "4KSTACKS "
10691-# else
10692-# define MODULE_STACKSIZE ""
10693-# endif
10694-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
10695+#if defined(CONFIG_X86_32) && defined(CONFIG_4KSTACKS)
10696+#define MODULE_STACKSIZE "4KSTACKS "
10697+#else
10698+#define MODULE_STACKSIZE ""
10699 #endif
10700
10701+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10702+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10703+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10704+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10705+#else
10706+#define MODULE_PAX_KERNEXEC ""
10707+#endif
10708+
10709+#ifdef CONFIG_PAX_MEMORY_UDEREF
10710+#define MODULE_PAX_UDEREF "UDEREF "
10711+#else
10712+#define MODULE_PAX_UDEREF ""
10713+#endif
10714+
10715+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10716+
10717 #endif /* _ASM_X86_MODULE_H */
10718diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10719index 7639dbf..e08a58c 100644
10720--- a/arch/x86/include/asm/page_64_types.h
10721+++ b/arch/x86/include/asm/page_64_types.h
10722@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10723
10724 /* duplicated to the one in bootmem.h */
10725 extern unsigned long max_pfn;
10726-extern unsigned long phys_base;
10727+extern const unsigned long phys_base;
10728
10729 extern unsigned long __phys_addr(unsigned long);
10730 #define __phys_reloc_hide(x) (x)
10731diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10732index efb3899..ef30687 100644
10733--- a/arch/x86/include/asm/paravirt.h
10734+++ b/arch/x86/include/asm/paravirt.h
10735@@ -648,6 +648,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10736 val);
10737 }
10738
10739+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10740+{
10741+ pgdval_t val = native_pgd_val(pgd);
10742+
10743+ if (sizeof(pgdval_t) > sizeof(long))
10744+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10745+ val, (u64)val >> 32);
10746+ else
10747+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10748+ val);
10749+}
10750+
10751 static inline void pgd_clear(pgd_t *pgdp)
10752 {
10753 set_pgd(pgdp, __pgd(0));
10754@@ -729,6 +741,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10755 pv_mmu_ops.set_fixmap(idx, phys, flags);
10756 }
10757
10758+#ifdef CONFIG_PAX_KERNEXEC
10759+static inline unsigned long pax_open_kernel(void)
10760+{
10761+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10762+}
10763+
10764+static inline unsigned long pax_close_kernel(void)
10765+{
10766+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10767+}
10768+#else
10769+static inline unsigned long pax_open_kernel(void) { return 0; }
10770+static inline unsigned long pax_close_kernel(void) { return 0; }
10771+#endif
10772+
10773 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10774
10775 static inline int __raw_spin_is_locked(struct raw_spinlock *lock)
10776@@ -945,7 +972,7 @@ extern void default_banner(void);
10777
10778 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10779 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10780-#define PARA_INDIRECT(addr) *%cs:addr
10781+#define PARA_INDIRECT(addr) *%ss:addr
10782 #endif
10783
10784 #define INTERRUPT_RETURN \
10785@@ -1022,6 +1049,21 @@ extern void default_banner(void);
10786 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
10787 CLBR_NONE, \
10788 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
10789+
10790+#define GET_CR0_INTO_RDI \
10791+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
10792+ mov %rax,%rdi
10793+
10794+#define SET_RDI_INTO_CR0 \
10795+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
10796+
10797+#define GET_CR3_INTO_RDI \
10798+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
10799+ mov %rax,%rdi
10800+
10801+#define SET_RDI_INTO_CR3 \
10802+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
10803+
10804 #endif /* CONFIG_X86_32 */
10805
10806 #endif /* __ASSEMBLY__ */
10807diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
10808index 9357473..aeb2de5 100644
10809--- a/arch/x86/include/asm/paravirt_types.h
10810+++ b/arch/x86/include/asm/paravirt_types.h
10811@@ -78,19 +78,19 @@ struct pv_init_ops {
10812 */
10813 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
10814 unsigned long addr, unsigned len);
10815-};
10816+} __no_const;
10817
10818
10819 struct pv_lazy_ops {
10820 /* Set deferred update mode, used for batching operations. */
10821 void (*enter)(void);
10822 void (*leave)(void);
10823-};
10824+} __no_const;
10825
10826 struct pv_time_ops {
10827 unsigned long long (*sched_clock)(void);
10828 unsigned long (*get_tsc_khz)(void);
10829-};
10830+} __no_const;
10831
10832 struct pv_cpu_ops {
10833 /* hooks for various privileged instructions */
10834@@ -186,7 +186,7 @@ struct pv_cpu_ops {
10835
10836 void (*start_context_switch)(struct task_struct *prev);
10837 void (*end_context_switch)(struct task_struct *next);
10838-};
10839+} __no_const;
10840
10841 struct pv_irq_ops {
10842 /*
10843@@ -217,7 +217,7 @@ struct pv_apic_ops {
10844 unsigned long start_eip,
10845 unsigned long start_esp);
10846 #endif
10847-};
10848+} __no_const;
10849
10850 struct pv_mmu_ops {
10851 unsigned long (*read_cr2)(void);
10852@@ -301,6 +301,7 @@ struct pv_mmu_ops {
10853 struct paravirt_callee_save make_pud;
10854
10855 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
10856+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
10857 #endif /* PAGETABLE_LEVELS == 4 */
10858 #endif /* PAGETABLE_LEVELS >= 3 */
10859
10860@@ -316,6 +317,12 @@ struct pv_mmu_ops {
10861 an mfn. We can tell which is which from the index. */
10862 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
10863 phys_addr_t phys, pgprot_t flags);
10864+
10865+#ifdef CONFIG_PAX_KERNEXEC
10866+ unsigned long (*pax_open_kernel)(void);
10867+ unsigned long (*pax_close_kernel)(void);
10868+#endif
10869+
10870 };
10871
10872 struct raw_spinlock;
10873@@ -326,7 +333,7 @@ struct pv_lock_ops {
10874 void (*spin_lock_flags)(struct raw_spinlock *lock, unsigned long flags);
10875 int (*spin_trylock)(struct raw_spinlock *lock);
10876 void (*spin_unlock)(struct raw_spinlock *lock);
10877-};
10878+} __no_const;
10879
10880 /* This contains all the paravirt structures: we get a convenient
10881 * number for each function using the offset which we use to indicate
10882diff --git a/arch/x86/include/asm/pci_x86.h b/arch/x86/include/asm/pci_x86.h
10883index b399988..3f47c38 100644
10884--- a/arch/x86/include/asm/pci_x86.h
10885+++ b/arch/x86/include/asm/pci_x86.h
10886@@ -89,16 +89,16 @@ extern int (*pcibios_enable_irq)(struct pci_dev *dev);
10887 extern void (*pcibios_disable_irq)(struct pci_dev *dev);
10888
10889 struct pci_raw_ops {
10890- int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10891+ int (* const read)(unsigned int domain, unsigned int bus, unsigned int devfn,
10892 int reg, int len, u32 *val);
10893- int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10894+ int (* const write)(unsigned int domain, unsigned int bus, unsigned int devfn,
10895 int reg, int len, u32 val);
10896 };
10897
10898-extern struct pci_raw_ops *raw_pci_ops;
10899-extern struct pci_raw_ops *raw_pci_ext_ops;
10900+extern const struct pci_raw_ops *raw_pci_ops;
10901+extern const struct pci_raw_ops *raw_pci_ext_ops;
10902
10903-extern struct pci_raw_ops pci_direct_conf1;
10904+extern const struct pci_raw_ops pci_direct_conf1;
10905 extern bool port_cf9_safe;
10906
10907 /* arch_initcall level */
10908diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
10909index b65a36d..50345a4 100644
10910--- a/arch/x86/include/asm/percpu.h
10911+++ b/arch/x86/include/asm/percpu.h
10912@@ -78,6 +78,7 @@ do { \
10913 if (0) { \
10914 T__ tmp__; \
10915 tmp__ = (val); \
10916+ (void)tmp__; \
10917 } \
10918 switch (sizeof(var)) { \
10919 case 1: \
10920diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
10921index 271de94..ef944d6 100644
10922--- a/arch/x86/include/asm/pgalloc.h
10923+++ b/arch/x86/include/asm/pgalloc.h
10924@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
10925 pmd_t *pmd, pte_t *pte)
10926 {
10927 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10928+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
10929+}
10930+
10931+static inline void pmd_populate_user(struct mm_struct *mm,
10932+ pmd_t *pmd, pte_t *pte)
10933+{
10934+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
10935 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
10936 }
10937
10938diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
10939index 2334982..70bc412 100644
10940--- a/arch/x86/include/asm/pgtable-2level.h
10941+++ b/arch/x86/include/asm/pgtable-2level.h
10942@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
10943
10944 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10945 {
10946+ pax_open_kernel();
10947 *pmdp = pmd;
10948+ pax_close_kernel();
10949 }
10950
10951 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10952diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
10953index 33927d2..ccde329 100644
10954--- a/arch/x86/include/asm/pgtable-3level.h
10955+++ b/arch/x86/include/asm/pgtable-3level.h
10956@@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
10957
10958 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
10959 {
10960+ pax_open_kernel();
10961 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
10962+ pax_close_kernel();
10963 }
10964
10965 static inline void native_set_pud(pud_t *pudp, pud_t pud)
10966 {
10967+ pax_open_kernel();
10968 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
10969+ pax_close_kernel();
10970 }
10971
10972 /*
10973diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
10974index af6fd36..867ff74 100644
10975--- a/arch/x86/include/asm/pgtable.h
10976+++ b/arch/x86/include/asm/pgtable.h
10977@@ -39,6 +39,7 @@ extern struct list_head pgd_list;
10978
10979 #ifndef __PAGETABLE_PUD_FOLDED
10980 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
10981+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
10982 #define pgd_clear(pgd) native_pgd_clear(pgd)
10983 #endif
10984
10985@@ -74,12 +75,51 @@ extern struct list_head pgd_list;
10986
10987 #define arch_end_context_switch(prev) do {} while(0)
10988
10989+#define pax_open_kernel() native_pax_open_kernel()
10990+#define pax_close_kernel() native_pax_close_kernel()
10991 #endif /* CONFIG_PARAVIRT */
10992
10993+#define __HAVE_ARCH_PAX_OPEN_KERNEL
10994+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
10995+
10996+#ifdef CONFIG_PAX_KERNEXEC
10997+static inline unsigned long native_pax_open_kernel(void)
10998+{
10999+ unsigned long cr0;
11000+
11001+ preempt_disable();
11002+ barrier();
11003+ cr0 = read_cr0() ^ X86_CR0_WP;
11004+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11005+ write_cr0(cr0);
11006+ return cr0 ^ X86_CR0_WP;
11007+}
11008+
11009+static inline unsigned long native_pax_close_kernel(void)
11010+{
11011+ unsigned long cr0;
11012+
11013+ cr0 = read_cr0() ^ X86_CR0_WP;
11014+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11015+ write_cr0(cr0);
11016+ barrier();
11017+ preempt_enable_no_resched();
11018+ return cr0 ^ X86_CR0_WP;
11019+}
11020+#else
11021+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11022+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11023+#endif
11024+
11025 /*
11026 * The following only work if pte_present() is true.
11027 * Undefined behaviour if not..
11028 */
11029+static inline int pte_user(pte_t pte)
11030+{
11031+ return pte_val(pte) & _PAGE_USER;
11032+}
11033+
11034 static inline int pte_dirty(pte_t pte)
11035 {
11036 return pte_flags(pte) & _PAGE_DIRTY;
11037@@ -167,9 +207,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11038 return pte_clear_flags(pte, _PAGE_RW);
11039 }
11040
11041+static inline pte_t pte_mkread(pte_t pte)
11042+{
11043+ return __pte(pte_val(pte) | _PAGE_USER);
11044+}
11045+
11046 static inline pte_t pte_mkexec(pte_t pte)
11047 {
11048- return pte_clear_flags(pte, _PAGE_NX);
11049+#ifdef CONFIG_X86_PAE
11050+ if (__supported_pte_mask & _PAGE_NX)
11051+ return pte_clear_flags(pte, _PAGE_NX);
11052+ else
11053+#endif
11054+ return pte_set_flags(pte, _PAGE_USER);
11055+}
11056+
11057+static inline pte_t pte_exprotect(pte_t pte)
11058+{
11059+#ifdef CONFIG_X86_PAE
11060+ if (__supported_pte_mask & _PAGE_NX)
11061+ return pte_set_flags(pte, _PAGE_NX);
11062+ else
11063+#endif
11064+ return pte_clear_flags(pte, _PAGE_USER);
11065 }
11066
11067 static inline pte_t pte_mkdirty(pte_t pte)
11068@@ -302,6 +362,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11069 #endif
11070
11071 #ifndef __ASSEMBLY__
11072+
11073+#ifdef CONFIG_PAX_PER_CPU_PGD
11074+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11075+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11076+{
11077+ return cpu_pgd[cpu];
11078+}
11079+#endif
11080+
11081 #include <linux/mm_types.h>
11082
11083 static inline int pte_none(pte_t pte)
11084@@ -472,7 +541,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11085
11086 static inline int pgd_bad(pgd_t pgd)
11087 {
11088- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11089+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11090 }
11091
11092 static inline int pgd_none(pgd_t pgd)
11093@@ -495,7 +564,12 @@ static inline int pgd_none(pgd_t pgd)
11094 * pgd_offset() returns a (pgd_t *)
11095 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11096 */
11097-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11098+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11099+
11100+#ifdef CONFIG_PAX_PER_CPU_PGD
11101+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11102+#endif
11103+
11104 /*
11105 * a shortcut which implies the use of the kernel's pgd, instead
11106 * of a process's
11107@@ -506,6 +580,20 @@ static inline int pgd_none(pgd_t pgd)
11108 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11109 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11110
11111+#ifdef CONFIG_X86_32
11112+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11113+#else
11114+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11115+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11116+
11117+#ifdef CONFIG_PAX_MEMORY_UDEREF
11118+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11119+#else
11120+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11121+#endif
11122+
11123+#endif
11124+
11125 #ifndef __ASSEMBLY__
11126
11127 extern int direct_gbpages;
11128@@ -611,11 +699,23 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm,
11129 * dst and src can be on the same page, but the range must not overlap,
11130 * and must not cross a page boundary.
11131 */
11132-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11133+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11134 {
11135- memcpy(dst, src, count * sizeof(pgd_t));
11136+ pax_open_kernel();
11137+ while (count--)
11138+ *dst++ = *src++;
11139+ pax_close_kernel();
11140 }
11141
11142+#ifdef CONFIG_PAX_PER_CPU_PGD
11143+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11144+#endif
11145+
11146+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11147+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
11148+#else
11149+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
11150+#endif
11151
11152 #include <asm-generic/pgtable.h>
11153 #endif /* __ASSEMBLY__ */
11154diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11155index 750f1bf..971e839 100644
11156--- a/arch/x86/include/asm/pgtable_32.h
11157+++ b/arch/x86/include/asm/pgtable_32.h
11158@@ -26,9 +26,6 @@
11159 struct mm_struct;
11160 struct vm_area_struct;
11161
11162-extern pgd_t swapper_pg_dir[1024];
11163-extern pgd_t trampoline_pg_dir[1024];
11164-
11165 static inline void pgtable_cache_init(void) { }
11166 static inline void check_pgt_cache(void) { }
11167 void paging_init(void);
11168@@ -49,6 +46,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11169 # include <asm/pgtable-2level.h>
11170 #endif
11171
11172+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11173+extern pgd_t trampoline_pg_dir[PTRS_PER_PGD];
11174+#ifdef CONFIG_X86_PAE
11175+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11176+#endif
11177+
11178 #if defined(CONFIG_HIGHPTE)
11179 #define __KM_PTE \
11180 (in_nmi() ? KM_NMI_PTE : \
11181@@ -73,7 +76,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11182 /* Clear a kernel PTE and flush it from the TLB */
11183 #define kpte_clear_flush(ptep, vaddr) \
11184 do { \
11185+ pax_open_kernel(); \
11186 pte_clear(&init_mm, (vaddr), (ptep)); \
11187+ pax_close_kernel(); \
11188 __flush_tlb_one((vaddr)); \
11189 } while (0)
11190
11191@@ -85,6 +90,9 @@ do { \
11192
11193 #endif /* !__ASSEMBLY__ */
11194
11195+#define HAVE_ARCH_UNMAPPED_AREA
11196+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11197+
11198 /*
11199 * kern_addr_valid() is (1) for FLATMEM and (0) for
11200 * SPARSEMEM and DISCONTIGMEM
11201diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11202index 5e67c15..12d5c47 100644
11203--- a/arch/x86/include/asm/pgtable_32_types.h
11204+++ b/arch/x86/include/asm/pgtable_32_types.h
11205@@ -8,7 +8,7 @@
11206 */
11207 #ifdef CONFIG_X86_PAE
11208 # include <asm/pgtable-3level_types.h>
11209-# define PMD_SIZE (1UL << PMD_SHIFT)
11210+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11211 # define PMD_MASK (~(PMD_SIZE - 1))
11212 #else
11213 # include <asm/pgtable-2level_types.h>
11214@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11215 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11216 #endif
11217
11218+#ifdef CONFIG_PAX_KERNEXEC
11219+#ifndef __ASSEMBLY__
11220+extern unsigned char MODULES_EXEC_VADDR[];
11221+extern unsigned char MODULES_EXEC_END[];
11222+#endif
11223+#include <asm/boot.h>
11224+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11225+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11226+#else
11227+#define ktla_ktva(addr) (addr)
11228+#define ktva_ktla(addr) (addr)
11229+#endif
11230+
11231 #define MODULES_VADDR VMALLOC_START
11232 #define MODULES_END VMALLOC_END
11233 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11234diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11235index c57a301..6b414ff 100644
11236--- a/arch/x86/include/asm/pgtable_64.h
11237+++ b/arch/x86/include/asm/pgtable_64.h
11238@@ -16,10 +16,14 @@
11239
11240 extern pud_t level3_kernel_pgt[512];
11241 extern pud_t level3_ident_pgt[512];
11242+extern pud_t level3_vmalloc_start_pgt[512];
11243+extern pud_t level3_vmalloc_end_pgt[512];
11244+extern pud_t level3_vmemmap_pgt[512];
11245+extern pud_t level2_vmemmap_pgt[512];
11246 extern pmd_t level2_kernel_pgt[512];
11247 extern pmd_t level2_fixmap_pgt[512];
11248-extern pmd_t level2_ident_pgt[512];
11249-extern pgd_t init_level4_pgt[];
11250+extern pmd_t level2_ident_pgt[512*2];
11251+extern pgd_t init_level4_pgt[512];
11252
11253 #define swapper_pg_dir init_level4_pgt
11254
11255@@ -74,7 +78,9 @@ static inline pte_t native_ptep_get_and_clear(pte_t *xp)
11256
11257 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11258 {
11259+ pax_open_kernel();
11260 *pmdp = pmd;
11261+ pax_close_kernel();
11262 }
11263
11264 static inline void native_pmd_clear(pmd_t *pmd)
11265@@ -94,6 +100,13 @@ static inline void native_pud_clear(pud_t *pud)
11266
11267 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11268 {
11269+ pax_open_kernel();
11270+ *pgdp = pgd;
11271+ pax_close_kernel();
11272+}
11273+
11274+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11275+{
11276 *pgdp = pgd;
11277 }
11278
11279diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11280index 766ea16..5b96cb3 100644
11281--- a/arch/x86/include/asm/pgtable_64_types.h
11282+++ b/arch/x86/include/asm/pgtable_64_types.h
11283@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11284 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11285 #define MODULES_END _AC(0xffffffffff000000, UL)
11286 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11287+#define MODULES_EXEC_VADDR MODULES_VADDR
11288+#define MODULES_EXEC_END MODULES_END
11289+
11290+#define ktla_ktva(addr) (addr)
11291+#define ktva_ktla(addr) (addr)
11292
11293 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11294diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11295index d1f4a76..2f46ba1 100644
11296--- a/arch/x86/include/asm/pgtable_types.h
11297+++ b/arch/x86/include/asm/pgtable_types.h
11298@@ -16,12 +16,11 @@
11299 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11300 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11301 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11302-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11303+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11304 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11305 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11306 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11307-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11308-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11309+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11310 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11311
11312 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11313@@ -39,7 +38,6 @@
11314 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11315 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11316 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11317-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11318 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11319 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11320 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11321@@ -55,8 +53,10 @@
11322
11323 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11324 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11325-#else
11326+#elif defined(CONFIG_KMEMCHECK)
11327 #define _PAGE_NX (_AT(pteval_t, 0))
11328+#else
11329+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11330 #endif
11331
11332 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11333@@ -93,6 +93,9 @@
11334 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11335 _PAGE_ACCESSED)
11336
11337+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11338+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11339+
11340 #define __PAGE_KERNEL_EXEC \
11341 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11342 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11343@@ -103,8 +106,8 @@
11344 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11345 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11346 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11347-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11348-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
11349+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11350+#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
11351 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11352 #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
11353 #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
11354@@ -163,8 +166,8 @@
11355 * bits are combined, this will alow user to access the high address mapped
11356 * VDSO in the presence of CONFIG_COMPAT_VDSO
11357 */
11358-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11359-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11360+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11361+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11362 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11363 #endif
11364
11365@@ -202,7 +205,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11366 {
11367 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11368 }
11369+#endif
11370
11371+#if PAGETABLE_LEVELS == 3
11372+#include <asm-generic/pgtable-nopud.h>
11373+#endif
11374+
11375+#if PAGETABLE_LEVELS == 2
11376+#include <asm-generic/pgtable-nopmd.h>
11377+#endif
11378+
11379+#ifndef __ASSEMBLY__
11380 #if PAGETABLE_LEVELS > 3
11381 typedef struct { pudval_t pud; } pud_t;
11382
11383@@ -216,8 +229,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11384 return pud.pud;
11385 }
11386 #else
11387-#include <asm-generic/pgtable-nopud.h>
11388-
11389 static inline pudval_t native_pud_val(pud_t pud)
11390 {
11391 return native_pgd_val(pud.pgd);
11392@@ -237,8 +248,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11393 return pmd.pmd;
11394 }
11395 #else
11396-#include <asm-generic/pgtable-nopmd.h>
11397-
11398 static inline pmdval_t native_pmd_val(pmd_t pmd)
11399 {
11400 return native_pgd_val(pmd.pud.pgd);
11401@@ -278,7 +287,16 @@ typedef struct page *pgtable_t;
11402
11403 extern pteval_t __supported_pte_mask;
11404 extern void set_nx(void);
11405+
11406+#ifdef CONFIG_X86_32
11407+#ifdef CONFIG_X86_PAE
11408 extern int nx_enabled;
11409+#else
11410+#define nx_enabled (0)
11411+#endif
11412+#else
11413+#define nx_enabled (1)
11414+#endif
11415
11416 #define pgprot_writecombine pgprot_writecombine
11417 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11418diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11419index fa04dea..5f823fc 100644
11420--- a/arch/x86/include/asm/processor.h
11421+++ b/arch/x86/include/asm/processor.h
11422@@ -272,7 +272,7 @@ struct tss_struct {
11423
11424 } ____cacheline_aligned;
11425
11426-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11427+extern struct tss_struct init_tss[NR_CPUS];
11428
11429 /*
11430 * Save the original ist values for checking stack pointers during debugging
11431@@ -911,11 +911,18 @@ static inline void spin_lock_prefetch(const void *x)
11432 */
11433 #define TASK_SIZE PAGE_OFFSET
11434 #define TASK_SIZE_MAX TASK_SIZE
11435+
11436+#ifdef CONFIG_PAX_SEGMEXEC
11437+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11438+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11439+#else
11440 #define STACK_TOP TASK_SIZE
11441-#define STACK_TOP_MAX STACK_TOP
11442+#endif
11443+
11444+#define STACK_TOP_MAX TASK_SIZE
11445
11446 #define INIT_THREAD { \
11447- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11448+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11449 .vm86_info = NULL, \
11450 .sysenter_cs = __KERNEL_CS, \
11451 .io_bitmap_ptr = NULL, \
11452@@ -929,7 +936,7 @@ static inline void spin_lock_prefetch(const void *x)
11453 */
11454 #define INIT_TSS { \
11455 .x86_tss = { \
11456- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11457+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11458 .ss0 = __KERNEL_DS, \
11459 .ss1 = __KERNEL_CS, \
11460 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11461@@ -940,11 +947,7 @@ static inline void spin_lock_prefetch(const void *x)
11462 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11463
11464 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11465-#define KSTK_TOP(info) \
11466-({ \
11467- unsigned long *__ptr = (unsigned long *)(info); \
11468- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11469-})
11470+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11471
11472 /*
11473 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11474@@ -959,7 +962,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11475 #define task_pt_regs(task) \
11476 ({ \
11477 struct pt_regs *__regs__; \
11478- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11479+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11480 __regs__ - 1; \
11481 })
11482
11483@@ -969,13 +972,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11484 /*
11485 * User space process size. 47bits minus one guard page.
11486 */
11487-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11488+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11489
11490 /* This decides where the kernel will search for a free chunk of vm
11491 * space during mmap's.
11492 */
11493 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11494- 0xc0000000 : 0xFFFFe000)
11495+ 0xc0000000 : 0xFFFFf000)
11496
11497 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11498 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11499@@ -986,11 +989,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11500 #define STACK_TOP_MAX TASK_SIZE_MAX
11501
11502 #define INIT_THREAD { \
11503- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11504+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11505 }
11506
11507 #define INIT_TSS { \
11508- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11509+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11510 }
11511
11512 /*
11513@@ -1012,6 +1015,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11514 */
11515 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11516
11517+#ifdef CONFIG_PAX_SEGMEXEC
11518+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11519+#endif
11520+
11521 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11522
11523 /* Get/set a process' ability to use the timestamp counter instruction */
11524diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11525index 0f0d908..f2e3da2 100644
11526--- a/arch/x86/include/asm/ptrace.h
11527+++ b/arch/x86/include/asm/ptrace.h
11528@@ -151,28 +151,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11529 }
11530
11531 /*
11532- * user_mode_vm(regs) determines whether a register set came from user mode.
11533+ * user_mode(regs) determines whether a register set came from user mode.
11534 * This is true if V8086 mode was enabled OR if the register set was from
11535 * protected mode with RPL-3 CS value. This tricky test checks that with
11536 * one comparison. Many places in the kernel can bypass this full check
11537- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11538+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11539+ * be used.
11540 */
11541-static inline int user_mode(struct pt_regs *regs)
11542+static inline int user_mode_novm(struct pt_regs *regs)
11543 {
11544 #ifdef CONFIG_X86_32
11545 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11546 #else
11547- return !!(regs->cs & 3);
11548+ return !!(regs->cs & SEGMENT_RPL_MASK);
11549 #endif
11550 }
11551
11552-static inline int user_mode_vm(struct pt_regs *regs)
11553+static inline int user_mode(struct pt_regs *regs)
11554 {
11555 #ifdef CONFIG_X86_32
11556 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11557 USER_RPL;
11558 #else
11559- return user_mode(regs);
11560+ return user_mode_novm(regs);
11561 #endif
11562 }
11563
11564diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11565index 562d4fd..6e39df1 100644
11566--- a/arch/x86/include/asm/reboot.h
11567+++ b/arch/x86/include/asm/reboot.h
11568@@ -6,19 +6,19 @@
11569 struct pt_regs;
11570
11571 struct machine_ops {
11572- void (*restart)(char *cmd);
11573- void (*halt)(void);
11574- void (*power_off)(void);
11575+ void (* __noreturn restart)(char *cmd);
11576+ void (* __noreturn halt)(void);
11577+ void (* __noreturn power_off)(void);
11578 void (*shutdown)(void);
11579 void (*crash_shutdown)(struct pt_regs *);
11580- void (*emergency_restart)(void);
11581-};
11582+ void (* __noreturn emergency_restart)(void);
11583+} __no_const;
11584
11585 extern struct machine_ops machine_ops;
11586
11587 void native_machine_crash_shutdown(struct pt_regs *regs);
11588 void native_machine_shutdown(void);
11589-void machine_real_restart(const unsigned char *code, int length);
11590+void machine_real_restart(const unsigned char *code, unsigned int length) __noreturn;
11591
11592 typedef void (*nmi_shootdown_cb)(int, struct die_args*);
11593 void nmi_shootdown_cpus(nmi_shootdown_cb callback);
11594diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11595index 606ede1..dbfff37 100644
11596--- a/arch/x86/include/asm/rwsem.h
11597+++ b/arch/x86/include/asm/rwsem.h
11598@@ -118,6 +118,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11599 {
11600 asm volatile("# beginning down_read\n\t"
11601 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11602+
11603+#ifdef CONFIG_PAX_REFCOUNT
11604+ "jno 0f\n"
11605+ LOCK_PREFIX _ASM_DEC "(%1)\n\t"
11606+ "int $4\n0:\n"
11607+ _ASM_EXTABLE(0b, 0b)
11608+#endif
11609+
11610 /* adds 0x00000001, returns the old value */
11611 " jns 1f\n"
11612 " call call_rwsem_down_read_failed\n"
11613@@ -139,6 +147,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11614 "1:\n\t"
11615 " mov %1,%2\n\t"
11616 " add %3,%2\n\t"
11617+
11618+#ifdef CONFIG_PAX_REFCOUNT
11619+ "jno 0f\n"
11620+ "sub %3,%2\n"
11621+ "int $4\n0:\n"
11622+ _ASM_EXTABLE(0b, 0b)
11623+#endif
11624+
11625 " jle 2f\n\t"
11626 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11627 " jnz 1b\n\t"
11628@@ -160,6 +176,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11629 tmp = RWSEM_ACTIVE_WRITE_BIAS;
11630 asm volatile("# beginning down_write\n\t"
11631 LOCK_PREFIX " xadd %1,(%2)\n\t"
11632+
11633+#ifdef CONFIG_PAX_REFCOUNT
11634+ "jno 0f\n"
11635+ "mov %1,(%2)\n"
11636+ "int $4\n0:\n"
11637+ _ASM_EXTABLE(0b, 0b)
11638+#endif
11639+
11640 /* subtract 0x0000ffff, returns the old value */
11641 " test %1,%1\n\t"
11642 /* was the count 0 before? */
11643@@ -198,6 +222,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11644 rwsem_count_t tmp = -RWSEM_ACTIVE_READ_BIAS;
11645 asm volatile("# beginning __up_read\n\t"
11646 LOCK_PREFIX " xadd %1,(%2)\n\t"
11647+
11648+#ifdef CONFIG_PAX_REFCOUNT
11649+ "jno 0f\n"
11650+ "mov %1,(%2)\n"
11651+ "int $4\n0:\n"
11652+ _ASM_EXTABLE(0b, 0b)
11653+#endif
11654+
11655 /* subtracts 1, returns the old value */
11656 " jns 1f\n\t"
11657 " call call_rwsem_wake\n"
11658@@ -216,6 +248,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11659 rwsem_count_t tmp;
11660 asm volatile("# beginning __up_write\n\t"
11661 LOCK_PREFIX " xadd %1,(%2)\n\t"
11662+
11663+#ifdef CONFIG_PAX_REFCOUNT
11664+ "jno 0f\n"
11665+ "mov %1,(%2)\n"
11666+ "int $4\n0:\n"
11667+ _ASM_EXTABLE(0b, 0b)
11668+#endif
11669+
11670 /* tries to transition
11671 0xffff0001 -> 0x00000000 */
11672 " jz 1f\n"
11673@@ -234,6 +274,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11674 {
11675 asm volatile("# beginning __downgrade_write\n\t"
11676 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11677+
11678+#ifdef CONFIG_PAX_REFCOUNT
11679+ "jno 0f\n"
11680+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11681+ "int $4\n0:\n"
11682+ _ASM_EXTABLE(0b, 0b)
11683+#endif
11684+
11685 /*
11686 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11687 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11688@@ -253,7 +301,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11689 static inline void rwsem_atomic_add(rwsem_count_t delta,
11690 struct rw_semaphore *sem)
11691 {
11692- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11693+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11694+
11695+#ifdef CONFIG_PAX_REFCOUNT
11696+ "jno 0f\n"
11697+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
11698+ "int $4\n0:\n"
11699+ _ASM_EXTABLE(0b, 0b)
11700+#endif
11701+
11702 : "+m" (sem->count)
11703 : "er" (delta));
11704 }
11705@@ -266,7 +322,15 @@ static inline rwsem_count_t rwsem_atomic_update(rwsem_count_t delta,
11706 {
11707 rwsem_count_t tmp = delta;
11708
11709- asm volatile(LOCK_PREFIX "xadd %0,%1"
11710+ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
11711+
11712+#ifdef CONFIG_PAX_REFCOUNT
11713+ "jno 0f\n"
11714+ "mov %0,%1\n"
11715+ "int $4\n0:\n"
11716+ _ASM_EXTABLE(0b, 0b)
11717+#endif
11718+
11719 : "+r" (tmp), "+m" (sem->count)
11720 : : "memory");
11721
11722diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
11723index 14e0ed8..7f7dd5e 100644
11724--- a/arch/x86/include/asm/segment.h
11725+++ b/arch/x86/include/asm/segment.h
11726@@ -62,10 +62,15 @@
11727 * 26 - ESPFIX small SS
11728 * 27 - per-cpu [ offset to per-cpu data area ]
11729 * 28 - stack_canary-20 [ for stack protector ]
11730- * 29 - unused
11731- * 30 - unused
11732+ * 29 - PCI BIOS CS
11733+ * 30 - PCI BIOS DS
11734 * 31 - TSS for double fault handler
11735 */
11736+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
11737+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
11738+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
11739+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
11740+
11741 #define GDT_ENTRY_TLS_MIN 6
11742 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
11743
11744@@ -77,6 +82,8 @@
11745
11746 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE + 0)
11747
11748+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
11749+
11750 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE + 1)
11751
11752 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE + 4)
11753@@ -88,7 +95,7 @@
11754 #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
11755 #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
11756
11757-#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
11758+#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
11759 #ifdef CONFIG_SMP
11760 #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
11761 #else
11762@@ -102,6 +109,12 @@
11763 #define __KERNEL_STACK_CANARY 0
11764 #endif
11765
11766+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 17)
11767+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
11768+
11769+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 18)
11770+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
11771+
11772 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
11773
11774 /*
11775@@ -139,7 +152,7 @@
11776 */
11777
11778 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
11779-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
11780+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
11781
11782
11783 #else
11784@@ -163,6 +176,8 @@
11785 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS * 8 + 3)
11786 #define __USER32_DS __USER_DS
11787
11788+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
11789+
11790 #define GDT_ENTRY_TSS 8 /* needs two entries */
11791 #define GDT_ENTRY_LDT 10 /* needs two entries */
11792 #define GDT_ENTRY_TLS_MIN 12
11793@@ -183,6 +198,7 @@
11794 #endif
11795
11796 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS * 8)
11797+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS * 8)
11798 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS * 8)
11799 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS* 8 + 3)
11800 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS* 8 + 3)
11801diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
11802index 4c2f63c..5685db2 100644
11803--- a/arch/x86/include/asm/smp.h
11804+++ b/arch/x86/include/asm/smp.h
11805@@ -24,7 +24,7 @@ extern unsigned int num_processors;
11806 DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);
11807 DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
11808 DECLARE_PER_CPU(u16, cpu_llc_id);
11809-DECLARE_PER_CPU(int, cpu_number);
11810+DECLARE_PER_CPU(unsigned int, cpu_number);
11811
11812 static inline struct cpumask *cpu_sibling_mask(int cpu)
11813 {
11814@@ -40,10 +40,7 @@ DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid);
11815 DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
11816
11817 /* Static state in head.S used to set up a CPU */
11818-extern struct {
11819- void *sp;
11820- unsigned short ss;
11821-} stack_start;
11822+extern unsigned long stack_start; /* Initial stack pointer address */
11823
11824 struct smp_ops {
11825 void (*smp_prepare_boot_cpu)(void);
11826@@ -60,7 +57,7 @@ struct smp_ops {
11827
11828 void (*send_call_func_ipi)(const struct cpumask *mask);
11829 void (*send_call_func_single_ipi)(int cpu);
11830-};
11831+} __no_const;
11832
11833 /* Globals due to paravirt */
11834 extern void set_cpu_sibling_map(int cpu);
11835@@ -175,14 +172,8 @@ extern unsigned disabled_cpus __cpuinitdata;
11836 extern int safe_smp_processor_id(void);
11837
11838 #elif defined(CONFIG_X86_64_SMP)
11839-#define raw_smp_processor_id() (percpu_read(cpu_number))
11840-
11841-#define stack_smp_processor_id() \
11842-({ \
11843- struct thread_info *ti; \
11844- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
11845- ti->cpu; \
11846-})
11847+#define raw_smp_processor_id() (percpu_read(cpu_number))
11848+#define stack_smp_processor_id() raw_smp_processor_id()
11849 #define safe_smp_processor_id() smp_processor_id()
11850
11851 #endif
11852diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
11853index 4e77853..4359783 100644
11854--- a/arch/x86/include/asm/spinlock.h
11855+++ b/arch/x86/include/asm/spinlock.h
11856@@ -249,6 +249,14 @@ static inline int __raw_write_can_lock(raw_rwlock_t *lock)
11857 static inline void __raw_read_lock(raw_rwlock_t *rw)
11858 {
11859 asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
11860+
11861+#ifdef CONFIG_PAX_REFCOUNT
11862+ "jno 0f\n"
11863+ LOCK_PREFIX " addl $1,(%0)\n"
11864+ "int $4\n0:\n"
11865+ _ASM_EXTABLE(0b, 0b)
11866+#endif
11867+
11868 "jns 1f\n"
11869 "call __read_lock_failed\n\t"
11870 "1:\n"
11871@@ -258,6 +266,14 @@ static inline void __raw_read_lock(raw_rwlock_t *rw)
11872 static inline void __raw_write_lock(raw_rwlock_t *rw)
11873 {
11874 asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
11875+
11876+#ifdef CONFIG_PAX_REFCOUNT
11877+ "jno 0f\n"
11878+ LOCK_PREFIX " addl %1,(%0)\n"
11879+ "int $4\n0:\n"
11880+ _ASM_EXTABLE(0b, 0b)
11881+#endif
11882+
11883 "jz 1f\n"
11884 "call __write_lock_failed\n\t"
11885 "1:\n"
11886@@ -286,12 +302,29 @@ static inline int __raw_write_trylock(raw_rwlock_t *lock)
11887
11888 static inline void __raw_read_unlock(raw_rwlock_t *rw)
11889 {
11890- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
11891+ asm volatile(LOCK_PREFIX "incl %0\n"
11892+
11893+#ifdef CONFIG_PAX_REFCOUNT
11894+ "jno 0f\n"
11895+ LOCK_PREFIX "decl %0\n"
11896+ "int $4\n0:\n"
11897+ _ASM_EXTABLE(0b, 0b)
11898+#endif
11899+
11900+ :"+m" (rw->lock) : : "memory");
11901 }
11902
11903 static inline void __raw_write_unlock(raw_rwlock_t *rw)
11904 {
11905- asm volatile(LOCK_PREFIX "addl %1, %0"
11906+ asm volatile(LOCK_PREFIX "addl %1, %0\n"
11907+
11908+#ifdef CONFIG_PAX_REFCOUNT
11909+ "jno 0f\n"
11910+ LOCK_PREFIX "subl %1, %0\n"
11911+ "int $4\n0:\n"
11912+ _ASM_EXTABLE(0b, 0b)
11913+#endif
11914+
11915 : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
11916 }
11917
11918diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
11919index 1575177..cb23f52 100644
11920--- a/arch/x86/include/asm/stackprotector.h
11921+++ b/arch/x86/include/asm/stackprotector.h
11922@@ -48,7 +48,7 @@
11923 * head_32 for boot CPU and setup_per_cpu_areas() for others.
11924 */
11925 #define GDT_STACK_CANARY_INIT \
11926- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
11927+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
11928
11929 /*
11930 * Initialize the stackprotector canary value.
11931@@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
11932
11933 static inline void load_stack_canary_segment(void)
11934 {
11935-#ifdef CONFIG_X86_32
11936+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
11937 asm volatile ("mov %0, %%gs" : : "r" (0));
11938 #endif
11939 }
11940diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
11941index e0fbf29..858ef4a 100644
11942--- a/arch/x86/include/asm/system.h
11943+++ b/arch/x86/include/asm/system.h
11944@@ -132,7 +132,7 @@ do { \
11945 "thread_return:\n\t" \
11946 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
11947 __switch_canary \
11948- "movq %P[thread_info](%%rsi),%%r8\n\t" \
11949+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
11950 "movq %%rax,%%rdi\n\t" \
11951 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
11952 "jnz ret_from_fork\n\t" \
11953@@ -143,7 +143,7 @@ do { \
11954 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
11955 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
11956 [_tif_fork] "i" (_TIF_FORK), \
11957- [thread_info] "i" (offsetof(struct task_struct, stack)), \
11958+ [thread_info] "m" (per_cpu_var(current_tinfo)), \
11959 [current_task] "m" (per_cpu_var(current_task)) \
11960 __switch_canary_iparam \
11961 : "memory", "cc" __EXTRA_CLOBBER)
11962@@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
11963 {
11964 unsigned long __limit;
11965 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
11966- return __limit + 1;
11967+ return __limit;
11968 }
11969
11970 static inline void native_clts(void)
11971@@ -340,12 +340,12 @@ void enable_hlt(void);
11972
11973 void cpu_idle_wait(void);
11974
11975-extern unsigned long arch_align_stack(unsigned long sp);
11976+#define arch_align_stack(x) ((x) & ~0xfUL)
11977 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11978
11979 void default_idle(void);
11980
11981-void stop_this_cpu(void *dummy);
11982+void stop_this_cpu(void *dummy) __noreturn;
11983
11984 /*
11985 * Force strict CPU ordering.
11986diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
11987index 19c3ce4..8962535 100644
11988--- a/arch/x86/include/asm/thread_info.h
11989+++ b/arch/x86/include/asm/thread_info.h
11990@@ -10,6 +10,7 @@
11991 #include <linux/compiler.h>
11992 #include <asm/page.h>
11993 #include <asm/types.h>
11994+#include <asm/percpu.h>
11995
11996 /*
11997 * low level task data that entry.S needs immediate access to
11998@@ -24,7 +25,6 @@ struct exec_domain;
11999 #include <asm/atomic.h>
12000
12001 struct thread_info {
12002- struct task_struct *task; /* main task structure */
12003 struct exec_domain *exec_domain; /* execution domain */
12004 __u32 flags; /* low level flags */
12005 __u32 status; /* thread synchronous flags */
12006@@ -34,18 +34,12 @@ struct thread_info {
12007 mm_segment_t addr_limit;
12008 struct restart_block restart_block;
12009 void __user *sysenter_return;
12010-#ifdef CONFIG_X86_32
12011- unsigned long previous_esp; /* ESP of the previous stack in
12012- case of nested (IRQ) stacks
12013- */
12014- __u8 supervisor_stack[0];
12015-#endif
12016+ unsigned long lowest_stack;
12017 int uaccess_err;
12018 };
12019
12020-#define INIT_THREAD_INFO(tsk) \
12021+#define INIT_THREAD_INFO \
12022 { \
12023- .task = &tsk, \
12024 .exec_domain = &default_exec_domain, \
12025 .flags = 0, \
12026 .cpu = 0, \
12027@@ -56,7 +50,7 @@ struct thread_info {
12028 }, \
12029 }
12030
12031-#define init_thread_info (init_thread_union.thread_info)
12032+#define init_thread_info (init_thread_union.stack)
12033 #define init_stack (init_thread_union.stack)
12034
12035 #else /* !__ASSEMBLY__ */
12036@@ -163,45 +157,40 @@ struct thread_info {
12037 #define alloc_thread_info(tsk) \
12038 ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
12039
12040-#ifdef CONFIG_X86_32
12041-
12042-#define STACK_WARN (THREAD_SIZE/8)
12043-/*
12044- * macros/functions for gaining access to the thread information structure
12045- *
12046- * preempt_count needs to be 1 initially, until the scheduler is functional.
12047- */
12048-#ifndef __ASSEMBLY__
12049-
12050-
12051-/* how to get the current stack pointer from C */
12052-register unsigned long current_stack_pointer asm("esp") __used;
12053-
12054-/* how to get the thread information struct from C */
12055-static inline struct thread_info *current_thread_info(void)
12056-{
12057- return (struct thread_info *)
12058- (current_stack_pointer & ~(THREAD_SIZE - 1));
12059-}
12060-
12061-#else /* !__ASSEMBLY__ */
12062-
12063+#ifdef __ASSEMBLY__
12064 /* how to get the thread information struct from ASM */
12065 #define GET_THREAD_INFO(reg) \
12066- movl $-THREAD_SIZE, reg; \
12067- andl %esp, reg
12068+ mov PER_CPU_VAR(current_tinfo), reg
12069
12070 /* use this one if reg already contains %esp */
12071-#define GET_THREAD_INFO_WITH_ESP(reg) \
12072- andl $-THREAD_SIZE, reg
12073+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12074+#else
12075+/* how to get the thread information struct from C */
12076+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12077+
12078+static __always_inline struct thread_info *current_thread_info(void)
12079+{
12080+ return percpu_read_stable(current_tinfo);
12081+}
12082+#endif
12083+
12084+#ifdef CONFIG_X86_32
12085+
12086+#define STACK_WARN (THREAD_SIZE/8)
12087+/*
12088+ * macros/functions for gaining access to the thread information structure
12089+ *
12090+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12091+ */
12092+#ifndef __ASSEMBLY__
12093+
12094+/* how to get the current stack pointer from C */
12095+register unsigned long current_stack_pointer asm("esp") __used;
12096
12097 #endif
12098
12099 #else /* X86_32 */
12100
12101-#include <asm/percpu.h>
12102-#define KERNEL_STACK_OFFSET (5*8)
12103-
12104 /*
12105 * macros/functions for gaining access to the thread information structure
12106 * preempt_count needs to be 1 initially, until the scheduler is functional.
12107@@ -209,21 +198,8 @@ static inline struct thread_info *current_thread_info(void)
12108 #ifndef __ASSEMBLY__
12109 DECLARE_PER_CPU(unsigned long, kernel_stack);
12110
12111-static inline struct thread_info *current_thread_info(void)
12112-{
12113- struct thread_info *ti;
12114- ti = (void *)(percpu_read_stable(kernel_stack) +
12115- KERNEL_STACK_OFFSET - THREAD_SIZE);
12116- return ti;
12117-}
12118-
12119-#else /* !__ASSEMBLY__ */
12120-
12121-/* how to get the thread information struct from ASM */
12122-#define GET_THREAD_INFO(reg) \
12123- movq PER_CPU_VAR(kernel_stack),reg ; \
12124- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12125-
12126+/* how to get the current stack pointer from C */
12127+register unsigned long current_stack_pointer asm("rsp") __used;
12128 #endif
12129
12130 #endif /* !X86_32 */
12131@@ -260,5 +236,16 @@ extern void arch_task_cache_init(void);
12132 extern void free_thread_info(struct thread_info *ti);
12133 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12134 #define arch_task_cache_init arch_task_cache_init
12135+
12136+#define __HAVE_THREAD_FUNCTIONS
12137+#define task_thread_info(task) (&(task)->tinfo)
12138+#define task_stack_page(task) ((task)->stack)
12139+#define setup_thread_stack(p, org) do {} while (0)
12140+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12141+
12142+#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12143+extern struct task_struct *alloc_task_struct(void);
12144+extern void free_task_struct(struct task_struct *);
12145+
12146 #endif
12147 #endif /* _ASM_X86_THREAD_INFO_H */
12148diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12149index 61c5874..8a046e9 100644
12150--- a/arch/x86/include/asm/uaccess.h
12151+++ b/arch/x86/include/asm/uaccess.h
12152@@ -8,12 +8,15 @@
12153 #include <linux/thread_info.h>
12154 #include <linux/prefetch.h>
12155 #include <linux/string.h>
12156+#include <linux/sched.h>
12157 #include <asm/asm.h>
12158 #include <asm/page.h>
12159
12160 #define VERIFY_READ 0
12161 #define VERIFY_WRITE 1
12162
12163+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12164+
12165 /*
12166 * The fs value determines whether argument validity checking should be
12167 * performed or not. If get_fs() == USER_DS, checking is performed, with
12168@@ -29,7 +32,12 @@
12169
12170 #define get_ds() (KERNEL_DS)
12171 #define get_fs() (current_thread_info()->addr_limit)
12172+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12173+void __set_fs(mm_segment_t x);
12174+void set_fs(mm_segment_t x);
12175+#else
12176 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12177+#endif
12178
12179 #define segment_eq(a, b) ((a).seg == (b).seg)
12180
12181@@ -77,7 +85,33 @@
12182 * checks that the pointer is in the user space range - after calling
12183 * this function, memory access functions may still return -EFAULT.
12184 */
12185-#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12186+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12187+#define access_ok(type, addr, size) \
12188+({ \
12189+ long __size = size; \
12190+ unsigned long __addr = (unsigned long)addr; \
12191+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12192+ unsigned long __end_ao = __addr + __size - 1; \
12193+ bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12194+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12195+ while(__addr_ao <= __end_ao) { \
12196+ char __c_ao; \
12197+ __addr_ao += PAGE_SIZE; \
12198+ if (__size > PAGE_SIZE) \
12199+ cond_resched(); \
12200+ if (__get_user(__c_ao, (char __user *)__addr)) \
12201+ break; \
12202+ if (type != VERIFY_WRITE) { \
12203+ __addr = __addr_ao; \
12204+ continue; \
12205+ } \
12206+ if (__put_user(__c_ao, (char __user *)__addr)) \
12207+ break; \
12208+ __addr = __addr_ao; \
12209+ } \
12210+ } \
12211+ __ret_ao; \
12212+})
12213
12214 /*
12215 * The exception table consists of pairs of addresses: the first is the
12216@@ -183,12 +217,20 @@ extern int __get_user_bad(void);
12217 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12218 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12219
12220-
12221+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12222+#define __copyuser_seg "gs;"
12223+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12224+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12225+#else
12226+#define __copyuser_seg
12227+#define __COPYUSER_SET_ES
12228+#define __COPYUSER_RESTORE_ES
12229+#endif
12230
12231 #ifdef CONFIG_X86_32
12232 #define __put_user_asm_u64(x, addr, err, errret) \
12233- asm volatile("1: movl %%eax,0(%2)\n" \
12234- "2: movl %%edx,4(%2)\n" \
12235+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12236+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12237 "3:\n" \
12238 ".section .fixup,\"ax\"\n" \
12239 "4: movl %3,%0\n" \
12240@@ -200,8 +242,8 @@ extern int __get_user_bad(void);
12241 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12242
12243 #define __put_user_asm_ex_u64(x, addr) \
12244- asm volatile("1: movl %%eax,0(%1)\n" \
12245- "2: movl %%edx,4(%1)\n" \
12246+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12247+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12248 "3:\n" \
12249 _ASM_EXTABLE(1b, 2b - 1b) \
12250 _ASM_EXTABLE(2b, 3b - 2b) \
12251@@ -253,7 +295,7 @@ extern void __put_user_8(void);
12252 __typeof__(*(ptr)) __pu_val; \
12253 __chk_user_ptr(ptr); \
12254 might_fault(); \
12255- __pu_val = x; \
12256+ __pu_val = (x); \
12257 switch (sizeof(*(ptr))) { \
12258 case 1: \
12259 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12260@@ -374,7 +416,7 @@ do { \
12261 } while (0)
12262
12263 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12264- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12265+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12266 "2:\n" \
12267 ".section .fixup,\"ax\"\n" \
12268 "3: mov %3,%0\n" \
12269@@ -382,7 +424,7 @@ do { \
12270 " jmp 2b\n" \
12271 ".previous\n" \
12272 _ASM_EXTABLE(1b, 3b) \
12273- : "=r" (err), ltype(x) \
12274+ : "=r" (err), ltype (x) \
12275 : "m" (__m(addr)), "i" (errret), "0" (err))
12276
12277 #define __get_user_size_ex(x, ptr, size) \
12278@@ -407,7 +449,7 @@ do { \
12279 } while (0)
12280
12281 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12282- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12283+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12284 "2:\n" \
12285 _ASM_EXTABLE(1b, 2b - 1b) \
12286 : ltype(x) : "m" (__m(addr)))
12287@@ -424,13 +466,24 @@ do { \
12288 int __gu_err; \
12289 unsigned long __gu_val; \
12290 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12291- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12292+ (x) = (__typeof__(*(ptr)))__gu_val; \
12293 __gu_err; \
12294 })
12295
12296 /* FIXME: this hack is definitely wrong -AK */
12297 struct __large_struct { unsigned long buf[100]; };
12298-#define __m(x) (*(struct __large_struct __user *)(x))
12299+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12300+#define ____m(x) \
12301+({ \
12302+ unsigned long ____x = (unsigned long)(x); \
12303+ if (____x < PAX_USER_SHADOW_BASE) \
12304+ ____x += PAX_USER_SHADOW_BASE; \
12305+ (void __user *)____x; \
12306+})
12307+#else
12308+#define ____m(x) (x)
12309+#endif
12310+#define __m(x) (*(struct __large_struct __user *)____m(x))
12311
12312 /*
12313 * Tell gcc we read from memory instead of writing: this is because
12314@@ -438,7 +491,7 @@ struct __large_struct { unsigned long buf[100]; };
12315 * aliasing issues.
12316 */
12317 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12318- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12319+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12320 "2:\n" \
12321 ".section .fixup,\"ax\"\n" \
12322 "3: mov %3,%0\n" \
12323@@ -446,10 +499,10 @@ struct __large_struct { unsigned long buf[100]; };
12324 ".previous\n" \
12325 _ASM_EXTABLE(1b, 3b) \
12326 : "=r"(err) \
12327- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12328+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12329
12330 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12331- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12332+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12333 "2:\n" \
12334 _ASM_EXTABLE(1b, 2b - 1b) \
12335 : : ltype(x), "m" (__m(addr)))
12336@@ -488,8 +541,12 @@ struct __large_struct { unsigned long buf[100]; };
12337 * On error, the variable @x is set to zero.
12338 */
12339
12340+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12341+#define __get_user(x, ptr) get_user((x), (ptr))
12342+#else
12343 #define __get_user(x, ptr) \
12344 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12345+#endif
12346
12347 /**
12348 * __put_user: - Write a simple value into user space, with less checking.
12349@@ -511,8 +568,12 @@ struct __large_struct { unsigned long buf[100]; };
12350 * Returns zero on success, or -EFAULT on error.
12351 */
12352
12353+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12354+#define __put_user(x, ptr) put_user((x), (ptr))
12355+#else
12356 #define __put_user(x, ptr) \
12357 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12358+#endif
12359
12360 #define __get_user_unaligned __get_user
12361 #define __put_user_unaligned __put_user
12362@@ -530,7 +591,7 @@ struct __large_struct { unsigned long buf[100]; };
12363 #define get_user_ex(x, ptr) do { \
12364 unsigned long __gue_val; \
12365 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12366- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12367+ (x) = (__typeof__(*(ptr)))__gue_val; \
12368 } while (0)
12369
12370 #ifdef CONFIG_X86_WP_WORKS_OK
12371@@ -567,6 +628,7 @@ extern struct movsl_mask {
12372
12373 #define ARCH_HAS_NOCACHE_UACCESS 1
12374
12375+#define ARCH_HAS_SORT_EXTABLE
12376 #ifdef CONFIG_X86_32
12377 # include "uaccess_32.h"
12378 #else
12379diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12380index 632fb44..e30e334 100644
12381--- a/arch/x86/include/asm/uaccess_32.h
12382+++ b/arch/x86/include/asm/uaccess_32.h
12383@@ -44,6 +44,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12384 static __always_inline unsigned long __must_check
12385 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12386 {
12387+ pax_track_stack();
12388+
12389+ if ((long)n < 0)
12390+ return n;
12391+
12392 if (__builtin_constant_p(n)) {
12393 unsigned long ret;
12394
12395@@ -62,6 +67,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12396 return ret;
12397 }
12398 }
12399+ if (!__builtin_constant_p(n))
12400+ check_object_size(from, n, true);
12401 return __copy_to_user_ll(to, from, n);
12402 }
12403
12404@@ -83,12 +90,16 @@ static __always_inline unsigned long __must_check
12405 __copy_to_user(void __user *to, const void *from, unsigned long n)
12406 {
12407 might_fault();
12408+
12409 return __copy_to_user_inatomic(to, from, n);
12410 }
12411
12412 static __always_inline unsigned long
12413 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12414 {
12415+ if ((long)n < 0)
12416+ return n;
12417+
12418 /* Avoid zeroing the tail if the copy fails..
12419 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12420 * but as the zeroing behaviour is only significant when n is not
12421@@ -138,6 +149,12 @@ static __always_inline unsigned long
12422 __copy_from_user(void *to, const void __user *from, unsigned long n)
12423 {
12424 might_fault();
12425+
12426+ pax_track_stack();
12427+
12428+ if ((long)n < 0)
12429+ return n;
12430+
12431 if (__builtin_constant_p(n)) {
12432 unsigned long ret;
12433
12434@@ -153,6 +170,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12435 return ret;
12436 }
12437 }
12438+ if (!__builtin_constant_p(n))
12439+ check_object_size(to, n, false);
12440 return __copy_from_user_ll(to, from, n);
12441 }
12442
12443@@ -160,6 +179,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12444 const void __user *from, unsigned long n)
12445 {
12446 might_fault();
12447+
12448+ if ((long)n < 0)
12449+ return n;
12450+
12451 if (__builtin_constant_p(n)) {
12452 unsigned long ret;
12453
12454@@ -182,14 +205,62 @@ static __always_inline unsigned long
12455 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12456 unsigned long n)
12457 {
12458- return __copy_from_user_ll_nocache_nozero(to, from, n);
12459+ if ((long)n < 0)
12460+ return n;
12461+
12462+ return __copy_from_user_ll_nocache_nozero(to, from, n);
12463+}
12464+
12465+/**
12466+ * copy_to_user: - Copy a block of data into user space.
12467+ * @to: Destination address, in user space.
12468+ * @from: Source address, in kernel space.
12469+ * @n: Number of bytes to copy.
12470+ *
12471+ * Context: User context only. This function may sleep.
12472+ *
12473+ * Copy data from kernel space to user space.
12474+ *
12475+ * Returns number of bytes that could not be copied.
12476+ * On success, this will be zero.
12477+ */
12478+static __always_inline unsigned long __must_check
12479+copy_to_user(void __user *to, const void *from, unsigned long n)
12480+{
12481+ if (access_ok(VERIFY_WRITE, to, n))
12482+ n = __copy_to_user(to, from, n);
12483+ return n;
12484+}
12485+
12486+/**
12487+ * copy_from_user: - Copy a block of data from user space.
12488+ * @to: Destination address, in kernel space.
12489+ * @from: Source address, in user space.
12490+ * @n: Number of bytes to copy.
12491+ *
12492+ * Context: User context only. This function may sleep.
12493+ *
12494+ * Copy data from user space to kernel space.
12495+ *
12496+ * Returns number of bytes that could not be copied.
12497+ * On success, this will be zero.
12498+ *
12499+ * If some data could not be copied, this function will pad the copied
12500+ * data to the requested size using zero bytes.
12501+ */
12502+static __always_inline unsigned long __must_check
12503+copy_from_user(void *to, const void __user *from, unsigned long n)
12504+{
12505+ if (access_ok(VERIFY_READ, from, n))
12506+ n = __copy_from_user(to, from, n);
12507+ else if ((long)n > 0) {
12508+ if (!__builtin_constant_p(n))
12509+ check_object_size(to, n, false);
12510+ memset(to, 0, n);
12511+ }
12512+ return n;
12513 }
12514
12515-unsigned long __must_check copy_to_user(void __user *to,
12516- const void *from, unsigned long n);
12517-unsigned long __must_check copy_from_user(void *to,
12518- const void __user *from,
12519- unsigned long n);
12520 long __must_check strncpy_from_user(char *dst, const char __user *src,
12521 long count);
12522 long __must_check __strncpy_from_user(char *dst,
12523diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12524index db24b21..f595ae7 100644
12525--- a/arch/x86/include/asm/uaccess_64.h
12526+++ b/arch/x86/include/asm/uaccess_64.h
12527@@ -9,6 +9,9 @@
12528 #include <linux/prefetch.h>
12529 #include <linux/lockdep.h>
12530 #include <asm/page.h>
12531+#include <asm/pgtable.h>
12532+
12533+#define set_fs(x) (current_thread_info()->addr_limit = (x))
12534
12535 /*
12536 * Copy To/From Userspace
12537@@ -16,116 +19,205 @@
12538
12539 /* Handles exceptions in both to and from, but doesn't do access_ok */
12540 __must_check unsigned long
12541-copy_user_generic(void *to, const void *from, unsigned len);
12542+copy_user_generic(void *to, const void *from, unsigned long len);
12543
12544 __must_check unsigned long
12545-copy_to_user(void __user *to, const void *from, unsigned len);
12546-__must_check unsigned long
12547-copy_from_user(void *to, const void __user *from, unsigned len);
12548-__must_check unsigned long
12549-copy_in_user(void __user *to, const void __user *from, unsigned len);
12550+copy_in_user(void __user *to, const void __user *from, unsigned long len);
12551
12552 static __always_inline __must_check
12553-int __copy_from_user(void *dst, const void __user *src, unsigned size)
12554+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
12555 {
12556- int ret = 0;
12557+ unsigned ret = 0;
12558
12559 might_fault();
12560- if (!__builtin_constant_p(size))
12561- return copy_user_generic(dst, (__force void *)src, size);
12562+
12563+ if (size > INT_MAX)
12564+ return size;
12565+
12566+#ifdef CONFIG_PAX_MEMORY_UDEREF
12567+ if (!__access_ok(VERIFY_READ, src, size))
12568+ return size;
12569+#endif
12570+
12571+ if (!__builtin_constant_p(size)) {
12572+ check_object_size(dst, size, false);
12573+
12574+#ifdef CONFIG_PAX_MEMORY_UDEREF
12575+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12576+ src += PAX_USER_SHADOW_BASE;
12577+#endif
12578+
12579+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
12580+ }
12581 switch (size) {
12582- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
12583+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
12584 ret, "b", "b", "=q", 1);
12585 return ret;
12586- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
12587+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
12588 ret, "w", "w", "=r", 2);
12589 return ret;
12590- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
12591+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
12592 ret, "l", "k", "=r", 4);
12593 return ret;
12594- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
12595+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12596 ret, "q", "", "=r", 8);
12597 return ret;
12598 case 10:
12599- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12600+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12601 ret, "q", "", "=r", 10);
12602 if (unlikely(ret))
12603 return ret;
12604 __get_user_asm(*(u16 *)(8 + (char *)dst),
12605- (u16 __user *)(8 + (char __user *)src),
12606+ (const u16 __user *)(8 + (const char __user *)src),
12607 ret, "w", "w", "=r", 2);
12608 return ret;
12609 case 16:
12610- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
12611+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
12612 ret, "q", "", "=r", 16);
12613 if (unlikely(ret))
12614 return ret;
12615 __get_user_asm(*(u64 *)(8 + (char *)dst),
12616- (u64 __user *)(8 + (char __user *)src),
12617+ (const u64 __user *)(8 + (const char __user *)src),
12618 ret, "q", "", "=r", 8);
12619 return ret;
12620 default:
12621- return copy_user_generic(dst, (__force void *)src, size);
12622+
12623+#ifdef CONFIG_PAX_MEMORY_UDEREF
12624+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12625+ src += PAX_USER_SHADOW_BASE;
12626+#endif
12627+
12628+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
12629 }
12630 }
12631
12632 static __always_inline __must_check
12633-int __copy_to_user(void __user *dst, const void *src, unsigned size)
12634+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
12635 {
12636- int ret = 0;
12637+ unsigned ret = 0;
12638
12639 might_fault();
12640- if (!__builtin_constant_p(size))
12641- return copy_user_generic((__force void *)dst, src, size);
12642+
12643+ pax_track_stack();
12644+
12645+ if (size > INT_MAX)
12646+ return size;
12647+
12648+#ifdef CONFIG_PAX_MEMORY_UDEREF
12649+ if (!__access_ok(VERIFY_WRITE, dst, size))
12650+ return size;
12651+#endif
12652+
12653+ if (!__builtin_constant_p(size)) {
12654+ check_object_size(src, size, true);
12655+
12656+#ifdef CONFIG_PAX_MEMORY_UDEREF
12657+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12658+ dst += PAX_USER_SHADOW_BASE;
12659+#endif
12660+
12661+ return copy_user_generic((__force_kernel void *)dst, src, size);
12662+ }
12663 switch (size) {
12664- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
12665+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
12666 ret, "b", "b", "iq", 1);
12667 return ret;
12668- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
12669+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
12670 ret, "w", "w", "ir", 2);
12671 return ret;
12672- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
12673+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
12674 ret, "l", "k", "ir", 4);
12675 return ret;
12676- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
12677+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12678 ret, "q", "", "er", 8);
12679 return ret;
12680 case 10:
12681- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12682+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12683 ret, "q", "", "er", 10);
12684 if (unlikely(ret))
12685 return ret;
12686 asm("":::"memory");
12687- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
12688+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
12689 ret, "w", "w", "ir", 2);
12690 return ret;
12691 case 16:
12692- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
12693+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
12694 ret, "q", "", "er", 16);
12695 if (unlikely(ret))
12696 return ret;
12697 asm("":::"memory");
12698- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
12699+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
12700 ret, "q", "", "er", 8);
12701 return ret;
12702 default:
12703- return copy_user_generic((__force void *)dst, src, size);
12704+
12705+#ifdef CONFIG_PAX_MEMORY_UDEREF
12706+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12707+ dst += PAX_USER_SHADOW_BASE;
12708+#endif
12709+
12710+ return copy_user_generic((__force_kernel void *)dst, src, size);
12711+ }
12712+}
12713+
12714+static __always_inline __must_check
12715+unsigned long copy_to_user(void __user *to, const void *from, unsigned long len)
12716+{
12717+ if (access_ok(VERIFY_WRITE, to, len))
12718+ len = __copy_to_user(to, from, len);
12719+ return len;
12720+}
12721+
12722+static __always_inline __must_check
12723+unsigned long copy_from_user(void *to, const void __user *from, unsigned long len)
12724+{
12725+ might_fault();
12726+
12727+ if (access_ok(VERIFY_READ, from, len))
12728+ len = __copy_from_user(to, from, len);
12729+ else if (len < INT_MAX) {
12730+ if (!__builtin_constant_p(len))
12731+ check_object_size(to, len, false);
12732+ memset(to, 0, len);
12733 }
12734+ return len;
12735 }
12736
12737 static __always_inline __must_check
12738-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12739+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
12740 {
12741- int ret = 0;
12742+ unsigned ret = 0;
12743
12744 might_fault();
12745- if (!__builtin_constant_p(size))
12746- return copy_user_generic((__force void *)dst,
12747- (__force void *)src, size);
12748+
12749+ pax_track_stack();
12750+
12751+ if (size > INT_MAX)
12752+ return size;
12753+
12754+#ifdef CONFIG_PAX_MEMORY_UDEREF
12755+ if (!__access_ok(VERIFY_READ, src, size))
12756+ return size;
12757+ if (!__access_ok(VERIFY_WRITE, dst, size))
12758+ return size;
12759+#endif
12760+
12761+ if (!__builtin_constant_p(size)) {
12762+
12763+#ifdef CONFIG_PAX_MEMORY_UDEREF
12764+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12765+ src += PAX_USER_SHADOW_BASE;
12766+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12767+ dst += PAX_USER_SHADOW_BASE;
12768+#endif
12769+
12770+ return copy_user_generic((__force_kernel void *)dst,
12771+ (__force_kernel const void *)src, size);
12772+ }
12773 switch (size) {
12774 case 1: {
12775 u8 tmp;
12776- __get_user_asm(tmp, (u8 __user *)src,
12777+ __get_user_asm(tmp, (const u8 __user *)src,
12778 ret, "b", "b", "=q", 1);
12779 if (likely(!ret))
12780 __put_user_asm(tmp, (u8 __user *)dst,
12781@@ -134,7 +226,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12782 }
12783 case 2: {
12784 u16 tmp;
12785- __get_user_asm(tmp, (u16 __user *)src,
12786+ __get_user_asm(tmp, (const u16 __user *)src,
12787 ret, "w", "w", "=r", 2);
12788 if (likely(!ret))
12789 __put_user_asm(tmp, (u16 __user *)dst,
12790@@ -144,7 +236,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12791
12792 case 4: {
12793 u32 tmp;
12794- __get_user_asm(tmp, (u32 __user *)src,
12795+ __get_user_asm(tmp, (const u32 __user *)src,
12796 ret, "l", "k", "=r", 4);
12797 if (likely(!ret))
12798 __put_user_asm(tmp, (u32 __user *)dst,
12799@@ -153,7 +245,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12800 }
12801 case 8: {
12802 u64 tmp;
12803- __get_user_asm(tmp, (u64 __user *)src,
12804+ __get_user_asm(tmp, (const u64 __user *)src,
12805 ret, "q", "", "=r", 8);
12806 if (likely(!ret))
12807 __put_user_asm(tmp, (u64 __user *)dst,
12808@@ -161,8 +253,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
12809 return ret;
12810 }
12811 default:
12812- return copy_user_generic((__force void *)dst,
12813- (__force void *)src, size);
12814+
12815+#ifdef CONFIG_PAX_MEMORY_UDEREF
12816+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12817+ src += PAX_USER_SHADOW_BASE;
12818+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12819+ dst += PAX_USER_SHADOW_BASE;
12820+#endif
12821+
12822+ return copy_user_generic((__force_kernel void *)dst,
12823+ (__force_kernel const void *)src, size);
12824 }
12825 }
12826
12827@@ -176,33 +276,75 @@ __must_check long strlen_user(const char __user *str);
12828 __must_check unsigned long clear_user(void __user *mem, unsigned long len);
12829 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
12830
12831-__must_check long __copy_from_user_inatomic(void *dst, const void __user *src,
12832- unsigned size);
12833+static __must_check __always_inline unsigned long
12834+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
12835+{
12836+ pax_track_stack();
12837+
12838+ if (size > INT_MAX)
12839+ return size;
12840+
12841+#ifdef CONFIG_PAX_MEMORY_UDEREF
12842+ if (!__access_ok(VERIFY_READ, src, size))
12843+ return size;
12844
12845-static __must_check __always_inline int
12846-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
12847+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
12848+ src += PAX_USER_SHADOW_BASE;
12849+#endif
12850+
12851+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
12852+}
12853+
12854+static __must_check __always_inline unsigned long
12855+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
12856 {
12857- return copy_user_generic((__force void *)dst, src, size);
12858+ if (size > INT_MAX)
12859+ return size;
12860+
12861+#ifdef CONFIG_PAX_MEMORY_UDEREF
12862+ if (!__access_ok(VERIFY_WRITE, dst, size))
12863+ return size;
12864+
12865+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
12866+ dst += PAX_USER_SHADOW_BASE;
12867+#endif
12868+
12869+ return copy_user_generic((__force_kernel void *)dst, src, size);
12870 }
12871
12872-extern long __copy_user_nocache(void *dst, const void __user *src,
12873- unsigned size, int zerorest);
12874+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
12875+ unsigned long size, int zerorest);
12876
12877-static inline int
12878-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
12879+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
12880 {
12881 might_sleep();
12882+
12883+ if (size > INT_MAX)
12884+ return size;
12885+
12886+#ifdef CONFIG_PAX_MEMORY_UDEREF
12887+ if (!__access_ok(VERIFY_READ, src, size))
12888+ return size;
12889+#endif
12890+
12891 return __copy_user_nocache(dst, src, size, 1);
12892 }
12893
12894-static inline int
12895-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12896- unsigned size)
12897+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
12898+ unsigned long size)
12899 {
12900+ if (size > INT_MAX)
12901+ return size;
12902+
12903+#ifdef CONFIG_PAX_MEMORY_UDEREF
12904+ if (!__access_ok(VERIFY_READ, src, size))
12905+ return size;
12906+#endif
12907+
12908 return __copy_user_nocache(dst, src, size, 0);
12909 }
12910
12911-unsigned long
12912-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
12913+extern unsigned long
12914+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest);
12915
12916 #endif /* _ASM_X86_UACCESS_64_H */
12917diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
12918index 9064052..786cfbc 100644
12919--- a/arch/x86/include/asm/vdso.h
12920+++ b/arch/x86/include/asm/vdso.h
12921@@ -25,7 +25,7 @@ extern const char VDSO32_PRELINK[];
12922 #define VDSO32_SYMBOL(base, name) \
12923 ({ \
12924 extern const char VDSO32_##name[]; \
12925- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12926+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
12927 })
12928 #endif
12929
12930diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
12931index 3d61e20..9507180 100644
12932--- a/arch/x86/include/asm/vgtod.h
12933+++ b/arch/x86/include/asm/vgtod.h
12934@@ -14,6 +14,7 @@ struct vsyscall_gtod_data {
12935 int sysctl_enabled;
12936 struct timezone sys_tz;
12937 struct { /* extract of a clocksource struct */
12938+ char name[8];
12939 cycle_t (*vread)(void);
12940 cycle_t cycle_last;
12941 cycle_t mask;
12942diff --git a/arch/x86/include/asm/vmi.h b/arch/x86/include/asm/vmi.h
12943index 61e08c0..b0da582 100644
12944--- a/arch/x86/include/asm/vmi.h
12945+++ b/arch/x86/include/asm/vmi.h
12946@@ -191,6 +191,7 @@ struct vrom_header {
12947 u8 reserved[96]; /* Reserved for headers */
12948 char vmi_init[8]; /* VMI_Init jump point */
12949 char get_reloc[8]; /* VMI_GetRelocationInfo jump point */
12950+ char rom_data[8048]; /* rest of the option ROM */
12951 } __attribute__((packed));
12952
12953 struct pnp_header {
12954diff --git a/arch/x86/include/asm/vmi_time.h b/arch/x86/include/asm/vmi_time.h
12955index c6e0bee..fcb9f74 100644
12956--- a/arch/x86/include/asm/vmi_time.h
12957+++ b/arch/x86/include/asm/vmi_time.h
12958@@ -43,7 +43,7 @@ extern struct vmi_timer_ops {
12959 int (*wallclock_updated)(void);
12960 void (*set_alarm)(u32 flags, u64 expiry, u64 period);
12961 void (*cancel_alarm)(u32 flags);
12962-} vmi_timer_ops;
12963+} __no_const vmi_timer_ops;
12964
12965 /* Prototypes */
12966 extern void __init vmi_time_init(void);
12967diff --git a/arch/x86/include/asm/vsyscall.h b/arch/x86/include/asm/vsyscall.h
12968index d0983d2..1f7c9e9 100644
12969--- a/arch/x86/include/asm/vsyscall.h
12970+++ b/arch/x86/include/asm/vsyscall.h
12971@@ -15,9 +15,10 @@ enum vsyscall_num {
12972
12973 #ifdef __KERNEL__
12974 #include <linux/seqlock.h>
12975+#include <linux/getcpu.h>
12976+#include <linux/time.h>
12977
12978 #define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))
12979-#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16)))
12980
12981 /* Definitions for CONFIG_GENERIC_TIME definitions */
12982 #define __section_vsyscall_gtod_data __attribute__ \
12983@@ -31,7 +32,6 @@ enum vsyscall_num {
12984 #define VGETCPU_LSL 2
12985
12986 extern int __vgetcpu_mode;
12987-extern volatile unsigned long __jiffies;
12988
12989 /* kernel space (writeable) */
12990 extern int vgetcpu_mode;
12991@@ -39,6 +39,9 @@ extern struct timezone sys_tz;
12992
12993 extern void map_vsyscall(void);
12994
12995+extern int vgettimeofday(struct timeval * tv, struct timezone * tz);
12996+extern time_t vtime(time_t *t);
12997+extern long vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache);
12998 #endif /* __KERNEL__ */
12999
13000 #endif /* _ASM_X86_VSYSCALL_H */
13001diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13002index 2c756fd..3377e37 100644
13003--- a/arch/x86/include/asm/x86_init.h
13004+++ b/arch/x86/include/asm/x86_init.h
13005@@ -28,7 +28,7 @@ struct x86_init_mpparse {
13006 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13007 void (*find_smp_config)(unsigned int reserve);
13008 void (*get_smp_config)(unsigned int early);
13009-};
13010+} __no_const;
13011
13012 /**
13013 * struct x86_init_resources - platform specific resource related ops
13014@@ -42,7 +42,7 @@ struct x86_init_resources {
13015 void (*probe_roms)(void);
13016 void (*reserve_resources)(void);
13017 char *(*memory_setup)(void);
13018-};
13019+} __no_const;
13020
13021 /**
13022 * struct x86_init_irqs - platform specific interrupt setup
13023@@ -55,7 +55,7 @@ struct x86_init_irqs {
13024 void (*pre_vector_init)(void);
13025 void (*intr_init)(void);
13026 void (*trap_init)(void);
13027-};
13028+} __no_const;
13029
13030 /**
13031 * struct x86_init_oem - oem platform specific customizing functions
13032@@ -65,7 +65,7 @@ struct x86_init_irqs {
13033 struct x86_init_oem {
13034 void (*arch_setup)(void);
13035 void (*banner)(void);
13036-};
13037+} __no_const;
13038
13039 /**
13040 * struct x86_init_paging - platform specific paging functions
13041@@ -75,7 +75,7 @@ struct x86_init_oem {
13042 struct x86_init_paging {
13043 void (*pagetable_setup_start)(pgd_t *base);
13044 void (*pagetable_setup_done)(pgd_t *base);
13045-};
13046+} __no_const;
13047
13048 /**
13049 * struct x86_init_timers - platform specific timer setup
13050@@ -88,7 +88,7 @@ struct x86_init_timers {
13051 void (*setup_percpu_clockev)(void);
13052 void (*tsc_pre_init)(void);
13053 void (*timer_init)(void);
13054-};
13055+} __no_const;
13056
13057 /**
13058 * struct x86_init_ops - functions for platform specific setup
13059@@ -101,7 +101,7 @@ struct x86_init_ops {
13060 struct x86_init_oem oem;
13061 struct x86_init_paging paging;
13062 struct x86_init_timers timers;
13063-};
13064+} __no_const;
13065
13066 /**
13067 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13068@@ -109,7 +109,7 @@ struct x86_init_ops {
13069 */
13070 struct x86_cpuinit_ops {
13071 void (*setup_percpu_clockev)(void);
13072-};
13073+} __no_const;
13074
13075 /**
13076 * struct x86_platform_ops - platform specific runtime functions
13077@@ -121,7 +121,7 @@ struct x86_platform_ops {
13078 unsigned long (*calibrate_tsc)(void);
13079 unsigned long (*get_wallclock)(void);
13080 int (*set_wallclock)(unsigned long nowtime);
13081-};
13082+} __no_const;
13083
13084 extern struct x86_init_ops x86_init;
13085 extern struct x86_cpuinit_ops x86_cpuinit;
13086diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13087index 727acc1..554f3eb 100644
13088--- a/arch/x86/include/asm/xsave.h
13089+++ b/arch/x86/include/asm/xsave.h
13090@@ -56,6 +56,12 @@ static inline int xrstor_checking(struct xsave_struct *fx)
13091 static inline int xsave_user(struct xsave_struct __user *buf)
13092 {
13093 int err;
13094+
13095+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13096+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13097+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13098+#endif
13099+
13100 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
13101 "2:\n"
13102 ".section .fixup,\"ax\"\n"
13103@@ -78,10 +84,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13104 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13105 {
13106 int err;
13107- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13108+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13109 u32 lmask = mask;
13110 u32 hmask = mask >> 32;
13111
13112+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13113+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13114+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13115+#endif
13116+
13117 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13118 "2:\n"
13119 ".section .fixup,\"ax\"\n"
13120diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13121index 6a564ac..9b1340c 100644
13122--- a/arch/x86/kernel/acpi/realmode/Makefile
13123+++ b/arch/x86/kernel/acpi/realmode/Makefile
13124@@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13125 $(call cc-option, -fno-stack-protector) \
13126 $(call cc-option, -mpreferred-stack-boundary=2)
13127 KBUILD_CFLAGS += $(call cc-option, -m32)
13128+ifdef CONSTIFY_PLUGIN
13129+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13130+endif
13131 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13132 GCOV_PROFILE := n
13133
13134diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13135index 580b4e2..d4129e4 100644
13136--- a/arch/x86/kernel/acpi/realmode/wakeup.S
13137+++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13138@@ -91,6 +91,9 @@ _start:
13139 /* Do any other stuff... */
13140
13141 #ifndef CONFIG_64BIT
13142+ /* Recheck NX bit overrides (64bit path does this in trampoline) */
13143+ call verify_cpu
13144+
13145 /* This could also be done in C code... */
13146 movl pmode_cr3, %eax
13147 movl %eax, %cr3
13148@@ -104,7 +107,7 @@ _start:
13149 movl %eax, %ecx
13150 orl %edx, %ecx
13151 jz 1f
13152- movl $0xc0000080, %ecx
13153+ mov $MSR_EFER, %ecx
13154 wrmsr
13155 1:
13156
13157@@ -114,6 +117,7 @@ _start:
13158 movl pmode_cr0, %eax
13159 movl %eax, %cr0
13160 jmp pmode_return
13161+# include "../../verify_cpu.S"
13162 #else
13163 pushw $0
13164 pushw trampoline_segment
13165diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13166index ca93638..7042f24 100644
13167--- a/arch/x86/kernel/acpi/sleep.c
13168+++ b/arch/x86/kernel/acpi/sleep.c
13169@@ -11,11 +11,12 @@
13170 #include <linux/cpumask.h>
13171 #include <asm/segment.h>
13172 #include <asm/desc.h>
13173+#include <asm/e820.h>
13174
13175 #include "realmode/wakeup.h"
13176 #include "sleep.h"
13177
13178-unsigned long acpi_wakeup_address;
13179+unsigned long acpi_wakeup_address = 0x2000;
13180 unsigned long acpi_realmode_flags;
13181
13182 /* address in low memory of the wakeup routine. */
13183@@ -98,9 +99,13 @@ int acpi_save_state_mem(void)
13184 #else /* CONFIG_64BIT */
13185 header->trampoline_segment = setup_trampoline() >> 4;
13186 #ifdef CONFIG_SMP
13187- stack_start.sp = temp_stack + sizeof(temp_stack);
13188+ stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13189+
13190+ pax_open_kernel();
13191 early_gdt_descr.address =
13192 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13193+ pax_close_kernel();
13194+
13195 initial_gs = per_cpu_offset(smp_processor_id());
13196 #endif
13197 initial_code = (unsigned long)wakeup_long64;
13198@@ -134,14 +139,8 @@ void __init acpi_reserve_bootmem(void)
13199 return;
13200 }
13201
13202- acpi_realmode = (unsigned long)alloc_bootmem_low(WAKEUP_SIZE);
13203-
13204- if (!acpi_realmode) {
13205- printk(KERN_ERR "ACPI: Cannot allocate lowmem, S3 disabled.\n");
13206- return;
13207- }
13208-
13209- acpi_wakeup_address = virt_to_phys((void *)acpi_realmode);
13210+ reserve_early(acpi_wakeup_address, acpi_wakeup_address + WAKEUP_SIZE, "ACPI Wakeup Code");
13211+ acpi_realmode = (unsigned long)__va(acpi_wakeup_address);;
13212 }
13213
13214
13215diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13216index 8ded418..079961e 100644
13217--- a/arch/x86/kernel/acpi/wakeup_32.S
13218+++ b/arch/x86/kernel/acpi/wakeup_32.S
13219@@ -30,13 +30,11 @@ wakeup_pmode_return:
13220 # and restore the stack ... but you need gdt for this to work
13221 movl saved_context_esp, %esp
13222
13223- movl %cs:saved_magic, %eax
13224- cmpl $0x12345678, %eax
13225+ cmpl $0x12345678, saved_magic
13226 jne bogus_magic
13227
13228 # jump to place where we left off
13229- movl saved_eip, %eax
13230- jmp *%eax
13231+ jmp *(saved_eip)
13232
13233 bogus_magic:
13234 jmp bogus_magic
13235diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13236index de7353c..075da5f 100644
13237--- a/arch/x86/kernel/alternative.c
13238+++ b/arch/x86/kernel/alternative.c
13239@@ -407,7 +407,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13240
13241 BUG_ON(p->len > MAX_PATCH_LEN);
13242 /* prep the buffer with the original instructions */
13243- memcpy(insnbuf, p->instr, p->len);
13244+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13245 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13246 (unsigned long)p->instr, p->len);
13247
13248@@ -475,7 +475,7 @@ void __init alternative_instructions(void)
13249 if (smp_alt_once)
13250 free_init_pages("SMP alternatives",
13251 (unsigned long)__smp_locks,
13252- (unsigned long)__smp_locks_end);
13253+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13254
13255 restart_nmi();
13256 }
13257@@ -492,13 +492,17 @@ void __init alternative_instructions(void)
13258 * instructions. And on the local CPU you need to be protected again NMI or MCE
13259 * handlers seeing an inconsistent instruction while you patch.
13260 */
13261-static void *__init_or_module text_poke_early(void *addr, const void *opcode,
13262+static void *__kprobes text_poke_early(void *addr, const void *opcode,
13263 size_t len)
13264 {
13265 unsigned long flags;
13266 local_irq_save(flags);
13267- memcpy(addr, opcode, len);
13268+
13269+ pax_open_kernel();
13270+ memcpy(ktla_ktva(addr), opcode, len);
13271 sync_core();
13272+ pax_close_kernel();
13273+
13274 local_irq_restore(flags);
13275 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13276 that causes hangs on some VIA CPUs. */
13277@@ -520,35 +524,21 @@ static void *__init_or_module text_poke_early(void *addr, const void *opcode,
13278 */
13279 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13280 {
13281- unsigned long flags;
13282- char *vaddr;
13283+ unsigned char *vaddr = ktla_ktva(addr);
13284 struct page *pages[2];
13285- int i;
13286+ size_t i;
13287
13288 if (!core_kernel_text((unsigned long)addr)) {
13289- pages[0] = vmalloc_to_page(addr);
13290- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13291+ pages[0] = vmalloc_to_page(vaddr);
13292+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13293 } else {
13294- pages[0] = virt_to_page(addr);
13295+ pages[0] = virt_to_page(vaddr);
13296 WARN_ON(!PageReserved(pages[0]));
13297- pages[1] = virt_to_page(addr + PAGE_SIZE);
13298+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13299 }
13300 BUG_ON(!pages[0]);
13301- local_irq_save(flags);
13302- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13303- if (pages[1])
13304- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13305- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13306- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13307- clear_fixmap(FIX_TEXT_POKE0);
13308- if (pages[1])
13309- clear_fixmap(FIX_TEXT_POKE1);
13310- local_flush_tlb();
13311- sync_core();
13312- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13313- that causes hangs on some VIA CPUs. */
13314+ text_poke_early(addr, opcode, len);
13315 for (i = 0; i < len; i++)
13316- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13317- local_irq_restore(flags);
13318+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13319 return addr;
13320 }
13321diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
13322index 3a44b75..1601800 100644
13323--- a/arch/x86/kernel/amd_iommu.c
13324+++ b/arch/x86/kernel/amd_iommu.c
13325@@ -2076,7 +2076,7 @@ static void prealloc_protection_domains(void)
13326 }
13327 }
13328
13329-static struct dma_map_ops amd_iommu_dma_ops = {
13330+static const struct dma_map_ops amd_iommu_dma_ops = {
13331 .alloc_coherent = alloc_coherent,
13332 .free_coherent = free_coherent,
13333 .map_page = map_page,
13334diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13335index 1d2d670..8e3f477 100644
13336--- a/arch/x86/kernel/apic/apic.c
13337+++ b/arch/x86/kernel/apic/apic.c
13338@@ -170,7 +170,7 @@ int first_system_vector = 0xfe;
13339 /*
13340 * Debug level, exported for io_apic.c
13341 */
13342-unsigned int apic_verbosity;
13343+int apic_verbosity;
13344
13345 int pic_mode;
13346
13347@@ -1794,7 +1794,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13348 apic_write(APIC_ESR, 0);
13349 v1 = apic_read(APIC_ESR);
13350 ack_APIC_irq();
13351- atomic_inc(&irq_err_count);
13352+ atomic_inc_unchecked(&irq_err_count);
13353
13354 /*
13355 * Here is what the APIC error bits mean:
13356@@ -2184,6 +2184,8 @@ static int __cpuinit apic_cluster_num(void)
13357 u16 *bios_cpu_apicid;
13358 DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
13359
13360+ pax_track_stack();
13361+
13362 bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
13363 bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
13364
13365diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13366index 8928d97..f799cea 100644
13367--- a/arch/x86/kernel/apic/io_apic.c
13368+++ b/arch/x86/kernel/apic/io_apic.c
13369@@ -716,7 +716,7 @@ struct IO_APIC_route_entry **alloc_ioapic_entries(void)
13370 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
13371 GFP_ATOMIC);
13372 if (!ioapic_entries)
13373- return 0;
13374+ return NULL;
13375
13376 for (apic = 0; apic < nr_ioapics; apic++) {
13377 ioapic_entries[apic] =
13378@@ -733,7 +733,7 @@ nomem:
13379 kfree(ioapic_entries[apic]);
13380 kfree(ioapic_entries);
13381
13382- return 0;
13383+ return NULL;
13384 }
13385
13386 /*
13387@@ -1150,7 +1150,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13388 }
13389 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13390
13391-void lock_vector_lock(void)
13392+void lock_vector_lock(void) __acquires(vector_lock)
13393 {
13394 /* Used to the online set of cpus does not change
13395 * during assign_irq_vector.
13396@@ -1158,7 +1158,7 @@ void lock_vector_lock(void)
13397 spin_lock(&vector_lock);
13398 }
13399
13400-void unlock_vector_lock(void)
13401+void unlock_vector_lock(void) __releases(vector_lock)
13402 {
13403 spin_unlock(&vector_lock);
13404 }
13405@@ -2542,7 +2542,7 @@ static void ack_apic_edge(unsigned int irq)
13406 ack_APIC_irq();
13407 }
13408
13409-atomic_t irq_mis_count;
13410+atomic_unchecked_t irq_mis_count;
13411
13412 static void ack_apic_level(unsigned int irq)
13413 {
13414@@ -2626,7 +2626,7 @@ static void ack_apic_level(unsigned int irq)
13415
13416 /* Tail end of version 0x11 I/O APIC bug workaround */
13417 if (!(v & (1 << (i & 0x1f)))) {
13418- atomic_inc(&irq_mis_count);
13419+ atomic_inc_unchecked(&irq_mis_count);
13420 spin_lock(&ioapic_lock);
13421 __mask_and_edge_IO_APIC_irq(cfg);
13422 __unmask_and_level_IO_APIC_irq(cfg);
13423diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13424index 151ace6..f317474 100644
13425--- a/arch/x86/kernel/apm_32.c
13426+++ b/arch/x86/kernel/apm_32.c
13427@@ -410,7 +410,7 @@ static DEFINE_SPINLOCK(user_list_lock);
13428 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13429 * even though they are called in protected mode.
13430 */
13431-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13432+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13433 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13434
13435 static const char driver_version[] = "1.16ac"; /* no spaces */
13436@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13437 BUG_ON(cpu != 0);
13438 gdt = get_cpu_gdt_table(cpu);
13439 save_desc_40 = gdt[0x40 / 8];
13440+
13441+ pax_open_kernel();
13442 gdt[0x40 / 8] = bad_bios_desc;
13443+ pax_close_kernel();
13444
13445 apm_irq_save(flags);
13446 APM_DO_SAVE_SEGS;
13447@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13448 &call->esi);
13449 APM_DO_RESTORE_SEGS;
13450 apm_irq_restore(flags);
13451+
13452+ pax_open_kernel();
13453 gdt[0x40 / 8] = save_desc_40;
13454+ pax_close_kernel();
13455+
13456 put_cpu();
13457
13458 return call->eax & 0xff;
13459@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13460 BUG_ON(cpu != 0);
13461 gdt = get_cpu_gdt_table(cpu);
13462 save_desc_40 = gdt[0x40 / 8];
13463+
13464+ pax_open_kernel();
13465 gdt[0x40 / 8] = bad_bios_desc;
13466+ pax_close_kernel();
13467
13468 apm_irq_save(flags);
13469 APM_DO_SAVE_SEGS;
13470@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13471 &call->eax);
13472 APM_DO_RESTORE_SEGS;
13473 apm_irq_restore(flags);
13474+
13475+ pax_open_kernel();
13476 gdt[0x40 / 8] = save_desc_40;
13477+ pax_close_kernel();
13478+
13479 put_cpu();
13480 return error;
13481 }
13482@@ -975,7 +989,7 @@ recalc:
13483
13484 static void apm_power_off(void)
13485 {
13486- unsigned char po_bios_call[] = {
13487+ const unsigned char po_bios_call[] = {
13488 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
13489 0x8e, 0xd0, /* movw ax,ss */
13490 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
13491@@ -2357,12 +2371,15 @@ static int __init apm_init(void)
13492 * code to that CPU.
13493 */
13494 gdt = get_cpu_gdt_table(0);
13495+
13496+ pax_open_kernel();
13497 set_desc_base(&gdt[APM_CS >> 3],
13498 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13499 set_desc_base(&gdt[APM_CS_16 >> 3],
13500 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13501 set_desc_base(&gdt[APM_DS >> 3],
13502 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13503+ pax_close_kernel();
13504
13505 proc_create("apm", 0, NULL, &apm_file_ops);
13506
13507diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c
13508index dfdbf64..9b2b6ce 100644
13509--- a/arch/x86/kernel/asm-offsets_32.c
13510+++ b/arch/x86/kernel/asm-offsets_32.c
13511@@ -51,7 +51,6 @@ void foo(void)
13512 OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
13513 BLANK();
13514
13515- OFFSET(TI_task, thread_info, task);
13516 OFFSET(TI_exec_domain, thread_info, exec_domain);
13517 OFFSET(TI_flags, thread_info, flags);
13518 OFFSET(TI_status, thread_info, status);
13519@@ -60,6 +59,8 @@ void foo(void)
13520 OFFSET(TI_restart_block, thread_info, restart_block);
13521 OFFSET(TI_sysenter_return, thread_info, sysenter_return);
13522 OFFSET(TI_cpu, thread_info, cpu);
13523+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13524+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13525 BLANK();
13526
13527 OFFSET(GDS_size, desc_ptr, size);
13528@@ -99,6 +100,7 @@ void foo(void)
13529
13530 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13531 DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13532+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13533 DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
13534 DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
13535 DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
13536@@ -115,6 +117,11 @@ void foo(void)
13537 OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
13538 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13539 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13540+
13541+#ifdef CONFIG_PAX_KERNEXEC
13542+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13543+#endif
13544+
13545 #endif
13546
13547 #ifdef CONFIG_XEN
13548diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13549index 4a6aeed..371de20 100644
13550--- a/arch/x86/kernel/asm-offsets_64.c
13551+++ b/arch/x86/kernel/asm-offsets_64.c
13552@@ -44,6 +44,8 @@ int main(void)
13553 ENTRY(addr_limit);
13554 ENTRY(preempt_count);
13555 ENTRY(status);
13556+ ENTRY(lowest_stack);
13557+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13558 #ifdef CONFIG_IA32_EMULATION
13559 ENTRY(sysenter_return);
13560 #endif
13561@@ -63,6 +65,18 @@ int main(void)
13562 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13563 OFFSET(PV_CPU_swapgs, pv_cpu_ops, swapgs);
13564 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13565+
13566+#ifdef CONFIG_PAX_KERNEXEC
13567+ OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13568+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13569+#endif
13570+
13571+#ifdef CONFIG_PAX_MEMORY_UDEREF
13572+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13573+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13574+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13575+#endif
13576+
13577 #endif
13578
13579
13580@@ -115,6 +129,7 @@ int main(void)
13581 ENTRY(cr8);
13582 BLANK();
13583 #undef ENTRY
13584+ DEFINE(TSS_size, sizeof(struct tss_struct));
13585 DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
13586 BLANK();
13587 DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
13588@@ -130,6 +145,7 @@ int main(void)
13589
13590 BLANK();
13591 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13592+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13593 #ifdef CONFIG_XEN
13594 BLANK();
13595 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13596diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13597index ff502cc..dc5133e 100644
13598--- a/arch/x86/kernel/cpu/Makefile
13599+++ b/arch/x86/kernel/cpu/Makefile
13600@@ -7,10 +7,6 @@ ifdef CONFIG_FUNCTION_TRACER
13601 CFLAGS_REMOVE_common.o = -pg
13602 endif
13603
13604-# Make sure load_percpu_segment has no stackprotector
13605-nostackp := $(call cc-option, -fno-stack-protector)
13606-CFLAGS_common.o := $(nostackp)
13607-
13608 obj-y := intel_cacheinfo.o addon_cpuid_features.o
13609 obj-y += proc.o capflags.o powerflags.o common.o
13610 obj-y += vmware.o hypervisor.o sched.o
13611diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13612index 6e082dc..a0b5f36 100644
13613--- a/arch/x86/kernel/cpu/amd.c
13614+++ b/arch/x86/kernel/cpu/amd.c
13615@@ -602,7 +602,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13616 unsigned int size)
13617 {
13618 /* AMD errata T13 (order #21922) */
13619- if ((c->x86 == 6)) {
13620+ if (c->x86 == 6) {
13621 /* Duron Rev A0 */
13622 if (c->x86_model == 3 && c->x86_mask == 0)
13623 size = 64;
13624diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13625index 4e34d10..ba6bc97 100644
13626--- a/arch/x86/kernel/cpu/common.c
13627+++ b/arch/x86/kernel/cpu/common.c
13628@@ -83,60 +83,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13629
13630 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13631
13632-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13633-#ifdef CONFIG_X86_64
13634- /*
13635- * We need valid kernel segments for data and code in long mode too
13636- * IRET will check the segment types kkeil 2000/10/28
13637- * Also sysret mandates a special GDT layout
13638- *
13639- * TLS descriptors are currently at a different place compared to i386.
13640- * Hopefully nobody expects them at a fixed place (Wine?)
13641- */
13642- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
13643- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
13644- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
13645- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
13646- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
13647- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
13648-#else
13649- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
13650- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13651- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
13652- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
13653- /*
13654- * Segments used for calling PnP BIOS have byte granularity.
13655- * They code segments and data segments have fixed 64k limits,
13656- * the transfer segment sizes are set at run time.
13657- */
13658- /* 32-bit code */
13659- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13660- /* 16-bit code */
13661- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13662- /* 16-bit data */
13663- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
13664- /* 16-bit data */
13665- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
13666- /* 16-bit data */
13667- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
13668- /*
13669- * The APM segments have byte granularity and their bases
13670- * are set at run time. All have 64k limits.
13671- */
13672- /* 32-bit code */
13673- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
13674- /* 16-bit code */
13675- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
13676- /* data */
13677- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
13678-
13679- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13680- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
13681- GDT_STACK_CANARY_INIT
13682-#endif
13683-} };
13684-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
13685-
13686 static int __init x86_xsave_setup(char *s)
13687 {
13688 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
13689@@ -344,7 +290,7 @@ void switch_to_new_gdt(int cpu)
13690 {
13691 struct desc_ptr gdt_descr;
13692
13693- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
13694+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
13695 gdt_descr.size = GDT_SIZE - 1;
13696 load_gdt(&gdt_descr);
13697 /* Reload the per-cpu base */
13698@@ -798,6 +744,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
13699 /* Filter out anything that depends on CPUID levels we don't have */
13700 filter_cpuid_features(c, true);
13701
13702+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
13703+ setup_clear_cpu_cap(X86_FEATURE_SEP);
13704+#endif
13705+
13706 /* If the model name is still unset, do table lookup. */
13707 if (!c->x86_model_id[0]) {
13708 const char *p;
13709@@ -980,6 +930,9 @@ static __init int setup_disablecpuid(char *arg)
13710 }
13711 __setup("clearcpuid=", setup_disablecpuid);
13712
13713+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
13714+EXPORT_PER_CPU_SYMBOL(current_tinfo);
13715+
13716 #ifdef CONFIG_X86_64
13717 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
13718
13719@@ -995,7 +948,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
13720 EXPORT_PER_CPU_SYMBOL(current_task);
13721
13722 DEFINE_PER_CPU(unsigned long, kernel_stack) =
13723- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
13724+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
13725 EXPORT_PER_CPU_SYMBOL(kernel_stack);
13726
13727 DEFINE_PER_CPU(char *, irq_stack_ptr) =
13728@@ -1060,7 +1013,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
13729 {
13730 memset(regs, 0, sizeof(struct pt_regs));
13731 regs->fs = __KERNEL_PERCPU;
13732- regs->gs = __KERNEL_STACK_CANARY;
13733+ savesegment(gs, regs->gs);
13734
13735 return regs;
13736 }
13737@@ -1101,7 +1054,7 @@ void __cpuinit cpu_init(void)
13738 int i;
13739
13740 cpu = stack_smp_processor_id();
13741- t = &per_cpu(init_tss, cpu);
13742+ t = init_tss + cpu;
13743 orig_ist = &per_cpu(orig_ist, cpu);
13744
13745 #ifdef CONFIG_NUMA
13746@@ -1127,7 +1080,7 @@ void __cpuinit cpu_init(void)
13747 switch_to_new_gdt(cpu);
13748 loadsegment(fs, 0);
13749
13750- load_idt((const struct desc_ptr *)&idt_descr);
13751+ load_idt(&idt_descr);
13752
13753 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
13754 syscall_init();
13755@@ -1136,7 +1089,6 @@ void __cpuinit cpu_init(void)
13756 wrmsrl(MSR_KERNEL_GS_BASE, 0);
13757 barrier();
13758
13759- check_efer();
13760 if (cpu != 0)
13761 enable_x2apic();
13762
13763@@ -1199,7 +1151,7 @@ void __cpuinit cpu_init(void)
13764 {
13765 int cpu = smp_processor_id();
13766 struct task_struct *curr = current;
13767- struct tss_struct *t = &per_cpu(init_tss, cpu);
13768+ struct tss_struct *t = init_tss + cpu;
13769 struct thread_struct *thread = &curr->thread;
13770
13771 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
13772diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
13773index 6a77cca..4f4fca0 100644
13774--- a/arch/x86/kernel/cpu/intel.c
13775+++ b/arch/x86/kernel/cpu/intel.c
13776@@ -162,7 +162,7 @@ static void __cpuinit trap_init_f00f_bug(void)
13777 * Update the IDT descriptor and reload the IDT so that
13778 * it uses the read-only mapped virtual address.
13779 */
13780- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
13781+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
13782 load_idt(&idt_descr);
13783 }
13784 #endif
13785diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
13786index 417990f..96dc36b 100644
13787--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
13788+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
13789@@ -921,7 +921,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
13790 return ret;
13791 }
13792
13793-static struct sysfs_ops sysfs_ops = {
13794+static const struct sysfs_ops sysfs_ops = {
13795 .show = show,
13796 .store = store,
13797 };
13798diff --git a/arch/x86/kernel/cpu/mcheck/mce-inject.c b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13799index 472763d..9831e11 100644
13800--- a/arch/x86/kernel/cpu/mcheck/mce-inject.c
13801+++ b/arch/x86/kernel/cpu/mcheck/mce-inject.c
13802@@ -211,7 +211,9 @@ static ssize_t mce_write(struct file *filp, const char __user *ubuf,
13803 static int inject_init(void)
13804 {
13805 printk(KERN_INFO "Machine check injector initialized\n");
13806- mce_chrdev_ops.write = mce_write;
13807+ pax_open_kernel();
13808+ *(void **)&mce_chrdev_ops.write = mce_write;
13809+ pax_close_kernel();
13810 register_die_notifier(&mce_raise_nb);
13811 return 0;
13812 }
13813diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
13814index 0f16a2b..21740f5 100644
13815--- a/arch/x86/kernel/cpu/mcheck/mce.c
13816+++ b/arch/x86/kernel/cpu/mcheck/mce.c
13817@@ -43,6 +43,7 @@
13818 #include <asm/ipi.h>
13819 #include <asm/mce.h>
13820 #include <asm/msr.h>
13821+#include <asm/local.h>
13822
13823 #include "mce-internal.h"
13824
13825@@ -187,7 +188,7 @@ static void print_mce(struct mce *m)
13826 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
13827 m->cs, m->ip);
13828
13829- if (m->cs == __KERNEL_CS)
13830+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
13831 print_symbol("{%s}", m->ip);
13832 pr_cont("\n");
13833 }
13834@@ -221,10 +222,10 @@ static void print_mce_tail(void)
13835
13836 #define PANIC_TIMEOUT 5 /* 5 seconds */
13837
13838-static atomic_t mce_paniced;
13839+static atomic_unchecked_t mce_paniced;
13840
13841 static int fake_panic;
13842-static atomic_t mce_fake_paniced;
13843+static atomic_unchecked_t mce_fake_paniced;
13844
13845 /* Panic in progress. Enable interrupts and wait for final IPI */
13846 static void wait_for_panic(void)
13847@@ -248,7 +249,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13848 /*
13849 * Make sure only one CPU runs in machine check panic
13850 */
13851- if (atomic_inc_return(&mce_paniced) > 1)
13852+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
13853 wait_for_panic();
13854 barrier();
13855
13856@@ -256,7 +257,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
13857 console_verbose();
13858 } else {
13859 /* Don't log too much for fake panic */
13860- if (atomic_inc_return(&mce_fake_paniced) > 1)
13861+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
13862 return;
13863 }
13864 print_mce_head();
13865@@ -616,7 +617,7 @@ static int mce_timed_out(u64 *t)
13866 * might have been modified by someone else.
13867 */
13868 rmb();
13869- if (atomic_read(&mce_paniced))
13870+ if (atomic_read_unchecked(&mce_paniced))
13871 wait_for_panic();
13872 if (!monarch_timeout)
13873 goto out;
13874@@ -1394,7 +1395,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
13875 }
13876
13877 /* Call the installed machine check handler for this CPU setup. */
13878-void (*machine_check_vector)(struct pt_regs *, long error_code) =
13879+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
13880 unexpected_machine_check;
13881
13882 /*
13883@@ -1416,7 +1417,9 @@ void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
13884 return;
13885 }
13886
13887+ pax_open_kernel();
13888 machine_check_vector = do_machine_check;
13889+ pax_close_kernel();
13890
13891 mce_init();
13892 mce_cpu_features(c);
13893@@ -1429,14 +1432,14 @@ void __cpuinit mcheck_init(struct cpuinfo_x86 *c)
13894 */
13895
13896 static DEFINE_SPINLOCK(mce_state_lock);
13897-static int open_count; /* #times opened */
13898+static local_t open_count; /* #times opened */
13899 static int open_exclu; /* already open exclusive? */
13900
13901 static int mce_open(struct inode *inode, struct file *file)
13902 {
13903 spin_lock(&mce_state_lock);
13904
13905- if (open_exclu || (open_count && (file->f_flags & O_EXCL))) {
13906+ if (open_exclu || (local_read(&open_count) && (file->f_flags & O_EXCL))) {
13907 spin_unlock(&mce_state_lock);
13908
13909 return -EBUSY;
13910@@ -1444,7 +1447,7 @@ static int mce_open(struct inode *inode, struct file *file)
13911
13912 if (file->f_flags & O_EXCL)
13913 open_exclu = 1;
13914- open_count++;
13915+ local_inc(&open_count);
13916
13917 spin_unlock(&mce_state_lock);
13918
13919@@ -1455,7 +1458,7 @@ static int mce_release(struct inode *inode, struct file *file)
13920 {
13921 spin_lock(&mce_state_lock);
13922
13923- open_count--;
13924+ local_dec(&open_count);
13925 open_exclu = 0;
13926
13927 spin_unlock(&mce_state_lock);
13928@@ -2082,7 +2085,7 @@ struct dentry *mce_get_debugfs_dir(void)
13929 static void mce_reset(void)
13930 {
13931 cpu_missing = 0;
13932- atomic_set(&mce_fake_paniced, 0);
13933+ atomic_set_unchecked(&mce_fake_paniced, 0);
13934 atomic_set(&mce_executing, 0);
13935 atomic_set(&mce_callin, 0);
13936 atomic_set(&global_nwo, 0);
13937diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
13938index ef3cd31..9d2f6ab 100644
13939--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
13940+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
13941@@ -385,7 +385,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
13942 return ret;
13943 }
13944
13945-static struct sysfs_ops threshold_ops = {
13946+static const struct sysfs_ops threshold_ops = {
13947 .show = show,
13948 .store = store,
13949 };
13950diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
13951index 5c0e653..1e82c7c 100644
13952--- a/arch/x86/kernel/cpu/mcheck/p5.c
13953+++ b/arch/x86/kernel/cpu/mcheck/p5.c
13954@@ -50,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
13955 if (!cpu_has(c, X86_FEATURE_MCE))
13956 return;
13957
13958+ pax_open_kernel();
13959 machine_check_vector = pentium_machine_check;
13960+ pax_close_kernel();
13961 /* Make sure the vector pointer is visible before we enable MCEs: */
13962 wmb();
13963
13964diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
13965index 54060f5..e6ba93d 100644
13966--- a/arch/x86/kernel/cpu/mcheck/winchip.c
13967+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
13968@@ -24,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
13969 {
13970 u32 lo, hi;
13971
13972+ pax_open_kernel();
13973 machine_check_vector = winchip_machine_check;
13974+ pax_close_kernel();
13975 /* Make sure the vector pointer is visible before we enable MCEs: */
13976 wmb();
13977
13978diff --git a/arch/x86/kernel/cpu/mtrr/amd.c b/arch/x86/kernel/cpu/mtrr/amd.c
13979index 33af141..92ba9cd 100644
13980--- a/arch/x86/kernel/cpu/mtrr/amd.c
13981+++ b/arch/x86/kernel/cpu/mtrr/amd.c
13982@@ -108,7 +108,7 @@ amd_validate_add_page(unsigned long base, unsigned long size, unsigned int type)
13983 return 0;
13984 }
13985
13986-static struct mtrr_ops amd_mtrr_ops = {
13987+static const struct mtrr_ops amd_mtrr_ops = {
13988 .vendor = X86_VENDOR_AMD,
13989 .set = amd_set_mtrr,
13990 .get = amd_get_mtrr,
13991diff --git a/arch/x86/kernel/cpu/mtrr/centaur.c b/arch/x86/kernel/cpu/mtrr/centaur.c
13992index de89f14..316fe3e 100644
13993--- a/arch/x86/kernel/cpu/mtrr/centaur.c
13994+++ b/arch/x86/kernel/cpu/mtrr/centaur.c
13995@@ -110,7 +110,7 @@ centaur_validate_add_page(unsigned long base, unsigned long size, unsigned int t
13996 return 0;
13997 }
13998
13999-static struct mtrr_ops centaur_mtrr_ops = {
14000+static const struct mtrr_ops centaur_mtrr_ops = {
14001 .vendor = X86_VENDOR_CENTAUR,
14002 .set = centaur_set_mcr,
14003 .get = centaur_get_mcr,
14004diff --git a/arch/x86/kernel/cpu/mtrr/cyrix.c b/arch/x86/kernel/cpu/mtrr/cyrix.c
14005index 228d982..68a3343 100644
14006--- a/arch/x86/kernel/cpu/mtrr/cyrix.c
14007+++ b/arch/x86/kernel/cpu/mtrr/cyrix.c
14008@@ -265,7 +265,7 @@ static void cyrix_set_all(void)
14009 post_set();
14010 }
14011
14012-static struct mtrr_ops cyrix_mtrr_ops = {
14013+static const struct mtrr_ops cyrix_mtrr_ops = {
14014 .vendor = X86_VENDOR_CYRIX,
14015 .set_all = cyrix_set_all,
14016 .set = cyrix_set_arr,
14017diff --git a/arch/x86/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
14018index 55da0c5..4d75584 100644
14019--- a/arch/x86/kernel/cpu/mtrr/generic.c
14020+++ b/arch/x86/kernel/cpu/mtrr/generic.c
14021@@ -752,7 +752,7 @@ int positive_have_wrcomb(void)
14022 /*
14023 * Generic structure...
14024 */
14025-struct mtrr_ops generic_mtrr_ops = {
14026+const struct mtrr_ops generic_mtrr_ops = {
14027 .use_intel_if = 1,
14028 .set_all = generic_set_all,
14029 .get = generic_get_mtrr,
14030diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14031index fd60f09..c94ef52 100644
14032--- a/arch/x86/kernel/cpu/mtrr/main.c
14033+++ b/arch/x86/kernel/cpu/mtrr/main.c
14034@@ -60,14 +60,14 @@ static DEFINE_MUTEX(mtrr_mutex);
14035 u64 size_or_mask, size_and_mask;
14036 static bool mtrr_aps_delayed_init;
14037
14038-static struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14039+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14040
14041-struct mtrr_ops *mtrr_if;
14042+const struct mtrr_ops *mtrr_if;
14043
14044 static void set_mtrr(unsigned int reg, unsigned long base,
14045 unsigned long size, mtrr_type type);
14046
14047-void set_mtrr_ops(struct mtrr_ops *ops)
14048+void set_mtrr_ops(const struct mtrr_ops *ops)
14049 {
14050 if (ops->vendor && ops->vendor < X86_VENDOR_NUM)
14051 mtrr_ops[ops->vendor] = ops;
14052diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14053index a501dee..816c719 100644
14054--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14055+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14056@@ -25,14 +25,14 @@ struct mtrr_ops {
14057 int (*validate_add_page)(unsigned long base, unsigned long size,
14058 unsigned int type);
14059 int (*have_wrcomb)(void);
14060-};
14061+} __do_const;
14062
14063 extern int generic_get_free_region(unsigned long base, unsigned long size,
14064 int replace_reg);
14065 extern int generic_validate_add_page(unsigned long base, unsigned long size,
14066 unsigned int type);
14067
14068-extern struct mtrr_ops generic_mtrr_ops;
14069+extern const struct mtrr_ops generic_mtrr_ops;
14070
14071 extern int positive_have_wrcomb(void);
14072
14073@@ -53,10 +53,10 @@ void fill_mtrr_var_range(unsigned int index,
14074 u32 base_lo, u32 base_hi, u32 mask_lo, u32 mask_hi);
14075 void get_mtrr_state(void);
14076
14077-extern void set_mtrr_ops(struct mtrr_ops *ops);
14078+extern void set_mtrr_ops(const struct mtrr_ops *ops);
14079
14080 extern u64 size_or_mask, size_and_mask;
14081-extern struct mtrr_ops *mtrr_if;
14082+extern const struct mtrr_ops *mtrr_if;
14083
14084 #define is_cpu(vnd) (mtrr_if && mtrr_if->vendor == X86_VENDOR_##vnd)
14085 #define use_intel() (mtrr_if && mtrr_if->use_intel_if == 1)
14086diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14087index 0ff02ca..fc49a60 100644
14088--- a/arch/x86/kernel/cpu/perf_event.c
14089+++ b/arch/x86/kernel/cpu/perf_event.c
14090@@ -723,10 +723,10 @@ x86_perf_event_update(struct perf_event *event,
14091 * count to the generic event atomically:
14092 */
14093 again:
14094- prev_raw_count = atomic64_read(&hwc->prev_count);
14095+ prev_raw_count = atomic64_read_unchecked(&hwc->prev_count);
14096 rdmsrl(hwc->event_base + idx, new_raw_count);
14097
14098- if (atomic64_cmpxchg(&hwc->prev_count, prev_raw_count,
14099+ if (atomic64_cmpxchg_unchecked(&hwc->prev_count, prev_raw_count,
14100 new_raw_count) != prev_raw_count)
14101 goto again;
14102
14103@@ -741,7 +741,7 @@ again:
14104 delta = (new_raw_count << shift) - (prev_raw_count << shift);
14105 delta >>= shift;
14106
14107- atomic64_add(delta, &event->count);
14108+ atomic64_add_unchecked(delta, &event->count);
14109 atomic64_sub(delta, &hwc->period_left);
14110
14111 return new_raw_count;
14112@@ -1353,7 +1353,7 @@ x86_perf_event_set_period(struct perf_event *event,
14113 * The hw event starts counting from this event offset,
14114 * mark it to be able to extra future deltas:
14115 */
14116- atomic64_set(&hwc->prev_count, (u64)-left);
14117+ atomic64_set_unchecked(&hwc->prev_count, (u64)-left);
14118
14119 err = checking_wrmsrl(hwc->event_base + idx,
14120 (u64)(-left) & x86_pmu.event_mask);
14121@@ -2357,7 +2357,7 @@ perf_callchain_user(struct pt_regs *regs, struct perf_callchain_entry *entry)
14122 break;
14123
14124 callchain_store(entry, frame.return_address);
14125- fp = frame.next_frame;
14126+ fp = (__force const void __user *)frame.next_frame;
14127 }
14128 }
14129
14130diff --git a/arch/x86/kernel/cpu/perfctr-watchdog.c b/arch/x86/kernel/cpu/perfctr-watchdog.c
14131index 898df97..9e82503 100644
14132--- a/arch/x86/kernel/cpu/perfctr-watchdog.c
14133+++ b/arch/x86/kernel/cpu/perfctr-watchdog.c
14134@@ -30,11 +30,11 @@ struct nmi_watchdog_ctlblk {
14135
14136 /* Interface defining a CPU specific perfctr watchdog */
14137 struct wd_ops {
14138- int (*reserve)(void);
14139- void (*unreserve)(void);
14140- int (*setup)(unsigned nmi_hz);
14141- void (*rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
14142- void (*stop)(void);
14143+ int (* const reserve)(void);
14144+ void (* const unreserve)(void);
14145+ int (* const setup)(unsigned nmi_hz);
14146+ void (* const rearm)(struct nmi_watchdog_ctlblk *wd, unsigned nmi_hz);
14147+ void (* const stop)(void);
14148 unsigned perfctr;
14149 unsigned evntsel;
14150 u64 checkbit;
14151@@ -645,6 +645,7 @@ static const struct wd_ops p4_wd_ops = {
14152 #define ARCH_PERFMON_NMI_EVENT_SEL ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL
14153 #define ARCH_PERFMON_NMI_EVENT_UMASK ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK
14154
14155+/* cannot be const */
14156 static struct wd_ops intel_arch_wd_ops;
14157
14158 static int setup_intel_arch_watchdog(unsigned nmi_hz)
14159@@ -697,6 +698,7 @@ static int setup_intel_arch_watchdog(unsigned nmi_hz)
14160 return 1;
14161 }
14162
14163+/* cannot be const */
14164 static struct wd_ops intel_arch_wd_ops __read_mostly = {
14165 .reserve = single_msr_reserve,
14166 .unreserve = single_msr_unreserve,
14167diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14168index ff95824..2ffdcb5 100644
14169--- a/arch/x86/kernel/crash.c
14170+++ b/arch/x86/kernel/crash.c
14171@@ -41,7 +41,7 @@ static void kdump_nmi_callback(int cpu, struct die_args *args)
14172 regs = args->regs;
14173
14174 #ifdef CONFIG_X86_32
14175- if (!user_mode_vm(regs)) {
14176+ if (!user_mode(regs)) {
14177 crash_fixup_ss_esp(&fixed_regs, regs);
14178 regs = &fixed_regs;
14179 }
14180diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14181index 37250fe..bf2ec74 100644
14182--- a/arch/x86/kernel/doublefault_32.c
14183+++ b/arch/x86/kernel/doublefault_32.c
14184@@ -11,7 +11,7 @@
14185
14186 #define DOUBLEFAULT_STACKSIZE (1024)
14187 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14188-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14189+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14190
14191 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14192
14193@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14194 unsigned long gdt, tss;
14195
14196 store_gdt(&gdt_desc);
14197- gdt = gdt_desc.address;
14198+ gdt = (unsigned long)gdt_desc.address;
14199
14200 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14201
14202@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14203 /* 0x2 bit is always set */
14204 .flags = X86_EFLAGS_SF | 0x2,
14205 .sp = STACK_START,
14206- .es = __USER_DS,
14207+ .es = __KERNEL_DS,
14208 .cs = __KERNEL_CS,
14209 .ss = __KERNEL_DS,
14210- .ds = __USER_DS,
14211+ .ds = __KERNEL_DS,
14212 .fs = __KERNEL_PERCPU,
14213
14214 .__cr3 = __pa_nodebug(swapper_pg_dir),
14215diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14216index 2d8a371..4fa6ae6 100644
14217--- a/arch/x86/kernel/dumpstack.c
14218+++ b/arch/x86/kernel/dumpstack.c
14219@@ -2,6 +2,9 @@
14220 * Copyright (C) 1991, 1992 Linus Torvalds
14221 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14222 */
14223+#ifdef CONFIG_GRKERNSEC_HIDESYM
14224+#define __INCLUDED_BY_HIDESYM 1
14225+#endif
14226 #include <linux/kallsyms.h>
14227 #include <linux/kprobes.h>
14228 #include <linux/uaccess.h>
14229@@ -28,7 +31,7 @@ static int die_counter;
14230
14231 void printk_address(unsigned long address, int reliable)
14232 {
14233- printk(" [<%p>] %s%pS\n", (void *) address,
14234+ printk(" [<%p>] %s%pA\n", (void *) address,
14235 reliable ? "" : "? ", (void *) address);
14236 }
14237
14238@@ -36,9 +39,8 @@ void printk_address(unsigned long address, int reliable)
14239 static void
14240 print_ftrace_graph_addr(unsigned long addr, void *data,
14241 const struct stacktrace_ops *ops,
14242- struct thread_info *tinfo, int *graph)
14243+ struct task_struct *task, int *graph)
14244 {
14245- struct task_struct *task = tinfo->task;
14246 unsigned long ret_addr;
14247 int index = task->curr_ret_stack;
14248
14249@@ -59,7 +61,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14250 static inline void
14251 print_ftrace_graph_addr(unsigned long addr, void *data,
14252 const struct stacktrace_ops *ops,
14253- struct thread_info *tinfo, int *graph)
14254+ struct task_struct *task, int *graph)
14255 { }
14256 #endif
14257
14258@@ -70,10 +72,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14259 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14260 */
14261
14262-static inline int valid_stack_ptr(struct thread_info *tinfo,
14263- void *p, unsigned int size, void *end)
14264+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14265 {
14266- void *t = tinfo;
14267 if (end) {
14268 if (p < end && p >= (end-THREAD_SIZE))
14269 return 1;
14270@@ -84,14 +84,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14271 }
14272
14273 unsigned long
14274-print_context_stack(struct thread_info *tinfo,
14275+print_context_stack(struct task_struct *task, void *stack_start,
14276 unsigned long *stack, unsigned long bp,
14277 const struct stacktrace_ops *ops, void *data,
14278 unsigned long *end, int *graph)
14279 {
14280 struct stack_frame *frame = (struct stack_frame *)bp;
14281
14282- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14283+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14284 unsigned long addr;
14285
14286 addr = *stack;
14287@@ -103,7 +103,7 @@ print_context_stack(struct thread_info *tinfo,
14288 } else {
14289 ops->address(data, addr, 0);
14290 }
14291- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14292+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14293 }
14294 stack++;
14295 }
14296@@ -180,7 +180,7 @@ void dump_stack(void)
14297 #endif
14298
14299 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14300- current->pid, current->comm, print_tainted(),
14301+ task_pid_nr(current), current->comm, print_tainted(),
14302 init_utsname()->release,
14303 (int)strcspn(init_utsname()->version, " "),
14304 init_utsname()->version);
14305@@ -220,6 +220,8 @@ unsigned __kprobes long oops_begin(void)
14306 return flags;
14307 }
14308
14309+extern void gr_handle_kernel_exploit(void);
14310+
14311 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14312 {
14313 if (regs && kexec_should_crash(current))
14314@@ -241,7 +243,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14315 panic("Fatal exception in interrupt");
14316 if (panic_on_oops)
14317 panic("Fatal exception");
14318- do_exit(signr);
14319+
14320+ gr_handle_kernel_exploit();
14321+
14322+ do_group_exit(signr);
14323 }
14324
14325 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14326@@ -295,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14327 unsigned long flags = oops_begin();
14328 int sig = SIGSEGV;
14329
14330- if (!user_mode_vm(regs))
14331+ if (!user_mode(regs))
14332 report_bug(regs->ip, regs);
14333
14334 if (__die(str, regs, err))
14335diff --git a/arch/x86/kernel/dumpstack.h b/arch/x86/kernel/dumpstack.h
14336index 81086c2..13e8b17 100644
14337--- a/arch/x86/kernel/dumpstack.h
14338+++ b/arch/x86/kernel/dumpstack.h
14339@@ -15,7 +15,7 @@
14340 #endif
14341
14342 extern unsigned long
14343-print_context_stack(struct thread_info *tinfo,
14344+print_context_stack(struct task_struct *task, void *stack_start,
14345 unsigned long *stack, unsigned long bp,
14346 const struct stacktrace_ops *ops, void *data,
14347 unsigned long *end, int *graph);
14348diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14349index f7dd2a7..504f53b 100644
14350--- a/arch/x86/kernel/dumpstack_32.c
14351+++ b/arch/x86/kernel/dumpstack_32.c
14352@@ -53,16 +53,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14353 #endif
14354
14355 for (;;) {
14356- struct thread_info *context;
14357+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14358+ bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14359
14360- context = (struct thread_info *)
14361- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14362- bp = print_context_stack(context, stack, bp, ops,
14363- data, NULL, &graph);
14364-
14365- stack = (unsigned long *)context->previous_esp;
14366- if (!stack)
14367+ if (stack_start == task_stack_page(task))
14368 break;
14369+ stack = *(unsigned long **)stack_start;
14370 if (ops->stack(data, "IRQ") < 0)
14371 break;
14372 touch_nmi_watchdog();
14373@@ -112,11 +108,12 @@ void show_registers(struct pt_regs *regs)
14374 * When in-kernel, we also print out the stack and code at the
14375 * time of the fault..
14376 */
14377- if (!user_mode_vm(regs)) {
14378+ if (!user_mode(regs)) {
14379 unsigned int code_prologue = code_bytes * 43 / 64;
14380 unsigned int code_len = code_bytes;
14381 unsigned char c;
14382 u8 *ip;
14383+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14384
14385 printk(KERN_EMERG "Stack:\n");
14386 show_stack_log_lvl(NULL, regs, &regs->sp,
14387@@ -124,10 +121,10 @@ void show_registers(struct pt_regs *regs)
14388
14389 printk(KERN_EMERG "Code: ");
14390
14391- ip = (u8 *)regs->ip - code_prologue;
14392+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14393 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14394 /* try starting at IP */
14395- ip = (u8 *)regs->ip;
14396+ ip = (u8 *)regs->ip + cs_base;
14397 code_len = code_len - code_prologue + 1;
14398 }
14399 for (i = 0; i < code_len; i++, ip++) {
14400@@ -136,7 +133,7 @@ void show_registers(struct pt_regs *regs)
14401 printk(" Bad EIP value.");
14402 break;
14403 }
14404- if (ip == (u8 *)regs->ip)
14405+ if (ip == (u8 *)regs->ip + cs_base)
14406 printk("<%02x> ", c);
14407 else
14408 printk("%02x ", c);
14409@@ -145,10 +142,23 @@ void show_registers(struct pt_regs *regs)
14410 printk("\n");
14411 }
14412
14413+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14414+void pax_check_alloca(unsigned long size)
14415+{
14416+ unsigned long sp = (unsigned long)&sp, stack_left;
14417+
14418+ /* all kernel stacks are of the same size */
14419+ stack_left = sp & (THREAD_SIZE - 1);
14420+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14421+}
14422+EXPORT_SYMBOL(pax_check_alloca);
14423+#endif
14424+
14425 int is_valid_bugaddr(unsigned long ip)
14426 {
14427 unsigned short ud2;
14428
14429+ ip = ktla_ktva(ip);
14430 if (ip < PAGE_OFFSET)
14431 return 0;
14432 if (probe_kernel_address((unsigned short *)ip, ud2))
14433diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14434index a071e6b..36cd585 100644
14435--- a/arch/x86/kernel/dumpstack_64.c
14436+++ b/arch/x86/kernel/dumpstack_64.c
14437@@ -116,8 +116,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14438 unsigned long *irq_stack_end =
14439 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14440 unsigned used = 0;
14441- struct thread_info *tinfo;
14442 int graph = 0;
14443+ void *stack_start;
14444
14445 if (!task)
14446 task = current;
14447@@ -146,10 +146,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14448 * current stack address. If the stacks consist of nested
14449 * exceptions
14450 */
14451- tinfo = task_thread_info(task);
14452 for (;;) {
14453 char *id;
14454 unsigned long *estack_end;
14455+
14456 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14457 &used, &id);
14458
14459@@ -157,7 +157,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14460 if (ops->stack(data, id) < 0)
14461 break;
14462
14463- bp = print_context_stack(tinfo, stack, bp, ops,
14464+ bp = print_context_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14465 data, estack_end, &graph);
14466 ops->stack(data, "<EOE>");
14467 /*
14468@@ -176,7 +176,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14469 if (stack >= irq_stack && stack < irq_stack_end) {
14470 if (ops->stack(data, "IRQ") < 0)
14471 break;
14472- bp = print_context_stack(tinfo, stack, bp,
14473+ bp = print_context_stack(task, irq_stack, stack, bp,
14474 ops, data, irq_stack_end, &graph);
14475 /*
14476 * We link to the next stack (which would be
14477@@ -195,7 +195,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14478 /*
14479 * This handles the process stack:
14480 */
14481- bp = print_context_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14482+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14483+ bp = print_context_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14484 put_cpu();
14485 }
14486 EXPORT_SYMBOL(dump_trace);
14487@@ -304,3 +305,50 @@ int is_valid_bugaddr(unsigned long ip)
14488 return ud2 == 0x0b0f;
14489 }
14490
14491+
14492+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14493+void pax_check_alloca(unsigned long size)
14494+{
14495+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14496+ unsigned cpu, used;
14497+ char *id;
14498+
14499+ /* check the process stack first */
14500+ stack_start = (unsigned long)task_stack_page(current);
14501+ stack_end = stack_start + THREAD_SIZE;
14502+ if (likely(stack_start <= sp && sp < stack_end)) {
14503+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14504+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14505+ return;
14506+ }
14507+
14508+ cpu = get_cpu();
14509+
14510+ /* check the irq stacks */
14511+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14512+ stack_start = stack_end - IRQ_STACK_SIZE;
14513+ if (stack_start <= sp && sp < stack_end) {
14514+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14515+ put_cpu();
14516+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14517+ return;
14518+ }
14519+
14520+ /* check the exception stacks */
14521+ used = 0;
14522+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14523+ stack_start = stack_end - EXCEPTION_STKSZ;
14524+ if (stack_end && stack_start <= sp && sp < stack_end) {
14525+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14526+ put_cpu();
14527+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14528+ return;
14529+ }
14530+
14531+ put_cpu();
14532+
14533+ /* unknown stack */
14534+ BUG();
14535+}
14536+EXPORT_SYMBOL(pax_check_alloca);
14537+#endif
14538diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
14539index a89739a..95e0c48 100644
14540--- a/arch/x86/kernel/e820.c
14541+++ b/arch/x86/kernel/e820.c
14542@@ -733,7 +733,7 @@ struct early_res {
14543 };
14544 static struct early_res early_res[MAX_EARLY_RES] __initdata = {
14545 { 0, PAGE_SIZE, "BIOS data page" }, /* BIOS data page */
14546- {}
14547+ { 0, 0, {0}, 0 }
14548 };
14549
14550 static int __init find_overlapped_early(u64 start, u64 end)
14551diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14552index b9c830c..1e41a96 100644
14553--- a/arch/x86/kernel/early_printk.c
14554+++ b/arch/x86/kernel/early_printk.c
14555@@ -7,6 +7,7 @@
14556 #include <linux/pci_regs.h>
14557 #include <linux/pci_ids.h>
14558 #include <linux/errno.h>
14559+#include <linux/sched.h>
14560 #include <asm/io.h>
14561 #include <asm/processor.h>
14562 #include <asm/fcntl.h>
14563@@ -170,6 +171,8 @@ asmlinkage void early_printk(const char *fmt, ...)
14564 int n;
14565 va_list ap;
14566
14567+ pax_track_stack();
14568+
14569 va_start(ap, fmt);
14570 n = vscnprintf(buf, sizeof(buf), fmt, ap);
14571 early_console->write(early_console, buf, n);
14572diff --git a/arch/x86/kernel/efi_32.c b/arch/x86/kernel/efi_32.c
14573index 5cab48e..b025f9b 100644
14574--- a/arch/x86/kernel/efi_32.c
14575+++ b/arch/x86/kernel/efi_32.c
14576@@ -38,70 +38,56 @@
14577 */
14578
14579 static unsigned long efi_rt_eflags;
14580-static pgd_t efi_bak_pg_dir_pointer[2];
14581+static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
14582
14583-void efi_call_phys_prelog(void)
14584+void __init efi_call_phys_prelog(void)
14585 {
14586- unsigned long cr4;
14587- unsigned long temp;
14588 struct desc_ptr gdt_descr;
14589
14590+#ifdef CONFIG_PAX_KERNEXEC
14591+ struct desc_struct d;
14592+#endif
14593+
14594 local_irq_save(efi_rt_eflags);
14595
14596- /*
14597- * If I don't have PAE, I should just duplicate two entries in page
14598- * directory. If I have PAE, I just need to duplicate one entry in
14599- * page directory.
14600- */
14601- cr4 = read_cr4_safe();
14602-
14603- if (cr4 & X86_CR4_PAE) {
14604- efi_bak_pg_dir_pointer[0].pgd =
14605- swapper_pg_dir[pgd_index(0)].pgd;
14606- swapper_pg_dir[0].pgd =
14607- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
14608- } else {
14609- efi_bak_pg_dir_pointer[0].pgd =
14610- swapper_pg_dir[pgd_index(0)].pgd;
14611- efi_bak_pg_dir_pointer[1].pgd =
14612- swapper_pg_dir[pgd_index(0x400000)].pgd;
14613- swapper_pg_dir[pgd_index(0)].pgd =
14614- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
14615- temp = PAGE_OFFSET + 0x400000;
14616- swapper_pg_dir[pgd_index(0x400000)].pgd =
14617- swapper_pg_dir[pgd_index(temp)].pgd;
14618- }
14619+ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
14620+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
14621+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
14622
14623 /*
14624 * After the lock is released, the original page table is restored.
14625 */
14626 __flush_tlb_all();
14627
14628+#ifdef CONFIG_PAX_KERNEXEC
14629+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
14630+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
14631+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
14632+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
14633+#endif
14634+
14635 gdt_descr.address = __pa(get_cpu_gdt_table(0));
14636 gdt_descr.size = GDT_SIZE - 1;
14637 load_gdt(&gdt_descr);
14638 }
14639
14640-void efi_call_phys_epilog(void)
14641+void __init efi_call_phys_epilog(void)
14642 {
14643- unsigned long cr4;
14644 struct desc_ptr gdt_descr;
14645
14646+#ifdef CONFIG_PAX_KERNEXEC
14647+ struct desc_struct d;
14648+
14649+ memset(&d, 0, sizeof d);
14650+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
14651+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
14652+#endif
14653+
14654 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
14655 gdt_descr.size = GDT_SIZE - 1;
14656 load_gdt(&gdt_descr);
14657
14658- cr4 = read_cr4_safe();
14659-
14660- if (cr4 & X86_CR4_PAE) {
14661- swapper_pg_dir[pgd_index(0)].pgd =
14662- efi_bak_pg_dir_pointer[0].pgd;
14663- } else {
14664- swapper_pg_dir[pgd_index(0)].pgd =
14665- efi_bak_pg_dir_pointer[0].pgd;
14666- swapper_pg_dir[pgd_index(0x400000)].pgd =
14667- efi_bak_pg_dir_pointer[1].pgd;
14668- }
14669+ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
14670
14671 /*
14672 * After the lock is released, the original page table is restored.
14673diff --git a/arch/x86/kernel/efi_stub_32.S b/arch/x86/kernel/efi_stub_32.S
14674index fbe66e6..c5c0dd2 100644
14675--- a/arch/x86/kernel/efi_stub_32.S
14676+++ b/arch/x86/kernel/efi_stub_32.S
14677@@ -6,7 +6,9 @@
14678 */
14679
14680 #include <linux/linkage.h>
14681+#include <linux/init.h>
14682 #include <asm/page_types.h>
14683+#include <asm/segment.h>
14684
14685 /*
14686 * efi_call_phys(void *, ...) is a function with variable parameters.
14687@@ -20,7 +22,7 @@
14688 * service functions will comply with gcc calling convention, too.
14689 */
14690
14691-.text
14692+__INIT
14693 ENTRY(efi_call_phys)
14694 /*
14695 * 0. The function can only be called in Linux kernel. So CS has been
14696@@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
14697 * The mapping of lower virtual memory has been created in prelog and
14698 * epilog.
14699 */
14700- movl $1f, %edx
14701- subl $__PAGE_OFFSET, %edx
14702- jmp *%edx
14703+ movl $(__KERNEXEC_EFI_DS), %edx
14704+ mov %edx, %ds
14705+ mov %edx, %es
14706+ mov %edx, %ss
14707+ ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
14708 1:
14709
14710 /*
14711@@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
14712 * parameter 2, ..., param n. To make things easy, we save the return
14713 * address of efi_call_phys in a global variable.
14714 */
14715- popl %edx
14716- movl %edx, saved_return_addr
14717- /* get the function pointer into ECX*/
14718- popl %ecx
14719- movl %ecx, efi_rt_function_ptr
14720- movl $2f, %edx
14721- subl $__PAGE_OFFSET, %edx
14722- pushl %edx
14723+ popl (saved_return_addr)
14724+ popl (efi_rt_function_ptr)
14725
14726 /*
14727 * 3. Clear PG bit in %CR0.
14728@@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
14729 /*
14730 * 5. Call the physical function.
14731 */
14732- jmp *%ecx
14733+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
14734
14735-2:
14736 /*
14737 * 6. After EFI runtime service returns, control will return to
14738 * following instruction. We'd better readjust stack pointer first.
14739@@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
14740 movl %cr0, %edx
14741 orl $0x80000000, %edx
14742 movl %edx, %cr0
14743- jmp 1f
14744-1:
14745+
14746 /*
14747 * 8. Now restore the virtual mode from flat mode by
14748 * adding EIP with PAGE_OFFSET.
14749 */
14750- movl $1f, %edx
14751- jmp *%edx
14752+ ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
14753 1:
14754+ movl $(__KERNEL_DS), %edx
14755+ mov %edx, %ds
14756+ mov %edx, %es
14757+ mov %edx, %ss
14758
14759 /*
14760 * 9. Balance the stack. And because EAX contain the return value,
14761 * we'd better not clobber it.
14762 */
14763- leal efi_rt_function_ptr, %edx
14764- movl (%edx), %ecx
14765- pushl %ecx
14766+ pushl (efi_rt_function_ptr)
14767
14768 /*
14769- * 10. Push the saved return address onto the stack and return.
14770+ * 10. Return to the saved return address.
14771 */
14772- leal saved_return_addr, %edx
14773- movl (%edx), %ecx
14774- pushl %ecx
14775- ret
14776+ jmpl *(saved_return_addr)
14777 ENDPROC(efi_call_phys)
14778 .previous
14779
14780-.data
14781+__INITDATA
14782 saved_return_addr:
14783 .long 0
14784 efi_rt_function_ptr:
14785diff --git a/arch/x86/kernel/efi_stub_64.S b/arch/x86/kernel/efi_stub_64.S
14786index 4c07cca..2c8427d 100644
14787--- a/arch/x86/kernel/efi_stub_64.S
14788+++ b/arch/x86/kernel/efi_stub_64.S
14789@@ -7,6 +7,7 @@
14790 */
14791
14792 #include <linux/linkage.h>
14793+#include <asm/alternative-asm.h>
14794
14795 #define SAVE_XMM \
14796 mov %rsp, %rax; \
14797@@ -40,6 +41,7 @@ ENTRY(efi_call0)
14798 call *%rdi
14799 addq $32, %rsp
14800 RESTORE_XMM
14801+ pax_force_retaddr 0, 1
14802 ret
14803 ENDPROC(efi_call0)
14804
14805@@ -50,6 +52,7 @@ ENTRY(efi_call1)
14806 call *%rdi
14807 addq $32, %rsp
14808 RESTORE_XMM
14809+ pax_force_retaddr 0, 1
14810 ret
14811 ENDPROC(efi_call1)
14812
14813@@ -60,6 +63,7 @@ ENTRY(efi_call2)
14814 call *%rdi
14815 addq $32, %rsp
14816 RESTORE_XMM
14817+ pax_force_retaddr 0, 1
14818 ret
14819 ENDPROC(efi_call2)
14820
14821@@ -71,6 +75,7 @@ ENTRY(efi_call3)
14822 call *%rdi
14823 addq $32, %rsp
14824 RESTORE_XMM
14825+ pax_force_retaddr 0, 1
14826 ret
14827 ENDPROC(efi_call3)
14828
14829@@ -83,6 +88,7 @@ ENTRY(efi_call4)
14830 call *%rdi
14831 addq $32, %rsp
14832 RESTORE_XMM
14833+ pax_force_retaddr 0, 1
14834 ret
14835 ENDPROC(efi_call4)
14836
14837@@ -96,6 +102,7 @@ ENTRY(efi_call5)
14838 call *%rdi
14839 addq $48, %rsp
14840 RESTORE_XMM
14841+ pax_force_retaddr 0, 1
14842 ret
14843 ENDPROC(efi_call5)
14844
14845@@ -112,5 +119,6 @@ ENTRY(efi_call6)
14846 call *%rdi
14847 addq $48, %rsp
14848 RESTORE_XMM
14849+ pax_force_retaddr 0, 1
14850 ret
14851 ENDPROC(efi_call6)
14852diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14853index c097e7d..c689cf4 100644
14854--- a/arch/x86/kernel/entry_32.S
14855+++ b/arch/x86/kernel/entry_32.S
14856@@ -185,13 +185,146 @@
14857 /*CFI_REL_OFFSET gs, PT_GS*/
14858 .endm
14859 .macro SET_KERNEL_GS reg
14860+
14861+#ifdef CONFIG_CC_STACKPROTECTOR
14862 movl $(__KERNEL_STACK_CANARY), \reg
14863+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14864+ movl $(__USER_DS), \reg
14865+#else
14866+ xorl \reg, \reg
14867+#endif
14868+
14869 movl \reg, %gs
14870 .endm
14871
14872 #endif /* CONFIG_X86_32_LAZY_GS */
14873
14874-.macro SAVE_ALL
14875+.macro pax_enter_kernel
14876+#ifdef CONFIG_PAX_KERNEXEC
14877+ call pax_enter_kernel
14878+#endif
14879+.endm
14880+
14881+.macro pax_exit_kernel
14882+#ifdef CONFIG_PAX_KERNEXEC
14883+ call pax_exit_kernel
14884+#endif
14885+.endm
14886+
14887+#ifdef CONFIG_PAX_KERNEXEC
14888+ENTRY(pax_enter_kernel)
14889+#ifdef CONFIG_PARAVIRT
14890+ pushl %eax
14891+ pushl %ecx
14892+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14893+ mov %eax, %esi
14894+#else
14895+ mov %cr0, %esi
14896+#endif
14897+ bts $16, %esi
14898+ jnc 1f
14899+ mov %cs, %esi
14900+ cmp $__KERNEL_CS, %esi
14901+ jz 3f
14902+ ljmp $__KERNEL_CS, $3f
14903+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14904+2:
14905+#ifdef CONFIG_PARAVIRT
14906+ mov %esi, %eax
14907+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14908+#else
14909+ mov %esi, %cr0
14910+#endif
14911+3:
14912+#ifdef CONFIG_PARAVIRT
14913+ popl %ecx
14914+ popl %eax
14915+#endif
14916+ ret
14917+ENDPROC(pax_enter_kernel)
14918+
14919+ENTRY(pax_exit_kernel)
14920+#ifdef CONFIG_PARAVIRT
14921+ pushl %eax
14922+ pushl %ecx
14923+#endif
14924+ mov %cs, %esi
14925+ cmp $__KERNEXEC_KERNEL_CS, %esi
14926+ jnz 2f
14927+#ifdef CONFIG_PARAVIRT
14928+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14929+ mov %eax, %esi
14930+#else
14931+ mov %cr0, %esi
14932+#endif
14933+ btr $16, %esi
14934+ ljmp $__KERNEL_CS, $1f
14935+1:
14936+#ifdef CONFIG_PARAVIRT
14937+ mov %esi, %eax
14938+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14939+#else
14940+ mov %esi, %cr0
14941+#endif
14942+2:
14943+#ifdef CONFIG_PARAVIRT
14944+ popl %ecx
14945+ popl %eax
14946+#endif
14947+ ret
14948+ENDPROC(pax_exit_kernel)
14949+#endif
14950+
14951+.macro pax_erase_kstack
14952+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14953+ call pax_erase_kstack
14954+#endif
14955+.endm
14956+
14957+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14958+/*
14959+ * ebp: thread_info
14960+ * ecx, edx: can be clobbered
14961+ */
14962+ENTRY(pax_erase_kstack)
14963+ pushl %edi
14964+ pushl %eax
14965+
14966+ mov TI_lowest_stack(%ebp), %edi
14967+ mov $-0xBEEF, %eax
14968+ std
14969+
14970+1: mov %edi, %ecx
14971+ and $THREAD_SIZE_asm - 1, %ecx
14972+ shr $2, %ecx
14973+ repne scasl
14974+ jecxz 2f
14975+
14976+ cmp $2*16, %ecx
14977+ jc 2f
14978+
14979+ mov $2*16, %ecx
14980+ repe scasl
14981+ jecxz 2f
14982+ jne 1b
14983+
14984+2: cld
14985+ mov %esp, %ecx
14986+ sub %edi, %ecx
14987+ shr $2, %ecx
14988+ rep stosl
14989+
14990+ mov TI_task_thread_sp0(%ebp), %edi
14991+ sub $128, %edi
14992+ mov %edi, TI_lowest_stack(%ebp)
14993+
14994+ popl %eax
14995+ popl %edi
14996+ ret
14997+ENDPROC(pax_erase_kstack)
14998+#endif
14999+
15000+.macro __SAVE_ALL _DS
15001 cld
15002 PUSH_GS
15003 pushl %fs
15004@@ -224,7 +357,7 @@
15005 pushl %ebx
15006 CFI_ADJUST_CFA_OFFSET 4
15007 CFI_REL_OFFSET ebx, 0
15008- movl $(__USER_DS), %edx
15009+ movl $\_DS, %edx
15010 movl %edx, %ds
15011 movl %edx, %es
15012 movl $(__KERNEL_PERCPU), %edx
15013@@ -232,6 +365,15 @@
15014 SET_KERNEL_GS %edx
15015 .endm
15016
15017+.macro SAVE_ALL
15018+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15019+ __SAVE_ALL __KERNEL_DS
15020+ pax_enter_kernel
15021+#else
15022+ __SAVE_ALL __USER_DS
15023+#endif
15024+.endm
15025+
15026 .macro RESTORE_INT_REGS
15027 popl %ebx
15028 CFI_ADJUST_CFA_OFFSET -4
15029@@ -331,7 +473,7 @@ ENTRY(ret_from_fork)
15030 CFI_ADJUST_CFA_OFFSET -4
15031 jmp syscall_exit
15032 CFI_ENDPROC
15033-END(ret_from_fork)
15034+ENDPROC(ret_from_fork)
15035
15036 /*
15037 * Return to user mode is not as complex as all this looks,
15038@@ -352,7 +494,15 @@ check_userspace:
15039 movb PT_CS(%esp), %al
15040 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
15041 cmpl $USER_RPL, %eax
15042+
15043+#ifdef CONFIG_PAX_KERNEXEC
15044+ jae resume_userspace
15045+
15046+ PAX_EXIT_KERNEL
15047+ jmp resume_kernel
15048+#else
15049 jb resume_kernel # not returning to v8086 or userspace
15050+#endif
15051
15052 ENTRY(resume_userspace)
15053 LOCKDEP_SYS_EXIT
15054@@ -364,8 +514,8 @@ ENTRY(resume_userspace)
15055 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15056 # int/exception return?
15057 jne work_pending
15058- jmp restore_all
15059-END(ret_from_exception)
15060+ jmp restore_all_pax
15061+ENDPROC(ret_from_exception)
15062
15063 #ifdef CONFIG_PREEMPT
15064 ENTRY(resume_kernel)
15065@@ -380,7 +530,7 @@ need_resched:
15066 jz restore_all
15067 call preempt_schedule_irq
15068 jmp need_resched
15069-END(resume_kernel)
15070+ENDPROC(resume_kernel)
15071 #endif
15072 CFI_ENDPROC
15073
15074@@ -414,25 +564,36 @@ sysenter_past_esp:
15075 /*CFI_REL_OFFSET cs, 0*/
15076 /*
15077 * Push current_thread_info()->sysenter_return to the stack.
15078- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15079- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15080 */
15081- pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
15082+ pushl $0
15083 CFI_ADJUST_CFA_OFFSET 4
15084 CFI_REL_OFFSET eip, 0
15085
15086 pushl %eax
15087 CFI_ADJUST_CFA_OFFSET 4
15088 SAVE_ALL
15089+ GET_THREAD_INFO(%ebp)
15090+ movl TI_sysenter_return(%ebp),%ebp
15091+ movl %ebp,PT_EIP(%esp)
15092 ENABLE_INTERRUPTS(CLBR_NONE)
15093
15094 /*
15095 * Load the potential sixth argument from user stack.
15096 * Careful about security.
15097 */
15098+ movl PT_OLDESP(%esp),%ebp
15099+
15100+#ifdef CONFIG_PAX_MEMORY_UDEREF
15101+ mov PT_OLDSS(%esp),%ds
15102+1: movl %ds:(%ebp),%ebp
15103+ push %ss
15104+ pop %ds
15105+#else
15106 cmpl $__PAGE_OFFSET-3,%ebp
15107 jae syscall_fault
15108 1: movl (%ebp),%ebp
15109+#endif
15110+
15111 movl %ebp,PT_EBP(%esp)
15112 .section __ex_table,"a"
15113 .align 4
15114@@ -455,12 +616,24 @@ sysenter_do_call:
15115 testl $_TIF_ALLWORK_MASK, %ecx
15116 jne sysexit_audit
15117 sysenter_exit:
15118+
15119+#ifdef CONFIG_PAX_RANDKSTACK
15120+ pushl_cfi %eax
15121+ movl %esp, %eax
15122+ call pax_randomize_kstack
15123+ popl_cfi %eax
15124+#endif
15125+
15126+ pax_erase_kstack
15127+
15128 /* if something modifies registers it must also disable sysexit */
15129 movl PT_EIP(%esp), %edx
15130 movl PT_OLDESP(%esp), %ecx
15131 xorl %ebp,%ebp
15132 TRACE_IRQS_ON
15133 1: mov PT_FS(%esp), %fs
15134+2: mov PT_DS(%esp), %ds
15135+3: mov PT_ES(%esp), %es
15136 PTGS_TO_GS
15137 ENABLE_INTERRUPTS_SYSEXIT
15138
15139@@ -477,6 +650,9 @@ sysenter_audit:
15140 movl %eax,%edx /* 2nd arg: syscall number */
15141 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15142 call audit_syscall_entry
15143+
15144+ pax_erase_kstack
15145+
15146 pushl %ebx
15147 CFI_ADJUST_CFA_OFFSET 4
15148 movl PT_EAX(%esp),%eax /* reload syscall number */
15149@@ -504,11 +680,17 @@ sysexit_audit:
15150
15151 CFI_ENDPROC
15152 .pushsection .fixup,"ax"
15153-2: movl $0,PT_FS(%esp)
15154+4: movl $0,PT_FS(%esp)
15155+ jmp 1b
15156+5: movl $0,PT_DS(%esp)
15157+ jmp 1b
15158+6: movl $0,PT_ES(%esp)
15159 jmp 1b
15160 .section __ex_table,"a"
15161 .align 4
15162- .long 1b,2b
15163+ .long 1b,4b
15164+ .long 2b,5b
15165+ .long 3b,6b
15166 .popsection
15167 PTGS_TO_GS_EX
15168 ENDPROC(ia32_sysenter_target)
15169@@ -538,6 +720,15 @@ syscall_exit:
15170 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15171 jne syscall_exit_work
15172
15173+restore_all_pax:
15174+
15175+#ifdef CONFIG_PAX_RANDKSTACK
15176+ movl %esp, %eax
15177+ call pax_randomize_kstack
15178+#endif
15179+
15180+ pax_erase_kstack
15181+
15182 restore_all:
15183 TRACE_IRQS_IRET
15184 restore_all_notrace:
15185@@ -602,10 +793,29 @@ ldt_ss:
15186 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15187 mov %dx, %ax /* eax: new kernel esp */
15188 sub %eax, %edx /* offset (low word is 0) */
15189- PER_CPU(gdt_page, %ebx)
15190+#ifdef CONFIG_SMP
15191+ movl PER_CPU_VAR(cpu_number), %ebx
15192+ shll $PAGE_SHIFT_asm, %ebx
15193+ addl $cpu_gdt_table, %ebx
15194+#else
15195+ movl $cpu_gdt_table, %ebx
15196+#endif
15197 shr $16, %edx
15198+
15199+#ifdef CONFIG_PAX_KERNEXEC
15200+ mov %cr0, %esi
15201+ btr $16, %esi
15202+ mov %esi, %cr0
15203+#endif
15204+
15205 mov %dl, GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx) /* bits 16..23 */
15206 mov %dh, GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx) /* bits 24..31 */
15207+
15208+#ifdef CONFIG_PAX_KERNEXEC
15209+ bts $16, %esi
15210+ mov %esi, %cr0
15211+#endif
15212+
15213 pushl $__ESPFIX_SS
15214 CFI_ADJUST_CFA_OFFSET 4
15215 push %eax /* new kernel esp */
15216@@ -636,36 +846,30 @@ work_resched:
15217 movl TI_flags(%ebp), %ecx
15218 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15219 # than syscall tracing?
15220- jz restore_all
15221+ jz restore_all_pax
15222 testb $_TIF_NEED_RESCHED, %cl
15223 jnz work_resched
15224
15225 work_notifysig: # deal with pending signals and
15226 # notify-resume requests
15227+ movl %esp, %eax
15228 #ifdef CONFIG_VM86
15229 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15230- movl %esp, %eax
15231- jne work_notifysig_v86 # returning to kernel-space or
15232+ jz 1f # returning to kernel-space or
15233 # vm86-space
15234- xorl %edx, %edx
15235- call do_notify_resume
15236- jmp resume_userspace_sig
15237
15238- ALIGN
15239-work_notifysig_v86:
15240 pushl %ecx # save ti_flags for do_notify_resume
15241 CFI_ADJUST_CFA_OFFSET 4
15242 call save_v86_state # %eax contains pt_regs pointer
15243 popl %ecx
15244 CFI_ADJUST_CFA_OFFSET -4
15245 movl %eax, %esp
15246-#else
15247- movl %esp, %eax
15248+1:
15249 #endif
15250 xorl %edx, %edx
15251 call do_notify_resume
15252 jmp resume_userspace_sig
15253-END(work_pending)
15254+ENDPROC(work_pending)
15255
15256 # perform syscall exit tracing
15257 ALIGN
15258@@ -673,11 +877,14 @@ syscall_trace_entry:
15259 movl $-ENOSYS,PT_EAX(%esp)
15260 movl %esp, %eax
15261 call syscall_trace_enter
15262+
15263+ pax_erase_kstack
15264+
15265 /* What it returned is what we'll actually use. */
15266 cmpl $(nr_syscalls), %eax
15267 jnae syscall_call
15268 jmp syscall_exit
15269-END(syscall_trace_entry)
15270+ENDPROC(syscall_trace_entry)
15271
15272 # perform syscall exit tracing
15273 ALIGN
15274@@ -690,20 +897,24 @@ syscall_exit_work:
15275 movl %esp, %eax
15276 call syscall_trace_leave
15277 jmp resume_userspace
15278-END(syscall_exit_work)
15279+ENDPROC(syscall_exit_work)
15280 CFI_ENDPROC
15281
15282 RING0_INT_FRAME # can't unwind into user space anyway
15283 syscall_fault:
15284+#ifdef CONFIG_PAX_MEMORY_UDEREF
15285+ push %ss
15286+ pop %ds
15287+#endif
15288 GET_THREAD_INFO(%ebp)
15289 movl $-EFAULT,PT_EAX(%esp)
15290 jmp resume_userspace
15291-END(syscall_fault)
15292+ENDPROC(syscall_fault)
15293
15294 syscall_badsys:
15295 movl $-ENOSYS,PT_EAX(%esp)
15296 jmp resume_userspace
15297-END(syscall_badsys)
15298+ENDPROC(syscall_badsys)
15299 CFI_ENDPROC
15300
15301 /*
15302@@ -726,6 +937,33 @@ PTREGSCALL(rt_sigreturn)
15303 PTREGSCALL(vm86)
15304 PTREGSCALL(vm86old)
15305
15306+ ALIGN;
15307+ENTRY(kernel_execve)
15308+ push %ebp
15309+ sub $PT_OLDSS+4,%esp
15310+ push %edi
15311+ push %ecx
15312+ push %eax
15313+ lea 3*4(%esp),%edi
15314+ mov $PT_OLDSS/4+1,%ecx
15315+ xorl %eax,%eax
15316+ rep stosl
15317+ pop %eax
15318+ pop %ecx
15319+ pop %edi
15320+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15321+ mov %eax,PT_EBX(%esp)
15322+ mov %edx,PT_ECX(%esp)
15323+ mov %ecx,PT_EDX(%esp)
15324+ mov %esp,%eax
15325+ call sys_execve
15326+ GET_THREAD_INFO(%ebp)
15327+ test %eax,%eax
15328+ jz syscall_exit
15329+ add $PT_OLDSS+4,%esp
15330+ pop %ebp
15331+ ret
15332+
15333 .macro FIXUP_ESPFIX_STACK
15334 /*
15335 * Switch back for ESPFIX stack to the normal zerobased stack
15336@@ -735,7 +973,13 @@ PTREGSCALL(vm86old)
15337 * normal stack and adjusts ESP with the matching offset.
15338 */
15339 /* fixup the stack */
15340- PER_CPU(gdt_page, %ebx)
15341+#ifdef CONFIG_SMP
15342+ movl PER_CPU_VAR(cpu_number), %ebx
15343+ shll $PAGE_SHIFT_asm, %ebx
15344+ addl $cpu_gdt_table, %ebx
15345+#else
15346+ movl $cpu_gdt_table, %ebx
15347+#endif
15348 mov GDT_ENTRY_ESPFIX_SS * 8 + 4(%ebx), %al /* bits 16..23 */
15349 mov GDT_ENTRY_ESPFIX_SS * 8 + 7(%ebx), %ah /* bits 24..31 */
15350 shl $16, %eax
15351@@ -793,7 +1037,7 @@ vector=vector+1
15352 .endr
15353 2: jmp common_interrupt
15354 .endr
15355-END(irq_entries_start)
15356+ENDPROC(irq_entries_start)
15357
15358 .previous
15359 END(interrupt)
15360@@ -840,7 +1084,7 @@ ENTRY(coprocessor_error)
15361 CFI_ADJUST_CFA_OFFSET 4
15362 jmp error_code
15363 CFI_ENDPROC
15364-END(coprocessor_error)
15365+ENDPROC(coprocessor_error)
15366
15367 ENTRY(simd_coprocessor_error)
15368 RING0_INT_FRAME
15369@@ -850,7 +1094,7 @@ ENTRY(simd_coprocessor_error)
15370 CFI_ADJUST_CFA_OFFSET 4
15371 jmp error_code
15372 CFI_ENDPROC
15373-END(simd_coprocessor_error)
15374+ENDPROC(simd_coprocessor_error)
15375
15376 ENTRY(device_not_available)
15377 RING0_INT_FRAME
15378@@ -860,7 +1104,7 @@ ENTRY(device_not_available)
15379 CFI_ADJUST_CFA_OFFSET 4
15380 jmp error_code
15381 CFI_ENDPROC
15382-END(device_not_available)
15383+ENDPROC(device_not_available)
15384
15385 #ifdef CONFIG_PARAVIRT
15386 ENTRY(native_iret)
15387@@ -869,12 +1113,12 @@ ENTRY(native_iret)
15388 .align 4
15389 .long native_iret, iret_exc
15390 .previous
15391-END(native_iret)
15392+ENDPROC(native_iret)
15393
15394 ENTRY(native_irq_enable_sysexit)
15395 sti
15396 sysexit
15397-END(native_irq_enable_sysexit)
15398+ENDPROC(native_irq_enable_sysexit)
15399 #endif
15400
15401 ENTRY(overflow)
15402@@ -885,7 +1129,7 @@ ENTRY(overflow)
15403 CFI_ADJUST_CFA_OFFSET 4
15404 jmp error_code
15405 CFI_ENDPROC
15406-END(overflow)
15407+ENDPROC(overflow)
15408
15409 ENTRY(bounds)
15410 RING0_INT_FRAME
15411@@ -895,7 +1139,7 @@ ENTRY(bounds)
15412 CFI_ADJUST_CFA_OFFSET 4
15413 jmp error_code
15414 CFI_ENDPROC
15415-END(bounds)
15416+ENDPROC(bounds)
15417
15418 ENTRY(invalid_op)
15419 RING0_INT_FRAME
15420@@ -905,7 +1149,7 @@ ENTRY(invalid_op)
15421 CFI_ADJUST_CFA_OFFSET 4
15422 jmp error_code
15423 CFI_ENDPROC
15424-END(invalid_op)
15425+ENDPROC(invalid_op)
15426
15427 ENTRY(coprocessor_segment_overrun)
15428 RING0_INT_FRAME
15429@@ -915,7 +1159,7 @@ ENTRY(coprocessor_segment_overrun)
15430 CFI_ADJUST_CFA_OFFSET 4
15431 jmp error_code
15432 CFI_ENDPROC
15433-END(coprocessor_segment_overrun)
15434+ENDPROC(coprocessor_segment_overrun)
15435
15436 ENTRY(invalid_TSS)
15437 RING0_EC_FRAME
15438@@ -923,7 +1167,7 @@ ENTRY(invalid_TSS)
15439 CFI_ADJUST_CFA_OFFSET 4
15440 jmp error_code
15441 CFI_ENDPROC
15442-END(invalid_TSS)
15443+ENDPROC(invalid_TSS)
15444
15445 ENTRY(segment_not_present)
15446 RING0_EC_FRAME
15447@@ -931,7 +1175,7 @@ ENTRY(segment_not_present)
15448 CFI_ADJUST_CFA_OFFSET 4
15449 jmp error_code
15450 CFI_ENDPROC
15451-END(segment_not_present)
15452+ENDPROC(segment_not_present)
15453
15454 ENTRY(stack_segment)
15455 RING0_EC_FRAME
15456@@ -939,7 +1183,7 @@ ENTRY(stack_segment)
15457 CFI_ADJUST_CFA_OFFSET 4
15458 jmp error_code
15459 CFI_ENDPROC
15460-END(stack_segment)
15461+ENDPROC(stack_segment)
15462
15463 ENTRY(alignment_check)
15464 RING0_EC_FRAME
15465@@ -947,7 +1191,7 @@ ENTRY(alignment_check)
15466 CFI_ADJUST_CFA_OFFSET 4
15467 jmp error_code
15468 CFI_ENDPROC
15469-END(alignment_check)
15470+ENDPROC(alignment_check)
15471
15472 ENTRY(divide_error)
15473 RING0_INT_FRAME
15474@@ -957,7 +1201,7 @@ ENTRY(divide_error)
15475 CFI_ADJUST_CFA_OFFSET 4
15476 jmp error_code
15477 CFI_ENDPROC
15478-END(divide_error)
15479+ENDPROC(divide_error)
15480
15481 #ifdef CONFIG_X86_MCE
15482 ENTRY(machine_check)
15483@@ -968,7 +1212,7 @@ ENTRY(machine_check)
15484 CFI_ADJUST_CFA_OFFSET 4
15485 jmp error_code
15486 CFI_ENDPROC
15487-END(machine_check)
15488+ENDPROC(machine_check)
15489 #endif
15490
15491 ENTRY(spurious_interrupt_bug)
15492@@ -979,7 +1223,7 @@ ENTRY(spurious_interrupt_bug)
15493 CFI_ADJUST_CFA_OFFSET 4
15494 jmp error_code
15495 CFI_ENDPROC
15496-END(spurious_interrupt_bug)
15497+ENDPROC(spurious_interrupt_bug)
15498
15499 ENTRY(kernel_thread_helper)
15500 pushl $0 # fake return address for unwinder
15501@@ -1095,7 +1339,7 @@ ENDPROC(xen_failsafe_callback)
15502
15503 ENTRY(mcount)
15504 ret
15505-END(mcount)
15506+ENDPROC(mcount)
15507
15508 ENTRY(ftrace_caller)
15509 cmpl $0, function_trace_stop
15510@@ -1124,7 +1368,7 @@ ftrace_graph_call:
15511 .globl ftrace_stub
15512 ftrace_stub:
15513 ret
15514-END(ftrace_caller)
15515+ENDPROC(ftrace_caller)
15516
15517 #else /* ! CONFIG_DYNAMIC_FTRACE */
15518
15519@@ -1160,7 +1404,7 @@ trace:
15520 popl %ecx
15521 popl %eax
15522 jmp ftrace_stub
15523-END(mcount)
15524+ENDPROC(mcount)
15525 #endif /* CONFIG_DYNAMIC_FTRACE */
15526 #endif /* CONFIG_FUNCTION_TRACER */
15527
15528@@ -1181,7 +1425,7 @@ ENTRY(ftrace_graph_caller)
15529 popl %ecx
15530 popl %eax
15531 ret
15532-END(ftrace_graph_caller)
15533+ENDPROC(ftrace_graph_caller)
15534
15535 .globl return_to_handler
15536 return_to_handler:
15537@@ -1198,7 +1442,6 @@ return_to_handler:
15538 ret
15539 #endif
15540
15541-.section .rodata,"a"
15542 #include "syscall_table_32.S"
15543
15544 syscall_table_size=(.-sys_call_table)
15545@@ -1255,15 +1498,18 @@ error_code:
15546 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15547 REG_TO_PTGS %ecx
15548 SET_KERNEL_GS %ecx
15549- movl $(__USER_DS), %ecx
15550+ movl $(__KERNEL_DS), %ecx
15551 movl %ecx, %ds
15552 movl %ecx, %es
15553+
15554+ pax_enter_kernel
15555+
15556 TRACE_IRQS_OFF
15557 movl %esp,%eax # pt_regs pointer
15558 call *%edi
15559 jmp ret_from_exception
15560 CFI_ENDPROC
15561-END(page_fault)
15562+ENDPROC(page_fault)
15563
15564 /*
15565 * Debug traps and NMI can happen at the one SYSENTER instruction
15566@@ -1309,7 +1555,7 @@ debug_stack_correct:
15567 call do_debug
15568 jmp ret_from_exception
15569 CFI_ENDPROC
15570-END(debug)
15571+ENDPROC(debug)
15572
15573 /*
15574 * NMI is doubly nasty. It can happen _while_ we're handling
15575@@ -1351,6 +1597,9 @@ nmi_stack_correct:
15576 xorl %edx,%edx # zero error code
15577 movl %esp,%eax # pt_regs pointer
15578 call do_nmi
15579+
15580+ pax_exit_kernel
15581+
15582 jmp restore_all_notrace
15583 CFI_ENDPROC
15584
15585@@ -1391,12 +1640,15 @@ nmi_espfix_stack:
15586 FIXUP_ESPFIX_STACK # %eax == %esp
15587 xorl %edx,%edx # zero error code
15588 call do_nmi
15589+
15590+ pax_exit_kernel
15591+
15592 RESTORE_REGS
15593 lss 12+4(%esp), %esp # back to espfix stack
15594 CFI_ADJUST_CFA_OFFSET -24
15595 jmp irq_return
15596 CFI_ENDPROC
15597-END(nmi)
15598+ENDPROC(nmi)
15599
15600 ENTRY(int3)
15601 RING0_INT_FRAME
15602@@ -1409,7 +1661,7 @@ ENTRY(int3)
15603 call do_int3
15604 jmp ret_from_exception
15605 CFI_ENDPROC
15606-END(int3)
15607+ENDPROC(int3)
15608
15609 ENTRY(general_protection)
15610 RING0_EC_FRAME
15611@@ -1417,7 +1669,7 @@ ENTRY(general_protection)
15612 CFI_ADJUST_CFA_OFFSET 4
15613 jmp error_code
15614 CFI_ENDPROC
15615-END(general_protection)
15616+ENDPROC(general_protection)
15617
15618 /*
15619 * End of kprobes section
15620diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15621index 34a56a9..4aa5c8b 100644
15622--- a/arch/x86/kernel/entry_64.S
15623+++ b/arch/x86/kernel/entry_64.S
15624@@ -53,6 +53,8 @@
15625 #include <asm/paravirt.h>
15626 #include <asm/ftrace.h>
15627 #include <asm/percpu.h>
15628+#include <asm/pgtable.h>
15629+#include <asm/alternative-asm.h>
15630
15631 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15632 #include <linux/elf-em.h>
15633@@ -64,8 +66,9 @@
15634 #ifdef CONFIG_FUNCTION_TRACER
15635 #ifdef CONFIG_DYNAMIC_FTRACE
15636 ENTRY(mcount)
15637+ pax_force_retaddr
15638 retq
15639-END(mcount)
15640+ENDPROC(mcount)
15641
15642 ENTRY(ftrace_caller)
15643 cmpl $0, function_trace_stop
15644@@ -88,8 +91,9 @@ GLOBAL(ftrace_graph_call)
15645 #endif
15646
15647 GLOBAL(ftrace_stub)
15648+ pax_force_retaddr
15649 retq
15650-END(ftrace_caller)
15651+ENDPROC(ftrace_caller)
15652
15653 #else /* ! CONFIG_DYNAMIC_FTRACE */
15654 ENTRY(mcount)
15655@@ -108,6 +112,7 @@ ENTRY(mcount)
15656 #endif
15657
15658 GLOBAL(ftrace_stub)
15659+ pax_force_retaddr
15660 retq
15661
15662 trace:
15663@@ -117,12 +122,13 @@ trace:
15664 movq 8(%rbp), %rsi
15665 subq $MCOUNT_INSN_SIZE, %rdi
15666
15667+ pax_force_fptr ftrace_trace_function
15668 call *ftrace_trace_function
15669
15670 MCOUNT_RESTORE_FRAME
15671
15672 jmp ftrace_stub
15673-END(mcount)
15674+ENDPROC(mcount)
15675 #endif /* CONFIG_DYNAMIC_FTRACE */
15676 #endif /* CONFIG_FUNCTION_TRACER */
15677
15678@@ -142,8 +148,9 @@ ENTRY(ftrace_graph_caller)
15679
15680 MCOUNT_RESTORE_FRAME
15681
15682+ pax_force_retaddr
15683 retq
15684-END(ftrace_graph_caller)
15685+ENDPROC(ftrace_graph_caller)
15686
15687 GLOBAL(return_to_handler)
15688 subq $24, %rsp
15689@@ -159,6 +166,7 @@ GLOBAL(return_to_handler)
15690 movq 8(%rsp), %rdx
15691 movq (%rsp), %rax
15692 addq $16, %rsp
15693+ pax_force_retaddr
15694 retq
15695 #endif
15696
15697@@ -174,6 +182,282 @@ ENTRY(native_usergs_sysret64)
15698 ENDPROC(native_usergs_sysret64)
15699 #endif /* CONFIG_PARAVIRT */
15700
15701+ .macro ljmpq sel, off
15702+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15703+ .byte 0x48; ljmp *1234f(%rip)
15704+ .pushsection .rodata
15705+ .align 16
15706+ 1234: .quad \off; .word \sel
15707+ .popsection
15708+#else
15709+ pushq $\sel
15710+ pushq $\off
15711+ lretq
15712+#endif
15713+ .endm
15714+
15715+ .macro pax_enter_kernel
15716+ pax_set_fptr_mask
15717+#ifdef CONFIG_PAX_KERNEXEC
15718+ call pax_enter_kernel
15719+#endif
15720+ .endm
15721+
15722+ .macro pax_exit_kernel
15723+#ifdef CONFIG_PAX_KERNEXEC
15724+ call pax_exit_kernel
15725+#endif
15726+ .endm
15727+
15728+#ifdef CONFIG_PAX_KERNEXEC
15729+ENTRY(pax_enter_kernel)
15730+ pushq %rdi
15731+
15732+#ifdef CONFIG_PARAVIRT
15733+ PV_SAVE_REGS(CLBR_RDI)
15734+#endif
15735+
15736+ GET_CR0_INTO_RDI
15737+ bts $16,%rdi
15738+ jnc 3f
15739+ mov %cs,%edi
15740+ cmp $__KERNEL_CS,%edi
15741+ jnz 2f
15742+1:
15743+
15744+#ifdef CONFIG_PARAVIRT
15745+ PV_RESTORE_REGS(CLBR_RDI)
15746+#endif
15747+
15748+ popq %rdi
15749+ pax_force_retaddr
15750+ retq
15751+
15752+2: ljmpq __KERNEL_CS,1f
15753+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15754+4: SET_RDI_INTO_CR0
15755+ jmp 1b
15756+ENDPROC(pax_enter_kernel)
15757+
15758+ENTRY(pax_exit_kernel)
15759+ pushq %rdi
15760+
15761+#ifdef CONFIG_PARAVIRT
15762+ PV_SAVE_REGS(CLBR_RDI)
15763+#endif
15764+
15765+ mov %cs,%rdi
15766+ cmp $__KERNEXEC_KERNEL_CS,%edi
15767+ jz 2f
15768+1:
15769+
15770+#ifdef CONFIG_PARAVIRT
15771+ PV_RESTORE_REGS(CLBR_RDI);
15772+#endif
15773+
15774+ popq %rdi
15775+ pax_force_retaddr
15776+ retq
15777+
15778+2: GET_CR0_INTO_RDI
15779+ btr $16,%rdi
15780+ ljmpq __KERNEL_CS,3f
15781+3: SET_RDI_INTO_CR0
15782+ jmp 1b
15783+#ifdef CONFIG_PARAVIRT
15784+ PV_RESTORE_REGS(CLBR_RDI);
15785+#endif
15786+
15787+ popq %rdi
15788+ pax_force_retaddr
15789+ retq
15790+ENDPROC(pax_exit_kernel)
15791+#endif
15792+
15793+ .macro pax_enter_kernel_user
15794+ pax_set_fptr_mask
15795+#ifdef CONFIG_PAX_MEMORY_UDEREF
15796+ call pax_enter_kernel_user
15797+#endif
15798+ .endm
15799+
15800+ .macro pax_exit_kernel_user
15801+#ifdef CONFIG_PAX_MEMORY_UDEREF
15802+ call pax_exit_kernel_user
15803+#endif
15804+#ifdef CONFIG_PAX_RANDKSTACK
15805+ pushq %rax
15806+ call pax_randomize_kstack
15807+ popq %rax
15808+#endif
15809+ .endm
15810+
15811+#ifdef CONFIG_PAX_MEMORY_UDEREF
15812+ENTRY(pax_enter_kernel_user)
15813+ pushq %rdi
15814+ pushq %rbx
15815+
15816+#ifdef CONFIG_PARAVIRT
15817+ PV_SAVE_REGS(CLBR_RDI)
15818+#endif
15819+
15820+ GET_CR3_INTO_RDI
15821+ mov %rdi,%rbx
15822+ add $__START_KERNEL_map,%rbx
15823+ sub phys_base(%rip),%rbx
15824+
15825+#ifdef CONFIG_PARAVIRT
15826+ pushq %rdi
15827+ cmpl $0, pv_info+PARAVIRT_enabled
15828+ jz 1f
15829+ i = 0
15830+ .rept USER_PGD_PTRS
15831+ mov i*8(%rbx),%rsi
15832+ mov $0,%sil
15833+ lea i*8(%rbx),%rdi
15834+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15835+ i = i + 1
15836+ .endr
15837+ jmp 2f
15838+1:
15839+#endif
15840+
15841+ i = 0
15842+ .rept USER_PGD_PTRS
15843+ movb $0,i*8(%rbx)
15844+ i = i + 1
15845+ .endr
15846+
15847+#ifdef CONFIG_PARAVIRT
15848+2: popq %rdi
15849+#endif
15850+ SET_RDI_INTO_CR3
15851+
15852+#ifdef CONFIG_PAX_KERNEXEC
15853+ GET_CR0_INTO_RDI
15854+ bts $16,%rdi
15855+ SET_RDI_INTO_CR0
15856+#endif
15857+
15858+#ifdef CONFIG_PARAVIRT
15859+ PV_RESTORE_REGS(CLBR_RDI)
15860+#endif
15861+
15862+ popq %rbx
15863+ popq %rdi
15864+ pax_force_retaddr
15865+ retq
15866+ENDPROC(pax_enter_kernel_user)
15867+
15868+ENTRY(pax_exit_kernel_user)
15869+ push %rdi
15870+
15871+#ifdef CONFIG_PARAVIRT
15872+ pushq %rbx
15873+ PV_SAVE_REGS(CLBR_RDI)
15874+#endif
15875+
15876+#ifdef CONFIG_PAX_KERNEXEC
15877+ GET_CR0_INTO_RDI
15878+ btr $16,%rdi
15879+ SET_RDI_INTO_CR0
15880+#endif
15881+
15882+ GET_CR3_INTO_RDI
15883+ add $__START_KERNEL_map,%rdi
15884+ sub phys_base(%rip),%rdi
15885+
15886+#ifdef CONFIG_PARAVIRT
15887+ cmpl $0, pv_info+PARAVIRT_enabled
15888+ jz 1f
15889+ mov %rdi,%rbx
15890+ i = 0
15891+ .rept USER_PGD_PTRS
15892+ mov i*8(%rbx),%rsi
15893+ mov $0x67,%sil
15894+ lea i*8(%rbx),%rdi
15895+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15896+ i = i + 1
15897+ .endr
15898+ jmp 2f
15899+1:
15900+#endif
15901+
15902+ i = 0
15903+ .rept USER_PGD_PTRS
15904+ movb $0x67,i*8(%rdi)
15905+ i = i + 1
15906+ .endr
15907+
15908+#ifdef CONFIG_PARAVIRT
15909+2: PV_RESTORE_REGS(CLBR_RDI)
15910+ popq %rbx
15911+#endif
15912+
15913+ popq %rdi
15914+ pax_force_retaddr
15915+ retq
15916+ENDPROC(pax_exit_kernel_user)
15917+#endif
15918+
15919+.macro pax_erase_kstack
15920+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15921+ call pax_erase_kstack
15922+#endif
15923+.endm
15924+
15925+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15926+/*
15927+ * r11: thread_info
15928+ * rcx, rdx: can be clobbered
15929+ */
15930+ENTRY(pax_erase_kstack)
15931+ pushq %rdi
15932+ pushq %rax
15933+ pushq %r11
15934+
15935+ GET_THREAD_INFO(%r11)
15936+ mov TI_lowest_stack(%r11), %rdi
15937+ mov $-0xBEEF, %rax
15938+ std
15939+
15940+1: mov %edi, %ecx
15941+ and $THREAD_SIZE_asm - 1, %ecx
15942+ shr $3, %ecx
15943+ repne scasq
15944+ jecxz 2f
15945+
15946+ cmp $2*8, %ecx
15947+ jc 2f
15948+
15949+ mov $2*8, %ecx
15950+ repe scasq
15951+ jecxz 2f
15952+ jne 1b
15953+
15954+2: cld
15955+ mov %esp, %ecx
15956+ sub %edi, %ecx
15957+
15958+ cmp $THREAD_SIZE_asm, %rcx
15959+ jb 3f
15960+ ud2
15961+3:
15962+
15963+ shr $3, %ecx
15964+ rep stosq
15965+
15966+ mov TI_task_thread_sp0(%r11), %rdi
15967+ sub $256, %rdi
15968+ mov %rdi, TI_lowest_stack(%r11)
15969+
15970+ popq %r11
15971+ popq %rax
15972+ popq %rdi
15973+ pax_force_retaddr
15974+ ret
15975+ENDPROC(pax_erase_kstack)
15976+#endif
15977
15978 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15979 #ifdef CONFIG_TRACE_IRQFLAGS
15980@@ -233,8 +517,8 @@ ENDPROC(native_usergs_sysret64)
15981 .endm
15982
15983 .macro UNFAKE_STACK_FRAME
15984- addq $8*6, %rsp
15985- CFI_ADJUST_CFA_OFFSET -(6*8)
15986+ addq $8*6 + ARG_SKIP, %rsp
15987+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15988 .endm
15989
15990 /*
15991@@ -317,7 +601,7 @@ ENTRY(save_args)
15992 leaq -ARGOFFSET+16(%rsp),%rdi /* arg1 for handler */
15993 movq_cfi rbp, 8 /* push %rbp */
15994 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
15995- testl $3, CS(%rdi)
15996+ testb $3, CS(%rdi)
15997 je 1f
15998 SWAPGS
15999 /*
16000@@ -337,9 +621,10 @@ ENTRY(save_args)
16001 * We entered an interrupt context - irqs are off:
16002 */
16003 2: TRACE_IRQS_OFF
16004+ pax_force_retaddr
16005 ret
16006 CFI_ENDPROC
16007-END(save_args)
16008+ENDPROC(save_args)
16009
16010 ENTRY(save_rest)
16011 PARTIAL_FRAME 1 REST_SKIP+8
16012@@ -352,9 +637,10 @@ ENTRY(save_rest)
16013 movq_cfi r15, R15+16
16014 movq %r11, 8(%rsp) /* return address */
16015 FIXUP_TOP_OF_STACK %r11, 16
16016+ pax_force_retaddr
16017 ret
16018 CFI_ENDPROC
16019-END(save_rest)
16020+ENDPROC(save_rest)
16021
16022 /* save complete stack frame */
16023 .pushsection .kprobes.text, "ax"
16024@@ -383,9 +669,10 @@ ENTRY(save_paranoid)
16025 js 1f /* negative -> in kernel */
16026 SWAPGS
16027 xorl %ebx,%ebx
16028-1: ret
16029+1: pax_force_retaddr_bts
16030+ ret
16031 CFI_ENDPROC
16032-END(save_paranoid)
16033+ENDPROC(save_paranoid)
16034 .popsection
16035
16036 /*
16037@@ -409,7 +696,7 @@ ENTRY(ret_from_fork)
16038
16039 RESTORE_REST
16040
16041- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16042+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16043 je int_ret_from_sys_call
16044
16045 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16046@@ -419,7 +706,7 @@ ENTRY(ret_from_fork)
16047 jmp ret_from_sys_call # go to the SYSRET fastpath
16048
16049 CFI_ENDPROC
16050-END(ret_from_fork)
16051+ENDPROC(ret_from_fork)
16052
16053 /*
16054 * System call entry. Upto 6 arguments in registers are supported.
16055@@ -455,7 +742,7 @@ END(ret_from_fork)
16056 ENTRY(system_call)
16057 CFI_STARTPROC simple
16058 CFI_SIGNAL_FRAME
16059- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16060+ CFI_DEF_CFA rsp,0
16061 CFI_REGISTER rip,rcx
16062 /*CFI_REGISTER rflags,r11*/
16063 SWAPGS_UNSAFE_STACK
16064@@ -468,12 +755,13 @@ ENTRY(system_call_after_swapgs)
16065
16066 movq %rsp,PER_CPU_VAR(old_rsp)
16067 movq PER_CPU_VAR(kernel_stack),%rsp
16068+ SAVE_ARGS 8*6,1
16069+ pax_enter_kernel_user
16070 /*
16071 * No need to follow this irqs off/on section - it's straight
16072 * and short:
16073 */
16074 ENABLE_INTERRUPTS(CLBR_NONE)
16075- SAVE_ARGS 8,1
16076 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16077 movq %rcx,RIP-ARGOFFSET(%rsp)
16078 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16079@@ -483,7 +771,7 @@ ENTRY(system_call_after_swapgs)
16080 system_call_fastpath:
16081 cmpq $__NR_syscall_max,%rax
16082 ja badsys
16083- movq %r10,%rcx
16084+ movq R10-ARGOFFSET(%rsp),%rcx
16085 call *sys_call_table(,%rax,8) # XXX: rip relative
16086 movq %rax,RAX-ARGOFFSET(%rsp)
16087 /*
16088@@ -502,6 +790,8 @@ sysret_check:
16089 andl %edi,%edx
16090 jnz sysret_careful
16091 CFI_REMEMBER_STATE
16092+ pax_exit_kernel_user
16093+ pax_erase_kstack
16094 /*
16095 * sysretq will re-enable interrupts:
16096 */
16097@@ -555,14 +845,18 @@ badsys:
16098 * jump back to the normal fast path.
16099 */
16100 auditsys:
16101- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16102+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16103 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16104 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16105 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16106 movq %rax,%rsi /* 2nd arg: syscall number */
16107 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16108 call audit_syscall_entry
16109+
16110+ pax_erase_kstack
16111+
16112 LOAD_ARGS 0 /* reload call-clobbered registers */
16113+ pax_set_fptr_mask
16114 jmp system_call_fastpath
16115
16116 /*
16117@@ -592,16 +886,20 @@ tracesys:
16118 FIXUP_TOP_OF_STACK %rdi
16119 movq %rsp,%rdi
16120 call syscall_trace_enter
16121+
16122+ pax_erase_kstack
16123+
16124 /*
16125 * Reload arg registers from stack in case ptrace changed them.
16126 * We don't reload %rax because syscall_trace_enter() returned
16127 * the value it wants us to use in the table lookup.
16128 */
16129 LOAD_ARGS ARGOFFSET, 1
16130+ pax_set_fptr_mask
16131 RESTORE_REST
16132 cmpq $__NR_syscall_max,%rax
16133 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16134- movq %r10,%rcx /* fixup for C */
16135+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16136 call *sys_call_table(,%rax,8)
16137 movq %rax,RAX-ARGOFFSET(%rsp)
16138 /* Use IRET because user could have changed frame */
16139@@ -613,7 +911,7 @@ tracesys:
16140 GLOBAL(int_ret_from_sys_call)
16141 DISABLE_INTERRUPTS(CLBR_NONE)
16142 TRACE_IRQS_OFF
16143- testl $3,CS-ARGOFFSET(%rsp)
16144+ testb $3,CS-ARGOFFSET(%rsp)
16145 je retint_restore_args
16146 movl $_TIF_ALLWORK_MASK,%edi
16147 /* edi: mask to check */
16148@@ -674,7 +972,7 @@ int_restore_rest:
16149 TRACE_IRQS_OFF
16150 jmp int_with_check
16151 CFI_ENDPROC
16152-END(system_call)
16153+ENDPROC(system_call)
16154
16155 /*
16156 * Certain special system calls that need to save a complete full stack frame.
16157@@ -690,7 +988,7 @@ ENTRY(\label)
16158 call \func
16159 jmp ptregscall_common
16160 CFI_ENDPROC
16161-END(\label)
16162+ENDPROC(\label)
16163 .endm
16164
16165 PTREGSCALL stub_clone, sys_clone, %r8
16166@@ -708,9 +1006,10 @@ ENTRY(ptregscall_common)
16167 movq_cfi_restore R12+8, r12
16168 movq_cfi_restore RBP+8, rbp
16169 movq_cfi_restore RBX+8, rbx
16170+ pax_force_retaddr
16171 ret $REST_SKIP /* pop extended registers */
16172 CFI_ENDPROC
16173-END(ptregscall_common)
16174+ENDPROC(ptregscall_common)
16175
16176 ENTRY(stub_execve)
16177 CFI_STARTPROC
16178@@ -726,7 +1025,7 @@ ENTRY(stub_execve)
16179 RESTORE_REST
16180 jmp int_ret_from_sys_call
16181 CFI_ENDPROC
16182-END(stub_execve)
16183+ENDPROC(stub_execve)
16184
16185 /*
16186 * sigreturn is special because it needs to restore all registers on return.
16187@@ -744,7 +1043,7 @@ ENTRY(stub_rt_sigreturn)
16188 RESTORE_REST
16189 jmp int_ret_from_sys_call
16190 CFI_ENDPROC
16191-END(stub_rt_sigreturn)
16192+ENDPROC(stub_rt_sigreturn)
16193
16194 /*
16195 * Build the entry stubs and pointer table with some assembler magic.
16196@@ -780,7 +1079,7 @@ vector=vector+1
16197 2: jmp common_interrupt
16198 .endr
16199 CFI_ENDPROC
16200-END(irq_entries_start)
16201+ENDPROC(irq_entries_start)
16202
16203 .previous
16204 END(interrupt)
16205@@ -800,6 +1099,16 @@ END(interrupt)
16206 CFI_ADJUST_CFA_OFFSET 10*8
16207 call save_args
16208 PARTIAL_FRAME 0
16209+#ifdef CONFIG_PAX_MEMORY_UDEREF
16210+ testb $3, CS(%rdi)
16211+ jnz 1f
16212+ pax_enter_kernel
16213+ jmp 2f
16214+1: pax_enter_kernel_user
16215+2:
16216+#else
16217+ pax_enter_kernel
16218+#endif
16219 call \func
16220 .endm
16221
16222@@ -822,7 +1131,7 @@ ret_from_intr:
16223 CFI_ADJUST_CFA_OFFSET -8
16224 exit_intr:
16225 GET_THREAD_INFO(%rcx)
16226- testl $3,CS-ARGOFFSET(%rsp)
16227+ testb $3,CS-ARGOFFSET(%rsp)
16228 je retint_kernel
16229
16230 /* Interrupt came from user space */
16231@@ -844,12 +1153,16 @@ retint_swapgs: /* return to user-space */
16232 * The iretq could re-enable interrupts:
16233 */
16234 DISABLE_INTERRUPTS(CLBR_ANY)
16235+ pax_exit_kernel_user
16236+ pax_erase_kstack
16237 TRACE_IRQS_IRETQ
16238 SWAPGS
16239 jmp restore_args
16240
16241 retint_restore_args: /* return to kernel space */
16242 DISABLE_INTERRUPTS(CLBR_ANY)
16243+ pax_exit_kernel
16244+ pax_force_retaddr RIP-ARGOFFSET
16245 /*
16246 * The iretq could re-enable interrupts:
16247 */
16248@@ -940,7 +1253,7 @@ ENTRY(retint_kernel)
16249 #endif
16250
16251 CFI_ENDPROC
16252-END(common_interrupt)
16253+ENDPROC(common_interrupt)
16254
16255 /*
16256 * APIC interrupts.
16257@@ -953,7 +1266,7 @@ ENTRY(\sym)
16258 interrupt \do_sym
16259 jmp ret_from_intr
16260 CFI_ENDPROC
16261-END(\sym)
16262+ENDPROC(\sym)
16263 .endm
16264
16265 #ifdef CONFIG_SMP
16266@@ -1032,12 +1345,22 @@ ENTRY(\sym)
16267 CFI_ADJUST_CFA_OFFSET 15*8
16268 call error_entry
16269 DEFAULT_FRAME 0
16270+#ifdef CONFIG_PAX_MEMORY_UDEREF
16271+ testb $3, CS(%rsp)
16272+ jnz 1f
16273+ pax_enter_kernel
16274+ jmp 2f
16275+1: pax_enter_kernel_user
16276+2:
16277+#else
16278+ pax_enter_kernel
16279+#endif
16280 movq %rsp,%rdi /* pt_regs pointer */
16281 xorl %esi,%esi /* no error code */
16282 call \do_sym
16283 jmp error_exit /* %ebx: no swapgs flag */
16284 CFI_ENDPROC
16285-END(\sym)
16286+ENDPROC(\sym)
16287 .endm
16288
16289 .macro paranoidzeroentry sym do_sym
16290@@ -1049,12 +1372,22 @@ ENTRY(\sym)
16291 subq $15*8, %rsp
16292 call save_paranoid
16293 TRACE_IRQS_OFF
16294+#ifdef CONFIG_PAX_MEMORY_UDEREF
16295+ testb $3, CS(%rsp)
16296+ jnz 1f
16297+ pax_enter_kernel
16298+ jmp 2f
16299+1: pax_enter_kernel_user
16300+2:
16301+#else
16302+ pax_enter_kernel
16303+#endif
16304 movq %rsp,%rdi /* pt_regs pointer */
16305 xorl %esi,%esi /* no error code */
16306 call \do_sym
16307 jmp paranoid_exit /* %ebx: no swapgs flag */
16308 CFI_ENDPROC
16309-END(\sym)
16310+ENDPROC(\sym)
16311 .endm
16312
16313 .macro paranoidzeroentry_ist sym do_sym ist
16314@@ -1066,15 +1399,30 @@ ENTRY(\sym)
16315 subq $15*8, %rsp
16316 call save_paranoid
16317 TRACE_IRQS_OFF
16318+#ifdef CONFIG_PAX_MEMORY_UDEREF
16319+ testb $3, CS(%rsp)
16320+ jnz 1f
16321+ pax_enter_kernel
16322+ jmp 2f
16323+1: pax_enter_kernel_user
16324+2:
16325+#else
16326+ pax_enter_kernel
16327+#endif
16328 movq %rsp,%rdi /* pt_regs pointer */
16329 xorl %esi,%esi /* no error code */
16330- PER_CPU(init_tss, %rbp)
16331+#ifdef CONFIG_SMP
16332+ imul $TSS_size, PER_CPU_VAR(cpu_number), %ebp
16333+ lea init_tss(%rbp), %rbp
16334+#else
16335+ lea init_tss(%rip), %rbp
16336+#endif
16337 subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
16338 call \do_sym
16339 addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
16340 jmp paranoid_exit /* %ebx: no swapgs flag */
16341 CFI_ENDPROC
16342-END(\sym)
16343+ENDPROC(\sym)
16344 .endm
16345
16346 .macro errorentry sym do_sym
16347@@ -1085,13 +1433,23 @@ ENTRY(\sym)
16348 CFI_ADJUST_CFA_OFFSET 15*8
16349 call error_entry
16350 DEFAULT_FRAME 0
16351+#ifdef CONFIG_PAX_MEMORY_UDEREF
16352+ testb $3, CS(%rsp)
16353+ jnz 1f
16354+ pax_enter_kernel
16355+ jmp 2f
16356+1: pax_enter_kernel_user
16357+2:
16358+#else
16359+ pax_enter_kernel
16360+#endif
16361 movq %rsp,%rdi /* pt_regs pointer */
16362 movq ORIG_RAX(%rsp),%rsi /* get error code */
16363 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16364 call \do_sym
16365 jmp error_exit /* %ebx: no swapgs flag */
16366 CFI_ENDPROC
16367-END(\sym)
16368+ENDPROC(\sym)
16369 .endm
16370
16371 /* error code is on the stack already */
16372@@ -1104,13 +1462,23 @@ ENTRY(\sym)
16373 call save_paranoid
16374 DEFAULT_FRAME 0
16375 TRACE_IRQS_OFF
16376+#ifdef CONFIG_PAX_MEMORY_UDEREF
16377+ testb $3, CS(%rsp)
16378+ jnz 1f
16379+ pax_enter_kernel
16380+ jmp 2f
16381+1: pax_enter_kernel_user
16382+2:
16383+#else
16384+ pax_enter_kernel
16385+#endif
16386 movq %rsp,%rdi /* pt_regs pointer */
16387 movq ORIG_RAX(%rsp),%rsi /* get error code */
16388 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16389 call \do_sym
16390 jmp paranoid_exit /* %ebx: no swapgs flag */
16391 CFI_ENDPROC
16392-END(\sym)
16393+ENDPROC(\sym)
16394 .endm
16395
16396 zeroentry divide_error do_divide_error
16397@@ -1141,9 +1509,10 @@ gs_change:
16398 SWAPGS
16399 popf
16400 CFI_ADJUST_CFA_OFFSET -8
16401+ pax_force_retaddr
16402 ret
16403 CFI_ENDPROC
16404-END(native_load_gs_index)
16405+ENDPROC(native_load_gs_index)
16406
16407 .section __ex_table,"a"
16408 .align 8
16409@@ -1193,11 +1562,12 @@ ENTRY(kernel_thread)
16410 * of hacks for example to fork off the per-CPU idle tasks.
16411 * [Hopefully no generic code relies on the reschedule -AK]
16412 */
16413- RESTORE_ALL
16414+ RESTORE_REST
16415 UNFAKE_STACK_FRAME
16416+ pax_force_retaddr
16417 ret
16418 CFI_ENDPROC
16419-END(kernel_thread)
16420+ENDPROC(kernel_thread)
16421
16422 ENTRY(child_rip)
16423 pushq $0 # fake return address
16424@@ -1208,13 +1578,14 @@ ENTRY(child_rip)
16425 */
16426 movq %rdi, %rax
16427 movq %rsi, %rdi
16428+ pax_force_fptr %rax
16429 call *%rax
16430 # exit
16431 mov %eax, %edi
16432 call do_exit
16433 ud2 # padding for call trace
16434 CFI_ENDPROC
16435-END(child_rip)
16436+ENDPROC(child_rip)
16437
16438 /*
16439 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16440@@ -1241,11 +1612,11 @@ ENTRY(kernel_execve)
16441 RESTORE_REST
16442 testq %rax,%rax
16443 je int_ret_from_sys_call
16444- RESTORE_ARGS
16445 UNFAKE_STACK_FRAME
16446+ pax_force_retaddr
16447 ret
16448 CFI_ENDPROC
16449-END(kernel_execve)
16450+ENDPROC(kernel_execve)
16451
16452 /* Call softirq on interrupt stack. Interrupts are off. */
16453 ENTRY(call_softirq)
16454@@ -1263,9 +1634,10 @@ ENTRY(call_softirq)
16455 CFI_DEF_CFA_REGISTER rsp
16456 CFI_ADJUST_CFA_OFFSET -8
16457 decl PER_CPU_VAR(irq_count)
16458+ pax_force_retaddr
16459 ret
16460 CFI_ENDPROC
16461-END(call_softirq)
16462+ENDPROC(call_softirq)
16463
16464 #ifdef CONFIG_XEN
16465 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16466@@ -1303,7 +1675,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16467 decl PER_CPU_VAR(irq_count)
16468 jmp error_exit
16469 CFI_ENDPROC
16470-END(xen_do_hypervisor_callback)
16471+ENDPROC(xen_do_hypervisor_callback)
16472
16473 /*
16474 * Hypervisor uses this for application faults while it executes.
16475@@ -1362,7 +1734,7 @@ ENTRY(xen_failsafe_callback)
16476 SAVE_ALL
16477 jmp error_exit
16478 CFI_ENDPROC
16479-END(xen_failsafe_callback)
16480+ENDPROC(xen_failsafe_callback)
16481
16482 #endif /* CONFIG_XEN */
16483
16484@@ -1405,16 +1777,31 @@ ENTRY(paranoid_exit)
16485 TRACE_IRQS_OFF
16486 testl %ebx,%ebx /* swapgs needed? */
16487 jnz paranoid_restore
16488- testl $3,CS(%rsp)
16489+ testb $3,CS(%rsp)
16490 jnz paranoid_userspace
16491+#ifdef CONFIG_PAX_MEMORY_UDEREF
16492+ pax_exit_kernel
16493+ TRACE_IRQS_IRETQ 0
16494+ SWAPGS_UNSAFE_STACK
16495+ RESTORE_ALL 8
16496+ pax_force_retaddr_bts
16497+ jmp irq_return
16498+#endif
16499 paranoid_swapgs:
16500+#ifdef CONFIG_PAX_MEMORY_UDEREF
16501+ pax_exit_kernel_user
16502+#else
16503+ pax_exit_kernel
16504+#endif
16505 TRACE_IRQS_IRETQ 0
16506 SWAPGS_UNSAFE_STACK
16507 RESTORE_ALL 8
16508 jmp irq_return
16509 paranoid_restore:
16510+ pax_exit_kernel
16511 TRACE_IRQS_IRETQ 0
16512 RESTORE_ALL 8
16513+ pax_force_retaddr_bts
16514 jmp irq_return
16515 paranoid_userspace:
16516 GET_THREAD_INFO(%rcx)
16517@@ -1443,7 +1830,7 @@ paranoid_schedule:
16518 TRACE_IRQS_OFF
16519 jmp paranoid_userspace
16520 CFI_ENDPROC
16521-END(paranoid_exit)
16522+ENDPROC(paranoid_exit)
16523
16524 /*
16525 * Exception entry point. This expects an error code/orig_rax on the stack.
16526@@ -1470,12 +1857,13 @@ ENTRY(error_entry)
16527 movq_cfi r14, R14+8
16528 movq_cfi r15, R15+8
16529 xorl %ebx,%ebx
16530- testl $3,CS+8(%rsp)
16531+ testb $3,CS+8(%rsp)
16532 je error_kernelspace
16533 error_swapgs:
16534 SWAPGS
16535 error_sti:
16536 TRACE_IRQS_OFF
16537+ pax_force_retaddr_bts
16538 ret
16539 CFI_ENDPROC
16540
16541@@ -1497,7 +1885,7 @@ error_kernelspace:
16542 cmpq $gs_change,RIP+8(%rsp)
16543 je error_swapgs
16544 jmp error_sti
16545-END(error_entry)
16546+ENDPROC(error_entry)
16547
16548
16549 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16550@@ -1517,7 +1905,7 @@ ENTRY(error_exit)
16551 jnz retint_careful
16552 jmp retint_swapgs
16553 CFI_ENDPROC
16554-END(error_exit)
16555+ENDPROC(error_exit)
16556
16557
16558 /* runs on exception stack */
16559@@ -1529,6 +1917,16 @@ ENTRY(nmi)
16560 CFI_ADJUST_CFA_OFFSET 15*8
16561 call save_paranoid
16562 DEFAULT_FRAME 0
16563+#ifdef CONFIG_PAX_MEMORY_UDEREF
16564+ testb $3, CS(%rsp)
16565+ jnz 1f
16566+ pax_enter_kernel
16567+ jmp 2f
16568+1: pax_enter_kernel_user
16569+2:
16570+#else
16571+ pax_enter_kernel
16572+#endif
16573 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16574 movq %rsp,%rdi
16575 movq $-1,%rsi
16576@@ -1539,12 +1937,28 @@ ENTRY(nmi)
16577 DISABLE_INTERRUPTS(CLBR_NONE)
16578 testl %ebx,%ebx /* swapgs needed? */
16579 jnz nmi_restore
16580- testl $3,CS(%rsp)
16581+ testb $3,CS(%rsp)
16582 jnz nmi_userspace
16583+#ifdef CONFIG_PAX_MEMORY_UDEREF
16584+ pax_exit_kernel
16585+ SWAPGS_UNSAFE_STACK
16586+ RESTORE_ALL 8
16587+ pax_force_retaddr_bts
16588+ jmp irq_return
16589+#endif
16590 nmi_swapgs:
16591+#ifdef CONFIG_PAX_MEMORY_UDEREF
16592+ pax_exit_kernel_user
16593+#else
16594+ pax_exit_kernel
16595+#endif
16596 SWAPGS_UNSAFE_STACK
16597+ RESTORE_ALL 8
16598+ jmp irq_return
16599 nmi_restore:
16600+ pax_exit_kernel
16601 RESTORE_ALL 8
16602+ pax_force_retaddr_bts
16603 jmp irq_return
16604 nmi_userspace:
16605 GET_THREAD_INFO(%rcx)
16606@@ -1573,14 +1987,14 @@ nmi_schedule:
16607 jmp paranoid_exit
16608 CFI_ENDPROC
16609 #endif
16610-END(nmi)
16611+ENDPROC(nmi)
16612
16613 ENTRY(ignore_sysret)
16614 CFI_STARTPROC
16615 mov $-ENOSYS,%eax
16616 sysret
16617 CFI_ENDPROC
16618-END(ignore_sysret)
16619+ENDPROC(ignore_sysret)
16620
16621 /*
16622 * End of kprobes section
16623diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16624index 9dbb527..7b3615a 100644
16625--- a/arch/x86/kernel/ftrace.c
16626+++ b/arch/x86/kernel/ftrace.c
16627@@ -103,7 +103,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16628 static void *mod_code_newcode; /* holds the text to write to the IP */
16629
16630 static unsigned nmi_wait_count;
16631-static atomic_t nmi_update_count = ATOMIC_INIT(0);
16632+static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16633
16634 int ftrace_arch_read_dyn_info(char *buf, int size)
16635 {
16636@@ -111,7 +111,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16637
16638 r = snprintf(buf, size, "%u %u",
16639 nmi_wait_count,
16640- atomic_read(&nmi_update_count));
16641+ atomic_read_unchecked(&nmi_update_count));
16642 return r;
16643 }
16644
16645@@ -149,8 +149,10 @@ void ftrace_nmi_enter(void)
16646 {
16647 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16648 smp_rmb();
16649+ pax_open_kernel();
16650 ftrace_mod_code();
16651- atomic_inc(&nmi_update_count);
16652+ pax_close_kernel();
16653+ atomic_inc_unchecked(&nmi_update_count);
16654 }
16655 /* Must have previous changes seen before executions */
16656 smp_mb();
16657@@ -215,7 +217,7 @@ do_ftrace_mod_code(unsigned long ip, void *new_code)
16658
16659
16660
16661-static unsigned char ftrace_nop[MCOUNT_INSN_SIZE];
16662+static unsigned char ftrace_nop[MCOUNT_INSN_SIZE] __read_only;
16663
16664 static unsigned char *ftrace_nop_replace(void)
16665 {
16666@@ -228,6 +230,8 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
16667 {
16668 unsigned char replaced[MCOUNT_INSN_SIZE];
16669
16670+ ip = ktla_ktva(ip);
16671+
16672 /*
16673 * Note: Due to modules and __init, code can
16674 * disappear and change, we need to protect against faulting
16675@@ -284,7 +288,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16676 unsigned char old[MCOUNT_INSN_SIZE], *new;
16677 int ret;
16678
16679- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16680+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16681 new = ftrace_call_replace(ip, (unsigned long)func);
16682 ret = ftrace_modify_code(ip, old, new);
16683
16684@@ -337,15 +341,15 @@ int __init ftrace_dyn_arch_init(void *data)
16685 switch (faulted) {
16686 case 0:
16687 pr_info("ftrace: converting mcount calls to 0f 1f 44 00 00\n");
16688- memcpy(ftrace_nop, ftrace_test_p6nop, MCOUNT_INSN_SIZE);
16689+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_p6nop), MCOUNT_INSN_SIZE);
16690 break;
16691 case 1:
16692 pr_info("ftrace: converting mcount calls to 66 66 66 66 90\n");
16693- memcpy(ftrace_nop, ftrace_test_nop5, MCOUNT_INSN_SIZE);
16694+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_nop5), MCOUNT_INSN_SIZE);
16695 break;
16696 case 2:
16697 pr_info("ftrace: converting mcount calls to jmp . + 5\n");
16698- memcpy(ftrace_nop, ftrace_test_jmp, MCOUNT_INSN_SIZE);
16699+ memcpy(ftrace_nop, ktla_ktva(ftrace_test_jmp), MCOUNT_INSN_SIZE);
16700 break;
16701 }
16702
16703@@ -366,6 +370,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16704 {
16705 unsigned char code[MCOUNT_INSN_SIZE];
16706
16707+ ip = ktla_ktva(ip);
16708+
16709 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16710 return -EFAULT;
16711
16712diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16713index 4f8e250..df24706 100644
16714--- a/arch/x86/kernel/head32.c
16715+++ b/arch/x86/kernel/head32.c
16716@@ -16,6 +16,7 @@
16717 #include <asm/apic.h>
16718 #include <asm/io_apic.h>
16719 #include <asm/bios_ebda.h>
16720+#include <asm/boot.h>
16721
16722 static void __init i386_default_early_setup(void)
16723 {
16724@@ -31,7 +32,7 @@ void __init i386_start_kernel(void)
16725 {
16726 reserve_trampoline_memory();
16727
16728- reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
16729+ reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
16730
16731 #ifdef CONFIG_BLK_DEV_INITRD
16732 /* Reserve INITRD */
16733diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16734index 34c3308..6fc4e76 100644
16735--- a/arch/x86/kernel/head_32.S
16736+++ b/arch/x86/kernel/head_32.S
16737@@ -19,10 +19,17 @@
16738 #include <asm/setup.h>
16739 #include <asm/processor-flags.h>
16740 #include <asm/percpu.h>
16741+#include <asm/msr-index.h>
16742
16743 /* Physical address */
16744 #define pa(X) ((X) - __PAGE_OFFSET)
16745
16746+#ifdef CONFIG_PAX_KERNEXEC
16747+#define ta(X) (X)
16748+#else
16749+#define ta(X) ((X) - __PAGE_OFFSET)
16750+#endif
16751+
16752 /*
16753 * References to members of the new_cpu_data structure.
16754 */
16755@@ -52,11 +59,7 @@
16756 * and small than max_low_pfn, otherwise will waste some page table entries
16757 */
16758
16759-#if PTRS_PER_PMD > 1
16760-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16761-#else
16762-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16763-#endif
16764+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16765
16766 /* Enough space to fit pagetables for the low memory linear map */
16767 MAPPING_BEYOND_END = \
16768@@ -73,6 +76,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE_asm
16769 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16770
16771 /*
16772+ * Real beginning of normal "text" segment
16773+ */
16774+ENTRY(stext)
16775+ENTRY(_stext)
16776+
16777+/*
16778 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16779 * %esi points to the real-mode code as a 32-bit pointer.
16780 * CS and DS must be 4 GB flat segments, but we don't depend on
16781@@ -80,7 +89,16 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16782 * can.
16783 */
16784 __HEAD
16785+
16786+#ifdef CONFIG_PAX_KERNEXEC
16787+ jmp startup_32
16788+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16789+.fill PAGE_SIZE-5,1,0xcc
16790+#endif
16791+
16792 ENTRY(startup_32)
16793+ movl pa(stack_start),%ecx
16794+
16795 /* test KEEP_SEGMENTS flag to see if the bootloader is asking
16796 us to not reload segments */
16797 testb $(1<<6), BP_loadflags(%esi)
16798@@ -95,7 +113,60 @@ ENTRY(startup_32)
16799 movl %eax,%es
16800 movl %eax,%fs
16801 movl %eax,%gs
16802+ movl %eax,%ss
16803 2:
16804+ leal -__PAGE_OFFSET(%ecx),%esp
16805+
16806+#ifdef CONFIG_SMP
16807+ movl $pa(cpu_gdt_table),%edi
16808+ movl $__per_cpu_load,%eax
16809+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16810+ rorl $16,%eax
16811+ movb %al,__KERNEL_PERCPU + 4(%edi)
16812+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16813+ movl $__per_cpu_end - 1,%eax
16814+ subl $__per_cpu_start,%eax
16815+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16816+#endif
16817+
16818+#ifdef CONFIG_PAX_MEMORY_UDEREF
16819+ movl $NR_CPUS,%ecx
16820+ movl $pa(cpu_gdt_table),%edi
16821+1:
16822+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16823+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16824+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16825+ addl $PAGE_SIZE_asm,%edi
16826+ loop 1b
16827+#endif
16828+
16829+#ifdef CONFIG_PAX_KERNEXEC
16830+ movl $pa(boot_gdt),%edi
16831+ movl $__LOAD_PHYSICAL_ADDR,%eax
16832+ movw %ax,__BOOT_CS + 2(%edi)
16833+ rorl $16,%eax
16834+ movb %al,__BOOT_CS + 4(%edi)
16835+ movb %ah,__BOOT_CS + 7(%edi)
16836+ rorl $16,%eax
16837+
16838+ ljmp $(__BOOT_CS),$1f
16839+1:
16840+
16841+ movl $NR_CPUS,%ecx
16842+ movl $pa(cpu_gdt_table),%edi
16843+ addl $__PAGE_OFFSET,%eax
16844+1:
16845+ movw %ax,__KERNEL_CS + 2(%edi)
16846+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16847+ rorl $16,%eax
16848+ movb %al,__KERNEL_CS + 4(%edi)
16849+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16850+ movb %ah,__KERNEL_CS + 7(%edi)
16851+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16852+ rorl $16,%eax
16853+ addl $PAGE_SIZE_asm,%edi
16854+ loop 1b
16855+#endif
16856
16857 /*
16858 * Clear BSS first so that there are no surprises...
16859@@ -140,9 +211,7 @@ ENTRY(startup_32)
16860 cmpl $num_subarch_entries, %eax
16861 jae bad_subarch
16862
16863- movl pa(subarch_entries)(,%eax,4), %eax
16864- subl $__PAGE_OFFSET, %eax
16865- jmp *%eax
16866+ jmp *pa(subarch_entries)(,%eax,4)
16867
16868 bad_subarch:
16869 WEAK(lguest_entry)
16870@@ -154,10 +223,10 @@ WEAK(xen_entry)
16871 __INITDATA
16872
16873 subarch_entries:
16874- .long default_entry /* normal x86/PC */
16875- .long lguest_entry /* lguest hypervisor */
16876- .long xen_entry /* Xen hypervisor */
16877- .long default_entry /* Moorestown MID */
16878+ .long ta(default_entry) /* normal x86/PC */
16879+ .long ta(lguest_entry) /* lguest hypervisor */
16880+ .long ta(xen_entry) /* Xen hypervisor */
16881+ .long ta(default_entry) /* Moorestown MID */
16882 num_subarch_entries = (. - subarch_entries) / 4
16883 .previous
16884 #endif /* CONFIG_PARAVIRT */
16885@@ -218,8 +287,11 @@ default_entry:
16886 movl %eax, pa(max_pfn_mapped)
16887
16888 /* Do early initialization of the fixmap area */
16889- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
16890- movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
16891+#ifdef CONFIG_COMPAT_VDSO
16892+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_pmd+0x1000*KPMDS-8)
16893+#else
16894+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
16895+#endif
16896 #else /* Not PAE */
16897
16898 page_pde_offset = (__PAGE_OFFSET >> 20);
16899@@ -249,8 +321,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16900 movl %eax, pa(max_pfn_mapped)
16901
16902 /* Do early initialization of the fixmap area */
16903- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
16904- movl %eax,pa(swapper_pg_dir+0xffc)
16905+#ifdef CONFIG_COMPAT_VDSO
16906+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(swapper_pg_dir+0xffc)
16907+#else
16908+ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_dir+0xffc)
16909+#endif
16910 #endif
16911 jmp 3f
16912 /*
16913@@ -272,6 +347,9 @@ ENTRY(startup_32_smp)
16914 movl %eax,%es
16915 movl %eax,%fs
16916 movl %eax,%gs
16917+ movl pa(stack_start),%ecx
16918+ movl %eax,%ss
16919+ leal -__PAGE_OFFSET(%ecx),%esp
16920 #endif /* CONFIG_SMP */
16921 3:
16922
16923@@ -297,6 +375,7 @@ ENTRY(startup_32_smp)
16924 orl %edx,%eax
16925 movl %eax,%cr4
16926
16927+#ifdef CONFIG_X86_PAE
16928 btl $5, %eax # check if PAE is enabled
16929 jnc 6f
16930
16931@@ -305,6 +384,10 @@ ENTRY(startup_32_smp)
16932 cpuid
16933 cmpl $0x80000000, %eax
16934 jbe 6f
16935+
16936+ /* Clear bogus XD_DISABLE bits */
16937+ call verify_cpu
16938+
16939 mov $0x80000001, %eax
16940 cpuid
16941 /* Execute Disable bit supported? */
16942@@ -312,13 +395,17 @@ ENTRY(startup_32_smp)
16943 jnc 6f
16944
16945 /* Setup EFER (Extended Feature Enable Register) */
16946- movl $0xc0000080, %ecx
16947+ movl $MSR_EFER, %ecx
16948 rdmsr
16949
16950 btsl $11, %eax
16951 /* Make changes effective */
16952 wrmsr
16953
16954+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16955+ movl $1,pa(nx_enabled)
16956+#endif
16957+
16958 6:
16959
16960 /*
16961@@ -331,8 +418,8 @@ ENTRY(startup_32_smp)
16962 movl %eax,%cr0 /* ..and set paging (PG) bit */
16963 ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */
16964 1:
16965- /* Set up the stack pointer */
16966- lss stack_start,%esp
16967+ /* Shift the stack pointer to a virtual address */
16968+ addl $__PAGE_OFFSET, %esp
16969
16970 /*
16971 * Initialize eflags. Some BIOS's leave bits like NT set. This would
16972@@ -344,9 +431,7 @@ ENTRY(startup_32_smp)
16973
16974 #ifdef CONFIG_SMP
16975 cmpb $0, ready
16976- jz 1f /* Initial CPU cleans BSS */
16977- jmp checkCPUtype
16978-1:
16979+ jnz checkCPUtype
16980 #endif /* CONFIG_SMP */
16981
16982 /*
16983@@ -424,7 +509,7 @@ is386: movl $2,%ecx # set MP
16984 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16985 movl %eax,%ss # after changing gdt.
16986
16987- movl $(__USER_DS),%eax # DS/ES contains default USER segment
16988+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16989 movl %eax,%ds
16990 movl %eax,%es
16991
16992@@ -438,15 +523,22 @@ is386: movl $2,%ecx # set MP
16993 */
16994 cmpb $0,ready
16995 jne 1f
16996- movl $per_cpu__gdt_page,%eax
16997+ movl $cpu_gdt_table,%eax
16998 movl $per_cpu__stack_canary,%ecx
16999+#ifdef CONFIG_SMP
17000+ addl $__per_cpu_load,%ecx
17001+#endif
17002 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17003 shrl $16, %ecx
17004 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17005 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
17006 1:
17007-#endif
17008 movl $(__KERNEL_STACK_CANARY),%eax
17009+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17010+ movl $(__USER_DS),%eax
17011+#else
17012+ xorl %eax,%eax
17013+#endif
17014 movl %eax,%gs
17015
17016 xorl %eax,%eax # Clear LDT
17017@@ -454,14 +546,7 @@ is386: movl $2,%ecx # set MP
17018
17019 cld # gcc2 wants the direction flag cleared at all times
17020 pushl $0 # fake return address for unwinder
17021-#ifdef CONFIG_SMP
17022- movb ready, %cl
17023 movb $1, ready
17024- cmpb $0,%cl # the first CPU calls start_kernel
17025- je 1f
17026- movl (stack_start), %esp
17027-1:
17028-#endif /* CONFIG_SMP */
17029 jmp *(initial_code)
17030
17031 /*
17032@@ -546,22 +631,22 @@ early_page_fault:
17033 jmp early_fault
17034
17035 early_fault:
17036- cld
17037 #ifdef CONFIG_PRINTK
17038+ cmpl $1,%ss:early_recursion_flag
17039+ je hlt_loop
17040+ incl %ss:early_recursion_flag
17041+ cld
17042 pusha
17043 movl $(__KERNEL_DS),%eax
17044 movl %eax,%ds
17045 movl %eax,%es
17046- cmpl $2,early_recursion_flag
17047- je hlt_loop
17048- incl early_recursion_flag
17049 movl %cr2,%eax
17050 pushl %eax
17051 pushl %edx /* trapno */
17052 pushl $fault_msg
17053 call printk
17054+; call dump_stack
17055 #endif
17056- call dump_stack
17057 hlt_loop:
17058 hlt
17059 jmp hlt_loop
17060@@ -569,8 +654,11 @@ hlt_loop:
17061 /* This is the default interrupt "handler" :-) */
17062 ALIGN
17063 ignore_int:
17064- cld
17065 #ifdef CONFIG_PRINTK
17066+ cmpl $2,%ss:early_recursion_flag
17067+ je hlt_loop
17068+ incl %ss:early_recursion_flag
17069+ cld
17070 pushl %eax
17071 pushl %ecx
17072 pushl %edx
17073@@ -579,9 +667,6 @@ ignore_int:
17074 movl $(__KERNEL_DS),%eax
17075 movl %eax,%ds
17076 movl %eax,%es
17077- cmpl $2,early_recursion_flag
17078- je hlt_loop
17079- incl early_recursion_flag
17080 pushl 16(%esp)
17081 pushl 24(%esp)
17082 pushl 32(%esp)
17083@@ -600,6 +685,8 @@ ignore_int:
17084 #endif
17085 iret
17086
17087+#include "verify_cpu.S"
17088+
17089 __REFDATA
17090 .align 4
17091 ENTRY(initial_code)
17092@@ -610,31 +697,47 @@ ENTRY(initial_page_table)
17093 /*
17094 * BSS section
17095 */
17096-__PAGE_ALIGNED_BSS
17097- .align PAGE_SIZE_asm
17098 #ifdef CONFIG_X86_PAE
17099+.section .swapper_pg_pmd,"a",@progbits
17100 swapper_pg_pmd:
17101 .fill 1024*KPMDS,4,0
17102 #else
17103+.section .swapper_pg_dir,"a",@progbits
17104 ENTRY(swapper_pg_dir)
17105 .fill 1024,4,0
17106 #endif
17107+.section .swapper_pg_fixmap,"a",@progbits
17108 swapper_pg_fixmap:
17109 .fill 1024,4,0
17110 #ifdef CONFIG_X86_TRAMPOLINE
17111+.section .trampoline_pg_dir,"a",@progbits
17112 ENTRY(trampoline_pg_dir)
17113+#ifdef CONFIG_X86_PAE
17114+ .fill 4,8,0
17115+#else
17116 .fill 1024,4,0
17117 #endif
17118+#endif
17119+
17120+.section .empty_zero_page,"a",@progbits
17121 ENTRY(empty_zero_page)
17122 .fill 4096,1,0
17123
17124 /*
17125+ * The IDT has to be page-aligned to simplify the Pentium
17126+ * F0 0F bug workaround.. We have a special link segment
17127+ * for this.
17128+ */
17129+.section .idt,"a",@progbits
17130+ENTRY(idt_table)
17131+ .fill 256,8,0
17132+
17133+/*
17134 * This starts the data section.
17135 */
17136 #ifdef CONFIG_X86_PAE
17137-__PAGE_ALIGNED_DATA
17138- /* Page-aligned for the benefit of paravirt? */
17139- .align PAGE_SIZE_asm
17140+.section .swapper_pg_dir,"a",@progbits
17141+
17142 ENTRY(swapper_pg_dir)
17143 .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17144 # if KPMDS == 3
17145@@ -653,15 +756,24 @@ ENTRY(swapper_pg_dir)
17146 # error "Kernel PMDs should be 1, 2 or 3"
17147 # endif
17148 .align PAGE_SIZE_asm /* needs to be page-sized too */
17149+
17150+#ifdef CONFIG_PAX_PER_CPU_PGD
17151+ENTRY(cpu_pgd)
17152+ .rept NR_CPUS
17153+ .fill 4,8,0
17154+ .endr
17155+#endif
17156+
17157 #endif
17158
17159 .data
17160+.balign 4
17161 ENTRY(stack_start)
17162- .long init_thread_union+THREAD_SIZE
17163- .long __BOOT_DS
17164+ .long init_thread_union+THREAD_SIZE-8
17165
17166 ready: .byte 0
17167
17168+.section .rodata,"a",@progbits
17169 early_recursion_flag:
17170 .long 0
17171
17172@@ -697,7 +809,7 @@ fault_msg:
17173 .word 0 # 32 bit align gdt_desc.address
17174 boot_gdt_descr:
17175 .word __BOOT_DS+7
17176- .long boot_gdt - __PAGE_OFFSET
17177+ .long pa(boot_gdt)
17178
17179 .word 0 # 32-bit align idt_desc.address
17180 idt_descr:
17181@@ -708,7 +820,7 @@ idt_descr:
17182 .word 0 # 32 bit align gdt_desc.address
17183 ENTRY(early_gdt_descr)
17184 .word GDT_ENTRIES*8-1
17185- .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
17186+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17187
17188 /*
17189 * The boot_gdt must mirror the equivalent in setup.S and is
17190@@ -717,5 +829,65 @@ ENTRY(early_gdt_descr)
17191 .align L1_CACHE_BYTES
17192 ENTRY(boot_gdt)
17193 .fill GDT_ENTRY_BOOT_CS,8,0
17194- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17195- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17196+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17197+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17198+
17199+ .align PAGE_SIZE_asm
17200+ENTRY(cpu_gdt_table)
17201+ .rept NR_CPUS
17202+ .quad 0x0000000000000000 /* NULL descriptor */
17203+ .quad 0x0000000000000000 /* 0x0b reserved */
17204+ .quad 0x0000000000000000 /* 0x13 reserved */
17205+ .quad 0x0000000000000000 /* 0x1b reserved */
17206+
17207+#ifdef CONFIG_PAX_KERNEXEC
17208+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17209+#else
17210+ .quad 0x0000000000000000 /* 0x20 unused */
17211+#endif
17212+
17213+ .quad 0x0000000000000000 /* 0x28 unused */
17214+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17215+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17216+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17217+ .quad 0x0000000000000000 /* 0x4b reserved */
17218+ .quad 0x0000000000000000 /* 0x53 reserved */
17219+ .quad 0x0000000000000000 /* 0x5b reserved */
17220+
17221+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17222+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17223+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17224+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17225+
17226+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17227+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17228+
17229+ /*
17230+ * Segments used for calling PnP BIOS have byte granularity.
17231+ * The code segments and data segments have fixed 64k limits,
17232+ * the transfer segment sizes are set at run time.
17233+ */
17234+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17235+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17236+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17237+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17238+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17239+
17240+ /*
17241+ * The APM segments have byte granularity and their bases
17242+ * are set at run time. All have 64k limits.
17243+ */
17244+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17245+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17246+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17247+
17248+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17249+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17250+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17251+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17252+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17253+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17254+
17255+ /* Be sure this is zeroed to avoid false validations in Xen */
17256+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17257+ .endr
17258diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17259index 780cd92..758b2a6 100644
17260--- a/arch/x86/kernel/head_64.S
17261+++ b/arch/x86/kernel/head_64.S
17262@@ -19,6 +19,8 @@
17263 #include <asm/cache.h>
17264 #include <asm/processor-flags.h>
17265 #include <asm/percpu.h>
17266+#include <asm/cpufeature.h>
17267+#include <asm/alternative-asm.h>
17268
17269 #ifdef CONFIG_PARAVIRT
17270 #include <asm/asm-offsets.h>
17271@@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17272 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17273 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17274 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17275+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17276+L3_VMALLOC_START = pud_index(VMALLOC_START)
17277+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17278+L3_VMALLOC_END = pud_index(VMALLOC_END)
17279+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17280+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17281
17282 .text
17283 __HEAD
17284@@ -85,35 +93,23 @@ startup_64:
17285 */
17286 addq %rbp, init_level4_pgt + 0(%rip)
17287 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17288+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17289+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17290+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17291 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17292
17293 addq %rbp, level3_ident_pgt + 0(%rip)
17294+#ifndef CONFIG_XEN
17295+ addq %rbp, level3_ident_pgt + 8(%rip)
17296+#endif
17297
17298- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17299- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17300+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17301+
17302+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17303+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17304
17305 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17306-
17307- /* Add an Identity mapping if I am above 1G */
17308- leaq _text(%rip), %rdi
17309- andq $PMD_PAGE_MASK, %rdi
17310-
17311- movq %rdi, %rax
17312- shrq $PUD_SHIFT, %rax
17313- andq $(PTRS_PER_PUD - 1), %rax
17314- jz ident_complete
17315-
17316- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17317- leaq level3_ident_pgt(%rip), %rbx
17318- movq %rdx, 0(%rbx, %rax, 8)
17319-
17320- movq %rdi, %rax
17321- shrq $PMD_SHIFT, %rax
17322- andq $(PTRS_PER_PMD - 1), %rax
17323- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17324- leaq level2_spare_pgt(%rip), %rbx
17325- movq %rdx, 0(%rbx, %rax, 8)
17326-ident_complete:
17327+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17328
17329 /*
17330 * Fixup the kernel text+data virtual addresses. Note that
17331@@ -161,8 +157,8 @@ ENTRY(secondary_startup_64)
17332 * after the boot processor executes this code.
17333 */
17334
17335- /* Enable PAE mode and PGE */
17336- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17337+ /* Enable PAE mode and PSE/PGE */
17338+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17339 movq %rax, %cr4
17340
17341 /* Setup early boot stage 4 level pagetables. */
17342@@ -184,9 +180,16 @@ ENTRY(secondary_startup_64)
17343 movl $MSR_EFER, %ecx
17344 rdmsr
17345 btsl $_EFER_SCE, %eax /* Enable System Call */
17346- btl $20,%edi /* No Execute supported? */
17347+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17348 jnc 1f
17349 btsl $_EFER_NX, %eax
17350+ leaq init_level4_pgt(%rip), %rdi
17351+#ifndef CONFIG_EFI
17352+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17353+#endif
17354+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17355+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17356+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17357 1: wrmsr /* Make changes effective */
17358
17359 /* Setup cr0 */
17360@@ -249,6 +252,7 @@ ENTRY(secondary_startup_64)
17361 * jump. In addition we need to ensure %cs is set so we make this
17362 * a far return.
17363 */
17364+ pax_set_fptr_mask
17365 movq initial_code(%rip),%rax
17366 pushq $0 # fake return address to stop unwinder
17367 pushq $__KERNEL_CS # set correct cs
17368@@ -262,16 +266,16 @@ ENTRY(secondary_startup_64)
17369 .quad x86_64_start_kernel
17370 ENTRY(initial_gs)
17371 .quad INIT_PER_CPU_VAR(irq_stack_union)
17372- __FINITDATA
17373
17374 ENTRY(stack_start)
17375 .quad init_thread_union+THREAD_SIZE-8
17376 .word 0
17377+ __FINITDATA
17378
17379 bad_address:
17380 jmp bad_address
17381
17382- .section ".init.text","ax"
17383+ __INIT
17384 #ifdef CONFIG_EARLY_PRINTK
17385 .globl early_idt_handlers
17386 early_idt_handlers:
17387@@ -316,18 +320,23 @@ ENTRY(early_idt_handler)
17388 #endif /* EARLY_PRINTK */
17389 1: hlt
17390 jmp 1b
17391+ .previous
17392
17393 #ifdef CONFIG_EARLY_PRINTK
17394+ __INITDATA
17395 early_recursion_flag:
17396 .long 0
17397+ .previous
17398
17399+ .section .rodata,"a",@progbits
17400 early_idt_msg:
17401 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17402 early_idt_ripmsg:
17403 .asciz "RIP %s\n"
17404+ .previous
17405 #endif /* CONFIG_EARLY_PRINTK */
17406- .previous
17407
17408+ .section .rodata,"a",@progbits
17409 #define NEXT_PAGE(name) \
17410 .balign PAGE_SIZE; \
17411 ENTRY(name)
17412@@ -350,13 +359,41 @@ NEXT_PAGE(init_level4_pgt)
17413 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17414 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17415 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17416+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17417+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17418+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17419+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17420+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17421+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17422 .org init_level4_pgt + L4_START_KERNEL*8, 0
17423 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17424 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17425
17426+#ifdef CONFIG_PAX_PER_CPU_PGD
17427+NEXT_PAGE(cpu_pgd)
17428+ .rept NR_CPUS
17429+ .fill 512,8,0
17430+ .endr
17431+#endif
17432+
17433 NEXT_PAGE(level3_ident_pgt)
17434 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17435+#ifdef CONFIG_XEN
17436 .fill 511,8,0
17437+#else
17438+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17439+ .fill 510,8,0
17440+#endif
17441+
17442+NEXT_PAGE(level3_vmalloc_start_pgt)
17443+ .fill 512,8,0
17444+
17445+NEXT_PAGE(level3_vmalloc_end_pgt)
17446+ .fill 512,8,0
17447+
17448+NEXT_PAGE(level3_vmemmap_pgt)
17449+ .fill L3_VMEMMAP_START,8,0
17450+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17451
17452 NEXT_PAGE(level3_kernel_pgt)
17453 .fill L3_START_KERNEL,8,0
17454@@ -364,20 +401,23 @@ NEXT_PAGE(level3_kernel_pgt)
17455 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17456 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17457
17458+NEXT_PAGE(level2_vmemmap_pgt)
17459+ .fill 512,8,0
17460+
17461 NEXT_PAGE(level2_fixmap_pgt)
17462- .fill 506,8,0
17463- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17464- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17465- .fill 5,8,0
17466+ .fill 507,8,0
17467+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17468+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17469+ .fill 4,8,0
17470
17471-NEXT_PAGE(level1_fixmap_pgt)
17472+NEXT_PAGE(level1_vsyscall_pgt)
17473 .fill 512,8,0
17474
17475-NEXT_PAGE(level2_ident_pgt)
17476- /* Since I easily can, map the first 1G.
17477+ /* Since I easily can, map the first 2G.
17478 * Don't set NX because code runs from these pages.
17479 */
17480- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17481+NEXT_PAGE(level2_ident_pgt)
17482+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17483
17484 NEXT_PAGE(level2_kernel_pgt)
17485 /*
17486@@ -390,33 +430,55 @@ NEXT_PAGE(level2_kernel_pgt)
17487 * If you want to increase this then increase MODULES_VADDR
17488 * too.)
17489 */
17490- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17491- KERNEL_IMAGE_SIZE/PMD_SIZE)
17492-
17493-NEXT_PAGE(level2_spare_pgt)
17494- .fill 512, 8, 0
17495+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17496
17497 #undef PMDS
17498 #undef NEXT_PAGE
17499
17500- .data
17501+ .align PAGE_SIZE
17502+ENTRY(cpu_gdt_table)
17503+ .rept NR_CPUS
17504+ .quad 0x0000000000000000 /* NULL descriptor */
17505+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17506+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17507+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17508+ .quad 0x00cffb000000ffff /* __USER32_CS */
17509+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17510+ .quad 0x00affb000000ffff /* __USER_CS */
17511+
17512+#ifdef CONFIG_PAX_KERNEXEC
17513+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17514+#else
17515+ .quad 0x0 /* unused */
17516+#endif
17517+
17518+ .quad 0,0 /* TSS */
17519+ .quad 0,0 /* LDT */
17520+ .quad 0,0,0 /* three TLS descriptors */
17521+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17522+ /* asm/segment.h:GDT_ENTRIES must match this */
17523+
17524+ /* zero the remaining page */
17525+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17526+ .endr
17527+
17528 .align 16
17529 .globl early_gdt_descr
17530 early_gdt_descr:
17531 .word GDT_ENTRIES*8-1
17532 early_gdt_descr_base:
17533- .quad INIT_PER_CPU_VAR(gdt_page)
17534+ .quad cpu_gdt_table
17535
17536 ENTRY(phys_base)
17537 /* This must match the first entry in level2_kernel_pgt */
17538 .quad 0x0000000000000000
17539
17540 #include "../../x86/xen/xen-head.S"
17541-
17542- .section .bss, "aw", @nobits
17543+
17544+ .section .rodata,"a",@progbits
17545 .align L1_CACHE_BYTES
17546 ENTRY(idt_table)
17547- .skip IDT_ENTRIES * 16
17548+ .fill 512,8,0
17549
17550 __PAGE_ALIGNED_BSS
17551 .align PAGE_SIZE
17552diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17553index 9c3bd4a..e1d9b35 100644
17554--- a/arch/x86/kernel/i386_ksyms_32.c
17555+++ b/arch/x86/kernel/i386_ksyms_32.c
17556@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17557 EXPORT_SYMBOL(cmpxchg8b_emu);
17558 #endif
17559
17560+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17561+
17562 /* Networking helper routines. */
17563 EXPORT_SYMBOL(csum_partial_copy_generic);
17564+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17565+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17566
17567 EXPORT_SYMBOL(__get_user_1);
17568 EXPORT_SYMBOL(__get_user_2);
17569@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17570
17571 EXPORT_SYMBOL(csum_partial);
17572 EXPORT_SYMBOL(empty_zero_page);
17573+
17574+#ifdef CONFIG_PAX_KERNEXEC
17575+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17576+#endif
17577diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17578index df89102..a244320 100644
17579--- a/arch/x86/kernel/i8259.c
17580+++ b/arch/x86/kernel/i8259.c
17581@@ -208,7 +208,7 @@ spurious_8259A_irq:
17582 "spurious 8259A interrupt: IRQ%d.\n", irq);
17583 spurious_irq_mask |= irqmask;
17584 }
17585- atomic_inc(&irq_err_count);
17586+ atomic_inc_unchecked(&irq_err_count);
17587 /*
17588 * Theoretically we do not have to handle this IRQ,
17589 * but in Linux this does not cause problems and is
17590diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17591index 3a54dcb..1c22348 100644
17592--- a/arch/x86/kernel/init_task.c
17593+++ b/arch/x86/kernel/init_task.c
17594@@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17595 * way process stacks are handled. This is done by having a special
17596 * "init_task" linker map entry..
17597 */
17598-union thread_union init_thread_union __init_task_data =
17599- { INIT_THREAD_INFO(init_task) };
17600+union thread_union init_thread_union __init_task_data;
17601
17602 /*
17603 * Initial task structure.
17604@@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17605 * section. Since TSS's are completely CPU-local, we want them
17606 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17607 */
17608-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17609-
17610+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17611+EXPORT_SYMBOL(init_tss);
17612diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17613index 99c4d30..74c84e9 100644
17614--- a/arch/x86/kernel/ioport.c
17615+++ b/arch/x86/kernel/ioport.c
17616@@ -6,6 +6,7 @@
17617 #include <linux/sched.h>
17618 #include <linux/kernel.h>
17619 #include <linux/capability.h>
17620+#include <linux/security.h>
17621 #include <linux/errno.h>
17622 #include <linux/types.h>
17623 #include <linux/ioport.h>
17624@@ -41,6 +42,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17625
17626 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17627 return -EINVAL;
17628+#ifdef CONFIG_GRKERNSEC_IO
17629+ if (turn_on && grsec_disable_privio) {
17630+ gr_handle_ioperm();
17631+ return -EPERM;
17632+ }
17633+#endif
17634 if (turn_on && !capable(CAP_SYS_RAWIO))
17635 return -EPERM;
17636
17637@@ -67,7 +74,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17638 * because the ->io_bitmap_max value must match the bitmap
17639 * contents:
17640 */
17641- tss = &per_cpu(init_tss, get_cpu());
17642+ tss = init_tss + get_cpu();
17643
17644 set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
17645
17646@@ -111,6 +118,12 @@ static int do_iopl(unsigned int level, struct pt_regs *regs)
17647 return -EINVAL;
17648 /* Trying to gain more privileges? */
17649 if (level > old) {
17650+#ifdef CONFIG_GRKERNSEC_IO
17651+ if (grsec_disable_privio) {
17652+ gr_handle_iopl();
17653+ return -EPERM;
17654+ }
17655+#endif
17656 if (!capable(CAP_SYS_RAWIO))
17657 return -EPERM;
17658 }
17659diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17660index 04bbd52..83a07d9 100644
17661--- a/arch/x86/kernel/irq.c
17662+++ b/arch/x86/kernel/irq.c
17663@@ -15,7 +15,7 @@
17664 #include <asm/mce.h>
17665 #include <asm/hw_irq.h>
17666
17667-atomic_t irq_err_count;
17668+atomic_unchecked_t irq_err_count;
17669
17670 /* Function pointer for generic interrupt vector handling */
17671 void (*generic_interrupt_extension)(void) = NULL;
17672@@ -114,9 +114,9 @@ static int show_other_interrupts(struct seq_file *p, int prec)
17673 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17674 seq_printf(p, " Machine check polls\n");
17675 #endif
17676- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17677+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17678 #if defined(CONFIG_X86_IO_APIC)
17679- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17680+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17681 #endif
17682 return 0;
17683 }
17684@@ -209,10 +209,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17685
17686 u64 arch_irq_stat(void)
17687 {
17688- u64 sum = atomic_read(&irq_err_count);
17689+ u64 sum = atomic_read_unchecked(&irq_err_count);
17690
17691 #ifdef CONFIG_X86_IO_APIC
17692- sum += atomic_read(&irq_mis_count);
17693+ sum += atomic_read_unchecked(&irq_mis_count);
17694 #endif
17695 return sum;
17696 }
17697diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17698index 7d35d0f..03f1d52 100644
17699--- a/arch/x86/kernel/irq_32.c
17700+++ b/arch/x86/kernel/irq_32.c
17701@@ -35,7 +35,7 @@ static int check_stack_overflow(void)
17702 __asm__ __volatile__("andl %%esp,%0" :
17703 "=r" (sp) : "0" (THREAD_SIZE - 1));
17704
17705- return sp < (sizeof(struct thread_info) + STACK_WARN);
17706+ return sp < STACK_WARN;
17707 }
17708
17709 static void print_stack_overflow(void)
17710@@ -54,9 +54,9 @@ static inline void print_stack_overflow(void) { }
17711 * per-CPU IRQ handling contexts (thread information and stack)
17712 */
17713 union irq_ctx {
17714- struct thread_info tinfo;
17715- u32 stack[THREAD_SIZE/sizeof(u32)];
17716-} __attribute__((aligned(PAGE_SIZE)));
17717+ unsigned long previous_esp;
17718+ u32 stack[THREAD_SIZE/sizeof(u32)];
17719+} __attribute__((aligned(THREAD_SIZE)));
17720
17721 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17722 static DEFINE_PER_CPU(union irq_ctx *, softirq_ctx);
17723@@ -78,10 +78,9 @@ static void call_on_stack(void *func, void *stack)
17724 static inline int
17725 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17726 {
17727- union irq_ctx *curctx, *irqctx;
17728+ union irq_ctx *irqctx;
17729 u32 *isp, arg1, arg2;
17730
17731- curctx = (union irq_ctx *) current_thread_info();
17732 irqctx = __get_cpu_var(hardirq_ctx);
17733
17734 /*
17735@@ -90,21 +89,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17736 * handler) we can't do that and just have to keep using the
17737 * current stack (which is the irq stack already after all)
17738 */
17739- if (unlikely(curctx == irqctx))
17740+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17741 return 0;
17742
17743 /* build the stack frame on the IRQ stack */
17744- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17745- irqctx->tinfo.task = curctx->tinfo.task;
17746- irqctx->tinfo.previous_esp = current_stack_pointer;
17747+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17748+ irqctx->previous_esp = current_stack_pointer;
17749
17750- /*
17751- * Copy the softirq bits in preempt_count so that the
17752- * softirq checks work in the hardirq context.
17753- */
17754- irqctx->tinfo.preempt_count =
17755- (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17756- (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17757+#ifdef CONFIG_PAX_MEMORY_UDEREF
17758+ __set_fs(MAKE_MM_SEG(0));
17759+#endif
17760
17761 if (unlikely(overflow))
17762 call_on_stack(print_stack_overflow, isp);
17763@@ -116,6 +110,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17764 : "0" (irq), "1" (desc), "2" (isp),
17765 "D" (desc->handle_irq)
17766 : "memory", "cc", "ecx");
17767+
17768+#ifdef CONFIG_PAX_MEMORY_UDEREF
17769+ __set_fs(current_thread_info()->addr_limit);
17770+#endif
17771+
17772 return 1;
17773 }
17774
17775@@ -124,28 +123,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17776 */
17777 void __cpuinit irq_ctx_init(int cpu)
17778 {
17779- union irq_ctx *irqctx;
17780-
17781 if (per_cpu(hardirq_ctx, cpu))
17782 return;
17783
17784- irqctx = &per_cpu(hardirq_stack, cpu);
17785- irqctx->tinfo.task = NULL;
17786- irqctx->tinfo.exec_domain = NULL;
17787- irqctx->tinfo.cpu = cpu;
17788- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17789- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17790-
17791- per_cpu(hardirq_ctx, cpu) = irqctx;
17792-
17793- irqctx = &per_cpu(softirq_stack, cpu);
17794- irqctx->tinfo.task = NULL;
17795- irqctx->tinfo.exec_domain = NULL;
17796- irqctx->tinfo.cpu = cpu;
17797- irqctx->tinfo.preempt_count = 0;
17798- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17799-
17800- per_cpu(softirq_ctx, cpu) = irqctx;
17801+ per_cpu(hardirq_ctx, cpu) = &per_cpu(hardirq_stack, cpu);
17802+ per_cpu(softirq_ctx, cpu) = &per_cpu(softirq_stack, cpu);
17803
17804 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17805 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17806@@ -159,7 +141,6 @@ void irq_ctx_exit(int cpu)
17807 asmlinkage void do_softirq(void)
17808 {
17809 unsigned long flags;
17810- struct thread_info *curctx;
17811 union irq_ctx *irqctx;
17812 u32 *isp;
17813
17814@@ -169,15 +150,22 @@ asmlinkage void do_softirq(void)
17815 local_irq_save(flags);
17816
17817 if (local_softirq_pending()) {
17818- curctx = current_thread_info();
17819 irqctx = __get_cpu_var(softirq_ctx);
17820- irqctx->tinfo.task = curctx->task;
17821- irqctx->tinfo.previous_esp = current_stack_pointer;
17822+ irqctx->previous_esp = current_stack_pointer;
17823
17824 /* build the stack frame on the softirq stack */
17825- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17826+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17827+
17828+#ifdef CONFIG_PAX_MEMORY_UDEREF
17829+ __set_fs(MAKE_MM_SEG(0));
17830+#endif
17831
17832 call_on_stack(__do_softirq, isp);
17833+
17834+#ifdef CONFIG_PAX_MEMORY_UDEREF
17835+ __set_fs(current_thread_info()->addr_limit);
17836+#endif
17837+
17838 /*
17839 * Shouldnt happen, we returned above if in_interrupt():
17840 */
17841diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17842index 8d82a77..0baf312 100644
17843--- a/arch/x86/kernel/kgdb.c
17844+++ b/arch/x86/kernel/kgdb.c
17845@@ -390,13 +390,13 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17846
17847 /* clear the trace bit */
17848 linux_regs->flags &= ~X86_EFLAGS_TF;
17849- atomic_set(&kgdb_cpu_doing_single_step, -1);
17850+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17851
17852 /* set the trace bit if we're stepping */
17853 if (remcomInBuffer[0] == 's') {
17854 linux_regs->flags |= X86_EFLAGS_TF;
17855 kgdb_single_step = 1;
17856- atomic_set(&kgdb_cpu_doing_single_step,
17857+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17858 raw_smp_processor_id());
17859 }
17860
17861@@ -476,7 +476,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17862 break;
17863
17864 case DIE_DEBUG:
17865- if (atomic_read(&kgdb_cpu_doing_single_step) ==
17866+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) ==
17867 raw_smp_processor_id()) {
17868 if (user_mode(regs))
17869 return single_step_cont(regs, args);
17870@@ -573,7 +573,7 @@ unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
17871 return instruction_pointer(regs);
17872 }
17873
17874-struct kgdb_arch arch_kgdb_ops = {
17875+const struct kgdb_arch arch_kgdb_ops = {
17876 /* Breakpoint instruction: */
17877 .gdb_bpt_instr = { 0xcc },
17878 .flags = KGDB_HW_BREAKPOINT,
17879diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17880index 7a67820..8d15b75 100644
17881--- a/arch/x86/kernel/kprobes.c
17882+++ b/arch/x86/kernel/kprobes.c
17883@@ -168,9 +168,13 @@ static void __kprobes set_jmp_op(void *from, void *to)
17884 char op;
17885 s32 raddr;
17886 } __attribute__((packed)) * jop;
17887- jop = (struct __arch_jmp_op *)from;
17888+
17889+ jop = (struct __arch_jmp_op *)(ktla_ktva(from));
17890+
17891+ pax_open_kernel();
17892 jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
17893 jop->op = RELATIVEJUMP_INSTRUCTION;
17894+ pax_close_kernel();
17895 }
17896
17897 /*
17898@@ -195,7 +199,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17899 kprobe_opcode_t opcode;
17900 kprobe_opcode_t *orig_opcodes = opcodes;
17901
17902- if (search_exception_tables((unsigned long)opcodes))
17903+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17904 return 0; /* Page fault may occur on this address. */
17905
17906 retry:
17907@@ -339,7 +343,9 @@ static void __kprobes fix_riprel(struct kprobe *p)
17908 disp = (u8 *) p->addr + *((s32 *) insn) -
17909 (u8 *) p->ainsn.insn;
17910 BUG_ON((s64) (s32) disp != disp); /* Sanity check. */
17911+ pax_open_kernel();
17912 *(s32 *)insn = (s32) disp;
17913+ pax_close_kernel();
17914 }
17915 }
17916 #endif
17917@@ -347,16 +353,18 @@ static void __kprobes fix_riprel(struct kprobe *p)
17918
17919 static void __kprobes arch_copy_kprobe(struct kprobe *p)
17920 {
17921- memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
17922+ pax_open_kernel();
17923+ memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
17924+ pax_close_kernel();
17925
17926 fix_riprel(p);
17927
17928- if (can_boost(p->addr))
17929+ if (can_boost(ktla_ktva(p->addr)))
17930 p->ainsn.boostable = 0;
17931 else
17932 p->ainsn.boostable = -1;
17933
17934- p->opcode = *p->addr;
17935+ p->opcode = *(ktla_ktva(p->addr));
17936 }
17937
17938 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17939@@ -434,7 +442,7 @@ static void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
17940 if (p->opcode == BREAKPOINT_INSTRUCTION)
17941 regs->ip = (unsigned long)p->addr;
17942 else
17943- regs->ip = (unsigned long)p->ainsn.insn;
17944+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17945 }
17946
17947 void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
17948@@ -455,7 +463,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17949 if (p->ainsn.boostable == 1 && !p->post_handler) {
17950 /* Boost up -- we can execute copied instructions directly */
17951 reset_current_kprobe();
17952- regs->ip = (unsigned long)p->ainsn.insn;
17953+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17954 preempt_enable_no_resched();
17955 return;
17956 }
17957@@ -525,7 +533,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17958 struct kprobe_ctlblk *kcb;
17959
17960 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
17961- if (*addr != BREAKPOINT_INSTRUCTION) {
17962+ if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17963 /*
17964 * The breakpoint instruction was removed right
17965 * after we hit it. Another cpu has removed
17966@@ -637,6 +645,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17967 /* Skip orig_ax, ip, cs */
17968 " addq $24, %rsp\n"
17969 " popfq\n"
17970+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
17971+ " btsq $63,(%rsp)\n"
17972+#endif
17973 #else
17974 " pushf\n"
17975 /*
17976@@ -777,7 +788,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17977 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17978 {
17979 unsigned long *tos = stack_addr(regs);
17980- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17981+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17982 unsigned long orig_ip = (unsigned long)p->addr;
17983 kprobe_opcode_t *insn = p->ainsn.insn;
17984
17985@@ -960,7 +971,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17986 struct die_args *args = data;
17987 int ret = NOTIFY_DONE;
17988
17989- if (args->regs && user_mode_vm(args->regs))
17990+ if (args->regs && user_mode(args->regs))
17991 return ret;
17992
17993 switch (val) {
17994diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
17995index 63b0ec8..6d92227 100644
17996--- a/arch/x86/kernel/kvm.c
17997+++ b/arch/x86/kernel/kvm.c
17998@@ -216,6 +216,7 @@ static void __init paravirt_ops_setup(void)
17999 pv_mmu_ops.set_pud = kvm_set_pud;
18000 #if PAGETABLE_LEVELS == 4
18001 pv_mmu_ops.set_pgd = kvm_set_pgd;
18002+ pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
18003 #endif
18004 #endif
18005 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
18006diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18007index ec6ef60..ab2c824 100644
18008--- a/arch/x86/kernel/ldt.c
18009+++ b/arch/x86/kernel/ldt.c
18010@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18011 if (reload) {
18012 #ifdef CONFIG_SMP
18013 preempt_disable();
18014- load_LDT(pc);
18015+ load_LDT_nolock(pc);
18016 if (!cpumask_equal(mm_cpumask(current->mm),
18017 cpumask_of(smp_processor_id())))
18018 smp_call_function(flush_ldt, current->mm, 1);
18019 preempt_enable();
18020 #else
18021- load_LDT(pc);
18022+ load_LDT_nolock(pc);
18023 #endif
18024 }
18025 if (oldsize) {
18026@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18027 return err;
18028
18029 for (i = 0; i < old->size; i++)
18030- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18031+ write_ldt_entry(new->ldt, i, old->ldt + i);
18032 return 0;
18033 }
18034
18035@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18036 retval = copy_ldt(&mm->context, &old_mm->context);
18037 mutex_unlock(&old_mm->context.lock);
18038 }
18039+
18040+ if (tsk == current) {
18041+ mm->context.vdso = 0;
18042+
18043+#ifdef CONFIG_X86_32
18044+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18045+ mm->context.user_cs_base = 0UL;
18046+ mm->context.user_cs_limit = ~0UL;
18047+
18048+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18049+ cpus_clear(mm->context.cpu_user_cs_mask);
18050+#endif
18051+
18052+#endif
18053+#endif
18054+
18055+ }
18056+
18057 return retval;
18058 }
18059
18060@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18061 }
18062 }
18063
18064+#ifdef CONFIG_PAX_SEGMEXEC
18065+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18066+ error = -EINVAL;
18067+ goto out_unlock;
18068+ }
18069+#endif
18070+
18071 fill_ldt(&ldt, &ldt_info);
18072 if (oldmode)
18073 ldt.avl = 0;
18074diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18075index c1c429d..f02eaf9 100644
18076--- a/arch/x86/kernel/machine_kexec_32.c
18077+++ b/arch/x86/kernel/machine_kexec_32.c
18078@@ -26,7 +26,7 @@
18079 #include <asm/system.h>
18080 #include <asm/cacheflush.h>
18081
18082-static void set_idt(void *newidt, __u16 limit)
18083+static void set_idt(struct desc_struct *newidt, __u16 limit)
18084 {
18085 struct desc_ptr curidt;
18086
18087@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18088 }
18089
18090
18091-static void set_gdt(void *newgdt, __u16 limit)
18092+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18093 {
18094 struct desc_ptr curgdt;
18095
18096@@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
18097 }
18098
18099 control_page = page_address(image->control_code_page);
18100- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18101+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18102
18103 relocate_kernel_ptr = control_page;
18104 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18105diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
18106index 1e47679..e73449d 100644
18107--- a/arch/x86/kernel/microcode_amd.c
18108+++ b/arch/x86/kernel/microcode_amd.c
18109@@ -364,7 +364,7 @@ static void microcode_fini_cpu_amd(int cpu)
18110 uci->mc = NULL;
18111 }
18112
18113-static struct microcode_ops microcode_amd_ops = {
18114+static const struct microcode_ops microcode_amd_ops = {
18115 .request_microcode_user = request_microcode_user,
18116 .request_microcode_fw = request_microcode_fw,
18117 .collect_cpu_info = collect_cpu_info_amd,
18118@@ -372,7 +372,7 @@ static struct microcode_ops microcode_amd_ops = {
18119 .microcode_fini_cpu = microcode_fini_cpu_amd,
18120 };
18121
18122-struct microcode_ops * __init init_amd_microcode(void)
18123+const struct microcode_ops * __init init_amd_microcode(void)
18124 {
18125 return &microcode_amd_ops;
18126 }
18127diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
18128index 378e9a8..b5a6ea9 100644
18129--- a/arch/x86/kernel/microcode_core.c
18130+++ b/arch/x86/kernel/microcode_core.c
18131@@ -90,7 +90,7 @@ MODULE_LICENSE("GPL");
18132
18133 #define MICROCODE_VERSION "2.00"
18134
18135-static struct microcode_ops *microcode_ops;
18136+static const struct microcode_ops *microcode_ops;
18137
18138 /*
18139 * Synchronization.
18140diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18141index 0d334dd..14cedaf 100644
18142--- a/arch/x86/kernel/microcode_intel.c
18143+++ b/arch/x86/kernel/microcode_intel.c
18144@@ -443,13 +443,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18145
18146 static int get_ucode_user(void *to, const void *from, size_t n)
18147 {
18148- return copy_from_user(to, from, n);
18149+ return copy_from_user(to, (const void __force_user *)from, n);
18150 }
18151
18152 static enum ucode_state
18153 request_microcode_user(int cpu, const void __user *buf, size_t size)
18154 {
18155- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18156+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18157 }
18158
18159 static void microcode_fini_cpu(int cpu)
18160@@ -460,7 +460,7 @@ static void microcode_fini_cpu(int cpu)
18161 uci->mc = NULL;
18162 }
18163
18164-static struct microcode_ops microcode_intel_ops = {
18165+static const struct microcode_ops microcode_intel_ops = {
18166 .request_microcode_user = request_microcode_user,
18167 .request_microcode_fw = request_microcode_fw,
18168 .collect_cpu_info = collect_cpu_info,
18169@@ -468,7 +468,7 @@ static struct microcode_ops microcode_intel_ops = {
18170 .microcode_fini_cpu = microcode_fini_cpu,
18171 };
18172
18173-struct microcode_ops * __init init_intel_microcode(void)
18174+const struct microcode_ops * __init init_intel_microcode(void)
18175 {
18176 return &microcode_intel_ops;
18177 }
18178diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18179index 89f386f..9028f51 100644
18180--- a/arch/x86/kernel/module.c
18181+++ b/arch/x86/kernel/module.c
18182@@ -34,7 +34,7 @@
18183 #define DEBUGP(fmt...)
18184 #endif
18185
18186-void *module_alloc(unsigned long size)
18187+static void *__module_alloc(unsigned long size, pgprot_t prot)
18188 {
18189 struct vm_struct *area;
18190
18191@@ -48,8 +48,18 @@ void *module_alloc(unsigned long size)
18192 if (!area)
18193 return NULL;
18194
18195- return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM,
18196- PAGE_KERNEL_EXEC);
18197+ return __vmalloc_area(area, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot);
18198+}
18199+
18200+void *module_alloc(unsigned long size)
18201+{
18202+
18203+#ifdef CONFIG_PAX_KERNEXEC
18204+ return __module_alloc(size, PAGE_KERNEL);
18205+#else
18206+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18207+#endif
18208+
18209 }
18210
18211 /* Free memory returned from module_alloc */
18212@@ -58,6 +68,40 @@ void module_free(struct module *mod, void *module_region)
18213 vfree(module_region);
18214 }
18215
18216+#ifdef CONFIG_PAX_KERNEXEC
18217+#ifdef CONFIG_X86_32
18218+void *module_alloc_exec(unsigned long size)
18219+{
18220+ struct vm_struct *area;
18221+
18222+ if (size == 0)
18223+ return NULL;
18224+
18225+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18226+ return area ? area->addr : NULL;
18227+}
18228+EXPORT_SYMBOL(module_alloc_exec);
18229+
18230+void module_free_exec(struct module *mod, void *module_region)
18231+{
18232+ vunmap(module_region);
18233+}
18234+EXPORT_SYMBOL(module_free_exec);
18235+#else
18236+void module_free_exec(struct module *mod, void *module_region)
18237+{
18238+ module_free(mod, module_region);
18239+}
18240+EXPORT_SYMBOL(module_free_exec);
18241+
18242+void *module_alloc_exec(unsigned long size)
18243+{
18244+ return __module_alloc(size, PAGE_KERNEL_RX);
18245+}
18246+EXPORT_SYMBOL(module_alloc_exec);
18247+#endif
18248+#endif
18249+
18250 /* We don't need anything special. */
18251 int module_frob_arch_sections(Elf_Ehdr *hdr,
18252 Elf_Shdr *sechdrs,
18253@@ -77,14 +121,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18254 unsigned int i;
18255 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18256 Elf32_Sym *sym;
18257- uint32_t *location;
18258+ uint32_t *plocation, location;
18259
18260 DEBUGP("Applying relocate section %u to %u\n", relsec,
18261 sechdrs[relsec].sh_info);
18262 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18263 /* This is where to make the change */
18264- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18265- + rel[i].r_offset;
18266+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18267+ location = (uint32_t)plocation;
18268+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18269+ plocation = ktla_ktva((void *)plocation);
18270 /* This is the symbol it is referring to. Note that all
18271 undefined symbols have been resolved. */
18272 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18273@@ -93,11 +139,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18274 switch (ELF32_R_TYPE(rel[i].r_info)) {
18275 case R_386_32:
18276 /* We add the value into the location given */
18277- *location += sym->st_value;
18278+ pax_open_kernel();
18279+ *plocation += sym->st_value;
18280+ pax_close_kernel();
18281 break;
18282 case R_386_PC32:
18283 /* Add the value, subtract its postition */
18284- *location += sym->st_value - (uint32_t)location;
18285+ pax_open_kernel();
18286+ *plocation += sym->st_value - location;
18287+ pax_close_kernel();
18288 break;
18289 default:
18290 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18291@@ -153,21 +203,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18292 case R_X86_64_NONE:
18293 break;
18294 case R_X86_64_64:
18295+ pax_open_kernel();
18296 *(u64 *)loc = val;
18297+ pax_close_kernel();
18298 break;
18299 case R_X86_64_32:
18300+ pax_open_kernel();
18301 *(u32 *)loc = val;
18302+ pax_close_kernel();
18303 if (val != *(u32 *)loc)
18304 goto overflow;
18305 break;
18306 case R_X86_64_32S:
18307+ pax_open_kernel();
18308 *(s32 *)loc = val;
18309+ pax_close_kernel();
18310 if ((s64)val != *(s32 *)loc)
18311 goto overflow;
18312 break;
18313 case R_X86_64_PC32:
18314 val -= (u64)loc;
18315+ pax_open_kernel();
18316 *(u32 *)loc = val;
18317+ pax_close_kernel();
18318+
18319 #if 0
18320 if ((s64)val != *(s32 *)loc)
18321 goto overflow;
18322diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18323index 3a7c5a4..9191528 100644
18324--- a/arch/x86/kernel/paravirt-spinlocks.c
18325+++ b/arch/x86/kernel/paravirt-spinlocks.c
18326@@ -13,7 +13,7 @@ default_spin_lock_flags(raw_spinlock_t *lock, unsigned long flags)
18327 __raw_spin_lock(lock);
18328 }
18329
18330-struct pv_lock_ops pv_lock_ops = {
18331+struct pv_lock_ops pv_lock_ops __read_only = {
18332 #ifdef CONFIG_SMP
18333 .spin_is_locked = __ticket_spin_is_locked,
18334 .spin_is_contended = __ticket_spin_is_contended,
18335diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18336index 1b1739d..dea6077 100644
18337--- a/arch/x86/kernel/paravirt.c
18338+++ b/arch/x86/kernel/paravirt.c
18339@@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
18340 {
18341 return x;
18342 }
18343+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18344+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18345+#endif
18346
18347 void __init default_banner(void)
18348 {
18349@@ -122,7 +125,7 @@ unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
18350 * corresponding structure. */
18351 static void *get_call_destination(u8 type)
18352 {
18353- struct paravirt_patch_template tmpl = {
18354+ const struct paravirt_patch_template tmpl = {
18355 .pv_init_ops = pv_init_ops,
18356 .pv_time_ops = pv_time_ops,
18357 .pv_cpu_ops = pv_cpu_ops,
18358@@ -133,6 +136,8 @@ static void *get_call_destination(u8 type)
18359 .pv_lock_ops = pv_lock_ops,
18360 #endif
18361 };
18362+
18363+ pax_track_stack();
18364 return *((void **)&tmpl + type);
18365 }
18366
18367@@ -145,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18368 if (opfunc == NULL)
18369 /* If there's no function, patch it with a ud2a (BUG) */
18370 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18371- else if (opfunc == _paravirt_nop)
18372+ else if (opfunc == (void *)_paravirt_nop)
18373 /* If the operation is a nop, then nop the callsite */
18374 ret = paravirt_patch_nop();
18375
18376 /* identity functions just return their single argument */
18377- else if (opfunc == _paravirt_ident_32)
18378+ else if (opfunc == (void *)_paravirt_ident_32)
18379 ret = paravirt_patch_ident_32(insnbuf, len);
18380- else if (opfunc == _paravirt_ident_64)
18381+ else if (opfunc == (void *)_paravirt_ident_64)
18382 ret = paravirt_patch_ident_64(insnbuf, len);
18383+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18384+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18385+ ret = paravirt_patch_ident_64(insnbuf, len);
18386+#endif
18387
18388 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18389 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18390@@ -178,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18391 if (insn_len > len || start == NULL)
18392 insn_len = len;
18393 else
18394- memcpy(insnbuf, start, insn_len);
18395+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18396
18397 return insn_len;
18398 }
18399@@ -294,22 +303,22 @@ void arch_flush_lazy_mmu_mode(void)
18400 preempt_enable();
18401 }
18402
18403-struct pv_info pv_info = {
18404+struct pv_info pv_info __read_only = {
18405 .name = "bare hardware",
18406 .paravirt_enabled = 0,
18407 .kernel_rpl = 0,
18408 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
18409 };
18410
18411-struct pv_init_ops pv_init_ops = {
18412+struct pv_init_ops pv_init_ops __read_only = {
18413 .patch = native_patch,
18414 };
18415
18416-struct pv_time_ops pv_time_ops = {
18417+struct pv_time_ops pv_time_ops __read_only = {
18418 .sched_clock = native_sched_clock,
18419 };
18420
18421-struct pv_irq_ops pv_irq_ops = {
18422+struct pv_irq_ops pv_irq_ops __read_only = {
18423 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18424 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18425 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18426@@ -321,7 +330,7 @@ struct pv_irq_ops pv_irq_ops = {
18427 #endif
18428 };
18429
18430-struct pv_cpu_ops pv_cpu_ops = {
18431+struct pv_cpu_ops pv_cpu_ops __read_only = {
18432 .cpuid = native_cpuid,
18433 .get_debugreg = native_get_debugreg,
18434 .set_debugreg = native_set_debugreg,
18435@@ -382,21 +391,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18436 .end_context_switch = paravirt_nop,
18437 };
18438
18439-struct pv_apic_ops pv_apic_ops = {
18440+struct pv_apic_ops pv_apic_ops __read_only = {
18441 #ifdef CONFIG_X86_LOCAL_APIC
18442 .startup_ipi_hook = paravirt_nop,
18443 #endif
18444 };
18445
18446-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18447+#ifdef CONFIG_X86_32
18448+#ifdef CONFIG_X86_PAE
18449+/* 64-bit pagetable entries */
18450+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18451+#else
18452 /* 32-bit pagetable entries */
18453 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18454+#endif
18455 #else
18456 /* 64-bit pagetable entries */
18457 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18458 #endif
18459
18460-struct pv_mmu_ops pv_mmu_ops = {
18461+struct pv_mmu_ops pv_mmu_ops __read_only = {
18462
18463 .read_cr2 = native_read_cr2,
18464 .write_cr2 = native_write_cr2,
18465@@ -448,6 +462,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18466 .make_pud = PTE_IDENT,
18467
18468 .set_pgd = native_set_pgd,
18469+ .set_pgd_batched = native_set_pgd_batched,
18470 #endif
18471 #endif /* PAGETABLE_LEVELS >= 3 */
18472
18473@@ -467,6 +482,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18474 },
18475
18476 .set_fixmap = native_set_fixmap,
18477+
18478+#ifdef CONFIG_PAX_KERNEXEC
18479+ .pax_open_kernel = native_pax_open_kernel,
18480+ .pax_close_kernel = native_pax_close_kernel,
18481+#endif
18482+
18483 };
18484
18485 EXPORT_SYMBOL_GPL(pv_time_ops);
18486diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
18487index 1a2d4b1..6a0dd55 100644
18488--- a/arch/x86/kernel/pci-calgary_64.c
18489+++ b/arch/x86/kernel/pci-calgary_64.c
18490@@ -477,7 +477,7 @@ static void calgary_free_coherent(struct device *dev, size_t size,
18491 free_pages((unsigned long)vaddr, get_order(size));
18492 }
18493
18494-static struct dma_map_ops calgary_dma_ops = {
18495+static const struct dma_map_ops calgary_dma_ops = {
18496 .alloc_coherent = calgary_alloc_coherent,
18497 .free_coherent = calgary_free_coherent,
18498 .map_sg = calgary_map_sg,
18499diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
18500index 6ac3931..42b4414 100644
18501--- a/arch/x86/kernel/pci-dma.c
18502+++ b/arch/x86/kernel/pci-dma.c
18503@@ -14,7 +14,7 @@
18504
18505 static int forbid_dac __read_mostly;
18506
18507-struct dma_map_ops *dma_ops;
18508+const struct dma_map_ops *dma_ops;
18509 EXPORT_SYMBOL(dma_ops);
18510
18511 static int iommu_sac_force __read_mostly;
18512@@ -243,7 +243,7 @@ early_param("iommu", iommu_setup);
18513
18514 int dma_supported(struct device *dev, u64 mask)
18515 {
18516- struct dma_map_ops *ops = get_dma_ops(dev);
18517+ const struct dma_map_ops *ops = get_dma_ops(dev);
18518
18519 #ifdef CONFIG_PCI
18520 if (mask > 0xffffffff && forbid_dac > 0) {
18521diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c
18522index 1c76691..e3632db 100644
18523--- a/arch/x86/kernel/pci-gart_64.c
18524+++ b/arch/x86/kernel/pci-gart_64.c
18525@@ -682,7 +682,7 @@ static __init int init_k8_gatt(struct agp_kern_info *info)
18526 return -1;
18527 }
18528
18529-static struct dma_map_ops gart_dma_ops = {
18530+static const struct dma_map_ops gart_dma_ops = {
18531 .map_sg = gart_map_sg,
18532 .unmap_sg = gart_unmap_sg,
18533 .map_page = gart_map_page,
18534diff --git a/arch/x86/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu.c
18535index a3933d4..c898869 100644
18536--- a/arch/x86/kernel/pci-nommu.c
18537+++ b/arch/x86/kernel/pci-nommu.c
18538@@ -94,7 +94,7 @@ static void nommu_sync_sg_for_device(struct device *dev,
18539 flush_write_buffers();
18540 }
18541
18542-struct dma_map_ops nommu_dma_ops = {
18543+const struct dma_map_ops nommu_dma_ops = {
18544 .alloc_coherent = dma_generic_alloc_coherent,
18545 .free_coherent = nommu_free_coherent,
18546 .map_sg = nommu_map_sg,
18547diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
18548index aaa6b78..4de1881 100644
18549--- a/arch/x86/kernel/pci-swiotlb.c
18550+++ b/arch/x86/kernel/pci-swiotlb.c
18551@@ -25,7 +25,7 @@ static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
18552 return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
18553 }
18554
18555-static struct dma_map_ops swiotlb_dma_ops = {
18556+static const struct dma_map_ops swiotlb_dma_ops = {
18557 .mapping_error = swiotlb_dma_mapping_error,
18558 .alloc_coherent = x86_swiotlb_alloc_coherent,
18559 .free_coherent = swiotlb_free_coherent,
18560diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18561index fc6c84d..0312ca2 100644
18562--- a/arch/x86/kernel/process.c
18563+++ b/arch/x86/kernel/process.c
18564@@ -51,16 +51,33 @@ void free_thread_xstate(struct task_struct *tsk)
18565
18566 void free_thread_info(struct thread_info *ti)
18567 {
18568- free_thread_xstate(ti->task);
18569 free_pages((unsigned long)ti, get_order(THREAD_SIZE));
18570 }
18571
18572+static struct kmem_cache *task_struct_cachep;
18573+
18574 void arch_task_cache_init(void)
18575 {
18576- task_xstate_cachep =
18577- kmem_cache_create("task_xstate", xstate_size,
18578+ /* create a slab on which task_structs can be allocated */
18579+ task_struct_cachep =
18580+ kmem_cache_create("task_struct", sizeof(struct task_struct),
18581+ ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18582+
18583+ task_xstate_cachep =
18584+ kmem_cache_create("task_xstate", xstate_size,
18585 __alignof__(union thread_xstate),
18586- SLAB_PANIC | SLAB_NOTRACK, NULL);
18587+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18588+}
18589+
18590+struct task_struct *alloc_task_struct(void)
18591+{
18592+ return kmem_cache_alloc(task_struct_cachep, GFP_KERNEL);
18593+}
18594+
18595+void free_task_struct(struct task_struct *task)
18596+{
18597+ free_thread_xstate(task);
18598+ kmem_cache_free(task_struct_cachep, task);
18599 }
18600
18601 /*
18602@@ -73,7 +90,7 @@ void exit_thread(void)
18603 unsigned long *bp = t->io_bitmap_ptr;
18604
18605 if (bp) {
18606- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18607+ struct tss_struct *tss = init_tss + get_cpu();
18608
18609 t->io_bitmap_ptr = NULL;
18610 clear_thread_flag(TIF_IO_BITMAP);
18611@@ -93,6 +110,9 @@ void flush_thread(void)
18612
18613 clear_tsk_thread_flag(tsk, TIF_DEBUG);
18614
18615+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18616+ loadsegment(gs, 0);
18617+#endif
18618 tsk->thread.debugreg0 = 0;
18619 tsk->thread.debugreg1 = 0;
18620 tsk->thread.debugreg2 = 0;
18621@@ -307,7 +327,7 @@ void default_idle(void)
18622 EXPORT_SYMBOL(default_idle);
18623 #endif
18624
18625-void stop_this_cpu(void *dummy)
18626+__noreturn void stop_this_cpu(void *dummy)
18627 {
18628 local_irq_disable();
18629 /*
18630@@ -568,16 +588,38 @@ static int __init idle_setup(char *str)
18631 }
18632 early_param("idle", idle_setup);
18633
18634-unsigned long arch_align_stack(unsigned long sp)
18635+#ifdef CONFIG_PAX_RANDKSTACK
18636+void pax_randomize_kstack(struct pt_regs *regs)
18637 {
18638- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18639- sp -= get_random_int() % 8192;
18640- return sp & ~0xf;
18641-}
18642+ struct thread_struct *thread = &current->thread;
18643+ unsigned long time;
18644
18645-unsigned long arch_randomize_brk(struct mm_struct *mm)
18646-{
18647- unsigned long range_end = mm->brk + 0x02000000;
18648- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18649+ if (!randomize_va_space)
18650+ return;
18651+
18652+ if (v8086_mode(regs))
18653+ return;
18654+
18655+ rdtscl(time);
18656+
18657+ /* P4 seems to return a 0 LSB, ignore it */
18658+#ifdef CONFIG_MPENTIUM4
18659+ time &= 0x3EUL;
18660+ time <<= 2;
18661+#elif defined(CONFIG_X86_64)
18662+ time &= 0xFUL;
18663+ time <<= 4;
18664+#else
18665+ time &= 0x1FUL;
18666+ time <<= 3;
18667+#endif
18668+
18669+ thread->sp0 ^= time;
18670+ load_sp0(init_tss + smp_processor_id(), thread);
18671+
18672+#ifdef CONFIG_X86_64
18673+ percpu_write(kernel_stack, thread->sp0);
18674+#endif
18675 }
18676+#endif
18677
18678diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18679index c40c432..6e1df72 100644
18680--- a/arch/x86/kernel/process_32.c
18681+++ b/arch/x86/kernel/process_32.c
18682@@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18683 unsigned long thread_saved_pc(struct task_struct *tsk)
18684 {
18685 return ((unsigned long *)tsk->thread.sp)[3];
18686+//XXX return tsk->thread.eip;
18687 }
18688
18689 #ifndef CONFIG_SMP
18690@@ -129,15 +130,14 @@ void __show_regs(struct pt_regs *regs, int all)
18691 unsigned short ss, gs;
18692 const char *board;
18693
18694- if (user_mode_vm(regs)) {
18695+ if (user_mode(regs)) {
18696 sp = regs->sp;
18697 ss = regs->ss & 0xffff;
18698- gs = get_user_gs(regs);
18699 } else {
18700 sp = (unsigned long) (&regs->sp);
18701 savesegment(ss, ss);
18702- savesegment(gs, gs);
18703 }
18704+ gs = get_user_gs(regs);
18705
18706 printk("\n");
18707
18708@@ -210,10 +210,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18709 regs.bx = (unsigned long) fn;
18710 regs.dx = (unsigned long) arg;
18711
18712- regs.ds = __USER_DS;
18713- regs.es = __USER_DS;
18714+ regs.ds = __KERNEL_DS;
18715+ regs.es = __KERNEL_DS;
18716 regs.fs = __KERNEL_PERCPU;
18717- regs.gs = __KERNEL_STACK_CANARY;
18718+ savesegment(gs, regs.gs);
18719 regs.orig_ax = -1;
18720 regs.ip = (unsigned long) kernel_thread_helper;
18721 regs.cs = __KERNEL_CS | get_kernel_rpl();
18722@@ -247,13 +247,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18723 struct task_struct *tsk;
18724 int err;
18725
18726- childregs = task_pt_regs(p);
18727+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18728 *childregs = *regs;
18729 childregs->ax = 0;
18730 childregs->sp = sp;
18731
18732 p->thread.sp = (unsigned long) childregs;
18733 p->thread.sp0 = (unsigned long) (childregs+1);
18734+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18735
18736 p->thread.ip = (unsigned long) ret_from_fork;
18737
18738@@ -345,7 +346,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18739 struct thread_struct *prev = &prev_p->thread,
18740 *next = &next_p->thread;
18741 int cpu = smp_processor_id();
18742- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18743+ struct tss_struct *tss = init_tss + cpu;
18744 bool preload_fpu;
18745
18746 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18747@@ -380,6 +381,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18748 */
18749 lazy_save_gs(prev->gs);
18750
18751+#ifdef CONFIG_PAX_MEMORY_UDEREF
18752+ __set_fs(task_thread_info(next_p)->addr_limit);
18753+#endif
18754+
18755 /*
18756 * Load the per-thread Thread-Local Storage descriptor.
18757 */
18758@@ -415,6 +420,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18759 */
18760 arch_end_context_switch(next_p);
18761
18762+ percpu_write(current_task, next_p);
18763+ percpu_write(current_tinfo, &next_p->tinfo);
18764+
18765 if (preload_fpu)
18766 __math_state_restore();
18767
18768@@ -424,8 +432,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18769 if (prev->gs | next->gs)
18770 lazy_load_gs(next->gs);
18771
18772- percpu_write(current_task, next_p);
18773-
18774 return prev_p;
18775 }
18776
18777@@ -495,4 +501,3 @@ unsigned long get_wchan(struct task_struct *p)
18778 } while (count++ < 16);
18779 return 0;
18780 }
18781-
18782diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18783index 39493bc..196816d 100644
18784--- a/arch/x86/kernel/process_64.c
18785+++ b/arch/x86/kernel/process_64.c
18786@@ -91,7 +91,7 @@ static void __exit_idle(void)
18787 void exit_idle(void)
18788 {
18789 /* idle loop has pid 0 */
18790- if (current->pid)
18791+ if (task_pid_nr(current))
18792 return;
18793 __exit_idle();
18794 }
18795@@ -170,7 +170,7 @@ void __show_regs(struct pt_regs *regs, int all)
18796 if (!board)
18797 board = "";
18798 printk(KERN_INFO "Pid: %d, comm: %.20s %s %s %.*s %s\n",
18799- current->pid, current->comm, print_tainted(),
18800+ task_pid_nr(current), current->comm, print_tainted(),
18801 init_utsname()->release,
18802 (int)strcspn(init_utsname()->version, " "),
18803 init_utsname()->version, board);
18804@@ -280,8 +280,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18805 struct pt_regs *childregs;
18806 struct task_struct *me = current;
18807
18808- childregs = ((struct pt_regs *)
18809- (THREAD_SIZE + task_stack_page(p))) - 1;
18810+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18811 *childregs = *regs;
18812
18813 childregs->ax = 0;
18814@@ -292,6 +291,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18815 p->thread.sp = (unsigned long) childregs;
18816 p->thread.sp0 = (unsigned long) (childregs+1);
18817 p->thread.usersp = me->thread.usersp;
18818+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18819
18820 set_tsk_thread_flag(p, TIF_FORK);
18821
18822@@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18823 struct thread_struct *prev = &prev_p->thread;
18824 struct thread_struct *next = &next_p->thread;
18825 int cpu = smp_processor_id();
18826- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18827+ struct tss_struct *tss = init_tss + cpu;
18828 unsigned fsindex, gsindex;
18829 bool preload_fpu;
18830
18831@@ -475,10 +475,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18832 prev->usersp = percpu_read(old_rsp);
18833 percpu_write(old_rsp, next->usersp);
18834 percpu_write(current_task, next_p);
18835+ percpu_write(current_tinfo, &next_p->tinfo);
18836
18837- percpu_write(kernel_stack,
18838- (unsigned long)task_stack_page(next_p) +
18839- THREAD_SIZE - KERNEL_STACK_OFFSET);
18840+ percpu_write(kernel_stack, next->sp0);
18841
18842 /*
18843 * Now maybe reload the debug registers and handle I/O bitmaps
18844@@ -559,12 +558,11 @@ unsigned long get_wchan(struct task_struct *p)
18845 if (!p || p == current || p->state == TASK_RUNNING)
18846 return 0;
18847 stack = (unsigned long)task_stack_page(p);
18848- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18849+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18850 return 0;
18851 fp = *(u64 *)(p->thread.sp);
18852 do {
18853- if (fp < (unsigned long)stack ||
18854- fp >= (unsigned long)stack+THREAD_SIZE)
18855+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18856 return 0;
18857 ip = *(u64 *)(fp+8);
18858 if (!in_sched_functions(ip))
18859diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18860index c06acdd..3f5fff5 100644
18861--- a/arch/x86/kernel/ptrace.c
18862+++ b/arch/x86/kernel/ptrace.c
18863@@ -925,7 +925,7 @@ static const struct user_regset_view user_x86_32_view; /* Initialized below. */
18864 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18865 {
18866 int ret;
18867- unsigned long __user *datap = (unsigned long __user *)data;
18868+ unsigned long __user *datap = (__force unsigned long __user *)data;
18869
18870 switch (request) {
18871 /* read the word at location addr in the USER area. */
18872@@ -1012,14 +1012,14 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18873 if (addr < 0)
18874 return -EIO;
18875 ret = do_get_thread_area(child, addr,
18876- (struct user_desc __user *) data);
18877+ (__force struct user_desc __user *) data);
18878 break;
18879
18880 case PTRACE_SET_THREAD_AREA:
18881 if (addr < 0)
18882 return -EIO;
18883 ret = do_set_thread_area(child, addr,
18884- (struct user_desc __user *) data, 0);
18885+ (__force struct user_desc __user *) data, 0);
18886 break;
18887 #endif
18888
18889@@ -1038,12 +1038,12 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18890 #ifdef CONFIG_X86_PTRACE_BTS
18891 case PTRACE_BTS_CONFIG:
18892 ret = ptrace_bts_config
18893- (child, data, (struct ptrace_bts_config __user *)addr);
18894+ (child, data, (__force struct ptrace_bts_config __user *)addr);
18895 break;
18896
18897 case PTRACE_BTS_STATUS:
18898 ret = ptrace_bts_status
18899- (child, data, (struct ptrace_bts_config __user *)addr);
18900+ (child, data, (__force struct ptrace_bts_config __user *)addr);
18901 break;
18902
18903 case PTRACE_BTS_SIZE:
18904@@ -1052,7 +1052,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18905
18906 case PTRACE_BTS_GET:
18907 ret = ptrace_bts_read_record
18908- (child, data, (struct bts_struct __user *) addr);
18909+ (child, data, (__force struct bts_struct __user *) addr);
18910 break;
18911
18912 case PTRACE_BTS_CLEAR:
18913@@ -1061,7 +1061,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
18914
18915 case PTRACE_BTS_DRAIN:
18916 ret = ptrace_bts_drain
18917- (child, data, (struct bts_struct __user *) addr);
18918+ (child, data, (__force struct bts_struct __user *) addr);
18919 break;
18920 #endif /* CONFIG_X86_PTRACE_BTS */
18921
18922@@ -1450,7 +1450,7 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18923 info.si_code = si_code;
18924
18925 /* User-mode ip? */
18926- info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
18927+ info.si_addr = user_mode(regs) ? (__force void __user *) regs->ip : NULL;
18928
18929 /* Send us the fake SIGTRAP */
18930 force_sig_info(SIGTRAP, &info, tsk);
18931@@ -1469,7 +1469,7 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18932 * We must return the syscall number to actually look up in the table.
18933 * This can be -1L to skip running any syscall at all.
18934 */
18935-asmregparm long syscall_trace_enter(struct pt_regs *regs)
18936+long syscall_trace_enter(struct pt_regs *regs)
18937 {
18938 long ret = 0;
18939
18940@@ -1514,7 +1514,7 @@ asmregparm long syscall_trace_enter(struct pt_regs *regs)
18941 return ret ?: regs->orig_ax;
18942 }
18943
18944-asmregparm void syscall_trace_leave(struct pt_regs *regs)
18945+void syscall_trace_leave(struct pt_regs *regs)
18946 {
18947 if (unlikely(current->audit_context))
18948 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
18949diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18950index cf98100..e76e03d 100644
18951--- a/arch/x86/kernel/reboot.c
18952+++ b/arch/x86/kernel/reboot.c
18953@@ -33,7 +33,7 @@ void (*pm_power_off)(void);
18954 EXPORT_SYMBOL(pm_power_off);
18955
18956 static const struct desc_ptr no_idt = {};
18957-static int reboot_mode;
18958+static unsigned short reboot_mode;
18959 enum reboot_type reboot_type = BOOT_KBD;
18960 int reboot_force;
18961
18962@@ -292,12 +292,12 @@ core_initcall(reboot_init);
18963 controller to pulse the CPU reset line, which is more thorough, but
18964 doesn't work with at least one type of 486 motherboard. It is easy
18965 to stop this code working; hence the copious comments. */
18966-static const unsigned long long
18967-real_mode_gdt_entries [3] =
18968+static struct desc_struct
18969+real_mode_gdt_entries [3] __read_only =
18970 {
18971- 0x0000000000000000ULL, /* Null descriptor */
18972- 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
18973- 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
18974+ GDT_ENTRY_INIT(0, 0, 0), /* Null descriptor */
18975+ GDT_ENTRY_INIT(0x9b, 0, 0xffff), /* 16-bit real-mode 64k code at 0x00000000 */
18976+ GDT_ENTRY_INIT(0x93, 0x100, 0xffff) /* 16-bit real-mode 64k data at 0x00000100 */
18977 };
18978
18979 static const struct desc_ptr
18980@@ -346,7 +346,7 @@ static const unsigned char jump_to_bios [] =
18981 * specified by the code and length parameters.
18982 * We assume that length will aways be less that 100!
18983 */
18984-void machine_real_restart(const unsigned char *code, int length)
18985+__noreturn void machine_real_restart(const unsigned char *code, unsigned int length)
18986 {
18987 local_irq_disable();
18988
18989@@ -366,8 +366,8 @@ void machine_real_restart(const unsigned char *code, int length)
18990 /* Remap the kernel at virtual address zero, as well as offset zero
18991 from the kernel segment. This assumes the kernel segment starts at
18992 virtual address PAGE_OFFSET. */
18993- memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18994- sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
18995+ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
18996+ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
18997
18998 /*
18999 * Use `swapper_pg_dir' as our page directory.
19000@@ -379,16 +379,15 @@ void machine_real_restart(const unsigned char *code, int length)
19001 boot)". This seems like a fairly standard thing that gets set by
19002 REBOOT.COM programs, and the previous reset routine did this
19003 too. */
19004- *((unsigned short *)0x472) = reboot_mode;
19005+ *(unsigned short *)(__va(0x472)) = reboot_mode;
19006
19007 /* For the switch to real mode, copy some code to low memory. It has
19008 to be in the first 64k because it is running in 16-bit mode, and it
19009 has to have the same physical and virtual address, because it turns
19010 off paging. Copy it near the end of the first page, out of the way
19011 of BIOS variables. */
19012- memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
19013- real_mode_switch, sizeof (real_mode_switch));
19014- memcpy((void *)(0x1000 - 100), code, length);
19015+ memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
19016+ memcpy(__va(0x1000 - 100), code, length);
19017
19018 /* Set up the IDT for real mode. */
19019 load_idt(&real_mode_idt);
19020@@ -416,6 +415,7 @@ void machine_real_restart(const unsigned char *code, int length)
19021 __asm__ __volatile__ ("ljmp $0x0008,%0"
19022 :
19023 : "i" ((void *)(0x1000 - sizeof (real_mode_switch) - 100)));
19024+ do { } while (1);
19025 }
19026 #ifdef CONFIG_APM_MODULE
19027 EXPORT_SYMBOL(machine_real_restart);
19028@@ -544,7 +544,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
19029 {
19030 }
19031
19032-static void native_machine_emergency_restart(void)
19033+__noreturn static void native_machine_emergency_restart(void)
19034 {
19035 int i;
19036
19037@@ -659,13 +659,13 @@ void native_machine_shutdown(void)
19038 #endif
19039 }
19040
19041-static void __machine_emergency_restart(int emergency)
19042+static __noreturn void __machine_emergency_restart(int emergency)
19043 {
19044 reboot_emergency = emergency;
19045 machine_ops.emergency_restart();
19046 }
19047
19048-static void native_machine_restart(char *__unused)
19049+static __noreturn void native_machine_restart(char *__unused)
19050 {
19051 printk("machine restart\n");
19052
19053@@ -674,7 +674,7 @@ static void native_machine_restart(char *__unused)
19054 __machine_emergency_restart(0);
19055 }
19056
19057-static void native_machine_halt(void)
19058+static __noreturn void native_machine_halt(void)
19059 {
19060 /* stop other cpus and apics */
19061 machine_shutdown();
19062@@ -685,7 +685,7 @@ static void native_machine_halt(void)
19063 stop_this_cpu(NULL);
19064 }
19065
19066-static void native_machine_power_off(void)
19067+__noreturn static void native_machine_power_off(void)
19068 {
19069 if (pm_power_off) {
19070 if (!reboot_force)
19071@@ -694,6 +694,7 @@ static void native_machine_power_off(void)
19072 }
19073 /* a fallback in case there is no PM info available */
19074 tboot_shutdown(TB_SHUTDOWN_HALT);
19075+ do { } while (1);
19076 }
19077
19078 struct machine_ops machine_ops = {
19079diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
19080index 7a6f3b3..976a959 100644
19081--- a/arch/x86/kernel/relocate_kernel_64.S
19082+++ b/arch/x86/kernel/relocate_kernel_64.S
19083@@ -11,6 +11,7 @@
19084 #include <asm/kexec.h>
19085 #include <asm/processor-flags.h>
19086 #include <asm/pgtable_types.h>
19087+#include <asm/alternative-asm.h>
19088
19089 /*
19090 * Must be relocatable PIC code callable as a C function
19091@@ -167,6 +168,7 @@ identity_mapped:
19092 xorq %r14, %r14
19093 xorq %r15, %r15
19094
19095+ pax_force_retaddr 0, 1
19096 ret
19097
19098 1:
19099diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19100index 5449a26..0b6c759 100644
19101--- a/arch/x86/kernel/setup.c
19102+++ b/arch/x86/kernel/setup.c
19103@@ -783,14 +783,14 @@ void __init setup_arch(char **cmdline_p)
19104
19105 if (!boot_params.hdr.root_flags)
19106 root_mountflags &= ~MS_RDONLY;
19107- init_mm.start_code = (unsigned long) _text;
19108- init_mm.end_code = (unsigned long) _etext;
19109+ init_mm.start_code = ktla_ktva((unsigned long) _text);
19110+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
19111 init_mm.end_data = (unsigned long) _edata;
19112 init_mm.brk = _brk_end;
19113
19114- code_resource.start = virt_to_phys(_text);
19115- code_resource.end = virt_to_phys(_etext)-1;
19116- data_resource.start = virt_to_phys(_etext);
19117+ code_resource.start = virt_to_phys(ktla_ktva(_text));
19118+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19119+ data_resource.start = virt_to_phys(_sdata);
19120 data_resource.end = virt_to_phys(_edata)-1;
19121 bss_resource.start = virt_to_phys(&__bss_start);
19122 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19123diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19124index d559af9..524c6ad 100644
19125--- a/arch/x86/kernel/setup_percpu.c
19126+++ b/arch/x86/kernel/setup_percpu.c
19127@@ -25,19 +25,17 @@
19128 # define DBG(x...)
19129 #endif
19130
19131-DEFINE_PER_CPU(int, cpu_number);
19132+#ifdef CONFIG_SMP
19133+DEFINE_PER_CPU(unsigned int, cpu_number);
19134 EXPORT_PER_CPU_SYMBOL(cpu_number);
19135+#endif
19136
19137-#ifdef CONFIG_X86_64
19138 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19139-#else
19140-#define BOOT_PERCPU_OFFSET 0
19141-#endif
19142
19143 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19144 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19145
19146-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19147+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19148 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19149 };
19150 EXPORT_SYMBOL(__per_cpu_offset);
19151@@ -159,10 +157,10 @@ static inline void setup_percpu_segment(int cpu)
19152 {
19153 #ifdef CONFIG_X86_32
19154 struct desc_struct gdt;
19155+ unsigned long base = per_cpu_offset(cpu);
19156
19157- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19158- 0x2 | DESCTYPE_S, 0x8);
19159- gdt.s = 1;
19160+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19161+ 0x83 | DESCTYPE_S, 0xC);
19162 write_gdt_entry(get_cpu_gdt_table(cpu),
19163 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19164 #endif
19165@@ -212,6 +210,11 @@ void __init setup_per_cpu_areas(void)
19166 /* alrighty, percpu areas up and running */
19167 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19168 for_each_possible_cpu(cpu) {
19169+#ifdef CONFIG_CC_STACKPROTECTOR
19170+#ifdef CONFIG_X86_32
19171+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19172+#endif
19173+#endif
19174 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19175 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19176 per_cpu(cpu_number, cpu) = cpu;
19177@@ -239,6 +242,12 @@ void __init setup_per_cpu_areas(void)
19178 early_per_cpu_map(x86_cpu_to_node_map, cpu);
19179 #endif
19180 #endif
19181+#ifdef CONFIG_CC_STACKPROTECTOR
19182+#ifdef CONFIG_X86_32
19183+ if (!cpu)
19184+ per_cpu(stack_canary.canary, cpu) = canary;
19185+#endif
19186+#endif
19187 /*
19188 * Up to this point, the boot CPU has been using .data.init
19189 * area. Reload any changed state for the boot CPU.
19190diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19191index 6a44a76..a9287a1 100644
19192--- a/arch/x86/kernel/signal.c
19193+++ b/arch/x86/kernel/signal.c
19194@@ -197,7 +197,7 @@ static unsigned long align_sigframe(unsigned long sp)
19195 * Align the stack pointer according to the i386 ABI,
19196 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19197 */
19198- sp = ((sp + 4) & -16ul) - 4;
19199+ sp = ((sp - 12) & -16ul) - 4;
19200 #else /* !CONFIG_X86_32 */
19201 sp = round_down(sp, 16) - 8;
19202 #endif
19203@@ -248,11 +248,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19204 * Return an always-bogus address instead so we will die with SIGSEGV.
19205 */
19206 if (onsigstack && !likely(on_sig_stack(sp)))
19207- return (void __user *)-1L;
19208+ return (__force void __user *)-1L;
19209
19210 /* save i387 state */
19211 if (used_math() && save_i387_xstate(*fpstate) < 0)
19212- return (void __user *)-1L;
19213+ return (__force void __user *)-1L;
19214
19215 return (void __user *)sp;
19216 }
19217@@ -307,9 +307,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19218 }
19219
19220 if (current->mm->context.vdso)
19221- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19222+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19223 else
19224- restorer = &frame->retcode;
19225+ restorer = (void __user *)&frame->retcode;
19226 if (ka->sa.sa_flags & SA_RESTORER)
19227 restorer = ka->sa.sa_restorer;
19228
19229@@ -323,7 +323,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19230 * reasons and because gdb uses it as a signature to notice
19231 * signal handler stack frames.
19232 */
19233- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19234+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19235
19236 if (err)
19237 return -EFAULT;
19238@@ -377,7 +377,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19239 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19240
19241 /* Set up to return from userspace. */
19242- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19243+ if (current->mm->context.vdso)
19244+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19245+ else
19246+ restorer = (void __user *)&frame->retcode;
19247 if (ka->sa.sa_flags & SA_RESTORER)
19248 restorer = ka->sa.sa_restorer;
19249 put_user_ex(restorer, &frame->pretcode);
19250@@ -389,7 +392,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19251 * reasons and because gdb uses it as a signature to notice
19252 * signal handler stack frames.
19253 */
19254- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19255+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19256 } put_user_catch(err);
19257
19258 if (err)
19259@@ -782,6 +785,8 @@ static void do_signal(struct pt_regs *regs)
19260 int signr;
19261 sigset_t *oldset;
19262
19263+ pax_track_stack();
19264+
19265 /*
19266 * We want the common case to go fast, which is why we may in certain
19267 * cases get here from kernel mode. Just return without doing anything
19268@@ -789,7 +794,7 @@ static void do_signal(struct pt_regs *regs)
19269 * X86_32: vm86 regs switched out by assembly code before reaching
19270 * here, so testing against kernel CS suffices.
19271 */
19272- if (!user_mode(regs))
19273+ if (!user_mode_novm(regs))
19274 return;
19275
19276 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
19277diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19278index 7e8e905..64d5c32 100644
19279--- a/arch/x86/kernel/smpboot.c
19280+++ b/arch/x86/kernel/smpboot.c
19281@@ -94,14 +94,14 @@ static DEFINE_PER_CPU(struct task_struct *, idle_thread_array);
19282 */
19283 static DEFINE_MUTEX(x86_cpu_hotplug_driver_mutex);
19284
19285-void cpu_hotplug_driver_lock()
19286+void cpu_hotplug_driver_lock(void)
19287 {
19288- mutex_lock(&x86_cpu_hotplug_driver_mutex);
19289+ mutex_lock(&x86_cpu_hotplug_driver_mutex);
19290 }
19291
19292-void cpu_hotplug_driver_unlock()
19293+void cpu_hotplug_driver_unlock(void)
19294 {
19295- mutex_unlock(&x86_cpu_hotplug_driver_mutex);
19296+ mutex_unlock(&x86_cpu_hotplug_driver_mutex);
19297 }
19298
19299 ssize_t arch_cpu_probe(const char *buf, size_t count) { return -1; }
19300@@ -625,7 +625,7 @@ wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip)
19301 * target processor state.
19302 */
19303 startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
19304- (unsigned long)stack_start.sp);
19305+ stack_start);
19306
19307 /*
19308 * Run STARTUP IPI loop.
19309@@ -743,6 +743,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19310 set_idle_for_cpu(cpu, c_idle.idle);
19311 do_rest:
19312 per_cpu(current_task, cpu) = c_idle.idle;
19313+ per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19314 #ifdef CONFIG_X86_32
19315 /* Stack for startup_32 can be just as for start_secondary onwards */
19316 irq_ctx_init(cpu);
19317@@ -750,13 +751,15 @@ do_rest:
19318 #else
19319 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19320 initial_gs = per_cpu_offset(cpu);
19321- per_cpu(kernel_stack, cpu) =
19322- (unsigned long)task_stack_page(c_idle.idle) -
19323- KERNEL_STACK_OFFSET + THREAD_SIZE;
19324+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19325 #endif
19326+
19327+ pax_open_kernel();
19328 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19329+ pax_close_kernel();
19330+
19331 initial_code = (unsigned long)start_secondary;
19332- stack_start.sp = (void *) c_idle.idle->thread.sp;
19333+ stack_start = c_idle.idle->thread.sp;
19334
19335 /* start_ip had better be page-aligned! */
19336 start_ip = setup_trampoline();
19337@@ -891,6 +894,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19338
19339 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19340
19341+#ifdef CONFIG_PAX_PER_CPU_PGD
19342+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19343+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19344+ KERNEL_PGD_PTRS);
19345+#endif
19346+
19347 err = do_boot_cpu(apicid, cpu);
19348
19349 if (err) {
19350diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19351index 3149032..14f1053 100644
19352--- a/arch/x86/kernel/step.c
19353+++ b/arch/x86/kernel/step.c
19354@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19355 struct desc_struct *desc;
19356 unsigned long base;
19357
19358- seg &= ~7UL;
19359+ seg >>= 3;
19360
19361 mutex_lock(&child->mm->context.lock);
19362- if (unlikely((seg >> 3) >= child->mm->context.size))
19363+ if (unlikely(seg >= child->mm->context.size))
19364 addr = -1L; /* bogus selector, access would fault */
19365 else {
19366 desc = child->mm->context.ldt + seg;
19367@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19368 addr += base;
19369 }
19370 mutex_unlock(&child->mm->context.lock);
19371- }
19372+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19373+ addr = ktla_ktva(addr);
19374
19375 return addr;
19376 }
19377@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19378 unsigned char opcode[15];
19379 unsigned long addr = convert_ip_to_linear(child, regs);
19380
19381+ if (addr == -EINVAL)
19382+ return 0;
19383+
19384 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19385 for (i = 0; i < copied; i++) {
19386 switch (opcode[i]) {
19387@@ -74,7 +78,7 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19388
19389 #ifdef CONFIG_X86_64
19390 case 0x40 ... 0x4f:
19391- if (regs->cs != __USER_CS)
19392+ if ((regs->cs & 0xffff) != __USER_CS)
19393 /* 32-bit mode: register increment */
19394 return 0;
19395 /* 64-bit mode: REX prefix */
19396diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19397index dee1ff7..a397f7f 100644
19398--- a/arch/x86/kernel/sys_i386_32.c
19399+++ b/arch/x86/kernel/sys_i386_32.c
19400@@ -24,6 +24,21 @@
19401
19402 #include <asm/syscalls.h>
19403
19404+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19405+{
19406+ unsigned long pax_task_size = TASK_SIZE;
19407+
19408+#ifdef CONFIG_PAX_SEGMEXEC
19409+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19410+ pax_task_size = SEGMEXEC_TASK_SIZE;
19411+#endif
19412+
19413+ if (len > pax_task_size || addr > pax_task_size - len)
19414+ return -EINVAL;
19415+
19416+ return 0;
19417+}
19418+
19419 /*
19420 * Perform the select(nd, in, out, ex, tv) and mmap() system
19421 * calls. Linux/i386 didn't use to be able to handle more than
19422@@ -58,6 +73,212 @@ out:
19423 return err;
19424 }
19425
19426+unsigned long
19427+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19428+ unsigned long len, unsigned long pgoff, unsigned long flags)
19429+{
19430+ struct mm_struct *mm = current->mm;
19431+ struct vm_area_struct *vma;
19432+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19433+
19434+#ifdef CONFIG_PAX_SEGMEXEC
19435+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19436+ pax_task_size = SEGMEXEC_TASK_SIZE;
19437+#endif
19438+
19439+ pax_task_size -= PAGE_SIZE;
19440+
19441+ if (len > pax_task_size)
19442+ return -ENOMEM;
19443+
19444+ if (flags & MAP_FIXED)
19445+ return addr;
19446+
19447+#ifdef CONFIG_PAX_RANDMMAP
19448+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19449+#endif
19450+
19451+ if (addr) {
19452+ addr = PAGE_ALIGN(addr);
19453+ if (pax_task_size - len >= addr) {
19454+ vma = find_vma(mm, addr);
19455+ if (check_heap_stack_gap(vma, addr, len))
19456+ return addr;
19457+ }
19458+ }
19459+ if (len > mm->cached_hole_size) {
19460+ start_addr = addr = mm->free_area_cache;
19461+ } else {
19462+ start_addr = addr = mm->mmap_base;
19463+ mm->cached_hole_size = 0;
19464+ }
19465+
19466+#ifdef CONFIG_PAX_PAGEEXEC
19467+ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19468+ start_addr = 0x00110000UL;
19469+
19470+#ifdef CONFIG_PAX_RANDMMAP
19471+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19472+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19473+#endif
19474+
19475+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19476+ start_addr = addr = mm->mmap_base;
19477+ else
19478+ addr = start_addr;
19479+ }
19480+#endif
19481+
19482+full_search:
19483+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19484+ /* At this point: (!vma || addr < vma->vm_end). */
19485+ if (pax_task_size - len < addr) {
19486+ /*
19487+ * Start a new search - just in case we missed
19488+ * some holes.
19489+ */
19490+ if (start_addr != mm->mmap_base) {
19491+ start_addr = addr = mm->mmap_base;
19492+ mm->cached_hole_size = 0;
19493+ goto full_search;
19494+ }
19495+ return -ENOMEM;
19496+ }
19497+ if (check_heap_stack_gap(vma, addr, len))
19498+ break;
19499+ if (addr + mm->cached_hole_size < vma->vm_start)
19500+ mm->cached_hole_size = vma->vm_start - addr;
19501+ addr = vma->vm_end;
19502+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19503+ start_addr = addr = mm->mmap_base;
19504+ mm->cached_hole_size = 0;
19505+ goto full_search;
19506+ }
19507+ }
19508+
19509+ /*
19510+ * Remember the place where we stopped the search:
19511+ */
19512+ mm->free_area_cache = addr + len;
19513+ return addr;
19514+}
19515+
19516+unsigned long
19517+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19518+ const unsigned long len, const unsigned long pgoff,
19519+ const unsigned long flags)
19520+{
19521+ struct vm_area_struct *vma;
19522+ struct mm_struct *mm = current->mm;
19523+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19524+
19525+#ifdef CONFIG_PAX_SEGMEXEC
19526+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19527+ pax_task_size = SEGMEXEC_TASK_SIZE;
19528+#endif
19529+
19530+ pax_task_size -= PAGE_SIZE;
19531+
19532+ /* requested length too big for entire address space */
19533+ if (len > pax_task_size)
19534+ return -ENOMEM;
19535+
19536+ if (flags & MAP_FIXED)
19537+ return addr;
19538+
19539+#ifdef CONFIG_PAX_PAGEEXEC
19540+ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19541+ goto bottomup;
19542+#endif
19543+
19544+#ifdef CONFIG_PAX_RANDMMAP
19545+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19546+#endif
19547+
19548+ /* requesting a specific address */
19549+ if (addr) {
19550+ addr = PAGE_ALIGN(addr);
19551+ if (pax_task_size - len >= addr) {
19552+ vma = find_vma(mm, addr);
19553+ if (check_heap_stack_gap(vma, addr, len))
19554+ return addr;
19555+ }
19556+ }
19557+
19558+ /* check if free_area_cache is useful for us */
19559+ if (len <= mm->cached_hole_size) {
19560+ mm->cached_hole_size = 0;
19561+ mm->free_area_cache = mm->mmap_base;
19562+ }
19563+
19564+ /* either no address requested or can't fit in requested address hole */
19565+ addr = mm->free_area_cache;
19566+
19567+ /* make sure it can fit in the remaining address space */
19568+ if (addr > len) {
19569+ vma = find_vma(mm, addr-len);
19570+ if (check_heap_stack_gap(vma, addr - len, len))
19571+ /* remember the address as a hint for next time */
19572+ return (mm->free_area_cache = addr-len);
19573+ }
19574+
19575+ if (mm->mmap_base < len)
19576+ goto bottomup;
19577+
19578+ addr = mm->mmap_base-len;
19579+
19580+ do {
19581+ /*
19582+ * Lookup failure means no vma is above this address,
19583+ * else if new region fits below vma->vm_start,
19584+ * return with success:
19585+ */
19586+ vma = find_vma(mm, addr);
19587+ if (check_heap_stack_gap(vma, addr, len))
19588+ /* remember the address as a hint for next time */
19589+ return (mm->free_area_cache = addr);
19590+
19591+ /* remember the largest hole we saw so far */
19592+ if (addr + mm->cached_hole_size < vma->vm_start)
19593+ mm->cached_hole_size = vma->vm_start - addr;
19594+
19595+ /* try just below the current vma->vm_start */
19596+ addr = skip_heap_stack_gap(vma, len);
19597+ } while (!IS_ERR_VALUE(addr));
19598+
19599+bottomup:
19600+ /*
19601+ * A failed mmap() very likely causes application failure,
19602+ * so fall back to the bottom-up function here. This scenario
19603+ * can happen with large stack limits and large mmap()
19604+ * allocations.
19605+ */
19606+
19607+#ifdef CONFIG_PAX_SEGMEXEC
19608+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19609+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19610+ else
19611+#endif
19612+
19613+ mm->mmap_base = TASK_UNMAPPED_BASE;
19614+
19615+#ifdef CONFIG_PAX_RANDMMAP
19616+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19617+ mm->mmap_base += mm->delta_mmap;
19618+#endif
19619+
19620+ mm->free_area_cache = mm->mmap_base;
19621+ mm->cached_hole_size = ~0UL;
19622+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19623+ /*
19624+ * Restore the topdown base:
19625+ */
19626+ mm->mmap_base = base;
19627+ mm->free_area_cache = base;
19628+ mm->cached_hole_size = ~0UL;
19629+
19630+ return addr;
19631+}
19632
19633 struct sel_arg_struct {
19634 unsigned long n;
19635@@ -93,7 +314,7 @@ asmlinkage int sys_ipc(uint call, int first, int second,
19636 return sys_semtimedop(first, (struct sembuf __user *)ptr, second, NULL);
19637 case SEMTIMEDOP:
19638 return sys_semtimedop(first, (struct sembuf __user *)ptr, second,
19639- (const struct timespec __user *)fifth);
19640+ (__force const struct timespec __user *)fifth);
19641
19642 case SEMGET:
19643 return sys_semget(first, second, third);
19644@@ -140,7 +361,7 @@ asmlinkage int sys_ipc(uint call, int first, int second,
19645 ret = do_shmat(first, (char __user *) ptr, second, &raddr);
19646 if (ret)
19647 return ret;
19648- return put_user(raddr, (ulong __user *) third);
19649+ return put_user(raddr, (__force ulong __user *) third);
19650 }
19651 case 1: /* iBCS2 emulator entry point */
19652 if (!segment_eq(get_fs(), get_ds()))
19653@@ -207,17 +428,3 @@ asmlinkage int sys_olduname(struct oldold_utsname __user *name)
19654
19655 return error;
19656 }
19657-
19658-
19659-/*
19660- * Do a system call from kernel instead of calling sys_execve so we
19661- * end up with proper pt_regs.
19662- */
19663-int kernel_execve(const char *filename, char *const argv[], char *const envp[])
19664-{
19665- long __res;
19666- asm volatile ("push %%ebx ; movl %2,%%ebx ; int $0x80 ; pop %%ebx"
19667- : "=a" (__res)
19668- : "0" (__NR_execve), "ri" (filename), "c" (argv), "d" (envp) : "memory");
19669- return __res;
19670-}
19671diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19672index 8aa2057..b604bc1 100644
19673--- a/arch/x86/kernel/sys_x86_64.c
19674+++ b/arch/x86/kernel/sys_x86_64.c
19675@@ -32,8 +32,8 @@ out:
19676 return error;
19677 }
19678
19679-static void find_start_end(unsigned long flags, unsigned long *begin,
19680- unsigned long *end)
19681+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19682+ unsigned long *begin, unsigned long *end)
19683 {
19684 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19685 unsigned long new_begin;
19686@@ -52,7 +52,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19687 *begin = new_begin;
19688 }
19689 } else {
19690- *begin = TASK_UNMAPPED_BASE;
19691+ *begin = mm->mmap_base;
19692 *end = TASK_SIZE;
19693 }
19694 }
19695@@ -69,16 +69,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19696 if (flags & MAP_FIXED)
19697 return addr;
19698
19699- find_start_end(flags, &begin, &end);
19700+ find_start_end(mm, flags, &begin, &end);
19701
19702 if (len > end)
19703 return -ENOMEM;
19704
19705+#ifdef CONFIG_PAX_RANDMMAP
19706+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19707+#endif
19708+
19709 if (addr) {
19710 addr = PAGE_ALIGN(addr);
19711 vma = find_vma(mm, addr);
19712- if (end - len >= addr &&
19713- (!vma || addr + len <= vma->vm_start))
19714+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19715 return addr;
19716 }
19717 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19718@@ -106,7 +109,7 @@ full_search:
19719 }
19720 return -ENOMEM;
19721 }
19722- if (!vma || addr + len <= vma->vm_start) {
19723+ if (check_heap_stack_gap(vma, addr, len)) {
19724 /*
19725 * Remember the place where we stopped the search:
19726 */
19727@@ -128,7 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19728 {
19729 struct vm_area_struct *vma;
19730 struct mm_struct *mm = current->mm;
19731- unsigned long addr = addr0;
19732+ unsigned long base = mm->mmap_base, addr = addr0;
19733
19734 /* requested length too big for entire address space */
19735 if (len > TASK_SIZE)
19736@@ -141,13 +144,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19737 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19738 goto bottomup;
19739
19740+#ifdef CONFIG_PAX_RANDMMAP
19741+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19742+#endif
19743+
19744 /* requesting a specific address */
19745 if (addr) {
19746 addr = PAGE_ALIGN(addr);
19747- vma = find_vma(mm, addr);
19748- if (TASK_SIZE - len >= addr &&
19749- (!vma || addr + len <= vma->vm_start))
19750- return addr;
19751+ if (TASK_SIZE - len >= addr) {
19752+ vma = find_vma(mm, addr);
19753+ if (check_heap_stack_gap(vma, addr, len))
19754+ return addr;
19755+ }
19756 }
19757
19758 /* check if free_area_cache is useful for us */
19759@@ -162,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19760 /* make sure it can fit in the remaining address space */
19761 if (addr > len) {
19762 vma = find_vma(mm, addr-len);
19763- if (!vma || addr <= vma->vm_start)
19764+ if (check_heap_stack_gap(vma, addr - len, len))
19765 /* remember the address as a hint for next time */
19766 return mm->free_area_cache = addr-len;
19767 }
19768@@ -179,7 +187,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19769 * return with success:
19770 */
19771 vma = find_vma(mm, addr);
19772- if (!vma || addr+len <= vma->vm_start)
19773+ if (check_heap_stack_gap(vma, addr, len))
19774 /* remember the address as a hint for next time */
19775 return mm->free_area_cache = addr;
19776
19777@@ -188,8 +196,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19778 mm->cached_hole_size = vma->vm_start - addr;
19779
19780 /* try just below the current vma->vm_start */
19781- addr = vma->vm_start-len;
19782- } while (len < vma->vm_start);
19783+ addr = skip_heap_stack_gap(vma, len);
19784+ } while (!IS_ERR_VALUE(addr));
19785
19786 bottomup:
19787 /*
19788@@ -198,13 +206,21 @@ bottomup:
19789 * can happen with large stack limits and large mmap()
19790 * allocations.
19791 */
19792+ mm->mmap_base = TASK_UNMAPPED_BASE;
19793+
19794+#ifdef CONFIG_PAX_RANDMMAP
19795+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19796+ mm->mmap_base += mm->delta_mmap;
19797+#endif
19798+
19799+ mm->free_area_cache = mm->mmap_base;
19800 mm->cached_hole_size = ~0UL;
19801- mm->free_area_cache = TASK_UNMAPPED_BASE;
19802 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19803 /*
19804 * Restore the topdown base:
19805 */
19806- mm->free_area_cache = mm->mmap_base;
19807+ mm->mmap_base = base;
19808+ mm->free_area_cache = base;
19809 mm->cached_hole_size = ~0UL;
19810
19811 return addr;
19812diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
19813index 76d70a4..4c94a44 100644
19814--- a/arch/x86/kernel/syscall_table_32.S
19815+++ b/arch/x86/kernel/syscall_table_32.S
19816@@ -1,3 +1,4 @@
19817+.section .rodata,"a",@progbits
19818 ENTRY(sys_call_table)
19819 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
19820 .long sys_exit
19821diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19822index 46b8277..3349d55 100644
19823--- a/arch/x86/kernel/tboot.c
19824+++ b/arch/x86/kernel/tboot.c
19825@@ -216,7 +216,7 @@ static int tboot_setup_sleep(void)
19826
19827 void tboot_shutdown(u32 shutdown_type)
19828 {
19829- void (*shutdown)(void);
19830+ void (* __noreturn shutdown)(void);
19831
19832 if (!tboot_enabled())
19833 return;
19834@@ -238,7 +238,7 @@ void tboot_shutdown(u32 shutdown_type)
19835
19836 switch_to_tboot_pt();
19837
19838- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19839+ shutdown = (void *)tboot->shutdown_entry;
19840 shutdown();
19841
19842 /* should not reach here */
19843@@ -295,7 +295,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19844 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19845 }
19846
19847-static atomic_t ap_wfs_count;
19848+static atomic_unchecked_t ap_wfs_count;
19849
19850 static int tboot_wait_for_aps(int num_aps)
19851 {
19852@@ -319,9 +319,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19853 {
19854 switch (action) {
19855 case CPU_DYING:
19856- atomic_inc(&ap_wfs_count);
19857+ atomic_inc_unchecked(&ap_wfs_count);
19858 if (num_online_cpus() == 1)
19859- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19860+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19861 return NOTIFY_BAD;
19862 break;
19863 }
19864@@ -340,7 +340,7 @@ static __init int tboot_late_init(void)
19865
19866 tboot_create_trampoline();
19867
19868- atomic_set(&ap_wfs_count, 0);
19869+ atomic_set_unchecked(&ap_wfs_count, 0);
19870 register_hotcpu_notifier(&tboot_cpu_notifier);
19871 return 0;
19872 }
19873diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19874index be25734..87fe232 100644
19875--- a/arch/x86/kernel/time.c
19876+++ b/arch/x86/kernel/time.c
19877@@ -26,17 +26,13 @@
19878 int timer_ack;
19879 #endif
19880
19881-#ifdef CONFIG_X86_64
19882-volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
19883-#endif
19884-
19885 unsigned long profile_pc(struct pt_regs *regs)
19886 {
19887 unsigned long pc = instruction_pointer(regs);
19888
19889- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19890+ if (!user_mode(regs) && in_lock_functions(pc)) {
19891 #ifdef CONFIG_FRAME_POINTER
19892- return *(unsigned long *)(regs->bp + sizeof(long));
19893+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19894 #else
19895 unsigned long *sp =
19896 (unsigned long *)kernel_stack_pointer(regs);
19897@@ -45,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19898 * or above a saved flags. Eflags has bits 22-31 zero,
19899 * kernel addresses don't.
19900 */
19901+
19902+#ifdef CONFIG_PAX_KERNEXEC
19903+ return ktla_ktva(sp[0]);
19904+#else
19905 if (sp[0] >> 22)
19906 return sp[0];
19907 if (sp[1] >> 22)
19908 return sp[1];
19909 #endif
19910+
19911+#endif
19912 }
19913 return pc;
19914 }
19915diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19916index 6bb7b85..dd853e1 100644
19917--- a/arch/x86/kernel/tls.c
19918+++ b/arch/x86/kernel/tls.c
19919@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19920 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19921 return -EINVAL;
19922
19923+#ifdef CONFIG_PAX_SEGMEXEC
19924+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19925+ return -EINVAL;
19926+#endif
19927+
19928 set_tls_desc(p, idx, &info, 1);
19929
19930 return 0;
19931diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19932index 8508237..229b664 100644
19933--- a/arch/x86/kernel/trampoline_32.S
19934+++ b/arch/x86/kernel/trampoline_32.S
19935@@ -32,6 +32,12 @@
19936 #include <asm/segment.h>
19937 #include <asm/page_types.h>
19938
19939+#ifdef CONFIG_PAX_KERNEXEC
19940+#define ta(X) (X)
19941+#else
19942+#define ta(X) ((X) - __PAGE_OFFSET)
19943+#endif
19944+
19945 /* We can free up trampoline after bootup if cpu hotplug is not supported. */
19946 __CPUINITRODATA
19947 .code16
19948@@ -60,7 +66,7 @@ r_base = .
19949 inc %ax # protected mode (PE) bit
19950 lmsw %ax # into protected mode
19951 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19952- ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19953+ ljmpl $__BOOT_CS, $ta(startup_32_smp)
19954
19955 # These need to be in the same 64K segment as the above;
19956 # hence we don't use the boot_gdt_descr defined in head.S
19957diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19958index 3af2dff..ba8aa49 100644
19959--- a/arch/x86/kernel/trampoline_64.S
19960+++ b/arch/x86/kernel/trampoline_64.S
19961@@ -91,7 +91,7 @@ startup_32:
19962 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19963 movl %eax, %ds
19964
19965- movl $X86_CR4_PAE, %eax
19966+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19967 movl %eax, %cr4 # Enable PAE mode
19968
19969 # Setup trampoline 4 level pagetables
19970@@ -127,7 +127,7 @@ startup_64:
19971 no_longmode:
19972 hlt
19973 jmp no_longmode
19974-#include "verify_cpu_64.S"
19975+#include "verify_cpu.S"
19976
19977 # Careful these need to be in the same 64K segment as the above;
19978 tidt:
19979@@ -138,7 +138,7 @@ tidt:
19980 # so the kernel can live anywhere
19981 .balign 4
19982 tgdt:
19983- .short tgdt_end - tgdt # gdt limit
19984+ .short tgdt_end - tgdt - 1 # gdt limit
19985 .long tgdt - r_base
19986 .short 0
19987 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19988diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19989index 7e37dce..ec3f8e5 100644
19990--- a/arch/x86/kernel/traps.c
19991+++ b/arch/x86/kernel/traps.c
19992@@ -69,12 +69,6 @@ asmlinkage int system_call(void);
19993
19994 /* Do we ignore FPU interrupts ? */
19995 char ignore_fpu_irq;
19996-
19997-/*
19998- * The IDT has to be page-aligned to simplify the Pentium
19999- * F0 0F bug workaround.
20000- */
20001-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
20002 #endif
20003
20004 DECLARE_BITMAP(used_vectors, NR_VECTORS);
20005@@ -112,19 +106,19 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
20006 static inline void
20007 die_if_kernel(const char *str, struct pt_regs *regs, long err)
20008 {
20009- if (!user_mode_vm(regs))
20010+ if (!user_mode(regs))
20011 die(str, regs, err);
20012 }
20013 #endif
20014
20015 static void __kprobes
20016-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20017+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
20018 long error_code, siginfo_t *info)
20019 {
20020 struct task_struct *tsk = current;
20021
20022 #ifdef CONFIG_X86_32
20023- if (regs->flags & X86_VM_MASK) {
20024+ if (v8086_mode(regs)) {
20025 /*
20026 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
20027 * On nmi (interrupt 2), do_trap should not be called.
20028@@ -135,7 +129,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
20029 }
20030 #endif
20031
20032- if (!user_mode(regs))
20033+ if (!user_mode_novm(regs))
20034 goto kernel_trap;
20035
20036 #ifdef CONFIG_X86_32
20037@@ -158,7 +152,7 @@ trap_signal:
20038 printk_ratelimit()) {
20039 printk(KERN_INFO
20040 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
20041- tsk->comm, tsk->pid, str,
20042+ tsk->comm, task_pid_nr(tsk), str,
20043 regs->ip, regs->sp, error_code);
20044 print_vma_addr(" in ", regs->ip);
20045 printk("\n");
20046@@ -175,8 +169,20 @@ kernel_trap:
20047 if (!fixup_exception(regs)) {
20048 tsk->thread.error_code = error_code;
20049 tsk->thread.trap_no = trapnr;
20050+
20051+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20052+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
20053+ str = "PAX: suspicious stack segment fault";
20054+#endif
20055+
20056 die(str, regs, error_code);
20057 }
20058+
20059+#ifdef CONFIG_PAX_REFCOUNT
20060+ if (trapnr == 4)
20061+ pax_report_refcount_overflow(regs);
20062+#endif
20063+
20064 return;
20065
20066 #ifdef CONFIG_X86_32
20067@@ -265,14 +271,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
20068 conditional_sti(regs);
20069
20070 #ifdef CONFIG_X86_32
20071- if (regs->flags & X86_VM_MASK)
20072+ if (v8086_mode(regs))
20073 goto gp_in_vm86;
20074 #endif
20075
20076 tsk = current;
20077- if (!user_mode(regs))
20078+ if (!user_mode_novm(regs))
20079 goto gp_in_kernel;
20080
20081+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
20082+ if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
20083+ struct mm_struct *mm = tsk->mm;
20084+ unsigned long limit;
20085+
20086+ down_write(&mm->mmap_sem);
20087+ limit = mm->context.user_cs_limit;
20088+ if (limit < TASK_SIZE) {
20089+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
20090+ up_write(&mm->mmap_sem);
20091+ return;
20092+ }
20093+ up_write(&mm->mmap_sem);
20094+ }
20095+#endif
20096+
20097 tsk->thread.error_code = error_code;
20098 tsk->thread.trap_no = 13;
20099
20100@@ -305,6 +327,13 @@ gp_in_kernel:
20101 if (notify_die(DIE_GPF, "general protection fault", regs,
20102 error_code, 13, SIGSEGV) == NOTIFY_STOP)
20103 return;
20104+
20105+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20106+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
20107+ die("PAX: suspicious general protection fault", regs, error_code);
20108+ else
20109+#endif
20110+
20111 die("general protection fault", regs, error_code);
20112 }
20113
20114@@ -435,6 +464,17 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
20115 dotraplinkage notrace __kprobes void
20116 do_nmi(struct pt_regs *regs, long error_code)
20117 {
20118+
20119+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20120+ if (!user_mode(regs)) {
20121+ unsigned long cs = regs->cs & 0xFFFF;
20122+ unsigned long ip = ktva_ktla(regs->ip);
20123+
20124+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
20125+ regs->ip = ip;
20126+ }
20127+#endif
20128+
20129 nmi_enter();
20130
20131 inc_irq_stat(__nmi_count);
20132@@ -558,7 +598,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20133 }
20134
20135 #ifdef CONFIG_X86_32
20136- if (regs->flags & X86_VM_MASK)
20137+ if (v8086_mode(regs))
20138 goto debug_vm86;
20139 #endif
20140
20141@@ -570,7 +610,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
20142 * kernel space (but re-enable TF when returning to user mode).
20143 */
20144 if (condition & DR_STEP) {
20145- if (!user_mode(regs))
20146+ if (!user_mode_novm(regs))
20147 goto clear_TF_reenable;
20148 }
20149
20150@@ -757,7 +797,7 @@ do_simd_coprocessor_error(struct pt_regs *regs, long error_code)
20151 * Handle strange cache flush from user space exception
20152 * in all other cases. This is undocumented behaviour.
20153 */
20154- if (regs->flags & X86_VM_MASK) {
20155+ if (v8086_mode(regs)) {
20156 handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
20157 return;
20158 }
20159@@ -798,7 +838,7 @@ asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
20160 void __math_state_restore(void)
20161 {
20162 struct thread_info *thread = current_thread_info();
20163- struct task_struct *tsk = thread->task;
20164+ struct task_struct *tsk = current;
20165
20166 /*
20167 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
20168@@ -825,8 +865,7 @@ void __math_state_restore(void)
20169 */
20170 asmlinkage void math_state_restore(void)
20171 {
20172- struct thread_info *thread = current_thread_info();
20173- struct task_struct *tsk = thread->task;
20174+ struct task_struct *tsk = current;
20175
20176 if (!tsk_used_math(tsk)) {
20177 local_irq_enable();
20178diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
20179new file mode 100644
20180index 0000000..50c5edd
20181--- /dev/null
20182+++ b/arch/x86/kernel/verify_cpu.S
20183@@ -0,0 +1,140 @@
20184+/*
20185+ *
20186+ * verify_cpu.S - Code for cpu long mode and SSE verification. This
20187+ * code has been borrowed from boot/setup.S and was introduced by
20188+ * Andi Kleen.
20189+ *
20190+ * Copyright (c) 2007 Andi Kleen (ak@suse.de)
20191+ * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
20192+ * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
20193+ * Copyright (c) 2010 Kees Cook (kees.cook@canonical.com)
20194+ *
20195+ * This source code is licensed under the GNU General Public License,
20196+ * Version 2. See the file COPYING for more details.
20197+ *
20198+ * This is a common code for verification whether CPU supports
20199+ * long mode and SSE or not. It is not called directly instead this
20200+ * file is included at various places and compiled in that context.
20201+ * This file is expected to run in 32bit code. Currently:
20202+ *
20203+ * arch/x86/boot/compressed/head_64.S: Boot cpu verification
20204+ * arch/x86/kernel/trampoline_64.S: secondary processor verification
20205+ * arch/x86/kernel/head_32.S: processor startup
20206+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
20207+ *
20208+ * verify_cpu, returns the status of longmode and SSE in register %eax.
20209+ * 0: Success 1: Failure
20210+ *
20211+ * On Intel, the XD_DISABLE flag will be cleared as a side-effect.
20212+ *
20213+ * The caller needs to check for the error code and take the action
20214+ * appropriately. Either display a message or halt.
20215+ */
20216+
20217+#include <asm/cpufeature.h>
20218+#include <asm/msr-index.h>
20219+
20220+verify_cpu:
20221+ pushfl # Save caller passed flags
20222+ pushl $0 # Kill any dangerous flags
20223+ popfl
20224+
20225+ pushfl # standard way to check for cpuid
20226+ popl %eax
20227+ movl %eax,%ebx
20228+ xorl $0x200000,%eax
20229+ pushl %eax
20230+ popfl
20231+ pushfl
20232+ popl %eax
20233+ cmpl %eax,%ebx
20234+ jz verify_cpu_no_longmode # cpu has no cpuid
20235+
20236+ movl $0x0,%eax # See if cpuid 1 is implemented
20237+ cpuid
20238+ cmpl $0x1,%eax
20239+ jb verify_cpu_no_longmode # no cpuid 1
20240+
20241+ xor %di,%di
20242+ cmpl $0x68747541,%ebx # AuthenticAMD
20243+ jnz verify_cpu_noamd
20244+ cmpl $0x69746e65,%edx
20245+ jnz verify_cpu_noamd
20246+ cmpl $0x444d4163,%ecx
20247+ jnz verify_cpu_noamd
20248+ mov $1,%di # cpu is from AMD
20249+ jmp verify_cpu_check
20250+
20251+verify_cpu_noamd:
20252+ cmpl $0x756e6547,%ebx # GenuineIntel?
20253+ jnz verify_cpu_check
20254+ cmpl $0x49656e69,%edx
20255+ jnz verify_cpu_check
20256+ cmpl $0x6c65746e,%ecx
20257+ jnz verify_cpu_check
20258+
20259+ # only call IA32_MISC_ENABLE when:
20260+ # family > 6 || (family == 6 && model >= 0xd)
20261+ movl $0x1, %eax # check CPU family and model
20262+ cpuid
20263+ movl %eax, %ecx
20264+
20265+ andl $0x0ff00f00, %eax # mask family and extended family
20266+ shrl $8, %eax
20267+ cmpl $6, %eax
20268+ ja verify_cpu_clear_xd # family > 6, ok
20269+ jb verify_cpu_check # family < 6, skip
20270+
20271+ andl $0x000f00f0, %ecx # mask model and extended model
20272+ shrl $4, %ecx
20273+ cmpl $0xd, %ecx
20274+ jb verify_cpu_check # family == 6, model < 0xd, skip
20275+
20276+verify_cpu_clear_xd:
20277+ movl $MSR_IA32_MISC_ENABLE, %ecx
20278+ rdmsr
20279+ btrl $2, %edx # clear MSR_IA32_MISC_ENABLE_XD_DISABLE
20280+ jnc verify_cpu_check # only write MSR if bit was changed
20281+ wrmsr
20282+
20283+verify_cpu_check:
20284+ movl $0x1,%eax # Does the cpu have what it takes
20285+ cpuid
20286+ andl $REQUIRED_MASK0,%edx
20287+ xorl $REQUIRED_MASK0,%edx
20288+ jnz verify_cpu_no_longmode
20289+
20290+ movl $0x80000000,%eax # See if extended cpuid is implemented
20291+ cpuid
20292+ cmpl $0x80000001,%eax
20293+ jb verify_cpu_no_longmode # no extended cpuid
20294+
20295+ movl $0x80000001,%eax # Does the cpu have what it takes
20296+ cpuid
20297+ andl $REQUIRED_MASK1,%edx
20298+ xorl $REQUIRED_MASK1,%edx
20299+ jnz verify_cpu_no_longmode
20300+
20301+verify_cpu_sse_test:
20302+ movl $1,%eax
20303+ cpuid
20304+ andl $SSE_MASK,%edx
20305+ cmpl $SSE_MASK,%edx
20306+ je verify_cpu_sse_ok
20307+ test %di,%di
20308+ jz verify_cpu_no_longmode # only try to force SSE on AMD
20309+ movl $MSR_K7_HWCR,%ecx
20310+ rdmsr
20311+ btr $15,%eax # enable SSE
20312+ wrmsr
20313+ xor %di,%di # don't loop
20314+ jmp verify_cpu_sse_test # try again
20315+
20316+verify_cpu_no_longmode:
20317+ popfl # Restore caller passed flags
20318+ movl $1,%eax
20319+ ret
20320+verify_cpu_sse_ok:
20321+ popfl # Restore caller passed flags
20322+ xorl %eax, %eax
20323+ ret
20324diff --git a/arch/x86/kernel/verify_cpu_64.S b/arch/x86/kernel/verify_cpu_64.S
20325deleted file mode 100644
20326index 45b6f8a..0000000
20327--- a/arch/x86/kernel/verify_cpu_64.S
20328+++ /dev/null
20329@@ -1,105 +0,0 @@
20330-/*
20331- *
20332- * verify_cpu.S - Code for cpu long mode and SSE verification. This
20333- * code has been borrowed from boot/setup.S and was introduced by
20334- * Andi Kleen.
20335- *
20336- * Copyright (c) 2007 Andi Kleen (ak@suse.de)
20337- * Copyright (c) 2007 Eric Biederman (ebiederm@xmission.com)
20338- * Copyright (c) 2007 Vivek Goyal (vgoyal@in.ibm.com)
20339- *
20340- * This source code is licensed under the GNU General Public License,
20341- * Version 2. See the file COPYING for more details.
20342- *
20343- * This is a common code for verification whether CPU supports
20344- * long mode and SSE or not. It is not called directly instead this
20345- * file is included at various places and compiled in that context.
20346- * Following are the current usage.
20347- *
20348- * This file is included by both 16bit and 32bit code.
20349- *
20350- * arch/x86_64/boot/setup.S : Boot cpu verification (16bit)
20351- * arch/x86_64/boot/compressed/head.S: Boot cpu verification (32bit)
20352- * arch/x86_64/kernel/trampoline.S: secondary processor verfication (16bit)
20353- * arch/x86_64/kernel/acpi/wakeup.S:Verfication at resume (16bit)
20354- *
20355- * verify_cpu, returns the status of cpu check in register %eax.
20356- * 0: Success 1: Failure
20357- *
20358- * The caller needs to check for the error code and take the action
20359- * appropriately. Either display a message or halt.
20360- */
20361-
20362-#include <asm/cpufeature.h>
20363-
20364-verify_cpu:
20365- pushfl # Save caller passed flags
20366- pushl $0 # Kill any dangerous flags
20367- popfl
20368-
20369- pushfl # standard way to check for cpuid
20370- popl %eax
20371- movl %eax,%ebx
20372- xorl $0x200000,%eax
20373- pushl %eax
20374- popfl
20375- pushfl
20376- popl %eax
20377- cmpl %eax,%ebx
20378- jz verify_cpu_no_longmode # cpu has no cpuid
20379-
20380- movl $0x0,%eax # See if cpuid 1 is implemented
20381- cpuid
20382- cmpl $0x1,%eax
20383- jb verify_cpu_no_longmode # no cpuid 1
20384-
20385- xor %di,%di
20386- cmpl $0x68747541,%ebx # AuthenticAMD
20387- jnz verify_cpu_noamd
20388- cmpl $0x69746e65,%edx
20389- jnz verify_cpu_noamd
20390- cmpl $0x444d4163,%ecx
20391- jnz verify_cpu_noamd
20392- mov $1,%di # cpu is from AMD
20393-
20394-verify_cpu_noamd:
20395- movl $0x1,%eax # Does the cpu have what it takes
20396- cpuid
20397- andl $REQUIRED_MASK0,%edx
20398- xorl $REQUIRED_MASK0,%edx
20399- jnz verify_cpu_no_longmode
20400-
20401- movl $0x80000000,%eax # See if extended cpuid is implemented
20402- cpuid
20403- cmpl $0x80000001,%eax
20404- jb verify_cpu_no_longmode # no extended cpuid
20405-
20406- movl $0x80000001,%eax # Does the cpu have what it takes
20407- cpuid
20408- andl $REQUIRED_MASK1,%edx
20409- xorl $REQUIRED_MASK1,%edx
20410- jnz verify_cpu_no_longmode
20411-
20412-verify_cpu_sse_test:
20413- movl $1,%eax
20414- cpuid
20415- andl $SSE_MASK,%edx
20416- cmpl $SSE_MASK,%edx
20417- je verify_cpu_sse_ok
20418- test %di,%di
20419- jz verify_cpu_no_longmode # only try to force SSE on AMD
20420- movl $0xc0010015,%ecx # HWCR
20421- rdmsr
20422- btr $15,%eax # enable SSE
20423- wrmsr
20424- xor %di,%di # don't loop
20425- jmp verify_cpu_sse_test # try again
20426-
20427-verify_cpu_no_longmode:
20428- popfl # Restore caller passed flags
20429- movl $1,%eax
20430- ret
20431-verify_cpu_sse_ok:
20432- popfl # Restore caller passed flags
20433- xorl %eax, %eax
20434- ret
20435diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
20436index 9c4e625..c992817 100644
20437--- a/arch/x86/kernel/vm86_32.c
20438+++ b/arch/x86/kernel/vm86_32.c
20439@@ -41,6 +41,7 @@
20440 #include <linux/ptrace.h>
20441 #include <linux/audit.h>
20442 #include <linux/stddef.h>
20443+#include <linux/grsecurity.h>
20444
20445 #include <asm/uaccess.h>
20446 #include <asm/io.h>
20447@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
20448 do_exit(SIGSEGV);
20449 }
20450
20451- tss = &per_cpu(init_tss, get_cpu());
20452+ tss = init_tss + get_cpu();
20453 current->thread.sp0 = current->thread.saved_sp0;
20454 current->thread.sysenter_cs = __KERNEL_CS;
20455 load_sp0(tss, &current->thread);
20456@@ -208,6 +209,13 @@ int sys_vm86old(struct pt_regs *regs)
20457 struct task_struct *tsk;
20458 int tmp, ret = -EPERM;
20459
20460+#ifdef CONFIG_GRKERNSEC_VM86
20461+ if (!capable(CAP_SYS_RAWIO)) {
20462+ gr_handle_vm86();
20463+ goto out;
20464+ }
20465+#endif
20466+
20467 tsk = current;
20468 if (tsk->thread.saved_sp0)
20469 goto out;
20470@@ -238,6 +246,14 @@ int sys_vm86(struct pt_regs *regs)
20471 int tmp, ret;
20472 struct vm86plus_struct __user *v86;
20473
20474+#ifdef CONFIG_GRKERNSEC_VM86
20475+ if (!capable(CAP_SYS_RAWIO)) {
20476+ gr_handle_vm86();
20477+ ret = -EPERM;
20478+ goto out;
20479+ }
20480+#endif
20481+
20482 tsk = current;
20483 switch (regs->bx) {
20484 case VM86_REQUEST_IRQ:
20485@@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
20486 tsk->thread.saved_fs = info->regs32->fs;
20487 tsk->thread.saved_gs = get_user_gs(info->regs32);
20488
20489- tss = &per_cpu(init_tss, get_cpu());
20490+ tss = init_tss + get_cpu();
20491 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
20492 if (cpu_has_sep)
20493 tsk->thread.sysenter_cs = 0;
20494@@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
20495 goto cannot_handle;
20496 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
20497 goto cannot_handle;
20498- intr_ptr = (unsigned long __user *) (i << 2);
20499+ intr_ptr = (__force unsigned long __user *) (i << 2);
20500 if (get_user(segoffs, intr_ptr))
20501 goto cannot_handle;
20502 if ((segoffs >> 16) == BIOSSEG)
20503diff --git a/arch/x86/kernel/vmi_32.c b/arch/x86/kernel/vmi_32.c
20504index d430e4c..831f817 100644
20505--- a/arch/x86/kernel/vmi_32.c
20506+++ b/arch/x86/kernel/vmi_32.c
20507@@ -44,12 +44,17 @@ typedef u32 __attribute__((regparm(1))) (VROMFUNC)(void);
20508 typedef u64 __attribute__((regparm(2))) (VROMLONGFUNC)(int);
20509
20510 #define call_vrom_func(rom,func) \
20511- (((VROMFUNC *)(rom->func))())
20512+ (((VROMFUNC *)(ktva_ktla(rom.func)))())
20513
20514 #define call_vrom_long_func(rom,func,arg) \
20515- (((VROMLONGFUNC *)(rom->func)) (arg))
20516+({\
20517+ u64 __reloc = ((VROMLONGFUNC *)(ktva_ktla(rom.func))) (arg);\
20518+ struct vmi_relocation_info *const __rel = (struct vmi_relocation_info *)&__reloc;\
20519+ __rel->eip = (unsigned char *)ktva_ktla((unsigned long)__rel->eip);\
20520+ __reloc;\
20521+})
20522
20523-static struct vrom_header *vmi_rom;
20524+static struct vrom_header vmi_rom __attribute((__section__(".vmi.rom"), __aligned__(PAGE_SIZE)));
20525 static int disable_pge;
20526 static int disable_pse;
20527 static int disable_sep;
20528@@ -76,10 +81,10 @@ static struct {
20529 void (*set_initial_ap_state)(int, int);
20530 void (*halt)(void);
20531 void (*set_lazy_mode)(int mode);
20532-} vmi_ops;
20533+} __no_const vmi_ops __read_only;
20534
20535 /* Cached VMI operations */
20536-struct vmi_timer_ops vmi_timer_ops;
20537+struct vmi_timer_ops vmi_timer_ops __read_only;
20538
20539 /*
20540 * VMI patching routines.
20541@@ -94,7 +99,7 @@ struct vmi_timer_ops vmi_timer_ops;
20542 static inline void patch_offset(void *insnbuf,
20543 unsigned long ip, unsigned long dest)
20544 {
20545- *(unsigned long *)(insnbuf+1) = dest-ip-5;
20546+ *(unsigned long *)(insnbuf+1) = dest-ip-5;
20547 }
20548
20549 static unsigned patch_internal(int call, unsigned len, void *insnbuf,
20550@@ -102,6 +107,7 @@ static unsigned patch_internal(int call, unsigned len, void *insnbuf,
20551 {
20552 u64 reloc;
20553 struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
20554+
20555 reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
20556 switch(rel->type) {
20557 case VMI_RELOCATION_CALL_REL:
20558@@ -404,13 +410,13 @@ static void vmi_set_pud(pud_t *pudp, pud_t pudval)
20559
20560 static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
20561 {
20562- const pte_t pte = { .pte = 0 };
20563+ const pte_t pte = __pte(0ULL);
20564 vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
20565 }
20566
20567 static void vmi_pmd_clear(pmd_t *pmd)
20568 {
20569- const pte_t pte = { .pte = 0 };
20570+ const pte_t pte = __pte(0ULL);
20571 vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
20572 }
20573 #endif
20574@@ -438,10 +444,10 @@ vmi_startup_ipi_hook(int phys_apicid, unsigned long start_eip,
20575 ap.ss = __KERNEL_DS;
20576 ap.esp = (unsigned long) start_esp;
20577
20578- ap.ds = __USER_DS;
20579- ap.es = __USER_DS;
20580+ ap.ds = __KERNEL_DS;
20581+ ap.es = __KERNEL_DS;
20582 ap.fs = __KERNEL_PERCPU;
20583- ap.gs = __KERNEL_STACK_CANARY;
20584+ savesegment(gs, ap.gs);
20585
20586 ap.eflags = 0;
20587
20588@@ -486,6 +492,18 @@ static void vmi_leave_lazy_mmu(void)
20589 paravirt_leave_lazy_mmu();
20590 }
20591
20592+#ifdef CONFIG_PAX_KERNEXEC
20593+static unsigned long vmi_pax_open_kernel(void)
20594+{
20595+ return 0;
20596+}
20597+
20598+static unsigned long vmi_pax_close_kernel(void)
20599+{
20600+ return 0;
20601+}
20602+#endif
20603+
20604 static inline int __init check_vmi_rom(struct vrom_header *rom)
20605 {
20606 struct pci_header *pci;
20607@@ -498,6 +516,10 @@ static inline int __init check_vmi_rom(struct vrom_header *rom)
20608 return 0;
20609 if (rom->vrom_signature != VMI_SIGNATURE)
20610 return 0;
20611+ if (rom->rom_length * 512 > sizeof(*rom)) {
20612+ printk(KERN_WARNING "PAX: VMI: ROM size too big: %x\n", rom->rom_length * 512);
20613+ return 0;
20614+ }
20615 if (rom->api_version_maj != VMI_API_REV_MAJOR ||
20616 rom->api_version_min+1 < VMI_API_REV_MINOR+1) {
20617 printk(KERN_WARNING "VMI: Found mismatched rom version %d.%d\n",
20618@@ -562,7 +584,7 @@ static inline int __init probe_vmi_rom(void)
20619 struct vrom_header *romstart;
20620 romstart = (struct vrom_header *)isa_bus_to_virt(base);
20621 if (check_vmi_rom(romstart)) {
20622- vmi_rom = romstart;
20623+ vmi_rom = *romstart;
20624 return 1;
20625 }
20626 }
20627@@ -836,6 +858,11 @@ static inline int __init activate_vmi(void)
20628
20629 para_fill(pv_irq_ops.safe_halt, Halt);
20630
20631+#ifdef CONFIG_PAX_KERNEXEC
20632+ pv_mmu_ops.pax_open_kernel = vmi_pax_open_kernel;
20633+ pv_mmu_ops.pax_close_kernel = vmi_pax_close_kernel;
20634+#endif
20635+
20636 /*
20637 * Alternative instruction rewriting doesn't happen soon enough
20638 * to convert VMI_IRET to a call instead of a jump; so we have
20639@@ -853,16 +880,16 @@ static inline int __init activate_vmi(void)
20640
20641 void __init vmi_init(void)
20642 {
20643- if (!vmi_rom)
20644+ if (!vmi_rom.rom_signature)
20645 probe_vmi_rom();
20646 else
20647- check_vmi_rom(vmi_rom);
20648+ check_vmi_rom(&vmi_rom);
20649
20650 /* In case probing for or validating the ROM failed, basil */
20651- if (!vmi_rom)
20652+ if (!vmi_rom.rom_signature)
20653 return;
20654
20655- reserve_top_address(-vmi_rom->virtual_top);
20656+ reserve_top_address(-vmi_rom.virtual_top);
20657
20658 #ifdef CONFIG_X86_IO_APIC
20659 /* This is virtual hardware; timer routing is wired correctly */
20660@@ -874,7 +901,7 @@ void __init vmi_activate(void)
20661 {
20662 unsigned long flags;
20663
20664- if (!vmi_rom)
20665+ if (!vmi_rom.rom_signature)
20666 return;
20667
20668 local_irq_save(flags);
20669diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20670index 3c68fe2..12c8280 100644
20671--- a/arch/x86/kernel/vmlinux.lds.S
20672+++ b/arch/x86/kernel/vmlinux.lds.S
20673@@ -26,6 +26,13 @@
20674 #include <asm/page_types.h>
20675 #include <asm/cache.h>
20676 #include <asm/boot.h>
20677+#include <asm/segment.h>
20678+
20679+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20680+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20681+#else
20682+#define __KERNEL_TEXT_OFFSET 0
20683+#endif
20684
20685 #undef i386 /* in case the preprocessor is a 32bit one */
20686
20687@@ -34,40 +41,53 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT, CONFIG_OUTPUT_FORMAT)
20688 #ifdef CONFIG_X86_32
20689 OUTPUT_ARCH(i386)
20690 ENTRY(phys_startup_32)
20691-jiffies = jiffies_64;
20692 #else
20693 OUTPUT_ARCH(i386:x86-64)
20694 ENTRY(phys_startup_64)
20695-jiffies_64 = jiffies;
20696 #endif
20697
20698 PHDRS {
20699 text PT_LOAD FLAGS(5); /* R_E */
20700- data PT_LOAD FLAGS(7); /* RWE */
20701+#ifdef CONFIG_X86_32
20702+ module PT_LOAD FLAGS(5); /* R_E */
20703+#endif
20704+#ifdef CONFIG_XEN
20705+ rodata PT_LOAD FLAGS(5); /* R_E */
20706+#else
20707+ rodata PT_LOAD FLAGS(4); /* R__ */
20708+#endif
20709+ data PT_LOAD FLAGS(6); /* RW_ */
20710 #ifdef CONFIG_X86_64
20711 user PT_LOAD FLAGS(5); /* R_E */
20712+#endif
20713+ init.begin PT_LOAD FLAGS(6); /* RW_ */
20714 #ifdef CONFIG_SMP
20715 percpu PT_LOAD FLAGS(6); /* RW_ */
20716 #endif
20717+ text.init PT_LOAD FLAGS(5); /* R_E */
20718+ text.exit PT_LOAD FLAGS(5); /* R_E */
20719 init PT_LOAD FLAGS(7); /* RWE */
20720-#endif
20721 note PT_NOTE FLAGS(0); /* ___ */
20722 }
20723
20724 SECTIONS
20725 {
20726 #ifdef CONFIG_X86_32
20727- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20728- phys_startup_32 = startup_32 - LOAD_OFFSET;
20729+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20730 #else
20731- . = __START_KERNEL;
20732- phys_startup_64 = startup_64 - LOAD_OFFSET;
20733+ . = __START_KERNEL;
20734 #endif
20735
20736 /* Text and read-only data */
20737- .text : AT(ADDR(.text) - LOAD_OFFSET) {
20738- _text = .;
20739+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20740 /* bootstrapping code */
20741+#ifdef CONFIG_X86_32
20742+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20743+#else
20744+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20745+#endif
20746+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20747+ _text = .;
20748 HEAD_TEXT
20749 #ifdef CONFIG_X86_32
20750 . = ALIGN(PAGE_SIZE);
20751@@ -82,28 +102,71 @@ SECTIONS
20752 IRQENTRY_TEXT
20753 *(.fixup)
20754 *(.gnu.warning)
20755- /* End of text section */
20756- _etext = .;
20757 } :text = 0x9090
20758
20759- NOTES :text :note
20760+ . += __KERNEL_TEXT_OFFSET;
20761
20762- EXCEPTION_TABLE(16) :text = 0x9090
20763+#ifdef CONFIG_X86_32
20764+ . = ALIGN(PAGE_SIZE);
20765+ .vmi.rom : AT(ADDR(.vmi.rom) - LOAD_OFFSET) {
20766+ *(.vmi.rom)
20767+ } :module
20768+
20769+ . = ALIGN(PAGE_SIZE);
20770+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20771+
20772+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20773+ MODULES_EXEC_VADDR = .;
20774+ BYTE(0)
20775+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20776+ . = ALIGN(HPAGE_SIZE);
20777+ MODULES_EXEC_END = . - 1;
20778+#endif
20779+
20780+ } :module
20781+#endif
20782+
20783+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20784+ /* End of text section */
20785+ _etext = . - __KERNEL_TEXT_OFFSET;
20786+ }
20787+
20788+#ifdef CONFIG_X86_32
20789+ . = ALIGN(PAGE_SIZE);
20790+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20791+ *(.idt)
20792+ . = ALIGN(PAGE_SIZE);
20793+ *(.empty_zero_page)
20794+ *(.swapper_pg_fixmap)
20795+ *(.swapper_pg_pmd)
20796+ *(.swapper_pg_dir)
20797+ *(.trampoline_pg_dir)
20798+ } :rodata
20799+#endif
20800+
20801+ . = ALIGN(PAGE_SIZE);
20802+ NOTES :rodata :note
20803+
20804+ EXCEPTION_TABLE(16) :rodata
20805
20806 RO_DATA(PAGE_SIZE)
20807
20808 /* Data */
20809 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20810+
20811+#ifdef CONFIG_PAX_KERNEXEC
20812+ . = ALIGN(HPAGE_SIZE);
20813+#else
20814+ . = ALIGN(PAGE_SIZE);
20815+#endif
20816+
20817 /* Start of data section */
20818 _sdata = .;
20819
20820 /* init_task */
20821 INIT_TASK_DATA(THREAD_SIZE)
20822
20823-#ifdef CONFIG_X86_32
20824- /* 32 bit has nosave before _edata */
20825 NOSAVE_DATA
20826-#endif
20827
20828 PAGE_ALIGNED_DATA(PAGE_SIZE)
20829
20830@@ -112,6 +175,8 @@ SECTIONS
20831 DATA_DATA
20832 CONSTRUCTORS
20833
20834+ jiffies = jiffies_64;
20835+
20836 /* rarely changed data like cpu maps */
20837 READ_MOSTLY_DATA(CONFIG_X86_INTERNODE_CACHE_BYTES)
20838
20839@@ -166,12 +231,6 @@ SECTIONS
20840 }
20841 vgetcpu_mode = VVIRT(.vgetcpu_mode);
20842
20843- . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
20844- .jiffies : AT(VLOAD(.jiffies)) {
20845- *(.jiffies)
20846- }
20847- jiffies = VVIRT(.jiffies);
20848-
20849 .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) {
20850 *(.vsyscall_3)
20851 }
20852@@ -187,12 +246,19 @@ SECTIONS
20853 #endif /* CONFIG_X86_64 */
20854
20855 /* Init code and data - will be freed after init */
20856- . = ALIGN(PAGE_SIZE);
20857 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20858+ BYTE(0)
20859+
20860+#ifdef CONFIG_PAX_KERNEXEC
20861+ . = ALIGN(HPAGE_SIZE);
20862+#else
20863+ . = ALIGN(PAGE_SIZE);
20864+#endif
20865+
20866 __init_begin = .; /* paired with __init_end */
20867- }
20868+ } :init.begin
20869
20870-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20871+#ifdef CONFIG_SMP
20872 /*
20873 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20874 * output PHDR, so the next output section - .init.text - should
20875@@ -201,12 +267,27 @@ SECTIONS
20876 PERCPU_VADDR(0, :percpu)
20877 #endif
20878
20879- INIT_TEXT_SECTION(PAGE_SIZE)
20880-#ifdef CONFIG_X86_64
20881- :init
20882-#endif
20883+ . = ALIGN(PAGE_SIZE);
20884+ init_begin = .;
20885+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20886+ VMLINUX_SYMBOL(_sinittext) = .;
20887+ INIT_TEXT
20888+ VMLINUX_SYMBOL(_einittext) = .;
20889+ . = ALIGN(PAGE_SIZE);
20890+ } :text.init
20891
20892- INIT_DATA_SECTION(16)
20893+ /*
20894+ * .exit.text is discard at runtime, not link time, to deal with
20895+ * references from .altinstructions and .eh_frame
20896+ */
20897+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20898+ EXIT_TEXT
20899+ . = ALIGN(16);
20900+ } :text.exit
20901+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20902+
20903+ . = ALIGN(PAGE_SIZE);
20904+ INIT_DATA_SECTION(16) :init
20905
20906 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20907 __x86_cpu_dev_start = .;
20908@@ -232,19 +313,11 @@ SECTIONS
20909 *(.altinstr_replacement)
20910 }
20911
20912- /*
20913- * .exit.text is discard at runtime, not link time, to deal with
20914- * references from .altinstructions and .eh_frame
20915- */
20916- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20917- EXIT_TEXT
20918- }
20919-
20920 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20921 EXIT_DATA
20922 }
20923
20924-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20925+#ifndef CONFIG_SMP
20926 PERCPU(PAGE_SIZE)
20927 #endif
20928
20929@@ -267,12 +340,6 @@ SECTIONS
20930 . = ALIGN(PAGE_SIZE);
20931 }
20932
20933-#ifdef CONFIG_X86_64
20934- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20935- NOSAVE_DATA
20936- }
20937-#endif
20938-
20939 /* BSS */
20940 . = ALIGN(PAGE_SIZE);
20941 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20942@@ -288,6 +355,7 @@ SECTIONS
20943 __brk_base = .;
20944 . += 64 * 1024; /* 64k alignment slop space */
20945 *(.brk_reservation) /* areas brk users have reserved */
20946+ . = ALIGN(HPAGE_SIZE);
20947 __brk_limit = .;
20948 }
20949
20950@@ -316,13 +384,12 @@ SECTIONS
20951 * for the boot processor.
20952 */
20953 #define INIT_PER_CPU(x) init_per_cpu__##x = per_cpu__##x + __per_cpu_load
20954-INIT_PER_CPU(gdt_page);
20955 INIT_PER_CPU(irq_stack_union);
20956
20957 /*
20958 * Build-time check on the image size:
20959 */
20960-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20961+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20962 "kernel image bigger than KERNEL_IMAGE_SIZE");
20963
20964 #ifdef CONFIG_SMP
20965diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20966index 62f39d7..3bc46a1 100644
20967--- a/arch/x86/kernel/vsyscall_64.c
20968+++ b/arch/x86/kernel/vsyscall_64.c
20969@@ -80,6 +80,7 @@ void update_vsyscall(struct timespec *wall_time, struct clocksource *clock,
20970
20971 write_seqlock_irqsave(&vsyscall_gtod_data.lock, flags);
20972 /* copy vsyscall data */
20973+ strlcpy(vsyscall_gtod_data.clock.name, clock->name, sizeof vsyscall_gtod_data.clock.name);
20974 vsyscall_gtod_data.clock.vread = clock->vread;
20975 vsyscall_gtod_data.clock.cycle_last = clock->cycle_last;
20976 vsyscall_gtod_data.clock.mask = clock->mask;
20977@@ -203,7 +204,7 @@ vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache)
20978 We do this here because otherwise user space would do it on
20979 its own in a likely inferior way (no access to jiffies).
20980 If you don't like it pass NULL. */
20981- if (tcache && tcache->blob[0] == (j = __jiffies)) {
20982+ if (tcache && tcache->blob[0] == (j = jiffies)) {
20983 p = tcache->blob[1];
20984 } else if (__vgetcpu_mode == VGETCPU_RDTSCP) {
20985 /* Load per CPU data from RDTSCP */
20986diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20987index 3909e3b..5433a97 100644
20988--- a/arch/x86/kernel/x8664_ksyms_64.c
20989+++ b/arch/x86/kernel/x8664_ksyms_64.c
20990@@ -30,8 +30,6 @@ EXPORT_SYMBOL(__put_user_8);
20991
20992 EXPORT_SYMBOL(copy_user_generic);
20993 EXPORT_SYMBOL(__copy_user_nocache);
20994-EXPORT_SYMBOL(copy_from_user);
20995-EXPORT_SYMBOL(copy_to_user);
20996 EXPORT_SYMBOL(__copy_from_user_inatomic);
20997
20998 EXPORT_SYMBOL(copy_page);
20999diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21000index c5ee17e..d63218f 100644
21001--- a/arch/x86/kernel/xsave.c
21002+++ b/arch/x86/kernel/xsave.c
21003@@ -54,7 +54,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
21004 fx_sw_user->xstate_size > fx_sw_user->extended_size)
21005 return -1;
21006
21007- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
21008+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
21009 fx_sw_user->extended_size -
21010 FP_XSTATE_MAGIC2_SIZE));
21011 /*
21012@@ -196,7 +196,7 @@ fx_only:
21013 * the other extended state.
21014 */
21015 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
21016- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
21017+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
21018 }
21019
21020 /*
21021@@ -228,7 +228,7 @@ int restore_i387_xstate(void __user *buf)
21022 if (task_thread_info(tsk)->status & TS_XSAVE)
21023 err = restore_user_xstate(buf);
21024 else
21025- err = fxrstor_checking((__force struct i387_fxsave_struct *)
21026+ err = fxrstor_checking((struct i387_fxsave_struct __user *)
21027 buf);
21028 if (unlikely(err)) {
21029 /*
21030diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21031index 1350e43..a94b011 100644
21032--- a/arch/x86/kvm/emulate.c
21033+++ b/arch/x86/kvm/emulate.c
21034@@ -81,8 +81,8 @@
21035 #define Src2CL (1<<29)
21036 #define Src2ImmByte (2<<29)
21037 #define Src2One (3<<29)
21038-#define Src2Imm16 (4<<29)
21039-#define Src2Mask (7<<29)
21040+#define Src2Imm16 (4U<<29)
21041+#define Src2Mask (7U<<29)
21042
21043 enum {
21044 Group1_80, Group1_81, Group1_82, Group1_83,
21045@@ -411,6 +411,7 @@ static u32 group2_table[] = {
21046
21047 #define ____emulate_2op(_op, _src, _dst, _eflags, _x, _y, _suffix) \
21048 do { \
21049+ unsigned long _tmp; \
21050 __asm__ __volatile__ ( \
21051 _PRE_EFLAGS("0", "4", "2") \
21052 _op _suffix " %"_x"3,%1; " \
21053@@ -424,8 +425,6 @@ static u32 group2_table[] = {
21054 /* Raw emulation: instruction has two explicit operands. */
21055 #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
21056 do { \
21057- unsigned long _tmp; \
21058- \
21059 switch ((_dst).bytes) { \
21060 case 2: \
21061 ____emulate_2op(_op,_src,_dst,_eflags,_wx,_wy,"w"); \
21062@@ -441,7 +440,6 @@ static u32 group2_table[] = {
21063
21064 #define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21065 do { \
21066- unsigned long _tmp; \
21067 switch ((_dst).bytes) { \
21068 case 1: \
21069 ____emulate_2op(_op,_src,_dst,_eflags,_bx,_by,"b"); \
21070diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21071index 8dfeaaa..4daa395 100644
21072--- a/arch/x86/kvm/lapic.c
21073+++ b/arch/x86/kvm/lapic.c
21074@@ -52,7 +52,7 @@
21075 #define APIC_BUS_CYCLE_NS 1
21076
21077 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21078-#define apic_debug(fmt, arg...)
21079+#define apic_debug(fmt, arg...) do {} while (0)
21080
21081 #define APIC_LVT_NUM 6
21082 /* 14 is the version for Xeon and Pentium 8.4.8*/
21083diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21084index 3bc2707..dd157e2 100644
21085--- a/arch/x86/kvm/paging_tmpl.h
21086+++ b/arch/x86/kvm/paging_tmpl.h
21087@@ -416,6 +416,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
21088 int level = PT_PAGE_TABLE_LEVEL;
21089 unsigned long mmu_seq;
21090
21091+ pax_track_stack();
21092+
21093 pgprintk("%s: addr %lx err %x\n", __func__, addr, error_code);
21094 kvm_mmu_audit(vcpu, "pre page fault");
21095
21096@@ -461,6 +463,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
21097 kvm_mmu_free_some_pages(vcpu);
21098 sptep = FNAME(fetch)(vcpu, addr, &walker, user_fault, write_fault,
21099 level, &write_pt, pfn);
21100+ (void)sptep;
21101 pgprintk("%s: shadow pte %p %llx ptwrite %d\n", __func__,
21102 sptep, *sptep, write_pt);
21103
21104diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21105index 7c6e63e..c5d92c1 100644
21106--- a/arch/x86/kvm/svm.c
21107+++ b/arch/x86/kvm/svm.c
21108@@ -2486,7 +2486,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21109 int cpu = raw_smp_processor_id();
21110
21111 struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
21112+
21113+ pax_open_kernel();
21114 svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
21115+ pax_close_kernel();
21116+
21117 load_TR_desc();
21118 }
21119
21120@@ -2947,7 +2951,7 @@ static bool svm_gb_page_enable(void)
21121 return true;
21122 }
21123
21124-static struct kvm_x86_ops svm_x86_ops = {
21125+static const struct kvm_x86_ops svm_x86_ops = {
21126 .cpu_has_kvm_support = has_svm,
21127 .disabled_by_bios = is_disabled,
21128 .hardware_setup = svm_hardware_setup,
21129diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21130index e6d925f..e7a4af8 100644
21131--- a/arch/x86/kvm/vmx.c
21132+++ b/arch/x86/kvm/vmx.c
21133@@ -570,7 +570,11 @@ static void reload_tss(void)
21134
21135 kvm_get_gdt(&gdt);
21136 descs = (void *)gdt.base;
21137+
21138+ pax_open_kernel();
21139 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21140+ pax_close_kernel();
21141+
21142 load_TR_desc();
21143 }
21144
21145@@ -1410,8 +1414,11 @@ static __init int hardware_setup(void)
21146 if (!cpu_has_vmx_flexpriority())
21147 flexpriority_enabled = 0;
21148
21149- if (!cpu_has_vmx_tpr_shadow())
21150- kvm_x86_ops->update_cr8_intercept = NULL;
21151+ if (!cpu_has_vmx_tpr_shadow()) {
21152+ pax_open_kernel();
21153+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21154+ pax_close_kernel();
21155+ }
21156
21157 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21158 kvm_disable_largepages();
21159@@ -2362,7 +2369,7 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
21160 vmcs_writel(HOST_IDTR_BASE, dt.base); /* 22.2.4 */
21161
21162 asm("mov $.Lkvm_vmx_return, %0" : "=r"(kvm_vmx_return));
21163- vmcs_writel(HOST_RIP, kvm_vmx_return); /* 22.2.5 */
21164+ vmcs_writel(HOST_RIP, ktla_ktva(kvm_vmx_return)); /* 22.2.5 */
21165 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, 0);
21166 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, 0);
21167 vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, 0);
21168@@ -3718,6 +3725,12 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
21169 "jmp .Lkvm_vmx_return \n\t"
21170 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
21171 ".Lkvm_vmx_return: "
21172+
21173+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21174+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
21175+ ".Lkvm_vmx_return2: "
21176+#endif
21177+
21178 /* Save guest registers, load host registers, keep flags */
21179 "xchg %0, (%%"R"sp) \n\t"
21180 "mov %%"R"ax, %c[rax](%0) \n\t"
21181@@ -3764,8 +3777,13 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
21182 [r15]"i"(offsetof(struct vcpu_vmx, vcpu.arch.regs[VCPU_REGS_R15])),
21183 #endif
21184 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2))
21185+
21186+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21187+ ,[cs]"i"(__KERNEL_CS)
21188+#endif
21189+
21190 : "cc", "memory"
21191- , R"bx", R"di", R"si"
21192+ , R"ax", R"bx", R"di", R"si"
21193 #ifdef CONFIG_X86_64
21194 , "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
21195 #endif
21196@@ -3782,7 +3800,16 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
21197 if (vmx->rmode.irq.pending)
21198 fixup_rmode_irq(vmx);
21199
21200- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
21201+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
21202+
21203+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21204+ loadsegment(fs, __KERNEL_PERCPU);
21205+#endif
21206+
21207+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21208+ __set_fs(current_thread_info()->addr_limit);
21209+#endif
21210+
21211 vmx->launched = 1;
21212
21213 vmx_complete_interrupts(vmx);
21214@@ -3957,7 +3984,7 @@ static bool vmx_gb_page_enable(void)
21215 return false;
21216 }
21217
21218-static struct kvm_x86_ops vmx_x86_ops = {
21219+static const struct kvm_x86_ops vmx_x86_ops = {
21220 .cpu_has_kvm_support = cpu_has_kvm_support,
21221 .disabled_by_bios = vmx_disabled_by_bios,
21222 .hardware_setup = hardware_setup,
21223diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
21224index df1cefb..5e882ad 100644
21225--- a/arch/x86/kvm/x86.c
21226+++ b/arch/x86/kvm/x86.c
21227@@ -82,7 +82,7 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu);
21228 static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
21229 struct kvm_cpuid_entry2 __user *entries);
21230
21231-struct kvm_x86_ops *kvm_x86_ops;
21232+const struct kvm_x86_ops *kvm_x86_ops;
21233 EXPORT_SYMBOL_GPL(kvm_x86_ops);
21234
21235 int ignore_msrs = 0;
21236@@ -1430,15 +1430,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21237 struct kvm_cpuid2 *cpuid,
21238 struct kvm_cpuid_entry2 __user *entries)
21239 {
21240- int r;
21241+ int r, i;
21242
21243 r = -E2BIG;
21244 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21245 goto out;
21246 r = -EFAULT;
21247- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21248- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21249+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21250 goto out;
21251+ for (i = 0; i < cpuid->nent; ++i) {
21252+ struct kvm_cpuid_entry2 cpuid_entry;
21253+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21254+ goto out;
21255+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
21256+ }
21257 vcpu->arch.cpuid_nent = cpuid->nent;
21258 kvm_apic_set_version(vcpu);
21259 return 0;
21260@@ -1451,16 +1456,20 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21261 struct kvm_cpuid2 *cpuid,
21262 struct kvm_cpuid_entry2 __user *entries)
21263 {
21264- int r;
21265+ int r, i;
21266
21267 vcpu_load(vcpu);
21268 r = -E2BIG;
21269 if (cpuid->nent < vcpu->arch.cpuid_nent)
21270 goto out;
21271 r = -EFAULT;
21272- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21273- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21274+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21275 goto out;
21276+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21277+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21278+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21279+ goto out;
21280+ }
21281 return 0;
21282
21283 out:
21284@@ -1678,7 +1687,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
21285 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
21286 struct kvm_interrupt *irq)
21287 {
21288- if (irq->irq < 0 || irq->irq >= 256)
21289+ if (irq->irq >= 256)
21290 return -EINVAL;
21291 if (irqchip_in_kernel(vcpu->kvm))
21292 return -ENXIO;
21293@@ -3260,10 +3269,10 @@ static struct notifier_block kvmclock_cpufreq_notifier_block = {
21294 .notifier_call = kvmclock_cpufreq_notifier
21295 };
21296
21297-int kvm_arch_init(void *opaque)
21298+int kvm_arch_init(const void *opaque)
21299 {
21300 int r, cpu;
21301- struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
21302+ const struct kvm_x86_ops *ops = (const struct kvm_x86_ops *)opaque;
21303
21304 if (kvm_x86_ops) {
21305 printk(KERN_ERR "kvm: already loaded the other module\n");
21306diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
21307index 7e59dc1..b88c98f 100644
21308--- a/arch/x86/lguest/boot.c
21309+++ b/arch/x86/lguest/boot.c
21310@@ -1172,9 +1172,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
21311 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
21312 * Launcher to reboot us.
21313 */
21314-static void lguest_restart(char *reason)
21315+static __noreturn void lguest_restart(char *reason)
21316 {
21317 kvm_hypercall2(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART);
21318+ BUG();
21319 }
21320
21321 /*G:050
21322diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
21323index 824fa0b..c619e96 100644
21324--- a/arch/x86/lib/atomic64_32.c
21325+++ b/arch/x86/lib/atomic64_32.c
21326@@ -25,6 +25,12 @@ u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val)
21327 }
21328 EXPORT_SYMBOL(atomic64_cmpxchg);
21329
21330+u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old_val, u64 new_val)
21331+{
21332+ return cmpxchg8b(&ptr->counter, old_val, new_val);
21333+}
21334+EXPORT_SYMBOL(atomic64_cmpxchg_unchecked);
21335+
21336 /**
21337 * atomic64_xchg - xchg atomic64 variable
21338 * @ptr: pointer to type atomic64_t
21339@@ -56,6 +62,36 @@ u64 atomic64_xchg(atomic64_t *ptr, u64 new_val)
21340 EXPORT_SYMBOL(atomic64_xchg);
21341
21342 /**
21343+ * atomic64_xchg_unchecked - xchg atomic64 variable
21344+ * @ptr: pointer to type atomic64_unchecked_t
21345+ * @new_val: value to assign
21346+ *
21347+ * Atomically xchgs the value of @ptr to @new_val and returns
21348+ * the old value.
21349+ */
21350+u64 atomic64_xchg_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
21351+{
21352+ /*
21353+ * Try first with a (possibly incorrect) assumption about
21354+ * what we have there. We'll do two loops most likely,
21355+ * but we'll get an ownership MESI transaction straight away
21356+ * instead of a read transaction followed by a
21357+ * flush-for-ownership transaction:
21358+ */
21359+ u64 old_val, real_val = 0;
21360+
21361+ do {
21362+ old_val = real_val;
21363+
21364+ real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
21365+
21366+ } while (real_val != old_val);
21367+
21368+ return old_val;
21369+}
21370+EXPORT_SYMBOL(atomic64_xchg_unchecked);
21371+
21372+/**
21373 * atomic64_set - set atomic64 variable
21374 * @ptr: pointer to type atomic64_t
21375 * @new_val: value to assign
21376@@ -69,7 +105,19 @@ void atomic64_set(atomic64_t *ptr, u64 new_val)
21377 EXPORT_SYMBOL(atomic64_set);
21378
21379 /**
21380-EXPORT_SYMBOL(atomic64_read);
21381+ * atomic64_unchecked_set - set atomic64 variable
21382+ * @ptr: pointer to type atomic64_unchecked_t
21383+ * @new_val: value to assign
21384+ *
21385+ * Atomically sets the value of @ptr to @new_val.
21386+ */
21387+void atomic64_set_unchecked(atomic64_unchecked_t *ptr, u64 new_val)
21388+{
21389+ atomic64_xchg_unchecked(ptr, new_val);
21390+}
21391+EXPORT_SYMBOL(atomic64_set_unchecked);
21392+
21393+/**
21394 * atomic64_add_return - add and return
21395 * @delta: integer value to add
21396 * @ptr: pointer to type atomic64_t
21397@@ -99,24 +147,72 @@ noinline u64 atomic64_add_return(u64 delta, atomic64_t *ptr)
21398 }
21399 EXPORT_SYMBOL(atomic64_add_return);
21400
21401+/**
21402+ * atomic64_add_return_unchecked - add and return
21403+ * @delta: integer value to add
21404+ * @ptr: pointer to type atomic64_unchecked_t
21405+ *
21406+ * Atomically adds @delta to @ptr and returns @delta + *@ptr
21407+ */
21408+noinline u64 atomic64_add_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21409+{
21410+ /*
21411+ * Try first with a (possibly incorrect) assumption about
21412+ * what we have there. We'll do two loops most likely,
21413+ * but we'll get an ownership MESI transaction straight away
21414+ * instead of a read transaction followed by a
21415+ * flush-for-ownership transaction:
21416+ */
21417+ u64 old_val, new_val, real_val = 0;
21418+
21419+ do {
21420+ old_val = real_val;
21421+ new_val = old_val + delta;
21422+
21423+ real_val = atomic64_cmpxchg_unchecked(ptr, old_val, new_val);
21424+
21425+ } while (real_val != old_val);
21426+
21427+ return new_val;
21428+}
21429+EXPORT_SYMBOL(atomic64_add_return_unchecked);
21430+
21431 u64 atomic64_sub_return(u64 delta, atomic64_t *ptr)
21432 {
21433 return atomic64_add_return(-delta, ptr);
21434 }
21435 EXPORT_SYMBOL(atomic64_sub_return);
21436
21437+u64 atomic64_sub_return_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21438+{
21439+ return atomic64_add_return_unchecked(-delta, ptr);
21440+}
21441+EXPORT_SYMBOL(atomic64_sub_return_unchecked);
21442+
21443 u64 atomic64_inc_return(atomic64_t *ptr)
21444 {
21445 return atomic64_add_return(1, ptr);
21446 }
21447 EXPORT_SYMBOL(atomic64_inc_return);
21448
21449+u64 atomic64_inc_return_unchecked(atomic64_unchecked_t *ptr)
21450+{
21451+ return atomic64_add_return_unchecked(1, ptr);
21452+}
21453+EXPORT_SYMBOL(atomic64_inc_return_unchecked);
21454+
21455 u64 atomic64_dec_return(atomic64_t *ptr)
21456 {
21457 return atomic64_sub_return(1, ptr);
21458 }
21459 EXPORT_SYMBOL(atomic64_dec_return);
21460
21461+u64 atomic64_dec_return_unchecked(atomic64_unchecked_t *ptr)
21462+{
21463+ return atomic64_sub_return_unchecked(1, ptr);
21464+}
21465+EXPORT_SYMBOL(atomic64_dec_return_unchecked);
21466+
21467 /**
21468 * atomic64_add - add integer to atomic64 variable
21469 * @delta: integer value to add
21470@@ -131,6 +227,19 @@ void atomic64_add(u64 delta, atomic64_t *ptr)
21471 EXPORT_SYMBOL(atomic64_add);
21472
21473 /**
21474+ * atomic64_add_unchecked - add integer to atomic64 variable
21475+ * @delta: integer value to add
21476+ * @ptr: pointer to type atomic64_unchecked_t
21477+ *
21478+ * Atomically adds @delta to @ptr.
21479+ */
21480+void atomic64_add_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21481+{
21482+ atomic64_add_return_unchecked(delta, ptr);
21483+}
21484+EXPORT_SYMBOL(atomic64_add_unchecked);
21485+
21486+/**
21487 * atomic64_sub - subtract the atomic64 variable
21488 * @delta: integer value to subtract
21489 * @ptr: pointer to type atomic64_t
21490@@ -144,6 +253,19 @@ void atomic64_sub(u64 delta, atomic64_t *ptr)
21491 EXPORT_SYMBOL(atomic64_sub);
21492
21493 /**
21494+ * atomic64_sub_unchecked - subtract the atomic64 variable
21495+ * @delta: integer value to subtract
21496+ * @ptr: pointer to type atomic64_unchecked_t
21497+ *
21498+ * Atomically subtracts @delta from @ptr.
21499+ */
21500+void atomic64_sub_unchecked(u64 delta, atomic64_unchecked_t *ptr)
21501+{
21502+ atomic64_add_unchecked(-delta, ptr);
21503+}
21504+EXPORT_SYMBOL(atomic64_sub_unchecked);
21505+
21506+/**
21507 * atomic64_sub_and_test - subtract value from variable and test result
21508 * @delta: integer value to subtract
21509 * @ptr: pointer to type atomic64_t
21510@@ -173,6 +295,18 @@ void atomic64_inc(atomic64_t *ptr)
21511 EXPORT_SYMBOL(atomic64_inc);
21512
21513 /**
21514+ * atomic64_inc_unchecked - increment atomic64 variable
21515+ * @ptr: pointer to type atomic64_unchecked_t
21516+ *
21517+ * Atomically increments @ptr by 1.
21518+ */
21519+void atomic64_inc_unchecked(atomic64_unchecked_t *ptr)
21520+{
21521+ atomic64_add_unchecked(1, ptr);
21522+}
21523+EXPORT_SYMBOL(atomic64_inc_unchecked);
21524+
21525+/**
21526 * atomic64_dec - decrement atomic64 variable
21527 * @ptr: pointer to type atomic64_t
21528 *
21529@@ -185,6 +319,18 @@ void atomic64_dec(atomic64_t *ptr)
21530 EXPORT_SYMBOL(atomic64_dec);
21531
21532 /**
21533+ * atomic64_dec_unchecked - decrement atomic64 variable
21534+ * @ptr: pointer to type atomic64_unchecked_t
21535+ *
21536+ * Atomically decrements @ptr by 1.
21537+ */
21538+void atomic64_dec_unchecked(atomic64_unchecked_t *ptr)
21539+{
21540+ atomic64_sub_unchecked(1, ptr);
21541+}
21542+EXPORT_SYMBOL(atomic64_dec_unchecked);
21543+
21544+/**
21545 * atomic64_dec_and_test - decrement and test
21546 * @ptr: pointer to type atomic64_t
21547 *
21548diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21549index adbccd0..98f96c8 100644
21550--- a/arch/x86/lib/checksum_32.S
21551+++ b/arch/x86/lib/checksum_32.S
21552@@ -28,7 +28,8 @@
21553 #include <linux/linkage.h>
21554 #include <asm/dwarf2.h>
21555 #include <asm/errno.h>
21556-
21557+#include <asm/segment.h>
21558+
21559 /*
21560 * computes a partial checksum, e.g. for TCP/UDP fragments
21561 */
21562@@ -304,9 +305,28 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21563
21564 #define ARGBASE 16
21565 #define FP 12
21566-
21567-ENTRY(csum_partial_copy_generic)
21568+
21569+ENTRY(csum_partial_copy_generic_to_user)
21570 CFI_STARTPROC
21571+
21572+#ifdef CONFIG_PAX_MEMORY_UDEREF
21573+ pushl %gs
21574+ CFI_ADJUST_CFA_OFFSET 4
21575+ popl %es
21576+ CFI_ADJUST_CFA_OFFSET -4
21577+ jmp csum_partial_copy_generic
21578+#endif
21579+
21580+ENTRY(csum_partial_copy_generic_from_user)
21581+
21582+#ifdef CONFIG_PAX_MEMORY_UDEREF
21583+ pushl %gs
21584+ CFI_ADJUST_CFA_OFFSET 4
21585+ popl %ds
21586+ CFI_ADJUST_CFA_OFFSET -4
21587+#endif
21588+
21589+ENTRY(csum_partial_copy_generic)
21590 subl $4,%esp
21591 CFI_ADJUST_CFA_OFFSET 4
21592 pushl %edi
21593@@ -331,7 +351,7 @@ ENTRY(csum_partial_copy_generic)
21594 jmp 4f
21595 SRC(1: movw (%esi), %bx )
21596 addl $2, %esi
21597-DST( movw %bx, (%edi) )
21598+DST( movw %bx, %es:(%edi) )
21599 addl $2, %edi
21600 addw %bx, %ax
21601 adcl $0, %eax
21602@@ -343,30 +363,30 @@ DST( movw %bx, (%edi) )
21603 SRC(1: movl (%esi), %ebx )
21604 SRC( movl 4(%esi), %edx )
21605 adcl %ebx, %eax
21606-DST( movl %ebx, (%edi) )
21607+DST( movl %ebx, %es:(%edi) )
21608 adcl %edx, %eax
21609-DST( movl %edx, 4(%edi) )
21610+DST( movl %edx, %es:4(%edi) )
21611
21612 SRC( movl 8(%esi), %ebx )
21613 SRC( movl 12(%esi), %edx )
21614 adcl %ebx, %eax
21615-DST( movl %ebx, 8(%edi) )
21616+DST( movl %ebx, %es:8(%edi) )
21617 adcl %edx, %eax
21618-DST( movl %edx, 12(%edi) )
21619+DST( movl %edx, %es:12(%edi) )
21620
21621 SRC( movl 16(%esi), %ebx )
21622 SRC( movl 20(%esi), %edx )
21623 adcl %ebx, %eax
21624-DST( movl %ebx, 16(%edi) )
21625+DST( movl %ebx, %es:16(%edi) )
21626 adcl %edx, %eax
21627-DST( movl %edx, 20(%edi) )
21628+DST( movl %edx, %es:20(%edi) )
21629
21630 SRC( movl 24(%esi), %ebx )
21631 SRC( movl 28(%esi), %edx )
21632 adcl %ebx, %eax
21633-DST( movl %ebx, 24(%edi) )
21634+DST( movl %ebx, %es:24(%edi) )
21635 adcl %edx, %eax
21636-DST( movl %edx, 28(%edi) )
21637+DST( movl %edx, %es:28(%edi) )
21638
21639 lea 32(%esi), %esi
21640 lea 32(%edi), %edi
21641@@ -380,7 +400,7 @@ DST( movl %edx, 28(%edi) )
21642 shrl $2, %edx # This clears CF
21643 SRC(3: movl (%esi), %ebx )
21644 adcl %ebx, %eax
21645-DST( movl %ebx, (%edi) )
21646+DST( movl %ebx, %es:(%edi) )
21647 lea 4(%esi), %esi
21648 lea 4(%edi), %edi
21649 dec %edx
21650@@ -392,12 +412,12 @@ DST( movl %ebx, (%edi) )
21651 jb 5f
21652 SRC( movw (%esi), %cx )
21653 leal 2(%esi), %esi
21654-DST( movw %cx, (%edi) )
21655+DST( movw %cx, %es:(%edi) )
21656 leal 2(%edi), %edi
21657 je 6f
21658 shll $16,%ecx
21659 SRC(5: movb (%esi), %cl )
21660-DST( movb %cl, (%edi) )
21661+DST( movb %cl, %es:(%edi) )
21662 6: addl %ecx, %eax
21663 adcl $0, %eax
21664 7:
21665@@ -408,7 +428,7 @@ DST( movb %cl, (%edi) )
21666
21667 6001:
21668 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21669- movl $-EFAULT, (%ebx)
21670+ movl $-EFAULT, %ss:(%ebx)
21671
21672 # zero the complete destination - computing the rest
21673 # is too much work
21674@@ -421,11 +441,19 @@ DST( movb %cl, (%edi) )
21675
21676 6002:
21677 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21678- movl $-EFAULT,(%ebx)
21679+ movl $-EFAULT,%ss:(%ebx)
21680 jmp 5000b
21681
21682 .previous
21683
21684+ pushl %ss
21685+ CFI_ADJUST_CFA_OFFSET 4
21686+ popl %ds
21687+ CFI_ADJUST_CFA_OFFSET -4
21688+ pushl %ss
21689+ CFI_ADJUST_CFA_OFFSET 4
21690+ popl %es
21691+ CFI_ADJUST_CFA_OFFSET -4
21692 popl %ebx
21693 CFI_ADJUST_CFA_OFFSET -4
21694 CFI_RESTORE ebx
21695@@ -439,26 +467,47 @@ DST( movb %cl, (%edi) )
21696 CFI_ADJUST_CFA_OFFSET -4
21697 ret
21698 CFI_ENDPROC
21699-ENDPROC(csum_partial_copy_generic)
21700+ENDPROC(csum_partial_copy_generic_to_user)
21701
21702 #else
21703
21704 /* Version for PentiumII/PPro */
21705
21706 #define ROUND1(x) \
21707+ nop; nop; nop; \
21708 SRC(movl x(%esi), %ebx ) ; \
21709 addl %ebx, %eax ; \
21710- DST(movl %ebx, x(%edi) ) ;
21711+ DST(movl %ebx, %es:x(%edi)) ;
21712
21713 #define ROUND(x) \
21714+ nop; nop; nop; \
21715 SRC(movl x(%esi), %ebx ) ; \
21716 adcl %ebx, %eax ; \
21717- DST(movl %ebx, x(%edi) ) ;
21718+ DST(movl %ebx, %es:x(%edi)) ;
21719
21720 #define ARGBASE 12
21721-
21722-ENTRY(csum_partial_copy_generic)
21723+
21724+ENTRY(csum_partial_copy_generic_to_user)
21725 CFI_STARTPROC
21726+
21727+#ifdef CONFIG_PAX_MEMORY_UDEREF
21728+ pushl %gs
21729+ CFI_ADJUST_CFA_OFFSET 4
21730+ popl %es
21731+ CFI_ADJUST_CFA_OFFSET -4
21732+ jmp csum_partial_copy_generic
21733+#endif
21734+
21735+ENTRY(csum_partial_copy_generic_from_user)
21736+
21737+#ifdef CONFIG_PAX_MEMORY_UDEREF
21738+ pushl %gs
21739+ CFI_ADJUST_CFA_OFFSET 4
21740+ popl %ds
21741+ CFI_ADJUST_CFA_OFFSET -4
21742+#endif
21743+
21744+ENTRY(csum_partial_copy_generic)
21745 pushl %ebx
21746 CFI_ADJUST_CFA_OFFSET 4
21747 CFI_REL_OFFSET ebx, 0
21748@@ -482,7 +531,7 @@ ENTRY(csum_partial_copy_generic)
21749 subl %ebx, %edi
21750 lea -1(%esi),%edx
21751 andl $-32,%edx
21752- lea 3f(%ebx,%ebx), %ebx
21753+ lea 3f(%ebx,%ebx,2), %ebx
21754 testl %esi, %esi
21755 jmp *%ebx
21756 1: addl $64,%esi
21757@@ -503,19 +552,19 @@ ENTRY(csum_partial_copy_generic)
21758 jb 5f
21759 SRC( movw (%esi), %dx )
21760 leal 2(%esi), %esi
21761-DST( movw %dx, (%edi) )
21762+DST( movw %dx, %es:(%edi) )
21763 leal 2(%edi), %edi
21764 je 6f
21765 shll $16,%edx
21766 5:
21767 SRC( movb (%esi), %dl )
21768-DST( movb %dl, (%edi) )
21769+DST( movb %dl, %es:(%edi) )
21770 6: addl %edx, %eax
21771 adcl $0, %eax
21772 7:
21773 .section .fixup, "ax"
21774 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21775- movl $-EFAULT, (%ebx)
21776+ movl $-EFAULT, %ss:(%ebx)
21777 # zero the complete destination (computing the rest is too much work)
21778 movl ARGBASE+8(%esp),%edi # dst
21779 movl ARGBASE+12(%esp),%ecx # len
21780@@ -523,10 +572,21 @@ DST( movb %dl, (%edi) )
21781 rep; stosb
21782 jmp 7b
21783 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21784- movl $-EFAULT, (%ebx)
21785+ movl $-EFAULT, %ss:(%ebx)
21786 jmp 7b
21787 .previous
21788
21789+#ifdef CONFIG_PAX_MEMORY_UDEREF
21790+ pushl %ss
21791+ CFI_ADJUST_CFA_OFFSET 4
21792+ popl %ds
21793+ CFI_ADJUST_CFA_OFFSET -4
21794+ pushl %ss
21795+ CFI_ADJUST_CFA_OFFSET 4
21796+ popl %es
21797+ CFI_ADJUST_CFA_OFFSET -4
21798+#endif
21799+
21800 popl %esi
21801 CFI_ADJUST_CFA_OFFSET -4
21802 CFI_RESTORE esi
21803@@ -538,7 +598,7 @@ DST( movb %dl, (%edi) )
21804 CFI_RESTORE ebx
21805 ret
21806 CFI_ENDPROC
21807-ENDPROC(csum_partial_copy_generic)
21808+ENDPROC(csum_partial_copy_generic_to_user)
21809
21810 #undef ROUND
21811 #undef ROUND1
21812diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21813index ebeafcc..1e3a402 100644
21814--- a/arch/x86/lib/clear_page_64.S
21815+++ b/arch/x86/lib/clear_page_64.S
21816@@ -1,5 +1,6 @@
21817 #include <linux/linkage.h>
21818 #include <asm/dwarf2.h>
21819+#include <asm/alternative-asm.h>
21820
21821 /*
21822 * Zero a page.
21823@@ -10,6 +11,7 @@ ENTRY(clear_page_c)
21824 movl $4096/8,%ecx
21825 xorl %eax,%eax
21826 rep stosq
21827+ pax_force_retaddr
21828 ret
21829 CFI_ENDPROC
21830 ENDPROC(clear_page_c)
21831@@ -33,6 +35,7 @@ ENTRY(clear_page)
21832 leaq 64(%rdi),%rdi
21833 jnz .Lloop
21834 nop
21835+ pax_force_retaddr
21836 ret
21837 CFI_ENDPROC
21838 .Lclear_page_end:
21839@@ -43,7 +46,7 @@ ENDPROC(clear_page)
21840
21841 #include <asm/cpufeature.h>
21842
21843- .section .altinstr_replacement,"ax"
21844+ .section .altinstr_replacement,"a"
21845 1: .byte 0xeb /* jmp <disp8> */
21846 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21847 2:
21848diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21849index 727a5d4..333818a 100644
21850--- a/arch/x86/lib/copy_page_64.S
21851+++ b/arch/x86/lib/copy_page_64.S
21852@@ -2,12 +2,14 @@
21853
21854 #include <linux/linkage.h>
21855 #include <asm/dwarf2.h>
21856+#include <asm/alternative-asm.h>
21857
21858 ALIGN
21859 copy_page_c:
21860 CFI_STARTPROC
21861 movl $4096/8,%ecx
21862 rep movsq
21863+ pax_force_retaddr
21864 ret
21865 CFI_ENDPROC
21866 ENDPROC(copy_page_c)
21867@@ -38,7 +40,7 @@ ENTRY(copy_page)
21868 movq 16 (%rsi), %rdx
21869 movq 24 (%rsi), %r8
21870 movq 32 (%rsi), %r9
21871- movq 40 (%rsi), %r10
21872+ movq 40 (%rsi), %r13
21873 movq 48 (%rsi), %r11
21874 movq 56 (%rsi), %r12
21875
21876@@ -49,7 +51,7 @@ ENTRY(copy_page)
21877 movq %rdx, 16 (%rdi)
21878 movq %r8, 24 (%rdi)
21879 movq %r9, 32 (%rdi)
21880- movq %r10, 40 (%rdi)
21881+ movq %r13, 40 (%rdi)
21882 movq %r11, 48 (%rdi)
21883 movq %r12, 56 (%rdi)
21884
21885@@ -68,7 +70,7 @@ ENTRY(copy_page)
21886 movq 16 (%rsi), %rdx
21887 movq 24 (%rsi), %r8
21888 movq 32 (%rsi), %r9
21889- movq 40 (%rsi), %r10
21890+ movq 40 (%rsi), %r13
21891 movq 48 (%rsi), %r11
21892 movq 56 (%rsi), %r12
21893
21894@@ -77,7 +79,7 @@ ENTRY(copy_page)
21895 movq %rdx, 16 (%rdi)
21896 movq %r8, 24 (%rdi)
21897 movq %r9, 32 (%rdi)
21898- movq %r10, 40 (%rdi)
21899+ movq %r13, 40 (%rdi)
21900 movq %r11, 48 (%rdi)
21901 movq %r12, 56 (%rdi)
21902
21903@@ -94,6 +96,7 @@ ENTRY(copy_page)
21904 CFI_RESTORE r13
21905 addq $3*8,%rsp
21906 CFI_ADJUST_CFA_OFFSET -3*8
21907+ pax_force_retaddr
21908 ret
21909 .Lcopy_page_end:
21910 CFI_ENDPROC
21911@@ -104,7 +107,7 @@ ENDPROC(copy_page)
21912
21913 #include <asm/cpufeature.h>
21914
21915- .section .altinstr_replacement,"ax"
21916+ .section .altinstr_replacement,"a"
21917 1: .byte 0xeb /* jmp <disp8> */
21918 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21919 2:
21920diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21921index af8debd..40c75f3 100644
21922--- a/arch/x86/lib/copy_user_64.S
21923+++ b/arch/x86/lib/copy_user_64.S
21924@@ -15,13 +15,15 @@
21925 #include <asm/asm-offsets.h>
21926 #include <asm/thread_info.h>
21927 #include <asm/cpufeature.h>
21928+#include <asm/pgtable.h>
21929+#include <asm/alternative-asm.h>
21930
21931 .macro ALTERNATIVE_JUMP feature,orig,alt
21932 0:
21933 .byte 0xe9 /* 32bit jump */
21934 .long \orig-1f /* by default jump to orig */
21935 1:
21936- .section .altinstr_replacement,"ax"
21937+ .section .altinstr_replacement,"a"
21938 2: .byte 0xe9 /* near jump with 32bit immediate */
21939 .long \alt-1b /* offset */ /* or alternatively to alt */
21940 .previous
21941@@ -64,55 +66,26 @@
21942 #endif
21943 .endm
21944
21945-/* Standard copy_to_user with segment limit checking */
21946-ENTRY(copy_to_user)
21947- CFI_STARTPROC
21948- GET_THREAD_INFO(%rax)
21949- movq %rdi,%rcx
21950- addq %rdx,%rcx
21951- jc bad_to_user
21952- cmpq TI_addr_limit(%rax),%rcx
21953- ja bad_to_user
21954- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21955- CFI_ENDPROC
21956-ENDPROC(copy_to_user)
21957-
21958-/* Standard copy_from_user with segment limit checking */
21959-ENTRY(copy_from_user)
21960- CFI_STARTPROC
21961- GET_THREAD_INFO(%rax)
21962- movq %rsi,%rcx
21963- addq %rdx,%rcx
21964- jc bad_from_user
21965- cmpq TI_addr_limit(%rax),%rcx
21966- ja bad_from_user
21967- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21968- CFI_ENDPROC
21969-ENDPROC(copy_from_user)
21970-
21971 ENTRY(copy_user_generic)
21972 CFI_STARTPROC
21973 ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21974 CFI_ENDPROC
21975 ENDPROC(copy_user_generic)
21976
21977-ENTRY(__copy_from_user_inatomic)
21978- CFI_STARTPROC
21979- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,copy_user_generic_unrolled,copy_user_generic_string
21980- CFI_ENDPROC
21981-ENDPROC(__copy_from_user_inatomic)
21982-
21983 .section .fixup,"ax"
21984 /* must zero dest */
21985 ENTRY(bad_from_user)
21986 bad_from_user:
21987 CFI_STARTPROC
21988+ testl %edx,%edx
21989+ js bad_to_user
21990 movl %edx,%ecx
21991 xorl %eax,%eax
21992 rep
21993 stosb
21994 bad_to_user:
21995 movl %edx,%eax
21996+ pax_force_retaddr
21997 ret
21998 CFI_ENDPROC
21999 ENDPROC(bad_from_user)
22000@@ -142,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
22001 jz 17f
22002 1: movq (%rsi),%r8
22003 2: movq 1*8(%rsi),%r9
22004-3: movq 2*8(%rsi),%r10
22005+3: movq 2*8(%rsi),%rax
22006 4: movq 3*8(%rsi),%r11
22007 5: movq %r8,(%rdi)
22008 6: movq %r9,1*8(%rdi)
22009-7: movq %r10,2*8(%rdi)
22010+7: movq %rax,2*8(%rdi)
22011 8: movq %r11,3*8(%rdi)
22012 9: movq 4*8(%rsi),%r8
22013 10: movq 5*8(%rsi),%r9
22014-11: movq 6*8(%rsi),%r10
22015+11: movq 6*8(%rsi),%rax
22016 12: movq 7*8(%rsi),%r11
22017 13: movq %r8,4*8(%rdi)
22018 14: movq %r9,5*8(%rdi)
22019-15: movq %r10,6*8(%rdi)
22020+15: movq %rax,6*8(%rdi)
22021 16: movq %r11,7*8(%rdi)
22022 leaq 64(%rsi),%rsi
22023 leaq 64(%rdi),%rdi
22024@@ -180,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
22025 decl %ecx
22026 jnz 21b
22027 23: xor %eax,%eax
22028+ pax_force_retaddr
22029 ret
22030
22031 .section .fixup,"ax"
22032@@ -252,6 +226,7 @@ ENTRY(copy_user_generic_string)
22033 3: rep
22034 movsb
22035 4: xorl %eax,%eax
22036+ pax_force_retaddr
22037 ret
22038
22039 .section .fixup,"ax"
22040diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
22041index cb0c112..e3a6895 100644
22042--- a/arch/x86/lib/copy_user_nocache_64.S
22043+++ b/arch/x86/lib/copy_user_nocache_64.S
22044@@ -8,12 +8,14 @@
22045
22046 #include <linux/linkage.h>
22047 #include <asm/dwarf2.h>
22048+#include <asm/alternative-asm.h>
22049
22050 #define FIX_ALIGNMENT 1
22051
22052 #include <asm/current.h>
22053 #include <asm/asm-offsets.h>
22054 #include <asm/thread_info.h>
22055+#include <asm/pgtable.h>
22056
22057 .macro ALIGN_DESTINATION
22058 #ifdef FIX_ALIGNMENT
22059@@ -50,6 +52,15 @@
22060 */
22061 ENTRY(__copy_user_nocache)
22062 CFI_STARTPROC
22063+
22064+#ifdef CONFIG_PAX_MEMORY_UDEREF
22065+ mov $PAX_USER_SHADOW_BASE,%rcx
22066+ cmp %rcx,%rsi
22067+ jae 1f
22068+ add %rcx,%rsi
22069+1:
22070+#endif
22071+
22072 cmpl $8,%edx
22073 jb 20f /* less then 8 bytes, go to byte copy loop */
22074 ALIGN_DESTINATION
22075@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
22076 jz 17f
22077 1: movq (%rsi),%r8
22078 2: movq 1*8(%rsi),%r9
22079-3: movq 2*8(%rsi),%r10
22080+3: movq 2*8(%rsi),%rax
22081 4: movq 3*8(%rsi),%r11
22082 5: movnti %r8,(%rdi)
22083 6: movnti %r9,1*8(%rdi)
22084-7: movnti %r10,2*8(%rdi)
22085+7: movnti %rax,2*8(%rdi)
22086 8: movnti %r11,3*8(%rdi)
22087 9: movq 4*8(%rsi),%r8
22088 10: movq 5*8(%rsi),%r9
22089-11: movq 6*8(%rsi),%r10
22090+11: movq 6*8(%rsi),%rax
22091 12: movq 7*8(%rsi),%r11
22092 13: movnti %r8,4*8(%rdi)
22093 14: movnti %r9,5*8(%rdi)
22094-15: movnti %r10,6*8(%rdi)
22095+15: movnti %rax,6*8(%rdi)
22096 16: movnti %r11,7*8(%rdi)
22097 leaq 64(%rsi),%rsi
22098 leaq 64(%rdi),%rdi
22099@@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
22100 jnz 21b
22101 23: xorl %eax,%eax
22102 sfence
22103+ pax_force_retaddr
22104 ret
22105
22106 .section .fixup,"ax"
22107diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
22108index f0dba36..48cb4d6 100644
22109--- a/arch/x86/lib/csum-copy_64.S
22110+++ b/arch/x86/lib/csum-copy_64.S
22111@@ -8,6 +8,7 @@
22112 #include <linux/linkage.h>
22113 #include <asm/dwarf2.h>
22114 #include <asm/errno.h>
22115+#include <asm/alternative-asm.h>
22116
22117 /*
22118 * Checksum copy with exception handling.
22119@@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
22120 CFI_RESTORE rbp
22121 addq $7*8,%rsp
22122 CFI_ADJUST_CFA_OFFSET -7*8
22123+ pax_force_retaddr 0, 1
22124 ret
22125 CFI_RESTORE_STATE
22126
22127diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
22128index 459b58a..9570bc7 100644
22129--- a/arch/x86/lib/csum-wrappers_64.c
22130+++ b/arch/x86/lib/csum-wrappers_64.c
22131@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
22132 len -= 2;
22133 }
22134 }
22135- isum = csum_partial_copy_generic((__force const void *)src,
22136+
22137+#ifdef CONFIG_PAX_MEMORY_UDEREF
22138+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
22139+ src += PAX_USER_SHADOW_BASE;
22140+#endif
22141+
22142+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
22143 dst, len, isum, errp, NULL);
22144 if (unlikely(*errp))
22145 goto out_err;
22146@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
22147 }
22148
22149 *errp = 0;
22150- return csum_partial_copy_generic(src, (void __force *)dst,
22151+
22152+#ifdef CONFIG_PAX_MEMORY_UDEREF
22153+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
22154+ dst += PAX_USER_SHADOW_BASE;
22155+#endif
22156+
22157+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
22158 len, isum, NULL, errp);
22159 }
22160 EXPORT_SYMBOL(csum_partial_copy_to_user);
22161diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
22162index 51f1504..ddac4c1 100644
22163--- a/arch/x86/lib/getuser.S
22164+++ b/arch/x86/lib/getuser.S
22165@@ -33,15 +33,38 @@
22166 #include <asm/asm-offsets.h>
22167 #include <asm/thread_info.h>
22168 #include <asm/asm.h>
22169+#include <asm/segment.h>
22170+#include <asm/pgtable.h>
22171+#include <asm/alternative-asm.h>
22172+
22173+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22174+#define __copyuser_seg gs;
22175+#else
22176+#define __copyuser_seg
22177+#endif
22178
22179 .text
22180 ENTRY(__get_user_1)
22181 CFI_STARTPROC
22182+
22183+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22184 GET_THREAD_INFO(%_ASM_DX)
22185 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22186 jae bad_get_user
22187-1: movzb (%_ASM_AX),%edx
22188+
22189+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22190+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22191+ cmp %_ASM_DX,%_ASM_AX
22192+ jae 1234f
22193+ add %_ASM_DX,%_ASM_AX
22194+1234:
22195+#endif
22196+
22197+#endif
22198+
22199+1: __copyuser_seg movzb (%_ASM_AX),%edx
22200 xor %eax,%eax
22201+ pax_force_retaddr
22202 ret
22203 CFI_ENDPROC
22204 ENDPROC(__get_user_1)
22205@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
22206 ENTRY(__get_user_2)
22207 CFI_STARTPROC
22208 add $1,%_ASM_AX
22209+
22210+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22211 jc bad_get_user
22212 GET_THREAD_INFO(%_ASM_DX)
22213 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22214 jae bad_get_user
22215-2: movzwl -1(%_ASM_AX),%edx
22216+
22217+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22218+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22219+ cmp %_ASM_DX,%_ASM_AX
22220+ jae 1234f
22221+ add %_ASM_DX,%_ASM_AX
22222+1234:
22223+#endif
22224+
22225+#endif
22226+
22227+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
22228 xor %eax,%eax
22229+ pax_force_retaddr
22230 ret
22231 CFI_ENDPROC
22232 ENDPROC(__get_user_2)
22233@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
22234 ENTRY(__get_user_4)
22235 CFI_STARTPROC
22236 add $3,%_ASM_AX
22237+
22238+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22239 jc bad_get_user
22240 GET_THREAD_INFO(%_ASM_DX)
22241 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22242 jae bad_get_user
22243-3: mov -3(%_ASM_AX),%edx
22244+
22245+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22246+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22247+ cmp %_ASM_DX,%_ASM_AX
22248+ jae 1234f
22249+ add %_ASM_DX,%_ASM_AX
22250+1234:
22251+#endif
22252+
22253+#endif
22254+
22255+3: __copyuser_seg mov -3(%_ASM_AX),%edx
22256 xor %eax,%eax
22257+ pax_force_retaddr
22258 ret
22259 CFI_ENDPROC
22260 ENDPROC(__get_user_4)
22261@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
22262 GET_THREAD_INFO(%_ASM_DX)
22263 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
22264 jae bad_get_user
22265+
22266+#ifdef CONFIG_PAX_MEMORY_UDEREF
22267+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
22268+ cmp %_ASM_DX,%_ASM_AX
22269+ jae 1234f
22270+ add %_ASM_DX,%_ASM_AX
22271+1234:
22272+#endif
22273+
22274 4: movq -7(%_ASM_AX),%_ASM_DX
22275 xor %eax,%eax
22276+ pax_force_retaddr
22277 ret
22278 CFI_ENDPROC
22279 ENDPROC(__get_user_8)
22280@@ -91,6 +152,7 @@ bad_get_user:
22281 CFI_STARTPROC
22282 xor %edx,%edx
22283 mov $(-EFAULT),%_ASM_AX
22284+ pax_force_retaddr
22285 ret
22286 CFI_ENDPROC
22287 END(bad_get_user)
22288diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
22289index 05a95e7..326f2fa 100644
22290--- a/arch/x86/lib/iomap_copy_64.S
22291+++ b/arch/x86/lib/iomap_copy_64.S
22292@@ -17,6 +17,7 @@
22293
22294 #include <linux/linkage.h>
22295 #include <asm/dwarf2.h>
22296+#include <asm/alternative-asm.h>
22297
22298 /*
22299 * override generic version in lib/iomap_copy.c
22300@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
22301 CFI_STARTPROC
22302 movl %edx,%ecx
22303 rep movsd
22304+ pax_force_retaddr
22305 ret
22306 CFI_ENDPROC
22307 ENDPROC(__iowrite32_copy)
22308diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
22309index ad5441e..610e351 100644
22310--- a/arch/x86/lib/memcpy_64.S
22311+++ b/arch/x86/lib/memcpy_64.S
22312@@ -4,6 +4,7 @@
22313
22314 #include <asm/cpufeature.h>
22315 #include <asm/dwarf2.h>
22316+#include <asm/alternative-asm.h>
22317
22318 /*
22319 * memcpy - Copy a memory block.
22320@@ -34,6 +35,7 @@ memcpy_c:
22321 rep movsq
22322 movl %edx, %ecx
22323 rep movsb
22324+ pax_force_retaddr
22325 ret
22326 CFI_ENDPROC
22327 ENDPROC(memcpy_c)
22328@@ -118,6 +120,7 @@ ENTRY(memcpy)
22329 jnz .Lloop_1
22330
22331 .Lend:
22332+ pax_force_retaddr 0, 1
22333 ret
22334 CFI_ENDPROC
22335 ENDPROC(memcpy)
22336@@ -128,7 +131,7 @@ ENDPROC(__memcpy)
22337 * It is also a lot simpler. Use this when possible:
22338 */
22339
22340- .section .altinstr_replacement, "ax"
22341+ .section .altinstr_replacement, "a"
22342 1: .byte 0xeb /* jmp <disp8> */
22343 .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
22344 2:
22345diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22346index 2c59481..7e9ba4e 100644
22347--- a/arch/x86/lib/memset_64.S
22348+++ b/arch/x86/lib/memset_64.S
22349@@ -2,6 +2,7 @@
22350
22351 #include <linux/linkage.h>
22352 #include <asm/dwarf2.h>
22353+#include <asm/alternative-asm.h>
22354
22355 /*
22356 * ISO C memset - set a memory block to a byte value.
22357@@ -28,6 +29,7 @@ memset_c:
22358 movl %r8d,%ecx
22359 rep stosb
22360 movq %r9,%rax
22361+ pax_force_retaddr
22362 ret
22363 CFI_ENDPROC
22364 ENDPROC(memset_c)
22365@@ -35,13 +37,13 @@ ENDPROC(memset_c)
22366 ENTRY(memset)
22367 ENTRY(__memset)
22368 CFI_STARTPROC
22369- movq %rdi,%r10
22370 movq %rdx,%r11
22371
22372 /* expand byte value */
22373 movzbl %sil,%ecx
22374 movabs $0x0101010101010101,%rax
22375 mul %rcx /* with rax, clobbers rdx */
22376+ movq %rdi,%rdx
22377
22378 /* align dst */
22379 movl %edi,%r9d
22380@@ -95,7 +97,8 @@ ENTRY(__memset)
22381 jnz .Lloop_1
22382
22383 .Lende:
22384- movq %r10,%rax
22385+ movq %rdx,%rax
22386+ pax_force_retaddr
22387 ret
22388
22389 CFI_RESTORE_STATE
22390@@ -118,7 +121,7 @@ ENDPROC(__memset)
22391
22392 #include <asm/cpufeature.h>
22393
22394- .section .altinstr_replacement,"ax"
22395+ .section .altinstr_replacement,"a"
22396 1: .byte 0xeb /* jmp <disp8> */
22397 .byte (memset_c - memset) - (2f - 1b) /* offset */
22398 2:
22399diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22400index c9f2d9b..e7fd2c0 100644
22401--- a/arch/x86/lib/mmx_32.c
22402+++ b/arch/x86/lib/mmx_32.c
22403@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22404 {
22405 void *p;
22406 int i;
22407+ unsigned long cr0;
22408
22409 if (unlikely(in_interrupt()))
22410 return __memcpy(to, from, len);
22411@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22412 kernel_fpu_begin();
22413
22414 __asm__ __volatile__ (
22415- "1: prefetch (%0)\n" /* This set is 28 bytes */
22416- " prefetch 64(%0)\n"
22417- " prefetch 128(%0)\n"
22418- " prefetch 192(%0)\n"
22419- " prefetch 256(%0)\n"
22420+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22421+ " prefetch 64(%1)\n"
22422+ " prefetch 128(%1)\n"
22423+ " prefetch 192(%1)\n"
22424+ " prefetch 256(%1)\n"
22425 "2: \n"
22426 ".section .fixup, \"ax\"\n"
22427- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22428+ "3: \n"
22429+
22430+#ifdef CONFIG_PAX_KERNEXEC
22431+ " movl %%cr0, %0\n"
22432+ " movl %0, %%eax\n"
22433+ " andl $0xFFFEFFFF, %%eax\n"
22434+ " movl %%eax, %%cr0\n"
22435+#endif
22436+
22437+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22438+
22439+#ifdef CONFIG_PAX_KERNEXEC
22440+ " movl %0, %%cr0\n"
22441+#endif
22442+
22443 " jmp 2b\n"
22444 ".previous\n"
22445 _ASM_EXTABLE(1b, 3b)
22446- : : "r" (from));
22447+ : "=&r" (cr0) : "r" (from) : "ax");
22448
22449 for ( ; i > 5; i--) {
22450 __asm__ __volatile__ (
22451- "1: prefetch 320(%0)\n"
22452- "2: movq (%0), %%mm0\n"
22453- " movq 8(%0), %%mm1\n"
22454- " movq 16(%0), %%mm2\n"
22455- " movq 24(%0), %%mm3\n"
22456- " movq %%mm0, (%1)\n"
22457- " movq %%mm1, 8(%1)\n"
22458- " movq %%mm2, 16(%1)\n"
22459- " movq %%mm3, 24(%1)\n"
22460- " movq 32(%0), %%mm0\n"
22461- " movq 40(%0), %%mm1\n"
22462- " movq 48(%0), %%mm2\n"
22463- " movq 56(%0), %%mm3\n"
22464- " movq %%mm0, 32(%1)\n"
22465- " movq %%mm1, 40(%1)\n"
22466- " movq %%mm2, 48(%1)\n"
22467- " movq %%mm3, 56(%1)\n"
22468+ "1: prefetch 320(%1)\n"
22469+ "2: movq (%1), %%mm0\n"
22470+ " movq 8(%1), %%mm1\n"
22471+ " movq 16(%1), %%mm2\n"
22472+ " movq 24(%1), %%mm3\n"
22473+ " movq %%mm0, (%2)\n"
22474+ " movq %%mm1, 8(%2)\n"
22475+ " movq %%mm2, 16(%2)\n"
22476+ " movq %%mm3, 24(%2)\n"
22477+ " movq 32(%1), %%mm0\n"
22478+ " movq 40(%1), %%mm1\n"
22479+ " movq 48(%1), %%mm2\n"
22480+ " movq 56(%1), %%mm3\n"
22481+ " movq %%mm0, 32(%2)\n"
22482+ " movq %%mm1, 40(%2)\n"
22483+ " movq %%mm2, 48(%2)\n"
22484+ " movq %%mm3, 56(%2)\n"
22485 ".section .fixup, \"ax\"\n"
22486- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22487+ "3:\n"
22488+
22489+#ifdef CONFIG_PAX_KERNEXEC
22490+ " movl %%cr0, %0\n"
22491+ " movl %0, %%eax\n"
22492+ " andl $0xFFFEFFFF, %%eax\n"
22493+ " movl %%eax, %%cr0\n"
22494+#endif
22495+
22496+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22497+
22498+#ifdef CONFIG_PAX_KERNEXEC
22499+ " movl %0, %%cr0\n"
22500+#endif
22501+
22502 " jmp 2b\n"
22503 ".previous\n"
22504 _ASM_EXTABLE(1b, 3b)
22505- : : "r" (from), "r" (to) : "memory");
22506+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22507
22508 from += 64;
22509 to += 64;
22510@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22511 static void fast_copy_page(void *to, void *from)
22512 {
22513 int i;
22514+ unsigned long cr0;
22515
22516 kernel_fpu_begin();
22517
22518@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22519 * but that is for later. -AV
22520 */
22521 __asm__ __volatile__(
22522- "1: prefetch (%0)\n"
22523- " prefetch 64(%0)\n"
22524- " prefetch 128(%0)\n"
22525- " prefetch 192(%0)\n"
22526- " prefetch 256(%0)\n"
22527+ "1: prefetch (%1)\n"
22528+ " prefetch 64(%1)\n"
22529+ " prefetch 128(%1)\n"
22530+ " prefetch 192(%1)\n"
22531+ " prefetch 256(%1)\n"
22532 "2: \n"
22533 ".section .fixup, \"ax\"\n"
22534- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22535+ "3: \n"
22536+
22537+#ifdef CONFIG_PAX_KERNEXEC
22538+ " movl %%cr0, %0\n"
22539+ " movl %0, %%eax\n"
22540+ " andl $0xFFFEFFFF, %%eax\n"
22541+ " movl %%eax, %%cr0\n"
22542+#endif
22543+
22544+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22545+
22546+#ifdef CONFIG_PAX_KERNEXEC
22547+ " movl %0, %%cr0\n"
22548+#endif
22549+
22550 " jmp 2b\n"
22551 ".previous\n"
22552- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22553+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22554
22555 for (i = 0; i < (4096-320)/64; i++) {
22556 __asm__ __volatile__ (
22557- "1: prefetch 320(%0)\n"
22558- "2: movq (%0), %%mm0\n"
22559- " movntq %%mm0, (%1)\n"
22560- " movq 8(%0), %%mm1\n"
22561- " movntq %%mm1, 8(%1)\n"
22562- " movq 16(%0), %%mm2\n"
22563- " movntq %%mm2, 16(%1)\n"
22564- " movq 24(%0), %%mm3\n"
22565- " movntq %%mm3, 24(%1)\n"
22566- " movq 32(%0), %%mm4\n"
22567- " movntq %%mm4, 32(%1)\n"
22568- " movq 40(%0), %%mm5\n"
22569- " movntq %%mm5, 40(%1)\n"
22570- " movq 48(%0), %%mm6\n"
22571- " movntq %%mm6, 48(%1)\n"
22572- " movq 56(%0), %%mm7\n"
22573- " movntq %%mm7, 56(%1)\n"
22574+ "1: prefetch 320(%1)\n"
22575+ "2: movq (%1), %%mm0\n"
22576+ " movntq %%mm0, (%2)\n"
22577+ " movq 8(%1), %%mm1\n"
22578+ " movntq %%mm1, 8(%2)\n"
22579+ " movq 16(%1), %%mm2\n"
22580+ " movntq %%mm2, 16(%2)\n"
22581+ " movq 24(%1), %%mm3\n"
22582+ " movntq %%mm3, 24(%2)\n"
22583+ " movq 32(%1), %%mm4\n"
22584+ " movntq %%mm4, 32(%2)\n"
22585+ " movq 40(%1), %%mm5\n"
22586+ " movntq %%mm5, 40(%2)\n"
22587+ " movq 48(%1), %%mm6\n"
22588+ " movntq %%mm6, 48(%2)\n"
22589+ " movq 56(%1), %%mm7\n"
22590+ " movntq %%mm7, 56(%2)\n"
22591 ".section .fixup, \"ax\"\n"
22592- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22593+ "3:\n"
22594+
22595+#ifdef CONFIG_PAX_KERNEXEC
22596+ " movl %%cr0, %0\n"
22597+ " movl %0, %%eax\n"
22598+ " andl $0xFFFEFFFF, %%eax\n"
22599+ " movl %%eax, %%cr0\n"
22600+#endif
22601+
22602+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22603+
22604+#ifdef CONFIG_PAX_KERNEXEC
22605+ " movl %0, %%cr0\n"
22606+#endif
22607+
22608 " jmp 2b\n"
22609 ".previous\n"
22610- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22611+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22612
22613 from += 64;
22614 to += 64;
22615@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22616 static void fast_copy_page(void *to, void *from)
22617 {
22618 int i;
22619+ unsigned long cr0;
22620
22621 kernel_fpu_begin();
22622
22623 __asm__ __volatile__ (
22624- "1: prefetch (%0)\n"
22625- " prefetch 64(%0)\n"
22626- " prefetch 128(%0)\n"
22627- " prefetch 192(%0)\n"
22628- " prefetch 256(%0)\n"
22629+ "1: prefetch (%1)\n"
22630+ " prefetch 64(%1)\n"
22631+ " prefetch 128(%1)\n"
22632+ " prefetch 192(%1)\n"
22633+ " prefetch 256(%1)\n"
22634 "2: \n"
22635 ".section .fixup, \"ax\"\n"
22636- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22637+ "3: \n"
22638+
22639+#ifdef CONFIG_PAX_KERNEXEC
22640+ " movl %%cr0, %0\n"
22641+ " movl %0, %%eax\n"
22642+ " andl $0xFFFEFFFF, %%eax\n"
22643+ " movl %%eax, %%cr0\n"
22644+#endif
22645+
22646+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22647+
22648+#ifdef CONFIG_PAX_KERNEXEC
22649+ " movl %0, %%cr0\n"
22650+#endif
22651+
22652 " jmp 2b\n"
22653 ".previous\n"
22654- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22655+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22656
22657 for (i = 0; i < 4096/64; i++) {
22658 __asm__ __volatile__ (
22659- "1: prefetch 320(%0)\n"
22660- "2: movq (%0), %%mm0\n"
22661- " movq 8(%0), %%mm1\n"
22662- " movq 16(%0), %%mm2\n"
22663- " movq 24(%0), %%mm3\n"
22664- " movq %%mm0, (%1)\n"
22665- " movq %%mm1, 8(%1)\n"
22666- " movq %%mm2, 16(%1)\n"
22667- " movq %%mm3, 24(%1)\n"
22668- " movq 32(%0), %%mm0\n"
22669- " movq 40(%0), %%mm1\n"
22670- " movq 48(%0), %%mm2\n"
22671- " movq 56(%0), %%mm3\n"
22672- " movq %%mm0, 32(%1)\n"
22673- " movq %%mm1, 40(%1)\n"
22674- " movq %%mm2, 48(%1)\n"
22675- " movq %%mm3, 56(%1)\n"
22676+ "1: prefetch 320(%1)\n"
22677+ "2: movq (%1), %%mm0\n"
22678+ " movq 8(%1), %%mm1\n"
22679+ " movq 16(%1), %%mm2\n"
22680+ " movq 24(%1), %%mm3\n"
22681+ " movq %%mm0, (%2)\n"
22682+ " movq %%mm1, 8(%2)\n"
22683+ " movq %%mm2, 16(%2)\n"
22684+ " movq %%mm3, 24(%2)\n"
22685+ " movq 32(%1), %%mm0\n"
22686+ " movq 40(%1), %%mm1\n"
22687+ " movq 48(%1), %%mm2\n"
22688+ " movq 56(%1), %%mm3\n"
22689+ " movq %%mm0, 32(%2)\n"
22690+ " movq %%mm1, 40(%2)\n"
22691+ " movq %%mm2, 48(%2)\n"
22692+ " movq %%mm3, 56(%2)\n"
22693 ".section .fixup, \"ax\"\n"
22694- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22695+ "3:\n"
22696+
22697+#ifdef CONFIG_PAX_KERNEXEC
22698+ " movl %%cr0, %0\n"
22699+ " movl %0, %%eax\n"
22700+ " andl $0xFFFEFFFF, %%eax\n"
22701+ " movl %%eax, %%cr0\n"
22702+#endif
22703+
22704+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22705+
22706+#ifdef CONFIG_PAX_KERNEXEC
22707+ " movl %0, %%cr0\n"
22708+#endif
22709+
22710 " jmp 2b\n"
22711 ".previous\n"
22712 _ASM_EXTABLE(1b, 3b)
22713- : : "r" (from), "r" (to) : "memory");
22714+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22715
22716 from += 64;
22717 to += 64;
22718diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22719index 69fa106..adda88b 100644
22720--- a/arch/x86/lib/msr-reg.S
22721+++ b/arch/x86/lib/msr-reg.S
22722@@ -3,6 +3,7 @@
22723 #include <asm/dwarf2.h>
22724 #include <asm/asm.h>
22725 #include <asm/msr.h>
22726+#include <asm/alternative-asm.h>
22727
22728 #ifdef CONFIG_X86_64
22729 /*
22730@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22731 CFI_STARTPROC
22732 pushq_cfi %rbx
22733 pushq_cfi %rbp
22734- movq %rdi, %r10 /* Save pointer */
22735+ movq %rdi, %r9 /* Save pointer */
22736 xorl %r11d, %r11d /* Return value */
22737 movl (%rdi), %eax
22738 movl 4(%rdi), %ecx
22739@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22740 movl 28(%rdi), %edi
22741 CFI_REMEMBER_STATE
22742 1: \op
22743-2: movl %eax, (%r10)
22744+2: movl %eax, (%r9)
22745 movl %r11d, %eax /* Return value */
22746- movl %ecx, 4(%r10)
22747- movl %edx, 8(%r10)
22748- movl %ebx, 12(%r10)
22749- movl %ebp, 20(%r10)
22750- movl %esi, 24(%r10)
22751- movl %edi, 28(%r10)
22752+ movl %ecx, 4(%r9)
22753+ movl %edx, 8(%r9)
22754+ movl %ebx, 12(%r9)
22755+ movl %ebp, 20(%r9)
22756+ movl %esi, 24(%r9)
22757+ movl %edi, 28(%r9)
22758 popq_cfi %rbp
22759 popq_cfi %rbx
22760+ pax_force_retaddr
22761 ret
22762 3:
22763 CFI_RESTORE_STATE
22764diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22765index 36b0d15..d381858 100644
22766--- a/arch/x86/lib/putuser.S
22767+++ b/arch/x86/lib/putuser.S
22768@@ -15,7 +15,9 @@
22769 #include <asm/thread_info.h>
22770 #include <asm/errno.h>
22771 #include <asm/asm.h>
22772-
22773+#include <asm/segment.h>
22774+#include <asm/pgtable.h>
22775+#include <asm/alternative-asm.h>
22776
22777 /*
22778 * __put_user_X
22779@@ -29,52 +31,119 @@
22780 * as they get called from within inline assembly.
22781 */
22782
22783-#define ENTER CFI_STARTPROC ; \
22784- GET_THREAD_INFO(%_ASM_BX)
22785-#define EXIT ret ; \
22786+#define ENTER CFI_STARTPROC
22787+#define EXIT pax_force_retaddr; ret ; \
22788 CFI_ENDPROC
22789
22790+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22791+#define _DEST %_ASM_CX,%_ASM_BX
22792+#else
22793+#define _DEST %_ASM_CX
22794+#endif
22795+
22796+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22797+#define __copyuser_seg gs;
22798+#else
22799+#define __copyuser_seg
22800+#endif
22801+
22802 .text
22803 ENTRY(__put_user_1)
22804 ENTER
22805+
22806+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22807+ GET_THREAD_INFO(%_ASM_BX)
22808 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22809 jae bad_put_user
22810-1: movb %al,(%_ASM_CX)
22811+
22812+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22813+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22814+ cmp %_ASM_BX,%_ASM_CX
22815+ jb 1234f
22816+ xor %ebx,%ebx
22817+1234:
22818+#endif
22819+
22820+#endif
22821+
22822+1: __copyuser_seg movb %al,(_DEST)
22823 xor %eax,%eax
22824 EXIT
22825 ENDPROC(__put_user_1)
22826
22827 ENTRY(__put_user_2)
22828 ENTER
22829+
22830+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22831+ GET_THREAD_INFO(%_ASM_BX)
22832 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22833 sub $1,%_ASM_BX
22834 cmp %_ASM_BX,%_ASM_CX
22835 jae bad_put_user
22836-2: movw %ax,(%_ASM_CX)
22837+
22838+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22839+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22840+ cmp %_ASM_BX,%_ASM_CX
22841+ jb 1234f
22842+ xor %ebx,%ebx
22843+1234:
22844+#endif
22845+
22846+#endif
22847+
22848+2: __copyuser_seg movw %ax,(_DEST)
22849 xor %eax,%eax
22850 EXIT
22851 ENDPROC(__put_user_2)
22852
22853 ENTRY(__put_user_4)
22854 ENTER
22855+
22856+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22857+ GET_THREAD_INFO(%_ASM_BX)
22858 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22859 sub $3,%_ASM_BX
22860 cmp %_ASM_BX,%_ASM_CX
22861 jae bad_put_user
22862-3: movl %eax,(%_ASM_CX)
22863+
22864+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22865+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22866+ cmp %_ASM_BX,%_ASM_CX
22867+ jb 1234f
22868+ xor %ebx,%ebx
22869+1234:
22870+#endif
22871+
22872+#endif
22873+
22874+3: __copyuser_seg movl %eax,(_DEST)
22875 xor %eax,%eax
22876 EXIT
22877 ENDPROC(__put_user_4)
22878
22879 ENTRY(__put_user_8)
22880 ENTER
22881+
22882+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22883+ GET_THREAD_INFO(%_ASM_BX)
22884 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22885 sub $7,%_ASM_BX
22886 cmp %_ASM_BX,%_ASM_CX
22887 jae bad_put_user
22888-4: mov %_ASM_AX,(%_ASM_CX)
22889+
22890+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22891+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22892+ cmp %_ASM_BX,%_ASM_CX
22893+ jb 1234f
22894+ xor %ebx,%ebx
22895+1234:
22896+#endif
22897+
22898+#endif
22899+
22900+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22901 #ifdef CONFIG_X86_32
22902-5: movl %edx,4(%_ASM_CX)
22903+5: __copyuser_seg movl %edx,4(_DEST)
22904 #endif
22905 xor %eax,%eax
22906 EXIT
22907diff --git a/arch/x86/lib/rwlock_64.S b/arch/x86/lib/rwlock_64.S
22908index 05ea55f..6345b9a 100644
22909--- a/arch/x86/lib/rwlock_64.S
22910+++ b/arch/x86/lib/rwlock_64.S
22911@@ -2,6 +2,7 @@
22912
22913 #include <linux/linkage.h>
22914 #include <asm/rwlock.h>
22915+#include <asm/asm.h>
22916 #include <asm/alternative-asm.h>
22917 #include <asm/dwarf2.h>
22918
22919@@ -10,13 +11,34 @@ ENTRY(__write_lock_failed)
22920 CFI_STARTPROC
22921 LOCK_PREFIX
22922 addl $RW_LOCK_BIAS,(%rdi)
22923+
22924+#ifdef CONFIG_PAX_REFCOUNT
22925+ jno 1234f
22926+ LOCK_PREFIX
22927+ subl $RW_LOCK_BIAS,(%rdi)
22928+ int $4
22929+1234:
22930+ _ASM_EXTABLE(1234b, 1234b)
22931+#endif
22932+
22933 1: rep
22934 nop
22935 cmpl $RW_LOCK_BIAS,(%rdi)
22936 jne 1b
22937 LOCK_PREFIX
22938 subl $RW_LOCK_BIAS,(%rdi)
22939+
22940+#ifdef CONFIG_PAX_REFCOUNT
22941+ jno 1234f
22942+ LOCK_PREFIX
22943+ addl $RW_LOCK_BIAS,(%rdi)
22944+ int $4
22945+1234:
22946+ _ASM_EXTABLE(1234b, 1234b)
22947+#endif
22948+
22949 jnz __write_lock_failed
22950+ pax_force_retaddr
22951 ret
22952 CFI_ENDPROC
22953 END(__write_lock_failed)
22954@@ -26,13 +48,34 @@ ENTRY(__read_lock_failed)
22955 CFI_STARTPROC
22956 LOCK_PREFIX
22957 incl (%rdi)
22958+
22959+#ifdef CONFIG_PAX_REFCOUNT
22960+ jno 1234f
22961+ LOCK_PREFIX
22962+ decl (%rdi)
22963+ int $4
22964+1234:
22965+ _ASM_EXTABLE(1234b, 1234b)
22966+#endif
22967+
22968 1: rep
22969 nop
22970 cmpl $1,(%rdi)
22971 js 1b
22972 LOCK_PREFIX
22973 decl (%rdi)
22974+
22975+#ifdef CONFIG_PAX_REFCOUNT
22976+ jno 1234f
22977+ LOCK_PREFIX
22978+ incl (%rdi)
22979+ int $4
22980+1234:
22981+ _ASM_EXTABLE(1234b, 1234b)
22982+#endif
22983+
22984 js __read_lock_failed
22985+ pax_force_retaddr
22986 ret
22987 CFI_ENDPROC
22988 END(__read_lock_failed)
22989diff --git a/arch/x86/lib/rwsem_64.S b/arch/x86/lib/rwsem_64.S
22990index 15acecf..f768b10 100644
22991--- a/arch/x86/lib/rwsem_64.S
22992+++ b/arch/x86/lib/rwsem_64.S
22993@@ -48,6 +48,7 @@ ENTRY(call_rwsem_down_read_failed)
22994 call rwsem_down_read_failed
22995 popq %rdx
22996 restore_common_regs
22997+ pax_force_retaddr
22998 ret
22999 ENDPROC(call_rwsem_down_read_failed)
23000
23001@@ -56,6 +57,7 @@ ENTRY(call_rwsem_down_write_failed)
23002 movq %rax,%rdi
23003 call rwsem_down_write_failed
23004 restore_common_regs
23005+ pax_force_retaddr
23006 ret
23007 ENDPROC(call_rwsem_down_write_failed)
23008
23009@@ -66,7 +68,8 @@ ENTRY(call_rwsem_wake)
23010 movq %rax,%rdi
23011 call rwsem_wake
23012 restore_common_regs
23013-1: ret
23014+1: pax_force_retaddr
23015+ ret
23016 ENDPROC(call_rwsem_wake)
23017
23018 /* Fix up special calling conventions */
23019@@ -77,5 +80,6 @@ ENTRY(call_rwsem_downgrade_wake)
23020 call rwsem_downgrade_wake
23021 popq %rdx
23022 restore_common_regs
23023+ pax_force_retaddr
23024 ret
23025 ENDPROC(call_rwsem_downgrade_wake)
23026diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
23027index bf9a7d5..fb06ab5 100644
23028--- a/arch/x86/lib/thunk_64.S
23029+++ b/arch/x86/lib/thunk_64.S
23030@@ -10,7 +10,8 @@
23031 #include <asm/dwarf2.h>
23032 #include <asm/calling.h>
23033 #include <asm/rwlock.h>
23034-
23035+ #include <asm/alternative-asm.h>
23036+
23037 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
23038 .macro thunk name,func
23039 .globl \name
23040@@ -70,6 +71,7 @@
23041 SAVE_ARGS
23042 restore:
23043 RESTORE_ARGS
23044+ pax_force_retaddr
23045 ret
23046 CFI_ENDPROC
23047
23048@@ -77,5 +79,6 @@ restore:
23049 SAVE_ARGS
23050 restore_norax:
23051 RESTORE_ARGS 1
23052+ pax_force_retaddr
23053 ret
23054 CFI_ENDPROC
23055diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
23056index 1f118d4..ec4a953 100644
23057--- a/arch/x86/lib/usercopy_32.c
23058+++ b/arch/x86/lib/usercopy_32.c
23059@@ -43,7 +43,7 @@ do { \
23060 __asm__ __volatile__( \
23061 " testl %1,%1\n" \
23062 " jz 2f\n" \
23063- "0: lodsb\n" \
23064+ "0: "__copyuser_seg"lodsb\n" \
23065 " stosb\n" \
23066 " testb %%al,%%al\n" \
23067 " jz 1f\n" \
23068@@ -128,10 +128,12 @@ do { \
23069 int __d0; \
23070 might_fault(); \
23071 __asm__ __volatile__( \
23072+ __COPYUSER_SET_ES \
23073 "0: rep; stosl\n" \
23074 " movl %2,%0\n" \
23075 "1: rep; stosb\n" \
23076 "2:\n" \
23077+ __COPYUSER_RESTORE_ES \
23078 ".section .fixup,\"ax\"\n" \
23079 "3: lea 0(%2,%0,4),%0\n" \
23080 " jmp 2b\n" \
23081@@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
23082 might_fault();
23083
23084 __asm__ __volatile__(
23085+ __COPYUSER_SET_ES
23086 " testl %0, %0\n"
23087 " jz 3f\n"
23088 " andl %0,%%ecx\n"
23089@@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
23090 " subl %%ecx,%0\n"
23091 " addl %0,%%eax\n"
23092 "1:\n"
23093+ __COPYUSER_RESTORE_ES
23094 ".section .fixup,\"ax\"\n"
23095 "2: xorl %%eax,%%eax\n"
23096 " jmp 1b\n"
23097@@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
23098
23099 #ifdef CONFIG_X86_INTEL_USERCOPY
23100 static unsigned long
23101-__copy_user_intel(void __user *to, const void *from, unsigned long size)
23102+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
23103 {
23104 int d0, d1;
23105 __asm__ __volatile__(
23106@@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23107 " .align 2,0x90\n"
23108 "3: movl 0(%4), %%eax\n"
23109 "4: movl 4(%4), %%edx\n"
23110- "5: movl %%eax, 0(%3)\n"
23111- "6: movl %%edx, 4(%3)\n"
23112+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
23113+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
23114 "7: movl 8(%4), %%eax\n"
23115 "8: movl 12(%4),%%edx\n"
23116- "9: movl %%eax, 8(%3)\n"
23117- "10: movl %%edx, 12(%3)\n"
23118+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
23119+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
23120 "11: movl 16(%4), %%eax\n"
23121 "12: movl 20(%4), %%edx\n"
23122- "13: movl %%eax, 16(%3)\n"
23123- "14: movl %%edx, 20(%3)\n"
23124+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
23125+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
23126 "15: movl 24(%4), %%eax\n"
23127 "16: movl 28(%4), %%edx\n"
23128- "17: movl %%eax, 24(%3)\n"
23129- "18: movl %%edx, 28(%3)\n"
23130+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
23131+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
23132 "19: movl 32(%4), %%eax\n"
23133 "20: movl 36(%4), %%edx\n"
23134- "21: movl %%eax, 32(%3)\n"
23135- "22: movl %%edx, 36(%3)\n"
23136+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
23137+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
23138 "23: movl 40(%4), %%eax\n"
23139 "24: movl 44(%4), %%edx\n"
23140- "25: movl %%eax, 40(%3)\n"
23141- "26: movl %%edx, 44(%3)\n"
23142+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
23143+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
23144 "27: movl 48(%4), %%eax\n"
23145 "28: movl 52(%4), %%edx\n"
23146- "29: movl %%eax, 48(%3)\n"
23147- "30: movl %%edx, 52(%3)\n"
23148+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
23149+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
23150 "31: movl 56(%4), %%eax\n"
23151 "32: movl 60(%4), %%edx\n"
23152- "33: movl %%eax, 56(%3)\n"
23153- "34: movl %%edx, 60(%3)\n"
23154+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
23155+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
23156 " addl $-64, %0\n"
23157 " addl $64, %4\n"
23158 " addl $64, %3\n"
23159@@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
23160 " shrl $2, %0\n"
23161 " andl $3, %%eax\n"
23162 " cld\n"
23163+ __COPYUSER_SET_ES
23164 "99: rep; movsl\n"
23165 "36: movl %%eax, %0\n"
23166 "37: rep; movsb\n"
23167 "100:\n"
23168+ __COPYUSER_RESTORE_ES
23169+ ".section .fixup,\"ax\"\n"
23170+ "101: lea 0(%%eax,%0,4),%0\n"
23171+ " jmp 100b\n"
23172+ ".previous\n"
23173+ ".section __ex_table,\"a\"\n"
23174+ " .align 4\n"
23175+ " .long 1b,100b\n"
23176+ " .long 2b,100b\n"
23177+ " .long 3b,100b\n"
23178+ " .long 4b,100b\n"
23179+ " .long 5b,100b\n"
23180+ " .long 6b,100b\n"
23181+ " .long 7b,100b\n"
23182+ " .long 8b,100b\n"
23183+ " .long 9b,100b\n"
23184+ " .long 10b,100b\n"
23185+ " .long 11b,100b\n"
23186+ " .long 12b,100b\n"
23187+ " .long 13b,100b\n"
23188+ " .long 14b,100b\n"
23189+ " .long 15b,100b\n"
23190+ " .long 16b,100b\n"
23191+ " .long 17b,100b\n"
23192+ " .long 18b,100b\n"
23193+ " .long 19b,100b\n"
23194+ " .long 20b,100b\n"
23195+ " .long 21b,100b\n"
23196+ " .long 22b,100b\n"
23197+ " .long 23b,100b\n"
23198+ " .long 24b,100b\n"
23199+ " .long 25b,100b\n"
23200+ " .long 26b,100b\n"
23201+ " .long 27b,100b\n"
23202+ " .long 28b,100b\n"
23203+ " .long 29b,100b\n"
23204+ " .long 30b,100b\n"
23205+ " .long 31b,100b\n"
23206+ " .long 32b,100b\n"
23207+ " .long 33b,100b\n"
23208+ " .long 34b,100b\n"
23209+ " .long 35b,100b\n"
23210+ " .long 36b,100b\n"
23211+ " .long 37b,100b\n"
23212+ " .long 99b,101b\n"
23213+ ".previous"
23214+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
23215+ : "1"(to), "2"(from), "0"(size)
23216+ : "eax", "edx", "memory");
23217+ return size;
23218+}
23219+
23220+static unsigned long
23221+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
23222+{
23223+ int d0, d1;
23224+ __asm__ __volatile__(
23225+ " .align 2,0x90\n"
23226+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
23227+ " cmpl $67, %0\n"
23228+ " jbe 3f\n"
23229+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
23230+ " .align 2,0x90\n"
23231+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
23232+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
23233+ "5: movl %%eax, 0(%3)\n"
23234+ "6: movl %%edx, 4(%3)\n"
23235+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
23236+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
23237+ "9: movl %%eax, 8(%3)\n"
23238+ "10: movl %%edx, 12(%3)\n"
23239+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23240+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23241+ "13: movl %%eax, 16(%3)\n"
23242+ "14: movl %%edx, 20(%3)\n"
23243+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23244+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23245+ "17: movl %%eax, 24(%3)\n"
23246+ "18: movl %%edx, 28(%3)\n"
23247+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23248+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23249+ "21: movl %%eax, 32(%3)\n"
23250+ "22: movl %%edx, 36(%3)\n"
23251+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23252+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23253+ "25: movl %%eax, 40(%3)\n"
23254+ "26: movl %%edx, 44(%3)\n"
23255+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23256+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23257+ "29: movl %%eax, 48(%3)\n"
23258+ "30: movl %%edx, 52(%3)\n"
23259+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23260+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23261+ "33: movl %%eax, 56(%3)\n"
23262+ "34: movl %%edx, 60(%3)\n"
23263+ " addl $-64, %0\n"
23264+ " addl $64, %4\n"
23265+ " addl $64, %3\n"
23266+ " cmpl $63, %0\n"
23267+ " ja 1b\n"
23268+ "35: movl %0, %%eax\n"
23269+ " shrl $2, %0\n"
23270+ " andl $3, %%eax\n"
23271+ " cld\n"
23272+ "99: rep; "__copyuser_seg" movsl\n"
23273+ "36: movl %%eax, %0\n"
23274+ "37: rep; "__copyuser_seg" movsb\n"
23275+ "100:\n"
23276 ".section .fixup,\"ax\"\n"
23277 "101: lea 0(%%eax,%0,4),%0\n"
23278 " jmp 100b\n"
23279@@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23280 int d0, d1;
23281 __asm__ __volatile__(
23282 " .align 2,0x90\n"
23283- "0: movl 32(%4), %%eax\n"
23284+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23285 " cmpl $67, %0\n"
23286 " jbe 2f\n"
23287- "1: movl 64(%4), %%eax\n"
23288+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23289 " .align 2,0x90\n"
23290- "2: movl 0(%4), %%eax\n"
23291- "21: movl 4(%4), %%edx\n"
23292+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23293+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23294 " movl %%eax, 0(%3)\n"
23295 " movl %%edx, 4(%3)\n"
23296- "3: movl 8(%4), %%eax\n"
23297- "31: movl 12(%4),%%edx\n"
23298+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23299+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23300 " movl %%eax, 8(%3)\n"
23301 " movl %%edx, 12(%3)\n"
23302- "4: movl 16(%4), %%eax\n"
23303- "41: movl 20(%4), %%edx\n"
23304+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23305+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23306 " movl %%eax, 16(%3)\n"
23307 " movl %%edx, 20(%3)\n"
23308- "10: movl 24(%4), %%eax\n"
23309- "51: movl 28(%4), %%edx\n"
23310+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23311+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23312 " movl %%eax, 24(%3)\n"
23313 " movl %%edx, 28(%3)\n"
23314- "11: movl 32(%4), %%eax\n"
23315- "61: movl 36(%4), %%edx\n"
23316+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23317+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23318 " movl %%eax, 32(%3)\n"
23319 " movl %%edx, 36(%3)\n"
23320- "12: movl 40(%4), %%eax\n"
23321- "71: movl 44(%4), %%edx\n"
23322+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23323+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23324 " movl %%eax, 40(%3)\n"
23325 " movl %%edx, 44(%3)\n"
23326- "13: movl 48(%4), %%eax\n"
23327- "81: movl 52(%4), %%edx\n"
23328+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23329+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23330 " movl %%eax, 48(%3)\n"
23331 " movl %%edx, 52(%3)\n"
23332- "14: movl 56(%4), %%eax\n"
23333- "91: movl 60(%4), %%edx\n"
23334+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23335+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23336 " movl %%eax, 56(%3)\n"
23337 " movl %%edx, 60(%3)\n"
23338 " addl $-64, %0\n"
23339@@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23340 " shrl $2, %0\n"
23341 " andl $3, %%eax\n"
23342 " cld\n"
23343- "6: rep; movsl\n"
23344+ "6: rep; "__copyuser_seg" movsl\n"
23345 " movl %%eax,%0\n"
23346- "7: rep; movsb\n"
23347+ "7: rep; "__copyuser_seg" movsb\n"
23348 "8:\n"
23349 ".section .fixup,\"ax\"\n"
23350 "9: lea 0(%%eax,%0,4),%0\n"
23351@@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23352
23353 __asm__ __volatile__(
23354 " .align 2,0x90\n"
23355- "0: movl 32(%4), %%eax\n"
23356+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23357 " cmpl $67, %0\n"
23358 " jbe 2f\n"
23359- "1: movl 64(%4), %%eax\n"
23360+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23361 " .align 2,0x90\n"
23362- "2: movl 0(%4), %%eax\n"
23363- "21: movl 4(%4), %%edx\n"
23364+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23365+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23366 " movnti %%eax, 0(%3)\n"
23367 " movnti %%edx, 4(%3)\n"
23368- "3: movl 8(%4), %%eax\n"
23369- "31: movl 12(%4),%%edx\n"
23370+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23371+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23372 " movnti %%eax, 8(%3)\n"
23373 " movnti %%edx, 12(%3)\n"
23374- "4: movl 16(%4), %%eax\n"
23375- "41: movl 20(%4), %%edx\n"
23376+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23377+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23378 " movnti %%eax, 16(%3)\n"
23379 " movnti %%edx, 20(%3)\n"
23380- "10: movl 24(%4), %%eax\n"
23381- "51: movl 28(%4), %%edx\n"
23382+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23383+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23384 " movnti %%eax, 24(%3)\n"
23385 " movnti %%edx, 28(%3)\n"
23386- "11: movl 32(%4), %%eax\n"
23387- "61: movl 36(%4), %%edx\n"
23388+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23389+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23390 " movnti %%eax, 32(%3)\n"
23391 " movnti %%edx, 36(%3)\n"
23392- "12: movl 40(%4), %%eax\n"
23393- "71: movl 44(%4), %%edx\n"
23394+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23395+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23396 " movnti %%eax, 40(%3)\n"
23397 " movnti %%edx, 44(%3)\n"
23398- "13: movl 48(%4), %%eax\n"
23399- "81: movl 52(%4), %%edx\n"
23400+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23401+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23402 " movnti %%eax, 48(%3)\n"
23403 " movnti %%edx, 52(%3)\n"
23404- "14: movl 56(%4), %%eax\n"
23405- "91: movl 60(%4), %%edx\n"
23406+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23407+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23408 " movnti %%eax, 56(%3)\n"
23409 " movnti %%edx, 60(%3)\n"
23410 " addl $-64, %0\n"
23411@@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23412 " shrl $2, %0\n"
23413 " andl $3, %%eax\n"
23414 " cld\n"
23415- "6: rep; movsl\n"
23416+ "6: rep; "__copyuser_seg" movsl\n"
23417 " movl %%eax,%0\n"
23418- "7: rep; movsb\n"
23419+ "7: rep; "__copyuser_seg" movsb\n"
23420 "8:\n"
23421 ".section .fixup,\"ax\"\n"
23422 "9: lea 0(%%eax,%0,4),%0\n"
23423@@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
23424
23425 __asm__ __volatile__(
23426 " .align 2,0x90\n"
23427- "0: movl 32(%4), %%eax\n"
23428+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23429 " cmpl $67, %0\n"
23430 " jbe 2f\n"
23431- "1: movl 64(%4), %%eax\n"
23432+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23433 " .align 2,0x90\n"
23434- "2: movl 0(%4), %%eax\n"
23435- "21: movl 4(%4), %%edx\n"
23436+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23437+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23438 " movnti %%eax, 0(%3)\n"
23439 " movnti %%edx, 4(%3)\n"
23440- "3: movl 8(%4), %%eax\n"
23441- "31: movl 12(%4),%%edx\n"
23442+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23443+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23444 " movnti %%eax, 8(%3)\n"
23445 " movnti %%edx, 12(%3)\n"
23446- "4: movl 16(%4), %%eax\n"
23447- "41: movl 20(%4), %%edx\n"
23448+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23449+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23450 " movnti %%eax, 16(%3)\n"
23451 " movnti %%edx, 20(%3)\n"
23452- "10: movl 24(%4), %%eax\n"
23453- "51: movl 28(%4), %%edx\n"
23454+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23455+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23456 " movnti %%eax, 24(%3)\n"
23457 " movnti %%edx, 28(%3)\n"
23458- "11: movl 32(%4), %%eax\n"
23459- "61: movl 36(%4), %%edx\n"
23460+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23461+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23462 " movnti %%eax, 32(%3)\n"
23463 " movnti %%edx, 36(%3)\n"
23464- "12: movl 40(%4), %%eax\n"
23465- "71: movl 44(%4), %%edx\n"
23466+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23467+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23468 " movnti %%eax, 40(%3)\n"
23469 " movnti %%edx, 44(%3)\n"
23470- "13: movl 48(%4), %%eax\n"
23471- "81: movl 52(%4), %%edx\n"
23472+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23473+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23474 " movnti %%eax, 48(%3)\n"
23475 " movnti %%edx, 52(%3)\n"
23476- "14: movl 56(%4), %%eax\n"
23477- "91: movl 60(%4), %%edx\n"
23478+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23479+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23480 " movnti %%eax, 56(%3)\n"
23481 " movnti %%edx, 60(%3)\n"
23482 " addl $-64, %0\n"
23483@@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23484 " shrl $2, %0\n"
23485 " andl $3, %%eax\n"
23486 " cld\n"
23487- "6: rep; movsl\n"
23488+ "6: rep; "__copyuser_seg" movsl\n"
23489 " movl %%eax,%0\n"
23490- "7: rep; movsb\n"
23491+ "7: rep; "__copyuser_seg" movsb\n"
23492 "8:\n"
23493 ".section .fixup,\"ax\"\n"
23494 "9: lea 0(%%eax,%0,4),%0\n"
23495@@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23496 */
23497 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23498 unsigned long size);
23499-unsigned long __copy_user_intel(void __user *to, const void *from,
23500+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23501+ unsigned long size);
23502+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23503 unsigned long size);
23504 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23505 const void __user *from, unsigned long size);
23506 #endif /* CONFIG_X86_INTEL_USERCOPY */
23507
23508 /* Generic arbitrary sized copy. */
23509-#define __copy_user(to, from, size) \
23510+#define __copy_user(to, from, size, prefix, set, restore) \
23511 do { \
23512 int __d0, __d1, __d2; \
23513 __asm__ __volatile__( \
23514+ set \
23515 " cmp $7,%0\n" \
23516 " jbe 1f\n" \
23517 " movl %1,%0\n" \
23518 " negl %0\n" \
23519 " andl $7,%0\n" \
23520 " subl %0,%3\n" \
23521- "4: rep; movsb\n" \
23522+ "4: rep; "prefix"movsb\n" \
23523 " movl %3,%0\n" \
23524 " shrl $2,%0\n" \
23525 " andl $3,%3\n" \
23526 " .align 2,0x90\n" \
23527- "0: rep; movsl\n" \
23528+ "0: rep; "prefix"movsl\n" \
23529 " movl %3,%0\n" \
23530- "1: rep; movsb\n" \
23531+ "1: rep; "prefix"movsb\n" \
23532 "2:\n" \
23533+ restore \
23534 ".section .fixup,\"ax\"\n" \
23535 "5: addl %3,%0\n" \
23536 " jmp 2b\n" \
23537@@ -682,14 +799,14 @@ do { \
23538 " negl %0\n" \
23539 " andl $7,%0\n" \
23540 " subl %0,%3\n" \
23541- "4: rep; movsb\n" \
23542+ "4: rep; "__copyuser_seg"movsb\n" \
23543 " movl %3,%0\n" \
23544 " shrl $2,%0\n" \
23545 " andl $3,%3\n" \
23546 " .align 2,0x90\n" \
23547- "0: rep; movsl\n" \
23548+ "0: rep; "__copyuser_seg"movsl\n" \
23549 " movl %3,%0\n" \
23550- "1: rep; movsb\n" \
23551+ "1: rep; "__copyuser_seg"movsb\n" \
23552 "2:\n" \
23553 ".section .fixup,\"ax\"\n" \
23554 "5: addl %3,%0\n" \
23555@@ -775,9 +892,9 @@ survive:
23556 }
23557 #endif
23558 if (movsl_is_ok(to, from, n))
23559- __copy_user(to, from, n);
23560+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23561 else
23562- n = __copy_user_intel(to, from, n);
23563+ n = __generic_copy_to_user_intel(to, from, n);
23564 return n;
23565 }
23566 EXPORT_SYMBOL(__copy_to_user_ll);
23567@@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23568 unsigned long n)
23569 {
23570 if (movsl_is_ok(to, from, n))
23571- __copy_user(to, from, n);
23572+ __copy_user(to, from, n, __copyuser_seg, "", "");
23573 else
23574- n = __copy_user_intel((void __user *)to,
23575- (const void *)from, n);
23576+ n = __generic_copy_from_user_intel(to, from, n);
23577 return n;
23578 }
23579 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23580@@ -827,59 +943,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23581 if (n > 64 && cpu_has_xmm2)
23582 n = __copy_user_intel_nocache(to, from, n);
23583 else
23584- __copy_user(to, from, n);
23585+ __copy_user(to, from, n, __copyuser_seg, "", "");
23586 #else
23587- __copy_user(to, from, n);
23588+ __copy_user(to, from, n, __copyuser_seg, "", "");
23589 #endif
23590 return n;
23591 }
23592 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23593
23594-/**
23595- * copy_to_user: - Copy a block of data into user space.
23596- * @to: Destination address, in user space.
23597- * @from: Source address, in kernel space.
23598- * @n: Number of bytes to copy.
23599- *
23600- * Context: User context only. This function may sleep.
23601- *
23602- * Copy data from kernel space to user space.
23603- *
23604- * Returns number of bytes that could not be copied.
23605- * On success, this will be zero.
23606- */
23607-unsigned long
23608-copy_to_user(void __user *to, const void *from, unsigned long n)
23609+#ifdef CONFIG_PAX_MEMORY_UDEREF
23610+void __set_fs(mm_segment_t x)
23611 {
23612- if (access_ok(VERIFY_WRITE, to, n))
23613- n = __copy_to_user(to, from, n);
23614- return n;
23615+ switch (x.seg) {
23616+ case 0:
23617+ loadsegment(gs, 0);
23618+ break;
23619+ case TASK_SIZE_MAX:
23620+ loadsegment(gs, __USER_DS);
23621+ break;
23622+ case -1UL:
23623+ loadsegment(gs, __KERNEL_DS);
23624+ break;
23625+ default:
23626+ BUG();
23627+ }
23628+ return;
23629 }
23630-EXPORT_SYMBOL(copy_to_user);
23631+EXPORT_SYMBOL(__set_fs);
23632
23633-/**
23634- * copy_from_user: - Copy a block of data from user space.
23635- * @to: Destination address, in kernel space.
23636- * @from: Source address, in user space.
23637- * @n: Number of bytes to copy.
23638- *
23639- * Context: User context only. This function may sleep.
23640- *
23641- * Copy data from user space to kernel space.
23642- *
23643- * Returns number of bytes that could not be copied.
23644- * On success, this will be zero.
23645- *
23646- * If some data could not be copied, this function will pad the copied
23647- * data to the requested size using zero bytes.
23648- */
23649-unsigned long
23650-copy_from_user(void *to, const void __user *from, unsigned long n)
23651+void set_fs(mm_segment_t x)
23652 {
23653- if (access_ok(VERIFY_READ, from, n))
23654- n = __copy_from_user(to, from, n);
23655- else
23656- memset(to, 0, n);
23657- return n;
23658+ current_thread_info()->addr_limit = x;
23659+ __set_fs(x);
23660 }
23661-EXPORT_SYMBOL(copy_from_user);
23662+EXPORT_SYMBOL(set_fs);
23663+#endif
23664diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23665index b7c2849..8633ad8 100644
23666--- a/arch/x86/lib/usercopy_64.c
23667+++ b/arch/x86/lib/usercopy_64.c
23668@@ -42,6 +42,12 @@ long
23669 __strncpy_from_user(char *dst, const char __user *src, long count)
23670 {
23671 long res;
23672+
23673+#ifdef CONFIG_PAX_MEMORY_UDEREF
23674+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23675+ src += PAX_USER_SHADOW_BASE;
23676+#endif
23677+
23678 __do_strncpy_from_user(dst, src, count, res);
23679 return res;
23680 }
23681@@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23682 {
23683 long __d0;
23684 might_fault();
23685+
23686+#ifdef CONFIG_PAX_MEMORY_UDEREF
23687+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23688+ addr += PAX_USER_SHADOW_BASE;
23689+#endif
23690+
23691 /* no memory constraint because it doesn't change any memory gcc knows
23692 about */
23693 asm volatile(
23694@@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23695 }
23696 EXPORT_SYMBOL(strlen_user);
23697
23698-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23699+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23700 {
23701- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23702- return copy_user_generic((__force void *)to, (__force void *)from, len);
23703- }
23704- return len;
23705+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23706+
23707+#ifdef CONFIG_PAX_MEMORY_UDEREF
23708+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23709+ to += PAX_USER_SHADOW_BASE;
23710+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23711+ from += PAX_USER_SHADOW_BASE;
23712+#endif
23713+
23714+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23715+ }
23716+ return len;
23717 }
23718 EXPORT_SYMBOL(copy_in_user);
23719
23720@@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
23721 * it is not necessary to optimize tail handling.
23722 */
23723 unsigned long
23724-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23725+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23726 {
23727 char c;
23728 unsigned zero_len;
23729diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23730index 61b41ca..5fef66a 100644
23731--- a/arch/x86/mm/extable.c
23732+++ b/arch/x86/mm/extable.c
23733@@ -1,14 +1,71 @@
23734 #include <linux/module.h>
23735 #include <linux/spinlock.h>
23736+#include <linux/sort.h>
23737 #include <asm/uaccess.h>
23738+#include <asm/pgtable.h>
23739
23740+/*
23741+ * The exception table needs to be sorted so that the binary
23742+ * search that we use to find entries in it works properly.
23743+ * This is used both for the kernel exception table and for
23744+ * the exception tables of modules that get loaded.
23745+ */
23746+static int cmp_ex(const void *a, const void *b)
23747+{
23748+ const struct exception_table_entry *x = a, *y = b;
23749+
23750+ /* avoid overflow */
23751+ if (x->insn > y->insn)
23752+ return 1;
23753+ if (x->insn < y->insn)
23754+ return -1;
23755+ return 0;
23756+}
23757+
23758+static void swap_ex(void *a, void *b, int size)
23759+{
23760+ struct exception_table_entry t, *x = a, *y = b;
23761+
23762+ t = *x;
23763+
23764+ pax_open_kernel();
23765+ *x = *y;
23766+ *y = t;
23767+ pax_close_kernel();
23768+}
23769+
23770+void sort_extable(struct exception_table_entry *start,
23771+ struct exception_table_entry *finish)
23772+{
23773+ sort(start, finish - start, sizeof(struct exception_table_entry),
23774+ cmp_ex, swap_ex);
23775+}
23776+
23777+#ifdef CONFIG_MODULES
23778+/*
23779+ * If the exception table is sorted, any referring to the module init
23780+ * will be at the beginning or the end.
23781+ */
23782+void trim_init_extable(struct module *m)
23783+{
23784+ /*trim the beginning*/
23785+ while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
23786+ m->extable++;
23787+ m->num_exentries--;
23788+ }
23789+ /*trim the end*/
23790+ while (m->num_exentries &&
23791+ within_module_init(m->extable[m->num_exentries-1].insn, m))
23792+ m->num_exentries--;
23793+}
23794+#endif /* CONFIG_MODULES */
23795
23796 int fixup_exception(struct pt_regs *regs)
23797 {
23798 const struct exception_table_entry *fixup;
23799
23800 #ifdef CONFIG_PNPBIOS
23801- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23802+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23803 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23804 extern u32 pnp_bios_is_utter_crap;
23805 pnp_bios_is_utter_crap = 1;
23806diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23807index 8ac0d76..87899a4 100644
23808--- a/arch/x86/mm/fault.c
23809+++ b/arch/x86/mm/fault.c
23810@@ -11,10 +11,19 @@
23811 #include <linux/kprobes.h> /* __kprobes, ... */
23812 #include <linux/mmiotrace.h> /* kmmio_handler, ... */
23813 #include <linux/perf_event.h> /* perf_sw_event */
23814+#include <linux/unistd.h>
23815+#include <linux/compiler.h>
23816
23817 #include <asm/traps.h> /* dotraplinkage, ... */
23818 #include <asm/pgalloc.h> /* pgd_*(), ... */
23819 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23820+#include <asm/vsyscall.h>
23821+#include <asm/tlbflush.h>
23822+
23823+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23824+#include <asm/stacktrace.h>
23825+#include "../kernel/dumpstack.h"
23826+#endif
23827
23828 /*
23829 * Page fault error code bits:
23830@@ -51,7 +60,7 @@ static inline int notify_page_fault(struct pt_regs *regs)
23831 int ret = 0;
23832
23833 /* kprobe_running() needs smp_processor_id() */
23834- if (kprobes_built_in() && !user_mode_vm(regs)) {
23835+ if (kprobes_built_in() && !user_mode(regs)) {
23836 preempt_disable();
23837 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23838 ret = 1;
23839@@ -112,7 +121,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23840 return !instr_lo || (instr_lo>>1) == 1;
23841 case 0x00:
23842 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23843- if (probe_kernel_address(instr, opcode))
23844+ if (user_mode(regs)) {
23845+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23846+ return 0;
23847+ } else if (probe_kernel_address(instr, opcode))
23848 return 0;
23849
23850 *prefetch = (instr_lo == 0xF) &&
23851@@ -146,7 +158,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23852 while (instr < max_instr) {
23853 unsigned char opcode;
23854
23855- if (probe_kernel_address(instr, opcode))
23856+ if (user_mode(regs)) {
23857+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23858+ break;
23859+ } else if (probe_kernel_address(instr, opcode))
23860 break;
23861
23862 instr++;
23863@@ -172,6 +187,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23864 force_sig_info(si_signo, &info, tsk);
23865 }
23866
23867+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23868+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23869+#endif
23870+
23871+#ifdef CONFIG_PAX_EMUTRAMP
23872+static int pax_handle_fetch_fault(struct pt_regs *regs);
23873+#endif
23874+
23875+#ifdef CONFIG_PAX_PAGEEXEC
23876+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23877+{
23878+ pgd_t *pgd;
23879+ pud_t *pud;
23880+ pmd_t *pmd;
23881+
23882+ pgd = pgd_offset(mm, address);
23883+ if (!pgd_present(*pgd))
23884+ return NULL;
23885+ pud = pud_offset(pgd, address);
23886+ if (!pud_present(*pud))
23887+ return NULL;
23888+ pmd = pmd_offset(pud, address);
23889+ if (!pmd_present(*pmd))
23890+ return NULL;
23891+ return pmd;
23892+}
23893+#endif
23894+
23895 DEFINE_SPINLOCK(pgd_lock);
23896 LIST_HEAD(pgd_list);
23897
23898@@ -224,11 +267,24 @@ void vmalloc_sync_all(void)
23899 address += PMD_SIZE) {
23900
23901 unsigned long flags;
23902+
23903+#ifdef CONFIG_PAX_PER_CPU_PGD
23904+ unsigned long cpu;
23905+#else
23906 struct page *page;
23907+#endif
23908
23909 spin_lock_irqsave(&pgd_lock, flags);
23910+
23911+#ifdef CONFIG_PAX_PER_CPU_PGD
23912+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
23913+ pgd_t *pgd = get_cpu_pgd(cpu);
23914+#else
23915 list_for_each_entry(page, &pgd_list, lru) {
23916- if (!vmalloc_sync_one(page_address(page), address))
23917+ pgd_t *pgd = page_address(page);
23918+#endif
23919+
23920+ if (!vmalloc_sync_one(pgd, address))
23921 break;
23922 }
23923 spin_unlock_irqrestore(&pgd_lock, flags);
23924@@ -258,6 +314,11 @@ static noinline int vmalloc_fault(unsigned long address)
23925 * an interrupt in the middle of a task switch..
23926 */
23927 pgd_paddr = read_cr3();
23928+
23929+#ifdef CONFIG_PAX_PER_CPU_PGD
23930+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23931+#endif
23932+
23933 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23934 if (!pmd_k)
23935 return -1;
23936@@ -332,15 +393,27 @@ void vmalloc_sync_all(void)
23937
23938 const pgd_t *pgd_ref = pgd_offset_k(address);
23939 unsigned long flags;
23940+
23941+#ifdef CONFIG_PAX_PER_CPU_PGD
23942+ unsigned long cpu;
23943+#else
23944 struct page *page;
23945+#endif
23946
23947 if (pgd_none(*pgd_ref))
23948 continue;
23949
23950 spin_lock_irqsave(&pgd_lock, flags);
23951+
23952+#ifdef CONFIG_PAX_PER_CPU_PGD
23953+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
23954+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
23955+#else
23956 list_for_each_entry(page, &pgd_list, lru) {
23957 pgd_t *pgd;
23958 pgd = (pgd_t *)page_address(page) + pgd_index(address);
23959+#endif
23960+
23961 if (pgd_none(*pgd))
23962 set_pgd(pgd, *pgd_ref);
23963 else
23964@@ -373,7 +446,14 @@ static noinline int vmalloc_fault(unsigned long address)
23965 * happen within a race in page table update. In the later
23966 * case just flush:
23967 */
23968+
23969+#ifdef CONFIG_PAX_PER_CPU_PGD
23970+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23971+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23972+#else
23973 pgd = pgd_offset(current->active_mm, address);
23974+#endif
23975+
23976 pgd_ref = pgd_offset_k(address);
23977 if (pgd_none(*pgd_ref))
23978 return -1;
23979@@ -535,7 +615,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23980 static int is_errata100(struct pt_regs *regs, unsigned long address)
23981 {
23982 #ifdef CONFIG_X86_64
23983- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23984+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23985 return 1;
23986 #endif
23987 return 0;
23988@@ -562,7 +642,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23989 }
23990
23991 static const char nx_warning[] = KERN_CRIT
23992-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23993+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23994
23995 static void
23996 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23997@@ -571,15 +651,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23998 if (!oops_may_print())
23999 return;
24000
24001- if (error_code & PF_INSTR) {
24002+ if (nx_enabled && (error_code & PF_INSTR)) {
24003 unsigned int level;
24004
24005 pte_t *pte = lookup_address(address, &level);
24006
24007 if (pte && pte_present(*pte) && !pte_exec(*pte))
24008- printk(nx_warning, current_uid());
24009+ printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
24010 }
24011
24012+#ifdef CONFIG_PAX_KERNEXEC
24013+ if (init_mm.start_code <= address && address < init_mm.end_code) {
24014+ if (current->signal->curr_ip)
24015+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
24016+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
24017+ else
24018+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
24019+ current->comm, task_pid_nr(current), current_uid(), current_euid());
24020+ }
24021+#endif
24022+
24023 printk(KERN_ALERT "BUG: unable to handle kernel ");
24024 if (address < PAGE_SIZE)
24025 printk(KERN_CONT "NULL pointer dereference");
24026@@ -705,6 +796,23 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
24027 {
24028 struct task_struct *tsk = current;
24029
24030+#ifdef CONFIG_X86_64
24031+ struct mm_struct *mm = tsk->mm;
24032+
24033+ if (mm && (error_code & PF_INSTR) && mm->context.vdso) {
24034+ if (regs->ip == (unsigned long)vgettimeofday) {
24035+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_gettimeofday);
24036+ return;
24037+ } else if (regs->ip == (unsigned long)vtime) {
24038+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, fallback_time);
24039+ return;
24040+ } else if (regs->ip == (unsigned long)vgetcpu) {
24041+ regs->ip = (unsigned long)VDSO64_SYMBOL(mm->context.vdso, getcpu);
24042+ return;
24043+ }
24044+ }
24045+#endif
24046+
24047 /* User mode accesses just cause a SIGSEGV */
24048 if (error_code & PF_USER) {
24049 /*
24050@@ -722,6 +830,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
24051 if (is_errata100(regs, address))
24052 return;
24053
24054+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24055+ if (pax_is_fetch_fault(regs, error_code, address)) {
24056+
24057+#ifdef CONFIG_PAX_EMUTRAMP
24058+ switch (pax_handle_fetch_fault(regs)) {
24059+ case 2:
24060+ return;
24061+ }
24062+#endif
24063+
24064+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24065+ do_group_exit(SIGKILL);
24066+ }
24067+#endif
24068+
24069 if (unlikely(show_unhandled_signals))
24070 show_signal_msg(regs, error_code, address, tsk);
24071
24072@@ -818,7 +941,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
24073 if (fault & VM_FAULT_HWPOISON) {
24074 printk(KERN_ERR
24075 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
24076- tsk->comm, tsk->pid, address);
24077+ tsk->comm, task_pid_nr(tsk), address);
24078 code = BUS_MCEERR_AR;
24079 }
24080 #endif
24081@@ -857,6 +980,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
24082 return 1;
24083 }
24084
24085+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24086+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
24087+{
24088+ pte_t *pte;
24089+ pmd_t *pmd;
24090+ spinlock_t *ptl;
24091+ unsigned char pte_mask;
24092+
24093+ if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
24094+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
24095+ return 0;
24096+
24097+ /* PaX: it's our fault, let's handle it if we can */
24098+
24099+ /* PaX: take a look at read faults before acquiring any locks */
24100+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
24101+ /* instruction fetch attempt from a protected page in user mode */
24102+ up_read(&mm->mmap_sem);
24103+
24104+#ifdef CONFIG_PAX_EMUTRAMP
24105+ switch (pax_handle_fetch_fault(regs)) {
24106+ case 2:
24107+ return 1;
24108+ }
24109+#endif
24110+
24111+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
24112+ do_group_exit(SIGKILL);
24113+ }
24114+
24115+ pmd = pax_get_pmd(mm, address);
24116+ if (unlikely(!pmd))
24117+ return 0;
24118+
24119+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
24120+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
24121+ pte_unmap_unlock(pte, ptl);
24122+ return 0;
24123+ }
24124+
24125+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
24126+ /* write attempt to a protected page in user mode */
24127+ pte_unmap_unlock(pte, ptl);
24128+ return 0;
24129+ }
24130+
24131+#ifdef CONFIG_SMP
24132+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
24133+#else
24134+ if (likely(address > get_limit(regs->cs)))
24135+#endif
24136+ {
24137+ set_pte(pte, pte_mkread(*pte));
24138+ __flush_tlb_one(address);
24139+ pte_unmap_unlock(pte, ptl);
24140+ up_read(&mm->mmap_sem);
24141+ return 1;
24142+ }
24143+
24144+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
24145+
24146+ /*
24147+ * PaX: fill DTLB with user rights and retry
24148+ */
24149+ __asm__ __volatile__ (
24150+ "orb %2,(%1)\n"
24151+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
24152+/*
24153+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
24154+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
24155+ * page fault when examined during a TLB load attempt. this is true not only
24156+ * for PTEs holding a non-present entry but also present entries that will
24157+ * raise a page fault (such as those set up by PaX, or the copy-on-write
24158+ * mechanism). in effect it means that we do *not* need to flush the TLBs
24159+ * for our target pages since their PTEs are simply not in the TLBs at all.
24160+
24161+ * the best thing in omitting it is that we gain around 15-20% speed in the
24162+ * fast path of the page fault handler and can get rid of tracing since we
24163+ * can no longer flush unintended entries.
24164+ */
24165+ "invlpg (%0)\n"
24166+#endif
24167+ __copyuser_seg"testb $0,(%0)\n"
24168+ "xorb %3,(%1)\n"
24169+ :
24170+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
24171+ : "memory", "cc");
24172+ pte_unmap_unlock(pte, ptl);
24173+ up_read(&mm->mmap_sem);
24174+ return 1;
24175+}
24176+#endif
24177+
24178 /*
24179 * Handle a spurious fault caused by a stale TLB entry.
24180 *
24181@@ -923,6 +1139,9 @@ int show_unhandled_signals = 1;
24182 static inline int
24183 access_error(unsigned long error_code, int write, struct vm_area_struct *vma)
24184 {
24185+ if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
24186+ return 1;
24187+
24188 if (write) {
24189 /* write, present and write, not present: */
24190 if (unlikely(!(vma->vm_flags & VM_WRITE)))
24191@@ -956,16 +1175,30 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24192 {
24193 struct vm_area_struct *vma;
24194 struct task_struct *tsk;
24195- unsigned long address;
24196 struct mm_struct *mm;
24197 int write;
24198 int fault;
24199
24200- tsk = current;
24201- mm = tsk->mm;
24202-
24203 /* Get the faulting address: */
24204- address = read_cr2();
24205+ unsigned long address = read_cr2();
24206+
24207+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24208+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
24209+ if (!search_exception_tables(regs->ip)) {
24210+ bad_area_nosemaphore(regs, error_code, address);
24211+ return;
24212+ }
24213+ if (address < PAX_USER_SHADOW_BASE) {
24214+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24215+ printk(KERN_ERR "PAX: faulting IP: %pA\n", (void *)regs->ip);
24216+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24217+ } else
24218+ address -= PAX_USER_SHADOW_BASE;
24219+ }
24220+#endif
24221+
24222+ tsk = current;
24223+ mm = tsk->mm;
24224
24225 /*
24226 * Detect and handle instructions that would cause a page fault for
24227@@ -1026,7 +1259,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24228 * User-mode registers count as a user access even for any
24229 * potential system fault or CPU buglet:
24230 */
24231- if (user_mode_vm(regs)) {
24232+ if (user_mode(regs)) {
24233 local_irq_enable();
24234 error_code |= PF_USER;
24235 } else {
24236@@ -1080,6 +1313,11 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24237 might_sleep();
24238 }
24239
24240+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24241+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24242+ return;
24243+#endif
24244+
24245 vma = find_vma(mm, address);
24246 if (unlikely(!vma)) {
24247 bad_area(regs, error_code, address);
24248@@ -1091,18 +1329,24 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24249 bad_area(regs, error_code, address);
24250 return;
24251 }
24252- if (error_code & PF_USER) {
24253- /*
24254- * Accessing the stack below %sp is always a bug.
24255- * The large cushion allows instructions like enter
24256- * and pusha to work. ("enter $65535, $31" pushes
24257- * 32 pointers and then decrements %sp by 65535.)
24258- */
24259- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24260- bad_area(regs, error_code, address);
24261- return;
24262- }
24263+ /*
24264+ * Accessing the stack below %sp is always a bug.
24265+ * The large cushion allows instructions like enter
24266+ * and pusha to work. ("enter $65535, $31" pushes
24267+ * 32 pointers and then decrements %sp by 65535.)
24268+ */
24269+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24270+ bad_area(regs, error_code, address);
24271+ return;
24272 }
24273+
24274+#ifdef CONFIG_PAX_SEGMEXEC
24275+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24276+ bad_area(regs, error_code, address);
24277+ return;
24278+ }
24279+#endif
24280+
24281 if (unlikely(expand_stack(vma, address))) {
24282 bad_area(regs, error_code, address);
24283 return;
24284@@ -1146,3 +1390,292 @@ good_area:
24285
24286 up_read(&mm->mmap_sem);
24287 }
24288+
24289+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24290+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24291+{
24292+ struct mm_struct *mm = current->mm;
24293+ unsigned long ip = regs->ip;
24294+
24295+ if (v8086_mode(regs))
24296+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24297+
24298+#ifdef CONFIG_PAX_PAGEEXEC
24299+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24300+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24301+ return true;
24302+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24303+ return true;
24304+ return false;
24305+ }
24306+#endif
24307+
24308+#ifdef CONFIG_PAX_SEGMEXEC
24309+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24310+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24311+ return true;
24312+ return false;
24313+ }
24314+#endif
24315+
24316+ return false;
24317+}
24318+#endif
24319+
24320+#ifdef CONFIG_PAX_EMUTRAMP
24321+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24322+{
24323+ int err;
24324+
24325+ do { /* PaX: libffi trampoline emulation */
24326+ unsigned char mov, jmp;
24327+ unsigned int addr1, addr2;
24328+
24329+#ifdef CONFIG_X86_64
24330+ if ((regs->ip + 9) >> 32)
24331+ break;
24332+#endif
24333+
24334+ err = get_user(mov, (unsigned char __user *)regs->ip);
24335+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24336+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24337+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24338+
24339+ if (err)
24340+ break;
24341+
24342+ if (mov == 0xB8 && jmp == 0xE9) {
24343+ regs->ax = addr1;
24344+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24345+ return 2;
24346+ }
24347+ } while (0);
24348+
24349+ do { /* PaX: gcc trampoline emulation #1 */
24350+ unsigned char mov1, mov2;
24351+ unsigned short jmp;
24352+ unsigned int addr1, addr2;
24353+
24354+#ifdef CONFIG_X86_64
24355+ if ((regs->ip + 11) >> 32)
24356+ break;
24357+#endif
24358+
24359+ err = get_user(mov1, (unsigned char __user *)regs->ip);
24360+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24361+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24362+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24363+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24364+
24365+ if (err)
24366+ break;
24367+
24368+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24369+ regs->cx = addr1;
24370+ regs->ax = addr2;
24371+ regs->ip = addr2;
24372+ return 2;
24373+ }
24374+ } while (0);
24375+
24376+ do { /* PaX: gcc trampoline emulation #2 */
24377+ unsigned char mov, jmp;
24378+ unsigned int addr1, addr2;
24379+
24380+#ifdef CONFIG_X86_64
24381+ if ((regs->ip + 9) >> 32)
24382+ break;
24383+#endif
24384+
24385+ err = get_user(mov, (unsigned char __user *)regs->ip);
24386+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24387+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24388+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24389+
24390+ if (err)
24391+ break;
24392+
24393+ if (mov == 0xB9 && jmp == 0xE9) {
24394+ regs->cx = addr1;
24395+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24396+ return 2;
24397+ }
24398+ } while (0);
24399+
24400+ return 1; /* PaX in action */
24401+}
24402+
24403+#ifdef CONFIG_X86_64
24404+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24405+{
24406+ int err;
24407+
24408+ do { /* PaX: libffi trampoline emulation */
24409+ unsigned short mov1, mov2, jmp1;
24410+ unsigned char stcclc, jmp2;
24411+ unsigned long addr1, addr2;
24412+
24413+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24414+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24415+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24416+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24417+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24418+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24419+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24420+
24421+ if (err)
24422+ break;
24423+
24424+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24425+ regs->r11 = addr1;
24426+ regs->r10 = addr2;
24427+ if (stcclc == 0xF8)
24428+ regs->flags &= ~X86_EFLAGS_CF;
24429+ else
24430+ regs->flags |= X86_EFLAGS_CF;
24431+ regs->ip = addr1;
24432+ return 2;
24433+ }
24434+ } while (0);
24435+
24436+ do { /* PaX: gcc trampoline emulation #1 */
24437+ unsigned short mov1, mov2, jmp1;
24438+ unsigned char jmp2;
24439+ unsigned int addr1;
24440+ unsigned long addr2;
24441+
24442+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24443+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24444+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24445+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24446+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24447+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24448+
24449+ if (err)
24450+ break;
24451+
24452+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24453+ regs->r11 = addr1;
24454+ regs->r10 = addr2;
24455+ regs->ip = addr1;
24456+ return 2;
24457+ }
24458+ } while (0);
24459+
24460+ do { /* PaX: gcc trampoline emulation #2 */
24461+ unsigned short mov1, mov2, jmp1;
24462+ unsigned char jmp2;
24463+ unsigned long addr1, addr2;
24464+
24465+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24466+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24467+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24468+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24469+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24470+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24471+
24472+ if (err)
24473+ break;
24474+
24475+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24476+ regs->r11 = addr1;
24477+ regs->r10 = addr2;
24478+ regs->ip = addr1;
24479+ return 2;
24480+ }
24481+ } while (0);
24482+
24483+ return 1; /* PaX in action */
24484+}
24485+#endif
24486+
24487+/*
24488+ * PaX: decide what to do with offenders (regs->ip = fault address)
24489+ *
24490+ * returns 1 when task should be killed
24491+ * 2 when gcc trampoline was detected
24492+ */
24493+static int pax_handle_fetch_fault(struct pt_regs *regs)
24494+{
24495+ if (v8086_mode(regs))
24496+ return 1;
24497+
24498+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24499+ return 1;
24500+
24501+#ifdef CONFIG_X86_32
24502+ return pax_handle_fetch_fault_32(regs);
24503+#else
24504+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24505+ return pax_handle_fetch_fault_32(regs);
24506+ else
24507+ return pax_handle_fetch_fault_64(regs);
24508+#endif
24509+}
24510+#endif
24511+
24512+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24513+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24514+{
24515+ long i;
24516+
24517+ printk(KERN_ERR "PAX: bytes at PC: ");
24518+ for (i = 0; i < 20; i++) {
24519+ unsigned char c;
24520+ if (get_user(c, (unsigned char __force_user *)pc+i))
24521+ printk(KERN_CONT "?? ");
24522+ else
24523+ printk(KERN_CONT "%02x ", c);
24524+ }
24525+ printk("\n");
24526+
24527+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24528+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24529+ unsigned long c;
24530+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24531+#ifdef CONFIG_X86_32
24532+ printk(KERN_CONT "???????? ");
24533+#else
24534+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24535+ printk(KERN_CONT "???????? ???????? ");
24536+ else
24537+ printk(KERN_CONT "???????????????? ");
24538+#endif
24539+ } else {
24540+#ifdef CONFIG_X86_64
24541+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24542+ printk(KERN_CONT "%08x ", (unsigned int)c);
24543+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24544+ } else
24545+#endif
24546+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24547+ }
24548+ }
24549+ printk("\n");
24550+}
24551+#endif
24552+
24553+/**
24554+ * probe_kernel_write(): safely attempt to write to a location
24555+ * @dst: address to write to
24556+ * @src: pointer to the data that shall be written
24557+ * @size: size of the data chunk
24558+ *
24559+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24560+ * happens, handle that and return -EFAULT.
24561+ */
24562+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24563+{
24564+ long ret;
24565+ mm_segment_t old_fs = get_fs();
24566+
24567+ set_fs(KERNEL_DS);
24568+ pagefault_disable();
24569+ pax_open_kernel();
24570+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24571+ pax_close_kernel();
24572+ pagefault_enable();
24573+ set_fs(old_fs);
24574+
24575+ return ret ? -EFAULT : 0;
24576+}
24577diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24578index 71da1bc..7a16bf4 100644
24579--- a/arch/x86/mm/gup.c
24580+++ b/arch/x86/mm/gup.c
24581@@ -237,7 +237,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24582 addr = start;
24583 len = (unsigned long) nr_pages << PAGE_SHIFT;
24584 end = start + len;
24585- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24586+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24587 (void __user *)start, len)))
24588 return 0;
24589
24590diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24591index 63a6ba6..79abd7a 100644
24592--- a/arch/x86/mm/highmem_32.c
24593+++ b/arch/x86/mm/highmem_32.c
24594@@ -43,7 +43,10 @@ void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot)
24595 idx = type + KM_TYPE_NR*smp_processor_id();
24596 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24597 BUG_ON(!pte_none(*(kmap_pte-idx)));
24598+
24599+ pax_open_kernel();
24600 set_pte(kmap_pte-idx, mk_pte(page, prot));
24601+ pax_close_kernel();
24602
24603 return (void *)vaddr;
24604 }
24605diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24606index f46c340..6ff9a26 100644
24607--- a/arch/x86/mm/hugetlbpage.c
24608+++ b/arch/x86/mm/hugetlbpage.c
24609@@ -267,13 +267,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24610 struct hstate *h = hstate_file(file);
24611 struct mm_struct *mm = current->mm;
24612 struct vm_area_struct *vma;
24613- unsigned long start_addr;
24614+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24615+
24616+#ifdef CONFIG_PAX_SEGMEXEC
24617+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24618+ pax_task_size = SEGMEXEC_TASK_SIZE;
24619+#endif
24620+
24621+ pax_task_size -= PAGE_SIZE;
24622
24623 if (len > mm->cached_hole_size) {
24624- start_addr = mm->free_area_cache;
24625+ start_addr = mm->free_area_cache;
24626 } else {
24627- start_addr = TASK_UNMAPPED_BASE;
24628- mm->cached_hole_size = 0;
24629+ start_addr = mm->mmap_base;
24630+ mm->cached_hole_size = 0;
24631 }
24632
24633 full_search:
24634@@ -281,26 +288,27 @@ full_search:
24635
24636 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24637 /* At this point: (!vma || addr < vma->vm_end). */
24638- if (TASK_SIZE - len < addr) {
24639+ if (pax_task_size - len < addr) {
24640 /*
24641 * Start a new search - just in case we missed
24642 * some holes.
24643 */
24644- if (start_addr != TASK_UNMAPPED_BASE) {
24645- start_addr = TASK_UNMAPPED_BASE;
24646+ if (start_addr != mm->mmap_base) {
24647+ start_addr = mm->mmap_base;
24648 mm->cached_hole_size = 0;
24649 goto full_search;
24650 }
24651 return -ENOMEM;
24652 }
24653- if (!vma || addr + len <= vma->vm_start) {
24654- mm->free_area_cache = addr + len;
24655- return addr;
24656- }
24657+ if (check_heap_stack_gap(vma, addr, len))
24658+ break;
24659 if (addr + mm->cached_hole_size < vma->vm_start)
24660 mm->cached_hole_size = vma->vm_start - addr;
24661 addr = ALIGN(vma->vm_end, huge_page_size(h));
24662 }
24663+
24664+ mm->free_area_cache = addr + len;
24665+ return addr;
24666 }
24667
24668 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24669@@ -309,10 +317,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24670 {
24671 struct hstate *h = hstate_file(file);
24672 struct mm_struct *mm = current->mm;
24673- struct vm_area_struct *vma, *prev_vma;
24674- unsigned long base = mm->mmap_base, addr = addr0;
24675+ struct vm_area_struct *vma;
24676+ unsigned long base = mm->mmap_base, addr;
24677 unsigned long largest_hole = mm->cached_hole_size;
24678- int first_time = 1;
24679
24680 /* don't allow allocations above current base */
24681 if (mm->free_area_cache > base)
24682@@ -322,64 +329,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24683 largest_hole = 0;
24684 mm->free_area_cache = base;
24685 }
24686-try_again:
24687+
24688 /* make sure it can fit in the remaining address space */
24689 if (mm->free_area_cache < len)
24690 goto fail;
24691
24692 /* either no address requested or cant fit in requested address hole */
24693- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24694+ addr = (mm->free_area_cache - len);
24695 do {
24696+ addr &= huge_page_mask(h);
24697+ vma = find_vma(mm, addr);
24698 /*
24699 * Lookup failure means no vma is above this address,
24700 * i.e. return with success:
24701- */
24702- if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
24703- return addr;
24704-
24705- /*
24706 * new region fits between prev_vma->vm_end and
24707 * vma->vm_start, use it:
24708 */
24709- if (addr + len <= vma->vm_start &&
24710- (!prev_vma || (addr >= prev_vma->vm_end))) {
24711+ if (check_heap_stack_gap(vma, addr, len)) {
24712 /* remember the address as a hint for next time */
24713- mm->cached_hole_size = largest_hole;
24714- return (mm->free_area_cache = addr);
24715- } else {
24716- /* pull free_area_cache down to the first hole */
24717- if (mm->free_area_cache == vma->vm_end) {
24718- mm->free_area_cache = vma->vm_start;
24719- mm->cached_hole_size = largest_hole;
24720- }
24721+ mm->cached_hole_size = largest_hole;
24722+ return (mm->free_area_cache = addr);
24723+ }
24724+ /* pull free_area_cache down to the first hole */
24725+ if (mm->free_area_cache == vma->vm_end) {
24726+ mm->free_area_cache = vma->vm_start;
24727+ mm->cached_hole_size = largest_hole;
24728 }
24729
24730 /* remember the largest hole we saw so far */
24731 if (addr + largest_hole < vma->vm_start)
24732- largest_hole = vma->vm_start - addr;
24733+ largest_hole = vma->vm_start - addr;
24734
24735 /* try just below the current vma->vm_start */
24736- addr = (vma->vm_start - len) & huge_page_mask(h);
24737- } while (len <= vma->vm_start);
24738+ addr = skip_heap_stack_gap(vma, len);
24739+ } while (!IS_ERR_VALUE(addr));
24740
24741 fail:
24742 /*
24743- * if hint left us with no space for the requested
24744- * mapping then try again:
24745- */
24746- if (first_time) {
24747- mm->free_area_cache = base;
24748- largest_hole = 0;
24749- first_time = 0;
24750- goto try_again;
24751- }
24752- /*
24753 * A failed mmap() very likely causes application failure,
24754 * so fall back to the bottom-up function here. This scenario
24755 * can happen with large stack limits and large mmap()
24756 * allocations.
24757 */
24758- mm->free_area_cache = TASK_UNMAPPED_BASE;
24759+
24760+#ifdef CONFIG_PAX_SEGMEXEC
24761+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24762+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24763+ else
24764+#endif
24765+
24766+ mm->mmap_base = TASK_UNMAPPED_BASE;
24767+
24768+#ifdef CONFIG_PAX_RANDMMAP
24769+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24770+ mm->mmap_base += mm->delta_mmap;
24771+#endif
24772+
24773+ mm->free_area_cache = mm->mmap_base;
24774 mm->cached_hole_size = ~0UL;
24775 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24776 len, pgoff, flags);
24777@@ -387,6 +393,7 @@ fail:
24778 /*
24779 * Restore the topdown base:
24780 */
24781+ mm->mmap_base = base;
24782 mm->free_area_cache = base;
24783 mm->cached_hole_size = ~0UL;
24784
24785@@ -400,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24786 struct hstate *h = hstate_file(file);
24787 struct mm_struct *mm = current->mm;
24788 struct vm_area_struct *vma;
24789+ unsigned long pax_task_size = TASK_SIZE;
24790
24791 if (len & ~huge_page_mask(h))
24792 return -EINVAL;
24793- if (len > TASK_SIZE)
24794+
24795+#ifdef CONFIG_PAX_SEGMEXEC
24796+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24797+ pax_task_size = SEGMEXEC_TASK_SIZE;
24798+#endif
24799+
24800+ pax_task_size -= PAGE_SIZE;
24801+
24802+ if (len > pax_task_size)
24803 return -ENOMEM;
24804
24805 if (flags & MAP_FIXED) {
24806@@ -415,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24807 if (addr) {
24808 addr = ALIGN(addr, huge_page_size(h));
24809 vma = find_vma(mm, addr);
24810- if (TASK_SIZE - len >= addr &&
24811- (!vma || addr + len <= vma->vm_start))
24812+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24813 return addr;
24814 }
24815 if (mm->get_unmapped_area == arch_get_unmapped_area)
24816diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24817index 73ffd55..ad78676 100644
24818--- a/arch/x86/mm/init.c
24819+++ b/arch/x86/mm/init.c
24820@@ -69,11 +69,7 @@ static void __init find_early_table_space(unsigned long end, int use_pse,
24821 * cause a hotspot and fill up ZONE_DMA. The page tables
24822 * need roughly 0.5KB per GB.
24823 */
24824-#ifdef CONFIG_X86_32
24825- start = 0x7000;
24826-#else
24827- start = 0x8000;
24828-#endif
24829+ start = 0x100000;
24830 e820_table_start = find_e820_area(start, max_pfn_mapped<<PAGE_SHIFT,
24831 tables, PAGE_SIZE);
24832 if (e820_table_start == -1UL)
24833@@ -147,7 +143,7 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24834 #endif
24835
24836 set_nx();
24837- if (nx_enabled)
24838+ if (nx_enabled && cpu_has_nx)
24839 printk(KERN_INFO "NX (Execute Disable) protection: active\n");
24840
24841 /* Enable PSE if available */
24842@@ -329,10 +325,27 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24843 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24844 * mmio resources as well as potential bios/acpi data regions.
24845 */
24846+
24847 int devmem_is_allowed(unsigned long pagenr)
24848 {
24849+#ifdef CONFIG_GRKERNSEC_KMEM
24850+ /* allow BDA */
24851+ if (!pagenr)
24852+ return 1;
24853+ /* allow EBDA */
24854+ if ((0x9f000 >> PAGE_SHIFT) == pagenr)
24855+ return 1;
24856+ /* allow ISA/video mem */
24857+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24858+ return 1;
24859+ /* throw out everything else below 1MB */
24860+ if (pagenr <= 256)
24861+ return 0;
24862+#else
24863 if (pagenr <= 256)
24864 return 1;
24865+#endif
24866+
24867 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24868 return 0;
24869 if (!page_is_ram(pagenr))
24870@@ -379,6 +392,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24871
24872 void free_initmem(void)
24873 {
24874+
24875+#ifdef CONFIG_PAX_KERNEXEC
24876+#ifdef CONFIG_X86_32
24877+ /* PaX: limit KERNEL_CS to actual size */
24878+ unsigned long addr, limit;
24879+ struct desc_struct d;
24880+ int cpu;
24881+
24882+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24883+ limit = (limit - 1UL) >> PAGE_SHIFT;
24884+
24885+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24886+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
24887+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24888+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24889+ }
24890+
24891+ /* PaX: make KERNEL_CS read-only */
24892+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24893+ if (!paravirt_enabled())
24894+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24895+/*
24896+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24897+ pgd = pgd_offset_k(addr);
24898+ pud = pud_offset(pgd, addr);
24899+ pmd = pmd_offset(pud, addr);
24900+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24901+ }
24902+*/
24903+#ifdef CONFIG_X86_PAE
24904+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24905+/*
24906+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24907+ pgd = pgd_offset_k(addr);
24908+ pud = pud_offset(pgd, addr);
24909+ pmd = pmd_offset(pud, addr);
24910+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24911+ }
24912+*/
24913+#endif
24914+
24915+#ifdef CONFIG_MODULES
24916+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24917+#endif
24918+
24919+#else
24920+ pgd_t *pgd;
24921+ pud_t *pud;
24922+ pmd_t *pmd;
24923+ unsigned long addr, end;
24924+
24925+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24926+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24927+ pgd = pgd_offset_k(addr);
24928+ pud = pud_offset(pgd, addr);
24929+ pmd = pmd_offset(pud, addr);
24930+ if (!pmd_present(*pmd))
24931+ continue;
24932+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24933+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24934+ else
24935+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24936+ }
24937+
24938+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24939+ end = addr + KERNEL_IMAGE_SIZE;
24940+ for (; addr < end; addr += PMD_SIZE) {
24941+ pgd = pgd_offset_k(addr);
24942+ pud = pud_offset(pgd, addr);
24943+ pmd = pmd_offset(pud, addr);
24944+ if (!pmd_present(*pmd))
24945+ continue;
24946+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24947+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24948+ }
24949+#endif
24950+
24951+ flush_tlb_all();
24952+#endif
24953+
24954 free_init_pages("unused kernel memory",
24955 (unsigned long)(&__init_begin),
24956 (unsigned long)(&__init_end));
24957diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24958index 30938c1..bda3d5d 100644
24959--- a/arch/x86/mm/init_32.c
24960+++ b/arch/x86/mm/init_32.c
24961@@ -72,36 +72,6 @@ static __init void *alloc_low_page(void)
24962 }
24963
24964 /*
24965- * Creates a middle page table and puts a pointer to it in the
24966- * given global directory entry. This only returns the gd entry
24967- * in non-PAE compilation mode, since the middle layer is folded.
24968- */
24969-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24970-{
24971- pud_t *pud;
24972- pmd_t *pmd_table;
24973-
24974-#ifdef CONFIG_X86_PAE
24975- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24976- if (after_bootmem)
24977- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24978- else
24979- pmd_table = (pmd_t *)alloc_low_page();
24980- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24981- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24982- pud = pud_offset(pgd, 0);
24983- BUG_ON(pmd_table != pmd_offset(pud, 0));
24984-
24985- return pmd_table;
24986- }
24987-#endif
24988- pud = pud_offset(pgd, 0);
24989- pmd_table = pmd_offset(pud, 0);
24990-
24991- return pmd_table;
24992-}
24993-
24994-/*
24995 * Create a page table and place a pointer to it in a middle page
24996 * directory entry:
24997 */
24998@@ -121,13 +91,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24999 page_table = (pte_t *)alloc_low_page();
25000
25001 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
25002+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25003+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
25004+#else
25005 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
25006+#endif
25007 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
25008 }
25009
25010 return pte_offset_kernel(pmd, 0);
25011 }
25012
25013+static pmd_t * __init one_md_table_init(pgd_t *pgd)
25014+{
25015+ pud_t *pud;
25016+ pmd_t *pmd_table;
25017+
25018+ pud = pud_offset(pgd, 0);
25019+ pmd_table = pmd_offset(pud, 0);
25020+
25021+ return pmd_table;
25022+}
25023+
25024 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
25025 {
25026 int pgd_idx = pgd_index(vaddr);
25027@@ -201,6 +186,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25028 int pgd_idx, pmd_idx;
25029 unsigned long vaddr;
25030 pgd_t *pgd;
25031+ pud_t *pud;
25032 pmd_t *pmd;
25033 pte_t *pte = NULL;
25034
25035@@ -210,8 +196,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25036 pgd = pgd_base + pgd_idx;
25037
25038 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
25039- pmd = one_md_table_init(pgd);
25040- pmd = pmd + pmd_index(vaddr);
25041+ pud = pud_offset(pgd, vaddr);
25042+ pmd = pmd_offset(pud, vaddr);
25043+
25044+#ifdef CONFIG_X86_PAE
25045+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25046+#endif
25047+
25048 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
25049 pmd++, pmd_idx++) {
25050 pte = page_table_kmap_check(one_page_table_init(pmd),
25051@@ -223,11 +214,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
25052 }
25053 }
25054
25055-static inline int is_kernel_text(unsigned long addr)
25056+static inline int is_kernel_text(unsigned long start, unsigned long end)
25057 {
25058- if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
25059- return 1;
25060- return 0;
25061+ if ((start > ktla_ktva((unsigned long)_etext) ||
25062+ end <= ktla_ktva((unsigned long)_stext)) &&
25063+ (start > ktla_ktva((unsigned long)_einittext) ||
25064+ end <= ktla_ktva((unsigned long)_sinittext)) &&
25065+
25066+#ifdef CONFIG_ACPI_SLEEP
25067+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
25068+#endif
25069+
25070+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
25071+ return 0;
25072+ return 1;
25073 }
25074
25075 /*
25076@@ -243,9 +243,10 @@ kernel_physical_mapping_init(unsigned long start,
25077 int use_pse = page_size_mask == (1<<PG_LEVEL_2M);
25078 unsigned long start_pfn, end_pfn;
25079 pgd_t *pgd_base = swapper_pg_dir;
25080- int pgd_idx, pmd_idx, pte_ofs;
25081+ unsigned int pgd_idx, pmd_idx, pte_ofs;
25082 unsigned long pfn;
25083 pgd_t *pgd;
25084+ pud_t *pud;
25085 pmd_t *pmd;
25086 pte_t *pte;
25087 unsigned pages_2m, pages_4k;
25088@@ -278,8 +279,13 @@ repeat:
25089 pfn = start_pfn;
25090 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25091 pgd = pgd_base + pgd_idx;
25092- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
25093- pmd = one_md_table_init(pgd);
25094+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
25095+ pud = pud_offset(pgd, 0);
25096+ pmd = pmd_offset(pud, 0);
25097+
25098+#ifdef CONFIG_X86_PAE
25099+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
25100+#endif
25101
25102 if (pfn >= end_pfn)
25103 continue;
25104@@ -291,14 +297,13 @@ repeat:
25105 #endif
25106 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
25107 pmd++, pmd_idx++) {
25108- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
25109+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
25110
25111 /*
25112 * Map with big pages if possible, otherwise
25113 * create normal page tables:
25114 */
25115 if (use_pse) {
25116- unsigned int addr2;
25117 pgprot_t prot = PAGE_KERNEL_LARGE;
25118 /*
25119 * first pass will use the same initial
25120@@ -308,11 +313,7 @@ repeat:
25121 __pgprot(PTE_IDENT_ATTR |
25122 _PAGE_PSE);
25123
25124- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
25125- PAGE_OFFSET + PAGE_SIZE-1;
25126-
25127- if (is_kernel_text(addr) ||
25128- is_kernel_text(addr2))
25129+ if (is_kernel_text(address, address + PMD_SIZE))
25130 prot = PAGE_KERNEL_LARGE_EXEC;
25131
25132 pages_2m++;
25133@@ -329,7 +330,7 @@ repeat:
25134 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
25135 pte += pte_ofs;
25136 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
25137- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
25138+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
25139 pgprot_t prot = PAGE_KERNEL;
25140 /*
25141 * first pass will use the same initial
25142@@ -337,7 +338,7 @@ repeat:
25143 */
25144 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
25145
25146- if (is_kernel_text(addr))
25147+ if (is_kernel_text(address, address + PAGE_SIZE))
25148 prot = PAGE_KERNEL_EXEC;
25149
25150 pages_4k++;
25151@@ -489,7 +490,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
25152
25153 pud = pud_offset(pgd, va);
25154 pmd = pmd_offset(pud, va);
25155- if (!pmd_present(*pmd))
25156+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
25157 break;
25158
25159 pte = pte_offset_kernel(pmd, va);
25160@@ -541,9 +542,7 @@ void __init early_ioremap_page_table_range_init(void)
25161
25162 static void __init pagetable_init(void)
25163 {
25164- pgd_t *pgd_base = swapper_pg_dir;
25165-
25166- permanent_kmaps_init(pgd_base);
25167+ permanent_kmaps_init(swapper_pg_dir);
25168 }
25169
25170 #ifdef CONFIG_ACPI_SLEEP
25171@@ -551,12 +550,12 @@ static void __init pagetable_init(void)
25172 * ACPI suspend needs this for resume, because things like the intel-agp
25173 * driver might have split up a kernel 4MB mapping.
25174 */
25175-char swsusp_pg_dir[PAGE_SIZE]
25176+pgd_t swsusp_pg_dir[PTRS_PER_PGD]
25177 __attribute__ ((aligned(PAGE_SIZE)));
25178
25179 static inline void save_pg_dir(void)
25180 {
25181- memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
25182+ clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
25183 }
25184 #else /* !CONFIG_ACPI_SLEEP */
25185 static inline void save_pg_dir(void)
25186@@ -588,7 +587,7 @@ void zap_low_mappings(bool early)
25187 flush_tlb_all();
25188 }
25189
25190-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25191+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
25192 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25193
25194 /* user-defined highmem size */
25195@@ -777,7 +776,7 @@ void __init setup_bootmem_allocator(void)
25196 * Initialize the boot-time allocator (with low memory only):
25197 */
25198 bootmap_size = bootmem_bootmap_pages(max_low_pfn)<<PAGE_SHIFT;
25199- bootmap = find_e820_area(0, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
25200+ bootmap = find_e820_area(0x100000, max_pfn_mapped<<PAGE_SHIFT, bootmap_size,
25201 PAGE_SIZE);
25202 if (bootmap == -1L)
25203 panic("Cannot find bootmem map of size %ld\n", bootmap_size);
25204@@ -864,6 +863,12 @@ void __init mem_init(void)
25205
25206 pci_iommu_alloc();
25207
25208+#ifdef CONFIG_PAX_PER_CPU_PGD
25209+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25210+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25211+ KERNEL_PGD_PTRS);
25212+#endif
25213+
25214 #ifdef CONFIG_FLATMEM
25215 BUG_ON(!mem_map);
25216 #endif
25217@@ -881,7 +886,7 @@ void __init mem_init(void)
25218 set_highmem_pages_init();
25219
25220 codesize = (unsigned long) &_etext - (unsigned long) &_text;
25221- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25222+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25223 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25224
25225 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25226@@ -923,10 +928,10 @@ void __init mem_init(void)
25227 ((unsigned long)&__init_end -
25228 (unsigned long)&__init_begin) >> 10,
25229
25230- (unsigned long)&_etext, (unsigned long)&_edata,
25231- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25232+ (unsigned long)&_sdata, (unsigned long)&_edata,
25233+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25234
25235- (unsigned long)&_text, (unsigned long)&_etext,
25236+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25237 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25238
25239 /*
25240@@ -1007,6 +1012,7 @@ void set_kernel_text_rw(void)
25241 if (!kernel_set_to_readonly)
25242 return;
25243
25244+ start = ktla_ktva(start);
25245 pr_debug("Set kernel text: %lx - %lx for read write\n",
25246 start, start+size);
25247
25248@@ -1021,6 +1027,7 @@ void set_kernel_text_ro(void)
25249 if (!kernel_set_to_readonly)
25250 return;
25251
25252+ start = ktla_ktva(start);
25253 pr_debug("Set kernel text: %lx - %lx for read only\n",
25254 start, start+size);
25255
25256@@ -1032,6 +1039,7 @@ void mark_rodata_ro(void)
25257 unsigned long start = PFN_ALIGN(_text);
25258 unsigned long size = PFN_ALIGN(_etext) - start;
25259
25260+ start = ktla_ktva(start);
25261 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25262 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25263 size >> 10);
25264diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25265index 7d095ad..25d2549 100644
25266--- a/arch/x86/mm/init_64.c
25267+++ b/arch/x86/mm/init_64.c
25268@@ -164,7 +164,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25269 pmd = fill_pmd(pud, vaddr);
25270 pte = fill_pte(pmd, vaddr);
25271
25272+ pax_open_kernel();
25273 set_pte(pte, new_pte);
25274+ pax_close_kernel();
25275
25276 /*
25277 * It's enough to flush this one mapping.
25278@@ -223,14 +225,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25279 pgd = pgd_offset_k((unsigned long)__va(phys));
25280 if (pgd_none(*pgd)) {
25281 pud = (pud_t *) spp_getpage();
25282- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25283- _PAGE_USER));
25284+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25285 }
25286 pud = pud_offset(pgd, (unsigned long)__va(phys));
25287 if (pud_none(*pud)) {
25288 pmd = (pmd_t *) spp_getpage();
25289- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25290- _PAGE_USER));
25291+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25292 }
25293 pmd = pmd_offset(pud, phys);
25294 BUG_ON(!pmd_none(*pmd));
25295@@ -675,6 +675,12 @@ void __init mem_init(void)
25296
25297 pci_iommu_alloc();
25298
25299+#ifdef CONFIG_PAX_PER_CPU_PGD
25300+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25301+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25302+ KERNEL_PGD_PTRS);
25303+#endif
25304+
25305 /* clear_bss() already clear the empty_zero_page */
25306
25307 reservedpages = 0;
25308@@ -861,8 +867,8 @@ int kern_addr_valid(unsigned long addr)
25309 static struct vm_area_struct gate_vma = {
25310 .vm_start = VSYSCALL_START,
25311 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25312- .vm_page_prot = PAGE_READONLY_EXEC,
25313- .vm_flags = VM_READ | VM_EXEC
25314+ .vm_page_prot = PAGE_READONLY,
25315+ .vm_flags = VM_READ
25316 };
25317
25318 struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
25319@@ -896,7 +902,7 @@ int in_gate_area_no_task(unsigned long addr)
25320
25321 const char *arch_vma_name(struct vm_area_struct *vma)
25322 {
25323- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25324+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25325 return "[vdso]";
25326 if (vma == &gate_vma)
25327 return "[vsyscall]";
25328diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25329index 84e236c..69bd3f6 100644
25330--- a/arch/x86/mm/iomap_32.c
25331+++ b/arch/x86/mm/iomap_32.c
25332@@ -65,7 +65,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, enum km_type type, pgprot_t prot)
25333 debug_kmap_atomic(type);
25334 idx = type + KM_TYPE_NR * smp_processor_id();
25335 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25336+
25337+ pax_open_kernel();
25338 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25339+ pax_close_kernel();
25340+
25341 arch_flush_lazy_mmu_mode();
25342
25343 return (void *)vaddr;
25344diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25345index 2feb9bd..3646202 100644
25346--- a/arch/x86/mm/ioremap.c
25347+++ b/arch/x86/mm/ioremap.c
25348@@ -41,8 +41,8 @@ int page_is_ram(unsigned long pagenr)
25349 * Second special case: Some BIOSen report the PC BIOS
25350 * area (640->1Mb) as ram even though it is not.
25351 */
25352- if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
25353- pagenr < (BIOS_END >> PAGE_SHIFT))
25354+ if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
25355+ pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
25356 return 0;
25357
25358 for (i = 0; i < e820.nr_map; i++) {
25359@@ -137,13 +137,10 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25360 /*
25361 * Don't allow anybody to remap normal RAM that we're using..
25362 */
25363- for (pfn = phys_addr >> PAGE_SHIFT;
25364- (pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK);
25365- pfn++) {
25366-
25367+ for (pfn = phys_addr >> PAGE_SHIFT; ((resource_size_t)pfn << PAGE_SHIFT) < (last_addr & PAGE_MASK); pfn++) {
25368 int is_ram = page_is_ram(pfn);
25369
25370- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25371+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25372 return NULL;
25373 WARN_ON_ONCE(is_ram);
25374 }
25375@@ -407,7 +404,7 @@ static int __init early_ioremap_debug_setup(char *str)
25376 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25377
25378 static __initdata int after_paging_init;
25379-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25380+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25381
25382 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25383 {
25384@@ -439,8 +436,7 @@ void __init early_ioremap_init(void)
25385 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25386
25387 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25388- memset(bm_pte, 0, sizeof(bm_pte));
25389- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25390+ pmd_populate_user(&init_mm, pmd, bm_pte);
25391
25392 /*
25393 * The boot-ioremap range spans multiple pmds, for which
25394diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25395index 8cc1833..1abbc5b 100644
25396--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25397+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25398@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25399 * memory (e.g. tracked pages)? For now, we need this to avoid
25400 * invoking kmemcheck for PnP BIOS calls.
25401 */
25402- if (regs->flags & X86_VM_MASK)
25403+ if (v8086_mode(regs))
25404 return false;
25405- if (regs->cs != __KERNEL_CS)
25406+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25407 return false;
25408
25409 pte = kmemcheck_pte_lookup(address);
25410diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25411index c8191de..2975082 100644
25412--- a/arch/x86/mm/mmap.c
25413+++ b/arch/x86/mm/mmap.c
25414@@ -49,7 +49,7 @@ static unsigned int stack_maxrandom_size(void)
25415 * Leave an at least ~128 MB hole with possible stack randomization.
25416 */
25417 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25418-#define MAX_GAP (TASK_SIZE/6*5)
25419+#define MAX_GAP (pax_task_size/6*5)
25420
25421 /*
25422 * True on X86_32 or when emulating IA32 on X86_64
25423@@ -94,27 +94,40 @@ static unsigned long mmap_rnd(void)
25424 return rnd << PAGE_SHIFT;
25425 }
25426
25427-static unsigned long mmap_base(void)
25428+static unsigned long mmap_base(struct mm_struct *mm)
25429 {
25430 unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
25431+ unsigned long pax_task_size = TASK_SIZE;
25432+
25433+#ifdef CONFIG_PAX_SEGMEXEC
25434+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25435+ pax_task_size = SEGMEXEC_TASK_SIZE;
25436+#endif
25437
25438 if (gap < MIN_GAP)
25439 gap = MIN_GAP;
25440 else if (gap > MAX_GAP)
25441 gap = MAX_GAP;
25442
25443- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25444+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25445 }
25446
25447 /*
25448 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25449 * does, but not when emulating X86_32
25450 */
25451-static unsigned long mmap_legacy_base(void)
25452+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25453 {
25454- if (mmap_is_ia32())
25455+ if (mmap_is_ia32()) {
25456+
25457+#ifdef CONFIG_PAX_SEGMEXEC
25458+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25459+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25460+ else
25461+#endif
25462+
25463 return TASK_UNMAPPED_BASE;
25464- else
25465+ } else
25466 return TASK_UNMAPPED_BASE + mmap_rnd();
25467 }
25468
25469@@ -125,11 +138,23 @@ static unsigned long mmap_legacy_base(void)
25470 void arch_pick_mmap_layout(struct mm_struct *mm)
25471 {
25472 if (mmap_is_legacy()) {
25473- mm->mmap_base = mmap_legacy_base();
25474+ mm->mmap_base = mmap_legacy_base(mm);
25475+
25476+#ifdef CONFIG_PAX_RANDMMAP
25477+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25478+ mm->mmap_base += mm->delta_mmap;
25479+#endif
25480+
25481 mm->get_unmapped_area = arch_get_unmapped_area;
25482 mm->unmap_area = arch_unmap_area;
25483 } else {
25484- mm->mmap_base = mmap_base();
25485+ mm->mmap_base = mmap_base(mm);
25486+
25487+#ifdef CONFIG_PAX_RANDMMAP
25488+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25489+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25490+#endif
25491+
25492 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25493 mm->unmap_area = arch_unmap_area_topdown;
25494 }
25495diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25496index 132772a..b961f11 100644
25497--- a/arch/x86/mm/mmio-mod.c
25498+++ b/arch/x86/mm/mmio-mod.c
25499@@ -193,7 +193,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25500 break;
25501 default:
25502 {
25503- unsigned char *ip = (unsigned char *)instptr;
25504+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25505 my_trace->opcode = MMIO_UNKNOWN_OP;
25506 my_trace->width = 0;
25507 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25508@@ -233,7 +233,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25509 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25510 void __iomem *addr)
25511 {
25512- static atomic_t next_id;
25513+ static atomic_unchecked_t next_id;
25514 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25515 /* These are page-unaligned. */
25516 struct mmiotrace_map map = {
25517@@ -257,7 +257,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25518 .private = trace
25519 },
25520 .phys = offset,
25521- .id = atomic_inc_return(&next_id)
25522+ .id = atomic_inc_return_unchecked(&next_id)
25523 };
25524 map.map_id = trace->id;
25525
25526diff --git a/arch/x86/mm/numa_32.c b/arch/x86/mm/numa_32.c
25527index d253006..e56dd6a 100644
25528--- a/arch/x86/mm/numa_32.c
25529+++ b/arch/x86/mm/numa_32.c
25530@@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int nid, unsigned long start_pfn,
25531 }
25532 #endif
25533
25534-extern unsigned long find_max_low_pfn(void);
25535 extern unsigned long highend_pfn, highstart_pfn;
25536
25537 #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
25538diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25539index e1d1069..2251ff3 100644
25540--- a/arch/x86/mm/pageattr-test.c
25541+++ b/arch/x86/mm/pageattr-test.c
25542@@ -36,7 +36,7 @@ enum {
25543
25544 static int pte_testbit(pte_t pte)
25545 {
25546- return pte_flags(pte) & _PAGE_UNUSED1;
25547+ return pte_flags(pte) & _PAGE_CPA_TEST;
25548 }
25549
25550 struct split_state {
25551diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25552index dd38bfb..8c12306 100644
25553--- a/arch/x86/mm/pageattr.c
25554+++ b/arch/x86/mm/pageattr.c
25555@@ -261,16 +261,17 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25556 * PCI BIOS based config access (CONFIG_PCI_GOBIOS) support.
25557 */
25558 if (within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25559- pgprot_val(forbidden) |= _PAGE_NX;
25560+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25561
25562 /*
25563 * The kernel text needs to be executable for obvious reasons
25564 * Does not cover __inittext since that is gone later on. On
25565 * 64bit we do not enforce !NX on the low mapping
25566 */
25567- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25568- pgprot_val(forbidden) |= _PAGE_NX;
25569+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25570+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25571
25572+#ifdef CONFIG_DEBUG_RODATA
25573 /*
25574 * The .rodata section needs to be read-only. Using the pfn
25575 * catches all aliases.
25576@@ -278,6 +279,14 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25577 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25578 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25579 pgprot_val(forbidden) |= _PAGE_RW;
25580+#endif
25581+
25582+#ifdef CONFIG_PAX_KERNEXEC
25583+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25584+ pgprot_val(forbidden) |= _PAGE_RW;
25585+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25586+ }
25587+#endif
25588
25589 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25590
25591@@ -331,23 +340,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25592 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25593 {
25594 /* change init_mm */
25595+ pax_open_kernel();
25596 set_pte_atomic(kpte, pte);
25597+
25598 #ifdef CONFIG_X86_32
25599 if (!SHARED_KERNEL_PMD) {
25600+
25601+#ifdef CONFIG_PAX_PER_CPU_PGD
25602+ unsigned long cpu;
25603+#else
25604 struct page *page;
25605+#endif
25606
25607+#ifdef CONFIG_PAX_PER_CPU_PGD
25608+ for (cpu = 0; cpu < NR_CPUS; ++cpu) {
25609+ pgd_t *pgd = get_cpu_pgd(cpu);
25610+#else
25611 list_for_each_entry(page, &pgd_list, lru) {
25612- pgd_t *pgd;
25613+ pgd_t *pgd = (pgd_t *)page_address(page);
25614+#endif
25615+
25616 pud_t *pud;
25617 pmd_t *pmd;
25618
25619- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25620+ pgd += pgd_index(address);
25621 pud = pud_offset(pgd, address);
25622 pmd = pmd_offset(pud, address);
25623 set_pte_atomic((pte_t *)pmd, pte);
25624 }
25625 }
25626 #endif
25627+ pax_close_kernel();
25628 }
25629
25630 static int
25631diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25632index e78cd0e..de0a817 100644
25633--- a/arch/x86/mm/pat.c
25634+++ b/arch/x86/mm/pat.c
25635@@ -258,7 +258,7 @@ chk_conflict(struct memtype *new, struct memtype *entry, unsigned long *type)
25636
25637 conflict:
25638 printk(KERN_INFO "%s:%d conflicting memory types "
25639- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, new->start,
25640+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), new->start,
25641 new->end, cattr_name(new->type), cattr_name(entry->type));
25642 return -EBUSY;
25643 }
25644@@ -559,7 +559,7 @@ unlock_ret:
25645
25646 if (err) {
25647 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25648- current->comm, current->pid, start, end);
25649+ current->comm, task_pid_nr(current), start, end);
25650 }
25651
25652 dprintk("free_memtype request 0x%Lx-0x%Lx\n", start, end);
25653@@ -689,8 +689,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25654 while (cursor < to) {
25655 if (!devmem_is_allowed(pfn)) {
25656 printk(KERN_INFO
25657- "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25658- current->comm, from, to);
25659+ "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25660+ current->comm, from, to, cursor);
25661 return 0;
25662 }
25663 cursor += PAGE_SIZE;
25664@@ -755,7 +755,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25665 printk(KERN_INFO
25666 "%s:%d ioremap_change_attr failed %s "
25667 "for %Lx-%Lx\n",
25668- current->comm, current->pid,
25669+ current->comm, task_pid_nr(current),
25670 cattr_name(flags),
25671 base, (unsigned long long)(base + size));
25672 return -EINVAL;
25673@@ -813,7 +813,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25674 free_memtype(paddr, paddr + size);
25675 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25676 " for %Lx-%Lx, got %s\n",
25677- current->comm, current->pid,
25678+ current->comm, task_pid_nr(current),
25679 cattr_name(want_flags),
25680 (unsigned long long)paddr,
25681 (unsigned long long)(paddr + size),
25682diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25683index df3d5c8..c2223e1 100644
25684--- a/arch/x86/mm/pf_in.c
25685+++ b/arch/x86/mm/pf_in.c
25686@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25687 int i;
25688 enum reason_type rv = OTHERS;
25689
25690- p = (unsigned char *)ins_addr;
25691+ p = (unsigned char *)ktla_ktva(ins_addr);
25692 p += skip_prefix(p, &prf);
25693 p += get_opcode(p, &opcode);
25694
25695@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25696 struct prefix_bits prf;
25697 int i;
25698
25699- p = (unsigned char *)ins_addr;
25700+ p = (unsigned char *)ktla_ktva(ins_addr);
25701 p += skip_prefix(p, &prf);
25702 p += get_opcode(p, &opcode);
25703
25704@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25705 struct prefix_bits prf;
25706 int i;
25707
25708- p = (unsigned char *)ins_addr;
25709+ p = (unsigned char *)ktla_ktva(ins_addr);
25710 p += skip_prefix(p, &prf);
25711 p += get_opcode(p, &opcode);
25712
25713@@ -417,7 +417,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25714 int i;
25715 unsigned long rv;
25716
25717- p = (unsigned char *)ins_addr;
25718+ p = (unsigned char *)ktla_ktva(ins_addr);
25719 p += skip_prefix(p, &prf);
25720 p += get_opcode(p, &opcode);
25721 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25722@@ -472,7 +472,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25723 int i;
25724 unsigned long rv;
25725
25726- p = (unsigned char *)ins_addr;
25727+ p = (unsigned char *)ktla_ktva(ins_addr);
25728 p += skip_prefix(p, &prf);
25729 p += get_opcode(p, &opcode);
25730 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25731diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25732index e0e6fad..6b90017 100644
25733--- a/arch/x86/mm/pgtable.c
25734+++ b/arch/x86/mm/pgtable.c
25735@@ -83,9 +83,52 @@ static inline void pgd_list_del(pgd_t *pgd)
25736 list_del(&page->lru);
25737 }
25738
25739-#define UNSHARED_PTRS_PER_PGD \
25740- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25741+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25742+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25743
25744+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25745+{
25746+ while (count--)
25747+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25748+}
25749+#endif
25750+
25751+#ifdef CONFIG_PAX_PER_CPU_PGD
25752+void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
25753+{
25754+ while (count--)
25755+
25756+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25757+ *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
25758+#else
25759+ *dst++ = *src++;
25760+#endif
25761+
25762+}
25763+#endif
25764+
25765+#ifdef CONFIG_X86_64
25766+#define pxd_t pud_t
25767+#define pyd_t pgd_t
25768+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25769+#define pxd_free(mm, pud) pud_free((mm), (pud))
25770+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25771+#define pyd_offset(mm ,address) pgd_offset((mm), (address))
25772+#define PYD_SIZE PGDIR_SIZE
25773+#else
25774+#define pxd_t pmd_t
25775+#define pyd_t pud_t
25776+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25777+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25778+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25779+#define pyd_offset(mm ,address) pud_offset((mm), (address))
25780+#define PYD_SIZE PUD_SIZE
25781+#endif
25782+
25783+#ifdef CONFIG_PAX_PER_CPU_PGD
25784+static inline void pgd_ctor(pgd_t *pgd) {}
25785+static inline void pgd_dtor(pgd_t *pgd) {}
25786+#else
25787 static void pgd_ctor(pgd_t *pgd)
25788 {
25789 /* If the pgd points to a shared pagetable level (either the
25790@@ -119,6 +162,7 @@ static void pgd_dtor(pgd_t *pgd)
25791 pgd_list_del(pgd);
25792 spin_unlock_irqrestore(&pgd_lock, flags);
25793 }
25794+#endif
25795
25796 /*
25797 * List of all pgd's needed for non-PAE so it can invalidate entries
25798@@ -131,7 +175,7 @@ static void pgd_dtor(pgd_t *pgd)
25799 * -- wli
25800 */
25801
25802-#ifdef CONFIG_X86_PAE
25803+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25804 /*
25805 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25806 * updating the top-level pagetable entries to guarantee the
25807@@ -143,7 +187,7 @@ static void pgd_dtor(pgd_t *pgd)
25808 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25809 * and initialize the kernel pmds here.
25810 */
25811-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25812+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25813
25814 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25815 {
25816@@ -161,36 +205,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25817 */
25818 flush_tlb_mm(mm);
25819 }
25820+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25821+#define PREALLOCATED_PXDS USER_PGD_PTRS
25822 #else /* !CONFIG_X86_PAE */
25823
25824 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25825-#define PREALLOCATED_PMDS 0
25826+#define PREALLOCATED_PXDS 0
25827
25828 #endif /* CONFIG_X86_PAE */
25829
25830-static void free_pmds(pmd_t *pmds[])
25831+static void free_pxds(pxd_t *pxds[])
25832 {
25833 int i;
25834
25835- for(i = 0; i < PREALLOCATED_PMDS; i++)
25836- if (pmds[i])
25837- free_page((unsigned long)pmds[i]);
25838+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25839+ if (pxds[i])
25840+ free_page((unsigned long)pxds[i]);
25841 }
25842
25843-static int preallocate_pmds(pmd_t *pmds[])
25844+static int preallocate_pxds(pxd_t *pxds[])
25845 {
25846 int i;
25847 bool failed = false;
25848
25849- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25850- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25851- if (pmd == NULL)
25852+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25853+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25854+ if (pxd == NULL)
25855 failed = true;
25856- pmds[i] = pmd;
25857+ pxds[i] = pxd;
25858 }
25859
25860 if (failed) {
25861- free_pmds(pmds);
25862+ free_pxds(pxds);
25863 return -ENOMEM;
25864 }
25865
25866@@ -203,51 +249,56 @@ static int preallocate_pmds(pmd_t *pmds[])
25867 * preallocate which never got a corresponding vma will need to be
25868 * freed manually.
25869 */
25870-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25871+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25872 {
25873 int i;
25874
25875- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25876+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25877 pgd_t pgd = pgdp[i];
25878
25879 if (pgd_val(pgd) != 0) {
25880- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25881+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25882
25883- pgdp[i] = native_make_pgd(0);
25884+ set_pgd(pgdp + i, native_make_pgd(0));
25885
25886- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25887- pmd_free(mm, pmd);
25888+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25889+ pxd_free(mm, pxd);
25890 }
25891 }
25892 }
25893
25894-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25895+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25896 {
25897- pud_t *pud;
25898+ pyd_t *pyd;
25899 unsigned long addr;
25900 int i;
25901
25902- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25903+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25904 return;
25905
25906- pud = pud_offset(pgd, 0);
25907+#ifdef CONFIG_X86_64
25908+ pyd = pyd_offset(mm, 0L);
25909+#else
25910+ pyd = pyd_offset(pgd, 0L);
25911+#endif
25912
25913- for (addr = i = 0; i < PREALLOCATED_PMDS;
25914- i++, pud++, addr += PUD_SIZE) {
25915- pmd_t *pmd = pmds[i];
25916+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25917+ i++, pyd++, addr += PYD_SIZE) {
25918+ pxd_t *pxd = pxds[i];
25919
25920 if (i >= KERNEL_PGD_BOUNDARY)
25921- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25922- sizeof(pmd_t) * PTRS_PER_PMD);
25923+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25924+ sizeof(pxd_t) * PTRS_PER_PMD);
25925
25926- pud_populate(mm, pud, pmd);
25927+ pyd_populate(mm, pyd, pxd);
25928 }
25929 }
25930
25931 pgd_t *pgd_alloc(struct mm_struct *mm)
25932 {
25933 pgd_t *pgd;
25934- pmd_t *pmds[PREALLOCATED_PMDS];
25935+ pxd_t *pxds[PREALLOCATED_PXDS];
25936+
25937 unsigned long flags;
25938
25939 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25940@@ -257,11 +308,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25941
25942 mm->pgd = pgd;
25943
25944- if (preallocate_pmds(pmds) != 0)
25945+ if (preallocate_pxds(pxds) != 0)
25946 goto out_free_pgd;
25947
25948 if (paravirt_pgd_alloc(mm) != 0)
25949- goto out_free_pmds;
25950+ goto out_free_pxds;
25951
25952 /*
25953 * Make sure that pre-populating the pmds is atomic with
25954@@ -271,14 +322,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25955 spin_lock_irqsave(&pgd_lock, flags);
25956
25957 pgd_ctor(pgd);
25958- pgd_prepopulate_pmd(mm, pgd, pmds);
25959+ pgd_prepopulate_pxd(mm, pgd, pxds);
25960
25961 spin_unlock_irqrestore(&pgd_lock, flags);
25962
25963 return pgd;
25964
25965-out_free_pmds:
25966- free_pmds(pmds);
25967+out_free_pxds:
25968+ free_pxds(pxds);
25969 out_free_pgd:
25970 free_page((unsigned long)pgd);
25971 out:
25972@@ -287,7 +338,7 @@ out:
25973
25974 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25975 {
25976- pgd_mop_up_pmds(mm, pgd);
25977+ pgd_mop_up_pxds(mm, pgd);
25978 pgd_dtor(pgd);
25979 paravirt_pgd_free(mm, pgd);
25980 free_page((unsigned long)pgd);
25981diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25982index 46c8834..fcab43d 100644
25983--- a/arch/x86/mm/pgtable_32.c
25984+++ b/arch/x86/mm/pgtable_32.c
25985@@ -49,10 +49,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25986 return;
25987 }
25988 pte = pte_offset_kernel(pmd, vaddr);
25989+
25990+ pax_open_kernel();
25991 if (pte_val(pteval))
25992 set_pte_at(&init_mm, vaddr, pte, pteval);
25993 else
25994 pte_clear(&init_mm, vaddr, pte);
25995+ pax_close_kernel();
25996
25997 /*
25998 * It's enough to flush this one mapping.
25999diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
26000index 513d8ed..978c161 100644
26001--- a/arch/x86/mm/setup_nx.c
26002+++ b/arch/x86/mm/setup_nx.c
26003@@ -4,11 +4,10 @@
26004
26005 #include <asm/pgtable.h>
26006
26007+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26008 int nx_enabled;
26009
26010-#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26011-static int disable_nx __cpuinitdata;
26012-
26013+#ifndef CONFIG_PAX_PAGEEXEC
26014 /*
26015 * noexec = on|off
26016 *
26017@@ -22,32 +21,26 @@ static int __init noexec_setup(char *str)
26018 if (!str)
26019 return -EINVAL;
26020 if (!strncmp(str, "on", 2)) {
26021- __supported_pte_mask |= _PAGE_NX;
26022- disable_nx = 0;
26023+ nx_enabled = 1;
26024 } else if (!strncmp(str, "off", 3)) {
26025- disable_nx = 1;
26026- __supported_pte_mask &= ~_PAGE_NX;
26027+ nx_enabled = 0;
26028 }
26029 return 0;
26030 }
26031 early_param("noexec", noexec_setup);
26032 #endif
26033+#endif
26034
26035 #ifdef CONFIG_X86_PAE
26036 void __init set_nx(void)
26037 {
26038- unsigned int v[4], l, h;
26039+ if (!nx_enabled && cpu_has_nx) {
26040+ unsigned l, h;
26041
26042- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
26043- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
26044-
26045- if ((v[3] & (1 << 20)) && !disable_nx) {
26046- rdmsr(MSR_EFER, l, h);
26047- l |= EFER_NX;
26048- wrmsr(MSR_EFER, l, h);
26049- nx_enabled = 1;
26050- __supported_pte_mask |= _PAGE_NX;
26051- }
26052+ __supported_pte_mask &= ~_PAGE_NX;
26053+ rdmsr(MSR_EFER, l, h);
26054+ l &= ~EFER_NX;
26055+ wrmsr(MSR_EFER, l, h);
26056 }
26057 }
26058 #else
26059@@ -62,7 +55,7 @@ void __cpuinit check_efer(void)
26060 unsigned long efer;
26061
26062 rdmsrl(MSR_EFER, efer);
26063- if (!(efer & EFER_NX) || disable_nx)
26064+ if (!(efer & EFER_NX) || !nx_enabled)
26065 __supported_pte_mask &= ~_PAGE_NX;
26066 }
26067 #endif
26068diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
26069index 36fe08e..b123d3a 100644
26070--- a/arch/x86/mm/tlb.c
26071+++ b/arch/x86/mm/tlb.c
26072@@ -61,7 +61,11 @@ void leave_mm(int cpu)
26073 BUG();
26074 cpumask_clear_cpu(cpu,
26075 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
26076+
26077+#ifndef CONFIG_PAX_PER_CPU_PGD
26078 load_cr3(swapper_pg_dir);
26079+#endif
26080+
26081 }
26082 EXPORT_SYMBOL_GPL(leave_mm);
26083
26084diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26085index 829edf0..672adb3 100644
26086--- a/arch/x86/oprofile/backtrace.c
26087+++ b/arch/x86/oprofile/backtrace.c
26088@@ -115,7 +115,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26089 {
26090 struct frame_head *head = (struct frame_head *)frame_pointer(regs);
26091
26092- if (!user_mode_vm(regs)) {
26093+ if (!user_mode(regs)) {
26094 unsigned long stack = kernel_stack_pointer(regs);
26095 if (depth)
26096 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26097diff --git a/arch/x86/oprofile/op_model_p4.c b/arch/x86/oprofile/op_model_p4.c
26098index e6a160a..36deff6 100644
26099--- a/arch/x86/oprofile/op_model_p4.c
26100+++ b/arch/x86/oprofile/op_model_p4.c
26101@@ -50,7 +50,7 @@ static inline void setup_num_counters(void)
26102 #endif
26103 }
26104
26105-static int inline addr_increment(void)
26106+static inline int addr_increment(void)
26107 {
26108 #ifdef CONFIG_SMP
26109 return smp_num_siblings == 2 ? 2 : 1;
26110diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c
26111index 1331fcf..03901b2 100644
26112--- a/arch/x86/pci/common.c
26113+++ b/arch/x86/pci/common.c
26114@@ -31,8 +31,8 @@ int noioapicreroute = 1;
26115 int pcibios_last_bus = -1;
26116 unsigned long pirq_table_addr;
26117 struct pci_bus *pci_root_bus;
26118-struct pci_raw_ops *raw_pci_ops;
26119-struct pci_raw_ops *raw_pci_ext_ops;
26120+const struct pci_raw_ops *raw_pci_ops;
26121+const struct pci_raw_ops *raw_pci_ext_ops;
26122
26123 int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
26124 int reg, int len, u32 *val)
26125diff --git a/arch/x86/pci/direct.c b/arch/x86/pci/direct.c
26126index 347d882..4baf6b6 100644
26127--- a/arch/x86/pci/direct.c
26128+++ b/arch/x86/pci/direct.c
26129@@ -79,7 +79,7 @@ static int pci_conf1_write(unsigned int seg, unsigned int bus,
26130
26131 #undef PCI_CONF1_ADDRESS
26132
26133-struct pci_raw_ops pci_direct_conf1 = {
26134+const struct pci_raw_ops pci_direct_conf1 = {
26135 .read = pci_conf1_read,
26136 .write = pci_conf1_write,
26137 };
26138@@ -173,7 +173,7 @@ static int pci_conf2_write(unsigned int seg, unsigned int bus,
26139
26140 #undef PCI_CONF2_ADDRESS
26141
26142-struct pci_raw_ops pci_direct_conf2 = {
26143+const struct pci_raw_ops pci_direct_conf2 = {
26144 .read = pci_conf2_read,
26145 .write = pci_conf2_write,
26146 };
26147@@ -189,7 +189,7 @@ struct pci_raw_ops pci_direct_conf2 = {
26148 * This should be close to trivial, but it isn't, because there are buggy
26149 * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
26150 */
26151-static int __init pci_sanity_check(struct pci_raw_ops *o)
26152+static int __init pci_sanity_check(const struct pci_raw_ops *o)
26153 {
26154 u32 x = 0;
26155 int year, devfn;
26156diff --git a/arch/x86/pci/mmconfig_32.c b/arch/x86/pci/mmconfig_32.c
26157index f10a7e9..0425342 100644
26158--- a/arch/x86/pci/mmconfig_32.c
26159+++ b/arch/x86/pci/mmconfig_32.c
26160@@ -125,7 +125,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
26161 return 0;
26162 }
26163
26164-static struct pci_raw_ops pci_mmcfg = {
26165+static const struct pci_raw_ops pci_mmcfg = {
26166 .read = pci_mmcfg_read,
26167 .write = pci_mmcfg_write,
26168 };
26169diff --git a/arch/x86/pci/mmconfig_64.c b/arch/x86/pci/mmconfig_64.c
26170index 94349f8..41600a7 100644
26171--- a/arch/x86/pci/mmconfig_64.c
26172+++ b/arch/x86/pci/mmconfig_64.c
26173@@ -104,7 +104,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
26174 return 0;
26175 }
26176
26177-static struct pci_raw_ops pci_mmcfg = {
26178+static const struct pci_raw_ops pci_mmcfg = {
26179 .read = pci_mmcfg_read,
26180 .write = pci_mmcfg_write,
26181 };
26182diff --git a/arch/x86/pci/numaq_32.c b/arch/x86/pci/numaq_32.c
26183index 8eb295e..86bd657 100644
26184--- a/arch/x86/pci/numaq_32.c
26185+++ b/arch/x86/pci/numaq_32.c
26186@@ -112,7 +112,7 @@ static int pci_conf1_mq_write(unsigned int seg, unsigned int bus,
26187
26188 #undef PCI_CONF1_MQ_ADDRESS
26189
26190-static struct pci_raw_ops pci_direct_conf1_mq = {
26191+static const struct pci_raw_ops pci_direct_conf1_mq = {
26192 .read = pci_conf1_mq_read,
26193 .write = pci_conf1_mq_write
26194 };
26195diff --git a/arch/x86/pci/olpc.c b/arch/x86/pci/olpc.c
26196index b889d82..5a58a0a 100644
26197--- a/arch/x86/pci/olpc.c
26198+++ b/arch/x86/pci/olpc.c
26199@@ -297,7 +297,7 @@ static int pci_olpc_write(unsigned int seg, unsigned int bus,
26200 return 0;
26201 }
26202
26203-static struct pci_raw_ops pci_olpc_conf = {
26204+static const struct pci_raw_ops pci_olpc_conf = {
26205 .read = pci_olpc_read,
26206 .write = pci_olpc_write,
26207 };
26208diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26209index 1c975cc..ffd0536 100644
26210--- a/arch/x86/pci/pcbios.c
26211+++ b/arch/x86/pci/pcbios.c
26212@@ -56,50 +56,93 @@ union bios32 {
26213 static struct {
26214 unsigned long address;
26215 unsigned short segment;
26216-} bios32_indirect = { 0, __KERNEL_CS };
26217+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26218
26219 /*
26220 * Returns the entry point for the given service, NULL on error
26221 */
26222
26223-static unsigned long bios32_service(unsigned long service)
26224+static unsigned long __devinit bios32_service(unsigned long service)
26225 {
26226 unsigned char return_code; /* %al */
26227 unsigned long address; /* %ebx */
26228 unsigned long length; /* %ecx */
26229 unsigned long entry; /* %edx */
26230 unsigned long flags;
26231+ struct desc_struct d, *gdt;
26232
26233 local_irq_save(flags);
26234- __asm__("lcall *(%%edi); cld"
26235+
26236+ gdt = get_cpu_gdt_table(smp_processor_id());
26237+
26238+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26239+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26240+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26241+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26242+
26243+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26244 : "=a" (return_code),
26245 "=b" (address),
26246 "=c" (length),
26247 "=d" (entry)
26248 : "0" (service),
26249 "1" (0),
26250- "D" (&bios32_indirect));
26251+ "D" (&bios32_indirect),
26252+ "r"(__PCIBIOS_DS)
26253+ : "memory");
26254+
26255+ pax_open_kernel();
26256+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26257+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26258+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26259+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26260+ pax_close_kernel();
26261+
26262 local_irq_restore(flags);
26263
26264 switch (return_code) {
26265- case 0:
26266- return address + entry;
26267- case 0x80: /* Not present */
26268- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26269- return 0;
26270- default: /* Shouldn't happen */
26271- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26272- service, return_code);
26273+ case 0: {
26274+ int cpu;
26275+ unsigned char flags;
26276+
26277+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26278+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26279+ printk(KERN_WARNING "bios32_service: not valid\n");
26280 return 0;
26281+ }
26282+ address = address + PAGE_OFFSET;
26283+ length += 16UL; /* some BIOSs underreport this... */
26284+ flags = 4;
26285+ if (length >= 64*1024*1024) {
26286+ length >>= PAGE_SHIFT;
26287+ flags |= 8;
26288+ }
26289+
26290+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
26291+ gdt = get_cpu_gdt_table(cpu);
26292+ pack_descriptor(&d, address, length, 0x9b, flags);
26293+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26294+ pack_descriptor(&d, address, length, 0x93, flags);
26295+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26296+ }
26297+ return entry;
26298+ }
26299+ case 0x80: /* Not present */
26300+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26301+ return 0;
26302+ default: /* Shouldn't happen */
26303+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26304+ service, return_code);
26305+ return 0;
26306 }
26307 }
26308
26309 static struct {
26310 unsigned long address;
26311 unsigned short segment;
26312-} pci_indirect = { 0, __KERNEL_CS };
26313+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26314
26315-static int pci_bios_present;
26316+static int pci_bios_present __read_only;
26317
26318 static int __devinit check_pcibios(void)
26319 {
26320@@ -108,11 +151,13 @@ static int __devinit check_pcibios(void)
26321 unsigned long flags, pcibios_entry;
26322
26323 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26324- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26325+ pci_indirect.address = pcibios_entry;
26326
26327 local_irq_save(flags);
26328- __asm__(
26329- "lcall *(%%edi); cld\n\t"
26330+ __asm__("movw %w6, %%ds\n\t"
26331+ "lcall *%%ss:(%%edi); cld\n\t"
26332+ "push %%ss\n\t"
26333+ "pop %%ds\n\t"
26334 "jc 1f\n\t"
26335 "xor %%ah, %%ah\n"
26336 "1:"
26337@@ -121,7 +166,8 @@ static int __devinit check_pcibios(void)
26338 "=b" (ebx),
26339 "=c" (ecx)
26340 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26341- "D" (&pci_indirect)
26342+ "D" (&pci_indirect),
26343+ "r" (__PCIBIOS_DS)
26344 : "memory");
26345 local_irq_restore(flags);
26346
26347@@ -165,7 +211,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26348
26349 switch (len) {
26350 case 1:
26351- __asm__("lcall *(%%esi); cld\n\t"
26352+ __asm__("movw %w6, %%ds\n\t"
26353+ "lcall *%%ss:(%%esi); cld\n\t"
26354+ "push %%ss\n\t"
26355+ "pop %%ds\n\t"
26356 "jc 1f\n\t"
26357 "xor %%ah, %%ah\n"
26358 "1:"
26359@@ -174,7 +223,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26360 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26361 "b" (bx),
26362 "D" ((long)reg),
26363- "S" (&pci_indirect));
26364+ "S" (&pci_indirect),
26365+ "r" (__PCIBIOS_DS));
26366 /*
26367 * Zero-extend the result beyond 8 bits, do not trust the
26368 * BIOS having done it:
26369@@ -182,7 +232,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26370 *value &= 0xff;
26371 break;
26372 case 2:
26373- __asm__("lcall *(%%esi); cld\n\t"
26374+ __asm__("movw %w6, %%ds\n\t"
26375+ "lcall *%%ss:(%%esi); cld\n\t"
26376+ "push %%ss\n\t"
26377+ "pop %%ds\n\t"
26378 "jc 1f\n\t"
26379 "xor %%ah, %%ah\n"
26380 "1:"
26381@@ -191,7 +244,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26382 : "1" (PCIBIOS_READ_CONFIG_WORD),
26383 "b" (bx),
26384 "D" ((long)reg),
26385- "S" (&pci_indirect));
26386+ "S" (&pci_indirect),
26387+ "r" (__PCIBIOS_DS));
26388 /*
26389 * Zero-extend the result beyond 16 bits, do not trust the
26390 * BIOS having done it:
26391@@ -199,7 +253,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26392 *value &= 0xffff;
26393 break;
26394 case 4:
26395- __asm__("lcall *(%%esi); cld\n\t"
26396+ __asm__("movw %w6, %%ds\n\t"
26397+ "lcall *%%ss:(%%esi); cld\n\t"
26398+ "push %%ss\n\t"
26399+ "pop %%ds\n\t"
26400 "jc 1f\n\t"
26401 "xor %%ah, %%ah\n"
26402 "1:"
26403@@ -208,7 +265,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26404 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26405 "b" (bx),
26406 "D" ((long)reg),
26407- "S" (&pci_indirect));
26408+ "S" (&pci_indirect),
26409+ "r" (__PCIBIOS_DS));
26410 break;
26411 }
26412
26413@@ -231,7 +289,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26414
26415 switch (len) {
26416 case 1:
26417- __asm__("lcall *(%%esi); cld\n\t"
26418+ __asm__("movw %w6, %%ds\n\t"
26419+ "lcall *%%ss:(%%esi); cld\n\t"
26420+ "push %%ss\n\t"
26421+ "pop %%ds\n\t"
26422 "jc 1f\n\t"
26423 "xor %%ah, %%ah\n"
26424 "1:"
26425@@ -240,10 +301,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26426 "c" (value),
26427 "b" (bx),
26428 "D" ((long)reg),
26429- "S" (&pci_indirect));
26430+ "S" (&pci_indirect),
26431+ "r" (__PCIBIOS_DS));
26432 break;
26433 case 2:
26434- __asm__("lcall *(%%esi); cld\n\t"
26435+ __asm__("movw %w6, %%ds\n\t"
26436+ "lcall *%%ss:(%%esi); cld\n\t"
26437+ "push %%ss\n\t"
26438+ "pop %%ds\n\t"
26439 "jc 1f\n\t"
26440 "xor %%ah, %%ah\n"
26441 "1:"
26442@@ -252,10 +317,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26443 "c" (value),
26444 "b" (bx),
26445 "D" ((long)reg),
26446- "S" (&pci_indirect));
26447+ "S" (&pci_indirect),
26448+ "r" (__PCIBIOS_DS));
26449 break;
26450 case 4:
26451- __asm__("lcall *(%%esi); cld\n\t"
26452+ __asm__("movw %w6, %%ds\n\t"
26453+ "lcall *%%ss:(%%esi); cld\n\t"
26454+ "push %%ss\n\t"
26455+ "pop %%ds\n\t"
26456 "jc 1f\n\t"
26457 "xor %%ah, %%ah\n"
26458 "1:"
26459@@ -264,7 +333,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26460 "c" (value),
26461 "b" (bx),
26462 "D" ((long)reg),
26463- "S" (&pci_indirect));
26464+ "S" (&pci_indirect),
26465+ "r" (__PCIBIOS_DS));
26466 break;
26467 }
26468
26469@@ -278,7 +348,7 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26470 * Function table for BIOS32 access
26471 */
26472
26473-static struct pci_raw_ops pci_bios_access = {
26474+static const struct pci_raw_ops pci_bios_access = {
26475 .read = pci_bios_read,
26476 .write = pci_bios_write
26477 };
26478@@ -287,7 +357,7 @@ static struct pci_raw_ops pci_bios_access = {
26479 * Try to find PCI BIOS.
26480 */
26481
26482-static struct pci_raw_ops * __devinit pci_find_bios(void)
26483+static const struct pci_raw_ops * __devinit pci_find_bios(void)
26484 {
26485 union bios32 *check;
26486 unsigned char sum;
26487@@ -368,10 +438,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26488
26489 DBG("PCI: Fetching IRQ routing table... ");
26490 __asm__("push %%es\n\t"
26491+ "movw %w8, %%ds\n\t"
26492 "push %%ds\n\t"
26493 "pop %%es\n\t"
26494- "lcall *(%%esi); cld\n\t"
26495+ "lcall *%%ss:(%%esi); cld\n\t"
26496 "pop %%es\n\t"
26497+ "push %%ss\n\t"
26498+ "pop %%ds\n"
26499 "jc 1f\n\t"
26500 "xor %%ah, %%ah\n"
26501 "1:"
26502@@ -382,7 +455,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26503 "1" (0),
26504 "D" ((long) &opt),
26505 "S" (&pci_indirect),
26506- "m" (opt)
26507+ "m" (opt),
26508+ "r" (__PCIBIOS_DS)
26509 : "memory");
26510 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26511 if (ret & 0xff00)
26512@@ -406,7 +480,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26513 {
26514 int ret;
26515
26516- __asm__("lcall *(%%esi); cld\n\t"
26517+ __asm__("movw %w5, %%ds\n\t"
26518+ "lcall *%%ss:(%%esi); cld\n\t"
26519+ "push %%ss\n\t"
26520+ "pop %%ds\n"
26521 "jc 1f\n\t"
26522 "xor %%ah, %%ah\n"
26523 "1:"
26524@@ -414,7 +491,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26525 : "0" (PCIBIOS_SET_PCI_HW_INT),
26526 "b" ((dev->bus->number << 8) | dev->devfn),
26527 "c" ((irq << 8) | (pin + 10)),
26528- "S" (&pci_indirect));
26529+ "S" (&pci_indirect),
26530+ "r" (__PCIBIOS_DS));
26531 return !(ret & 0xff00);
26532 }
26533 EXPORT_SYMBOL(pcibios_set_irq_routing);
26534diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26535index fa0f651..9d8f3d9 100644
26536--- a/arch/x86/power/cpu.c
26537+++ b/arch/x86/power/cpu.c
26538@@ -129,7 +129,7 @@ static void do_fpu_end(void)
26539 static void fix_processor_context(void)
26540 {
26541 int cpu = smp_processor_id();
26542- struct tss_struct *t = &per_cpu(init_tss, cpu);
26543+ struct tss_struct *t = init_tss + cpu;
26544
26545 set_tss_desc(cpu, t); /*
26546 * This just modifies memory; should not be
26547@@ -139,7 +139,9 @@ static void fix_processor_context(void)
26548 */
26549
26550 #ifdef CONFIG_X86_64
26551+ pax_open_kernel();
26552 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26553+ pax_close_kernel();
26554
26555 syscall_init(); /* This sets MSR_*STAR and related */
26556 #endif
26557diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26558index dd78ef6..f9d928d 100644
26559--- a/arch/x86/vdso/Makefile
26560+++ b/arch/x86/vdso/Makefile
26561@@ -122,7 +122,7 @@ quiet_cmd_vdso = VDSO $@
26562 $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \
26563 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^)
26564
26565-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26566+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26567 GCOV_PROFILE := n
26568
26569 #
26570diff --git a/arch/x86/vdso/vclock_gettime.c b/arch/x86/vdso/vclock_gettime.c
26571index ee55754..0013b2e 100644
26572--- a/arch/x86/vdso/vclock_gettime.c
26573+++ b/arch/x86/vdso/vclock_gettime.c
26574@@ -22,24 +22,48 @@
26575 #include <asm/hpet.h>
26576 #include <asm/unistd.h>
26577 #include <asm/io.h>
26578+#include <asm/fixmap.h>
26579 #include "vextern.h"
26580
26581 #define gtod vdso_vsyscall_gtod_data
26582
26583+notrace noinline long __vdso_fallback_time(long *t)
26584+{
26585+ long secs;
26586+ asm volatile("syscall"
26587+ : "=a" (secs)
26588+ : "0" (__NR_time),"D" (t) : "r11", "cx", "memory");
26589+ return secs;
26590+}
26591+
26592 notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
26593 {
26594 long ret;
26595 asm("syscall" : "=a" (ret) :
26596- "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "memory");
26597+ "0" (__NR_clock_gettime),"D" (clock), "S" (ts) : "r11", "cx", "memory");
26598 return ret;
26599 }
26600
26601+notrace static inline cycle_t __vdso_vread_hpet(void)
26602+{
26603+ return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
26604+}
26605+
26606+notrace static inline cycle_t __vdso_vread_tsc(void)
26607+{
26608+ cycle_t ret = (cycle_t)vget_cycles();
26609+
26610+ return ret >= gtod->clock.cycle_last ? ret : gtod->clock.cycle_last;
26611+}
26612+
26613 notrace static inline long vgetns(void)
26614 {
26615 long v;
26616- cycles_t (*vread)(void);
26617- vread = gtod->clock.vread;
26618- v = (vread() - gtod->clock.cycle_last) & gtod->clock.mask;
26619+ if (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3])
26620+ v = __vdso_vread_tsc();
26621+ else
26622+ v = __vdso_vread_hpet();
26623+ v = (v - gtod->clock.cycle_last) & gtod->clock.mask;
26624 return (v * gtod->clock.mult) >> gtod->clock.shift;
26625 }
26626
26627@@ -113,7 +137,9 @@ notrace static noinline int do_monotonic_coarse(struct timespec *ts)
26628
26629 notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
26630 {
26631- if (likely(gtod->sysctl_enabled))
26632+ if (likely(gtod->sysctl_enabled &&
26633+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
26634+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
26635 switch (clock) {
26636 case CLOCK_REALTIME:
26637 if (likely(gtod->clock.vread))
26638@@ -133,10 +159,20 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
26639 int clock_gettime(clockid_t, struct timespec *)
26640 __attribute__((weak, alias("__vdso_clock_gettime")));
26641
26642+notrace noinline int __vdso_fallback_gettimeofday(struct timeval *tv, struct timezone *tz)
26643+{
26644+ long ret;
26645+ asm("syscall" : "=a" (ret) :
26646+ "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "r11", "cx", "memory");
26647+ return ret;
26648+}
26649+
26650 notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
26651 {
26652- long ret;
26653- if (likely(gtod->sysctl_enabled && gtod->clock.vread)) {
26654+ if (likely(gtod->sysctl_enabled &&
26655+ ((gtod->clock.name[0] == 'h' && gtod->clock.name[1] == 'p' && gtod->clock.name[2] == 'e' && gtod->clock.name[3] == 't' && !gtod->clock.name[4]) ||
26656+ (gtod->clock.name[0] == 't' && gtod->clock.name[1] == 's' && gtod->clock.name[2] == 'c' && !gtod->clock.name[3]))))
26657+ {
26658 if (likely(tv != NULL)) {
26659 BUILD_BUG_ON(offsetof(struct timeval, tv_usec) !=
26660 offsetof(struct timespec, tv_nsec) ||
26661@@ -151,9 +187,7 @@ notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz)
26662 }
26663 return 0;
26664 }
26665- asm("syscall" : "=a" (ret) :
26666- "0" (__NR_gettimeofday), "D" (tv), "S" (tz) : "memory");
26667- return ret;
26668+ return __vdso_fallback_gettimeofday(tv, tz);
26669 }
26670 int gettimeofday(struct timeval *, struct timezone *)
26671 __attribute__((weak, alias("__vdso_gettimeofday")));
26672diff --git a/arch/x86/vdso/vdso.lds.S b/arch/x86/vdso/vdso.lds.S
26673index 4e5dd3b..00ba15e 100644
26674--- a/arch/x86/vdso/vdso.lds.S
26675+++ b/arch/x86/vdso/vdso.lds.S
26676@@ -35,3 +35,9 @@ VDSO64_PRELINK = VDSO_PRELINK;
26677 #define VEXTERN(x) VDSO64_ ## x = vdso_ ## x;
26678 #include "vextern.h"
26679 #undef VEXTERN
26680+
26681+#define VEXTERN(x) VDSO64_ ## x = __vdso_ ## x;
26682+VEXTERN(fallback_gettimeofday)
26683+VEXTERN(fallback_time)
26684+VEXTERN(getcpu)
26685+#undef VEXTERN
26686diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26687index 58bc00f..d53fb48 100644
26688--- a/arch/x86/vdso/vdso32-setup.c
26689+++ b/arch/x86/vdso/vdso32-setup.c
26690@@ -25,6 +25,7 @@
26691 #include <asm/tlbflush.h>
26692 #include <asm/vdso.h>
26693 #include <asm/proto.h>
26694+#include <asm/mman.h>
26695
26696 enum {
26697 VDSO_DISABLED = 0,
26698@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26699 void enable_sep_cpu(void)
26700 {
26701 int cpu = get_cpu();
26702- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26703+ struct tss_struct *tss = init_tss + cpu;
26704
26705 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26706 put_cpu();
26707@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26708 gate_vma.vm_start = FIXADDR_USER_START;
26709 gate_vma.vm_end = FIXADDR_USER_END;
26710 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26711- gate_vma.vm_page_prot = __P101;
26712+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26713 /*
26714 * Make sure the vDSO gets into every core dump.
26715 * Dumping its contents makes post-mortem fully interpretable later
26716@@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26717 if (compat)
26718 addr = VDSO_HIGH_BASE;
26719 else {
26720- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26721+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26722 if (IS_ERR_VALUE(addr)) {
26723 ret = addr;
26724 goto up_fail;
26725 }
26726 }
26727
26728- current->mm->context.vdso = (void *)addr;
26729+ current->mm->context.vdso = addr;
26730
26731 if (compat_uses_vma || !compat) {
26732 /*
26733@@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26734 }
26735
26736 current_thread_info()->sysenter_return =
26737- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26738+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26739
26740 up_fail:
26741 if (ret)
26742- current->mm->context.vdso = NULL;
26743+ current->mm->context.vdso = 0;
26744
26745 up_write(&mm->mmap_sem);
26746
26747@@ -413,8 +414,14 @@ __initcall(ia32_binfmt_init);
26748
26749 const char *arch_vma_name(struct vm_area_struct *vma)
26750 {
26751- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26752+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26753 return "[vdso]";
26754+
26755+#ifdef CONFIG_PAX_SEGMEXEC
26756+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26757+ return "[vdso]";
26758+#endif
26759+
26760 return NULL;
26761 }
26762
26763@@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct task_struct *tsk)
26764 struct mm_struct *mm = tsk->mm;
26765
26766 /* Check to see if this task was created in compat vdso mode */
26767- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26768+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26769 return &gate_vma;
26770 return NULL;
26771 }
26772diff --git a/arch/x86/vdso/vextern.h b/arch/x86/vdso/vextern.h
26773index 1683ba2..48d07f3 100644
26774--- a/arch/x86/vdso/vextern.h
26775+++ b/arch/x86/vdso/vextern.h
26776@@ -11,6 +11,5 @@
26777 put into vextern.h and be referenced as a pointer with vdso prefix.
26778 The main kernel later fills in the values. */
26779
26780-VEXTERN(jiffies)
26781 VEXTERN(vgetcpu_mode)
26782 VEXTERN(vsyscall_gtod_data)
26783diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26784index 21e1aeb..2c0b3c4 100644
26785--- a/arch/x86/vdso/vma.c
26786+++ b/arch/x86/vdso/vma.c
26787@@ -17,8 +17,6 @@
26788 #include "vextern.h" /* Just for VMAGIC. */
26789 #undef VEXTERN
26790
26791-unsigned int __read_mostly vdso_enabled = 1;
26792-
26793 extern char vdso_start[], vdso_end[];
26794 extern unsigned short vdso_sync_cpuid;
26795
26796@@ -27,10 +25,8 @@ static unsigned vdso_size;
26797
26798 static inline void *var_ref(void *p, char *name)
26799 {
26800- if (*(void **)p != (void *)VMAGIC) {
26801- printk("VDSO: variable %s broken\n", name);
26802- vdso_enabled = 0;
26803- }
26804+ if (*(void **)p != (void *)VMAGIC)
26805+ panic("VDSO: variable %s broken\n", name);
26806 return p;
26807 }
26808
26809@@ -57,21 +53,18 @@ static int __init init_vdso_vars(void)
26810 if (!vbase)
26811 goto oom;
26812
26813- if (memcmp(vbase, "\177ELF", 4)) {
26814- printk("VDSO: I'm broken; not ELF\n");
26815- vdso_enabled = 0;
26816- }
26817+ if (memcmp(vbase, ELFMAG, SELFMAG))
26818+ panic("VDSO: I'm broken; not ELF\n");
26819
26820 #define VEXTERN(x) \
26821 *(typeof(__ ## x) **) var_ref(VDSO64_SYMBOL(vbase, x), #x) = &__ ## x;
26822 #include "vextern.h"
26823 #undef VEXTERN
26824+ vunmap(vbase);
26825 return 0;
26826
26827 oom:
26828- printk("Cannot allocate vdso\n");
26829- vdso_enabled = 0;
26830- return -ENOMEM;
26831+ panic("Cannot allocate vdso\n");
26832 }
26833 __initcall(init_vdso_vars);
26834
26835@@ -102,13 +95,15 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26836 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26837 {
26838 struct mm_struct *mm = current->mm;
26839- unsigned long addr;
26840+ unsigned long addr = 0;
26841 int ret;
26842
26843- if (!vdso_enabled)
26844- return 0;
26845-
26846 down_write(&mm->mmap_sem);
26847+
26848+#ifdef CONFIG_PAX_RANDMMAP
26849+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26850+#endif
26851+
26852 addr = vdso_addr(mm->start_stack, vdso_size);
26853 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26854 if (IS_ERR_VALUE(addr)) {
26855@@ -116,7 +111,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26856 goto up_fail;
26857 }
26858
26859- current->mm->context.vdso = (void *)addr;
26860+ current->mm->context.vdso = addr;
26861
26862 ret = install_special_mapping(mm, addr, vdso_size,
26863 VM_READ|VM_EXEC|
26864@@ -124,7 +119,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26865 VM_ALWAYSDUMP,
26866 vdso_pages);
26867 if (ret) {
26868- current->mm->context.vdso = NULL;
26869+ current->mm->context.vdso = 0;
26870 goto up_fail;
26871 }
26872
26873@@ -132,10 +127,3 @@ up_fail:
26874 up_write(&mm->mmap_sem);
26875 return ret;
26876 }
26877-
26878-static __init int vdso_setup(char *s)
26879-{
26880- vdso_enabled = simple_strtoul(s, NULL, 0);
26881- return 0;
26882-}
26883-__setup("vdso=", vdso_setup);
26884diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
26885index 0087b00..eecb34f 100644
26886--- a/arch/x86/xen/enlighten.c
26887+++ b/arch/x86/xen/enlighten.c
26888@@ -71,8 +71,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
26889
26890 struct shared_info xen_dummy_shared_info;
26891
26892-void *xen_initial_gdt;
26893-
26894 /*
26895 * Point at some empty memory to start with. We map the real shared_info
26896 * page as soon as fixmap is up and running.
26897@@ -548,7 +546,7 @@ static void xen_write_idt_entry(gate_desc *dt, int entrynum, const gate_desc *g)
26898
26899 preempt_disable();
26900
26901- start = __get_cpu_var(idt_desc).address;
26902+ start = (unsigned long)__get_cpu_var(idt_desc).address;
26903 end = start + __get_cpu_var(idt_desc).size + 1;
26904
26905 xen_mc_flush();
26906@@ -993,7 +991,7 @@ static const struct pv_apic_ops xen_apic_ops __initdata = {
26907 #endif
26908 };
26909
26910-static void xen_reboot(int reason)
26911+static __noreturn void xen_reboot(int reason)
26912 {
26913 struct sched_shutdown r = { .reason = reason };
26914
26915@@ -1001,17 +999,17 @@ static void xen_reboot(int reason)
26916 BUG();
26917 }
26918
26919-static void xen_restart(char *msg)
26920+static __noreturn void xen_restart(char *msg)
26921 {
26922 xen_reboot(SHUTDOWN_reboot);
26923 }
26924
26925-static void xen_emergency_restart(void)
26926+static __noreturn void xen_emergency_restart(void)
26927 {
26928 xen_reboot(SHUTDOWN_reboot);
26929 }
26930
26931-static void xen_machine_halt(void)
26932+static __noreturn void xen_machine_halt(void)
26933 {
26934 xen_reboot(SHUTDOWN_poweroff);
26935 }
26936@@ -1095,9 +1093,20 @@ asmlinkage void __init xen_start_kernel(void)
26937 */
26938 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
26939
26940-#ifdef CONFIG_X86_64
26941 /* Work out if we support NX */
26942- check_efer();
26943+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
26944+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
26945+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
26946+ unsigned l, h;
26947+
26948+#ifdef CONFIG_X86_PAE
26949+ nx_enabled = 1;
26950+#endif
26951+ __supported_pte_mask |= _PAGE_NX;
26952+ rdmsr(MSR_EFER, l, h);
26953+ l |= EFER_NX;
26954+ wrmsr(MSR_EFER, l, h);
26955+ }
26956 #endif
26957
26958 xen_setup_features();
26959@@ -1129,13 +1138,6 @@ asmlinkage void __init xen_start_kernel(void)
26960
26961 machine_ops = xen_machine_ops;
26962
26963- /*
26964- * The only reliable way to retain the initial address of the
26965- * percpu gdt_page is to remember it here, so we can go and
26966- * mark it RW later, when the initial percpu area is freed.
26967- */
26968- xen_initial_gdt = &per_cpu(gdt_page, 0);
26969-
26970 xen_smp_init();
26971
26972 pgd = (pgd_t *)xen_start_info->pt_base;
26973diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
26974index 3f90a2c..2c2ad84 100644
26975--- a/arch/x86/xen/mmu.c
26976+++ b/arch/x86/xen/mmu.c
26977@@ -1719,6 +1719,9 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
26978 convert_pfn_mfn(init_level4_pgt);
26979 convert_pfn_mfn(level3_ident_pgt);
26980 convert_pfn_mfn(level3_kernel_pgt);
26981+ convert_pfn_mfn(level3_vmalloc_start_pgt);
26982+ convert_pfn_mfn(level3_vmalloc_end_pgt);
26983+ convert_pfn_mfn(level3_vmemmap_pgt);
26984
26985 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
26986 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
26987@@ -1737,7 +1740,11 @@ __init pgd_t *xen_setup_kernel_pagetable(pgd_t *pgd,
26988 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
26989 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
26990 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
26991+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
26992+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
26993+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
26994 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
26995+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
26996 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
26997 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
26998
26999@@ -1860,6 +1867,7 @@ static __init void xen_post_allocator_init(void)
27000 pv_mmu_ops.set_pud = xen_set_pud;
27001 #if PAGETABLE_LEVELS == 4
27002 pv_mmu_ops.set_pgd = xen_set_pgd;
27003+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27004 #endif
27005
27006 /* This will work as long as patching hasn't happened yet
27007@@ -1946,6 +1954,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initdata = {
27008 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27009 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27010 .set_pgd = xen_set_pgd_hyper,
27011+ .set_pgd_batched = xen_set_pgd_hyper,
27012
27013 .alloc_pud = xen_alloc_pmd_init,
27014 .release_pud = xen_release_pmd_init,
27015diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27016index a96204a..fca9b8e 100644
27017--- a/arch/x86/xen/smp.c
27018+++ b/arch/x86/xen/smp.c
27019@@ -168,11 +168,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27020 {
27021 BUG_ON(smp_processor_id() != 0);
27022 native_smp_prepare_boot_cpu();
27023-
27024- /* We've switched to the "real" per-cpu gdt, so make sure the
27025- old memory can be recycled */
27026- make_lowmem_page_readwrite(xen_initial_gdt);
27027-
27028 xen_setup_vcpu_info_placement();
27029 }
27030
27031@@ -241,12 +236,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27032 gdt = get_cpu_gdt_table(cpu);
27033
27034 ctxt->flags = VGCF_IN_KERNEL;
27035- ctxt->user_regs.ds = __USER_DS;
27036- ctxt->user_regs.es = __USER_DS;
27037+ ctxt->user_regs.ds = __KERNEL_DS;
27038+ ctxt->user_regs.es = __KERNEL_DS;
27039 ctxt->user_regs.ss = __KERNEL_DS;
27040 #ifdef CONFIG_X86_32
27041 ctxt->user_regs.fs = __KERNEL_PERCPU;
27042- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27043+ savesegment(gs, ctxt->user_regs.gs);
27044 #else
27045 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27046 #endif
27047@@ -297,13 +292,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27048 int rc;
27049
27050 per_cpu(current_task, cpu) = idle;
27051+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27052 #ifdef CONFIG_X86_32
27053 irq_ctx_init(cpu);
27054 #else
27055 clear_tsk_thread_flag(idle, TIF_FORK);
27056- per_cpu(kernel_stack, cpu) =
27057- (unsigned long)task_stack_page(idle) -
27058- KERNEL_STACK_OFFSET + THREAD_SIZE;
27059+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27060 #endif
27061 xen_setup_runstate_info(cpu);
27062 xen_setup_timer(cpu);
27063diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27064index 9a95a9c..4f39e774 100644
27065--- a/arch/x86/xen/xen-asm_32.S
27066+++ b/arch/x86/xen/xen-asm_32.S
27067@@ -83,14 +83,14 @@ ENTRY(xen_iret)
27068 ESP_OFFSET=4 # bytes pushed onto stack
27069
27070 /*
27071- * Store vcpu_info pointer for easy access. Do it this way to
27072- * avoid having to reload %fs
27073+ * Store vcpu_info pointer for easy access.
27074 */
27075 #ifdef CONFIG_SMP
27076- GET_THREAD_INFO(%eax)
27077- movl TI_cpu(%eax), %eax
27078- movl __per_cpu_offset(,%eax,4), %eax
27079- mov per_cpu__xen_vcpu(%eax), %eax
27080+ push %fs
27081+ mov $(__KERNEL_PERCPU), %eax
27082+ mov %eax, %fs
27083+ mov PER_CPU_VAR(xen_vcpu), %eax
27084+ pop %fs
27085 #else
27086 movl per_cpu__xen_vcpu, %eax
27087 #endif
27088diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27089index 1a5ff24..a187d40 100644
27090--- a/arch/x86/xen/xen-head.S
27091+++ b/arch/x86/xen/xen-head.S
27092@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27093 #ifdef CONFIG_X86_32
27094 mov %esi,xen_start_info
27095 mov $init_thread_union+THREAD_SIZE,%esp
27096+#ifdef CONFIG_SMP
27097+ movl $cpu_gdt_table,%edi
27098+ movl $__per_cpu_load,%eax
27099+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27100+ rorl $16,%eax
27101+ movb %al,__KERNEL_PERCPU + 4(%edi)
27102+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27103+ movl $__per_cpu_end - 1,%eax
27104+ subl $__per_cpu_start,%eax
27105+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27106+#endif
27107 #else
27108 mov %rsi,xen_start_info
27109 mov $init_thread_union+THREAD_SIZE,%rsp
27110diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27111index f9153a3..51eab3d 100644
27112--- a/arch/x86/xen/xen-ops.h
27113+++ b/arch/x86/xen/xen-ops.h
27114@@ -10,8 +10,6 @@
27115 extern const char xen_hypervisor_callback[];
27116 extern const char xen_failsafe_callback[];
27117
27118-extern void *xen_initial_gdt;
27119-
27120 struct trap_info;
27121 void xen_copy_trap_info(struct trap_info *traps);
27122
27123diff --git a/block/blk-integrity.c b/block/blk-integrity.c
27124index 15c6308..96e83c2 100644
27125--- a/block/blk-integrity.c
27126+++ b/block/blk-integrity.c
27127@@ -278,7 +278,7 @@ static struct attribute *integrity_attrs[] = {
27128 NULL,
27129 };
27130
27131-static struct sysfs_ops integrity_ops = {
27132+static const struct sysfs_ops integrity_ops = {
27133 .show = &integrity_attr_show,
27134 .store = &integrity_attr_store,
27135 };
27136diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27137index ca56420..f2fc409 100644
27138--- a/block/blk-iopoll.c
27139+++ b/block/blk-iopoll.c
27140@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27141 }
27142 EXPORT_SYMBOL(blk_iopoll_complete);
27143
27144-static void blk_iopoll_softirq(struct softirq_action *h)
27145+static void blk_iopoll_softirq(void)
27146 {
27147 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27148 int rearm = 0, budget = blk_iopoll_budget;
27149diff --git a/block/blk-map.c b/block/blk-map.c
27150index 30a7e51..0aeec6a 100644
27151--- a/block/blk-map.c
27152+++ b/block/blk-map.c
27153@@ -54,7 +54,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
27154 * direct dma. else, set up kernel bounce buffers
27155 */
27156 uaddr = (unsigned long) ubuf;
27157- if (blk_rq_aligned(q, ubuf, len) && !map_data)
27158+ if (blk_rq_aligned(q, (__force void *)ubuf, len) && !map_data)
27159 bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask);
27160 else
27161 bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask);
27162@@ -201,12 +201,13 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
27163 for (i = 0; i < iov_count; i++) {
27164 unsigned long uaddr = (unsigned long)iov[i].iov_base;
27165
27166+ if (!iov[i].iov_len)
27167+ return -EINVAL;
27168+
27169 if (uaddr & queue_dma_alignment(q)) {
27170 unaligned = 1;
27171 break;
27172 }
27173- if (!iov[i].iov_len)
27174- return -EINVAL;
27175 }
27176
27177 if (unaligned || (q->dma_pad_mask & len) || map_data)
27178@@ -299,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27179 if (!len || !kbuf)
27180 return -EINVAL;
27181
27182- do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
27183+ do_copy = !blk_rq_aligned(q, kbuf, len) || object_starts_on_stack(kbuf);
27184 if (do_copy)
27185 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27186 else
27187diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27188index ee9c216..58d410a 100644
27189--- a/block/blk-softirq.c
27190+++ b/block/blk-softirq.c
27191@@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27192 * Softirq action handler - move entries to local list and loop over them
27193 * while passing them to the queue registered handler.
27194 */
27195-static void blk_done_softirq(struct softirq_action *h)
27196+static void blk_done_softirq(void)
27197 {
27198 struct list_head *cpu_list, local_list;
27199
27200diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
27201index bb9c5ea..5330d48 100644
27202--- a/block/blk-sysfs.c
27203+++ b/block/blk-sysfs.c
27204@@ -414,7 +414,7 @@ static void blk_release_queue(struct kobject *kobj)
27205 kmem_cache_free(blk_requestq_cachep, q);
27206 }
27207
27208-static struct sysfs_ops queue_sysfs_ops = {
27209+static const struct sysfs_ops queue_sysfs_ops = {
27210 .show = queue_attr_show,
27211 .store = queue_attr_store,
27212 };
27213diff --git a/block/bsg.c b/block/bsg.c
27214index 7154a7a..08ac2f0 100644
27215--- a/block/bsg.c
27216+++ b/block/bsg.c
27217@@ -175,16 +175,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27218 struct sg_io_v4 *hdr, struct bsg_device *bd,
27219 fmode_t has_write_perm)
27220 {
27221+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27222+ unsigned char *cmdptr;
27223+
27224 if (hdr->request_len > BLK_MAX_CDB) {
27225 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27226 if (!rq->cmd)
27227 return -ENOMEM;
27228- }
27229+ cmdptr = rq->cmd;
27230+ } else
27231+ cmdptr = tmpcmd;
27232
27233- if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request,
27234+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27235 hdr->request_len))
27236 return -EFAULT;
27237
27238+ if (cmdptr != rq->cmd)
27239+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27240+
27241 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27242 if (blk_verify_command(rq->cmd, has_write_perm))
27243 return -EPERM;
27244@@ -282,7 +290,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
27245 rq->next_rq = next_rq;
27246 next_rq->cmd_type = rq->cmd_type;
27247
27248- dxferp = (void*)(unsigned long)hdr->din_xferp;
27249+ dxferp = (void __user *)(unsigned long)hdr->din_xferp;
27250 ret = blk_rq_map_user(q, next_rq, NULL, dxferp,
27251 hdr->din_xfer_len, GFP_KERNEL);
27252 if (ret)
27253@@ -291,10 +299,10 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
27254
27255 if (hdr->dout_xfer_len) {
27256 dxfer_len = hdr->dout_xfer_len;
27257- dxferp = (void*)(unsigned long)hdr->dout_xferp;
27258+ dxferp = (void __user *)(unsigned long)hdr->dout_xferp;
27259 } else if (hdr->din_xfer_len) {
27260 dxfer_len = hdr->din_xfer_len;
27261- dxferp = (void*)(unsigned long)hdr->din_xferp;
27262+ dxferp = (void __user *)(unsigned long)hdr->din_xferp;
27263 } else
27264 dxfer_len = 0;
27265
27266@@ -436,7 +444,7 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
27267 int len = min_t(unsigned int, hdr->max_response_len,
27268 rq->sense_len);
27269
27270- ret = copy_to_user((void*)(unsigned long)hdr->response,
27271+ ret = copy_to_user((void __user *)(unsigned long)hdr->response,
27272 rq->sense, len);
27273 if (!ret)
27274 hdr->response_len = len;
27275diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27276index 9bd086c..ca1fc22 100644
27277--- a/block/compat_ioctl.c
27278+++ b/block/compat_ioctl.c
27279@@ -354,7 +354,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27280 err |= __get_user(f->spec1, &uf->spec1);
27281 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27282 err |= __get_user(name, &uf->name);
27283- f->name = compat_ptr(name);
27284+ f->name = (void __force_kernel *)compat_ptr(name);
27285 if (err) {
27286 err = -EFAULT;
27287 goto out;
27288diff --git a/block/elevator.c b/block/elevator.c
27289index a847046..75a1746 100644
27290--- a/block/elevator.c
27291+++ b/block/elevator.c
27292@@ -889,7 +889,7 @@ elv_attr_store(struct kobject *kobj, struct attribute *attr,
27293 return error;
27294 }
27295
27296-static struct sysfs_ops elv_sysfs_ops = {
27297+static const struct sysfs_ops elv_sysfs_ops = {
27298 .show = elv_attr_show,
27299 .store = elv_attr_store,
27300 };
27301diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27302index 1d5a780..0e2fb8c 100644
27303--- a/block/scsi_ioctl.c
27304+++ b/block/scsi_ioctl.c
27305@@ -220,8 +220,20 @@ EXPORT_SYMBOL(blk_verify_command);
27306 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27307 struct sg_io_hdr *hdr, fmode_t mode)
27308 {
27309- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27310+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27311+ unsigned char *cmdptr;
27312+
27313+ if (rq->cmd != rq->__cmd)
27314+ cmdptr = rq->cmd;
27315+ else
27316+ cmdptr = tmpcmd;
27317+
27318+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27319 return -EFAULT;
27320+
27321+ if (cmdptr != rq->cmd)
27322+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27323+
27324 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27325 return -EPERM;
27326
27327@@ -430,6 +442,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27328 int err;
27329 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27330 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27331+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27332+ unsigned char *cmdptr;
27333
27334 if (!sic)
27335 return -EINVAL;
27336@@ -463,9 +477,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27337 */
27338 err = -EFAULT;
27339 rq->cmd_len = cmdlen;
27340- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27341+
27342+ if (rq->cmd != rq->__cmd)
27343+ cmdptr = rq->cmd;
27344+ else
27345+ cmdptr = tmpcmd;
27346+
27347+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27348 goto error;
27349
27350+ if (rq->cmd != cmdptr)
27351+ memcpy(rq->cmd, cmdptr, cmdlen);
27352+
27353 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27354 goto error;
27355
27356diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27357index 3533582..f143117 100644
27358--- a/crypto/cryptd.c
27359+++ b/crypto/cryptd.c
27360@@ -50,7 +50,7 @@ struct cryptd_blkcipher_ctx {
27361
27362 struct cryptd_blkcipher_request_ctx {
27363 crypto_completion_t complete;
27364-};
27365+} __no_const;
27366
27367 struct cryptd_hash_ctx {
27368 struct crypto_shash *child;
27369diff --git a/crypto/gf128mul.c b/crypto/gf128mul.c
27370index a90d260..7a9765e 100644
27371--- a/crypto/gf128mul.c
27372+++ b/crypto/gf128mul.c
27373@@ -182,7 +182,7 @@ void gf128mul_lle(be128 *r, const be128 *b)
27374 for (i = 0; i < 7; ++i)
27375 gf128mul_x_lle(&p[i + 1], &p[i]);
27376
27377- memset(r, 0, sizeof(r));
27378+ memset(r, 0, sizeof(*r));
27379 for (i = 0;;) {
27380 u8 ch = ((u8 *)b)[15 - i];
27381
27382@@ -220,7 +220,7 @@ void gf128mul_bbe(be128 *r, const be128 *b)
27383 for (i = 0; i < 7; ++i)
27384 gf128mul_x_bbe(&p[i + 1], &p[i]);
27385
27386- memset(r, 0, sizeof(r));
27387+ memset(r, 0, sizeof(*r));
27388 for (i = 0;;) {
27389 u8 ch = ((u8 *)b)[i];
27390
27391diff --git a/crypto/serpent.c b/crypto/serpent.c
27392index b651a55..023297d 100644
27393--- a/crypto/serpent.c
27394+++ b/crypto/serpent.c
27395@@ -21,6 +21,7 @@
27396 #include <asm/byteorder.h>
27397 #include <linux/crypto.h>
27398 #include <linux/types.h>
27399+#include <linux/sched.h>
27400
27401 /* Key is padded to the maximum of 256 bits before round key generation.
27402 * Any key length <= 256 bits (32 bytes) is allowed by the algorithm.
27403@@ -224,6 +225,8 @@ static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key,
27404 u32 r0,r1,r2,r3,r4;
27405 int i;
27406
27407+ pax_track_stack();
27408+
27409 /* Copy key, add padding */
27410
27411 for (i = 0; i < keylen; ++i)
27412diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c
27413index 0d2cdb8..d8de48d 100644
27414--- a/drivers/acpi/acpi_pad.c
27415+++ b/drivers/acpi/acpi_pad.c
27416@@ -30,7 +30,7 @@
27417 #include <acpi/acpi_bus.h>
27418 #include <acpi/acpi_drivers.h>
27419
27420-#define ACPI_PROCESSOR_AGGREGATOR_CLASS "processor_aggregator"
27421+#define ACPI_PROCESSOR_AGGREGATOR_CLASS "acpi_pad"
27422 #define ACPI_PROCESSOR_AGGREGATOR_DEVICE_NAME "Processor Aggregator"
27423 #define ACPI_PROCESSOR_AGGREGATOR_NOTIFY 0x80
27424 static DEFINE_MUTEX(isolated_cpus_lock);
27425diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
27426index 3f4602b..2e41d36 100644
27427--- a/drivers/acpi/battery.c
27428+++ b/drivers/acpi/battery.c
27429@@ -763,7 +763,7 @@ DECLARE_FILE_FUNCTIONS(alarm);
27430 }
27431
27432 static struct battery_file {
27433- struct file_operations ops;
27434+ const struct file_operations ops;
27435 mode_t mode;
27436 const char *name;
27437 } acpi_battery_file[] = {
27438diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
27439index 7338b6a..82f0257 100644
27440--- a/drivers/acpi/dock.c
27441+++ b/drivers/acpi/dock.c
27442@@ -77,7 +77,7 @@ struct dock_dependent_device {
27443 struct list_head list;
27444 struct list_head hotplug_list;
27445 acpi_handle handle;
27446- struct acpi_dock_ops *ops;
27447+ const struct acpi_dock_ops *ops;
27448 void *context;
27449 };
27450
27451@@ -605,7 +605,7 @@ EXPORT_SYMBOL_GPL(unregister_dock_notifier);
27452 * the dock driver after _DCK is executed.
27453 */
27454 int
27455-register_hotplug_dock_device(acpi_handle handle, struct acpi_dock_ops *ops,
27456+register_hotplug_dock_device(acpi_handle handle, const struct acpi_dock_ops *ops,
27457 void *context)
27458 {
27459 struct dock_dependent_device *dd;
27460diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
27461index 7c1c59e..2993595 100644
27462--- a/drivers/acpi/osl.c
27463+++ b/drivers/acpi/osl.c
27464@@ -523,6 +523,8 @@ acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
27465 void __iomem *virt_addr;
27466
27467 virt_addr = ioremap(phys_addr, width);
27468+ if (!virt_addr)
27469+ return AE_NO_MEMORY;
27470 if (!value)
27471 value = &dummy;
27472
27473@@ -551,6 +553,8 @@ acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
27474 void __iomem *virt_addr;
27475
27476 virt_addr = ioremap(phys_addr, width);
27477+ if (!virt_addr)
27478+ return AE_NO_MEMORY;
27479
27480 switch (width) {
27481 case 8:
27482diff --git a/drivers/acpi/power_meter.c b/drivers/acpi/power_meter.c
27483index c216062..eec10d2 100644
27484--- a/drivers/acpi/power_meter.c
27485+++ b/drivers/acpi/power_meter.c
27486@@ -315,8 +315,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
27487 return res;
27488
27489 temp /= 1000;
27490- if (temp < 0)
27491- return -EINVAL;
27492
27493 mutex_lock(&resource->lock);
27494 resource->trip[attr->index - 7] = temp;
27495diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27496index d0d25e2..961643d 100644
27497--- a/drivers/acpi/proc.c
27498+++ b/drivers/acpi/proc.c
27499@@ -391,20 +391,15 @@ acpi_system_write_wakeup_device(struct file *file,
27500 size_t count, loff_t * ppos)
27501 {
27502 struct list_head *node, *next;
27503- char strbuf[5];
27504- char str[5] = "";
27505- unsigned int len = count;
27506+ char strbuf[5] = {0};
27507 struct acpi_device *found_dev = NULL;
27508
27509- if (len > 4)
27510- len = 4;
27511- if (len < 0)
27512- return -EFAULT;
27513+ if (count > 4)
27514+ count = 4;
27515
27516- if (copy_from_user(strbuf, buffer, len))
27517+ if (copy_from_user(strbuf, buffer, count))
27518 return -EFAULT;
27519- strbuf[len] = '\0';
27520- sscanf(strbuf, "%s", str);
27521+ strbuf[count] = '\0';
27522
27523 mutex_lock(&acpi_device_lock);
27524 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27525@@ -413,7 +408,7 @@ acpi_system_write_wakeup_device(struct file *file,
27526 if (!dev->wakeup.flags.valid)
27527 continue;
27528
27529- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27530+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27531 dev->wakeup.state.enabled =
27532 dev->wakeup.state.enabled ? 0 : 1;
27533 found_dev = dev;
27534diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
27535index 7102474..de8ad22 100644
27536--- a/drivers/acpi/processor_core.c
27537+++ b/drivers/acpi/processor_core.c
27538@@ -790,7 +790,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27539 return 0;
27540 }
27541
27542- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27543+ BUG_ON(pr->id >= nr_cpu_ids);
27544
27545 /*
27546 * Buggy BIOS check
27547diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c
27548index d933980..5761f13 100644
27549--- a/drivers/acpi/sbshc.c
27550+++ b/drivers/acpi/sbshc.c
27551@@ -17,7 +17,7 @@
27552
27553 #define PREFIX "ACPI: "
27554
27555-#define ACPI_SMB_HC_CLASS "smbus_host_controller"
27556+#define ACPI_SMB_HC_CLASS "smbus_host_ctl"
27557 #define ACPI_SMB_HC_DEVICE_NAME "ACPI SMBus HC"
27558
27559 struct acpi_smb_hc {
27560diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
27561index 0458094..6978e7b 100644
27562--- a/drivers/acpi/sleep.c
27563+++ b/drivers/acpi/sleep.c
27564@@ -283,7 +283,7 @@ static int acpi_suspend_state_valid(suspend_state_t pm_state)
27565 }
27566 }
27567
27568-static struct platform_suspend_ops acpi_suspend_ops = {
27569+static const struct platform_suspend_ops acpi_suspend_ops = {
27570 .valid = acpi_suspend_state_valid,
27571 .begin = acpi_suspend_begin,
27572 .prepare_late = acpi_pm_prepare,
27573@@ -311,7 +311,7 @@ static int acpi_suspend_begin_old(suspend_state_t pm_state)
27574 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
27575 * been requested.
27576 */
27577-static struct platform_suspend_ops acpi_suspend_ops_old = {
27578+static const struct platform_suspend_ops acpi_suspend_ops_old = {
27579 .valid = acpi_suspend_state_valid,
27580 .begin = acpi_suspend_begin_old,
27581 .prepare_late = acpi_pm_disable_gpes,
27582@@ -460,7 +460,7 @@ static void acpi_pm_enable_gpes(void)
27583 acpi_enable_all_runtime_gpes();
27584 }
27585
27586-static struct platform_hibernation_ops acpi_hibernation_ops = {
27587+static const struct platform_hibernation_ops acpi_hibernation_ops = {
27588 .begin = acpi_hibernation_begin,
27589 .end = acpi_pm_end,
27590 .pre_snapshot = acpi_hibernation_pre_snapshot,
27591@@ -513,7 +513,7 @@ static int acpi_hibernation_pre_snapshot_old(void)
27592 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
27593 * been requested.
27594 */
27595-static struct platform_hibernation_ops acpi_hibernation_ops_old = {
27596+static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
27597 .begin = acpi_hibernation_begin_old,
27598 .end = acpi_pm_end,
27599 .pre_snapshot = acpi_hibernation_pre_snapshot_old,
27600diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
27601index 05dff63..b662ab7 100644
27602--- a/drivers/acpi/video.c
27603+++ b/drivers/acpi/video.c
27604@@ -359,7 +359,7 @@ static int acpi_video_set_brightness(struct backlight_device *bd)
27605 vd->brightness->levels[request_level]);
27606 }
27607
27608-static struct backlight_ops acpi_backlight_ops = {
27609+static const struct backlight_ops acpi_backlight_ops = {
27610 .get_brightness = acpi_video_get_brightness,
27611 .update_status = acpi_video_set_brightness,
27612 };
27613diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
27614index 6787aab..23ffb0e 100644
27615--- a/drivers/ata/ahci.c
27616+++ b/drivers/ata/ahci.c
27617@@ -387,7 +387,7 @@ static struct scsi_host_template ahci_sht = {
27618 .sdev_attrs = ahci_sdev_attrs,
27619 };
27620
27621-static struct ata_port_operations ahci_ops = {
27622+static const struct ata_port_operations ahci_ops = {
27623 .inherits = &sata_pmp_port_ops,
27624
27625 .qc_defer = sata_pmp_qc_defer_cmd_switch,
27626@@ -424,17 +424,17 @@ static struct ata_port_operations ahci_ops = {
27627 .port_stop = ahci_port_stop,
27628 };
27629
27630-static struct ata_port_operations ahci_vt8251_ops = {
27631+static const struct ata_port_operations ahci_vt8251_ops = {
27632 .inherits = &ahci_ops,
27633 .hardreset = ahci_vt8251_hardreset,
27634 };
27635
27636-static struct ata_port_operations ahci_p5wdh_ops = {
27637+static const struct ata_port_operations ahci_p5wdh_ops = {
27638 .inherits = &ahci_ops,
27639 .hardreset = ahci_p5wdh_hardreset,
27640 };
27641
27642-static struct ata_port_operations ahci_sb600_ops = {
27643+static const struct ata_port_operations ahci_sb600_ops = {
27644 .inherits = &ahci_ops,
27645 .softreset = ahci_sb600_softreset,
27646 .pmp_softreset = ahci_sb600_softreset,
27647diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
27648index 99e7196..4968c77 100644
27649--- a/drivers/ata/ata_generic.c
27650+++ b/drivers/ata/ata_generic.c
27651@@ -104,7 +104,7 @@ static struct scsi_host_template generic_sht = {
27652 ATA_BMDMA_SHT(DRV_NAME),
27653 };
27654
27655-static struct ata_port_operations generic_port_ops = {
27656+static const struct ata_port_operations generic_port_ops = {
27657 .inherits = &ata_bmdma_port_ops,
27658 .cable_detect = ata_cable_unknown,
27659 .set_mode = generic_set_mode,
27660diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
27661index c33591d..000c121 100644
27662--- a/drivers/ata/ata_piix.c
27663+++ b/drivers/ata/ata_piix.c
27664@@ -318,7 +318,7 @@ static struct scsi_host_template piix_sht = {
27665 ATA_BMDMA_SHT(DRV_NAME),
27666 };
27667
27668-static struct ata_port_operations piix_pata_ops = {
27669+static const struct ata_port_operations piix_pata_ops = {
27670 .inherits = &ata_bmdma32_port_ops,
27671 .cable_detect = ata_cable_40wire,
27672 .set_piomode = piix_set_piomode,
27673@@ -326,22 +326,22 @@ static struct ata_port_operations piix_pata_ops = {
27674 .prereset = piix_pata_prereset,
27675 };
27676
27677-static struct ata_port_operations piix_vmw_ops = {
27678+static const struct ata_port_operations piix_vmw_ops = {
27679 .inherits = &piix_pata_ops,
27680 .bmdma_status = piix_vmw_bmdma_status,
27681 };
27682
27683-static struct ata_port_operations ich_pata_ops = {
27684+static const struct ata_port_operations ich_pata_ops = {
27685 .inherits = &piix_pata_ops,
27686 .cable_detect = ich_pata_cable_detect,
27687 .set_dmamode = ich_set_dmamode,
27688 };
27689
27690-static struct ata_port_operations piix_sata_ops = {
27691+static const struct ata_port_operations piix_sata_ops = {
27692 .inherits = &ata_bmdma_port_ops,
27693 };
27694
27695-static struct ata_port_operations piix_sidpr_sata_ops = {
27696+static const struct ata_port_operations piix_sidpr_sata_ops = {
27697 .inherits = &piix_sata_ops,
27698 .hardreset = sata_std_hardreset,
27699 .scr_read = piix_sidpr_scr_read,
27700diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
27701index b0882cd..c295d65 100644
27702--- a/drivers/ata/libata-acpi.c
27703+++ b/drivers/ata/libata-acpi.c
27704@@ -223,12 +223,12 @@ static void ata_acpi_dev_uevent(acpi_handle handle, u32 event, void *data)
27705 ata_acpi_uevent(dev->link->ap, dev, event);
27706 }
27707
27708-static struct acpi_dock_ops ata_acpi_dev_dock_ops = {
27709+static const struct acpi_dock_ops ata_acpi_dev_dock_ops = {
27710 .handler = ata_acpi_dev_notify_dock,
27711 .uevent = ata_acpi_dev_uevent,
27712 };
27713
27714-static struct acpi_dock_ops ata_acpi_ap_dock_ops = {
27715+static const struct acpi_dock_ops ata_acpi_ap_dock_ops = {
27716 .handler = ata_acpi_ap_notify_dock,
27717 .uevent = ata_acpi_ap_uevent,
27718 };
27719diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27720index d4f7f99..94f603e 100644
27721--- a/drivers/ata/libata-core.c
27722+++ b/drivers/ata/libata-core.c
27723@@ -4954,7 +4954,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27724 struct ata_port *ap;
27725 unsigned int tag;
27726
27727- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27728+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27729 ap = qc->ap;
27730
27731 qc->flags = 0;
27732@@ -4970,7 +4970,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27733 struct ata_port *ap;
27734 struct ata_link *link;
27735
27736- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27737+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27738 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27739 ap = qc->ap;
27740 link = qc->dev->link;
27741@@ -5987,7 +5987,7 @@ static void ata_host_stop(struct device *gendev, void *res)
27742 * LOCKING:
27743 * None.
27744 */
27745-static void ata_finalize_port_ops(struct ata_port_operations *ops)
27746+static void ata_finalize_port_ops(const struct ata_port_operations *ops)
27747 {
27748 static DEFINE_SPINLOCK(lock);
27749 const struct ata_port_operations *cur;
27750@@ -5999,6 +5999,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27751 return;
27752
27753 spin_lock(&lock);
27754+ pax_open_kernel();
27755
27756 for (cur = ops->inherits; cur; cur = cur->inherits) {
27757 void **inherit = (void **)cur;
27758@@ -6012,8 +6013,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27759 if (IS_ERR(*pp))
27760 *pp = NULL;
27761
27762- ops->inherits = NULL;
27763+ *(struct ata_port_operations **)&ops->inherits = NULL;
27764
27765+ pax_close_kernel();
27766 spin_unlock(&lock);
27767 }
27768
27769@@ -6110,7 +6112,7 @@ int ata_host_start(struct ata_host *host)
27770 */
27771 /* KILLME - the only user left is ipr */
27772 void ata_host_init(struct ata_host *host, struct device *dev,
27773- unsigned long flags, struct ata_port_operations *ops)
27774+ unsigned long flags, const struct ata_port_operations *ops)
27775 {
27776 spin_lock_init(&host->lock);
27777 host->dev = dev;
27778@@ -6773,7 +6775,7 @@ static void ata_dummy_error_handler(struct ata_port *ap)
27779 /* truly dummy */
27780 }
27781
27782-struct ata_port_operations ata_dummy_port_ops = {
27783+const struct ata_port_operations ata_dummy_port_ops = {
27784 .qc_prep = ata_noop_qc_prep,
27785 .qc_issue = ata_dummy_qc_issue,
27786 .error_handler = ata_dummy_error_handler,
27787diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
27788index e5bdb9b..45a8e72 100644
27789--- a/drivers/ata/libata-eh.c
27790+++ b/drivers/ata/libata-eh.c
27791@@ -2423,6 +2423,8 @@ void ata_eh_report(struct ata_port *ap)
27792 {
27793 struct ata_link *link;
27794
27795+ pax_track_stack();
27796+
27797 ata_for_each_link(link, ap, HOST_FIRST)
27798 ata_eh_link_report(link);
27799 }
27800@@ -3594,7 +3596,7 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
27801 */
27802 void ata_std_error_handler(struct ata_port *ap)
27803 {
27804- struct ata_port_operations *ops = ap->ops;
27805+ const struct ata_port_operations *ops = ap->ops;
27806 ata_reset_fn_t hardreset = ops->hardreset;
27807
27808 /* ignore built-in hardreset if SCR access is not available */
27809diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
27810index 51f0ffb..19ce3e3 100644
27811--- a/drivers/ata/libata-pmp.c
27812+++ b/drivers/ata/libata-pmp.c
27813@@ -841,7 +841,7 @@ static int sata_pmp_handle_link_fail(struct ata_link *link, int *link_tries)
27814 */
27815 static int sata_pmp_eh_recover(struct ata_port *ap)
27816 {
27817- struct ata_port_operations *ops = ap->ops;
27818+ const struct ata_port_operations *ops = ap->ops;
27819 int pmp_tries, link_tries[SATA_PMP_MAX_PORTS];
27820 struct ata_link *pmp_link = &ap->link;
27821 struct ata_device *pmp_dev = pmp_link->device;
27822diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
27823index d8f35fe..288180a 100644
27824--- a/drivers/ata/pata_acpi.c
27825+++ b/drivers/ata/pata_acpi.c
27826@@ -215,7 +215,7 @@ static struct scsi_host_template pacpi_sht = {
27827 ATA_BMDMA_SHT(DRV_NAME),
27828 };
27829
27830-static struct ata_port_operations pacpi_ops = {
27831+static const struct ata_port_operations pacpi_ops = {
27832 .inherits = &ata_bmdma_port_ops,
27833 .qc_issue = pacpi_qc_issue,
27834 .cable_detect = pacpi_cable_detect,
27835diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
27836index 9434114..1f2f364 100644
27837--- a/drivers/ata/pata_ali.c
27838+++ b/drivers/ata/pata_ali.c
27839@@ -365,7 +365,7 @@ static struct scsi_host_template ali_sht = {
27840 * Port operations for PIO only ALi
27841 */
27842
27843-static struct ata_port_operations ali_early_port_ops = {
27844+static const struct ata_port_operations ali_early_port_ops = {
27845 .inherits = &ata_sff_port_ops,
27846 .cable_detect = ata_cable_40wire,
27847 .set_piomode = ali_set_piomode,
27848@@ -382,7 +382,7 @@ static const struct ata_port_operations ali_dma_base_ops = {
27849 * Port operations for DMA capable ALi without cable
27850 * detect
27851 */
27852-static struct ata_port_operations ali_20_port_ops = {
27853+static const struct ata_port_operations ali_20_port_ops = {
27854 .inherits = &ali_dma_base_ops,
27855 .cable_detect = ata_cable_40wire,
27856 .mode_filter = ali_20_filter,
27857@@ -393,7 +393,7 @@ static struct ata_port_operations ali_20_port_ops = {
27858 /*
27859 * Port operations for DMA capable ALi with cable detect
27860 */
27861-static struct ata_port_operations ali_c2_port_ops = {
27862+static const struct ata_port_operations ali_c2_port_ops = {
27863 .inherits = &ali_dma_base_ops,
27864 .check_atapi_dma = ali_check_atapi_dma,
27865 .cable_detect = ali_c2_cable_detect,
27866@@ -404,7 +404,7 @@ static struct ata_port_operations ali_c2_port_ops = {
27867 /*
27868 * Port operations for DMA capable ALi with cable detect
27869 */
27870-static struct ata_port_operations ali_c4_port_ops = {
27871+static const struct ata_port_operations ali_c4_port_ops = {
27872 .inherits = &ali_dma_base_ops,
27873 .check_atapi_dma = ali_check_atapi_dma,
27874 .cable_detect = ali_c2_cable_detect,
27875@@ -414,7 +414,7 @@ static struct ata_port_operations ali_c4_port_ops = {
27876 /*
27877 * Port operations for DMA capable ALi with cable detect and LBA48
27878 */
27879-static struct ata_port_operations ali_c5_port_ops = {
27880+static const struct ata_port_operations ali_c5_port_ops = {
27881 .inherits = &ali_dma_base_ops,
27882 .check_atapi_dma = ali_check_atapi_dma,
27883 .dev_config = ali_warn_atapi_dma,
27884diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
27885index 567f3f7..c8ee0da 100644
27886--- a/drivers/ata/pata_amd.c
27887+++ b/drivers/ata/pata_amd.c
27888@@ -397,28 +397,28 @@ static const struct ata_port_operations amd_base_port_ops = {
27889 .prereset = amd_pre_reset,
27890 };
27891
27892-static struct ata_port_operations amd33_port_ops = {
27893+static const struct ata_port_operations amd33_port_ops = {
27894 .inherits = &amd_base_port_ops,
27895 .cable_detect = ata_cable_40wire,
27896 .set_piomode = amd33_set_piomode,
27897 .set_dmamode = amd33_set_dmamode,
27898 };
27899
27900-static struct ata_port_operations amd66_port_ops = {
27901+static const struct ata_port_operations amd66_port_ops = {
27902 .inherits = &amd_base_port_ops,
27903 .cable_detect = ata_cable_unknown,
27904 .set_piomode = amd66_set_piomode,
27905 .set_dmamode = amd66_set_dmamode,
27906 };
27907
27908-static struct ata_port_operations amd100_port_ops = {
27909+static const struct ata_port_operations amd100_port_ops = {
27910 .inherits = &amd_base_port_ops,
27911 .cable_detect = ata_cable_unknown,
27912 .set_piomode = amd100_set_piomode,
27913 .set_dmamode = amd100_set_dmamode,
27914 };
27915
27916-static struct ata_port_operations amd133_port_ops = {
27917+static const struct ata_port_operations amd133_port_ops = {
27918 .inherits = &amd_base_port_ops,
27919 .cable_detect = amd_cable_detect,
27920 .set_piomode = amd133_set_piomode,
27921@@ -433,13 +433,13 @@ static const struct ata_port_operations nv_base_port_ops = {
27922 .host_stop = nv_host_stop,
27923 };
27924
27925-static struct ata_port_operations nv100_port_ops = {
27926+static const struct ata_port_operations nv100_port_ops = {
27927 .inherits = &nv_base_port_ops,
27928 .set_piomode = nv100_set_piomode,
27929 .set_dmamode = nv100_set_dmamode,
27930 };
27931
27932-static struct ata_port_operations nv133_port_ops = {
27933+static const struct ata_port_operations nv133_port_ops = {
27934 .inherits = &nv_base_port_ops,
27935 .set_piomode = nv133_set_piomode,
27936 .set_dmamode = nv133_set_dmamode,
27937diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
27938index d332cfd..4b7eaae 100644
27939--- a/drivers/ata/pata_artop.c
27940+++ b/drivers/ata/pata_artop.c
27941@@ -311,7 +311,7 @@ static struct scsi_host_template artop_sht = {
27942 ATA_BMDMA_SHT(DRV_NAME),
27943 };
27944
27945-static struct ata_port_operations artop6210_ops = {
27946+static const struct ata_port_operations artop6210_ops = {
27947 .inherits = &ata_bmdma_port_ops,
27948 .cable_detect = ata_cable_40wire,
27949 .set_piomode = artop6210_set_piomode,
27950@@ -320,7 +320,7 @@ static struct ata_port_operations artop6210_ops = {
27951 .qc_defer = artop6210_qc_defer,
27952 };
27953
27954-static struct ata_port_operations artop6260_ops = {
27955+static const struct ata_port_operations artop6260_ops = {
27956 .inherits = &ata_bmdma_port_ops,
27957 .cable_detect = artop6260_cable_detect,
27958 .set_piomode = artop6260_set_piomode,
27959diff --git a/drivers/ata/pata_at32.c b/drivers/ata/pata_at32.c
27960index 5c129f9..7bb7ccb 100644
27961--- a/drivers/ata/pata_at32.c
27962+++ b/drivers/ata/pata_at32.c
27963@@ -172,7 +172,7 @@ static struct scsi_host_template at32_sht = {
27964 ATA_PIO_SHT(DRV_NAME),
27965 };
27966
27967-static struct ata_port_operations at32_port_ops = {
27968+static const struct ata_port_operations at32_port_ops = {
27969 .inherits = &ata_sff_port_ops,
27970 .cable_detect = ata_cable_40wire,
27971 .set_piomode = pata_at32_set_piomode,
27972diff --git a/drivers/ata/pata_at91.c b/drivers/ata/pata_at91.c
27973index 41c94b1..829006d 100644
27974--- a/drivers/ata/pata_at91.c
27975+++ b/drivers/ata/pata_at91.c
27976@@ -195,7 +195,7 @@ static struct scsi_host_template pata_at91_sht = {
27977 ATA_PIO_SHT(DRV_NAME),
27978 };
27979
27980-static struct ata_port_operations pata_at91_port_ops = {
27981+static const struct ata_port_operations pata_at91_port_ops = {
27982 .inherits = &ata_sff_port_ops,
27983
27984 .sff_data_xfer = pata_at91_data_xfer_noirq,
27985diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
27986index ae4454d..d391eb4 100644
27987--- a/drivers/ata/pata_atiixp.c
27988+++ b/drivers/ata/pata_atiixp.c
27989@@ -205,7 +205,7 @@ static struct scsi_host_template atiixp_sht = {
27990 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
27991 };
27992
27993-static struct ata_port_operations atiixp_port_ops = {
27994+static const struct ata_port_operations atiixp_port_ops = {
27995 .inherits = &ata_bmdma_port_ops,
27996
27997 .qc_prep = ata_sff_dumb_qc_prep,
27998diff --git a/drivers/ata/pata_atp867x.c b/drivers/ata/pata_atp867x.c
27999index 6fe7ded..2a425dc 100644
28000--- a/drivers/ata/pata_atp867x.c
28001+++ b/drivers/ata/pata_atp867x.c
28002@@ -274,7 +274,7 @@ static struct scsi_host_template atp867x_sht = {
28003 ATA_BMDMA_SHT(DRV_NAME),
28004 };
28005
28006-static struct ata_port_operations atp867x_ops = {
28007+static const struct ata_port_operations atp867x_ops = {
28008 .inherits = &ata_bmdma_port_ops,
28009 .cable_detect = atp867x_cable_detect,
28010 .set_piomode = atp867x_set_piomode,
28011diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
28012index c4b47a3..b27a367 100644
28013--- a/drivers/ata/pata_bf54x.c
28014+++ b/drivers/ata/pata_bf54x.c
28015@@ -1464,7 +1464,7 @@ static struct scsi_host_template bfin_sht = {
28016 .dma_boundary = ATA_DMA_BOUNDARY,
28017 };
28018
28019-static struct ata_port_operations bfin_pata_ops = {
28020+static const struct ata_port_operations bfin_pata_ops = {
28021 .inherits = &ata_sff_port_ops,
28022
28023 .set_piomode = bfin_set_piomode,
28024diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c
28025index 5acf9fa..84248be 100644
28026--- a/drivers/ata/pata_cmd640.c
28027+++ b/drivers/ata/pata_cmd640.c
28028@@ -168,7 +168,7 @@ static struct scsi_host_template cmd640_sht = {
28029 ATA_BMDMA_SHT(DRV_NAME),
28030 };
28031
28032-static struct ata_port_operations cmd640_port_ops = {
28033+static const struct ata_port_operations cmd640_port_ops = {
28034 .inherits = &ata_bmdma_port_ops,
28035 /* In theory xfer_noirq is not needed once we kill the prefetcher */
28036 .sff_data_xfer = ata_sff_data_xfer_noirq,
28037diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
28038index ccd2694..c869c3d 100644
28039--- a/drivers/ata/pata_cmd64x.c
28040+++ b/drivers/ata/pata_cmd64x.c
28041@@ -271,18 +271,18 @@ static const struct ata_port_operations cmd64x_base_ops = {
28042 .set_dmamode = cmd64x_set_dmamode,
28043 };
28044
28045-static struct ata_port_operations cmd64x_port_ops = {
28046+static const struct ata_port_operations cmd64x_port_ops = {
28047 .inherits = &cmd64x_base_ops,
28048 .cable_detect = ata_cable_40wire,
28049 };
28050
28051-static struct ata_port_operations cmd646r1_port_ops = {
28052+static const struct ata_port_operations cmd646r1_port_ops = {
28053 .inherits = &cmd64x_base_ops,
28054 .bmdma_stop = cmd646r1_bmdma_stop,
28055 .cable_detect = ata_cable_40wire,
28056 };
28057
28058-static struct ata_port_operations cmd648_port_ops = {
28059+static const struct ata_port_operations cmd648_port_ops = {
28060 .inherits = &cmd64x_base_ops,
28061 .bmdma_stop = cmd648_bmdma_stop,
28062 .cable_detect = cmd648_cable_detect,
28063diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
28064index 0df83cf..d7595b0 100644
28065--- a/drivers/ata/pata_cs5520.c
28066+++ b/drivers/ata/pata_cs5520.c
28067@@ -144,7 +144,7 @@ static struct scsi_host_template cs5520_sht = {
28068 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28069 };
28070
28071-static struct ata_port_operations cs5520_port_ops = {
28072+static const struct ata_port_operations cs5520_port_ops = {
28073 .inherits = &ata_bmdma_port_ops,
28074 .qc_prep = ata_sff_dumb_qc_prep,
28075 .cable_detect = ata_cable_40wire,
28076diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
28077index c974b05..6d26b11 100644
28078--- a/drivers/ata/pata_cs5530.c
28079+++ b/drivers/ata/pata_cs5530.c
28080@@ -164,7 +164,7 @@ static struct scsi_host_template cs5530_sht = {
28081 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28082 };
28083
28084-static struct ata_port_operations cs5530_port_ops = {
28085+static const struct ata_port_operations cs5530_port_ops = {
28086 .inherits = &ata_bmdma_port_ops,
28087
28088 .qc_prep = ata_sff_dumb_qc_prep,
28089diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
28090index 403f561..aacd26b 100644
28091--- a/drivers/ata/pata_cs5535.c
28092+++ b/drivers/ata/pata_cs5535.c
28093@@ -160,7 +160,7 @@ static struct scsi_host_template cs5535_sht = {
28094 ATA_BMDMA_SHT(DRV_NAME),
28095 };
28096
28097-static struct ata_port_operations cs5535_port_ops = {
28098+static const struct ata_port_operations cs5535_port_ops = {
28099 .inherits = &ata_bmdma_port_ops,
28100 .cable_detect = cs5535_cable_detect,
28101 .set_piomode = cs5535_set_piomode,
28102diff --git a/drivers/ata/pata_cs5536.c b/drivers/ata/pata_cs5536.c
28103index 6da4cb4..de24a25 100644
28104--- a/drivers/ata/pata_cs5536.c
28105+++ b/drivers/ata/pata_cs5536.c
28106@@ -223,7 +223,7 @@ static struct scsi_host_template cs5536_sht = {
28107 ATA_BMDMA_SHT(DRV_NAME),
28108 };
28109
28110-static struct ata_port_operations cs5536_port_ops = {
28111+static const struct ata_port_operations cs5536_port_ops = {
28112 .inherits = &ata_bmdma_port_ops,
28113 .cable_detect = cs5536_cable_detect,
28114 .set_piomode = cs5536_set_piomode,
28115diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
28116index 8fb040b..b16a9c9 100644
28117--- a/drivers/ata/pata_cypress.c
28118+++ b/drivers/ata/pata_cypress.c
28119@@ -113,7 +113,7 @@ static struct scsi_host_template cy82c693_sht = {
28120 ATA_BMDMA_SHT(DRV_NAME),
28121 };
28122
28123-static struct ata_port_operations cy82c693_port_ops = {
28124+static const struct ata_port_operations cy82c693_port_ops = {
28125 .inherits = &ata_bmdma_port_ops,
28126 .cable_detect = ata_cable_40wire,
28127 .set_piomode = cy82c693_set_piomode,
28128diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
28129index 2a6412f..555ee11 100644
28130--- a/drivers/ata/pata_efar.c
28131+++ b/drivers/ata/pata_efar.c
28132@@ -222,7 +222,7 @@ static struct scsi_host_template efar_sht = {
28133 ATA_BMDMA_SHT(DRV_NAME),
28134 };
28135
28136-static struct ata_port_operations efar_ops = {
28137+static const struct ata_port_operations efar_ops = {
28138 .inherits = &ata_bmdma_port_ops,
28139 .cable_detect = efar_cable_detect,
28140 .set_piomode = efar_set_piomode,
28141diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
28142index b9d8836..0b92030 100644
28143--- a/drivers/ata/pata_hpt366.c
28144+++ b/drivers/ata/pata_hpt366.c
28145@@ -282,7 +282,7 @@ static struct scsi_host_template hpt36x_sht = {
28146 * Configuration for HPT366/68
28147 */
28148
28149-static struct ata_port_operations hpt366_port_ops = {
28150+static const struct ata_port_operations hpt366_port_ops = {
28151 .inherits = &ata_bmdma_port_ops,
28152 .cable_detect = hpt36x_cable_detect,
28153 .mode_filter = hpt366_filter,
28154diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
28155index 5af7f19..00c4980 100644
28156--- a/drivers/ata/pata_hpt37x.c
28157+++ b/drivers/ata/pata_hpt37x.c
28158@@ -576,7 +576,7 @@ static struct scsi_host_template hpt37x_sht = {
28159 * Configuration for HPT370
28160 */
28161
28162-static struct ata_port_operations hpt370_port_ops = {
28163+static const struct ata_port_operations hpt370_port_ops = {
28164 .inherits = &ata_bmdma_port_ops,
28165
28166 .bmdma_stop = hpt370_bmdma_stop,
28167@@ -591,7 +591,7 @@ static struct ata_port_operations hpt370_port_ops = {
28168 * Configuration for HPT370A. Close to 370 but less filters
28169 */
28170
28171-static struct ata_port_operations hpt370a_port_ops = {
28172+static const struct ata_port_operations hpt370a_port_ops = {
28173 .inherits = &hpt370_port_ops,
28174 .mode_filter = hpt370a_filter,
28175 };
28176@@ -601,7 +601,7 @@ static struct ata_port_operations hpt370a_port_ops = {
28177 * and DMA mode setting functionality.
28178 */
28179
28180-static struct ata_port_operations hpt372_port_ops = {
28181+static const struct ata_port_operations hpt372_port_ops = {
28182 .inherits = &ata_bmdma_port_ops,
28183
28184 .bmdma_stop = hpt37x_bmdma_stop,
28185@@ -616,7 +616,7 @@ static struct ata_port_operations hpt372_port_ops = {
28186 * but we have a different cable detection procedure for function 1.
28187 */
28188
28189-static struct ata_port_operations hpt374_fn1_port_ops = {
28190+static const struct ata_port_operations hpt374_fn1_port_ops = {
28191 .inherits = &hpt372_port_ops,
28192 .prereset = hpt374_fn1_pre_reset,
28193 };
28194diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
28195index 100f227..2e39382 100644
28196--- a/drivers/ata/pata_hpt3x2n.c
28197+++ b/drivers/ata/pata_hpt3x2n.c
28198@@ -337,7 +337,7 @@ static struct scsi_host_template hpt3x2n_sht = {
28199 * Configuration for HPT3x2n.
28200 */
28201
28202-static struct ata_port_operations hpt3x2n_port_ops = {
28203+static const struct ata_port_operations hpt3x2n_port_ops = {
28204 .inherits = &ata_bmdma_port_ops,
28205
28206 .bmdma_stop = hpt3x2n_bmdma_stop,
28207diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
28208index 7e31025..6fca8f4 100644
28209--- a/drivers/ata/pata_hpt3x3.c
28210+++ b/drivers/ata/pata_hpt3x3.c
28211@@ -141,7 +141,7 @@ static struct scsi_host_template hpt3x3_sht = {
28212 ATA_BMDMA_SHT(DRV_NAME),
28213 };
28214
28215-static struct ata_port_operations hpt3x3_port_ops = {
28216+static const struct ata_port_operations hpt3x3_port_ops = {
28217 .inherits = &ata_bmdma_port_ops,
28218 .cable_detect = ata_cable_40wire,
28219 .set_piomode = hpt3x3_set_piomode,
28220diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c
28221index b663b7f..9a26c2a 100644
28222--- a/drivers/ata/pata_icside.c
28223+++ b/drivers/ata/pata_icside.c
28224@@ -319,7 +319,7 @@ static void pata_icside_postreset(struct ata_link *link, unsigned int *classes)
28225 }
28226 }
28227
28228-static struct ata_port_operations pata_icside_port_ops = {
28229+static const struct ata_port_operations pata_icside_port_ops = {
28230 .inherits = &ata_sff_port_ops,
28231 /* no need to build any PRD tables for DMA */
28232 .qc_prep = ata_noop_qc_prep,
28233diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
28234index 4bceb88..457dfb6 100644
28235--- a/drivers/ata/pata_isapnp.c
28236+++ b/drivers/ata/pata_isapnp.c
28237@@ -23,12 +23,12 @@ static struct scsi_host_template isapnp_sht = {
28238 ATA_PIO_SHT(DRV_NAME),
28239 };
28240
28241-static struct ata_port_operations isapnp_port_ops = {
28242+static const struct ata_port_operations isapnp_port_ops = {
28243 .inherits = &ata_sff_port_ops,
28244 .cable_detect = ata_cable_40wire,
28245 };
28246
28247-static struct ata_port_operations isapnp_noalt_port_ops = {
28248+static const struct ata_port_operations isapnp_noalt_port_ops = {
28249 .inherits = &ata_sff_port_ops,
28250 .cable_detect = ata_cable_40wire,
28251 /* No altstatus so we don't want to use the lost interrupt poll */
28252diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
28253index f156da8..24976e2 100644
28254--- a/drivers/ata/pata_it8213.c
28255+++ b/drivers/ata/pata_it8213.c
28256@@ -234,7 +234,7 @@ static struct scsi_host_template it8213_sht = {
28257 };
28258
28259
28260-static struct ata_port_operations it8213_ops = {
28261+static const struct ata_port_operations it8213_ops = {
28262 .inherits = &ata_bmdma_port_ops,
28263 .cable_detect = it8213_cable_detect,
28264 .set_piomode = it8213_set_piomode,
28265diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
28266index 188bc2f..ca9e785 100644
28267--- a/drivers/ata/pata_it821x.c
28268+++ b/drivers/ata/pata_it821x.c
28269@@ -800,7 +800,7 @@ static struct scsi_host_template it821x_sht = {
28270 ATA_BMDMA_SHT(DRV_NAME),
28271 };
28272
28273-static struct ata_port_operations it821x_smart_port_ops = {
28274+static const struct ata_port_operations it821x_smart_port_ops = {
28275 .inherits = &ata_bmdma_port_ops,
28276
28277 .check_atapi_dma= it821x_check_atapi_dma,
28278@@ -814,7 +814,7 @@ static struct ata_port_operations it821x_smart_port_ops = {
28279 .port_start = it821x_port_start,
28280 };
28281
28282-static struct ata_port_operations it821x_passthru_port_ops = {
28283+static const struct ata_port_operations it821x_passthru_port_ops = {
28284 .inherits = &ata_bmdma_port_ops,
28285
28286 .check_atapi_dma= it821x_check_atapi_dma,
28287@@ -830,7 +830,7 @@ static struct ata_port_operations it821x_passthru_port_ops = {
28288 .port_start = it821x_port_start,
28289 };
28290
28291-static struct ata_port_operations it821x_rdc_port_ops = {
28292+static const struct ata_port_operations it821x_rdc_port_ops = {
28293 .inherits = &ata_bmdma_port_ops,
28294
28295 .check_atapi_dma= it821x_check_atapi_dma,
28296diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
28297index ba54b08..4b952b7 100644
28298--- a/drivers/ata/pata_ixp4xx_cf.c
28299+++ b/drivers/ata/pata_ixp4xx_cf.c
28300@@ -89,7 +89,7 @@ static struct scsi_host_template ixp4xx_sht = {
28301 ATA_PIO_SHT(DRV_NAME),
28302 };
28303
28304-static struct ata_port_operations ixp4xx_port_ops = {
28305+static const struct ata_port_operations ixp4xx_port_ops = {
28306 .inherits = &ata_sff_port_ops,
28307 .sff_data_xfer = ixp4xx_mmio_data_xfer,
28308 .cable_detect = ata_cable_40wire,
28309diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
28310index 3a1474a..434b0ff 100644
28311--- a/drivers/ata/pata_jmicron.c
28312+++ b/drivers/ata/pata_jmicron.c
28313@@ -111,7 +111,7 @@ static struct scsi_host_template jmicron_sht = {
28314 ATA_BMDMA_SHT(DRV_NAME),
28315 };
28316
28317-static struct ata_port_operations jmicron_ops = {
28318+static const struct ata_port_operations jmicron_ops = {
28319 .inherits = &ata_bmdma_port_ops,
28320 .prereset = jmicron_pre_reset,
28321 };
28322diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
28323index 6932e56..220e71d 100644
28324--- a/drivers/ata/pata_legacy.c
28325+++ b/drivers/ata/pata_legacy.c
28326@@ -106,7 +106,7 @@ struct legacy_probe {
28327
28328 struct legacy_controller {
28329 const char *name;
28330- struct ata_port_operations *ops;
28331+ const struct ata_port_operations *ops;
28332 unsigned int pio_mask;
28333 unsigned int flags;
28334 unsigned int pflags;
28335@@ -223,12 +223,12 @@ static const struct ata_port_operations legacy_base_port_ops = {
28336 * pio_mask as well.
28337 */
28338
28339-static struct ata_port_operations simple_port_ops = {
28340+static const struct ata_port_operations simple_port_ops = {
28341 .inherits = &legacy_base_port_ops,
28342 .sff_data_xfer = ata_sff_data_xfer_noirq,
28343 };
28344
28345-static struct ata_port_operations legacy_port_ops = {
28346+static const struct ata_port_operations legacy_port_ops = {
28347 .inherits = &legacy_base_port_ops,
28348 .sff_data_xfer = ata_sff_data_xfer_noirq,
28349 .set_mode = legacy_set_mode,
28350@@ -324,7 +324,7 @@ static unsigned int pdc_data_xfer_vlb(struct ata_device *dev,
28351 return buflen;
28352 }
28353
28354-static struct ata_port_operations pdc20230_port_ops = {
28355+static const struct ata_port_operations pdc20230_port_ops = {
28356 .inherits = &legacy_base_port_ops,
28357 .set_piomode = pdc20230_set_piomode,
28358 .sff_data_xfer = pdc_data_xfer_vlb,
28359@@ -357,7 +357,7 @@ static void ht6560a_set_piomode(struct ata_port *ap, struct ata_device *adev)
28360 ioread8(ap->ioaddr.status_addr);
28361 }
28362
28363-static struct ata_port_operations ht6560a_port_ops = {
28364+static const struct ata_port_operations ht6560a_port_ops = {
28365 .inherits = &legacy_base_port_ops,
28366 .set_piomode = ht6560a_set_piomode,
28367 };
28368@@ -400,7 +400,7 @@ static void ht6560b_set_piomode(struct ata_port *ap, struct ata_device *adev)
28369 ioread8(ap->ioaddr.status_addr);
28370 }
28371
28372-static struct ata_port_operations ht6560b_port_ops = {
28373+static const struct ata_port_operations ht6560b_port_ops = {
28374 .inherits = &legacy_base_port_ops,
28375 .set_piomode = ht6560b_set_piomode,
28376 };
28377@@ -499,7 +499,7 @@ static void opti82c611a_set_piomode(struct ata_port *ap,
28378 }
28379
28380
28381-static struct ata_port_operations opti82c611a_port_ops = {
28382+static const struct ata_port_operations opti82c611a_port_ops = {
28383 .inherits = &legacy_base_port_ops,
28384 .set_piomode = opti82c611a_set_piomode,
28385 };
28386@@ -609,7 +609,7 @@ static unsigned int opti82c46x_qc_issue(struct ata_queued_cmd *qc)
28387 return ata_sff_qc_issue(qc);
28388 }
28389
28390-static struct ata_port_operations opti82c46x_port_ops = {
28391+static const struct ata_port_operations opti82c46x_port_ops = {
28392 .inherits = &legacy_base_port_ops,
28393 .set_piomode = opti82c46x_set_piomode,
28394 .qc_issue = opti82c46x_qc_issue,
28395@@ -771,20 +771,20 @@ static int qdi_port(struct platform_device *dev,
28396 return 0;
28397 }
28398
28399-static struct ata_port_operations qdi6500_port_ops = {
28400+static const struct ata_port_operations qdi6500_port_ops = {
28401 .inherits = &legacy_base_port_ops,
28402 .set_piomode = qdi6500_set_piomode,
28403 .qc_issue = qdi_qc_issue,
28404 .sff_data_xfer = vlb32_data_xfer,
28405 };
28406
28407-static struct ata_port_operations qdi6580_port_ops = {
28408+static const struct ata_port_operations qdi6580_port_ops = {
28409 .inherits = &legacy_base_port_ops,
28410 .set_piomode = qdi6580_set_piomode,
28411 .sff_data_xfer = vlb32_data_xfer,
28412 };
28413
28414-static struct ata_port_operations qdi6580dp_port_ops = {
28415+static const struct ata_port_operations qdi6580dp_port_ops = {
28416 .inherits = &legacy_base_port_ops,
28417 .set_piomode = qdi6580dp_set_piomode,
28418 .sff_data_xfer = vlb32_data_xfer,
28419@@ -855,7 +855,7 @@ static int winbond_port(struct platform_device *dev,
28420 return 0;
28421 }
28422
28423-static struct ata_port_operations winbond_port_ops = {
28424+static const struct ata_port_operations winbond_port_ops = {
28425 .inherits = &legacy_base_port_ops,
28426 .set_piomode = winbond_set_piomode,
28427 .sff_data_xfer = vlb32_data_xfer,
28428@@ -978,7 +978,7 @@ static __init int legacy_init_one(struct legacy_probe *probe)
28429 int pio_modes = controller->pio_mask;
28430 unsigned long io = probe->port;
28431 u32 mask = (1 << probe->slot);
28432- struct ata_port_operations *ops = controller->ops;
28433+ const struct ata_port_operations *ops = controller->ops;
28434 struct legacy_data *ld = &legacy_data[probe->slot];
28435 struct ata_host *host = NULL;
28436 struct ata_port *ap;
28437diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
28438index 2096fb7..4d090fc 100644
28439--- a/drivers/ata/pata_marvell.c
28440+++ b/drivers/ata/pata_marvell.c
28441@@ -100,7 +100,7 @@ static struct scsi_host_template marvell_sht = {
28442 ATA_BMDMA_SHT(DRV_NAME),
28443 };
28444
28445-static struct ata_port_operations marvell_ops = {
28446+static const struct ata_port_operations marvell_ops = {
28447 .inherits = &ata_bmdma_port_ops,
28448 .cable_detect = marvell_cable_detect,
28449 .prereset = marvell_pre_reset,
28450diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
28451index 99d41be..7d56aa8 100644
28452--- a/drivers/ata/pata_mpc52xx.c
28453+++ b/drivers/ata/pata_mpc52xx.c
28454@@ -609,7 +609,7 @@ static struct scsi_host_template mpc52xx_ata_sht = {
28455 ATA_PIO_SHT(DRV_NAME),
28456 };
28457
28458-static struct ata_port_operations mpc52xx_ata_port_ops = {
28459+static const struct ata_port_operations mpc52xx_ata_port_ops = {
28460 .inherits = &ata_bmdma_port_ops,
28461 .sff_dev_select = mpc52xx_ata_dev_select,
28462 .set_piomode = mpc52xx_ata_set_piomode,
28463diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
28464index b21f002..0a27e7f 100644
28465--- a/drivers/ata/pata_mpiix.c
28466+++ b/drivers/ata/pata_mpiix.c
28467@@ -140,7 +140,7 @@ static struct scsi_host_template mpiix_sht = {
28468 ATA_PIO_SHT(DRV_NAME),
28469 };
28470
28471-static struct ata_port_operations mpiix_port_ops = {
28472+static const struct ata_port_operations mpiix_port_ops = {
28473 .inherits = &ata_sff_port_ops,
28474 .qc_issue = mpiix_qc_issue,
28475 .cable_detect = ata_cable_40wire,
28476diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
28477index f0d52f7..89c3be3 100644
28478--- a/drivers/ata/pata_netcell.c
28479+++ b/drivers/ata/pata_netcell.c
28480@@ -34,7 +34,7 @@ static struct scsi_host_template netcell_sht = {
28481 ATA_BMDMA_SHT(DRV_NAME),
28482 };
28483
28484-static struct ata_port_operations netcell_ops = {
28485+static const struct ata_port_operations netcell_ops = {
28486 .inherits = &ata_bmdma_port_ops,
28487 .cable_detect = ata_cable_80wire,
28488 .read_id = netcell_read_id,
28489diff --git a/drivers/ata/pata_ninja32.c b/drivers/ata/pata_ninja32.c
28490index dd53a66..a3f4317 100644
28491--- a/drivers/ata/pata_ninja32.c
28492+++ b/drivers/ata/pata_ninja32.c
28493@@ -81,7 +81,7 @@ static struct scsi_host_template ninja32_sht = {
28494 ATA_BMDMA_SHT(DRV_NAME),
28495 };
28496
28497-static struct ata_port_operations ninja32_port_ops = {
28498+static const struct ata_port_operations ninja32_port_ops = {
28499 .inherits = &ata_bmdma_port_ops,
28500 .sff_dev_select = ninja32_dev_select,
28501 .cable_detect = ata_cable_40wire,
28502diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
28503index ca53fac..9aa93ef 100644
28504--- a/drivers/ata/pata_ns87410.c
28505+++ b/drivers/ata/pata_ns87410.c
28506@@ -132,7 +132,7 @@ static struct scsi_host_template ns87410_sht = {
28507 ATA_PIO_SHT(DRV_NAME),
28508 };
28509
28510-static struct ata_port_operations ns87410_port_ops = {
28511+static const struct ata_port_operations ns87410_port_ops = {
28512 .inherits = &ata_sff_port_ops,
28513 .qc_issue = ns87410_qc_issue,
28514 .cable_detect = ata_cable_40wire,
28515diff --git a/drivers/ata/pata_ns87415.c b/drivers/ata/pata_ns87415.c
28516index 773b159..55f454e 100644
28517--- a/drivers/ata/pata_ns87415.c
28518+++ b/drivers/ata/pata_ns87415.c
28519@@ -299,7 +299,7 @@ static u8 ns87560_bmdma_status(struct ata_port *ap)
28520 }
28521 #endif /* 87560 SuperIO Support */
28522
28523-static struct ata_port_operations ns87415_pata_ops = {
28524+static const struct ata_port_operations ns87415_pata_ops = {
28525 .inherits = &ata_bmdma_port_ops,
28526
28527 .check_atapi_dma = ns87415_check_atapi_dma,
28528@@ -313,7 +313,7 @@ static struct ata_port_operations ns87415_pata_ops = {
28529 };
28530
28531 #if defined(CONFIG_SUPERIO)
28532-static struct ata_port_operations ns87560_pata_ops = {
28533+static const struct ata_port_operations ns87560_pata_ops = {
28534 .inherits = &ns87415_pata_ops,
28535 .sff_tf_read = ns87560_tf_read,
28536 .sff_check_status = ns87560_check_status,
28537diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
28538index d6f6956..639295b 100644
28539--- a/drivers/ata/pata_octeon_cf.c
28540+++ b/drivers/ata/pata_octeon_cf.c
28541@@ -801,6 +801,7 @@ static unsigned int octeon_cf_qc_issue(struct ata_queued_cmd *qc)
28542 return 0;
28543 }
28544
28545+/* cannot be const */
28546 static struct ata_port_operations octeon_cf_ops = {
28547 .inherits = &ata_sff_port_ops,
28548 .check_atapi_dma = octeon_cf_check_atapi_dma,
28549diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
28550index 84ac503..adee1cd 100644
28551--- a/drivers/ata/pata_oldpiix.c
28552+++ b/drivers/ata/pata_oldpiix.c
28553@@ -208,7 +208,7 @@ static struct scsi_host_template oldpiix_sht = {
28554 ATA_BMDMA_SHT(DRV_NAME),
28555 };
28556
28557-static struct ata_port_operations oldpiix_pata_ops = {
28558+static const struct ata_port_operations oldpiix_pata_ops = {
28559 .inherits = &ata_bmdma_port_ops,
28560 .qc_issue = oldpiix_qc_issue,
28561 .cable_detect = ata_cable_40wire,
28562diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
28563index 99eddda..3a4c0aa 100644
28564--- a/drivers/ata/pata_opti.c
28565+++ b/drivers/ata/pata_opti.c
28566@@ -152,7 +152,7 @@ static struct scsi_host_template opti_sht = {
28567 ATA_PIO_SHT(DRV_NAME),
28568 };
28569
28570-static struct ata_port_operations opti_port_ops = {
28571+static const struct ata_port_operations opti_port_ops = {
28572 .inherits = &ata_sff_port_ops,
28573 .cable_detect = ata_cable_40wire,
28574 .set_piomode = opti_set_piomode,
28575diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
28576index 86885a4..8e9968d 100644
28577--- a/drivers/ata/pata_optidma.c
28578+++ b/drivers/ata/pata_optidma.c
28579@@ -337,7 +337,7 @@ static struct scsi_host_template optidma_sht = {
28580 ATA_BMDMA_SHT(DRV_NAME),
28581 };
28582
28583-static struct ata_port_operations optidma_port_ops = {
28584+static const struct ata_port_operations optidma_port_ops = {
28585 .inherits = &ata_bmdma_port_ops,
28586 .cable_detect = ata_cable_40wire,
28587 .set_piomode = optidma_set_pio_mode,
28588@@ -346,7 +346,7 @@ static struct ata_port_operations optidma_port_ops = {
28589 .prereset = optidma_pre_reset,
28590 };
28591
28592-static struct ata_port_operations optiplus_port_ops = {
28593+static const struct ata_port_operations optiplus_port_ops = {
28594 .inherits = &optidma_port_ops,
28595 .set_piomode = optiplus_set_pio_mode,
28596 .set_dmamode = optiplus_set_dma_mode,
28597diff --git a/drivers/ata/pata_palmld.c b/drivers/ata/pata_palmld.c
28598index 11fb4cc..1a14022 100644
28599--- a/drivers/ata/pata_palmld.c
28600+++ b/drivers/ata/pata_palmld.c
28601@@ -37,7 +37,7 @@ static struct scsi_host_template palmld_sht = {
28602 ATA_PIO_SHT(DRV_NAME),
28603 };
28604
28605-static struct ata_port_operations palmld_port_ops = {
28606+static const struct ata_port_operations palmld_port_ops = {
28607 .inherits = &ata_sff_port_ops,
28608 .sff_data_xfer = ata_sff_data_xfer_noirq,
28609 .cable_detect = ata_cable_40wire,
28610diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
28611index dc99e26..7f4b1e4 100644
28612--- a/drivers/ata/pata_pcmcia.c
28613+++ b/drivers/ata/pata_pcmcia.c
28614@@ -162,14 +162,14 @@ static struct scsi_host_template pcmcia_sht = {
28615 ATA_PIO_SHT(DRV_NAME),
28616 };
28617
28618-static struct ata_port_operations pcmcia_port_ops = {
28619+static const struct ata_port_operations pcmcia_port_ops = {
28620 .inherits = &ata_sff_port_ops,
28621 .sff_data_xfer = ata_sff_data_xfer_noirq,
28622 .cable_detect = ata_cable_40wire,
28623 .set_mode = pcmcia_set_mode,
28624 };
28625
28626-static struct ata_port_operations pcmcia_8bit_port_ops = {
28627+static const struct ata_port_operations pcmcia_8bit_port_ops = {
28628 .inherits = &ata_sff_port_ops,
28629 .sff_data_xfer = ata_data_xfer_8bit,
28630 .cable_detect = ata_cable_40wire,
28631@@ -256,7 +256,7 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
28632 unsigned long io_base, ctl_base;
28633 void __iomem *io_addr, *ctl_addr;
28634 int n_ports = 1;
28635- struct ata_port_operations *ops = &pcmcia_port_ops;
28636+ const struct ata_port_operations *ops = &pcmcia_port_ops;
28637
28638 info = kzalloc(sizeof(*info), GFP_KERNEL);
28639 if (info == NULL)
28640diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
28641index ca5cad0..3a1f125 100644
28642--- a/drivers/ata/pata_pdc2027x.c
28643+++ b/drivers/ata/pata_pdc2027x.c
28644@@ -132,14 +132,14 @@ static struct scsi_host_template pdc2027x_sht = {
28645 ATA_BMDMA_SHT(DRV_NAME),
28646 };
28647
28648-static struct ata_port_operations pdc2027x_pata100_ops = {
28649+static const struct ata_port_operations pdc2027x_pata100_ops = {
28650 .inherits = &ata_bmdma_port_ops,
28651 .check_atapi_dma = pdc2027x_check_atapi_dma,
28652 .cable_detect = pdc2027x_cable_detect,
28653 .prereset = pdc2027x_prereset,
28654 };
28655
28656-static struct ata_port_operations pdc2027x_pata133_ops = {
28657+static const struct ata_port_operations pdc2027x_pata133_ops = {
28658 .inherits = &pdc2027x_pata100_ops,
28659 .mode_filter = pdc2027x_mode_filter,
28660 .set_piomode = pdc2027x_set_piomode,
28661diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
28662index 2911120..4bf62aa 100644
28663--- a/drivers/ata/pata_pdc202xx_old.c
28664+++ b/drivers/ata/pata_pdc202xx_old.c
28665@@ -274,7 +274,7 @@ static struct scsi_host_template pdc202xx_sht = {
28666 ATA_BMDMA_SHT(DRV_NAME),
28667 };
28668
28669-static struct ata_port_operations pdc2024x_port_ops = {
28670+static const struct ata_port_operations pdc2024x_port_ops = {
28671 .inherits = &ata_bmdma_port_ops,
28672
28673 .cable_detect = ata_cable_40wire,
28674@@ -284,7 +284,7 @@ static struct ata_port_operations pdc2024x_port_ops = {
28675 .sff_exec_command = pdc202xx_exec_command,
28676 };
28677
28678-static struct ata_port_operations pdc2026x_port_ops = {
28679+static const struct ata_port_operations pdc2026x_port_ops = {
28680 .inherits = &pdc2024x_port_ops,
28681
28682 .check_atapi_dma = pdc2026x_check_atapi_dma,
28683diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
28684index 3f6ebc6..a18c358 100644
28685--- a/drivers/ata/pata_platform.c
28686+++ b/drivers/ata/pata_platform.c
28687@@ -48,7 +48,7 @@ static struct scsi_host_template pata_platform_sht = {
28688 ATA_PIO_SHT(DRV_NAME),
28689 };
28690
28691-static struct ata_port_operations pata_platform_port_ops = {
28692+static const struct ata_port_operations pata_platform_port_ops = {
28693 .inherits = &ata_sff_port_ops,
28694 .sff_data_xfer = ata_sff_data_xfer_noirq,
28695 .cable_detect = ata_cable_unknown,
28696diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
28697index 45879dc..165a9f9 100644
28698--- a/drivers/ata/pata_qdi.c
28699+++ b/drivers/ata/pata_qdi.c
28700@@ -157,7 +157,7 @@ static struct scsi_host_template qdi_sht = {
28701 ATA_PIO_SHT(DRV_NAME),
28702 };
28703
28704-static struct ata_port_operations qdi6500_port_ops = {
28705+static const struct ata_port_operations qdi6500_port_ops = {
28706 .inherits = &ata_sff_port_ops,
28707 .qc_issue = qdi_qc_issue,
28708 .sff_data_xfer = qdi_data_xfer,
28709@@ -165,7 +165,7 @@ static struct ata_port_operations qdi6500_port_ops = {
28710 .set_piomode = qdi6500_set_piomode,
28711 };
28712
28713-static struct ata_port_operations qdi6580_port_ops = {
28714+static const struct ata_port_operations qdi6580_port_ops = {
28715 .inherits = &qdi6500_port_ops,
28716 .set_piomode = qdi6580_set_piomode,
28717 };
28718diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
28719index 4401b33..716c5cc 100644
28720--- a/drivers/ata/pata_radisys.c
28721+++ b/drivers/ata/pata_radisys.c
28722@@ -187,7 +187,7 @@ static struct scsi_host_template radisys_sht = {
28723 ATA_BMDMA_SHT(DRV_NAME),
28724 };
28725
28726-static struct ata_port_operations radisys_pata_ops = {
28727+static const struct ata_port_operations radisys_pata_ops = {
28728 .inherits = &ata_bmdma_port_ops,
28729 .qc_issue = radisys_qc_issue,
28730 .cable_detect = ata_cable_unknown,
28731diff --git a/drivers/ata/pata_rb532_cf.c b/drivers/ata/pata_rb532_cf.c
28732index 45f1e10..fab6bca 100644
28733--- a/drivers/ata/pata_rb532_cf.c
28734+++ b/drivers/ata/pata_rb532_cf.c
28735@@ -68,7 +68,7 @@ static irqreturn_t rb532_pata_irq_handler(int irq, void *dev_instance)
28736 return IRQ_HANDLED;
28737 }
28738
28739-static struct ata_port_operations rb532_pata_port_ops = {
28740+static const struct ata_port_operations rb532_pata_port_ops = {
28741 .inherits = &ata_sff_port_ops,
28742 .sff_data_xfer = ata_sff_data_xfer32,
28743 };
28744diff --git a/drivers/ata/pata_rdc.c b/drivers/ata/pata_rdc.c
28745index c843a1e..b5853c3 100644
28746--- a/drivers/ata/pata_rdc.c
28747+++ b/drivers/ata/pata_rdc.c
28748@@ -272,7 +272,7 @@ static void rdc_set_dmamode(struct ata_port *ap, struct ata_device *adev)
28749 pci_write_config_byte(dev, 0x48, udma_enable);
28750 }
28751
28752-static struct ata_port_operations rdc_pata_ops = {
28753+static const struct ata_port_operations rdc_pata_ops = {
28754 .inherits = &ata_bmdma32_port_ops,
28755 .cable_detect = rdc_pata_cable_detect,
28756 .set_piomode = rdc_set_piomode,
28757diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
28758index a5e4dfe..080c8c9 100644
28759--- a/drivers/ata/pata_rz1000.c
28760+++ b/drivers/ata/pata_rz1000.c
28761@@ -54,7 +54,7 @@ static struct scsi_host_template rz1000_sht = {
28762 ATA_PIO_SHT(DRV_NAME),
28763 };
28764
28765-static struct ata_port_operations rz1000_port_ops = {
28766+static const struct ata_port_operations rz1000_port_ops = {
28767 .inherits = &ata_sff_port_ops,
28768 .cable_detect = ata_cable_40wire,
28769 .set_mode = rz1000_set_mode,
28770diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
28771index 3bbed83..e309daf 100644
28772--- a/drivers/ata/pata_sc1200.c
28773+++ b/drivers/ata/pata_sc1200.c
28774@@ -207,7 +207,7 @@ static struct scsi_host_template sc1200_sht = {
28775 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
28776 };
28777
28778-static struct ata_port_operations sc1200_port_ops = {
28779+static const struct ata_port_operations sc1200_port_ops = {
28780 .inherits = &ata_bmdma_port_ops,
28781 .qc_prep = ata_sff_dumb_qc_prep,
28782 .qc_issue = sc1200_qc_issue,
28783diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
28784index 4257d6b..4c1d9d5 100644
28785--- a/drivers/ata/pata_scc.c
28786+++ b/drivers/ata/pata_scc.c
28787@@ -965,7 +965,7 @@ static struct scsi_host_template scc_sht = {
28788 ATA_BMDMA_SHT(DRV_NAME),
28789 };
28790
28791-static struct ata_port_operations scc_pata_ops = {
28792+static const struct ata_port_operations scc_pata_ops = {
28793 .inherits = &ata_bmdma_port_ops,
28794
28795 .set_piomode = scc_set_piomode,
28796diff --git a/drivers/ata/pata_sch.c b/drivers/ata/pata_sch.c
28797index 99cceb4..e2e0a87 100644
28798--- a/drivers/ata/pata_sch.c
28799+++ b/drivers/ata/pata_sch.c
28800@@ -75,7 +75,7 @@ static struct scsi_host_template sch_sht = {
28801 ATA_BMDMA_SHT(DRV_NAME),
28802 };
28803
28804-static struct ata_port_operations sch_pata_ops = {
28805+static const struct ata_port_operations sch_pata_ops = {
28806 .inherits = &ata_bmdma_port_ops,
28807 .cable_detect = ata_cable_unknown,
28808 .set_piomode = sch_set_piomode,
28809diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
28810index beaed12..39969f1 100644
28811--- a/drivers/ata/pata_serverworks.c
28812+++ b/drivers/ata/pata_serverworks.c
28813@@ -299,7 +299,7 @@ static struct scsi_host_template serverworks_sht = {
28814 ATA_BMDMA_SHT(DRV_NAME),
28815 };
28816
28817-static struct ata_port_operations serverworks_osb4_port_ops = {
28818+static const struct ata_port_operations serverworks_osb4_port_ops = {
28819 .inherits = &ata_bmdma_port_ops,
28820 .cable_detect = serverworks_cable_detect,
28821 .mode_filter = serverworks_osb4_filter,
28822@@ -307,7 +307,7 @@ static struct ata_port_operations serverworks_osb4_port_ops = {
28823 .set_dmamode = serverworks_set_dmamode,
28824 };
28825
28826-static struct ata_port_operations serverworks_csb_port_ops = {
28827+static const struct ata_port_operations serverworks_csb_port_ops = {
28828 .inherits = &serverworks_osb4_port_ops,
28829 .mode_filter = serverworks_csb_filter,
28830 };
28831diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
28832index a2ace48..0463b44 100644
28833--- a/drivers/ata/pata_sil680.c
28834+++ b/drivers/ata/pata_sil680.c
28835@@ -194,7 +194,7 @@ static struct scsi_host_template sil680_sht = {
28836 ATA_BMDMA_SHT(DRV_NAME),
28837 };
28838
28839-static struct ata_port_operations sil680_port_ops = {
28840+static const struct ata_port_operations sil680_port_ops = {
28841 .inherits = &ata_bmdma32_port_ops,
28842 .cable_detect = sil680_cable_detect,
28843 .set_piomode = sil680_set_piomode,
28844diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
28845index 488e77b..b3724d5 100644
28846--- a/drivers/ata/pata_sis.c
28847+++ b/drivers/ata/pata_sis.c
28848@@ -503,47 +503,47 @@ static struct scsi_host_template sis_sht = {
28849 ATA_BMDMA_SHT(DRV_NAME),
28850 };
28851
28852-static struct ata_port_operations sis_133_for_sata_ops = {
28853+static const struct ata_port_operations sis_133_for_sata_ops = {
28854 .inherits = &ata_bmdma_port_ops,
28855 .set_piomode = sis_133_set_piomode,
28856 .set_dmamode = sis_133_set_dmamode,
28857 .cable_detect = sis_133_cable_detect,
28858 };
28859
28860-static struct ata_port_operations sis_base_ops = {
28861+static const struct ata_port_operations sis_base_ops = {
28862 .inherits = &ata_bmdma_port_ops,
28863 .prereset = sis_pre_reset,
28864 };
28865
28866-static struct ata_port_operations sis_133_ops = {
28867+static const struct ata_port_operations sis_133_ops = {
28868 .inherits = &sis_base_ops,
28869 .set_piomode = sis_133_set_piomode,
28870 .set_dmamode = sis_133_set_dmamode,
28871 .cable_detect = sis_133_cable_detect,
28872 };
28873
28874-static struct ata_port_operations sis_133_early_ops = {
28875+static const struct ata_port_operations sis_133_early_ops = {
28876 .inherits = &sis_base_ops,
28877 .set_piomode = sis_100_set_piomode,
28878 .set_dmamode = sis_133_early_set_dmamode,
28879 .cable_detect = sis_66_cable_detect,
28880 };
28881
28882-static struct ata_port_operations sis_100_ops = {
28883+static const struct ata_port_operations sis_100_ops = {
28884 .inherits = &sis_base_ops,
28885 .set_piomode = sis_100_set_piomode,
28886 .set_dmamode = sis_100_set_dmamode,
28887 .cable_detect = sis_66_cable_detect,
28888 };
28889
28890-static struct ata_port_operations sis_66_ops = {
28891+static const struct ata_port_operations sis_66_ops = {
28892 .inherits = &sis_base_ops,
28893 .set_piomode = sis_old_set_piomode,
28894 .set_dmamode = sis_66_set_dmamode,
28895 .cable_detect = sis_66_cable_detect,
28896 };
28897
28898-static struct ata_port_operations sis_old_ops = {
28899+static const struct ata_port_operations sis_old_ops = {
28900 .inherits = &sis_base_ops,
28901 .set_piomode = sis_old_set_piomode,
28902 .set_dmamode = sis_old_set_dmamode,
28903diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
28904index 29f733c..43e9ca0 100644
28905--- a/drivers/ata/pata_sl82c105.c
28906+++ b/drivers/ata/pata_sl82c105.c
28907@@ -231,7 +231,7 @@ static struct scsi_host_template sl82c105_sht = {
28908 ATA_BMDMA_SHT(DRV_NAME),
28909 };
28910
28911-static struct ata_port_operations sl82c105_port_ops = {
28912+static const struct ata_port_operations sl82c105_port_ops = {
28913 .inherits = &ata_bmdma_port_ops,
28914 .qc_defer = sl82c105_qc_defer,
28915 .bmdma_start = sl82c105_bmdma_start,
28916diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
28917index f1f13ff..df39e99 100644
28918--- a/drivers/ata/pata_triflex.c
28919+++ b/drivers/ata/pata_triflex.c
28920@@ -178,7 +178,7 @@ static struct scsi_host_template triflex_sht = {
28921 ATA_BMDMA_SHT(DRV_NAME),
28922 };
28923
28924-static struct ata_port_operations triflex_port_ops = {
28925+static const struct ata_port_operations triflex_port_ops = {
28926 .inherits = &ata_bmdma_port_ops,
28927 .bmdma_start = triflex_bmdma_start,
28928 .bmdma_stop = triflex_bmdma_stop,
28929diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
28930index 1d73b8d..98a4b29 100644
28931--- a/drivers/ata/pata_via.c
28932+++ b/drivers/ata/pata_via.c
28933@@ -419,7 +419,7 @@ static struct scsi_host_template via_sht = {
28934 ATA_BMDMA_SHT(DRV_NAME),
28935 };
28936
28937-static struct ata_port_operations via_port_ops = {
28938+static const struct ata_port_operations via_port_ops = {
28939 .inherits = &ata_bmdma_port_ops,
28940 .cable_detect = via_cable_detect,
28941 .set_piomode = via_set_piomode,
28942@@ -429,7 +429,7 @@ static struct ata_port_operations via_port_ops = {
28943 .port_start = via_port_start,
28944 };
28945
28946-static struct ata_port_operations via_port_ops_noirq = {
28947+static const struct ata_port_operations via_port_ops_noirq = {
28948 .inherits = &via_port_ops,
28949 .sff_data_xfer = ata_sff_data_xfer_noirq,
28950 };
28951diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
28952index 6d8619b..ad511c4 100644
28953--- a/drivers/ata/pata_winbond.c
28954+++ b/drivers/ata/pata_winbond.c
28955@@ -125,7 +125,7 @@ static struct scsi_host_template winbond_sht = {
28956 ATA_PIO_SHT(DRV_NAME),
28957 };
28958
28959-static struct ata_port_operations winbond_port_ops = {
28960+static const struct ata_port_operations winbond_port_ops = {
28961 .inherits = &ata_sff_port_ops,
28962 .sff_data_xfer = winbond_data_xfer,
28963 .cable_detect = ata_cable_40wire,
28964diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
28965index 6c65b07..f996ec7 100644
28966--- a/drivers/ata/pdc_adma.c
28967+++ b/drivers/ata/pdc_adma.c
28968@@ -145,7 +145,7 @@ static struct scsi_host_template adma_ata_sht = {
28969 .dma_boundary = ADMA_DMA_BOUNDARY,
28970 };
28971
28972-static struct ata_port_operations adma_ata_ops = {
28973+static const struct ata_port_operations adma_ata_ops = {
28974 .inherits = &ata_sff_port_ops,
28975
28976 .lost_interrupt = ATA_OP_NULL,
28977diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
28978index 172b57e..c49bc1e 100644
28979--- a/drivers/ata/sata_fsl.c
28980+++ b/drivers/ata/sata_fsl.c
28981@@ -1258,7 +1258,7 @@ static struct scsi_host_template sata_fsl_sht = {
28982 .dma_boundary = ATA_DMA_BOUNDARY,
28983 };
28984
28985-static struct ata_port_operations sata_fsl_ops = {
28986+static const struct ata_port_operations sata_fsl_ops = {
28987 .inherits = &sata_pmp_port_ops,
28988
28989 .qc_defer = ata_std_qc_defer,
28990diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
28991index 4406902..60603ef 100644
28992--- a/drivers/ata/sata_inic162x.c
28993+++ b/drivers/ata/sata_inic162x.c
28994@@ -721,7 +721,7 @@ static int inic_port_start(struct ata_port *ap)
28995 return 0;
28996 }
28997
28998-static struct ata_port_operations inic_port_ops = {
28999+static const struct ata_port_operations inic_port_ops = {
29000 .inherits = &sata_port_ops,
29001
29002 .check_atapi_dma = inic_check_atapi_dma,
29003diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
29004index cf41126..8107be6 100644
29005--- a/drivers/ata/sata_mv.c
29006+++ b/drivers/ata/sata_mv.c
29007@@ -656,7 +656,7 @@ static struct scsi_host_template mv6_sht = {
29008 .dma_boundary = MV_DMA_BOUNDARY,
29009 };
29010
29011-static struct ata_port_operations mv5_ops = {
29012+static const struct ata_port_operations mv5_ops = {
29013 .inherits = &ata_sff_port_ops,
29014
29015 .lost_interrupt = ATA_OP_NULL,
29016@@ -678,7 +678,7 @@ static struct ata_port_operations mv5_ops = {
29017 .port_stop = mv_port_stop,
29018 };
29019
29020-static struct ata_port_operations mv6_ops = {
29021+static const struct ata_port_operations mv6_ops = {
29022 .inherits = &mv5_ops,
29023 .dev_config = mv6_dev_config,
29024 .scr_read = mv_scr_read,
29025@@ -698,7 +698,7 @@ static struct ata_port_operations mv6_ops = {
29026 .bmdma_status = mv_bmdma_status,
29027 };
29028
29029-static struct ata_port_operations mv_iie_ops = {
29030+static const struct ata_port_operations mv_iie_ops = {
29031 .inherits = &mv6_ops,
29032 .dev_config = ATA_OP_NULL,
29033 .qc_prep = mv_qc_prep_iie,
29034diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
29035index ae2297c..d5c9c33 100644
29036--- a/drivers/ata/sata_nv.c
29037+++ b/drivers/ata/sata_nv.c
29038@@ -464,7 +464,7 @@ static struct scsi_host_template nv_swncq_sht = {
29039 * cases. Define nv_hardreset() which only kicks in for post-boot
29040 * probing and use it for all variants.
29041 */
29042-static struct ata_port_operations nv_generic_ops = {
29043+static const struct ata_port_operations nv_generic_ops = {
29044 .inherits = &ata_bmdma_port_ops,
29045 .lost_interrupt = ATA_OP_NULL,
29046 .scr_read = nv_scr_read,
29047@@ -472,20 +472,20 @@ static struct ata_port_operations nv_generic_ops = {
29048 .hardreset = nv_hardreset,
29049 };
29050
29051-static struct ata_port_operations nv_nf2_ops = {
29052+static const struct ata_port_operations nv_nf2_ops = {
29053 .inherits = &nv_generic_ops,
29054 .freeze = nv_nf2_freeze,
29055 .thaw = nv_nf2_thaw,
29056 };
29057
29058-static struct ata_port_operations nv_ck804_ops = {
29059+static const struct ata_port_operations nv_ck804_ops = {
29060 .inherits = &nv_generic_ops,
29061 .freeze = nv_ck804_freeze,
29062 .thaw = nv_ck804_thaw,
29063 .host_stop = nv_ck804_host_stop,
29064 };
29065
29066-static struct ata_port_operations nv_adma_ops = {
29067+static const struct ata_port_operations nv_adma_ops = {
29068 .inherits = &nv_ck804_ops,
29069
29070 .check_atapi_dma = nv_adma_check_atapi_dma,
29071@@ -509,7 +509,7 @@ static struct ata_port_operations nv_adma_ops = {
29072 .host_stop = nv_adma_host_stop,
29073 };
29074
29075-static struct ata_port_operations nv_swncq_ops = {
29076+static const struct ata_port_operations nv_swncq_ops = {
29077 .inherits = &nv_generic_ops,
29078
29079 .qc_defer = ata_std_qc_defer,
29080diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
29081index 07d8d00..6cc70bb 100644
29082--- a/drivers/ata/sata_promise.c
29083+++ b/drivers/ata/sata_promise.c
29084@@ -195,7 +195,7 @@ static const struct ata_port_operations pdc_common_ops = {
29085 .error_handler = pdc_error_handler,
29086 };
29087
29088-static struct ata_port_operations pdc_sata_ops = {
29089+static const struct ata_port_operations pdc_sata_ops = {
29090 .inherits = &pdc_common_ops,
29091 .cable_detect = pdc_sata_cable_detect,
29092 .freeze = pdc_sata_freeze,
29093@@ -208,14 +208,14 @@ static struct ata_port_operations pdc_sata_ops = {
29094
29095 /* First-generation chips need a more restrictive ->check_atapi_dma op,
29096 and ->freeze/thaw that ignore the hotplug controls. */
29097-static struct ata_port_operations pdc_old_sata_ops = {
29098+static const struct ata_port_operations pdc_old_sata_ops = {
29099 .inherits = &pdc_sata_ops,
29100 .freeze = pdc_freeze,
29101 .thaw = pdc_thaw,
29102 .check_atapi_dma = pdc_old_sata_check_atapi_dma,
29103 };
29104
29105-static struct ata_port_operations pdc_pata_ops = {
29106+static const struct ata_port_operations pdc_pata_ops = {
29107 .inherits = &pdc_common_ops,
29108 .cable_detect = pdc_pata_cable_detect,
29109 .freeze = pdc_freeze,
29110diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
29111index 326c0cf..36ecebe 100644
29112--- a/drivers/ata/sata_qstor.c
29113+++ b/drivers/ata/sata_qstor.c
29114@@ -132,7 +132,7 @@ static struct scsi_host_template qs_ata_sht = {
29115 .dma_boundary = QS_DMA_BOUNDARY,
29116 };
29117
29118-static struct ata_port_operations qs_ata_ops = {
29119+static const struct ata_port_operations qs_ata_ops = {
29120 .inherits = &ata_sff_port_ops,
29121
29122 .check_atapi_dma = qs_check_atapi_dma,
29123diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
29124index 3cb69d5..0871d3c 100644
29125--- a/drivers/ata/sata_sil.c
29126+++ b/drivers/ata/sata_sil.c
29127@@ -182,7 +182,7 @@ static struct scsi_host_template sil_sht = {
29128 .sg_tablesize = ATA_MAX_PRD
29129 };
29130
29131-static struct ata_port_operations sil_ops = {
29132+static const struct ata_port_operations sil_ops = {
29133 .inherits = &ata_bmdma32_port_ops,
29134 .dev_config = sil_dev_config,
29135 .set_mode = sil_set_mode,
29136diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
29137index e6946fc..eddb794 100644
29138--- a/drivers/ata/sata_sil24.c
29139+++ b/drivers/ata/sata_sil24.c
29140@@ -388,7 +388,7 @@ static struct scsi_host_template sil24_sht = {
29141 .dma_boundary = ATA_DMA_BOUNDARY,
29142 };
29143
29144-static struct ata_port_operations sil24_ops = {
29145+static const struct ata_port_operations sil24_ops = {
29146 .inherits = &sata_pmp_port_ops,
29147
29148 .qc_defer = sil24_qc_defer,
29149diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
29150index f8a91bf..9cb06b6 100644
29151--- a/drivers/ata/sata_sis.c
29152+++ b/drivers/ata/sata_sis.c
29153@@ -89,7 +89,7 @@ static struct scsi_host_template sis_sht = {
29154 ATA_BMDMA_SHT(DRV_NAME),
29155 };
29156
29157-static struct ata_port_operations sis_ops = {
29158+static const struct ata_port_operations sis_ops = {
29159 .inherits = &ata_bmdma_port_ops,
29160 .scr_read = sis_scr_read,
29161 .scr_write = sis_scr_write,
29162diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
29163index 7257f2d..d04c6f5 100644
29164--- a/drivers/ata/sata_svw.c
29165+++ b/drivers/ata/sata_svw.c
29166@@ -344,7 +344,7 @@ static struct scsi_host_template k2_sata_sht = {
29167 };
29168
29169
29170-static struct ata_port_operations k2_sata_ops = {
29171+static const struct ata_port_operations k2_sata_ops = {
29172 .inherits = &ata_bmdma_port_ops,
29173 .sff_tf_load = k2_sata_tf_load,
29174 .sff_tf_read = k2_sata_tf_read,
29175diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
29176index bbcf970..cd0df0d 100644
29177--- a/drivers/ata/sata_sx4.c
29178+++ b/drivers/ata/sata_sx4.c
29179@@ -248,7 +248,7 @@ static struct scsi_host_template pdc_sata_sht = {
29180 };
29181
29182 /* TODO: inherit from base port_ops after converting to new EH */
29183-static struct ata_port_operations pdc_20621_ops = {
29184+static const struct ata_port_operations pdc_20621_ops = {
29185 .inherits = &ata_sff_port_ops,
29186
29187 .check_atapi_dma = pdc_check_atapi_dma,
29188diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
29189index e5bff47..089d859 100644
29190--- a/drivers/ata/sata_uli.c
29191+++ b/drivers/ata/sata_uli.c
29192@@ -79,7 +79,7 @@ static struct scsi_host_template uli_sht = {
29193 ATA_BMDMA_SHT(DRV_NAME),
29194 };
29195
29196-static struct ata_port_operations uli_ops = {
29197+static const struct ata_port_operations uli_ops = {
29198 .inherits = &ata_bmdma_port_ops,
29199 .scr_read = uli_scr_read,
29200 .scr_write = uli_scr_write,
29201diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
29202index f5dcca7..77b94eb 100644
29203--- a/drivers/ata/sata_via.c
29204+++ b/drivers/ata/sata_via.c
29205@@ -115,32 +115,32 @@ static struct scsi_host_template svia_sht = {
29206 ATA_BMDMA_SHT(DRV_NAME),
29207 };
29208
29209-static struct ata_port_operations svia_base_ops = {
29210+static const struct ata_port_operations svia_base_ops = {
29211 .inherits = &ata_bmdma_port_ops,
29212 .sff_tf_load = svia_tf_load,
29213 };
29214
29215-static struct ata_port_operations vt6420_sata_ops = {
29216+static const struct ata_port_operations vt6420_sata_ops = {
29217 .inherits = &svia_base_ops,
29218 .freeze = svia_noop_freeze,
29219 .prereset = vt6420_prereset,
29220 .bmdma_start = vt6420_bmdma_start,
29221 };
29222
29223-static struct ata_port_operations vt6421_pata_ops = {
29224+static const struct ata_port_operations vt6421_pata_ops = {
29225 .inherits = &svia_base_ops,
29226 .cable_detect = vt6421_pata_cable_detect,
29227 .set_piomode = vt6421_set_pio_mode,
29228 .set_dmamode = vt6421_set_dma_mode,
29229 };
29230
29231-static struct ata_port_operations vt6421_sata_ops = {
29232+static const struct ata_port_operations vt6421_sata_ops = {
29233 .inherits = &svia_base_ops,
29234 .scr_read = svia_scr_read,
29235 .scr_write = svia_scr_write,
29236 };
29237
29238-static struct ata_port_operations vt8251_ops = {
29239+static const struct ata_port_operations vt8251_ops = {
29240 .inherits = &svia_base_ops,
29241 .hardreset = sata_std_hardreset,
29242 .scr_read = vt8251_scr_read,
29243diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
29244index 8b2a278..51e65d3 100644
29245--- a/drivers/ata/sata_vsc.c
29246+++ b/drivers/ata/sata_vsc.c
29247@@ -306,7 +306,7 @@ static struct scsi_host_template vsc_sata_sht = {
29248 };
29249
29250
29251-static struct ata_port_operations vsc_sata_ops = {
29252+static const struct ata_port_operations vsc_sata_ops = {
29253 .inherits = &ata_bmdma_port_ops,
29254 /* The IRQ handling is not quite standard SFF behaviour so we
29255 cannot use the default lost interrupt handler */
29256diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
29257index 5effec6..7e4019a 100644
29258--- a/drivers/atm/adummy.c
29259+++ b/drivers/atm/adummy.c
29260@@ -77,7 +77,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
29261 vcc->pop(vcc, skb);
29262 else
29263 dev_kfree_skb_any(skb);
29264- atomic_inc(&vcc->stats->tx);
29265+ atomic_inc_unchecked(&vcc->stats->tx);
29266
29267 return 0;
29268 }
29269diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
29270index 66e1813..26a27c6 100644
29271--- a/drivers/atm/ambassador.c
29272+++ b/drivers/atm/ambassador.c
29273@@ -453,7 +453,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
29274 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
29275
29276 // VC layer stats
29277- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29278+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29279
29280 // free the descriptor
29281 kfree (tx_descr);
29282@@ -494,7 +494,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29283 dump_skb ("<<<", vc, skb);
29284
29285 // VC layer stats
29286- atomic_inc(&atm_vcc->stats->rx);
29287+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29288 __net_timestamp(skb);
29289 // end of our responsability
29290 atm_vcc->push (atm_vcc, skb);
29291@@ -509,7 +509,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29292 } else {
29293 PRINTK (KERN_INFO, "dropped over-size frame");
29294 // should we count this?
29295- atomic_inc(&atm_vcc->stats->rx_drop);
29296+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29297 }
29298
29299 } else {
29300@@ -1341,7 +1341,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
29301 }
29302
29303 if (check_area (skb->data, skb->len)) {
29304- atomic_inc(&atm_vcc->stats->tx_err);
29305+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
29306 return -ENOMEM; // ?
29307 }
29308
29309diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
29310index 02ad83d..6daffeb 100644
29311--- a/drivers/atm/atmtcp.c
29312+++ b/drivers/atm/atmtcp.c
29313@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29314 if (vcc->pop) vcc->pop(vcc,skb);
29315 else dev_kfree_skb(skb);
29316 if (dev_data) return 0;
29317- atomic_inc(&vcc->stats->tx_err);
29318+ atomic_inc_unchecked(&vcc->stats->tx_err);
29319 return -ENOLINK;
29320 }
29321 size = skb->len+sizeof(struct atmtcp_hdr);
29322@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29323 if (!new_skb) {
29324 if (vcc->pop) vcc->pop(vcc,skb);
29325 else dev_kfree_skb(skb);
29326- atomic_inc(&vcc->stats->tx_err);
29327+ atomic_inc_unchecked(&vcc->stats->tx_err);
29328 return -ENOBUFS;
29329 }
29330 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
29331@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29332 if (vcc->pop) vcc->pop(vcc,skb);
29333 else dev_kfree_skb(skb);
29334 out_vcc->push(out_vcc,new_skb);
29335- atomic_inc(&vcc->stats->tx);
29336- atomic_inc(&out_vcc->stats->rx);
29337+ atomic_inc_unchecked(&vcc->stats->tx);
29338+ atomic_inc_unchecked(&out_vcc->stats->rx);
29339 return 0;
29340 }
29341
29342@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29343 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
29344 read_unlock(&vcc_sklist_lock);
29345 if (!out_vcc) {
29346- atomic_inc(&vcc->stats->tx_err);
29347+ atomic_inc_unchecked(&vcc->stats->tx_err);
29348 goto done;
29349 }
29350 skb_pull(skb,sizeof(struct atmtcp_hdr));
29351@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29352 __net_timestamp(new_skb);
29353 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
29354 out_vcc->push(out_vcc,new_skb);
29355- atomic_inc(&vcc->stats->tx);
29356- atomic_inc(&out_vcc->stats->rx);
29357+ atomic_inc_unchecked(&vcc->stats->tx);
29358+ atomic_inc_unchecked(&out_vcc->stats->rx);
29359 done:
29360 if (vcc->pop) vcc->pop(vcc,skb);
29361 else dev_kfree_skb(skb);
29362diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
29363index 0c30261..3da356e 100644
29364--- a/drivers/atm/eni.c
29365+++ b/drivers/atm/eni.c
29366@@ -525,7 +525,7 @@ static int rx_aal0(struct atm_vcc *vcc)
29367 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
29368 vcc->dev->number);
29369 length = 0;
29370- atomic_inc(&vcc->stats->rx_err);
29371+ atomic_inc_unchecked(&vcc->stats->rx_err);
29372 }
29373 else {
29374 length = ATM_CELL_SIZE-1; /* no HEC */
29375@@ -580,7 +580,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29376 size);
29377 }
29378 eff = length = 0;
29379- atomic_inc(&vcc->stats->rx_err);
29380+ atomic_inc_unchecked(&vcc->stats->rx_err);
29381 }
29382 else {
29383 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
29384@@ -597,7 +597,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29385 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
29386 vcc->dev->number,vcc->vci,length,size << 2,descr);
29387 length = eff = 0;
29388- atomic_inc(&vcc->stats->rx_err);
29389+ atomic_inc_unchecked(&vcc->stats->rx_err);
29390 }
29391 }
29392 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
29393@@ -770,7 +770,7 @@ rx_dequeued++;
29394 vcc->push(vcc,skb);
29395 pushed++;
29396 }
29397- atomic_inc(&vcc->stats->rx);
29398+ atomic_inc_unchecked(&vcc->stats->rx);
29399 }
29400 wake_up(&eni_dev->rx_wait);
29401 }
29402@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
29403 PCI_DMA_TODEVICE);
29404 if (vcc->pop) vcc->pop(vcc,skb);
29405 else dev_kfree_skb_irq(skb);
29406- atomic_inc(&vcc->stats->tx);
29407+ atomic_inc_unchecked(&vcc->stats->tx);
29408 wake_up(&eni_dev->tx_wait);
29409 dma_complete++;
29410 }
29411@@ -1570,7 +1570,7 @@ tx_complete++;
29412 /*--------------------------------- entries ---------------------------------*/
29413
29414
29415-static const char *media_name[] __devinitdata = {
29416+static const char *media_name[] __devinitconst = {
29417 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
29418 "UTP", "05?", "06?", "07?", /* 4- 7 */
29419 "TAXI","09?", "10?", "11?", /* 8-11 */
29420diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
29421index cd5049a..a51209f 100644
29422--- a/drivers/atm/firestream.c
29423+++ b/drivers/atm/firestream.c
29424@@ -748,7 +748,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
29425 }
29426 }
29427
29428- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29429+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29430
29431 fs_dprintk (FS_DEBUG_TXMEM, "i");
29432 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
29433@@ -815,7 +815,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29434 #endif
29435 skb_put (skb, qe->p1 & 0xffff);
29436 ATM_SKB(skb)->vcc = atm_vcc;
29437- atomic_inc(&atm_vcc->stats->rx);
29438+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29439 __net_timestamp(skb);
29440 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
29441 atm_vcc->push (atm_vcc, skb);
29442@@ -836,12 +836,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29443 kfree (pe);
29444 }
29445 if (atm_vcc)
29446- atomic_inc(&atm_vcc->stats->rx_drop);
29447+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29448 break;
29449 case 0x1f: /* Reassembly abort: no buffers. */
29450 /* Silently increment error counter. */
29451 if (atm_vcc)
29452- atomic_inc(&atm_vcc->stats->rx_drop);
29453+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29454 break;
29455 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
29456 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
29457diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
29458index f766cc4..a34002e 100644
29459--- a/drivers/atm/fore200e.c
29460+++ b/drivers/atm/fore200e.c
29461@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
29462 #endif
29463 /* check error condition */
29464 if (*entry->status & STATUS_ERROR)
29465- atomic_inc(&vcc->stats->tx_err);
29466+ atomic_inc_unchecked(&vcc->stats->tx_err);
29467 else
29468- atomic_inc(&vcc->stats->tx);
29469+ atomic_inc_unchecked(&vcc->stats->tx);
29470 }
29471 }
29472
29473@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29474 if (skb == NULL) {
29475 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
29476
29477- atomic_inc(&vcc->stats->rx_drop);
29478+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29479 return -ENOMEM;
29480 }
29481
29482@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29483
29484 dev_kfree_skb_any(skb);
29485
29486- atomic_inc(&vcc->stats->rx_drop);
29487+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29488 return -ENOMEM;
29489 }
29490
29491 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29492
29493 vcc->push(vcc, skb);
29494- atomic_inc(&vcc->stats->rx);
29495+ atomic_inc_unchecked(&vcc->stats->rx);
29496
29497 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29498
29499@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
29500 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
29501 fore200e->atm_dev->number,
29502 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
29503- atomic_inc(&vcc->stats->rx_err);
29504+ atomic_inc_unchecked(&vcc->stats->rx_err);
29505 }
29506 }
29507
29508@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
29509 goto retry_here;
29510 }
29511
29512- atomic_inc(&vcc->stats->tx_err);
29513+ atomic_inc_unchecked(&vcc->stats->tx_err);
29514
29515 fore200e->tx_sat++;
29516 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
29517diff --git a/drivers/atm/he.c b/drivers/atm/he.c
29518index 7066703..2b130de 100644
29519--- a/drivers/atm/he.c
29520+++ b/drivers/atm/he.c
29521@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29522
29523 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
29524 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
29525- atomic_inc(&vcc->stats->rx_drop);
29526+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29527 goto return_host_buffers;
29528 }
29529
29530@@ -1802,7 +1802,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29531 RBRQ_LEN_ERR(he_dev->rbrq_head)
29532 ? "LEN_ERR" : "",
29533 vcc->vpi, vcc->vci);
29534- atomic_inc(&vcc->stats->rx_err);
29535+ atomic_inc_unchecked(&vcc->stats->rx_err);
29536 goto return_host_buffers;
29537 }
29538
29539@@ -1861,7 +1861,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29540 vcc->push(vcc, skb);
29541 spin_lock(&he_dev->global_lock);
29542
29543- atomic_inc(&vcc->stats->rx);
29544+ atomic_inc_unchecked(&vcc->stats->rx);
29545
29546 return_host_buffers:
29547 ++pdus_assembled;
29548@@ -2206,7 +2206,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
29549 tpd->vcc->pop(tpd->vcc, tpd->skb);
29550 else
29551 dev_kfree_skb_any(tpd->skb);
29552- atomic_inc(&tpd->vcc->stats->tx_err);
29553+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
29554 }
29555 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
29556 return;
29557@@ -2618,7 +2618,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29558 vcc->pop(vcc, skb);
29559 else
29560 dev_kfree_skb_any(skb);
29561- atomic_inc(&vcc->stats->tx_err);
29562+ atomic_inc_unchecked(&vcc->stats->tx_err);
29563 return -EINVAL;
29564 }
29565
29566@@ -2629,7 +2629,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29567 vcc->pop(vcc, skb);
29568 else
29569 dev_kfree_skb_any(skb);
29570- atomic_inc(&vcc->stats->tx_err);
29571+ atomic_inc_unchecked(&vcc->stats->tx_err);
29572 return -EINVAL;
29573 }
29574 #endif
29575@@ -2641,7 +2641,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29576 vcc->pop(vcc, skb);
29577 else
29578 dev_kfree_skb_any(skb);
29579- atomic_inc(&vcc->stats->tx_err);
29580+ atomic_inc_unchecked(&vcc->stats->tx_err);
29581 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29582 return -ENOMEM;
29583 }
29584@@ -2683,7 +2683,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29585 vcc->pop(vcc, skb);
29586 else
29587 dev_kfree_skb_any(skb);
29588- atomic_inc(&vcc->stats->tx_err);
29589+ atomic_inc_unchecked(&vcc->stats->tx_err);
29590 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29591 return -ENOMEM;
29592 }
29593@@ -2714,7 +2714,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
29594 __enqueue_tpd(he_dev, tpd, cid);
29595 spin_unlock_irqrestore(&he_dev->global_lock, flags);
29596
29597- atomic_inc(&vcc->stats->tx);
29598+ atomic_inc_unchecked(&vcc->stats->tx);
29599
29600 return 0;
29601 }
29602diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
29603index 4e49021..01b1512 100644
29604--- a/drivers/atm/horizon.c
29605+++ b/drivers/atm/horizon.c
29606@@ -1033,7 +1033,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
29607 {
29608 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
29609 // VC layer stats
29610- atomic_inc(&vcc->stats->rx);
29611+ atomic_inc_unchecked(&vcc->stats->rx);
29612 __net_timestamp(skb);
29613 // end of our responsability
29614 vcc->push (vcc, skb);
29615@@ -1185,7 +1185,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
29616 dev->tx_iovec = NULL;
29617
29618 // VC layer stats
29619- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29620+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29621
29622 // free the skb
29623 hrz_kfree_skb (skb);
29624diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
29625index e33ae00..9deb4ab 100644
29626--- a/drivers/atm/idt77252.c
29627+++ b/drivers/atm/idt77252.c
29628@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
29629 else
29630 dev_kfree_skb(skb);
29631
29632- atomic_inc(&vcc->stats->tx);
29633+ atomic_inc_unchecked(&vcc->stats->tx);
29634 }
29635
29636 atomic_dec(&scq->used);
29637@@ -1073,13 +1073,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29638 if ((sb = dev_alloc_skb(64)) == NULL) {
29639 printk("%s: Can't allocate buffers for aal0.\n",
29640 card->name);
29641- atomic_add(i, &vcc->stats->rx_drop);
29642+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
29643 break;
29644 }
29645 if (!atm_charge(vcc, sb->truesize)) {
29646 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
29647 card->name);
29648- atomic_add(i - 1, &vcc->stats->rx_drop);
29649+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
29650 dev_kfree_skb(sb);
29651 break;
29652 }
29653@@ -1096,7 +1096,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29654 ATM_SKB(sb)->vcc = vcc;
29655 __net_timestamp(sb);
29656 vcc->push(vcc, sb);
29657- atomic_inc(&vcc->stats->rx);
29658+ atomic_inc_unchecked(&vcc->stats->rx);
29659
29660 cell += ATM_CELL_PAYLOAD;
29661 }
29662@@ -1133,13 +1133,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29663 "(CDC: %08x)\n",
29664 card->name, len, rpp->len, readl(SAR_REG_CDC));
29665 recycle_rx_pool_skb(card, rpp);
29666- atomic_inc(&vcc->stats->rx_err);
29667+ atomic_inc_unchecked(&vcc->stats->rx_err);
29668 return;
29669 }
29670 if (stat & SAR_RSQE_CRC) {
29671 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
29672 recycle_rx_pool_skb(card, rpp);
29673- atomic_inc(&vcc->stats->rx_err);
29674+ atomic_inc_unchecked(&vcc->stats->rx_err);
29675 return;
29676 }
29677 if (skb_queue_len(&rpp->queue) > 1) {
29678@@ -1150,7 +1150,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29679 RXPRINTK("%s: Can't alloc RX skb.\n",
29680 card->name);
29681 recycle_rx_pool_skb(card, rpp);
29682- atomic_inc(&vcc->stats->rx_err);
29683+ atomic_inc_unchecked(&vcc->stats->rx_err);
29684 return;
29685 }
29686 if (!atm_charge(vcc, skb->truesize)) {
29687@@ -1169,7 +1169,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29688 __net_timestamp(skb);
29689
29690 vcc->push(vcc, skb);
29691- atomic_inc(&vcc->stats->rx);
29692+ atomic_inc_unchecked(&vcc->stats->rx);
29693
29694 return;
29695 }
29696@@ -1191,7 +1191,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
29697 __net_timestamp(skb);
29698
29699 vcc->push(vcc, skb);
29700- atomic_inc(&vcc->stats->rx);
29701+ atomic_inc_unchecked(&vcc->stats->rx);
29702
29703 if (skb->truesize > SAR_FB_SIZE_3)
29704 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
29705@@ -1303,14 +1303,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
29706 if (vcc->qos.aal != ATM_AAL0) {
29707 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
29708 card->name, vpi, vci);
29709- atomic_inc(&vcc->stats->rx_drop);
29710+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29711 goto drop;
29712 }
29713
29714 if ((sb = dev_alloc_skb(64)) == NULL) {
29715 printk("%s: Can't allocate buffers for AAL0.\n",
29716 card->name);
29717- atomic_inc(&vcc->stats->rx_err);
29718+ atomic_inc_unchecked(&vcc->stats->rx_err);
29719 goto drop;
29720 }
29721
29722@@ -1329,7 +1329,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
29723 ATM_SKB(sb)->vcc = vcc;
29724 __net_timestamp(sb);
29725 vcc->push(vcc, sb);
29726- atomic_inc(&vcc->stats->rx);
29727+ atomic_inc_unchecked(&vcc->stats->rx);
29728
29729 drop:
29730 skb_pull(queue, 64);
29731@@ -1954,13 +1954,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29732
29733 if (vc == NULL) {
29734 printk("%s: NULL connection in send().\n", card->name);
29735- atomic_inc(&vcc->stats->tx_err);
29736+ atomic_inc_unchecked(&vcc->stats->tx_err);
29737 dev_kfree_skb(skb);
29738 return -EINVAL;
29739 }
29740 if (!test_bit(VCF_TX, &vc->flags)) {
29741 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
29742- atomic_inc(&vcc->stats->tx_err);
29743+ atomic_inc_unchecked(&vcc->stats->tx_err);
29744 dev_kfree_skb(skb);
29745 return -EINVAL;
29746 }
29747@@ -1972,14 +1972,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29748 break;
29749 default:
29750 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
29751- atomic_inc(&vcc->stats->tx_err);
29752+ atomic_inc_unchecked(&vcc->stats->tx_err);
29753 dev_kfree_skb(skb);
29754 return -EINVAL;
29755 }
29756
29757 if (skb_shinfo(skb)->nr_frags != 0) {
29758 printk("%s: No scatter-gather yet.\n", card->name);
29759- atomic_inc(&vcc->stats->tx_err);
29760+ atomic_inc_unchecked(&vcc->stats->tx_err);
29761 dev_kfree_skb(skb);
29762 return -EINVAL;
29763 }
29764@@ -1987,7 +1987,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
29765
29766 err = queue_skb(card, vc, skb, oam);
29767 if (err) {
29768- atomic_inc(&vcc->stats->tx_err);
29769+ atomic_inc_unchecked(&vcc->stats->tx_err);
29770 dev_kfree_skb(skb);
29771 return err;
29772 }
29773@@ -2010,7 +2010,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
29774 skb = dev_alloc_skb(64);
29775 if (!skb) {
29776 printk("%s: Out of memory in send_oam().\n", card->name);
29777- atomic_inc(&vcc->stats->tx_err);
29778+ atomic_inc_unchecked(&vcc->stats->tx_err);
29779 return -ENOMEM;
29780 }
29781 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
29782diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
29783index b2c1b37..faa672b 100644
29784--- a/drivers/atm/iphase.c
29785+++ b/drivers/atm/iphase.c
29786@@ -1123,7 +1123,7 @@ static int rx_pkt(struct atm_dev *dev)
29787 status = (u_short) (buf_desc_ptr->desc_mode);
29788 if (status & (RX_CER | RX_PTE | RX_OFL))
29789 {
29790- atomic_inc(&vcc->stats->rx_err);
29791+ atomic_inc_unchecked(&vcc->stats->rx_err);
29792 IF_ERR(printk("IA: bad packet, dropping it");)
29793 if (status & RX_CER) {
29794 IF_ERR(printk(" cause: packet CRC error\n");)
29795@@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
29796 len = dma_addr - buf_addr;
29797 if (len > iadev->rx_buf_sz) {
29798 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
29799- atomic_inc(&vcc->stats->rx_err);
29800+ atomic_inc_unchecked(&vcc->stats->rx_err);
29801 goto out_free_desc;
29802 }
29803
29804@@ -1296,7 +1296,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29805 ia_vcc = INPH_IA_VCC(vcc);
29806 if (ia_vcc == NULL)
29807 {
29808- atomic_inc(&vcc->stats->rx_err);
29809+ atomic_inc_unchecked(&vcc->stats->rx_err);
29810 dev_kfree_skb_any(skb);
29811 atm_return(vcc, atm_guess_pdu2truesize(len));
29812 goto INCR_DLE;
29813@@ -1308,7 +1308,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29814 if ((length > iadev->rx_buf_sz) || (length >
29815 (skb->len - sizeof(struct cpcs_trailer))))
29816 {
29817- atomic_inc(&vcc->stats->rx_err);
29818+ atomic_inc_unchecked(&vcc->stats->rx_err);
29819 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
29820 length, skb->len);)
29821 dev_kfree_skb_any(skb);
29822@@ -1324,7 +1324,7 @@ static void rx_dle_intr(struct atm_dev *dev)
29823
29824 IF_RX(printk("rx_dle_intr: skb push");)
29825 vcc->push(vcc,skb);
29826- atomic_inc(&vcc->stats->rx);
29827+ atomic_inc_unchecked(&vcc->stats->rx);
29828 iadev->rx_pkt_cnt++;
29829 }
29830 INCR_DLE:
29831@@ -2806,15 +2806,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
29832 {
29833 struct k_sonet_stats *stats;
29834 stats = &PRIV(_ia_dev[board])->sonet_stats;
29835- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
29836- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
29837- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
29838- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
29839- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
29840- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
29841- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
29842- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
29843- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
29844+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
29845+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
29846+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
29847+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
29848+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
29849+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
29850+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
29851+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
29852+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
29853 }
29854 ia_cmds.status = 0;
29855 break;
29856@@ -2919,7 +2919,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29857 if ((desc == 0) || (desc > iadev->num_tx_desc))
29858 {
29859 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
29860- atomic_inc(&vcc->stats->tx);
29861+ atomic_inc_unchecked(&vcc->stats->tx);
29862 if (vcc->pop)
29863 vcc->pop(vcc, skb);
29864 else
29865@@ -3024,14 +3024,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
29866 ATM_DESC(skb) = vcc->vci;
29867 skb_queue_tail(&iadev->tx_dma_q, skb);
29868
29869- atomic_inc(&vcc->stats->tx);
29870+ atomic_inc_unchecked(&vcc->stats->tx);
29871 iadev->tx_pkt_cnt++;
29872 /* Increment transaction counter */
29873 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
29874
29875 #if 0
29876 /* add flow control logic */
29877- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
29878+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
29879 if (iavcc->vc_desc_cnt > 10) {
29880 vcc->tx_quota = vcc->tx_quota * 3 / 4;
29881 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
29882diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
29883index cf97c34..8d30655 100644
29884--- a/drivers/atm/lanai.c
29885+++ b/drivers/atm/lanai.c
29886@@ -1305,7 +1305,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
29887 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
29888 lanai_endtx(lanai, lvcc);
29889 lanai_free_skb(lvcc->tx.atmvcc, skb);
29890- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
29891+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
29892 }
29893
29894 /* Try to fill the buffer - don't call unless there is backlog */
29895@@ -1428,7 +1428,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
29896 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
29897 __net_timestamp(skb);
29898 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
29899- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
29900+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
29901 out:
29902 lvcc->rx.buf.ptr = end;
29903 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
29904@@ -1670,7 +1670,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29905 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
29906 "vcc %d\n", lanai->number, (unsigned int) s, vci);
29907 lanai->stats.service_rxnotaal5++;
29908- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29909+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29910 return 0;
29911 }
29912 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
29913@@ -1682,7 +1682,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29914 int bytes;
29915 read_unlock(&vcc_sklist_lock);
29916 DPRINTK("got trashed rx pdu on vci %d\n", vci);
29917- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29918+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29919 lvcc->stats.x.aal5.service_trash++;
29920 bytes = (SERVICE_GET_END(s) * 16) -
29921 (((unsigned long) lvcc->rx.buf.ptr) -
29922@@ -1694,7 +1694,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29923 }
29924 if (s & SERVICE_STREAM) {
29925 read_unlock(&vcc_sklist_lock);
29926- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29927+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29928 lvcc->stats.x.aal5.service_stream++;
29929 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
29930 "PDU on VCI %d!\n", lanai->number, vci);
29931@@ -1702,7 +1702,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
29932 return 0;
29933 }
29934 DPRINTK("got rx crc error on vci %d\n", vci);
29935- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
29936+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
29937 lvcc->stats.x.aal5.service_rxcrc++;
29938 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
29939 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
29940diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
29941index 3da804b..d3b0eed 100644
29942--- a/drivers/atm/nicstar.c
29943+++ b/drivers/atm/nicstar.c
29944@@ -1723,7 +1723,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29945 if ((vc = (vc_map *) vcc->dev_data) == NULL)
29946 {
29947 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n", card->index);
29948- atomic_inc(&vcc->stats->tx_err);
29949+ atomic_inc_unchecked(&vcc->stats->tx_err);
29950 dev_kfree_skb_any(skb);
29951 return -EINVAL;
29952 }
29953@@ -1731,7 +1731,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29954 if (!vc->tx)
29955 {
29956 printk("nicstar%d: Trying to transmit on a non-tx VC.\n", card->index);
29957- atomic_inc(&vcc->stats->tx_err);
29958+ atomic_inc_unchecked(&vcc->stats->tx_err);
29959 dev_kfree_skb_any(skb);
29960 return -EINVAL;
29961 }
29962@@ -1739,7 +1739,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29963 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0)
29964 {
29965 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n", card->index);
29966- atomic_inc(&vcc->stats->tx_err);
29967+ atomic_inc_unchecked(&vcc->stats->tx_err);
29968 dev_kfree_skb_any(skb);
29969 return -EINVAL;
29970 }
29971@@ -1747,7 +1747,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29972 if (skb_shinfo(skb)->nr_frags != 0)
29973 {
29974 printk("nicstar%d: No scatter-gather yet.\n", card->index);
29975- atomic_inc(&vcc->stats->tx_err);
29976+ atomic_inc_unchecked(&vcc->stats->tx_err);
29977 dev_kfree_skb_any(skb);
29978 return -EINVAL;
29979 }
29980@@ -1792,11 +1792,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
29981
29982 if (push_scqe(card, vc, scq, &scqe, skb) != 0)
29983 {
29984- atomic_inc(&vcc->stats->tx_err);
29985+ atomic_inc_unchecked(&vcc->stats->tx_err);
29986 dev_kfree_skb_any(skb);
29987 return -EIO;
29988 }
29989- atomic_inc(&vcc->stats->tx);
29990+ atomic_inc_unchecked(&vcc->stats->tx);
29991
29992 return 0;
29993 }
29994@@ -2111,14 +2111,14 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
29995 {
29996 printk("nicstar%d: Can't allocate buffers for aal0.\n",
29997 card->index);
29998- atomic_add(i,&vcc->stats->rx_drop);
29999+ atomic_add_unchecked(i,&vcc->stats->rx_drop);
30000 break;
30001 }
30002 if (!atm_charge(vcc, sb->truesize))
30003 {
30004 RXPRINTK("nicstar%d: atm_charge() dropped aal0 packets.\n",
30005 card->index);
30006- atomic_add(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
30007+ atomic_add_unchecked(i-1,&vcc->stats->rx_drop); /* already increased by 1 */
30008 dev_kfree_skb_any(sb);
30009 break;
30010 }
30011@@ -2133,7 +2133,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30012 ATM_SKB(sb)->vcc = vcc;
30013 __net_timestamp(sb);
30014 vcc->push(vcc, sb);
30015- atomic_inc(&vcc->stats->rx);
30016+ atomic_inc_unchecked(&vcc->stats->rx);
30017 cell += ATM_CELL_PAYLOAD;
30018 }
30019
30020@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30021 if (iovb == NULL)
30022 {
30023 printk("nicstar%d: Out of iovec buffers.\n", card->index);
30024- atomic_inc(&vcc->stats->rx_drop);
30025+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30026 recycle_rx_buf(card, skb);
30027 return;
30028 }
30029@@ -2182,7 +2182,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30030 else if (NS_SKB(iovb)->iovcnt >= NS_MAX_IOVECS)
30031 {
30032 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30033- atomic_inc(&vcc->stats->rx_err);
30034+ atomic_inc_unchecked(&vcc->stats->rx_err);
30035 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data, NS_MAX_IOVECS);
30036 NS_SKB(iovb)->iovcnt = 0;
30037 iovb->len = 0;
30038@@ -2202,7 +2202,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30039 printk("nicstar%d: Expected a small buffer, and this is not one.\n",
30040 card->index);
30041 which_list(card, skb);
30042- atomic_inc(&vcc->stats->rx_err);
30043+ atomic_inc_unchecked(&vcc->stats->rx_err);
30044 recycle_rx_buf(card, skb);
30045 vc->rx_iov = NULL;
30046 recycle_iov_buf(card, iovb);
30047@@ -2216,7 +2216,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30048 printk("nicstar%d: Expected a large buffer, and this is not one.\n",
30049 card->index);
30050 which_list(card, skb);
30051- atomic_inc(&vcc->stats->rx_err);
30052+ atomic_inc_unchecked(&vcc->stats->rx_err);
30053 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
30054 NS_SKB(iovb)->iovcnt);
30055 vc->rx_iov = NULL;
30056@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30057 printk(" - PDU size mismatch.\n");
30058 else
30059 printk(".\n");
30060- atomic_inc(&vcc->stats->rx_err);
30061+ atomic_inc_unchecked(&vcc->stats->rx_err);
30062 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
30063 NS_SKB(iovb)->iovcnt);
30064 vc->rx_iov = NULL;
30065@@ -2256,7 +2256,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30066 if (!atm_charge(vcc, skb->truesize))
30067 {
30068 push_rxbufs(card, skb);
30069- atomic_inc(&vcc->stats->rx_drop);
30070+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30071 }
30072 else
30073 {
30074@@ -2268,7 +2268,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30075 ATM_SKB(skb)->vcc = vcc;
30076 __net_timestamp(skb);
30077 vcc->push(vcc, skb);
30078- atomic_inc(&vcc->stats->rx);
30079+ atomic_inc_unchecked(&vcc->stats->rx);
30080 }
30081 }
30082 else if (NS_SKB(iovb)->iovcnt == 2) /* One small plus one large buffer */
30083@@ -2283,7 +2283,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30084 if (!atm_charge(vcc, sb->truesize))
30085 {
30086 push_rxbufs(card, sb);
30087- atomic_inc(&vcc->stats->rx_drop);
30088+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30089 }
30090 else
30091 {
30092@@ -2295,7 +2295,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30093 ATM_SKB(sb)->vcc = vcc;
30094 __net_timestamp(sb);
30095 vcc->push(vcc, sb);
30096- atomic_inc(&vcc->stats->rx);
30097+ atomic_inc_unchecked(&vcc->stats->rx);
30098 }
30099
30100 push_rxbufs(card, skb);
30101@@ -2306,7 +2306,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30102 if (!atm_charge(vcc, skb->truesize))
30103 {
30104 push_rxbufs(card, skb);
30105- atomic_inc(&vcc->stats->rx_drop);
30106+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30107 }
30108 else
30109 {
30110@@ -2320,7 +2320,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30111 ATM_SKB(skb)->vcc = vcc;
30112 __net_timestamp(skb);
30113 vcc->push(vcc, skb);
30114- atomic_inc(&vcc->stats->rx);
30115+ atomic_inc_unchecked(&vcc->stats->rx);
30116 }
30117
30118 push_rxbufs(card, sb);
30119@@ -2342,7 +2342,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30120 if (hb == NULL)
30121 {
30122 printk("nicstar%d: Out of huge buffers.\n", card->index);
30123- atomic_inc(&vcc->stats->rx_drop);
30124+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30125 recycle_iovec_rx_bufs(card, (struct iovec *) iovb->data,
30126 NS_SKB(iovb)->iovcnt);
30127 vc->rx_iov = NULL;
30128@@ -2393,7 +2393,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30129 }
30130 else
30131 dev_kfree_skb_any(hb);
30132- atomic_inc(&vcc->stats->rx_drop);
30133+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30134 }
30135 else
30136 {
30137@@ -2427,7 +2427,7 @@ static void dequeue_rx(ns_dev *card, ns_rsqe *rsqe)
30138 #endif /* NS_USE_DESTRUCTORS */
30139 __net_timestamp(hb);
30140 vcc->push(vcc, hb);
30141- atomic_inc(&vcc->stats->rx);
30142+ atomic_inc_unchecked(&vcc->stats->rx);
30143 }
30144 }
30145
30146diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30147index 84c93ff..e6ed269 100644
30148--- a/drivers/atm/solos-pci.c
30149+++ b/drivers/atm/solos-pci.c
30150@@ -708,7 +708,7 @@ void solos_bh(unsigned long card_arg)
30151 }
30152 atm_charge(vcc, skb->truesize);
30153 vcc->push(vcc, skb);
30154- atomic_inc(&vcc->stats->rx);
30155+ atomic_inc_unchecked(&vcc->stats->rx);
30156 break;
30157
30158 case PKT_STATUS:
30159@@ -914,6 +914,8 @@ static int print_buffer(struct sk_buff *buf)
30160 char msg[500];
30161 char item[10];
30162
30163+ pax_track_stack();
30164+
30165 len = buf->len;
30166 for (i = 0; i < len; i++){
30167 if(i % 8 == 0)
30168@@ -1023,7 +1025,7 @@ static uint32_t fpga_tx(struct solos_card *card)
30169 vcc = SKB_CB(oldskb)->vcc;
30170
30171 if (vcc) {
30172- atomic_inc(&vcc->stats->tx);
30173+ atomic_inc_unchecked(&vcc->stats->tx);
30174 solos_pop(vcc, oldskb);
30175 } else
30176 dev_kfree_skb_irq(oldskb);
30177diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
30178index 6dd3f59..ee377f3 100644
30179--- a/drivers/atm/suni.c
30180+++ b/drivers/atm/suni.c
30181@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
30182
30183
30184 #define ADD_LIMITED(s,v) \
30185- atomic_add((v),&stats->s); \
30186- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
30187+ atomic_add_unchecked((v),&stats->s); \
30188+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
30189
30190
30191 static void suni_hz(unsigned long from_timer)
30192diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
30193index fc8cb07..4a80e53 100644
30194--- a/drivers/atm/uPD98402.c
30195+++ b/drivers/atm/uPD98402.c
30196@@ -41,7 +41,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
30197 struct sonet_stats tmp;
30198 int error = 0;
30199
30200- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30201+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30202 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
30203 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
30204 if (zero && !error) {
30205@@ -160,9 +160,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
30206
30207
30208 #define ADD_LIMITED(s,v) \
30209- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
30210- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
30211- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30212+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
30213+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
30214+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30215
30216
30217 static void stat_event(struct atm_dev *dev)
30218@@ -193,7 +193,7 @@ static void uPD98402_int(struct atm_dev *dev)
30219 if (reason & uPD98402_INT_PFM) stat_event(dev);
30220 if (reason & uPD98402_INT_PCO) {
30221 (void) GET(PCOCR); /* clear interrupt cause */
30222- atomic_add(GET(HECCT),
30223+ atomic_add_unchecked(GET(HECCT),
30224 &PRIV(dev)->sonet_stats.uncorr_hcs);
30225 }
30226 if ((reason & uPD98402_INT_RFO) &&
30227@@ -221,9 +221,9 @@ static int uPD98402_start(struct atm_dev *dev)
30228 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
30229 uPD98402_INT_LOS),PIMR); /* enable them */
30230 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
30231- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30232- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
30233- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
30234+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30235+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
30236+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
30237 return 0;
30238 }
30239
30240diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
30241index 2e9635b..32927b4 100644
30242--- a/drivers/atm/zatm.c
30243+++ b/drivers/atm/zatm.c
30244@@ -458,7 +458,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30245 }
30246 if (!size) {
30247 dev_kfree_skb_irq(skb);
30248- if (vcc) atomic_inc(&vcc->stats->rx_err);
30249+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
30250 continue;
30251 }
30252 if (!atm_charge(vcc,skb->truesize)) {
30253@@ -468,7 +468,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30254 skb->len = size;
30255 ATM_SKB(skb)->vcc = vcc;
30256 vcc->push(vcc,skb);
30257- atomic_inc(&vcc->stats->rx);
30258+ atomic_inc_unchecked(&vcc->stats->rx);
30259 }
30260 zout(pos & 0xffff,MTA(mbx));
30261 #if 0 /* probably a stupid idea */
30262@@ -732,7 +732,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
30263 skb_queue_head(&zatm_vcc->backlog,skb);
30264 break;
30265 }
30266- atomic_inc(&vcc->stats->tx);
30267+ atomic_inc_unchecked(&vcc->stats->tx);
30268 wake_up(&zatm_vcc->tx_wait);
30269 }
30270
30271diff --git a/drivers/base/bus.c b/drivers/base/bus.c
30272index 63c143e..fece183 100644
30273--- a/drivers/base/bus.c
30274+++ b/drivers/base/bus.c
30275@@ -70,7 +70,7 @@ static ssize_t drv_attr_store(struct kobject *kobj, struct attribute *attr,
30276 return ret;
30277 }
30278
30279-static struct sysfs_ops driver_sysfs_ops = {
30280+static const struct sysfs_ops driver_sysfs_ops = {
30281 .show = drv_attr_show,
30282 .store = drv_attr_store,
30283 };
30284@@ -115,7 +115,7 @@ static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr,
30285 return ret;
30286 }
30287
30288-static struct sysfs_ops bus_sysfs_ops = {
30289+static const struct sysfs_ops bus_sysfs_ops = {
30290 .show = bus_attr_show,
30291 .store = bus_attr_store,
30292 };
30293@@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
30294 return 0;
30295 }
30296
30297-static struct kset_uevent_ops bus_uevent_ops = {
30298+static const struct kset_uevent_ops bus_uevent_ops = {
30299 .filter = bus_uevent_filter,
30300 };
30301
30302diff --git a/drivers/base/class.c b/drivers/base/class.c
30303index 6e2c3b0..cb61871 100644
30304--- a/drivers/base/class.c
30305+++ b/drivers/base/class.c
30306@@ -63,7 +63,7 @@ static void class_release(struct kobject *kobj)
30307 kfree(cp);
30308 }
30309
30310-static struct sysfs_ops class_sysfs_ops = {
30311+static const struct sysfs_ops class_sysfs_ops = {
30312 .show = class_attr_show,
30313 .store = class_attr_store,
30314 };
30315diff --git a/drivers/base/core.c b/drivers/base/core.c
30316index f33d768..a9358d0 100644
30317--- a/drivers/base/core.c
30318+++ b/drivers/base/core.c
30319@@ -100,7 +100,7 @@ static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
30320 return ret;
30321 }
30322
30323-static struct sysfs_ops dev_sysfs_ops = {
30324+static const struct sysfs_ops dev_sysfs_ops = {
30325 .show = dev_attr_show,
30326 .store = dev_attr_store,
30327 };
30328@@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
30329 return retval;
30330 }
30331
30332-static struct kset_uevent_ops device_uevent_ops = {
30333+static const struct kset_uevent_ops device_uevent_ops = {
30334 .filter = dev_uevent_filter,
30335 .name = dev_uevent_name,
30336 .uevent = dev_uevent,
30337diff --git a/drivers/base/memory.c b/drivers/base/memory.c
30338index 989429c..2272b00 100644
30339--- a/drivers/base/memory.c
30340+++ b/drivers/base/memory.c
30341@@ -44,7 +44,7 @@ static int memory_uevent(struct kset *kset, struct kobject *obj, struct kobj_uev
30342 return retval;
30343 }
30344
30345-static struct kset_uevent_ops memory_uevent_ops = {
30346+static const struct kset_uevent_ops memory_uevent_ops = {
30347 .name = memory_uevent_name,
30348 .uevent = memory_uevent,
30349 };
30350diff --git a/drivers/base/sys.c b/drivers/base/sys.c
30351index 3f202f7..61c4a6f 100644
30352--- a/drivers/base/sys.c
30353+++ b/drivers/base/sys.c
30354@@ -54,7 +54,7 @@ sysdev_store(struct kobject *kobj, struct attribute *attr,
30355 return -EIO;
30356 }
30357
30358-static struct sysfs_ops sysfs_ops = {
30359+static const struct sysfs_ops sysfs_ops = {
30360 .show = sysdev_show,
30361 .store = sysdev_store,
30362 };
30363@@ -104,7 +104,7 @@ static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr,
30364 return -EIO;
30365 }
30366
30367-static struct sysfs_ops sysfs_class_ops = {
30368+static const struct sysfs_ops sysfs_class_ops = {
30369 .show = sysdev_class_show,
30370 .store = sysdev_class_store,
30371 };
30372diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
30373index eb4fa19..1954777 100644
30374--- a/drivers/block/DAC960.c
30375+++ b/drivers/block/DAC960.c
30376@@ -1973,6 +1973,8 @@ static bool DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
30377 unsigned long flags;
30378 int Channel, TargetID;
30379
30380+ pax_track_stack();
30381+
30382 if (!init_dma_loaf(Controller->PCIDevice, &local_dma,
30383 DAC960_V1_MaxChannels*(sizeof(DAC960_V1_DCDB_T) +
30384 sizeof(DAC960_SCSI_Inquiry_T) +
30385diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
30386index ca9c548..ca6899c 100644
30387--- a/drivers/block/cciss.c
30388+++ b/drivers/block/cciss.c
30389@@ -1011,6 +1011,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
30390 int err;
30391 u32 cp;
30392
30393+ memset(&arg64, 0, sizeof(arg64));
30394+
30395 err = 0;
30396 err |=
30397 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
30398@@ -2852,7 +2854,7 @@ static unsigned long pollcomplete(int ctlr)
30399 /* Wait (up to 20 seconds) for a command to complete */
30400
30401 for (i = 20 * HZ; i > 0; i--) {
30402- done = hba[ctlr]->access.command_completed(hba[ctlr]);
30403+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
30404 if (done == FIFO_EMPTY)
30405 schedule_timeout_uninterruptible(1);
30406 else
30407@@ -2876,7 +2878,7 @@ static int sendcmd_core(ctlr_info_t *h, CommandList_struct *c)
30408 resend_cmd1:
30409
30410 /* Disable interrupt on the board. */
30411- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30412+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30413
30414 /* Make sure there is room in the command FIFO */
30415 /* Actually it should be completely empty at this time */
30416@@ -2884,13 +2886,13 @@ resend_cmd1:
30417 /* tape side of the driver. */
30418 for (i = 200000; i > 0; i--) {
30419 /* if fifo isn't full go */
30420- if (!(h->access.fifo_full(h)))
30421+ if (!(h->access->fifo_full(h)))
30422 break;
30423 udelay(10);
30424 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
30425 " waiting!\n", h->ctlr);
30426 }
30427- h->access.submit_command(h, c); /* Send the cmd */
30428+ h->access->submit_command(h, c); /* Send the cmd */
30429 do {
30430 complete = pollcomplete(h->ctlr);
30431
30432@@ -3023,7 +3025,7 @@ static void start_io(ctlr_info_t *h)
30433 while (!hlist_empty(&h->reqQ)) {
30434 c = hlist_entry(h->reqQ.first, CommandList_struct, list);
30435 /* can't do anything if fifo is full */
30436- if ((h->access.fifo_full(h))) {
30437+ if ((h->access->fifo_full(h))) {
30438 printk(KERN_WARNING "cciss: fifo full\n");
30439 break;
30440 }
30441@@ -3033,7 +3035,7 @@ static void start_io(ctlr_info_t *h)
30442 h->Qdepth--;
30443
30444 /* Tell the controller execute command */
30445- h->access.submit_command(h, c);
30446+ h->access->submit_command(h, c);
30447
30448 /* Put job onto the completed Q */
30449 addQ(&h->cmpQ, c);
30450@@ -3393,17 +3395,17 @@ startio:
30451
30452 static inline unsigned long get_next_completion(ctlr_info_t *h)
30453 {
30454- return h->access.command_completed(h);
30455+ return h->access->command_completed(h);
30456 }
30457
30458 static inline int interrupt_pending(ctlr_info_t *h)
30459 {
30460- return h->access.intr_pending(h);
30461+ return h->access->intr_pending(h);
30462 }
30463
30464 static inline long interrupt_not_for_us(ctlr_info_t *h)
30465 {
30466- return (((h->access.intr_pending(h) == 0) ||
30467+ return (((h->access->intr_pending(h) == 0) ||
30468 (h->interrupts_enabled == 0)));
30469 }
30470
30471@@ -3892,7 +3894,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
30472 */
30473 c->max_commands = readl(&(c->cfgtable->CmdsOutMax));
30474 c->product_name = products[prod_index].product_name;
30475- c->access = *(products[prod_index].access);
30476+ c->access = products[prod_index].access;
30477 c->nr_cmds = c->max_commands - 4;
30478 if ((readb(&c->cfgtable->Signature[0]) != 'C') ||
30479 (readb(&c->cfgtable->Signature[1]) != 'I') ||
30480@@ -4291,7 +4293,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
30481 }
30482
30483 /* make sure the board interrupts are off */
30484- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
30485+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_OFF);
30486 if (request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
30487 IRQF_DISABLED | IRQF_SHARED, hba[i]->devname, hba[i])) {
30488 printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
30489@@ -4341,7 +4343,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
30490 cciss_scsi_setup(i);
30491
30492 /* Turn the interrupts on so we can service requests */
30493- hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_ON);
30494+ hba[i]->access->set_intr_mask(hba[i], CCISS_INTR_ON);
30495
30496 /* Get the firmware version */
30497 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
30498diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
30499index 04d6bf8..36e712d 100644
30500--- a/drivers/block/cciss.h
30501+++ b/drivers/block/cciss.h
30502@@ -90,7 +90,7 @@ struct ctlr_info
30503 // information about each logical volume
30504 drive_info_struct *drv[CISS_MAX_LUN];
30505
30506- struct access_method access;
30507+ struct access_method *access;
30508
30509 /* queue and queue Info */
30510 struct hlist_head reqQ;
30511diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
30512index 6422651..bb1bdef 100644
30513--- a/drivers/block/cpqarray.c
30514+++ b/drivers/block/cpqarray.c
30515@@ -402,7 +402,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30516 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
30517 goto Enomem4;
30518 }
30519- hba[i]->access.set_intr_mask(hba[i], 0);
30520+ hba[i]->access->set_intr_mask(hba[i], 0);
30521 if (request_irq(hba[i]->intr, do_ida_intr,
30522 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
30523 {
30524@@ -460,7 +460,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30525 add_timer(&hba[i]->timer);
30526
30527 /* Enable IRQ now that spinlock and rate limit timer are set up */
30528- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30529+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30530
30531 for(j=0; j<NWD; j++) {
30532 struct gendisk *disk = ida_gendisk[i][j];
30533@@ -695,7 +695,7 @@ DBGINFO(
30534 for(i=0; i<NR_PRODUCTS; i++) {
30535 if (board_id == products[i].board_id) {
30536 c->product_name = products[i].product_name;
30537- c->access = *(products[i].access);
30538+ c->access = products[i].access;
30539 break;
30540 }
30541 }
30542@@ -793,7 +793,7 @@ static int __init cpqarray_eisa_detect(void)
30543 hba[ctlr]->intr = intr;
30544 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
30545 hba[ctlr]->product_name = products[j].product_name;
30546- hba[ctlr]->access = *(products[j].access);
30547+ hba[ctlr]->access = products[j].access;
30548 hba[ctlr]->ctlr = ctlr;
30549 hba[ctlr]->board_id = board_id;
30550 hba[ctlr]->pci_dev = NULL; /* not PCI */
30551@@ -896,6 +896,8 @@ static void do_ida_request(struct request_queue *q)
30552 struct scatterlist tmp_sg[SG_MAX];
30553 int i, dir, seg;
30554
30555+ pax_track_stack();
30556+
30557 if (blk_queue_plugged(q))
30558 goto startio;
30559
30560@@ -968,7 +970,7 @@ static void start_io(ctlr_info_t *h)
30561
30562 while((c = h->reqQ) != NULL) {
30563 /* Can't do anything if we're busy */
30564- if (h->access.fifo_full(h) == 0)
30565+ if (h->access->fifo_full(h) == 0)
30566 return;
30567
30568 /* Get the first entry from the request Q */
30569@@ -976,7 +978,7 @@ static void start_io(ctlr_info_t *h)
30570 h->Qdepth--;
30571
30572 /* Tell the controller to do our bidding */
30573- h->access.submit_command(h, c);
30574+ h->access->submit_command(h, c);
30575
30576 /* Get onto the completion Q */
30577 addQ(&h->cmpQ, c);
30578@@ -1038,7 +1040,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30579 unsigned long flags;
30580 __u32 a,a1;
30581
30582- istat = h->access.intr_pending(h);
30583+ istat = h->access->intr_pending(h);
30584 /* Is this interrupt for us? */
30585 if (istat == 0)
30586 return IRQ_NONE;
30587@@ -1049,7 +1051,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30588 */
30589 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
30590 if (istat & FIFO_NOT_EMPTY) {
30591- while((a = h->access.command_completed(h))) {
30592+ while((a = h->access->command_completed(h))) {
30593 a1 = a; a &= ~3;
30594 if ((c = h->cmpQ) == NULL)
30595 {
30596@@ -1434,11 +1436,11 @@ static int sendcmd(
30597 /*
30598 * Disable interrupt
30599 */
30600- info_p->access.set_intr_mask(info_p, 0);
30601+ info_p->access->set_intr_mask(info_p, 0);
30602 /* Make sure there is room in the command FIFO */
30603 /* Actually it should be completely empty at this time. */
30604 for (i = 200000; i > 0; i--) {
30605- temp = info_p->access.fifo_full(info_p);
30606+ temp = info_p->access->fifo_full(info_p);
30607 if (temp != 0) {
30608 break;
30609 }
30610@@ -1451,7 +1453,7 @@ DBG(
30611 /*
30612 * Send the cmd
30613 */
30614- info_p->access.submit_command(info_p, c);
30615+ info_p->access->submit_command(info_p, c);
30616 complete = pollcomplete(ctlr);
30617
30618 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
30619@@ -1534,9 +1536,9 @@ static int revalidate_allvol(ctlr_info_t *host)
30620 * we check the new geometry. Then turn interrupts back on when
30621 * we're done.
30622 */
30623- host->access.set_intr_mask(host, 0);
30624+ host->access->set_intr_mask(host, 0);
30625 getgeometry(ctlr);
30626- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
30627+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
30628
30629 for(i=0; i<NWD; i++) {
30630 struct gendisk *disk = ida_gendisk[ctlr][i];
30631@@ -1576,7 +1578,7 @@ static int pollcomplete(int ctlr)
30632 /* Wait (up to 2 seconds) for a command to complete */
30633
30634 for (i = 200000; i > 0; i--) {
30635- done = hba[ctlr]->access.command_completed(hba[ctlr]);
30636+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
30637 if (done == 0) {
30638 udelay(10); /* a short fixed delay */
30639 } else
30640diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
30641index be73e9d..7fbf140 100644
30642--- a/drivers/block/cpqarray.h
30643+++ b/drivers/block/cpqarray.h
30644@@ -99,7 +99,7 @@ struct ctlr_info {
30645 drv_info_t drv[NWD];
30646 struct proc_dir_entry *proc;
30647
30648- struct access_method access;
30649+ struct access_method *access;
30650
30651 cmdlist_t *reqQ;
30652 cmdlist_t *cmpQ;
30653diff --git a/drivers/block/loop.c b/drivers/block/loop.c
30654index 8ec2d70..2804b30 100644
30655--- a/drivers/block/loop.c
30656+++ b/drivers/block/loop.c
30657@@ -282,7 +282,7 @@ static int __do_lo_send_write(struct file *file,
30658 mm_segment_t old_fs = get_fs();
30659
30660 set_fs(get_ds());
30661- bw = file->f_op->write(file, buf, len, &pos);
30662+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
30663 set_fs(old_fs);
30664 if (likely(bw == len))
30665 return 0;
30666diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
30667index 26ada47..083c480 100644
30668--- a/drivers/block/nbd.c
30669+++ b/drivers/block/nbd.c
30670@@ -155,6 +155,8 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size,
30671 struct kvec iov;
30672 sigset_t blocked, oldset;
30673
30674+ pax_track_stack();
30675+
30676 if (unlikely(!sock)) {
30677 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
30678 lo->disk->disk_name, (send ? "send" : "recv"));
30679@@ -569,6 +571,8 @@ static void do_nbd_request(struct request_queue *q)
30680 static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
30681 unsigned int cmd, unsigned long arg)
30682 {
30683+ pax_track_stack();
30684+
30685 switch (cmd) {
30686 case NBD_DISCONNECT: {
30687 struct request sreq;
30688diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
30689index a5d585d..d087be3 100644
30690--- a/drivers/block/pktcdvd.c
30691+++ b/drivers/block/pktcdvd.c
30692@@ -284,7 +284,7 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
30693 return len;
30694 }
30695
30696-static struct sysfs_ops kobj_pkt_ops = {
30697+static const struct sysfs_ops kobj_pkt_ops = {
30698 .show = kobj_pkt_show,
30699 .store = kobj_pkt_store
30700 };
30701diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
30702index 6aad99e..89cd142 100644
30703--- a/drivers/char/Kconfig
30704+++ b/drivers/char/Kconfig
30705@@ -90,7 +90,8 @@ config VT_HW_CONSOLE_BINDING
30706
30707 config DEVKMEM
30708 bool "/dev/kmem virtual device support"
30709- default y
30710+ default n
30711+ depends on !GRKERNSEC_KMEM
30712 help
30713 Say Y here if you want to support the /dev/kmem device. The
30714 /dev/kmem device is rarely used, but can be used for certain
30715@@ -1114,6 +1115,7 @@ config DEVPORT
30716 bool
30717 depends on !M68K
30718 depends on ISA || PCI
30719+ depends on !GRKERNSEC_KMEM
30720 default y
30721
30722 source "drivers/s390/char/Kconfig"
30723diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
30724index a96f319..a778a5b 100644
30725--- a/drivers/char/agp/frontend.c
30726+++ b/drivers/char/agp/frontend.c
30727@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
30728 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
30729 return -EFAULT;
30730
30731- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
30732+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
30733 return -EFAULT;
30734
30735 client = agp_find_client_by_pid(reserve.pid);
30736diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
30737index d8cff90..9628e70 100644
30738--- a/drivers/char/briq_panel.c
30739+++ b/drivers/char/briq_panel.c
30740@@ -10,6 +10,7 @@
30741 #include <linux/types.h>
30742 #include <linux/errno.h>
30743 #include <linux/tty.h>
30744+#include <linux/mutex.h>
30745 #include <linux/timer.h>
30746 #include <linux/kernel.h>
30747 #include <linux/wait.h>
30748@@ -36,6 +37,7 @@ static int vfd_is_open;
30749 static unsigned char vfd[40];
30750 static int vfd_cursor;
30751 static unsigned char ledpb, led;
30752+static DEFINE_MUTEX(vfd_mutex);
30753
30754 static void update_vfd(void)
30755 {
30756@@ -142,12 +144,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
30757 if (!vfd_is_open)
30758 return -EBUSY;
30759
30760+ mutex_lock(&vfd_mutex);
30761 for (;;) {
30762 char c;
30763 if (!indx)
30764 break;
30765- if (get_user(c, buf))
30766+ if (get_user(c, buf)) {
30767+ mutex_unlock(&vfd_mutex);
30768 return -EFAULT;
30769+ }
30770 if (esc) {
30771 set_led(c);
30772 esc = 0;
30773@@ -177,6 +182,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
30774 buf++;
30775 }
30776 update_vfd();
30777+ mutex_unlock(&vfd_mutex);
30778
30779 return len;
30780 }
30781diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
30782index 31e7c91..161afc0 100644
30783--- a/drivers/char/genrtc.c
30784+++ b/drivers/char/genrtc.c
30785@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct inode *inode, struct file *file,
30786 switch (cmd) {
30787
30788 case RTC_PLL_GET:
30789+ memset(&pll, 0, sizeof(pll));
30790 if (get_rtc_pll(&pll))
30791 return -EINVAL;
30792 else
30793diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
30794index 006466d..a2bb21c 100644
30795--- a/drivers/char/hpet.c
30796+++ b/drivers/char/hpet.c
30797@@ -430,7 +430,7 @@ static int hpet_release(struct inode *inode, struct file *file)
30798 return 0;
30799 }
30800
30801-static int hpet_ioctl_common(struct hpet_dev *, int, unsigned long, int);
30802+static int hpet_ioctl_common(struct hpet_dev *, unsigned int, unsigned long, int);
30803
30804 static int
30805 hpet_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
30806@@ -565,7 +565,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
30807 }
30808
30809 static int
30810-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
30811+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg, int kernel)
30812 {
30813 struct hpet_timer __iomem *timer;
30814 struct hpet __iomem *hpet;
30815@@ -608,11 +608,11 @@ hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg, int kernel)
30816 {
30817 struct hpet_info info;
30818
30819+ memset(&info, 0, sizeof(info));
30820+
30821 if (devp->hd_ireqfreq)
30822 info.hi_ireqfreq =
30823 hpet_time_div(hpetp, devp->hd_ireqfreq);
30824- else
30825- info.hi_ireqfreq = 0;
30826 info.hi_flags =
30827 readq(&timer->hpet_config) & Tn_PER_INT_CAP_MASK;
30828 info.hi_hpet = hpetp->hp_which;
30829diff --git a/drivers/char/hvc_beat.c b/drivers/char/hvc_beat.c
30830index 0afc8b8..6913fc3 100644
30831--- a/drivers/char/hvc_beat.c
30832+++ b/drivers/char/hvc_beat.c
30833@@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t vtermno, const char *buf, int cnt)
30834 return cnt;
30835 }
30836
30837-static struct hv_ops hvc_beat_get_put_ops = {
30838+static const struct hv_ops hvc_beat_get_put_ops = {
30839 .get_chars = hvc_beat_get_chars,
30840 .put_chars = hvc_beat_put_chars,
30841 };
30842diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
30843index 98097f2..407dddc 100644
30844--- a/drivers/char/hvc_console.c
30845+++ b/drivers/char/hvc_console.c
30846@@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_index(int index)
30847 * console interfaces but can still be used as a tty device. This has to be
30848 * static because kmalloc will not work during early console init.
30849 */
30850-static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
30851+static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES];
30852 static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
30853 {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1};
30854
30855@@ -249,7 +249,7 @@ static void destroy_hvc_struct(struct kref *kref)
30856 * vty adapters do NOT get an hvc_instantiate() callback since they
30857 * appear after early console init.
30858 */
30859-int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
30860+int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
30861 {
30862 struct hvc_struct *hp;
30863
30864@@ -758,7 +758,7 @@ static const struct tty_operations hvc_ops = {
30865 };
30866
30867 struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data,
30868- struct hv_ops *ops, int outbuf_size)
30869+ const struct hv_ops *ops, int outbuf_size)
30870 {
30871 struct hvc_struct *hp;
30872 int i;
30873diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h
30874index 10950ca..ed176c3 100644
30875--- a/drivers/char/hvc_console.h
30876+++ b/drivers/char/hvc_console.h
30877@@ -55,7 +55,7 @@ struct hvc_struct {
30878 int outbuf_size;
30879 int n_outbuf;
30880 uint32_t vtermno;
30881- struct hv_ops *ops;
30882+ const struct hv_ops *ops;
30883 int irq_requested;
30884 int data;
30885 struct winsize ws;
30886@@ -76,11 +76,11 @@ struct hv_ops {
30887 };
30888
30889 /* Register a vterm and a slot index for use as a console (console_init) */
30890-extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops);
30891+extern int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops);
30892
30893 /* register a vterm for hvc tty operation (module_init or hotplug add) */
30894 extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data,
30895- struct hv_ops *ops, int outbuf_size);
30896+ const struct hv_ops *ops, int outbuf_size);
30897 /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */
30898 extern int hvc_remove(struct hvc_struct *hp);
30899
30900diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
30901index 936d05b..fd02426 100644
30902--- a/drivers/char/hvc_iseries.c
30903+++ b/drivers/char/hvc_iseries.c
30904@@ -197,7 +197,7 @@ done:
30905 return sent;
30906 }
30907
30908-static struct hv_ops hvc_get_put_ops = {
30909+static const struct hv_ops hvc_get_put_ops = {
30910 .get_chars = get_chars,
30911 .put_chars = put_chars,
30912 .notifier_add = notifier_add_irq,
30913diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
30914index b0e168f..69cda2a 100644
30915--- a/drivers/char/hvc_iucv.c
30916+++ b/drivers/char/hvc_iucv.c
30917@@ -924,7 +924,7 @@ static int hvc_iucv_pm_restore_thaw(struct device *dev)
30918
30919
30920 /* HVC operations */
30921-static struct hv_ops hvc_iucv_ops = {
30922+static const struct hv_ops hvc_iucv_ops = {
30923 .get_chars = hvc_iucv_get_chars,
30924 .put_chars = hvc_iucv_put_chars,
30925 .notifier_add = hvc_iucv_notifier_add,
30926diff --git a/drivers/char/hvc_rtas.c b/drivers/char/hvc_rtas.c
30927index 88590d0..61c4a61 100644
30928--- a/drivers/char/hvc_rtas.c
30929+++ b/drivers/char/hvc_rtas.c
30930@@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count)
30931 return i;
30932 }
30933
30934-static struct hv_ops hvc_rtas_get_put_ops = {
30935+static const struct hv_ops hvc_rtas_get_put_ops = {
30936 .get_chars = hvc_rtas_read_console,
30937 .put_chars = hvc_rtas_write_console,
30938 };
30939diff --git a/drivers/char/hvc_udbg.c b/drivers/char/hvc_udbg.c
30940index bd63ba8..b0957e6 100644
30941--- a/drivers/char/hvc_udbg.c
30942+++ b/drivers/char/hvc_udbg.c
30943@@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno, char *buf, int count)
30944 return i;
30945 }
30946
30947-static struct hv_ops hvc_udbg_ops = {
30948+static const struct hv_ops hvc_udbg_ops = {
30949 .get_chars = hvc_udbg_get,
30950 .put_chars = hvc_udbg_put,
30951 };
30952diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
30953index 10be343..27370e9 100644
30954--- a/drivers/char/hvc_vio.c
30955+++ b/drivers/char/hvc_vio.c
30956@@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
30957 return got;
30958 }
30959
30960-static struct hv_ops hvc_get_put_ops = {
30961+static const struct hv_ops hvc_get_put_ops = {
30962 .get_chars = filtered_get_chars,
30963 .put_chars = hvc_put_chars,
30964 .notifier_add = notifier_add_irq,
30965diff --git a/drivers/char/hvc_xen.c b/drivers/char/hvc_xen.c
30966index a6ee32b..94f8c26 100644
30967--- a/drivers/char/hvc_xen.c
30968+++ b/drivers/char/hvc_xen.c
30969@@ -120,7 +120,7 @@ static int read_console(uint32_t vtermno, char *buf, int len)
30970 return recv;
30971 }
30972
30973-static struct hv_ops hvc_ops = {
30974+static const struct hv_ops hvc_ops = {
30975 .get_chars = read_console,
30976 .put_chars = write_console,
30977 .notifier_add = notifier_add_irq,
30978diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
30979index 266b858..f3ee0bb 100644
30980--- a/drivers/char/hvcs.c
30981+++ b/drivers/char/hvcs.c
30982@@ -82,6 +82,7 @@
30983 #include <asm/hvcserver.h>
30984 #include <asm/uaccess.h>
30985 #include <asm/vio.h>
30986+#include <asm/local.h>
30987
30988 /*
30989 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
30990@@ -269,7 +270,7 @@ struct hvcs_struct {
30991 unsigned int index;
30992
30993 struct tty_struct *tty;
30994- int open_count;
30995+ local_t open_count;
30996
30997 /*
30998 * Used to tell the driver kernel_thread what operations need to take
30999@@ -419,7 +420,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
31000
31001 spin_lock_irqsave(&hvcsd->lock, flags);
31002
31003- if (hvcsd->open_count > 0) {
31004+ if (local_read(&hvcsd->open_count) > 0) {
31005 spin_unlock_irqrestore(&hvcsd->lock, flags);
31006 printk(KERN_INFO "HVCS: vterm state unchanged. "
31007 "The hvcs device node is still in use.\n");
31008@@ -1135,7 +1136,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
31009 if ((retval = hvcs_partner_connect(hvcsd)))
31010 goto error_release;
31011
31012- hvcsd->open_count = 1;
31013+ local_set(&hvcsd->open_count, 1);
31014 hvcsd->tty = tty;
31015 tty->driver_data = hvcsd;
31016
31017@@ -1169,7 +1170,7 @@ fast_open:
31018
31019 spin_lock_irqsave(&hvcsd->lock, flags);
31020 kref_get(&hvcsd->kref);
31021- hvcsd->open_count++;
31022+ local_inc(&hvcsd->open_count);
31023 hvcsd->todo_mask |= HVCS_SCHED_READ;
31024 spin_unlock_irqrestore(&hvcsd->lock, flags);
31025
31026@@ -1213,7 +1214,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
31027 hvcsd = tty->driver_data;
31028
31029 spin_lock_irqsave(&hvcsd->lock, flags);
31030- if (--hvcsd->open_count == 0) {
31031+ if (local_dec_and_test(&hvcsd->open_count)) {
31032
31033 vio_disable_interrupts(hvcsd->vdev);
31034
31035@@ -1239,10 +1240,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
31036 free_irq(irq, hvcsd);
31037 kref_put(&hvcsd->kref, destroy_hvcs_struct);
31038 return;
31039- } else if (hvcsd->open_count < 0) {
31040+ } else if (local_read(&hvcsd->open_count) < 0) {
31041 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
31042 " is missmanaged.\n",
31043- hvcsd->vdev->unit_address, hvcsd->open_count);
31044+ hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
31045 }
31046
31047 spin_unlock_irqrestore(&hvcsd->lock, flags);
31048@@ -1258,7 +1259,7 @@ static void hvcs_hangup(struct tty_struct * tty)
31049
31050 spin_lock_irqsave(&hvcsd->lock, flags);
31051 /* Preserve this so that we know how many kref refs to put */
31052- temp_open_count = hvcsd->open_count;
31053+ temp_open_count = local_read(&hvcsd->open_count);
31054
31055 /*
31056 * Don't kref put inside the spinlock because the destruction
31057@@ -1273,7 +1274,7 @@ static void hvcs_hangup(struct tty_struct * tty)
31058 hvcsd->tty->driver_data = NULL;
31059 hvcsd->tty = NULL;
31060
31061- hvcsd->open_count = 0;
31062+ local_set(&hvcsd->open_count, 0);
31063
31064 /* This will drop any buffered data on the floor which is OK in a hangup
31065 * scenario. */
31066@@ -1344,7 +1345,7 @@ static int hvcs_write(struct tty_struct *tty,
31067 * the middle of a write operation? This is a crummy place to do this
31068 * but we want to keep it all in the spinlock.
31069 */
31070- if (hvcsd->open_count <= 0) {
31071+ if (local_read(&hvcsd->open_count) <= 0) {
31072 spin_unlock_irqrestore(&hvcsd->lock, flags);
31073 return -ENODEV;
31074 }
31075@@ -1418,7 +1419,7 @@ static int hvcs_write_room(struct tty_struct *tty)
31076 {
31077 struct hvcs_struct *hvcsd = tty->driver_data;
31078
31079- if (!hvcsd || hvcsd->open_count <= 0)
31080+ if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
31081 return 0;
31082
31083 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
31084diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31085index ec5e3f8..02455ba 100644
31086--- a/drivers/char/ipmi/ipmi_msghandler.c
31087+++ b/drivers/char/ipmi/ipmi_msghandler.c
31088@@ -414,7 +414,7 @@ struct ipmi_smi {
31089 struct proc_dir_entry *proc_dir;
31090 char proc_dir_name[10];
31091
31092- atomic_t stats[IPMI_NUM_STATS];
31093+ atomic_unchecked_t stats[IPMI_NUM_STATS];
31094
31095 /*
31096 * run_to_completion duplicate of smb_info, smi_info
31097@@ -447,9 +447,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31098
31099
31100 #define ipmi_inc_stat(intf, stat) \
31101- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31102+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31103 #define ipmi_get_stat(intf, stat) \
31104- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31105+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31106
31107 static int is_lan_addr(struct ipmi_addr *addr)
31108 {
31109@@ -2808,7 +2808,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31110 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31111 init_waitqueue_head(&intf->waitq);
31112 for (i = 0; i < IPMI_NUM_STATS; i++)
31113- atomic_set(&intf->stats[i], 0);
31114+ atomic_set_unchecked(&intf->stats[i], 0);
31115
31116 intf->proc_dir = NULL;
31117
31118@@ -4160,6 +4160,8 @@ static void send_panic_events(char *str)
31119 struct ipmi_smi_msg smi_msg;
31120 struct ipmi_recv_msg recv_msg;
31121
31122+ pax_track_stack();
31123+
31124 si = (struct ipmi_system_interface_addr *) &addr;
31125 si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
31126 si->channel = IPMI_BMC_CHANNEL;
31127diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31128index abae8c9..8021979 100644
31129--- a/drivers/char/ipmi/ipmi_si_intf.c
31130+++ b/drivers/char/ipmi/ipmi_si_intf.c
31131@@ -277,7 +277,7 @@ struct smi_info {
31132 unsigned char slave_addr;
31133
31134 /* Counters and things for the proc filesystem. */
31135- atomic_t stats[SI_NUM_STATS];
31136+ atomic_unchecked_t stats[SI_NUM_STATS];
31137
31138 struct task_struct *thread;
31139
31140@@ -285,9 +285,9 @@ struct smi_info {
31141 };
31142
31143 #define smi_inc_stat(smi, stat) \
31144- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31145+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31146 #define smi_get_stat(smi, stat) \
31147- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31148+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31149
31150 #define SI_MAX_PARMS 4
31151
31152@@ -2931,7 +2931,7 @@ static int try_smi_init(struct smi_info *new_smi)
31153 atomic_set(&new_smi->req_events, 0);
31154 new_smi->run_to_completion = 0;
31155 for (i = 0; i < SI_NUM_STATS; i++)
31156- atomic_set(&new_smi->stats[i], 0);
31157+ atomic_set_unchecked(&new_smi->stats[i], 0);
31158
31159 new_smi->interrupt_disabled = 0;
31160 atomic_set(&new_smi->stop_operation, 0);
31161diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
31162index 402838f..55e2200 100644
31163--- a/drivers/char/istallion.c
31164+++ b/drivers/char/istallion.c
31165@@ -187,7 +187,6 @@ static struct ktermios stli_deftermios = {
31166 * re-used for each stats call.
31167 */
31168 static comstats_t stli_comstats;
31169-static combrd_t stli_brdstats;
31170 static struct asystats stli_cdkstats;
31171
31172 /*****************************************************************************/
31173@@ -4058,6 +4057,7 @@ static int stli_getbrdstats(combrd_t __user *bp)
31174 {
31175 struct stlibrd *brdp;
31176 unsigned int i;
31177+ combrd_t stli_brdstats;
31178
31179 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
31180 return -EFAULT;
31181@@ -4269,6 +4269,8 @@ static int stli_getportstruct(struct stliport __user *arg)
31182 struct stliport stli_dummyport;
31183 struct stliport *portp;
31184
31185+ pax_track_stack();
31186+
31187 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
31188 return -EFAULT;
31189 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
31190@@ -4291,6 +4293,8 @@ static int stli_getbrdstruct(struct stlibrd __user *arg)
31191 struct stlibrd stli_dummybrd;
31192 struct stlibrd *brdp;
31193
31194+ pax_track_stack();
31195+
31196 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
31197 return -EFAULT;
31198 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
31199diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
31200index 950837c..e55a288 100644
31201--- a/drivers/char/keyboard.c
31202+++ b/drivers/char/keyboard.c
31203@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
31204 kbd->kbdmode == VC_MEDIUMRAW) &&
31205 value != KVAL(K_SAK))
31206 return; /* SAK is allowed even in raw mode */
31207+
31208+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
31209+ {
31210+ void *func = fn_handler[value];
31211+ if (func == fn_show_state || func == fn_show_ptregs ||
31212+ func == fn_show_mem)
31213+ return;
31214+ }
31215+#endif
31216+
31217 fn_handler[value](vc);
31218 }
31219
31220@@ -1386,7 +1396,7 @@ static const struct input_device_id kbd_ids[] = {
31221 .evbit = { BIT_MASK(EV_SND) },
31222 },
31223
31224- { }, /* Terminating entry */
31225+ { 0 }, /* Terminating entry */
31226 };
31227
31228 MODULE_DEVICE_TABLE(input, kbd_ids);
31229diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
31230index 87c67b4..230527a 100644
31231--- a/drivers/char/mbcs.c
31232+++ b/drivers/char/mbcs.c
31233@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
31234 return 0;
31235 }
31236
31237-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
31238+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
31239 {
31240 .part_num = MBCS_PART_NUM,
31241 .mfg_num = MBCS_MFG_NUM,
31242diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31243index 1270f64..8495f49 100644
31244--- a/drivers/char/mem.c
31245+++ b/drivers/char/mem.c
31246@@ -18,6 +18,7 @@
31247 #include <linux/raw.h>
31248 #include <linux/tty.h>
31249 #include <linux/capability.h>
31250+#include <linux/security.h>
31251 #include <linux/ptrace.h>
31252 #include <linux/device.h>
31253 #include <linux/highmem.h>
31254@@ -35,6 +36,10 @@
31255 # include <linux/efi.h>
31256 #endif
31257
31258+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31259+extern struct file_operations grsec_fops;
31260+#endif
31261+
31262 static inline unsigned long size_inside_page(unsigned long start,
31263 unsigned long size)
31264 {
31265@@ -102,9 +107,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31266
31267 while (cursor < to) {
31268 if (!devmem_is_allowed(pfn)) {
31269+#ifdef CONFIG_GRKERNSEC_KMEM
31270+ gr_handle_mem_readwrite(from, to);
31271+#else
31272 printk(KERN_INFO
31273 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31274 current->comm, from, to);
31275+#endif
31276 return 0;
31277 }
31278 cursor += PAGE_SIZE;
31279@@ -112,6 +121,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31280 }
31281 return 1;
31282 }
31283+#elif defined(CONFIG_GRKERNSEC_KMEM)
31284+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31285+{
31286+ return 0;
31287+}
31288 #else
31289 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31290 {
31291@@ -155,6 +169,8 @@ static ssize_t read_mem(struct file * file, char __user * buf,
31292 #endif
31293
31294 while (count > 0) {
31295+ char *temp;
31296+
31297 /*
31298 * Handle first page in case it's not aligned
31299 */
31300@@ -177,11 +193,31 @@ static ssize_t read_mem(struct file * file, char __user * buf,
31301 if (!ptr)
31302 return -EFAULT;
31303
31304- if (copy_to_user(buf, ptr, sz)) {
31305+#ifdef CONFIG_PAX_USERCOPY
31306+ temp = kmalloc(sz, GFP_KERNEL);
31307+ if (!temp) {
31308+ unxlate_dev_mem_ptr(p, ptr);
31309+ return -ENOMEM;
31310+ }
31311+ memcpy(temp, ptr, sz);
31312+#else
31313+ temp = ptr;
31314+#endif
31315+
31316+ if (copy_to_user(buf, temp, sz)) {
31317+
31318+#ifdef CONFIG_PAX_USERCOPY
31319+ kfree(temp);
31320+#endif
31321+
31322 unxlate_dev_mem_ptr(p, ptr);
31323 return -EFAULT;
31324 }
31325
31326+#ifdef CONFIG_PAX_USERCOPY
31327+ kfree(temp);
31328+#endif
31329+
31330 unxlate_dev_mem_ptr(p, ptr);
31331
31332 buf += sz;
31333@@ -419,9 +455,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31334 size_t count, loff_t *ppos)
31335 {
31336 unsigned long p = *ppos;
31337- ssize_t low_count, read, sz;
31338+ ssize_t low_count, read, sz, err = 0;
31339 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31340- int err = 0;
31341
31342 read = 0;
31343 if (p < (unsigned long) high_memory) {
31344@@ -444,6 +479,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31345 }
31346 #endif
31347 while (low_count > 0) {
31348+ char *temp;
31349+
31350 sz = size_inside_page(p, low_count);
31351
31352 /*
31353@@ -453,7 +490,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31354 */
31355 kbuf = xlate_dev_kmem_ptr((char *)p);
31356
31357- if (copy_to_user(buf, kbuf, sz))
31358+#ifdef CONFIG_PAX_USERCOPY
31359+ temp = kmalloc(sz, GFP_KERNEL);
31360+ if (!temp)
31361+ return -ENOMEM;
31362+ memcpy(temp, kbuf, sz);
31363+#else
31364+ temp = kbuf;
31365+#endif
31366+
31367+ err = copy_to_user(buf, temp, sz);
31368+
31369+#ifdef CONFIG_PAX_USERCOPY
31370+ kfree(temp);
31371+#endif
31372+
31373+ if (err)
31374 return -EFAULT;
31375 buf += sz;
31376 p += sz;
31377@@ -889,6 +941,9 @@ static const struct memdev {
31378 #ifdef CONFIG_CRASH_DUMP
31379 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31380 #endif
31381+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31382+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31383+#endif
31384 };
31385
31386 static int memory_open(struct inode *inode, struct file *filp)
31387diff --git a/drivers/char/pcmcia/ipwireless/tty.c b/drivers/char/pcmcia/ipwireless/tty.c
31388index 674b3ab..a8d1970 100644
31389--- a/drivers/char/pcmcia/ipwireless/tty.c
31390+++ b/drivers/char/pcmcia/ipwireless/tty.c
31391@@ -29,6 +29,7 @@
31392 #include <linux/tty_driver.h>
31393 #include <linux/tty_flip.h>
31394 #include <linux/uaccess.h>
31395+#include <asm/local.h>
31396
31397 #include "tty.h"
31398 #include "network.h"
31399@@ -51,7 +52,7 @@ struct ipw_tty {
31400 int tty_type;
31401 struct ipw_network *network;
31402 struct tty_struct *linux_tty;
31403- int open_count;
31404+ local_t open_count;
31405 unsigned int control_lines;
31406 struct mutex ipw_tty_mutex;
31407 int tx_bytes_queued;
31408@@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
31409 mutex_unlock(&tty->ipw_tty_mutex);
31410 return -ENODEV;
31411 }
31412- if (tty->open_count == 0)
31413+ if (local_read(&tty->open_count) == 0)
31414 tty->tx_bytes_queued = 0;
31415
31416- tty->open_count++;
31417+ local_inc(&tty->open_count);
31418
31419 tty->linux_tty = linux_tty;
31420 linux_tty->driver_data = tty;
31421@@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
31422
31423 static void do_ipw_close(struct ipw_tty *tty)
31424 {
31425- tty->open_count--;
31426-
31427- if (tty->open_count == 0) {
31428+ if (local_dec_return(&tty->open_count) == 0) {
31429 struct tty_struct *linux_tty = tty->linux_tty;
31430
31431 if (linux_tty != NULL) {
31432@@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
31433 return;
31434
31435 mutex_lock(&tty->ipw_tty_mutex);
31436- if (tty->open_count == 0) {
31437+ if (local_read(&tty->open_count) == 0) {
31438 mutex_unlock(&tty->ipw_tty_mutex);
31439 return;
31440 }
31441@@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
31442 return;
31443 }
31444
31445- if (!tty->open_count) {
31446+ if (!local_read(&tty->open_count)) {
31447 mutex_unlock(&tty->ipw_tty_mutex);
31448 return;
31449 }
31450@@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
31451 return -ENODEV;
31452
31453 mutex_lock(&tty->ipw_tty_mutex);
31454- if (!tty->open_count) {
31455+ if (!local_read(&tty->open_count)) {
31456 mutex_unlock(&tty->ipw_tty_mutex);
31457 return -EINVAL;
31458 }
31459@@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
31460 if (!tty)
31461 return -ENODEV;
31462
31463- if (!tty->open_count)
31464+ if (!local_read(&tty->open_count))
31465 return -EINVAL;
31466
31467 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
31468@@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
31469 if (!tty)
31470 return 0;
31471
31472- if (!tty->open_count)
31473+ if (!local_read(&tty->open_count))
31474 return 0;
31475
31476 return tty->tx_bytes_queued;
31477@@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty, struct file *file)
31478 if (!tty)
31479 return -ENODEV;
31480
31481- if (!tty->open_count)
31482+ if (!local_read(&tty->open_count))
31483 return -EINVAL;
31484
31485 return get_control_lines(tty);
31486@@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty, struct file *file,
31487 if (!tty)
31488 return -ENODEV;
31489
31490- if (!tty->open_count)
31491+ if (!local_read(&tty->open_count))
31492 return -EINVAL;
31493
31494 return set_control_lines(tty, set, clear);
31495@@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
31496 if (!tty)
31497 return -ENODEV;
31498
31499- if (!tty->open_count)
31500+ if (!local_read(&tty->open_count))
31501 return -EINVAL;
31502
31503 /* FIXME: Exactly how is the tty object locked here .. */
31504@@ -591,7 +590,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
31505 against a parallel ioctl etc */
31506 mutex_lock(&ttyj->ipw_tty_mutex);
31507 }
31508- while (ttyj->open_count)
31509+ while (local_read(&ttyj->open_count))
31510 do_ipw_close(ttyj);
31511 ipwireless_disassociate_network_ttys(network,
31512 ttyj->channel_idx);
31513diff --git a/drivers/char/pty.c b/drivers/char/pty.c
31514index 62f282e..e45c45c 100644
31515--- a/drivers/char/pty.c
31516+++ b/drivers/char/pty.c
31517@@ -736,8 +736,10 @@ static void __init unix98_pty_init(void)
31518 register_sysctl_table(pty_root_table);
31519
31520 /* Now create the /dev/ptmx special device */
31521+ pax_open_kernel();
31522 tty_default_fops(&ptmx_fops);
31523- ptmx_fops.open = ptmx_open;
31524+ *(void **)&ptmx_fops.open = ptmx_open;
31525+ pax_close_kernel();
31526
31527 cdev_init(&ptmx_cdev, &ptmx_fops);
31528 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
31529diff --git a/drivers/char/random.c b/drivers/char/random.c
31530index 3a19e2d..6ed09d3 100644
31531--- a/drivers/char/random.c
31532+++ b/drivers/char/random.c
31533@@ -254,8 +254,13 @@
31534 /*
31535 * Configuration information
31536 */
31537+#ifdef CONFIG_GRKERNSEC_RANDNET
31538+#define INPUT_POOL_WORDS 512
31539+#define OUTPUT_POOL_WORDS 128
31540+#else
31541 #define INPUT_POOL_WORDS 128
31542 #define OUTPUT_POOL_WORDS 32
31543+#endif
31544 #define SEC_XFER_SIZE 512
31545
31546 /*
31547@@ -292,10 +297,17 @@ static struct poolinfo {
31548 int poolwords;
31549 int tap1, tap2, tap3, tap4, tap5;
31550 } poolinfo_table[] = {
31551+#ifdef CONFIG_GRKERNSEC_RANDNET
31552+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
31553+ { 512, 411, 308, 208, 104, 1 },
31554+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
31555+ { 128, 103, 76, 51, 25, 1 },
31556+#else
31557 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
31558 { 128, 103, 76, 51, 25, 1 },
31559 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
31560 { 32, 26, 20, 14, 7, 1 },
31561+#endif
31562 #if 0
31563 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
31564 { 2048, 1638, 1231, 819, 411, 1 },
31565@@ -1209,7 +1221,7 @@ EXPORT_SYMBOL(generate_random_uuid);
31566 #include <linux/sysctl.h>
31567
31568 static int min_read_thresh = 8, min_write_thresh;
31569-static int max_read_thresh = INPUT_POOL_WORDS * 32;
31570+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
31571 static int max_write_thresh = INPUT_POOL_WORDS * 32;
31572 static char sysctl_bootid[16];
31573
31574diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
31575index 0e29a23..0efc2c2 100644
31576--- a/drivers/char/rocket.c
31577+++ b/drivers/char/rocket.c
31578@@ -1266,6 +1266,8 @@ static int get_ports(struct r_port *info, struct rocket_ports __user *retports)
31579 struct rocket_ports tmp;
31580 int board;
31581
31582+ pax_track_stack();
31583+
31584 if (!retports)
31585 return -EFAULT;
31586 memset(&tmp, 0, sizeof (tmp));
31587diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
31588index 8c262aa..4d3b058 100644
31589--- a/drivers/char/sonypi.c
31590+++ b/drivers/char/sonypi.c
31591@@ -55,6 +55,7 @@
31592 #include <asm/uaccess.h>
31593 #include <asm/io.h>
31594 #include <asm/system.h>
31595+#include <asm/local.h>
31596
31597 #include <linux/sonypi.h>
31598
31599@@ -491,7 +492,7 @@ static struct sonypi_device {
31600 spinlock_t fifo_lock;
31601 wait_queue_head_t fifo_proc_list;
31602 struct fasync_struct *fifo_async;
31603- int open_count;
31604+ local_t open_count;
31605 int model;
31606 struct input_dev *input_jog_dev;
31607 struct input_dev *input_key_dev;
31608@@ -895,7 +896,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
31609 static int sonypi_misc_release(struct inode *inode, struct file *file)
31610 {
31611 mutex_lock(&sonypi_device.lock);
31612- sonypi_device.open_count--;
31613+ local_dec(&sonypi_device.open_count);
31614 mutex_unlock(&sonypi_device.lock);
31615 return 0;
31616 }
31617@@ -905,9 +906,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
31618 lock_kernel();
31619 mutex_lock(&sonypi_device.lock);
31620 /* Flush input queue on first open */
31621- if (!sonypi_device.open_count)
31622+ if (!local_read(&sonypi_device.open_count))
31623 kfifo_reset(sonypi_device.fifo);
31624- sonypi_device.open_count++;
31625+ local_inc(&sonypi_device.open_count);
31626 mutex_unlock(&sonypi_device.lock);
31627 unlock_kernel();
31628 return 0;
31629diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
31630index db6dcfa..13834cb 100644
31631--- a/drivers/char/stallion.c
31632+++ b/drivers/char/stallion.c
31633@@ -2448,6 +2448,8 @@ static int stl_getportstruct(struct stlport __user *arg)
31634 struct stlport stl_dummyport;
31635 struct stlport *portp;
31636
31637+ pax_track_stack();
31638+
31639 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
31640 return -EFAULT;
31641 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
31642diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
31643index a0789f6..cea3902 100644
31644--- a/drivers/char/tpm/tpm.c
31645+++ b/drivers/char/tpm/tpm.c
31646@@ -405,7 +405,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
31647 chip->vendor.req_complete_val)
31648 goto out_recv;
31649
31650- if ((status == chip->vendor.req_canceled)) {
31651+ if (status == chip->vendor.req_canceled) {
31652 dev_err(chip->dev, "Operation Canceled\n");
31653 rc = -ECANCELED;
31654 goto out;
31655@@ -824,6 +824,8 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr,
31656
31657 struct tpm_chip *chip = dev_get_drvdata(dev);
31658
31659+ pax_track_stack();
31660+
31661 tpm_cmd.header.in = tpm_readpubek_header;
31662 err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
31663 "attempting to read the PUBEK");
31664diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
31665index bf2170f..ce8cab9 100644
31666--- a/drivers/char/tpm/tpm_bios.c
31667+++ b/drivers/char/tpm/tpm_bios.c
31668@@ -172,7 +172,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
31669 event = addr;
31670
31671 if ((event->event_type == 0 && event->event_size == 0) ||
31672- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
31673+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
31674 return NULL;
31675
31676 return addr;
31677@@ -197,7 +197,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
31678 return NULL;
31679
31680 if ((event->event_type == 0 && event->event_size == 0) ||
31681- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
31682+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
31683 return NULL;
31684
31685 (*pos)++;
31686@@ -290,7 +290,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
31687 int i;
31688
31689 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
31690- seq_putc(m, data[i]);
31691+ if (!seq_putc(m, data[i]))
31692+ return -EFAULT;
31693
31694 return 0;
31695 }
31696@@ -409,8 +410,13 @@ static int read_log(struct tpm_bios_log *log)
31697 log->bios_event_log_end = log->bios_event_log + len;
31698
31699 virt = acpi_os_map_memory(start, len);
31700+ if (!virt) {
31701+ kfree(log->bios_event_log);
31702+ log->bios_event_log = NULL;
31703+ return -EFAULT;
31704+ }
31705
31706- memcpy(log->bios_event_log, virt, len);
31707+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
31708
31709 acpi_os_unmap_memory(virt, len);
31710 return 0;
31711diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
31712index 123cedf..137edef 100644
31713--- a/drivers/char/tty_io.c
31714+++ b/drivers/char/tty_io.c
31715@@ -1774,6 +1774,7 @@ got_driver:
31716
31717 if (IS_ERR(tty)) {
31718 mutex_unlock(&tty_mutex);
31719+ tty_driver_kref_put(driver);
31720 return PTR_ERR(tty);
31721 }
31722 }
31723@@ -2603,8 +2604,10 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31724 return retval;
31725 }
31726
31727+EXPORT_SYMBOL(tty_ioctl);
31728+
31729 #ifdef CONFIG_COMPAT
31730-static long tty_compat_ioctl(struct file *file, unsigned int cmd,
31731+long tty_compat_ioctl(struct file *file, unsigned int cmd,
31732 unsigned long arg)
31733 {
31734 struct inode *inode = file->f_dentry->d_inode;
31735@@ -2628,6 +2631,8 @@ static long tty_compat_ioctl(struct file *file, unsigned int cmd,
31736
31737 return retval;
31738 }
31739+
31740+EXPORT_SYMBOL(tty_compat_ioctl);
31741 #endif
31742
31743 /*
31744@@ -3073,7 +3078,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
31745
31746 void tty_default_fops(struct file_operations *fops)
31747 {
31748- *fops = tty_fops;
31749+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
31750 }
31751
31752 /*
31753diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
31754index d814a3d..b55b9c9 100644
31755--- a/drivers/char/tty_ldisc.c
31756+++ b/drivers/char/tty_ldisc.c
31757@@ -74,7 +74,7 @@ static void put_ldisc(struct tty_ldisc *ld)
31758 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
31759 struct tty_ldisc_ops *ldo = ld->ops;
31760
31761- ldo->refcount--;
31762+ atomic_dec(&ldo->refcount);
31763 module_put(ldo->owner);
31764 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31765
31766@@ -109,7 +109,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
31767 spin_lock_irqsave(&tty_ldisc_lock, flags);
31768 tty_ldiscs[disc] = new_ldisc;
31769 new_ldisc->num = disc;
31770- new_ldisc->refcount = 0;
31771+ atomic_set(&new_ldisc->refcount, 0);
31772 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31773
31774 return ret;
31775@@ -137,7 +137,7 @@ int tty_unregister_ldisc(int disc)
31776 return -EINVAL;
31777
31778 spin_lock_irqsave(&tty_ldisc_lock, flags);
31779- if (tty_ldiscs[disc]->refcount)
31780+ if (atomic_read(&tty_ldiscs[disc]->refcount))
31781 ret = -EBUSY;
31782 else
31783 tty_ldiscs[disc] = NULL;
31784@@ -158,7 +158,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
31785 if (ldops) {
31786 ret = ERR_PTR(-EAGAIN);
31787 if (try_module_get(ldops->owner)) {
31788- ldops->refcount++;
31789+ atomic_inc(&ldops->refcount);
31790 ret = ldops;
31791 }
31792 }
31793@@ -171,7 +171,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
31794 unsigned long flags;
31795
31796 spin_lock_irqsave(&tty_ldisc_lock, flags);
31797- ldops->refcount--;
31798+ atomic_dec(&ldops->refcount);
31799 module_put(ldops->owner);
31800 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
31801 }
31802diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
31803index a035ae3..c27fe2c 100644
31804--- a/drivers/char/virtio_console.c
31805+++ b/drivers/char/virtio_console.c
31806@@ -133,7 +133,9 @@ static int get_chars(u32 vtermno, char *buf, int count)
31807 * virtqueue, so we let the drivers do some boutique early-output thing. */
31808 int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
31809 {
31810- virtio_cons.put_chars = put_chars;
31811+ pax_open_kernel();
31812+ *(void **)&virtio_cons.put_chars = put_chars;
31813+ pax_close_kernel();
31814 return hvc_instantiate(0, 0, &virtio_cons);
31815 }
31816
31817@@ -213,11 +215,13 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
31818 out_vq = vqs[1];
31819
31820 /* Start using the new console output. */
31821- virtio_cons.get_chars = get_chars;
31822- virtio_cons.put_chars = put_chars;
31823- virtio_cons.notifier_add = notifier_add_vio;
31824- virtio_cons.notifier_del = notifier_del_vio;
31825- virtio_cons.notifier_hangup = notifier_del_vio;
31826+ pax_open_kernel();
31827+ *(void **)&virtio_cons.get_chars = get_chars;
31828+ *(void **)&virtio_cons.put_chars = put_chars;
31829+ *(void **)&virtio_cons.notifier_add = notifier_add_vio;
31830+ *(void **)&virtio_cons.notifier_del = notifier_del_vio;
31831+ *(void **)&virtio_cons.notifier_hangup = notifier_del_vio;
31832+ pax_close_kernel();
31833
31834 /* The first argument of hvc_alloc() is the virtual console number, so
31835 * we use zero. The second argument is the parameter for the
31836diff --git a/drivers/char/vt.c b/drivers/char/vt.c
31837index 0c80c68..53d59c1 100644
31838--- a/drivers/char/vt.c
31839+++ b/drivers/char/vt.c
31840@@ -243,7 +243,7 @@ EXPORT_SYMBOL_GPL(unregister_vt_notifier);
31841
31842 static void notify_write(struct vc_data *vc, unsigned int unicode)
31843 {
31844- struct vt_notifier_param param = { .vc = vc, unicode = unicode };
31845+ struct vt_notifier_param param = { .vc = vc, .c = unicode };
31846 atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, &param);
31847 }
31848
31849diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
31850index 6351a26..999af95 100644
31851--- a/drivers/char/vt_ioctl.c
31852+++ b/drivers/char/vt_ioctl.c
31853@@ -210,9 +210,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
31854 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
31855 return -EFAULT;
31856
31857- if (!capable(CAP_SYS_TTY_CONFIG))
31858- perm = 0;
31859-
31860 switch (cmd) {
31861 case KDGKBENT:
31862 key_map = key_maps[s];
31863@@ -224,8 +221,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
31864 val = (i ? K_HOLE : K_NOSUCHMAP);
31865 return put_user(val, &user_kbe->kb_value);
31866 case KDSKBENT:
31867+ if (!capable(CAP_SYS_TTY_CONFIG))
31868+ perm = 0;
31869+
31870 if (!perm)
31871 return -EPERM;
31872+
31873 if (!i && v == K_NOSUCHMAP) {
31874 /* deallocate map */
31875 key_map = key_maps[s];
31876@@ -325,9 +326,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
31877 int i, j, k;
31878 int ret;
31879
31880- if (!capable(CAP_SYS_TTY_CONFIG))
31881- perm = 0;
31882-
31883 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
31884 if (!kbs) {
31885 ret = -ENOMEM;
31886@@ -361,6 +359,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
31887 kfree(kbs);
31888 return ((p && *p) ? -EOVERFLOW : 0);
31889 case KDSKBSENT:
31890+ if (!capable(CAP_SYS_TTY_CONFIG))
31891+ perm = 0;
31892+
31893 if (!perm) {
31894 ret = -EPERM;
31895 goto reterr;
31896diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
31897index c7ae026..1769c1d 100644
31898--- a/drivers/cpufreq/cpufreq.c
31899+++ b/drivers/cpufreq/cpufreq.c
31900@@ -750,7 +750,7 @@ static void cpufreq_sysfs_release(struct kobject *kobj)
31901 complete(&policy->kobj_unregister);
31902 }
31903
31904-static struct sysfs_ops sysfs_ops = {
31905+static const struct sysfs_ops sysfs_ops = {
31906 .show = show,
31907 .store = store,
31908 };
31909diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
31910index 97b0038..2056670 100644
31911--- a/drivers/cpuidle/sysfs.c
31912+++ b/drivers/cpuidle/sysfs.c
31913@@ -191,7 +191,7 @@ static ssize_t cpuidle_store(struct kobject * kobj, struct attribute * attr,
31914 return ret;
31915 }
31916
31917-static struct sysfs_ops cpuidle_sysfs_ops = {
31918+static const struct sysfs_ops cpuidle_sysfs_ops = {
31919 .show = cpuidle_show,
31920 .store = cpuidle_store,
31921 };
31922@@ -277,7 +277,7 @@ static ssize_t cpuidle_state_show(struct kobject * kobj,
31923 return ret;
31924 }
31925
31926-static struct sysfs_ops cpuidle_state_sysfs_ops = {
31927+static const struct sysfs_ops cpuidle_state_sysfs_ops = {
31928 .show = cpuidle_state_show,
31929 };
31930
31931@@ -294,7 +294,7 @@ static struct kobj_type ktype_state_cpuidle = {
31932 .release = cpuidle_state_sysfs_release,
31933 };
31934
31935-static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
31936+static inline void cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
31937 {
31938 kobject_put(&device->kobjs[i]->kobj);
31939 wait_for_completion(&device->kobjs[i]->kobj_unregister);
31940diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
31941index 5f753fc..0377ae9 100644
31942--- a/drivers/crypto/hifn_795x.c
31943+++ b/drivers/crypto/hifn_795x.c
31944@@ -1655,6 +1655,8 @@ static int hifn_test(struct hifn_device *dev, int encdec, u8 snum)
31945 0xCA, 0x34, 0x2B, 0x2E};
31946 struct scatterlist sg;
31947
31948+ pax_track_stack();
31949+
31950 memset(src, 0, sizeof(src));
31951 memset(ctx.key, 0, sizeof(ctx.key));
31952
31953diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
31954index 71e6482..de8d96c 100644
31955--- a/drivers/crypto/padlock-aes.c
31956+++ b/drivers/crypto/padlock-aes.c
31957@@ -108,6 +108,8 @@ static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
31958 struct crypto_aes_ctx gen_aes;
31959 int cpu;
31960
31961+ pax_track_stack();
31962+
31963 if (key_len % 8) {
31964 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
31965 return -EINVAL;
31966diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
31967index dcc4ab7..cc834bb 100644
31968--- a/drivers/dma/ioat/dma.c
31969+++ b/drivers/dma/ioat/dma.c
31970@@ -1146,7 +1146,7 @@ ioat_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
31971 return entry->show(&chan->common, page);
31972 }
31973
31974-struct sysfs_ops ioat_sysfs_ops = {
31975+const struct sysfs_ops ioat_sysfs_ops = {
31976 .show = ioat_attr_show,
31977 };
31978
31979diff --git a/drivers/dma/ioat/dma.h b/drivers/dma/ioat/dma.h
31980index bbc3e78..f2db62c 100644
31981--- a/drivers/dma/ioat/dma.h
31982+++ b/drivers/dma/ioat/dma.h
31983@@ -347,7 +347,7 @@ bool ioat_cleanup_preamble(struct ioat_chan_common *chan,
31984 unsigned long *phys_complete);
31985 void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type);
31986 void ioat_kobject_del(struct ioatdma_device *device);
31987-extern struct sysfs_ops ioat_sysfs_ops;
31988+extern const struct sysfs_ops ioat_sysfs_ops;
31989 extern struct ioat_sysfs_entry ioat_version_attr;
31990 extern struct ioat_sysfs_entry ioat_cap_attr;
31991 #endif /* IOATDMA_H */
31992diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
31993index 9908c9e..3ceb0e5 100644
31994--- a/drivers/dma/ioat/dma_v3.c
31995+++ b/drivers/dma/ioat/dma_v3.c
31996@@ -71,10 +71,10 @@
31997 /* provide a lookup table for setting the source address in the base or
31998 * extended descriptor of an xor or pq descriptor
31999 */
32000-static const u8 xor_idx_to_desc __read_mostly = 0xd0;
32001-static const u8 xor_idx_to_field[] __read_mostly = { 1, 4, 5, 6, 7, 0, 1, 2 };
32002-static const u8 pq_idx_to_desc __read_mostly = 0xf8;
32003-static const u8 pq_idx_to_field[] __read_mostly = { 1, 4, 5, 0, 1, 2, 4, 5 };
32004+static const u8 xor_idx_to_desc = 0xd0;
32005+static const u8 xor_idx_to_field[] = { 1, 4, 5, 6, 7, 0, 1, 2 };
32006+static const u8 pq_idx_to_desc = 0xf8;
32007+static const u8 pq_idx_to_field[] = { 1, 4, 5, 0, 1, 2, 4, 5 };
32008
32009 static dma_addr_t xor_get_src(struct ioat_raw_descriptor *descs[2], int idx)
32010 {
32011diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
32012index 85c464a..afd1e73 100644
32013--- a/drivers/edac/amd64_edac.c
32014+++ b/drivers/edac/amd64_edac.c
32015@@ -3099,7 +3099,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
32016 * PCI core identifies what devices are on a system during boot, and then
32017 * inquiry this table to see if this driver is for a given device found.
32018 */
32019-static const struct pci_device_id amd64_pci_table[] __devinitdata = {
32020+static const struct pci_device_id amd64_pci_table[] __devinitconst = {
32021 {
32022 .vendor = PCI_VENDOR_ID_AMD,
32023 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
32024diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
32025index 2b95f1a..4f52793 100644
32026--- a/drivers/edac/amd76x_edac.c
32027+++ b/drivers/edac/amd76x_edac.c
32028@@ -322,7 +322,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
32029 edac_mc_free(mci);
32030 }
32031
32032-static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
32033+static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
32034 {
32035 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32036 AMD762},
32037diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
32038index d205d49..74c9672 100644
32039--- a/drivers/edac/e752x_edac.c
32040+++ b/drivers/edac/e752x_edac.c
32041@@ -1282,7 +1282,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
32042 edac_mc_free(mci);
32043 }
32044
32045-static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
32046+static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
32047 {
32048 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32049 E7520},
32050diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
32051index c7d11cc..c59c1ca 100644
32052--- a/drivers/edac/e7xxx_edac.c
32053+++ b/drivers/edac/e7xxx_edac.c
32054@@ -526,7 +526,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
32055 edac_mc_free(mci);
32056 }
32057
32058-static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
32059+static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
32060 {
32061 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32062 E7205},
32063diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
32064index 5376457..5fdedbc 100644
32065--- a/drivers/edac/edac_device_sysfs.c
32066+++ b/drivers/edac/edac_device_sysfs.c
32067@@ -137,7 +137,7 @@ static ssize_t edac_dev_ctl_info_store(struct kobject *kobj,
32068 }
32069
32070 /* edac_dev file operations for an 'ctl_info' */
32071-static struct sysfs_ops device_ctl_info_ops = {
32072+static const struct sysfs_ops device_ctl_info_ops = {
32073 .show = edac_dev_ctl_info_show,
32074 .store = edac_dev_ctl_info_store
32075 };
32076@@ -373,7 +373,7 @@ static ssize_t edac_dev_instance_store(struct kobject *kobj,
32077 }
32078
32079 /* edac_dev file operations for an 'instance' */
32080-static struct sysfs_ops device_instance_ops = {
32081+static const struct sysfs_ops device_instance_ops = {
32082 .show = edac_dev_instance_show,
32083 .store = edac_dev_instance_store
32084 };
32085@@ -476,7 +476,7 @@ static ssize_t edac_dev_block_store(struct kobject *kobj,
32086 }
32087
32088 /* edac_dev file operations for a 'block' */
32089-static struct sysfs_ops device_block_ops = {
32090+static const struct sysfs_ops device_block_ops = {
32091 .show = edac_dev_block_show,
32092 .store = edac_dev_block_store
32093 };
32094diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
32095index e1d4ce0..88840e9 100644
32096--- a/drivers/edac/edac_mc_sysfs.c
32097+++ b/drivers/edac/edac_mc_sysfs.c
32098@@ -245,7 +245,7 @@ static ssize_t csrowdev_store(struct kobject *kobj, struct attribute *attr,
32099 return -EIO;
32100 }
32101
32102-static struct sysfs_ops csrowfs_ops = {
32103+static const struct sysfs_ops csrowfs_ops = {
32104 .show = csrowdev_show,
32105 .store = csrowdev_store
32106 };
32107@@ -575,7 +575,7 @@ static ssize_t mcidev_store(struct kobject *kobj, struct attribute *attr,
32108 }
32109
32110 /* Intermediate show/store table */
32111-static struct sysfs_ops mci_ops = {
32112+static const struct sysfs_ops mci_ops = {
32113 .show = mcidev_show,
32114 .store = mcidev_store
32115 };
32116diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32117index 422728c..d8d9c88 100644
32118--- a/drivers/edac/edac_pci_sysfs.c
32119+++ b/drivers/edac/edac_pci_sysfs.c
32120@@ -25,8 +25,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32121 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32122 static int edac_pci_poll_msec = 1000; /* one second workq period */
32123
32124-static atomic_t pci_parity_count = ATOMIC_INIT(0);
32125-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32126+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32127+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32128
32129 static struct kobject *edac_pci_top_main_kobj;
32130 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32131@@ -121,7 +121,7 @@ static ssize_t edac_pci_instance_store(struct kobject *kobj,
32132 }
32133
32134 /* fs_ops table */
32135-static struct sysfs_ops pci_instance_ops = {
32136+static const struct sysfs_ops pci_instance_ops = {
32137 .show = edac_pci_instance_show,
32138 .store = edac_pci_instance_store
32139 };
32140@@ -261,7 +261,7 @@ static ssize_t edac_pci_dev_store(struct kobject *kobj,
32141 return -EIO;
32142 }
32143
32144-static struct sysfs_ops edac_pci_sysfs_ops = {
32145+static const struct sysfs_ops edac_pci_sysfs_ops = {
32146 .show = edac_pci_dev_show,
32147 .store = edac_pci_dev_store
32148 };
32149@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32150 edac_printk(KERN_CRIT, EDAC_PCI,
32151 "Signaled System Error on %s\n",
32152 pci_name(dev));
32153- atomic_inc(&pci_nonparity_count);
32154+ atomic_inc_unchecked(&pci_nonparity_count);
32155 }
32156
32157 if (status & (PCI_STATUS_PARITY)) {
32158@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32159 "Master Data Parity Error on %s\n",
32160 pci_name(dev));
32161
32162- atomic_inc(&pci_parity_count);
32163+ atomic_inc_unchecked(&pci_parity_count);
32164 }
32165
32166 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32167@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32168 "Detected Parity Error on %s\n",
32169 pci_name(dev));
32170
32171- atomic_inc(&pci_parity_count);
32172+ atomic_inc_unchecked(&pci_parity_count);
32173 }
32174 }
32175
32176@@ -616,7 +616,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32177 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32178 "Signaled System Error on %s\n",
32179 pci_name(dev));
32180- atomic_inc(&pci_nonparity_count);
32181+ atomic_inc_unchecked(&pci_nonparity_count);
32182 }
32183
32184 if (status & (PCI_STATUS_PARITY)) {
32185@@ -624,7 +624,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32186 "Master Data Parity Error on "
32187 "%s\n", pci_name(dev));
32188
32189- atomic_inc(&pci_parity_count);
32190+ atomic_inc_unchecked(&pci_parity_count);
32191 }
32192
32193 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32194@@ -632,7 +632,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32195 "Detected Parity Error on %s\n",
32196 pci_name(dev));
32197
32198- atomic_inc(&pci_parity_count);
32199+ atomic_inc_unchecked(&pci_parity_count);
32200 }
32201 }
32202 }
32203@@ -674,7 +674,7 @@ void edac_pci_do_parity_check(void)
32204 if (!check_pci_errors)
32205 return;
32206
32207- before_count = atomic_read(&pci_parity_count);
32208+ before_count = atomic_read_unchecked(&pci_parity_count);
32209
32210 /* scan all PCI devices looking for a Parity Error on devices and
32211 * bridges.
32212@@ -686,7 +686,7 @@ void edac_pci_do_parity_check(void)
32213 /* Only if operator has selected panic on PCI Error */
32214 if (edac_pci_get_panic_on_pe()) {
32215 /* If the count is different 'after' from 'before' */
32216- if (before_count != atomic_read(&pci_parity_count))
32217+ if (before_count != atomic_read_unchecked(&pci_parity_count))
32218 panic("EDAC: PCI Parity Error");
32219 }
32220 }
32221diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
32222index 6c9a0f2..9c1cf7e 100644
32223--- a/drivers/edac/i3000_edac.c
32224+++ b/drivers/edac/i3000_edac.c
32225@@ -471,7 +471,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
32226 edac_mc_free(mci);
32227 }
32228
32229-static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
32230+static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
32231 {
32232 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32233 I3000},
32234diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
32235index fde4db9..fe108f9 100644
32236--- a/drivers/edac/i3200_edac.c
32237+++ b/drivers/edac/i3200_edac.c
32238@@ -444,7 +444,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
32239 edac_mc_free(mci);
32240 }
32241
32242-static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
32243+static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
32244 {
32245 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32246 I3200},
32247diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
32248index adc10a2..57d4ccf 100644
32249--- a/drivers/edac/i5000_edac.c
32250+++ b/drivers/edac/i5000_edac.c
32251@@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
32252 *
32253 * The "E500P" device is the first device supported.
32254 */
32255-static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
32256+static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
32257 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
32258 .driver_data = I5000P},
32259
32260diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
32261index 22db05a..b2b5503 100644
32262--- a/drivers/edac/i5100_edac.c
32263+++ b/drivers/edac/i5100_edac.c
32264@@ -944,7 +944,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
32265 edac_mc_free(mci);
32266 }
32267
32268-static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
32269+static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
32270 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
32271 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
32272 { 0, }
32273diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
32274index f99d106..f050710 100644
32275--- a/drivers/edac/i5400_edac.c
32276+++ b/drivers/edac/i5400_edac.c
32277@@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
32278 *
32279 * The "E500P" device is the first device supported.
32280 */
32281-static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
32282+static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
32283 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
32284 {0,} /* 0 terminated list. */
32285 };
32286diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
32287index 577760a..9ce16ce 100644
32288--- a/drivers/edac/i82443bxgx_edac.c
32289+++ b/drivers/edac/i82443bxgx_edac.c
32290@@ -381,7 +381,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
32291
32292 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
32293
32294-static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
32295+static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
32296 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
32297 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
32298 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
32299diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
32300index c0088ba..64a7b98 100644
32301--- a/drivers/edac/i82860_edac.c
32302+++ b/drivers/edac/i82860_edac.c
32303@@ -271,7 +271,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
32304 edac_mc_free(mci);
32305 }
32306
32307-static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
32308+static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
32309 {
32310 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32311 I82860},
32312diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
32313index b2d83b9..a34357b 100644
32314--- a/drivers/edac/i82875p_edac.c
32315+++ b/drivers/edac/i82875p_edac.c
32316@@ -512,7 +512,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
32317 edac_mc_free(mci);
32318 }
32319
32320-static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
32321+static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
32322 {
32323 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32324 I82875P},
32325diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
32326index 2eed3ea..87bbbd1 100644
32327--- a/drivers/edac/i82975x_edac.c
32328+++ b/drivers/edac/i82975x_edac.c
32329@@ -586,7 +586,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
32330 edac_mc_free(mci);
32331 }
32332
32333-static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
32334+static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
32335 {
32336 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32337 I82975X
32338diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
32339index 9900675..78ac2b6 100644
32340--- a/drivers/edac/r82600_edac.c
32341+++ b/drivers/edac/r82600_edac.c
32342@@ -374,7 +374,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
32343 edac_mc_free(mci);
32344 }
32345
32346-static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
32347+static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
32348 {
32349 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
32350 },
32351diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
32352index d4ec605..4cfec4e 100644
32353--- a/drivers/edac/x38_edac.c
32354+++ b/drivers/edac/x38_edac.c
32355@@ -441,7 +441,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
32356 edac_mc_free(mci);
32357 }
32358
32359-static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
32360+static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
32361 {
32362 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
32363 X38},
32364diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32365index 3fc2ceb..daf098f 100644
32366--- a/drivers/firewire/core-card.c
32367+++ b/drivers/firewire/core-card.c
32368@@ -558,7 +558,7 @@ void fw_card_release(struct kref *kref)
32369
32370 void fw_core_remove_card(struct fw_card *card)
32371 {
32372- struct fw_card_driver dummy_driver = dummy_driver_template;
32373+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
32374
32375 card->driver->update_phy_reg(card, 4,
32376 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32377diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32378index 4560d8f..36db24a 100644
32379--- a/drivers/firewire/core-cdev.c
32380+++ b/drivers/firewire/core-cdev.c
32381@@ -1141,8 +1141,7 @@ static int init_iso_resource(struct client *client,
32382 int ret;
32383
32384 if ((request->channels == 0 && request->bandwidth == 0) ||
32385- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32386- request->bandwidth < 0)
32387+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32388 return -EINVAL;
32389
32390 r = kmalloc(sizeof(*r), GFP_KERNEL);
32391diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32392index da628c7..cf54a2c 100644
32393--- a/drivers/firewire/core-transaction.c
32394+++ b/drivers/firewire/core-transaction.c
32395@@ -36,6 +36,7 @@
32396 #include <linux/string.h>
32397 #include <linux/timer.h>
32398 #include <linux/types.h>
32399+#include <linux/sched.h>
32400
32401 #include <asm/byteorder.h>
32402
32403@@ -344,6 +345,8 @@ int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
32404 struct transaction_callback_data d;
32405 struct fw_transaction t;
32406
32407+ pax_track_stack();
32408+
32409 init_completion(&d.done);
32410 d.payload = payload;
32411 fw_send_request(card, &t, tcode, destination_id, generation, speed,
32412diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32413index 7ff6e75..a2965d9 100644
32414--- a/drivers/firewire/core.h
32415+++ b/drivers/firewire/core.h
32416@@ -86,6 +86,7 @@ struct fw_card_driver {
32417
32418 int (*stop_iso)(struct fw_iso_context *ctx);
32419 };
32420+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32421
32422 void fw_card_initialize(struct fw_card *card,
32423 const struct fw_card_driver *driver, struct device *device);
32424diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32425index 3a2ccb0..82fd7c4 100644
32426--- a/drivers/firmware/dmi_scan.c
32427+++ b/drivers/firmware/dmi_scan.c
32428@@ -391,11 +391,6 @@ void __init dmi_scan_machine(void)
32429 }
32430 }
32431 else {
32432- /*
32433- * no iounmap() for that ioremap(); it would be a no-op, but
32434- * it's so early in setup that sucker gets confused into doing
32435- * what it shouldn't if we actually call it.
32436- */
32437 p = dmi_ioremap(0xF0000, 0x10000);
32438 if (p == NULL)
32439 goto error;
32440@@ -667,7 +662,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32441 if (buf == NULL)
32442 return -1;
32443
32444- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32445+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32446
32447 iounmap(buf);
32448 return 0;
32449diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
32450index 9e4f59d..110e24e 100644
32451--- a/drivers/firmware/edd.c
32452+++ b/drivers/firmware/edd.c
32453@@ -122,7 +122,7 @@ edd_attr_show(struct kobject * kobj, struct attribute *attr, char *buf)
32454 return ret;
32455 }
32456
32457-static struct sysfs_ops edd_attr_ops = {
32458+static const struct sysfs_ops edd_attr_ops = {
32459 .show = edd_attr_show,
32460 };
32461
32462diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32463index f4f709d..082f06e 100644
32464--- a/drivers/firmware/efivars.c
32465+++ b/drivers/firmware/efivars.c
32466@@ -362,7 +362,7 @@ static ssize_t efivar_attr_store(struct kobject *kobj, struct attribute *attr,
32467 return ret;
32468 }
32469
32470-static struct sysfs_ops efivar_attr_ops = {
32471+static const struct sysfs_ops efivar_attr_ops = {
32472 .show = efivar_attr_show,
32473 .store = efivar_attr_store,
32474 };
32475diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c
32476index 051d1eb..0a5d4e7 100644
32477--- a/drivers/firmware/iscsi_ibft.c
32478+++ b/drivers/firmware/iscsi_ibft.c
32479@@ -525,7 +525,7 @@ static ssize_t ibft_show_attribute(struct kobject *kobj,
32480 return ret;
32481 }
32482
32483-static struct sysfs_ops ibft_attr_ops = {
32484+static const struct sysfs_ops ibft_attr_ops = {
32485 .show = ibft_show_attribute,
32486 };
32487
32488diff --git a/drivers/firmware/memmap.c b/drivers/firmware/memmap.c
32489index 56f9234..8c58c7b 100644
32490--- a/drivers/firmware/memmap.c
32491+++ b/drivers/firmware/memmap.c
32492@@ -74,7 +74,7 @@ static struct attribute *def_attrs[] = {
32493 NULL
32494 };
32495
32496-static struct sysfs_ops memmap_attr_ops = {
32497+static const struct sysfs_ops memmap_attr_ops = {
32498 .show = memmap_attr_show,
32499 };
32500
32501diff --git a/drivers/gpio/vr41xx_giu.c b/drivers/gpio/vr41xx_giu.c
32502index b16c9a8..2af7d3f 100644
32503--- a/drivers/gpio/vr41xx_giu.c
32504+++ b/drivers/gpio/vr41xx_giu.c
32505@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32506 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32507 maskl, pendl, maskh, pendh);
32508
32509- atomic_inc(&irq_err_count);
32510+ atomic_inc_unchecked(&irq_err_count);
32511
32512 return -EINVAL;
32513 }
32514diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
32515index bea6efc..3dc0f42 100644
32516--- a/drivers/gpu/drm/drm_crtc.c
32517+++ b/drivers/gpu/drm/drm_crtc.c
32518@@ -1323,7 +1323,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32519 */
32520 if ((out_resp->count_modes >= mode_count) && mode_count) {
32521 copied = 0;
32522- mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
32523+ mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
32524 list_for_each_entry(mode, &connector->modes, head) {
32525 drm_crtc_convert_to_umode(&u_mode, mode);
32526 if (copy_to_user(mode_ptr + copied,
32527@@ -1338,8 +1338,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32528
32529 if ((out_resp->count_props >= props_count) && props_count) {
32530 copied = 0;
32531- prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
32532- prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
32533+ prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
32534+ prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
32535 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
32536 if (connector->property_ids[i] != 0) {
32537 if (put_user(connector->property_ids[i],
32538@@ -1361,7 +1361,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
32539
32540 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
32541 copied = 0;
32542- encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
32543+ encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
32544 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
32545 if (connector->encoder_ids[i] != 0) {
32546 if (put_user(connector->encoder_ids[i],
32547@@ -1513,7 +1513,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
32548 }
32549
32550 for (i = 0; i < crtc_req->count_connectors; i++) {
32551- set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
32552+ set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
32553 if (get_user(out_id, &set_connectors_ptr[i])) {
32554 ret = -EFAULT;
32555 goto out;
32556@@ -2118,7 +2118,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32557 out_resp->flags = property->flags;
32558
32559 if ((out_resp->count_values >= value_count) && value_count) {
32560- values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
32561+ values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
32562 for (i = 0; i < value_count; i++) {
32563 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
32564 ret = -EFAULT;
32565@@ -2131,7 +2131,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32566 if (property->flags & DRM_MODE_PROP_ENUM) {
32567 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
32568 copied = 0;
32569- enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
32570+ enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
32571 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
32572
32573 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
32574@@ -2154,7 +2154,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
32575 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
32576 copied = 0;
32577 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
32578- blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
32579+ blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
32580
32581 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
32582 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
32583@@ -2226,7 +2226,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
32584 blob = obj_to_blob(obj);
32585
32586 if (out_resp->length == blob->length) {
32587- blob_ptr = (void *)(unsigned long)out_resp->data;
32588+ blob_ptr = (void __user *)(unsigned long)out_resp->data;
32589 if (copy_to_user(blob_ptr, blob->data, blob->length)){
32590 ret = -EFAULT;
32591 goto done;
32592diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32593index 1b8745d..92fdbf6 100644
32594--- a/drivers/gpu/drm/drm_crtc_helper.c
32595+++ b/drivers/gpu/drm/drm_crtc_helper.c
32596@@ -573,7 +573,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32597 struct drm_crtc *tmp;
32598 int crtc_mask = 1;
32599
32600- WARN(!crtc, "checking null crtc?");
32601+ BUG_ON(!crtc);
32602
32603 dev = crtc->dev;
32604
32605@@ -642,6 +642,8 @@ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
32606
32607 adjusted_mode = drm_mode_duplicate(dev, mode);
32608
32609+ pax_track_stack();
32610+
32611 crtc->enabled = drm_helper_crtc_in_use(crtc);
32612
32613 if (!crtc->enabled)
32614diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32615index 0e27d98..dec8768 100644
32616--- a/drivers/gpu/drm/drm_drv.c
32617+++ b/drivers/gpu/drm/drm_drv.c
32618@@ -417,7 +417,7 @@ int drm_ioctl(struct inode *inode, struct file *filp,
32619 char *kdata = NULL;
32620
32621 atomic_inc(&dev->ioctl_count);
32622- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32623+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32624 ++file_priv->ioctl_count;
32625
32626 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32627diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32628index ba14553..182d0bb 100644
32629--- a/drivers/gpu/drm/drm_fops.c
32630+++ b/drivers/gpu/drm/drm_fops.c
32631@@ -66,7 +66,7 @@ static int drm_setup(struct drm_device * dev)
32632 }
32633
32634 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32635- atomic_set(&dev->counts[i], 0);
32636+ atomic_set_unchecked(&dev->counts[i], 0);
32637
32638 dev->sigdata.lock = NULL;
32639
32640@@ -130,9 +130,9 @@ int drm_open(struct inode *inode, struct file *filp)
32641
32642 retcode = drm_open_helper(inode, filp, dev);
32643 if (!retcode) {
32644- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32645+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32646 spin_lock(&dev->count_lock);
32647- if (!dev->open_count++) {
32648+ if (local_inc_return(&dev->open_count) == 1) {
32649 spin_unlock(&dev->count_lock);
32650 retcode = drm_setup(dev);
32651 goto out;
32652@@ -435,7 +435,7 @@ int drm_release(struct inode *inode, struct file *filp)
32653
32654 lock_kernel();
32655
32656- DRM_DEBUG("open_count = %d\n", dev->open_count);
32657+ DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
32658
32659 if (dev->driver->preclose)
32660 dev->driver->preclose(dev, file_priv);
32661@@ -447,7 +447,7 @@ int drm_release(struct inode *inode, struct file *filp)
32662 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32663 task_pid_nr(current),
32664 (long)old_encode_dev(file_priv->minor->device),
32665- dev->open_count);
32666+ local_read(&dev->open_count));
32667
32668 /* if the master has gone away we can't do anything with the lock */
32669 if (file_priv->minor->master)
32670@@ -524,9 +524,9 @@ int drm_release(struct inode *inode, struct file *filp)
32671 * End inline drm_release
32672 */
32673
32674- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32675+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32676 spin_lock(&dev->count_lock);
32677- if (!--dev->open_count) {
32678+ if (local_dec_and_test(&dev->open_count)) {
32679 if (atomic_read(&dev->ioctl_count)) {
32680 DRM_ERROR("Device busy: %d\n",
32681 atomic_read(&dev->ioctl_count));
32682diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
32683index 8bf3770..7942280 100644
32684--- a/drivers/gpu/drm/drm_gem.c
32685+++ b/drivers/gpu/drm/drm_gem.c
32686@@ -83,11 +83,11 @@ drm_gem_init(struct drm_device *dev)
32687 spin_lock_init(&dev->object_name_lock);
32688 idr_init(&dev->object_name_idr);
32689 atomic_set(&dev->object_count, 0);
32690- atomic_set(&dev->object_memory, 0);
32691+ atomic_set_unchecked(&dev->object_memory, 0);
32692 atomic_set(&dev->pin_count, 0);
32693- atomic_set(&dev->pin_memory, 0);
32694+ atomic_set_unchecked(&dev->pin_memory, 0);
32695 atomic_set(&dev->gtt_count, 0);
32696- atomic_set(&dev->gtt_memory, 0);
32697+ atomic_set_unchecked(&dev->gtt_memory, 0);
32698
32699 mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL);
32700 if (!mm) {
32701@@ -150,7 +150,7 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size)
32702 goto fput;
32703 }
32704 atomic_inc(&dev->object_count);
32705- atomic_add(obj->size, &dev->object_memory);
32706+ atomic_add_unchecked(obj->size, &dev->object_memory);
32707 return obj;
32708 fput:
32709 fput(obj->filp);
32710@@ -429,7 +429,7 @@ drm_gem_object_free(struct kref *kref)
32711
32712 fput(obj->filp);
32713 atomic_dec(&dev->object_count);
32714- atomic_sub(obj->size, &dev->object_memory);
32715+ atomic_sub_unchecked(obj->size, &dev->object_memory);
32716 kfree(obj);
32717 }
32718 EXPORT_SYMBOL(drm_gem_object_free);
32719diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32720index f0f6c6b..34af322 100644
32721--- a/drivers/gpu/drm/drm_info.c
32722+++ b/drivers/gpu/drm/drm_info.c
32723@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32724 struct drm_local_map *map;
32725 struct drm_map_list *r_list;
32726
32727- /* Hardcoded from _DRM_FRAME_BUFFER,
32728- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32729- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32730- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32731+ static const char * const types[] = {
32732+ [_DRM_FRAME_BUFFER] = "FB",
32733+ [_DRM_REGISTERS] = "REG",
32734+ [_DRM_SHM] = "SHM",
32735+ [_DRM_AGP] = "AGP",
32736+ [_DRM_SCATTER_GATHER] = "SG",
32737+ [_DRM_CONSISTENT] = "PCI",
32738+ [_DRM_GEM] = "GEM" };
32739 const char *type;
32740 int i;
32741
32742@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32743 map = r_list->map;
32744 if (!map)
32745 continue;
32746- if (map->type < 0 || map->type > 5)
32747+ if (map->type >= ARRAY_SIZE(types))
32748 type = "??";
32749 else
32750 type = types[map->type];
32751@@ -265,10 +269,10 @@ int drm_gem_object_info(struct seq_file *m, void* data)
32752 struct drm_device *dev = node->minor->dev;
32753
32754 seq_printf(m, "%d objects\n", atomic_read(&dev->object_count));
32755- seq_printf(m, "%d object bytes\n", atomic_read(&dev->object_memory));
32756+ seq_printf(m, "%d object bytes\n", atomic_read_unchecked(&dev->object_memory));
32757 seq_printf(m, "%d pinned\n", atomic_read(&dev->pin_count));
32758- seq_printf(m, "%d pin bytes\n", atomic_read(&dev->pin_memory));
32759- seq_printf(m, "%d gtt bytes\n", atomic_read(&dev->gtt_memory));
32760+ seq_printf(m, "%d pin bytes\n", atomic_read_unchecked(&dev->pin_memory));
32761+ seq_printf(m, "%d gtt bytes\n", atomic_read_unchecked(&dev->gtt_memory));
32762 seq_printf(m, "%d gtt total\n", dev->gtt_total);
32763 return 0;
32764 }
32765@@ -288,7 +292,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32766 mutex_lock(&dev->struct_mutex);
32767 seq_printf(m, "vma use count: %d, high_memory = %p, 0x%08llx\n",
32768 atomic_read(&dev->vma_count),
32769+#ifdef CONFIG_GRKERNSEC_HIDESYM
32770+ NULL, 0);
32771+#else
32772 high_memory, (u64)virt_to_phys(high_memory));
32773+#endif
32774
32775 list_for_each_entry(pt, &dev->vmalist, head) {
32776 vma = pt->vma;
32777@@ -296,14 +304,23 @@ int drm_vma_info(struct seq_file *m, void *data)
32778 continue;
32779 seq_printf(m,
32780 "\n%5d 0x%08lx-0x%08lx %c%c%c%c%c%c 0x%08lx000",
32781- pt->pid, vma->vm_start, vma->vm_end,
32782+ pt->pid,
32783+#ifdef CONFIG_GRKERNSEC_HIDESYM
32784+ 0, 0,
32785+#else
32786+ vma->vm_start, vma->vm_end,
32787+#endif
32788 vma->vm_flags & VM_READ ? 'r' : '-',
32789 vma->vm_flags & VM_WRITE ? 'w' : '-',
32790 vma->vm_flags & VM_EXEC ? 'x' : '-',
32791 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32792 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32793 vma->vm_flags & VM_IO ? 'i' : '-',
32794+#ifdef CONFIG_GRKERNSEC_HIDESYM
32795+ 0);
32796+#else
32797 vma->vm_pgoff);
32798+#endif
32799
32800 #if defined(__i386__)
32801 pgprot = pgprot_val(vma->vm_page_prot);
32802diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32803index 282d9fd..71e5f11 100644
32804--- a/drivers/gpu/drm/drm_ioc32.c
32805+++ b/drivers/gpu/drm/drm_ioc32.c
32806@@ -463,7 +463,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32807 request = compat_alloc_user_space(nbytes);
32808 if (!access_ok(VERIFY_WRITE, request, nbytes))
32809 return -EFAULT;
32810- list = (struct drm_buf_desc *) (request + 1);
32811+ list = (struct drm_buf_desc __user *) (request + 1);
32812
32813 if (__put_user(count, &request->count)
32814 || __put_user(list, &request->list))
32815@@ -525,7 +525,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32816 request = compat_alloc_user_space(nbytes);
32817 if (!access_ok(VERIFY_WRITE, request, nbytes))
32818 return -EFAULT;
32819- list = (struct drm_buf_pub *) (request + 1);
32820+ list = (struct drm_buf_pub __user *) (request + 1);
32821
32822 if (__put_user(count, &request->count)
32823 || __put_user(list, &request->list))
32824diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32825index 9b9ff46..4ea724c 100644
32826--- a/drivers/gpu/drm/drm_ioctl.c
32827+++ b/drivers/gpu/drm/drm_ioctl.c
32828@@ -283,7 +283,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32829 stats->data[i].value =
32830 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32831 else
32832- stats->data[i].value = atomic_read(&dev->counts[i]);
32833+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32834 stats->data[i].type = dev->types[i];
32835 }
32836
32837diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32838index e2f70a5..c703e86 100644
32839--- a/drivers/gpu/drm/drm_lock.c
32840+++ b/drivers/gpu/drm/drm_lock.c
32841@@ -87,7 +87,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32842 if (drm_lock_take(&master->lock, lock->context)) {
32843 master->lock.file_priv = file_priv;
32844 master->lock.lock_time = jiffies;
32845- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32846+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32847 break; /* Got lock */
32848 }
32849
32850@@ -165,7 +165,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32851 return -EINVAL;
32852 }
32853
32854- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32855+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32856
32857 /* kernel_context_switch isn't used by any of the x86 drm
32858 * modules but is required by the Sparc driver.
32859diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32860index 7d1d88c..b9131b2 100644
32861--- a/drivers/gpu/drm/i810/i810_dma.c
32862+++ b/drivers/gpu/drm/i810/i810_dma.c
32863@@ -952,8 +952,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32864 dma->buflist[vertex->idx],
32865 vertex->discard, vertex->used);
32866
32867- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32868- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32869+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32870+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32871 sarea_priv->last_enqueue = dev_priv->counter - 1;
32872 sarea_priv->last_dispatch = (int)hw_status[5];
32873
32874@@ -1115,8 +1115,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32875 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32876 mc->last_render);
32877
32878- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32879- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32880+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32881+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32882 sarea_priv->last_enqueue = dev_priv->counter - 1;
32883 sarea_priv->last_dispatch = (int)hw_status[5];
32884
32885diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32886index 21e2691..7321edd 100644
32887--- a/drivers/gpu/drm/i810/i810_drv.h
32888+++ b/drivers/gpu/drm/i810/i810_drv.h
32889@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32890 int page_flipping;
32891
32892 wait_queue_head_t irq_queue;
32893- atomic_t irq_received;
32894- atomic_t irq_emitted;
32895+ atomic_unchecked_t irq_received;
32896+ atomic_unchecked_t irq_emitted;
32897
32898 int front_offset;
32899 } drm_i810_private_t;
32900diff --git a/drivers/gpu/drm/i830/i830_drv.h b/drivers/gpu/drm/i830/i830_drv.h
32901index da82afe..48a45de 100644
32902--- a/drivers/gpu/drm/i830/i830_drv.h
32903+++ b/drivers/gpu/drm/i830/i830_drv.h
32904@@ -115,8 +115,8 @@ typedef struct drm_i830_private {
32905 int page_flipping;
32906
32907 wait_queue_head_t irq_queue;
32908- atomic_t irq_received;
32909- atomic_t irq_emitted;
32910+ atomic_unchecked_t irq_received;
32911+ atomic_unchecked_t irq_emitted;
32912
32913 int use_mi_batchbuffer_start;
32914
32915diff --git a/drivers/gpu/drm/i830/i830_irq.c b/drivers/gpu/drm/i830/i830_irq.c
32916index 91ec2bb..6f21fab 100644
32917--- a/drivers/gpu/drm/i830/i830_irq.c
32918+++ b/drivers/gpu/drm/i830/i830_irq.c
32919@@ -47,7 +47,7 @@ irqreturn_t i830_driver_irq_handler(DRM_IRQ_ARGS)
32920
32921 I830_WRITE16(I830REG_INT_IDENTITY_R, temp);
32922
32923- atomic_inc(&dev_priv->irq_received);
32924+ atomic_inc_unchecked(&dev_priv->irq_received);
32925 wake_up_interruptible(&dev_priv->irq_queue);
32926
32927 return IRQ_HANDLED;
32928@@ -60,14 +60,14 @@ static int i830_emit_irq(struct drm_device * dev)
32929
32930 DRM_DEBUG("%s\n", __func__);
32931
32932- atomic_inc(&dev_priv->irq_emitted);
32933+ atomic_inc_unchecked(&dev_priv->irq_emitted);
32934
32935 BEGIN_LP_RING(2);
32936 OUT_RING(0);
32937 OUT_RING(GFX_OP_USER_INTERRUPT);
32938 ADVANCE_LP_RING();
32939
32940- return atomic_read(&dev_priv->irq_emitted);
32941+ return atomic_read_unchecked(&dev_priv->irq_emitted);
32942 }
32943
32944 static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32945@@ -79,7 +79,7 @@ static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32946
32947 DRM_DEBUG("%s\n", __func__);
32948
32949- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
32950+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
32951 return 0;
32952
32953 dev_priv->sarea_priv->perf_boxes |= I830_BOX_WAIT;
32954@@ -88,7 +88,7 @@ static int i830_wait_irq(struct drm_device * dev, int irq_nr)
32955
32956 for (;;) {
32957 __set_current_state(TASK_INTERRUPTIBLE);
32958- if (atomic_read(&dev_priv->irq_received) >= irq_nr)
32959+ if (atomic_read_unchecked(&dev_priv->irq_received) >= irq_nr)
32960 break;
32961 if ((signed)(end - jiffies) <= 0) {
32962 DRM_ERROR("timeout iir %x imr %x ier %x hwstam %x\n",
32963@@ -163,8 +163,8 @@ void i830_driver_irq_preinstall(struct drm_device * dev)
32964 I830_WRITE16(I830REG_HWSTAM, 0xffff);
32965 I830_WRITE16(I830REG_INT_MASK_R, 0x0);
32966 I830_WRITE16(I830REG_INT_ENABLE_R, 0x0);
32967- atomic_set(&dev_priv->irq_received, 0);
32968- atomic_set(&dev_priv->irq_emitted, 0);
32969+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32970+ atomic_set_unchecked(&dev_priv->irq_emitted, 0);
32971 init_waitqueue_head(&dev_priv->irq_queue);
32972 }
32973
32974diff --git a/drivers/gpu/drm/i915/dvo.h b/drivers/gpu/drm/i915/dvo.h
32975index 288fc50..c6092055 100644
32976--- a/drivers/gpu/drm/i915/dvo.h
32977+++ b/drivers/gpu/drm/i915/dvo.h
32978@@ -135,23 +135,23 @@ struct intel_dvo_dev_ops {
32979 *
32980 * \return singly-linked list of modes or NULL if no modes found.
32981 */
32982- struct drm_display_mode *(*get_modes)(struct intel_dvo_device *dvo);
32983+ struct drm_display_mode *(* const get_modes)(struct intel_dvo_device *dvo);
32984
32985 /**
32986 * Clean up driver-specific bits of the output
32987 */
32988- void (*destroy) (struct intel_dvo_device *dvo);
32989+ void (* const destroy) (struct intel_dvo_device *dvo);
32990
32991 /**
32992 * Debugging hook to dump device registers to log file
32993 */
32994- void (*dump_regs)(struct intel_dvo_device *dvo);
32995+ void (* const dump_regs)(struct intel_dvo_device *dvo);
32996 };
32997
32998-extern struct intel_dvo_dev_ops sil164_ops;
32999-extern struct intel_dvo_dev_ops ch7xxx_ops;
33000-extern struct intel_dvo_dev_ops ivch_ops;
33001-extern struct intel_dvo_dev_ops tfp410_ops;
33002-extern struct intel_dvo_dev_ops ch7017_ops;
33003+extern const struct intel_dvo_dev_ops sil164_ops;
33004+extern const struct intel_dvo_dev_ops ch7xxx_ops;
33005+extern const struct intel_dvo_dev_ops ivch_ops;
33006+extern const struct intel_dvo_dev_ops tfp410_ops;
33007+extern const struct intel_dvo_dev_ops ch7017_ops;
33008
33009 #endif /* _INTEL_DVO_H */
33010diff --git a/drivers/gpu/drm/i915/dvo_ch7017.c b/drivers/gpu/drm/i915/dvo_ch7017.c
33011index 621815b..499d82e 100644
33012--- a/drivers/gpu/drm/i915/dvo_ch7017.c
33013+++ b/drivers/gpu/drm/i915/dvo_ch7017.c
33014@@ -443,7 +443,7 @@ static void ch7017_destroy(struct intel_dvo_device *dvo)
33015 }
33016 }
33017
33018-struct intel_dvo_dev_ops ch7017_ops = {
33019+const struct intel_dvo_dev_ops ch7017_ops = {
33020 .init = ch7017_init,
33021 .detect = ch7017_detect,
33022 .mode_valid = ch7017_mode_valid,
33023diff --git a/drivers/gpu/drm/i915/dvo_ch7xxx.c b/drivers/gpu/drm/i915/dvo_ch7xxx.c
33024index a9b8962..ac769ba 100644
33025--- a/drivers/gpu/drm/i915/dvo_ch7xxx.c
33026+++ b/drivers/gpu/drm/i915/dvo_ch7xxx.c
33027@@ -356,7 +356,7 @@ static void ch7xxx_destroy(struct intel_dvo_device *dvo)
33028 }
33029 }
33030
33031-struct intel_dvo_dev_ops ch7xxx_ops = {
33032+const struct intel_dvo_dev_ops ch7xxx_ops = {
33033 .init = ch7xxx_init,
33034 .detect = ch7xxx_detect,
33035 .mode_valid = ch7xxx_mode_valid,
33036diff --git a/drivers/gpu/drm/i915/dvo_ivch.c b/drivers/gpu/drm/i915/dvo_ivch.c
33037index aa176f9..ed2930c 100644
33038--- a/drivers/gpu/drm/i915/dvo_ivch.c
33039+++ b/drivers/gpu/drm/i915/dvo_ivch.c
33040@@ -430,7 +430,7 @@ static void ivch_destroy(struct intel_dvo_device *dvo)
33041 }
33042 }
33043
33044-struct intel_dvo_dev_ops ivch_ops= {
33045+const struct intel_dvo_dev_ops ivch_ops= {
33046 .init = ivch_init,
33047 .dpms = ivch_dpms,
33048 .save = ivch_save,
33049diff --git a/drivers/gpu/drm/i915/dvo_sil164.c b/drivers/gpu/drm/i915/dvo_sil164.c
33050index e1c1f73..7dbebcf 100644
33051--- a/drivers/gpu/drm/i915/dvo_sil164.c
33052+++ b/drivers/gpu/drm/i915/dvo_sil164.c
33053@@ -290,7 +290,7 @@ static void sil164_destroy(struct intel_dvo_device *dvo)
33054 }
33055 }
33056
33057-struct intel_dvo_dev_ops sil164_ops = {
33058+const struct intel_dvo_dev_ops sil164_ops = {
33059 .init = sil164_init,
33060 .detect = sil164_detect,
33061 .mode_valid = sil164_mode_valid,
33062diff --git a/drivers/gpu/drm/i915/dvo_tfp410.c b/drivers/gpu/drm/i915/dvo_tfp410.c
33063index 16dce84..7e1b6f8 100644
33064--- a/drivers/gpu/drm/i915/dvo_tfp410.c
33065+++ b/drivers/gpu/drm/i915/dvo_tfp410.c
33066@@ -323,7 +323,7 @@ static void tfp410_destroy(struct intel_dvo_device *dvo)
33067 }
33068 }
33069
33070-struct intel_dvo_dev_ops tfp410_ops = {
33071+const struct intel_dvo_dev_ops tfp410_ops = {
33072 .init = tfp410_init,
33073 .detect = tfp410_detect,
33074 .mode_valid = tfp410_mode_valid,
33075diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
33076index 7e859d6..7d1cf2b 100644
33077--- a/drivers/gpu/drm/i915/i915_debugfs.c
33078+++ b/drivers/gpu/drm/i915/i915_debugfs.c
33079@@ -192,7 +192,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
33080 I915_READ(GTIMR));
33081 }
33082 seq_printf(m, "Interrupts received: %d\n",
33083- atomic_read(&dev_priv->irq_received));
33084+ atomic_read_unchecked(&dev_priv->irq_received));
33085 if (dev_priv->hw_status_page != NULL) {
33086 seq_printf(m, "Current sequence: %d\n",
33087 i915_get_gem_seqno(dev));
33088diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
33089index 5449239..7e4f68d 100644
33090--- a/drivers/gpu/drm/i915/i915_drv.c
33091+++ b/drivers/gpu/drm/i915/i915_drv.c
33092@@ -285,7 +285,7 @@ i915_pci_resume(struct pci_dev *pdev)
33093 return i915_resume(dev);
33094 }
33095
33096-static struct vm_operations_struct i915_gem_vm_ops = {
33097+static const struct vm_operations_struct i915_gem_vm_ops = {
33098 .fault = i915_gem_fault,
33099 .open = drm_gem_vm_open,
33100 .close = drm_gem_vm_close,
33101diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
33102index 97163f7..c24c7c7 100644
33103--- a/drivers/gpu/drm/i915/i915_drv.h
33104+++ b/drivers/gpu/drm/i915/i915_drv.h
33105@@ -168,7 +168,7 @@ struct drm_i915_display_funcs {
33106 /* display clock increase/decrease */
33107 /* pll clock increase/decrease */
33108 /* clock gating init */
33109-};
33110+} __no_const;
33111
33112 typedef struct drm_i915_private {
33113 struct drm_device *dev;
33114@@ -197,7 +197,7 @@ typedef struct drm_i915_private {
33115 int page_flipping;
33116
33117 wait_queue_head_t irq_queue;
33118- atomic_t irq_received;
33119+ atomic_unchecked_t irq_received;
33120 /** Protects user_irq_refcount and irq_mask_reg */
33121 spinlock_t user_irq_lock;
33122 /** Refcount for i915_user_irq_get() versus i915_user_irq_put(). */
33123diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
33124index 27a3074..eb3f959 100644
33125--- a/drivers/gpu/drm/i915/i915_gem.c
33126+++ b/drivers/gpu/drm/i915/i915_gem.c
33127@@ -102,7 +102,7 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
33128
33129 args->aper_size = dev->gtt_total;
33130 args->aper_available_size = (args->aper_size -
33131- atomic_read(&dev->pin_memory));
33132+ atomic_read_unchecked(&dev->pin_memory));
33133
33134 return 0;
33135 }
33136@@ -2058,7 +2058,7 @@ i915_gem_object_unbind(struct drm_gem_object *obj)
33137
33138 if (obj_priv->gtt_space) {
33139 atomic_dec(&dev->gtt_count);
33140- atomic_sub(obj->size, &dev->gtt_memory);
33141+ atomic_sub_unchecked(obj->size, &dev->gtt_memory);
33142
33143 drm_mm_put_block(obj_priv->gtt_space);
33144 obj_priv->gtt_space = NULL;
33145@@ -2701,7 +2701,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
33146 goto search_free;
33147 }
33148 atomic_inc(&dev->gtt_count);
33149- atomic_add(obj->size, &dev->gtt_memory);
33150+ atomic_add_unchecked(obj->size, &dev->gtt_memory);
33151
33152 /* Assert that the object is not currently in any GPU domain. As it
33153 * wasn't in the GTT, there shouldn't be any way it could have been in
33154@@ -3755,9 +3755,9 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
33155 "%d/%d gtt bytes\n",
33156 atomic_read(&dev->object_count),
33157 atomic_read(&dev->pin_count),
33158- atomic_read(&dev->object_memory),
33159- atomic_read(&dev->pin_memory),
33160- atomic_read(&dev->gtt_memory),
33161+ atomic_read_unchecked(&dev->object_memory),
33162+ atomic_read_unchecked(&dev->pin_memory),
33163+ atomic_read_unchecked(&dev->gtt_memory),
33164 dev->gtt_total);
33165 }
33166 goto err;
33167@@ -3989,7 +3989,7 @@ i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment)
33168 */
33169 if (obj_priv->pin_count == 1) {
33170 atomic_inc(&dev->pin_count);
33171- atomic_add(obj->size, &dev->pin_memory);
33172+ atomic_add_unchecked(obj->size, &dev->pin_memory);
33173 if (!obj_priv->active &&
33174 (obj->write_domain & I915_GEM_GPU_DOMAINS) == 0 &&
33175 !list_empty(&obj_priv->list))
33176@@ -4022,7 +4022,7 @@ i915_gem_object_unpin(struct drm_gem_object *obj)
33177 list_move_tail(&obj_priv->list,
33178 &dev_priv->mm.inactive_list);
33179 atomic_dec(&dev->pin_count);
33180- atomic_sub(obj->size, &dev->pin_memory);
33181+ atomic_sub_unchecked(obj->size, &dev->pin_memory);
33182 }
33183 i915_verify_inactive(dev, __FILE__, __LINE__);
33184 }
33185diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
33186index 63f28ad..f5469da 100644
33187--- a/drivers/gpu/drm/i915/i915_irq.c
33188+++ b/drivers/gpu/drm/i915/i915_irq.c
33189@@ -528,7 +528,7 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
33190 int irq_received;
33191 int ret = IRQ_NONE;
33192
33193- atomic_inc(&dev_priv->irq_received);
33194+ atomic_inc_unchecked(&dev_priv->irq_received);
33195
33196 if (IS_IGDNG(dev))
33197 return igdng_irq_handler(dev);
33198@@ -1021,7 +1021,7 @@ void i915_driver_irq_preinstall(struct drm_device * dev)
33199 {
33200 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33201
33202- atomic_set(&dev_priv->irq_received, 0);
33203+ atomic_set_unchecked(&dev_priv->irq_received, 0);
33204
33205 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
33206 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
33207diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
33208index 5d9c6a7..d1b0e29 100644
33209--- a/drivers/gpu/drm/i915/intel_sdvo.c
33210+++ b/drivers/gpu/drm/i915/intel_sdvo.c
33211@@ -2795,7 +2795,9 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device)
33212 sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device);
33213
33214 /* Save the bit-banging i2c functionality for use by the DDC wrapper */
33215- intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
33216+ pax_open_kernel();
33217+ *(void **)&intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality;
33218+ pax_close_kernel();
33219
33220 /* Read the regs to test if we can talk to the device */
33221 for (i = 0; i < 0x40; i++) {
33222diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33223index be6c6b9..8615d9c 100644
33224--- a/drivers/gpu/drm/mga/mga_drv.h
33225+++ b/drivers/gpu/drm/mga/mga_drv.h
33226@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33227 u32 clear_cmd;
33228 u32 maccess;
33229
33230- atomic_t vbl_received; /**< Number of vblanks received. */
33231+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33232 wait_queue_head_t fence_queue;
33233- atomic_t last_fence_retired;
33234+ atomic_unchecked_t last_fence_retired;
33235 u32 next_fence_to_post;
33236
33237 unsigned int fb_cpp;
33238diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33239index daa6041..a28a5da 100644
33240--- a/drivers/gpu/drm/mga/mga_irq.c
33241+++ b/drivers/gpu/drm/mga/mga_irq.c
33242@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33243 if (crtc != 0)
33244 return 0;
33245
33246- return atomic_read(&dev_priv->vbl_received);
33247+ return atomic_read_unchecked(&dev_priv->vbl_received);
33248 }
33249
33250
33251@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33252 /* VBLANK interrupt */
33253 if (status & MGA_VLINEPEN) {
33254 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33255- atomic_inc(&dev_priv->vbl_received);
33256+ atomic_inc_unchecked(&dev_priv->vbl_received);
33257 drm_handle_vblank(dev, 0);
33258 handled = 1;
33259 }
33260@@ -80,7 +80,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33261 MGA_WRITE(MGA_PRIMEND, prim_end);
33262 }
33263
33264- atomic_inc(&dev_priv->last_fence_retired);
33265+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
33266 DRM_WAKEUP(&dev_priv->fence_queue);
33267 handled = 1;
33268 }
33269@@ -131,7 +131,7 @@ int mga_driver_fence_wait(struct drm_device * dev, unsigned int *sequence)
33270 * using fences.
33271 */
33272 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33273- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33274+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33275 - *sequence) <= (1 << 23)));
33276
33277 *sequence = cur_fence;
33278diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33279index 4c39a40..b22a9ea 100644
33280--- a/drivers/gpu/drm/r128/r128_cce.c
33281+++ b/drivers/gpu/drm/r128/r128_cce.c
33282@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device * dev, drm_r128_init_t * init)
33283
33284 /* GH: Simple idle check.
33285 */
33286- atomic_set(&dev_priv->idle_count, 0);
33287+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33288
33289 /* We don't support anything other than bus-mastering ring mode,
33290 * but the ring can be in either AGP or PCI space for the ring
33291diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33292index 3c60829..4faf484 100644
33293--- a/drivers/gpu/drm/r128/r128_drv.h
33294+++ b/drivers/gpu/drm/r128/r128_drv.h
33295@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33296 int is_pci;
33297 unsigned long cce_buffers_offset;
33298
33299- atomic_t idle_count;
33300+ atomic_unchecked_t idle_count;
33301
33302 int page_flipping;
33303 int current_page;
33304 u32 crtc_offset;
33305 u32 crtc_offset_cntl;
33306
33307- atomic_t vbl_received;
33308+ atomic_unchecked_t vbl_received;
33309
33310 u32 color_fmt;
33311 unsigned int front_offset;
33312diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33313index 69810fb..97bf17a 100644
33314--- a/drivers/gpu/drm/r128/r128_irq.c
33315+++ b/drivers/gpu/drm/r128/r128_irq.c
33316@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33317 if (crtc != 0)
33318 return 0;
33319
33320- return atomic_read(&dev_priv->vbl_received);
33321+ return atomic_read_unchecked(&dev_priv->vbl_received);
33322 }
33323
33324 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33325@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33326 /* VBLANK interrupt */
33327 if (status & R128_CRTC_VBLANK_INT) {
33328 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33329- atomic_inc(&dev_priv->vbl_received);
33330+ atomic_inc_unchecked(&dev_priv->vbl_received);
33331 drm_handle_vblank(dev, 0);
33332 return IRQ_HANDLED;
33333 }
33334diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33335index af2665c..51922d2 100644
33336--- a/drivers/gpu/drm/r128/r128_state.c
33337+++ b/drivers/gpu/drm/r128/r128_state.c
33338@@ -323,10 +323,10 @@ static void r128_clear_box(drm_r128_private_t * dev_priv,
33339
33340 static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
33341 {
33342- if (atomic_read(&dev_priv->idle_count) == 0) {
33343+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0) {
33344 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33345 } else {
33346- atomic_set(&dev_priv->idle_count, 0);
33347+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33348 }
33349 }
33350
33351diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
33352index dd72b91..8644b3c 100644
33353--- a/drivers/gpu/drm/radeon/atom.c
33354+++ b/drivers/gpu/drm/radeon/atom.c
33355@@ -1115,6 +1115,8 @@ struct atom_context *atom_parse(struct card_info *card, void *bios)
33356 char name[512];
33357 int i;
33358
33359+ pax_track_stack();
33360+
33361 ctx->card = card;
33362 ctx->bios = bios;
33363
33364diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33365index 0d79577..efaa7a5 100644
33366--- a/drivers/gpu/drm/radeon/mkregtable.c
33367+++ b/drivers/gpu/drm/radeon/mkregtable.c
33368@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33369 regex_t mask_rex;
33370 regmatch_t match[4];
33371 char buf[1024];
33372- size_t end;
33373+ long end;
33374 int len;
33375 int done = 0;
33376 int r;
33377 unsigned o;
33378 struct offset *offset;
33379 char last_reg_s[10];
33380- int last_reg;
33381+ unsigned long last_reg;
33382
33383 if (regcomp
33384 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33385diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
33386index 6735213..38c2c67 100644
33387--- a/drivers/gpu/drm/radeon/radeon.h
33388+++ b/drivers/gpu/drm/radeon/radeon.h
33389@@ -149,7 +149,7 @@ int radeon_pm_init(struct radeon_device *rdev);
33390 */
33391 struct radeon_fence_driver {
33392 uint32_t scratch_reg;
33393- atomic_t seq;
33394+ atomic_unchecked_t seq;
33395 uint32_t last_seq;
33396 unsigned long count_timeout;
33397 wait_queue_head_t queue;
33398@@ -640,7 +640,7 @@ struct radeon_asic {
33399 uint32_t offset, uint32_t obj_size);
33400 int (*clear_surface_reg)(struct radeon_device *rdev, int reg);
33401 void (*bandwidth_update)(struct radeon_device *rdev);
33402-};
33403+} __no_const;
33404
33405 /*
33406 * Asic structures
33407diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c
33408index 4e928b9..d8b6008 100644
33409--- a/drivers/gpu/drm/radeon/radeon_atombios.c
33410+++ b/drivers/gpu/drm/radeon/radeon_atombios.c
33411@@ -275,6 +275,8 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev)
33412 bool linkb;
33413 struct radeon_i2c_bus_rec ddc_bus;
33414
33415+ pax_track_stack();
33416+
33417 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
33418
33419 if (data_offset == 0)
33420@@ -520,13 +522,13 @@ static uint16_t atombios_get_connector_object_id(struct drm_device *dev,
33421 }
33422 }
33423
33424-struct bios_connector {
33425+static struct bios_connector {
33426 bool valid;
33427 uint16_t line_mux;
33428 uint16_t devices;
33429 int connector_type;
33430 struct radeon_i2c_bus_rec ddc_bus;
33431-};
33432+} bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
33433
33434 bool radeon_get_atom_connector_info_from_supported_devices_table(struct
33435 drm_device
33436@@ -542,7 +544,6 @@ bool radeon_get_atom_connector_info_from_supported_devices_table(struct
33437 uint8_t dac;
33438 union atom_supported_devices *supported_devices;
33439 int i, j;
33440- struct bios_connector bios_connectors[ATOM_MAX_SUPPORTED_DEVICE];
33441
33442 atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset);
33443
33444diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
33445index 083a181..ccccae0 100644
33446--- a/drivers/gpu/drm/radeon/radeon_display.c
33447+++ b/drivers/gpu/drm/radeon/radeon_display.c
33448@@ -482,7 +482,7 @@ void radeon_compute_pll(struct radeon_pll *pll,
33449
33450 if (flags & RADEON_PLL_PREFER_CLOSEST_LOWER) {
33451 error = freq - current_freq;
33452- error = error < 0 ? 0xffffffff : error;
33453+ error = (int32_t)error < 0 ? 0xffffffff : error;
33454 } else
33455 error = abs(current_freq - freq);
33456 vco_diff = abs(vco - best_vco);
33457diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33458index 76e4070..193fa7f 100644
33459--- a/drivers/gpu/drm/radeon/radeon_drv.h
33460+++ b/drivers/gpu/drm/radeon/radeon_drv.h
33461@@ -253,7 +253,7 @@ typedef struct drm_radeon_private {
33462
33463 /* SW interrupt */
33464 wait_queue_head_t swi_queue;
33465- atomic_t swi_emitted;
33466+ atomic_unchecked_t swi_emitted;
33467 int vblank_crtc;
33468 uint32_t irq_enable_reg;
33469 uint32_t r500_disp_irq_reg;
33470diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
33471index 3beb26d..6ce9c4a 100644
33472--- a/drivers/gpu/drm/radeon/radeon_fence.c
33473+++ b/drivers/gpu/drm/radeon/radeon_fence.c
33474@@ -47,7 +47,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
33475 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
33476 return 0;
33477 }
33478- fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
33479+ fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
33480 if (!rdev->cp.ready) {
33481 /* FIXME: cp is not running assume everythings is done right
33482 * away
33483@@ -364,7 +364,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
33484 return r;
33485 }
33486 WREG32(rdev->fence_drv.scratch_reg, 0);
33487- atomic_set(&rdev->fence_drv.seq, 0);
33488+ atomic_set_unchecked(&rdev->fence_drv.seq, 0);
33489 INIT_LIST_HEAD(&rdev->fence_drv.created);
33490 INIT_LIST_HEAD(&rdev->fence_drv.emited);
33491 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
33492diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33493index a1bf11d..4a123c0 100644
33494--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33495+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33496@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33497 request = compat_alloc_user_space(sizeof(*request));
33498 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33499 || __put_user(req32.param, &request->param)
33500- || __put_user((void __user *)(unsigned long)req32.value,
33501+ || __put_user((unsigned long)req32.value,
33502 &request->value))
33503 return -EFAULT;
33504
33505diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33506index b79ecc4..8dab92d 100644
33507--- a/drivers/gpu/drm/radeon/radeon_irq.c
33508+++ b/drivers/gpu/drm/radeon/radeon_irq.c
33509@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33510 unsigned int ret;
33511 RING_LOCALS;
33512
33513- atomic_inc(&dev_priv->swi_emitted);
33514- ret = atomic_read(&dev_priv->swi_emitted);
33515+ atomic_inc_unchecked(&dev_priv->swi_emitted);
33516+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33517
33518 BEGIN_RING(4);
33519 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33520@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33521 drm_radeon_private_t *dev_priv =
33522 (drm_radeon_private_t *) dev->dev_private;
33523
33524- atomic_set(&dev_priv->swi_emitted, 0);
33525+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33526 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33527
33528 dev->max_vblank_count = 0x001fffff;
33529diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33530index 4747910..48ca4b3 100644
33531--- a/drivers/gpu/drm/radeon/radeon_state.c
33532+++ b/drivers/gpu/drm/radeon/radeon_state.c
33533@@ -3021,7 +3021,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33534 {
33535 drm_radeon_private_t *dev_priv = dev->dev_private;
33536 drm_radeon_getparam_t *param = data;
33537- int value;
33538+ int value = 0;
33539
33540 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33541
33542diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33543index 1381e06..0e53b17 100644
33544--- a/drivers/gpu/drm/radeon/radeon_ttm.c
33545+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33546@@ -535,27 +535,10 @@ void radeon_ttm_fini(struct radeon_device *rdev)
33547 DRM_INFO("radeon: ttm finalized\n");
33548 }
33549
33550-static struct vm_operations_struct radeon_ttm_vm_ops;
33551-static const struct vm_operations_struct *ttm_vm_ops = NULL;
33552-
33553-static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33554-{
33555- struct ttm_buffer_object *bo;
33556- int r;
33557-
33558- bo = (struct ttm_buffer_object *)vma->vm_private_data;
33559- if (bo == NULL) {
33560- return VM_FAULT_NOPAGE;
33561- }
33562- r = ttm_vm_ops->fault(vma, vmf);
33563- return r;
33564-}
33565-
33566 int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33567 {
33568 struct drm_file *file_priv;
33569 struct radeon_device *rdev;
33570- int r;
33571
33572 if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET)) {
33573 return drm_mmap(filp, vma);
33574@@ -563,20 +546,9 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33575
33576 file_priv = (struct drm_file *)filp->private_data;
33577 rdev = file_priv->minor->dev->dev_private;
33578- if (rdev == NULL) {
33579+ if (!rdev)
33580 return -EINVAL;
33581- }
33582- r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
33583- if (unlikely(r != 0)) {
33584- return r;
33585- }
33586- if (unlikely(ttm_vm_ops == NULL)) {
33587- ttm_vm_ops = vma->vm_ops;
33588- radeon_ttm_vm_ops = *ttm_vm_ops;
33589- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33590- }
33591- vma->vm_ops = &radeon_ttm_vm_ops;
33592- return 0;
33593+ return ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
33594 }
33595
33596
33597diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33598index b12ff76..0bd0c6e 100644
33599--- a/drivers/gpu/drm/radeon/rs690.c
33600+++ b/drivers/gpu/drm/radeon/rs690.c
33601@@ -302,9 +302,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33602 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33603 rdev->pm.sideport_bandwidth.full)
33604 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33605- read_delay_latency.full = rfixed_const(370 * 800 * 1000);
33606+ read_delay_latency.full = rfixed_const(800 * 1000);
33607 read_delay_latency.full = rfixed_div(read_delay_latency,
33608 rdev->pm.igp_sideport_mclk);
33609+ a.full = rfixed_const(370);
33610+ read_delay_latency.full = rfixed_mul(read_delay_latency, a);
33611 } else {
33612 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33613 rdev->pm.k8_bandwidth.full)
33614diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
33615index 0ed436e..e6e7ce3 100644
33616--- a/drivers/gpu/drm/ttm/ttm_bo.c
33617+++ b/drivers/gpu/drm/ttm/ttm_bo.c
33618@@ -67,7 +67,7 @@ static struct attribute *ttm_bo_global_attrs[] = {
33619 NULL
33620 };
33621
33622-static struct sysfs_ops ttm_bo_global_ops = {
33623+static const struct sysfs_ops ttm_bo_global_ops = {
33624 .show = &ttm_bo_global_show
33625 };
33626
33627diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
33628index 1c040d0..f9e4af8 100644
33629--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
33630+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
33631@@ -73,7 +73,7 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33632 {
33633 struct ttm_buffer_object *bo = (struct ttm_buffer_object *)
33634 vma->vm_private_data;
33635- struct ttm_bo_device *bdev = bo->bdev;
33636+ struct ttm_bo_device *bdev;
33637 unsigned long bus_base;
33638 unsigned long bus_offset;
33639 unsigned long bus_size;
33640@@ -88,6 +88,10 @@ static int ttm_bo_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33641 unsigned long address = (unsigned long)vmf->virtual_address;
33642 int retval = VM_FAULT_NOPAGE;
33643
33644+ if (!bo)
33645+ return VM_FAULT_NOPAGE;
33646+ bdev = bo->bdev;
33647+
33648 /*
33649 * Work around locking order reversal in fault / nopfn
33650 * between mmap_sem and bo_reserve: Perform a trylock operation
33651diff --git a/drivers/gpu/drm/ttm/ttm_global.c b/drivers/gpu/drm/ttm/ttm_global.c
33652index b170071..28ae90e 100644
33653--- a/drivers/gpu/drm/ttm/ttm_global.c
33654+++ b/drivers/gpu/drm/ttm/ttm_global.c
33655@@ -36,7 +36,7 @@
33656 struct ttm_global_item {
33657 struct mutex mutex;
33658 void *object;
33659- int refcount;
33660+ atomic_t refcount;
33661 };
33662
33663 static struct ttm_global_item glob[TTM_GLOBAL_NUM];
33664@@ -49,7 +49,7 @@ void ttm_global_init(void)
33665 struct ttm_global_item *item = &glob[i];
33666 mutex_init(&item->mutex);
33667 item->object = NULL;
33668- item->refcount = 0;
33669+ atomic_set(&item->refcount, 0);
33670 }
33671 }
33672
33673@@ -59,7 +59,7 @@ void ttm_global_release(void)
33674 for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
33675 struct ttm_global_item *item = &glob[i];
33676 BUG_ON(item->object != NULL);
33677- BUG_ON(item->refcount != 0);
33678+ BUG_ON(atomic_read(&item->refcount) != 0);
33679 }
33680 }
33681
33682@@ -70,7 +70,7 @@ int ttm_global_item_ref(struct ttm_global_reference *ref)
33683 void *object;
33684
33685 mutex_lock(&item->mutex);
33686- if (item->refcount == 0) {
33687+ if (atomic_read(&item->refcount) == 0) {
33688 item->object = kzalloc(ref->size, GFP_KERNEL);
33689 if (unlikely(item->object == NULL)) {
33690 ret = -ENOMEM;
33691@@ -83,7 +83,7 @@ int ttm_global_item_ref(struct ttm_global_reference *ref)
33692 goto out_err;
33693
33694 }
33695- ++item->refcount;
33696+ atomic_inc(&item->refcount);
33697 ref->object = item->object;
33698 object = item->object;
33699 mutex_unlock(&item->mutex);
33700@@ -100,9 +100,9 @@ void ttm_global_item_unref(struct ttm_global_reference *ref)
33701 struct ttm_global_item *item = &glob[ref->global_type];
33702
33703 mutex_lock(&item->mutex);
33704- BUG_ON(item->refcount == 0);
33705+ BUG_ON(atomic_read(&item->refcount) == 0);
33706 BUG_ON(ref->object != item->object);
33707- if (--item->refcount == 0) {
33708+ if (atomic_dec_and_test(&item->refcount)) {
33709 ref->release(ref);
33710 item->object = NULL;
33711 }
33712diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
33713index 072c281..d8ef483 100644
33714--- a/drivers/gpu/drm/ttm/ttm_memory.c
33715+++ b/drivers/gpu/drm/ttm/ttm_memory.c
33716@@ -152,7 +152,7 @@ static struct attribute *ttm_mem_zone_attrs[] = {
33717 NULL
33718 };
33719
33720-static struct sysfs_ops ttm_mem_zone_ops = {
33721+static const struct sysfs_ops ttm_mem_zone_ops = {
33722 .show = &ttm_mem_zone_show,
33723 .store = &ttm_mem_zone_store
33724 };
33725diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33726index cafcb84..b8e66cc 100644
33727--- a/drivers/gpu/drm/via/via_drv.h
33728+++ b/drivers/gpu/drm/via/via_drv.h
33729@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33730 typedef uint32_t maskarray_t[5];
33731
33732 typedef struct drm_via_irq {
33733- atomic_t irq_received;
33734+ atomic_unchecked_t irq_received;
33735 uint32_t pending_mask;
33736 uint32_t enable_mask;
33737 wait_queue_head_t irq_queue;
33738@@ -75,7 +75,7 @@ typedef struct drm_via_private {
33739 struct timeval last_vblank;
33740 int last_vblank_valid;
33741 unsigned usec_per_vblank;
33742- atomic_t vbl_received;
33743+ atomic_unchecked_t vbl_received;
33744 drm_via_state_t hc_state;
33745 char pci_buf[VIA_PCI_BUF_SIZE];
33746 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33747diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33748index 5935b88..127a8a6 100644
33749--- a/drivers/gpu/drm/via/via_irq.c
33750+++ b/drivers/gpu/drm/via/via_irq.c
33751@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33752 if (crtc != 0)
33753 return 0;
33754
33755- return atomic_read(&dev_priv->vbl_received);
33756+ return atomic_read_unchecked(&dev_priv->vbl_received);
33757 }
33758
33759 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33760@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33761
33762 status = VIA_READ(VIA_REG_INTERRUPT);
33763 if (status & VIA_IRQ_VBLANK_PENDING) {
33764- atomic_inc(&dev_priv->vbl_received);
33765- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33766+ atomic_inc_unchecked(&dev_priv->vbl_received);
33767+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33768 do_gettimeofday(&cur_vblank);
33769 if (dev_priv->last_vblank_valid) {
33770 dev_priv->usec_per_vblank =
33771@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33772 dev_priv->last_vblank = cur_vblank;
33773 dev_priv->last_vblank_valid = 1;
33774 }
33775- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33776+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33777 DRM_DEBUG("US per vblank is: %u\n",
33778 dev_priv->usec_per_vblank);
33779 }
33780@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33781
33782 for (i = 0; i < dev_priv->num_irqs; ++i) {
33783 if (status & cur_irq->pending_mask) {
33784- atomic_inc(&cur_irq->irq_received);
33785+ atomic_inc_unchecked(&cur_irq->irq_received);
33786 DRM_WAKEUP(&cur_irq->irq_queue);
33787 handled = 1;
33788 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i) {
33789@@ -244,11 +244,11 @@ via_driver_irq_wait(struct drm_device * dev, unsigned int irq, int force_sequenc
33790 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33791 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33792 masks[irq][4]));
33793- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33794+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33795 } else {
33796 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33797 (((cur_irq_sequence =
33798- atomic_read(&cur_irq->irq_received)) -
33799+ atomic_read_unchecked(&cur_irq->irq_received)) -
33800 *sequence) <= (1 << 23)));
33801 }
33802 *sequence = cur_irq_sequence;
33803@@ -286,7 +286,7 @@ void via_driver_irq_preinstall(struct drm_device * dev)
33804 }
33805
33806 for (i = 0; i < dev_priv->num_irqs; ++i) {
33807- atomic_set(&cur_irq->irq_received, 0);
33808+ atomic_set_unchecked(&cur_irq->irq_received, 0);
33809 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33810 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33811 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33812@@ -368,7 +368,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33813 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33814 case VIA_IRQ_RELATIVE:
33815 irqwait->request.sequence +=
33816- atomic_read(&cur_irq->irq_received);
33817+ atomic_read_unchecked(&cur_irq->irq_received);
33818 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33819 case VIA_IRQ_ABSOLUTE:
33820 break;
33821diff --git a/drivers/gpu/vga/vgaarb.c b/drivers/gpu/vga/vgaarb.c
33822index aa8688d..6a0140c 100644
33823--- a/drivers/gpu/vga/vgaarb.c
33824+++ b/drivers/gpu/vga/vgaarb.c
33825@@ -894,14 +894,20 @@ static ssize_t vga_arb_write(struct file *file, const char __user * buf,
33826 uc = &priv->cards[i];
33827 }
33828
33829- if (!uc)
33830- return -EINVAL;
33831+ if (!uc) {
33832+ ret_val = -EINVAL;
33833+ goto done;
33834+ }
33835
33836- if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0)
33837- return -EINVAL;
33838+ if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0) {
33839+ ret_val = -EINVAL;
33840+ goto done;
33841+ }
33842
33843- if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0)
33844- return -EINVAL;
33845+ if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0) {
33846+ ret_val = -EINVAL;
33847+ goto done;
33848+ }
33849
33850 vga_put(pdev, io_state);
33851
33852diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33853index f3f1415..e561d90 100644
33854--- a/drivers/hid/hid-core.c
33855+++ b/drivers/hid/hid-core.c
33856@@ -1752,7 +1752,7 @@ static bool hid_ignore(struct hid_device *hdev)
33857
33858 int hid_add_device(struct hid_device *hdev)
33859 {
33860- static atomic_t id = ATOMIC_INIT(0);
33861+ static atomic_unchecked_t id = ATOMIC_INIT(0);
33862 int ret;
33863
33864 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33865@@ -1766,7 +1766,7 @@ int hid_add_device(struct hid_device *hdev)
33866 /* XXX hack, any other cleaner solution after the driver core
33867 * is converted to allow more than 20 bytes as the device name? */
33868 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33869- hdev->vendor, hdev->product, atomic_inc_return(&id));
33870+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33871
33872 ret = device_add(&hdev->dev);
33873 if (!ret)
33874diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33875index 8b6ee24..70f657d 100644
33876--- a/drivers/hid/usbhid/hiddev.c
33877+++ b/drivers/hid/usbhid/hiddev.c
33878@@ -617,7 +617,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33879 return put_user(HID_VERSION, (int __user *)arg);
33880
33881 case HIDIOCAPPLICATION:
33882- if (arg < 0 || arg >= hid->maxapplication)
33883+ if (arg >= hid->maxapplication)
33884 return -EINVAL;
33885
33886 for (i = 0; i < hid->maxcollection; i++)
33887diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c
33888index 5d5ed69..f40533e 100644
33889--- a/drivers/hwmon/lis3lv02d.c
33890+++ b/drivers/hwmon/lis3lv02d.c
33891@@ -146,7 +146,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *dummy)
33892 * the lid is closed. This leads to interrupts as soon as a little move
33893 * is done.
33894 */
33895- atomic_inc(&lis3_dev.count);
33896+ atomic_inc_unchecked(&lis3_dev.count);
33897
33898 wake_up_interruptible(&lis3_dev.misc_wait);
33899 kill_fasync(&lis3_dev.async_queue, SIGIO, POLL_IN);
33900@@ -160,7 +160,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
33901 if (test_and_set_bit(0, &lis3_dev.misc_opened))
33902 return -EBUSY; /* already open */
33903
33904- atomic_set(&lis3_dev.count, 0);
33905+ atomic_set_unchecked(&lis3_dev.count, 0);
33906
33907 /*
33908 * The sensor can generate interrupts for free-fall and direction
33909@@ -206,7 +206,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
33910 add_wait_queue(&lis3_dev.misc_wait, &wait);
33911 while (true) {
33912 set_current_state(TASK_INTERRUPTIBLE);
33913- data = atomic_xchg(&lis3_dev.count, 0);
33914+ data = atomic_xchg_unchecked(&lis3_dev.count, 0);
33915 if (data)
33916 break;
33917
33918@@ -244,7 +244,7 @@ out:
33919 static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
33920 {
33921 poll_wait(file, &lis3_dev.misc_wait, wait);
33922- if (atomic_read(&lis3_dev.count))
33923+ if (atomic_read_unchecked(&lis3_dev.count))
33924 return POLLIN | POLLRDNORM;
33925 return 0;
33926 }
33927diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h
33928index 7cdd76f..fe0efdf 100644
33929--- a/drivers/hwmon/lis3lv02d.h
33930+++ b/drivers/hwmon/lis3lv02d.h
33931@@ -201,7 +201,7 @@ struct lis3lv02d {
33932
33933 struct input_polled_dev *idev; /* input device */
33934 struct platform_device *pdev; /* platform device */
33935- atomic_t count; /* interrupt count after last read */
33936+ atomic_unchecked_t count; /* interrupt count after last read */
33937 int xcalib; /* calibrated null value for x */
33938 int ycalib; /* calibrated null value for y */
33939 int zcalib; /* calibrated null value for z */
33940diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33941index 2040507..706ec1e 100644
33942--- a/drivers/hwmon/sht15.c
33943+++ b/drivers/hwmon/sht15.c
33944@@ -112,7 +112,7 @@ struct sht15_data {
33945 int supply_uV;
33946 int supply_uV_valid;
33947 struct work_struct update_supply_work;
33948- atomic_t interrupt_handled;
33949+ atomic_unchecked_t interrupt_handled;
33950 };
33951
33952 /**
33953@@ -245,13 +245,13 @@ static inline int sht15_update_single_val(struct sht15_data *data,
33954 return ret;
33955
33956 gpio_direction_input(data->pdata->gpio_data);
33957- atomic_set(&data->interrupt_handled, 0);
33958+ atomic_set_unchecked(&data->interrupt_handled, 0);
33959
33960 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33961 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33962 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33963 /* Only relevant if the interrupt hasn't occured. */
33964- if (!atomic_read(&data->interrupt_handled))
33965+ if (!atomic_read_unchecked(&data->interrupt_handled))
33966 schedule_work(&data->read_work);
33967 }
33968 ret = wait_event_timeout(data->wait_queue,
33969@@ -398,7 +398,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33970 struct sht15_data *data = d;
33971 /* First disable the interrupt */
33972 disable_irq_nosync(irq);
33973- atomic_inc(&data->interrupt_handled);
33974+ atomic_inc_unchecked(&data->interrupt_handled);
33975 /* Then schedule a reading work struct */
33976 if (data->flag != SHT15_READING_NOTHING)
33977 schedule_work(&data->read_work);
33978@@ -449,11 +449,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33979 here as could have gone low in meantime so verify
33980 it hasn't!
33981 */
33982- atomic_set(&data->interrupt_handled, 0);
33983+ atomic_set_unchecked(&data->interrupt_handled, 0);
33984 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33985 /* If still not occured or another handler has been scheduled */
33986 if (gpio_get_value(data->pdata->gpio_data)
33987- || atomic_read(&data->interrupt_handled))
33988+ || atomic_read_unchecked(&data->interrupt_handled))
33989 return;
33990 }
33991 /* Read the data back from the device */
33992diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
33993index 97851c5..cb40626 100644
33994--- a/drivers/hwmon/w83791d.c
33995+++ b/drivers/hwmon/w83791d.c
33996@@ -330,8 +330,8 @@ static int w83791d_detect(struct i2c_client *client, int kind,
33997 struct i2c_board_info *info);
33998 static int w83791d_remove(struct i2c_client *client);
33999
34000-static int w83791d_read(struct i2c_client *client, u8 register);
34001-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
34002+static int w83791d_read(struct i2c_client *client, u8 reg);
34003+static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
34004 static struct w83791d_data *w83791d_update_device(struct device *dev);
34005
34006 #ifdef DEBUG
34007diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
34008index 378fcb5..5e91fa8 100644
34009--- a/drivers/i2c/busses/i2c-amd756-s4882.c
34010+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
34011@@ -43,7 +43,7 @@
34012 extern struct i2c_adapter amd756_smbus;
34013
34014 static struct i2c_adapter *s4882_adapter;
34015-static struct i2c_algorithm *s4882_algo;
34016+static i2c_algorithm_no_const *s4882_algo;
34017
34018 /* Wrapper access functions for multiplexed SMBus */
34019 static DEFINE_MUTEX(amd756_lock);
34020diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
34021index 29015eb..af2d8e9 100644
34022--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
34023+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
34024@@ -41,7 +41,7 @@
34025 extern struct i2c_adapter *nforce2_smbus;
34026
34027 static struct i2c_adapter *s4985_adapter;
34028-static struct i2c_algorithm *s4985_algo;
34029+static i2c_algorithm_no_const *s4985_algo;
34030
34031 /* Wrapper access functions for multiplexed SMBus */
34032 static DEFINE_MUTEX(nforce2_lock);
34033diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
34034index 878f8ec..12376fc 100644
34035--- a/drivers/ide/aec62xx.c
34036+++ b/drivers/ide/aec62xx.c
34037@@ -180,7 +180,7 @@ static const struct ide_port_ops atp86x_port_ops = {
34038 .cable_detect = atp86x_cable_detect,
34039 };
34040
34041-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
34042+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
34043 { /* 0: AEC6210 */
34044 .name = DRV_NAME,
34045 .init_chipset = init_chipset_aec62xx,
34046diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
34047index e59b6de..4b4fc65 100644
34048--- a/drivers/ide/alim15x3.c
34049+++ b/drivers/ide/alim15x3.c
34050@@ -509,7 +509,7 @@ static const struct ide_dma_ops ali_dma_ops = {
34051 .dma_sff_read_status = ide_dma_sff_read_status,
34052 };
34053
34054-static const struct ide_port_info ali15x3_chipset __devinitdata = {
34055+static const struct ide_port_info ali15x3_chipset __devinitconst = {
34056 .name = DRV_NAME,
34057 .init_chipset = init_chipset_ali15x3,
34058 .init_hwif = init_hwif_ali15x3,
34059diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
34060index 628cd2e..087a414 100644
34061--- a/drivers/ide/amd74xx.c
34062+++ b/drivers/ide/amd74xx.c
34063@@ -221,7 +221,7 @@ static const struct ide_port_ops amd_port_ops = {
34064 .udma_mask = udma, \
34065 }
34066
34067-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
34068+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
34069 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
34070 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
34071 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
34072diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
34073index 837322b..837fd71 100644
34074--- a/drivers/ide/atiixp.c
34075+++ b/drivers/ide/atiixp.c
34076@@ -137,7 +137,7 @@ static const struct ide_port_ops atiixp_port_ops = {
34077 .cable_detect = atiixp_cable_detect,
34078 };
34079
34080-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
34081+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
34082 { /* 0: IXP200/300/400/700 */
34083 .name = DRV_NAME,
34084 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
34085diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
34086index ca0c46f..d55318a 100644
34087--- a/drivers/ide/cmd64x.c
34088+++ b/drivers/ide/cmd64x.c
34089@@ -372,7 +372,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
34090 .dma_sff_read_status = ide_dma_sff_read_status,
34091 };
34092
34093-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
34094+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
34095 { /* 0: CMD643 */
34096 .name = DRV_NAME,
34097 .init_chipset = init_chipset_cmd64x,
34098diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
34099index 09f98ed..cebc5bc 100644
34100--- a/drivers/ide/cs5520.c
34101+++ b/drivers/ide/cs5520.c
34102@@ -93,7 +93,7 @@ static const struct ide_port_ops cs5520_port_ops = {
34103 .set_dma_mode = cs5520_set_dma_mode,
34104 };
34105
34106-static const struct ide_port_info cyrix_chipset __devinitdata = {
34107+static const struct ide_port_info cyrix_chipset __devinitconst = {
34108 .name = DRV_NAME,
34109 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
34110 .port_ops = &cs5520_port_ops,
34111diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
34112index 40bf05e..7d58ca0 100644
34113--- a/drivers/ide/cs5530.c
34114+++ b/drivers/ide/cs5530.c
34115@@ -244,7 +244,7 @@ static const struct ide_port_ops cs5530_port_ops = {
34116 .udma_filter = cs5530_udma_filter,
34117 };
34118
34119-static const struct ide_port_info cs5530_chipset __devinitdata = {
34120+static const struct ide_port_info cs5530_chipset __devinitconst = {
34121 .name = DRV_NAME,
34122 .init_chipset = init_chipset_cs5530,
34123 .init_hwif = init_hwif_cs5530,
34124diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
34125index 983d957..53e6172 100644
34126--- a/drivers/ide/cs5535.c
34127+++ b/drivers/ide/cs5535.c
34128@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
34129 .cable_detect = cs5535_cable_detect,
34130 };
34131
34132-static const struct ide_port_info cs5535_chipset __devinitdata = {
34133+static const struct ide_port_info cs5535_chipset __devinitconst = {
34134 .name = DRV_NAME,
34135 .port_ops = &cs5535_port_ops,
34136 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
34137diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
34138index 74fc540..8e933d8 100644
34139--- a/drivers/ide/cy82c693.c
34140+++ b/drivers/ide/cy82c693.c
34141@@ -288,7 +288,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
34142 .set_dma_mode = cy82c693_set_dma_mode,
34143 };
34144
34145-static const struct ide_port_info cy82c693_chipset __devinitdata = {
34146+static const struct ide_port_info cy82c693_chipset __devinitconst = {
34147 .name = DRV_NAME,
34148 .init_iops = init_iops_cy82c693,
34149 .port_ops = &cy82c693_port_ops,
34150diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
34151index 7ce68ef..e78197d 100644
34152--- a/drivers/ide/hpt366.c
34153+++ b/drivers/ide/hpt366.c
34154@@ -507,7 +507,7 @@ static struct hpt_timings hpt37x_timings = {
34155 }
34156 };
34157
34158-static const struct hpt_info hpt36x __devinitdata = {
34159+static const struct hpt_info hpt36x __devinitconst = {
34160 .chip_name = "HPT36x",
34161 .chip_type = HPT36x,
34162 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
34163@@ -515,7 +515,7 @@ static const struct hpt_info hpt36x __devinitdata = {
34164 .timings = &hpt36x_timings
34165 };
34166
34167-static const struct hpt_info hpt370 __devinitdata = {
34168+static const struct hpt_info hpt370 __devinitconst = {
34169 .chip_name = "HPT370",
34170 .chip_type = HPT370,
34171 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
34172@@ -523,7 +523,7 @@ static const struct hpt_info hpt370 __devinitdata = {
34173 .timings = &hpt37x_timings
34174 };
34175
34176-static const struct hpt_info hpt370a __devinitdata = {
34177+static const struct hpt_info hpt370a __devinitconst = {
34178 .chip_name = "HPT370A",
34179 .chip_type = HPT370A,
34180 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
34181@@ -531,7 +531,7 @@ static const struct hpt_info hpt370a __devinitdata = {
34182 .timings = &hpt37x_timings
34183 };
34184
34185-static const struct hpt_info hpt374 __devinitdata = {
34186+static const struct hpt_info hpt374 __devinitconst = {
34187 .chip_name = "HPT374",
34188 .chip_type = HPT374,
34189 .udma_mask = ATA_UDMA5,
34190@@ -539,7 +539,7 @@ static const struct hpt_info hpt374 __devinitdata = {
34191 .timings = &hpt37x_timings
34192 };
34193
34194-static const struct hpt_info hpt372 __devinitdata = {
34195+static const struct hpt_info hpt372 __devinitconst = {
34196 .chip_name = "HPT372",
34197 .chip_type = HPT372,
34198 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34199@@ -547,7 +547,7 @@ static const struct hpt_info hpt372 __devinitdata = {
34200 .timings = &hpt37x_timings
34201 };
34202
34203-static const struct hpt_info hpt372a __devinitdata = {
34204+static const struct hpt_info hpt372a __devinitconst = {
34205 .chip_name = "HPT372A",
34206 .chip_type = HPT372A,
34207 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34208@@ -555,7 +555,7 @@ static const struct hpt_info hpt372a __devinitdata = {
34209 .timings = &hpt37x_timings
34210 };
34211
34212-static const struct hpt_info hpt302 __devinitdata = {
34213+static const struct hpt_info hpt302 __devinitconst = {
34214 .chip_name = "HPT302",
34215 .chip_type = HPT302,
34216 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34217@@ -563,7 +563,7 @@ static const struct hpt_info hpt302 __devinitdata = {
34218 .timings = &hpt37x_timings
34219 };
34220
34221-static const struct hpt_info hpt371 __devinitdata = {
34222+static const struct hpt_info hpt371 __devinitconst = {
34223 .chip_name = "HPT371",
34224 .chip_type = HPT371,
34225 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34226@@ -571,7 +571,7 @@ static const struct hpt_info hpt371 __devinitdata = {
34227 .timings = &hpt37x_timings
34228 };
34229
34230-static const struct hpt_info hpt372n __devinitdata = {
34231+static const struct hpt_info hpt372n __devinitconst = {
34232 .chip_name = "HPT372N",
34233 .chip_type = HPT372N,
34234 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34235@@ -579,7 +579,7 @@ static const struct hpt_info hpt372n __devinitdata = {
34236 .timings = &hpt37x_timings
34237 };
34238
34239-static const struct hpt_info hpt302n __devinitdata = {
34240+static const struct hpt_info hpt302n __devinitconst = {
34241 .chip_name = "HPT302N",
34242 .chip_type = HPT302N,
34243 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34244@@ -587,7 +587,7 @@ static const struct hpt_info hpt302n __devinitdata = {
34245 .timings = &hpt37x_timings
34246 };
34247
34248-static const struct hpt_info hpt371n __devinitdata = {
34249+static const struct hpt_info hpt371n __devinitconst = {
34250 .chip_name = "HPT371N",
34251 .chip_type = HPT371N,
34252 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
34253@@ -1422,7 +1422,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
34254 .dma_sff_read_status = ide_dma_sff_read_status,
34255 };
34256
34257-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
34258+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
34259 { /* 0: HPT36x */
34260 .name = DRV_NAME,
34261 .init_chipset = init_chipset_hpt366,
34262diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
34263index 2de76cc..74186a1 100644
34264--- a/drivers/ide/ide-cd.c
34265+++ b/drivers/ide/ide-cd.c
34266@@ -774,7 +774,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
34267 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
34268 if ((unsigned long)buf & alignment
34269 || blk_rq_bytes(rq) & q->dma_pad_mask
34270- || object_is_on_stack(buf))
34271+ || object_starts_on_stack(buf))
34272 drive->dma = 0;
34273 }
34274 }
34275diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
34276index fefbdfc..62ff465 100644
34277--- a/drivers/ide/ide-floppy.c
34278+++ b/drivers/ide/ide-floppy.c
34279@@ -373,6 +373,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
34280 u8 pc_buf[256], header_len, desc_cnt;
34281 int i, rc = 1, blocks, length;
34282
34283+ pax_track_stack();
34284+
34285 ide_debug_log(IDE_DBG_FUNC, "enter");
34286
34287 drive->bios_cyl = 0;
34288diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
34289index 39d4e01..11538ce 100644
34290--- a/drivers/ide/ide-pci-generic.c
34291+++ b/drivers/ide/ide-pci-generic.c
34292@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
34293 .udma_mask = ATA_UDMA6, \
34294 }
34295
34296-static const struct ide_port_info generic_chipsets[] __devinitdata = {
34297+static const struct ide_port_info generic_chipsets[] __devinitconst = {
34298 /* 0: Unknown */
34299 DECLARE_GENERIC_PCI_DEV(0),
34300
34301diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
34302index 0d266a5..aaca790 100644
34303--- a/drivers/ide/it8172.c
34304+++ b/drivers/ide/it8172.c
34305@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
34306 .set_dma_mode = it8172_set_dma_mode,
34307 };
34308
34309-static const struct ide_port_info it8172_port_info __devinitdata = {
34310+static const struct ide_port_info it8172_port_info __devinitconst = {
34311 .name = DRV_NAME,
34312 .port_ops = &it8172_port_ops,
34313 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
34314diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
34315index 4797616..4be488a 100644
34316--- a/drivers/ide/it8213.c
34317+++ b/drivers/ide/it8213.c
34318@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
34319 .cable_detect = it8213_cable_detect,
34320 };
34321
34322-static const struct ide_port_info it8213_chipset __devinitdata = {
34323+static const struct ide_port_info it8213_chipset __devinitconst = {
34324 .name = DRV_NAME,
34325 .enablebits = { {0x41, 0x80, 0x80} },
34326 .port_ops = &it8213_port_ops,
34327diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
34328index 51aa745..146ee60 100644
34329--- a/drivers/ide/it821x.c
34330+++ b/drivers/ide/it821x.c
34331@@ -627,7 +627,7 @@ static const struct ide_port_ops it821x_port_ops = {
34332 .cable_detect = it821x_cable_detect,
34333 };
34334
34335-static const struct ide_port_info it821x_chipset __devinitdata = {
34336+static const struct ide_port_info it821x_chipset __devinitconst = {
34337 .name = DRV_NAME,
34338 .init_chipset = init_chipset_it821x,
34339 .init_hwif = init_hwif_it821x,
34340diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
34341index bf2be64..9270098 100644
34342--- a/drivers/ide/jmicron.c
34343+++ b/drivers/ide/jmicron.c
34344@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
34345 .cable_detect = jmicron_cable_detect,
34346 };
34347
34348-static const struct ide_port_info jmicron_chipset __devinitdata = {
34349+static const struct ide_port_info jmicron_chipset __devinitconst = {
34350 .name = DRV_NAME,
34351 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
34352 .port_ops = &jmicron_port_ops,
34353diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
34354index 95327a2..73f78d8 100644
34355--- a/drivers/ide/ns87415.c
34356+++ b/drivers/ide/ns87415.c
34357@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
34358 .dma_sff_read_status = superio_dma_sff_read_status,
34359 };
34360
34361-static const struct ide_port_info ns87415_chipset __devinitdata = {
34362+static const struct ide_port_info ns87415_chipset __devinitconst = {
34363 .name = DRV_NAME,
34364 .init_hwif = init_hwif_ns87415,
34365 .tp_ops = &ns87415_tp_ops,
34366diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
34367index f1d70d6..e1de05b 100644
34368--- a/drivers/ide/opti621.c
34369+++ b/drivers/ide/opti621.c
34370@@ -202,7 +202,7 @@ static const struct ide_port_ops opti621_port_ops = {
34371 .set_pio_mode = opti621_set_pio_mode,
34372 };
34373
34374-static const struct ide_port_info opti621_chipset __devinitdata = {
34375+static const struct ide_port_info opti621_chipset __devinitconst = {
34376 .name = DRV_NAME,
34377 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
34378 .port_ops = &opti621_port_ops,
34379diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
34380index 65ba823..7311f4d 100644
34381--- a/drivers/ide/pdc202xx_new.c
34382+++ b/drivers/ide/pdc202xx_new.c
34383@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
34384 .udma_mask = udma, \
34385 }
34386
34387-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
34388+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
34389 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
34390 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
34391 };
34392diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
34393index cb812f3..af816ef 100644
34394--- a/drivers/ide/pdc202xx_old.c
34395+++ b/drivers/ide/pdc202xx_old.c
34396@@ -285,7 +285,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
34397 .max_sectors = sectors, \
34398 }
34399
34400-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
34401+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
34402 { /* 0: PDC20246 */
34403 .name = DRV_NAME,
34404 .init_chipset = init_chipset_pdc202xx,
34405diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
34406index bf14f39..15c4b98 100644
34407--- a/drivers/ide/piix.c
34408+++ b/drivers/ide/piix.c
34409@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
34410 .udma_mask = udma, \
34411 }
34412
34413-static const struct ide_port_info piix_pci_info[] __devinitdata = {
34414+static const struct ide_port_info piix_pci_info[] __devinitconst = {
34415 /* 0: MPIIX */
34416 { /*
34417 * MPIIX actually has only a single IDE channel mapped to
34418diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
34419index a6414a8..c04173e 100644
34420--- a/drivers/ide/rz1000.c
34421+++ b/drivers/ide/rz1000.c
34422@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
34423 }
34424 }
34425
34426-static const struct ide_port_info rz1000_chipset __devinitdata = {
34427+static const struct ide_port_info rz1000_chipset __devinitconst = {
34428 .name = DRV_NAME,
34429 .host_flags = IDE_HFLAG_NO_DMA,
34430 };
34431diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
34432index d467478..9203942 100644
34433--- a/drivers/ide/sc1200.c
34434+++ b/drivers/ide/sc1200.c
34435@@ -290,7 +290,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
34436 .dma_sff_read_status = ide_dma_sff_read_status,
34437 };
34438
34439-static const struct ide_port_info sc1200_chipset __devinitdata = {
34440+static const struct ide_port_info sc1200_chipset __devinitconst = {
34441 .name = DRV_NAME,
34442 .port_ops = &sc1200_port_ops,
34443 .dma_ops = &sc1200_dma_ops,
34444diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
34445index 1104bb3..59c5194 100644
34446--- a/drivers/ide/scc_pata.c
34447+++ b/drivers/ide/scc_pata.c
34448@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
34449 .dma_sff_read_status = scc_dma_sff_read_status,
34450 };
34451
34452-static const struct ide_port_info scc_chipset __devinitdata = {
34453+static const struct ide_port_info scc_chipset __devinitconst = {
34454 .name = "sccIDE",
34455 .init_iops = init_iops_scc,
34456 .init_dma = scc_init_dma,
34457diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
34458index b6554ef..6cc2cc3 100644
34459--- a/drivers/ide/serverworks.c
34460+++ b/drivers/ide/serverworks.c
34461@@ -353,7 +353,7 @@ static const struct ide_port_ops svwks_port_ops = {
34462 .cable_detect = svwks_cable_detect,
34463 };
34464
34465-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
34466+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
34467 { /* 0: OSB4 */
34468 .name = DRV_NAME,
34469 .init_chipset = init_chipset_svwks,
34470diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
34471index ab3db61..afed580 100644
34472--- a/drivers/ide/setup-pci.c
34473+++ b/drivers/ide/setup-pci.c
34474@@ -542,6 +542,8 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
34475 int ret, i, n_ports = dev2 ? 4 : 2;
34476 struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
34477
34478+ pax_track_stack();
34479+
34480 for (i = 0; i < n_ports / 2; i++) {
34481 ret = ide_setup_pci_controller(pdev[i], d, !i);
34482 if (ret < 0)
34483diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
34484index d95df52..0b03a39 100644
34485--- a/drivers/ide/siimage.c
34486+++ b/drivers/ide/siimage.c
34487@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
34488 .udma_mask = ATA_UDMA6, \
34489 }
34490
34491-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
34492+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
34493 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
34494 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
34495 };
34496diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
34497index 3b88eba..ca8699d 100644
34498--- a/drivers/ide/sis5513.c
34499+++ b/drivers/ide/sis5513.c
34500@@ -561,7 +561,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
34501 .cable_detect = sis_cable_detect,
34502 };
34503
34504-static const struct ide_port_info sis5513_chipset __devinitdata = {
34505+static const struct ide_port_info sis5513_chipset __devinitconst = {
34506 .name = DRV_NAME,
34507 .init_chipset = init_chipset_sis5513,
34508 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
34509diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
34510index d698da4..fca42a4 100644
34511--- a/drivers/ide/sl82c105.c
34512+++ b/drivers/ide/sl82c105.c
34513@@ -319,7 +319,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
34514 .dma_sff_read_status = ide_dma_sff_read_status,
34515 };
34516
34517-static const struct ide_port_info sl82c105_chipset __devinitdata = {
34518+static const struct ide_port_info sl82c105_chipset __devinitconst = {
34519 .name = DRV_NAME,
34520 .init_chipset = init_chipset_sl82c105,
34521 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
34522diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
34523index 1ccfb40..83d5779 100644
34524--- a/drivers/ide/slc90e66.c
34525+++ b/drivers/ide/slc90e66.c
34526@@ -131,7 +131,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
34527 .cable_detect = slc90e66_cable_detect,
34528 };
34529
34530-static const struct ide_port_info slc90e66_chipset __devinitdata = {
34531+static const struct ide_port_info slc90e66_chipset __devinitconst = {
34532 .name = DRV_NAME,
34533 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
34534 .port_ops = &slc90e66_port_ops,
34535diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
34536index 05a93d6..5f9e325 100644
34537--- a/drivers/ide/tc86c001.c
34538+++ b/drivers/ide/tc86c001.c
34539@@ -190,7 +190,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
34540 .dma_sff_read_status = ide_dma_sff_read_status,
34541 };
34542
34543-static const struct ide_port_info tc86c001_chipset __devinitdata = {
34544+static const struct ide_port_info tc86c001_chipset __devinitconst = {
34545 .name = DRV_NAME,
34546 .init_hwif = init_hwif_tc86c001,
34547 .port_ops = &tc86c001_port_ops,
34548diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
34549index 8773c3b..7907d6c 100644
34550--- a/drivers/ide/triflex.c
34551+++ b/drivers/ide/triflex.c
34552@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
34553 .set_dma_mode = triflex_set_mode,
34554 };
34555
34556-static const struct ide_port_info triflex_device __devinitdata = {
34557+static const struct ide_port_info triflex_device __devinitconst = {
34558 .name = DRV_NAME,
34559 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
34560 .port_ops = &triflex_port_ops,
34561diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
34562index 4b42ca0..e494a98 100644
34563--- a/drivers/ide/trm290.c
34564+++ b/drivers/ide/trm290.c
34565@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
34566 .dma_check = trm290_dma_check,
34567 };
34568
34569-static const struct ide_port_info trm290_chipset __devinitdata = {
34570+static const struct ide_port_info trm290_chipset __devinitconst = {
34571 .name = DRV_NAME,
34572 .init_hwif = init_hwif_trm290,
34573 .tp_ops = &trm290_tp_ops,
34574diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
34575index 028de26..520d5d5 100644
34576--- a/drivers/ide/via82cxxx.c
34577+++ b/drivers/ide/via82cxxx.c
34578@@ -374,7 +374,7 @@ static const struct ide_port_ops via_port_ops = {
34579 .cable_detect = via82cxxx_cable_detect,
34580 };
34581
34582-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
34583+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
34584 .name = DRV_NAME,
34585 .init_chipset = init_chipset_via82cxxx,
34586 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
34587diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
34588index 2cd00b5..14de699 100644
34589--- a/drivers/ieee1394/dv1394.c
34590+++ b/drivers/ieee1394/dv1394.c
34591@@ -739,7 +739,7 @@ static void frame_prepare(struct video_card *video, unsigned int this_frame)
34592 based upon DIF section and sequence
34593 */
34594
34595-static void inline
34596+static inline void
34597 frame_put_packet (struct frame *f, struct packet *p)
34598 {
34599 int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
34600diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c
34601index e947d8f..6a966b9 100644
34602--- a/drivers/ieee1394/hosts.c
34603+++ b/drivers/ieee1394/hosts.c
34604@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso *iso, enum isoctl_cmd command,
34605 }
34606
34607 static struct hpsb_host_driver dummy_driver = {
34608+ .name = "dummy",
34609 .transmit_packet = dummy_transmit_packet,
34610 .devctl = dummy_devctl,
34611 .isoctl = dummy_isoctl
34612diff --git a/drivers/ieee1394/init_ohci1394_dma.c b/drivers/ieee1394/init_ohci1394_dma.c
34613index ddaab6e..8d37435 100644
34614--- a/drivers/ieee1394/init_ohci1394_dma.c
34615+++ b/drivers/ieee1394/init_ohci1394_dma.c
34616@@ -257,7 +257,7 @@ void __init init_ohci1394_dma_on_all_controllers(void)
34617 for (func = 0; func < 8; func++) {
34618 u32 class = read_pci_config(num,slot,func,
34619 PCI_CLASS_REVISION);
34620- if ((class == 0xffffffff))
34621+ if (class == 0xffffffff)
34622 continue; /* No device at this func */
34623
34624 if (class>>8 != PCI_CLASS_SERIAL_FIREWIRE_OHCI)
34625diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c
34626index 65c1429..5d8c11f 100644
34627--- a/drivers/ieee1394/ohci1394.c
34628+++ b/drivers/ieee1394/ohci1394.c
34629@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_DRIVER_NAME , ## args)
34630 printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
34631
34632 /* Module Parameters */
34633-static int phys_dma = 1;
34634+static int phys_dma;
34635 module_param(phys_dma, int, 0444);
34636-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
34637+MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
34638
34639 static void dma_trm_tasklet(unsigned long data);
34640 static void dma_trm_reset(struct dma_trm_ctx *d);
34641diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
34642index f199896..78c9fc8 100644
34643--- a/drivers/ieee1394/sbp2.c
34644+++ b/drivers/ieee1394/sbp2.c
34645@@ -2111,7 +2111,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver");
34646 MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
34647 MODULE_LICENSE("GPL");
34648
34649-static int sbp2_module_init(void)
34650+static int __init sbp2_module_init(void)
34651 {
34652 int ret;
34653
34654diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
34655index a5dea6b..0cefe8f 100644
34656--- a/drivers/infiniband/core/cm.c
34657+++ b/drivers/infiniband/core/cm.c
34658@@ -112,7 +112,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
34659
34660 struct cm_counter_group {
34661 struct kobject obj;
34662- atomic_long_t counter[CM_ATTR_COUNT];
34663+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
34664 };
34665
34666 struct cm_counter_attribute {
34667@@ -1386,7 +1386,7 @@ static void cm_dup_req_handler(struct cm_work *work,
34668 struct ib_mad_send_buf *msg = NULL;
34669 int ret;
34670
34671- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34672+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34673 counter[CM_REQ_COUNTER]);
34674
34675 /* Quick state check to discard duplicate REQs. */
34676@@ -1764,7 +1764,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
34677 if (!cm_id_priv)
34678 return;
34679
34680- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34681+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34682 counter[CM_REP_COUNTER]);
34683 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
34684 if (ret)
34685@@ -1931,7 +1931,7 @@ static int cm_rtu_handler(struct cm_work *work)
34686 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
34687 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
34688 spin_unlock_irq(&cm_id_priv->lock);
34689- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34690+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34691 counter[CM_RTU_COUNTER]);
34692 goto out;
34693 }
34694@@ -2110,7 +2110,7 @@ static int cm_dreq_handler(struct cm_work *work)
34695 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
34696 dreq_msg->local_comm_id);
34697 if (!cm_id_priv) {
34698- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34699+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34700 counter[CM_DREQ_COUNTER]);
34701 cm_issue_drep(work->port, work->mad_recv_wc);
34702 return -EINVAL;
34703@@ -2131,7 +2131,7 @@ static int cm_dreq_handler(struct cm_work *work)
34704 case IB_CM_MRA_REP_RCVD:
34705 break;
34706 case IB_CM_TIMEWAIT:
34707- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34708+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34709 counter[CM_DREQ_COUNTER]);
34710 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34711 goto unlock;
34712@@ -2145,7 +2145,7 @@ static int cm_dreq_handler(struct cm_work *work)
34713 cm_free_msg(msg);
34714 goto deref;
34715 case IB_CM_DREQ_RCVD:
34716- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34717+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34718 counter[CM_DREQ_COUNTER]);
34719 goto unlock;
34720 default:
34721@@ -2501,7 +2501,7 @@ static int cm_mra_handler(struct cm_work *work)
34722 ib_modify_mad(cm_id_priv->av.port->mad_agent,
34723 cm_id_priv->msg, timeout)) {
34724 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
34725- atomic_long_inc(&work->port->
34726+ atomic_long_inc_unchecked(&work->port->
34727 counter_group[CM_RECV_DUPLICATES].
34728 counter[CM_MRA_COUNTER]);
34729 goto out;
34730@@ -2510,7 +2510,7 @@ static int cm_mra_handler(struct cm_work *work)
34731 break;
34732 case IB_CM_MRA_REQ_RCVD:
34733 case IB_CM_MRA_REP_RCVD:
34734- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34735+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34736 counter[CM_MRA_COUNTER]);
34737 /* fall through */
34738 default:
34739@@ -2672,7 +2672,7 @@ static int cm_lap_handler(struct cm_work *work)
34740 case IB_CM_LAP_IDLE:
34741 break;
34742 case IB_CM_MRA_LAP_SENT:
34743- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34744+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34745 counter[CM_LAP_COUNTER]);
34746 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34747 goto unlock;
34748@@ -2688,7 +2688,7 @@ static int cm_lap_handler(struct cm_work *work)
34749 cm_free_msg(msg);
34750 goto deref;
34751 case IB_CM_LAP_RCVD:
34752- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34753+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34754 counter[CM_LAP_COUNTER]);
34755 goto unlock;
34756 default:
34757@@ -2972,7 +2972,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
34758 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34759 if (cur_cm_id_priv) {
34760 spin_unlock_irq(&cm.lock);
34761- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34762+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34763 counter[CM_SIDR_REQ_COUNTER]);
34764 goto out; /* Duplicate message. */
34765 }
34766@@ -3184,10 +3184,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34767 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34768 msg->retries = 1;
34769
34770- atomic_long_add(1 + msg->retries,
34771+ atomic_long_add_unchecked(1 + msg->retries,
34772 &port->counter_group[CM_XMIT].counter[attr_index]);
34773 if (msg->retries)
34774- atomic_long_add(msg->retries,
34775+ atomic_long_add_unchecked(msg->retries,
34776 &port->counter_group[CM_XMIT_RETRIES].
34777 counter[attr_index]);
34778
34779@@ -3397,7 +3397,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34780 }
34781
34782 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34783- atomic_long_inc(&port->counter_group[CM_RECV].
34784+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34785 counter[attr_id - CM_ATTR_ID_OFFSET]);
34786
34787 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34788@@ -3595,10 +3595,10 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34789 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34790
34791 return sprintf(buf, "%ld\n",
34792- atomic_long_read(&group->counter[cm_attr->index]));
34793+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34794 }
34795
34796-static struct sysfs_ops cm_counter_ops = {
34797+static const struct sysfs_ops cm_counter_ops = {
34798 .show = cm_show_counter
34799 };
34800
34801diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34802index 4507043..14ad522 100644
34803--- a/drivers/infiniband/core/fmr_pool.c
34804+++ b/drivers/infiniband/core/fmr_pool.c
34805@@ -97,8 +97,8 @@ struct ib_fmr_pool {
34806
34807 struct task_struct *thread;
34808
34809- atomic_t req_ser;
34810- atomic_t flush_ser;
34811+ atomic_unchecked_t req_ser;
34812+ atomic_unchecked_t flush_ser;
34813
34814 wait_queue_head_t force_wait;
34815 };
34816@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34817 struct ib_fmr_pool *pool = pool_ptr;
34818
34819 do {
34820- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34821+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34822 ib_fmr_batch_release(pool);
34823
34824- atomic_inc(&pool->flush_ser);
34825+ atomic_inc_unchecked(&pool->flush_ser);
34826 wake_up_interruptible(&pool->force_wait);
34827
34828 if (pool->flush_function)
34829@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34830 }
34831
34832 set_current_state(TASK_INTERRUPTIBLE);
34833- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34834+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34835 !kthread_should_stop())
34836 schedule();
34837 __set_current_state(TASK_RUNNING);
34838@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34839 pool->dirty_watermark = params->dirty_watermark;
34840 pool->dirty_len = 0;
34841 spin_lock_init(&pool->pool_lock);
34842- atomic_set(&pool->req_ser, 0);
34843- atomic_set(&pool->flush_ser, 0);
34844+ atomic_set_unchecked(&pool->req_ser, 0);
34845+ atomic_set_unchecked(&pool->flush_ser, 0);
34846 init_waitqueue_head(&pool->force_wait);
34847
34848 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34849@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34850 }
34851 spin_unlock_irq(&pool->pool_lock);
34852
34853- serial = atomic_inc_return(&pool->req_ser);
34854+ serial = atomic_inc_return_unchecked(&pool->req_ser);
34855 wake_up_process(pool->thread);
34856
34857 if (wait_event_interruptible(pool->force_wait,
34858- atomic_read(&pool->flush_ser) - serial >= 0))
34859+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34860 return -EINTR;
34861
34862 return 0;
34863@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34864 } else {
34865 list_add_tail(&fmr->list, &pool->dirty_list);
34866 if (++pool->dirty_len >= pool->dirty_watermark) {
34867- atomic_inc(&pool->req_ser);
34868+ atomic_inc_unchecked(&pool->req_ser);
34869 wake_up_process(pool->thread);
34870 }
34871 }
34872diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
34873index 158a214..1558bb7 100644
34874--- a/drivers/infiniband/core/sysfs.c
34875+++ b/drivers/infiniband/core/sysfs.c
34876@@ -79,7 +79,7 @@ static ssize_t port_attr_show(struct kobject *kobj,
34877 return port_attr->show(p, port_attr, buf);
34878 }
34879
34880-static struct sysfs_ops port_sysfs_ops = {
34881+static const struct sysfs_ops port_sysfs_ops = {
34882 .show = port_attr_show
34883 };
34884
34885diff --git a/drivers/infiniband/core/uverbs_marshall.c b/drivers/infiniband/core/uverbs_marshall.c
34886index 5440da0..1194ecb 100644
34887--- a/drivers/infiniband/core/uverbs_marshall.c
34888+++ b/drivers/infiniband/core/uverbs_marshall.c
34889@@ -40,18 +40,21 @@ void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
34890 dst->grh.sgid_index = src->grh.sgid_index;
34891 dst->grh.hop_limit = src->grh.hop_limit;
34892 dst->grh.traffic_class = src->grh.traffic_class;
34893+ memset(&dst->grh.reserved, 0, sizeof(dst->grh.reserved));
34894 dst->dlid = src->dlid;
34895 dst->sl = src->sl;
34896 dst->src_path_bits = src->src_path_bits;
34897 dst->static_rate = src->static_rate;
34898 dst->is_global = src->ah_flags & IB_AH_GRH ? 1 : 0;
34899 dst->port_num = src->port_num;
34900+ dst->reserved = 0;
34901 }
34902 EXPORT_SYMBOL(ib_copy_ah_attr_to_user);
34903
34904 void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
34905 struct ib_qp_attr *src)
34906 {
34907+ dst->qp_state = src->qp_state;
34908 dst->cur_qp_state = src->cur_qp_state;
34909 dst->path_mtu = src->path_mtu;
34910 dst->path_mig_state = src->path_mig_state;
34911@@ -83,6 +86,7 @@ void ib_copy_qp_attr_to_user(struct ib_uverbs_qp_attr *dst,
34912 dst->rnr_retry = src->rnr_retry;
34913 dst->alt_port_num = src->alt_port_num;
34914 dst->alt_timeout = src->alt_timeout;
34915+ memset(dst->reserved, 0, sizeof(dst->reserved));
34916 }
34917 EXPORT_SYMBOL(ib_copy_qp_attr_to_user);
34918
34919diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
34920index 100da85..62e6b88 100644
34921--- a/drivers/infiniband/hw/ipath/ipath_fs.c
34922+++ b/drivers/infiniband/hw/ipath/ipath_fs.c
34923@@ -110,6 +110,8 @@ static ssize_t atomic_counters_read(struct file *file, char __user *buf,
34924 struct infinipath_counters counters;
34925 struct ipath_devdata *dd;
34926
34927+ pax_track_stack();
34928+
34929 dd = file->f_path.dentry->d_inode->i_private;
34930 dd->ipath_f_read_counters(dd, &counters);
34931
34932diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34933index cbde0cf..afaf55c 100644
34934--- a/drivers/infiniband/hw/nes/nes.c
34935+++ b/drivers/infiniband/hw/nes/nes.c
34936@@ -102,7 +102,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34937 LIST_HEAD(nes_adapter_list);
34938 static LIST_HEAD(nes_dev_list);
34939
34940-atomic_t qps_destroyed;
34941+atomic_unchecked_t qps_destroyed;
34942
34943 static unsigned int ee_flsh_adapter;
34944 static unsigned int sysfs_nonidx_addr;
34945@@ -259,7 +259,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34946 struct nes_adapter *nesadapter = nesdev->nesadapter;
34947 u32 qp_id;
34948
34949- atomic_inc(&qps_destroyed);
34950+ atomic_inc_unchecked(&qps_destroyed);
34951
34952 /* Free the control structures */
34953
34954diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34955index bcc6abc..9c76b2f 100644
34956--- a/drivers/infiniband/hw/nes/nes.h
34957+++ b/drivers/infiniband/hw/nes/nes.h
34958@@ -174,17 +174,17 @@ extern unsigned int nes_debug_level;
34959 extern unsigned int wqm_quanta;
34960 extern struct list_head nes_adapter_list;
34961
34962-extern atomic_t cm_connects;
34963-extern atomic_t cm_accepts;
34964-extern atomic_t cm_disconnects;
34965-extern atomic_t cm_closes;
34966-extern atomic_t cm_connecteds;
34967-extern atomic_t cm_connect_reqs;
34968-extern atomic_t cm_rejects;
34969-extern atomic_t mod_qp_timouts;
34970-extern atomic_t qps_created;
34971-extern atomic_t qps_destroyed;
34972-extern atomic_t sw_qps_destroyed;
34973+extern atomic_unchecked_t cm_connects;
34974+extern atomic_unchecked_t cm_accepts;
34975+extern atomic_unchecked_t cm_disconnects;
34976+extern atomic_unchecked_t cm_closes;
34977+extern atomic_unchecked_t cm_connecteds;
34978+extern atomic_unchecked_t cm_connect_reqs;
34979+extern atomic_unchecked_t cm_rejects;
34980+extern atomic_unchecked_t mod_qp_timouts;
34981+extern atomic_unchecked_t qps_created;
34982+extern atomic_unchecked_t qps_destroyed;
34983+extern atomic_unchecked_t sw_qps_destroyed;
34984 extern u32 mh_detected;
34985 extern u32 mh_pauses_sent;
34986 extern u32 cm_packets_sent;
34987@@ -196,11 +196,11 @@ extern u32 cm_packets_retrans;
34988 extern u32 cm_listens_created;
34989 extern u32 cm_listens_destroyed;
34990 extern u32 cm_backlog_drops;
34991-extern atomic_t cm_loopbacks;
34992-extern atomic_t cm_nodes_created;
34993-extern atomic_t cm_nodes_destroyed;
34994-extern atomic_t cm_accel_dropped_pkts;
34995-extern atomic_t cm_resets_recvd;
34996+extern atomic_unchecked_t cm_loopbacks;
34997+extern atomic_unchecked_t cm_nodes_created;
34998+extern atomic_unchecked_t cm_nodes_destroyed;
34999+extern atomic_unchecked_t cm_accel_dropped_pkts;
35000+extern atomic_unchecked_t cm_resets_recvd;
35001
35002 extern u32 int_mod_timer_init;
35003 extern u32 int_mod_cq_depth_256;
35004diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
35005index 73473db..5ed06e8 100644
35006--- a/drivers/infiniband/hw/nes/nes_cm.c
35007+++ b/drivers/infiniband/hw/nes/nes_cm.c
35008@@ -69,11 +69,11 @@ u32 cm_packets_received;
35009 u32 cm_listens_created;
35010 u32 cm_listens_destroyed;
35011 u32 cm_backlog_drops;
35012-atomic_t cm_loopbacks;
35013-atomic_t cm_nodes_created;
35014-atomic_t cm_nodes_destroyed;
35015-atomic_t cm_accel_dropped_pkts;
35016-atomic_t cm_resets_recvd;
35017+atomic_unchecked_t cm_loopbacks;
35018+atomic_unchecked_t cm_nodes_created;
35019+atomic_unchecked_t cm_nodes_destroyed;
35020+atomic_unchecked_t cm_accel_dropped_pkts;
35021+atomic_unchecked_t cm_resets_recvd;
35022
35023 static inline int mini_cm_accelerated(struct nes_cm_core *,
35024 struct nes_cm_node *);
35025@@ -149,13 +149,13 @@ static struct nes_cm_ops nes_cm_api = {
35026
35027 static struct nes_cm_core *g_cm_core;
35028
35029-atomic_t cm_connects;
35030-atomic_t cm_accepts;
35031-atomic_t cm_disconnects;
35032-atomic_t cm_closes;
35033-atomic_t cm_connecteds;
35034-atomic_t cm_connect_reqs;
35035-atomic_t cm_rejects;
35036+atomic_unchecked_t cm_connects;
35037+atomic_unchecked_t cm_accepts;
35038+atomic_unchecked_t cm_disconnects;
35039+atomic_unchecked_t cm_closes;
35040+atomic_unchecked_t cm_connecteds;
35041+atomic_unchecked_t cm_connect_reqs;
35042+atomic_unchecked_t cm_rejects;
35043
35044
35045 /**
35046@@ -1195,7 +1195,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
35047 cm_node->rem_mac);
35048
35049 add_hte_node(cm_core, cm_node);
35050- atomic_inc(&cm_nodes_created);
35051+ atomic_inc_unchecked(&cm_nodes_created);
35052
35053 return cm_node;
35054 }
35055@@ -1253,7 +1253,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
35056 }
35057
35058 atomic_dec(&cm_core->node_cnt);
35059- atomic_inc(&cm_nodes_destroyed);
35060+ atomic_inc_unchecked(&cm_nodes_destroyed);
35061 nesqp = cm_node->nesqp;
35062 if (nesqp) {
35063 nesqp->cm_node = NULL;
35064@@ -1320,7 +1320,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
35065
35066 static void drop_packet(struct sk_buff *skb)
35067 {
35068- atomic_inc(&cm_accel_dropped_pkts);
35069+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35070 dev_kfree_skb_any(skb);
35071 }
35072
35073@@ -1377,7 +1377,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
35074
35075 int reset = 0; /* whether to send reset in case of err.. */
35076 int passive_state;
35077- atomic_inc(&cm_resets_recvd);
35078+ atomic_inc_unchecked(&cm_resets_recvd);
35079 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
35080 " refcnt=%d\n", cm_node, cm_node->state,
35081 atomic_read(&cm_node->ref_count));
35082@@ -2000,7 +2000,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
35083 rem_ref_cm_node(cm_node->cm_core, cm_node);
35084 return NULL;
35085 }
35086- atomic_inc(&cm_loopbacks);
35087+ atomic_inc_unchecked(&cm_loopbacks);
35088 loopbackremotenode->loopbackpartner = cm_node;
35089 loopbackremotenode->tcp_cntxt.rcv_wscale =
35090 NES_CM_DEFAULT_RCV_WND_SCALE;
35091@@ -2262,7 +2262,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
35092 add_ref_cm_node(cm_node);
35093 } else if (cm_node->state == NES_CM_STATE_TSA) {
35094 rem_ref_cm_node(cm_core, cm_node);
35095- atomic_inc(&cm_accel_dropped_pkts);
35096+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
35097 dev_kfree_skb_any(skb);
35098 break;
35099 }
35100@@ -2568,7 +2568,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35101
35102 if ((cm_id) && (cm_id->event_handler)) {
35103 if (issue_disconn) {
35104- atomic_inc(&cm_disconnects);
35105+ atomic_inc_unchecked(&cm_disconnects);
35106 cm_event.event = IW_CM_EVENT_DISCONNECT;
35107 cm_event.status = disconn_status;
35108 cm_event.local_addr = cm_id->local_addr;
35109@@ -2590,7 +2590,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35110 }
35111
35112 if (issue_close) {
35113- atomic_inc(&cm_closes);
35114+ atomic_inc_unchecked(&cm_closes);
35115 nes_disconnect(nesqp, 1);
35116
35117 cm_id->provider_data = nesqp;
35118@@ -2710,7 +2710,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35119
35120 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
35121 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
35122- atomic_inc(&cm_accepts);
35123+ atomic_inc_unchecked(&cm_accepts);
35124
35125 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
35126 atomic_read(&nesvnic->netdev->refcnt));
35127@@ -2919,7 +2919,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
35128
35129 struct nes_cm_core *cm_core;
35130
35131- atomic_inc(&cm_rejects);
35132+ atomic_inc_unchecked(&cm_rejects);
35133 cm_node = (struct nes_cm_node *) cm_id->provider_data;
35134 loopback = cm_node->loopbackpartner;
35135 cm_core = cm_node->cm_core;
35136@@ -2982,7 +2982,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35137 ntohl(cm_id->local_addr.sin_addr.s_addr),
35138 ntohs(cm_id->local_addr.sin_port));
35139
35140- atomic_inc(&cm_connects);
35141+ atomic_inc_unchecked(&cm_connects);
35142 nesqp->active_conn = 1;
35143
35144 /* cache the cm_id in the qp */
35145@@ -3195,7 +3195,7 @@ static void cm_event_connected(struct nes_cm_event *event)
35146 if (nesqp->destroyed) {
35147 return;
35148 }
35149- atomic_inc(&cm_connecteds);
35150+ atomic_inc_unchecked(&cm_connecteds);
35151 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
35152 " local port 0x%04X. jiffies = %lu.\n",
35153 nesqp->hwqp.qp_id,
35154@@ -3403,7 +3403,7 @@ static void cm_event_reset(struct nes_cm_event *event)
35155
35156 ret = cm_id->event_handler(cm_id, &cm_event);
35157 cm_id->add_ref(cm_id);
35158- atomic_inc(&cm_closes);
35159+ atomic_inc_unchecked(&cm_closes);
35160 cm_event.event = IW_CM_EVENT_CLOSE;
35161 cm_event.status = IW_CM_EVENT_STATUS_OK;
35162 cm_event.provider_data = cm_id->provider_data;
35163@@ -3439,7 +3439,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
35164 return;
35165 cm_id = cm_node->cm_id;
35166
35167- atomic_inc(&cm_connect_reqs);
35168+ atomic_inc_unchecked(&cm_connect_reqs);
35169 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35170 cm_node, cm_id, jiffies);
35171
35172@@ -3477,7 +3477,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
35173 return;
35174 cm_id = cm_node->cm_id;
35175
35176- atomic_inc(&cm_connect_reqs);
35177+ atomic_inc_unchecked(&cm_connect_reqs);
35178 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35179 cm_node, cm_id, jiffies);
35180
35181diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
35182index e593af3..870694a 100644
35183--- a/drivers/infiniband/hw/nes/nes_nic.c
35184+++ b/drivers/infiniband/hw/nes/nes_nic.c
35185@@ -1210,17 +1210,17 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35186 target_stat_values[++index] = mh_detected;
35187 target_stat_values[++index] = mh_pauses_sent;
35188 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
35189- target_stat_values[++index] = atomic_read(&cm_connects);
35190- target_stat_values[++index] = atomic_read(&cm_accepts);
35191- target_stat_values[++index] = atomic_read(&cm_disconnects);
35192- target_stat_values[++index] = atomic_read(&cm_connecteds);
35193- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
35194- target_stat_values[++index] = atomic_read(&cm_rejects);
35195- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
35196- target_stat_values[++index] = atomic_read(&qps_created);
35197- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
35198- target_stat_values[++index] = atomic_read(&qps_destroyed);
35199- target_stat_values[++index] = atomic_read(&cm_closes);
35200+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
35201+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
35202+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
35203+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
35204+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
35205+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
35206+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
35207+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
35208+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
35209+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
35210+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
35211 target_stat_values[++index] = cm_packets_sent;
35212 target_stat_values[++index] = cm_packets_bounced;
35213 target_stat_values[++index] = cm_packets_created;
35214@@ -1230,11 +1230,11 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35215 target_stat_values[++index] = cm_listens_created;
35216 target_stat_values[++index] = cm_listens_destroyed;
35217 target_stat_values[++index] = cm_backlog_drops;
35218- target_stat_values[++index] = atomic_read(&cm_loopbacks);
35219- target_stat_values[++index] = atomic_read(&cm_nodes_created);
35220- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
35221- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
35222- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
35223+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
35224+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
35225+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
35226+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
35227+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
35228 target_stat_values[++index] = int_mod_timer_init;
35229 target_stat_values[++index] = int_mod_cq_depth_1;
35230 target_stat_values[++index] = int_mod_cq_depth_4;
35231diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
35232index a680c42..f914deb 100644
35233--- a/drivers/infiniband/hw/nes/nes_verbs.c
35234+++ b/drivers/infiniband/hw/nes/nes_verbs.c
35235@@ -45,9 +45,9 @@
35236
35237 #include <rdma/ib_umem.h>
35238
35239-atomic_t mod_qp_timouts;
35240-atomic_t qps_created;
35241-atomic_t sw_qps_destroyed;
35242+atomic_unchecked_t mod_qp_timouts;
35243+atomic_unchecked_t qps_created;
35244+atomic_unchecked_t sw_qps_destroyed;
35245
35246 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
35247
35248@@ -1240,7 +1240,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
35249 if (init_attr->create_flags)
35250 return ERR_PTR(-EINVAL);
35251
35252- atomic_inc(&qps_created);
35253+ atomic_inc_unchecked(&qps_created);
35254 switch (init_attr->qp_type) {
35255 case IB_QPT_RC:
35256 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
35257@@ -1568,7 +1568,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
35258 struct iw_cm_event cm_event;
35259 int ret;
35260
35261- atomic_inc(&sw_qps_destroyed);
35262+ atomic_inc_unchecked(&sw_qps_destroyed);
35263 nesqp->destroyed = 1;
35264
35265 /* Blow away the connection if it exists. */
35266diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
35267index ac11be0..3883c04 100644
35268--- a/drivers/input/gameport/gameport.c
35269+++ b/drivers/input/gameport/gameport.c
35270@@ -515,13 +515,13 @@ EXPORT_SYMBOL(gameport_set_phys);
35271 */
35272 static void gameport_init_port(struct gameport *gameport)
35273 {
35274- static atomic_t gameport_no = ATOMIC_INIT(0);
35275+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
35276
35277 __module_get(THIS_MODULE);
35278
35279 mutex_init(&gameport->drv_mutex);
35280 device_initialize(&gameport->dev);
35281- dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1);
35282+ dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
35283 gameport->dev.bus = &gameport_bus;
35284 gameport->dev.release = gameport_release_port;
35285 if (gameport->parent)
35286diff --git a/drivers/input/input.c b/drivers/input/input.c
35287index c82ae82..8cfb9cb 100644
35288--- a/drivers/input/input.c
35289+++ b/drivers/input/input.c
35290@@ -1558,7 +1558,7 @@ EXPORT_SYMBOL(input_set_capability);
35291 */
35292 int input_register_device(struct input_dev *dev)
35293 {
35294- static atomic_t input_no = ATOMIC_INIT(0);
35295+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
35296 struct input_handler *handler;
35297 const char *path;
35298 int error;
35299@@ -1585,7 +1585,7 @@ int input_register_device(struct input_dev *dev)
35300 dev->setkeycode = input_default_setkeycode;
35301
35302 dev_set_name(&dev->dev, "input%ld",
35303- (unsigned long) atomic_inc_return(&input_no) - 1);
35304+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
35305
35306 error = device_add(&dev->dev);
35307 if (error)
35308diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
35309index ca13a6b..b032b0c 100644
35310--- a/drivers/input/joystick/sidewinder.c
35311+++ b/drivers/input/joystick/sidewinder.c
35312@@ -30,6 +30,7 @@
35313 #include <linux/kernel.h>
35314 #include <linux/module.h>
35315 #include <linux/slab.h>
35316+#include <linux/sched.h>
35317 #include <linux/init.h>
35318 #include <linux/input.h>
35319 #include <linux/gameport.h>
35320@@ -428,6 +429,8 @@ static int sw_read(struct sw *sw)
35321 unsigned char buf[SW_LENGTH];
35322 int i;
35323
35324+ pax_track_stack();
35325+
35326 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
35327
35328 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
35329diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
35330index 79e3edc..01412b9 100644
35331--- a/drivers/input/joystick/xpad.c
35332+++ b/drivers/input/joystick/xpad.c
35333@@ -621,7 +621,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
35334
35335 static int xpad_led_probe(struct usb_xpad *xpad)
35336 {
35337- static atomic_t led_seq = ATOMIC_INIT(0);
35338+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
35339 long led_no;
35340 struct xpad_led *led;
35341 struct led_classdev *led_cdev;
35342@@ -634,7 +634,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
35343 if (!led)
35344 return -ENOMEM;
35345
35346- led_no = (long)atomic_inc_return(&led_seq) - 1;
35347+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
35348
35349 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
35350 led->xpad = xpad;
35351diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
35352index 0236f0d..c7327f1 100644
35353--- a/drivers/input/serio/serio.c
35354+++ b/drivers/input/serio/serio.c
35355@@ -527,7 +527,7 @@ static void serio_release_port(struct device *dev)
35356 */
35357 static void serio_init_port(struct serio *serio)
35358 {
35359- static atomic_t serio_no = ATOMIC_INIT(0);
35360+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
35361
35362 __module_get(THIS_MODULE);
35363
35364@@ -536,7 +536,7 @@ static void serio_init_port(struct serio *serio)
35365 mutex_init(&serio->drv_mutex);
35366 device_initialize(&serio->dev);
35367 dev_set_name(&serio->dev, "serio%ld",
35368- (long)atomic_inc_return(&serio_no) - 1);
35369+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
35370 serio->dev.bus = &serio_bus;
35371 serio->dev.release = serio_release_port;
35372 if (serio->parent) {
35373diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
35374index 33dcd8d..2783d25 100644
35375--- a/drivers/isdn/gigaset/common.c
35376+++ b/drivers/isdn/gigaset/common.c
35377@@ -712,7 +712,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
35378 cs->commands_pending = 0;
35379 cs->cur_at_seq = 0;
35380 cs->gotfwver = -1;
35381- cs->open_count = 0;
35382+ local_set(&cs->open_count, 0);
35383 cs->dev = NULL;
35384 cs->tty = NULL;
35385 cs->tty_dev = NULL;
35386diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
35387index a2f6125..6a70677 100644
35388--- a/drivers/isdn/gigaset/gigaset.h
35389+++ b/drivers/isdn/gigaset/gigaset.h
35390@@ -34,6 +34,7 @@
35391 #include <linux/tty_driver.h>
35392 #include <linux/list.h>
35393 #include <asm/atomic.h>
35394+#include <asm/local.h>
35395
35396 #define GIG_VERSION {0,5,0,0}
35397 #define GIG_COMPAT {0,4,0,0}
35398@@ -446,7 +447,7 @@ struct cardstate {
35399 spinlock_t cmdlock;
35400 unsigned curlen, cmdbytes;
35401
35402- unsigned open_count;
35403+ local_t open_count;
35404 struct tty_struct *tty;
35405 struct tasklet_struct if_wake_tasklet;
35406 unsigned control_state;
35407diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
35408index b3065b8..c7e8cc9 100644
35409--- a/drivers/isdn/gigaset/interface.c
35410+++ b/drivers/isdn/gigaset/interface.c
35411@@ -165,9 +165,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
35412 return -ERESTARTSYS; // FIXME -EINTR?
35413 tty->driver_data = cs;
35414
35415- ++cs->open_count;
35416-
35417- if (cs->open_count == 1) {
35418+ if (local_inc_return(&cs->open_count) == 1) {
35419 spin_lock_irqsave(&cs->lock, flags);
35420 cs->tty = tty;
35421 spin_unlock_irqrestore(&cs->lock, flags);
35422@@ -195,10 +193,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
35423
35424 if (!cs->connected)
35425 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35426- else if (!cs->open_count)
35427+ else if (!local_read(&cs->open_count))
35428 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35429 else {
35430- if (!--cs->open_count) {
35431+ if (!local_dec_return(&cs->open_count)) {
35432 spin_lock_irqsave(&cs->lock, flags);
35433 cs->tty = NULL;
35434 spin_unlock_irqrestore(&cs->lock, flags);
35435@@ -233,7 +231,7 @@ static int if_ioctl(struct tty_struct *tty, struct file *file,
35436 if (!cs->connected) {
35437 gig_dbg(DEBUG_IF, "not connected");
35438 retval = -ENODEV;
35439- } else if (!cs->open_count)
35440+ } else if (!local_read(&cs->open_count))
35441 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35442 else {
35443 retval = 0;
35444@@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
35445 if (!cs->connected) {
35446 gig_dbg(DEBUG_IF, "not connected");
35447 retval = -ENODEV;
35448- } else if (!cs->open_count)
35449+ } else if (!local_read(&cs->open_count))
35450 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35451 else if (cs->mstate != MS_LOCKED) {
35452 dev_warn(cs->dev, "can't write to unlocked device\n");
35453@@ -395,7 +393,7 @@ static int if_write_room(struct tty_struct *tty)
35454 if (!cs->connected) {
35455 gig_dbg(DEBUG_IF, "not connected");
35456 retval = -ENODEV;
35457- } else if (!cs->open_count)
35458+ } else if (!local_read(&cs->open_count))
35459 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35460 else if (cs->mstate != MS_LOCKED) {
35461 dev_warn(cs->dev, "can't write to unlocked device\n");
35462@@ -425,7 +423,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
35463
35464 if (!cs->connected)
35465 gig_dbg(DEBUG_IF, "not connected");
35466- else if (!cs->open_count)
35467+ else if (!local_read(&cs->open_count))
35468 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35469 else if (cs->mstate != MS_LOCKED)
35470 dev_warn(cs->dev, "can't write to unlocked device\n");
35471@@ -453,7 +451,7 @@ static void if_throttle(struct tty_struct *tty)
35472
35473 if (!cs->connected)
35474 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35475- else if (!cs->open_count)
35476+ else if (!local_read(&cs->open_count))
35477 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35478 else {
35479 //FIXME
35480@@ -478,7 +476,7 @@ static void if_unthrottle(struct tty_struct *tty)
35481
35482 if (!cs->connected)
35483 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35484- else if (!cs->open_count)
35485+ else if (!local_read(&cs->open_count))
35486 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35487 else {
35488 //FIXME
35489@@ -510,7 +508,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
35490 goto out;
35491 }
35492
35493- if (!cs->open_count) {
35494+ if (!local_read(&cs->open_count)) {
35495 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35496 goto out;
35497 }
35498diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
35499index a7c0083..62a7cb6 100644
35500--- a/drivers/isdn/hardware/avm/b1.c
35501+++ b/drivers/isdn/hardware/avm/b1.c
35502@@ -173,7 +173,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
35503 }
35504 if (left) {
35505 if (t4file->user) {
35506- if (copy_from_user(buf, dp, left))
35507+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35508 return -EFAULT;
35509 } else {
35510 memcpy(buf, dp, left);
35511@@ -221,7 +221,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
35512 }
35513 if (left) {
35514 if (config->user) {
35515- if (copy_from_user(buf, dp, left))
35516+ if (left > sizeof buf || copy_from_user(buf, dp, left))
35517 return -EFAULT;
35518 } else {
35519 memcpy(buf, dp, left);
35520diff --git a/drivers/isdn/hardware/eicon/capidtmf.c b/drivers/isdn/hardware/eicon/capidtmf.c
35521index f130724..c373c68 100644
35522--- a/drivers/isdn/hardware/eicon/capidtmf.c
35523+++ b/drivers/isdn/hardware/eicon/capidtmf.c
35524@@ -498,6 +498,7 @@ void capidtmf_recv_block (t_capidtmf_state *p_state, byte *buffer, word leng
35525 byte goertzel_result_buffer[CAPIDTMF_RECV_TOTAL_FREQUENCY_COUNT];
35526 short windowed_sample_buffer[CAPIDTMF_RECV_WINDOWED_SAMPLES];
35527
35528+ pax_track_stack();
35529
35530 if (p_state->recv.state & CAPIDTMF_RECV_STATE_DTMF_ACTIVE)
35531 {
35532diff --git a/drivers/isdn/hardware/eicon/capifunc.c b/drivers/isdn/hardware/eicon/capifunc.c
35533index 4d425c6..a9be6c4 100644
35534--- a/drivers/isdn/hardware/eicon/capifunc.c
35535+++ b/drivers/isdn/hardware/eicon/capifunc.c
35536@@ -1055,6 +1055,8 @@ static int divacapi_connect_didd(void)
35537 IDI_SYNC_REQ req;
35538 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35539
35540+ pax_track_stack();
35541+
35542 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35543
35544 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35545diff --git a/drivers/isdn/hardware/eicon/diddfunc.c b/drivers/isdn/hardware/eicon/diddfunc.c
35546index 3029234..ef0d9e2 100644
35547--- a/drivers/isdn/hardware/eicon/diddfunc.c
35548+++ b/drivers/isdn/hardware/eicon/diddfunc.c
35549@@ -54,6 +54,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35550 IDI_SYNC_REQ req;
35551 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35552
35553+ pax_track_stack();
35554+
35555 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35556
35557 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35558diff --git a/drivers/isdn/hardware/eicon/divasfunc.c b/drivers/isdn/hardware/eicon/divasfunc.c
35559index d36a4c0..11e7d1a 100644
35560--- a/drivers/isdn/hardware/eicon/divasfunc.c
35561+++ b/drivers/isdn/hardware/eicon/divasfunc.c
35562@@ -161,6 +161,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35563 IDI_SYNC_REQ req;
35564 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35565
35566+ pax_track_stack();
35567+
35568 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35569
35570 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35571diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
35572index 85784a7..a19ca98 100644
35573--- a/drivers/isdn/hardware/eicon/divasync.h
35574+++ b/drivers/isdn/hardware/eicon/divasync.h
35575@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
35576 } diva_didd_add_adapter_t;
35577 typedef struct _diva_didd_remove_adapter {
35578 IDI_CALL p_request;
35579-} diva_didd_remove_adapter_t;
35580+} __no_const diva_didd_remove_adapter_t;
35581 typedef struct _diva_didd_read_adapter_array {
35582 void * buffer;
35583 dword length;
35584diff --git a/drivers/isdn/hardware/eicon/idifunc.c b/drivers/isdn/hardware/eicon/idifunc.c
35585index db87d51..7d09acf 100644
35586--- a/drivers/isdn/hardware/eicon/idifunc.c
35587+++ b/drivers/isdn/hardware/eicon/idifunc.c
35588@@ -188,6 +188,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35589 IDI_SYNC_REQ req;
35590 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35591
35592+ pax_track_stack();
35593+
35594 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35595
35596 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35597diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
35598index ae89fb8..0fab299 100644
35599--- a/drivers/isdn/hardware/eicon/message.c
35600+++ b/drivers/isdn/hardware/eicon/message.c
35601@@ -4889,6 +4889,8 @@ static void sig_ind(PLCI *plci)
35602 dword d;
35603 word w;
35604
35605+ pax_track_stack();
35606+
35607 a = plci->adapter;
35608 Id = ((word)plci->Id<<8)|a->Id;
35609 PUT_WORD(&SS_Ind[4],0x0000);
35610@@ -7484,6 +7486,8 @@ static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
35611 word j, n, w;
35612 dword d;
35613
35614+ pax_track_stack();
35615+
35616
35617 for(i=0;i<8;i++) bp_parms[i].length = 0;
35618 for(i=0;i<2;i++) global_config[i].length = 0;
35619@@ -7958,6 +7962,8 @@ static word add_b23(PLCI *plci, API_PARSE *bp)
35620 const byte llc3[] = {4,3,2,2,6,6,0};
35621 const byte header[] = {0,2,3,3,0,0,0};
35622
35623+ pax_track_stack();
35624+
35625 for(i=0;i<8;i++) bp_parms[i].length = 0;
35626 for(i=0;i<6;i++) b2_config_parms[i].length = 0;
35627 for(i=0;i<5;i++) b3_config_parms[i].length = 0;
35628@@ -14761,6 +14767,8 @@ static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
35629 word appl_number_group_type[MAX_APPL];
35630 PLCI *auxplci;
35631
35632+ pax_track_stack();
35633+
35634 set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
35635
35636 if(!a->group_optimization_enabled)
35637diff --git a/drivers/isdn/hardware/eicon/mntfunc.c b/drivers/isdn/hardware/eicon/mntfunc.c
35638index a564b75..f3cf8b5 100644
35639--- a/drivers/isdn/hardware/eicon/mntfunc.c
35640+++ b/drivers/isdn/hardware/eicon/mntfunc.c
35641@@ -79,6 +79,8 @@ static int DIVA_INIT_FUNCTION connect_didd(void)
35642 IDI_SYNC_REQ req;
35643 DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
35644
35645+ pax_track_stack();
35646+
35647 DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
35648
35649 for (x = 0; x < MAX_DESCRIPTORS; x++) {
35650diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
35651index a3bd163..8956575 100644
35652--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
35653+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
35654@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
35655 typedef struct _diva_os_idi_adapter_interface {
35656 diva_init_card_proc_t cleanup_adapter_proc;
35657 diva_cmd_card_proc_t cmd_proc;
35658-} diva_os_idi_adapter_interface_t;
35659+} __no_const diva_os_idi_adapter_interface_t;
35660
35661 typedef struct _diva_os_xdi_adapter {
35662 struct list_head link;
35663diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
35664index adb1e8c..21b590b 100644
35665--- a/drivers/isdn/i4l/isdn_common.c
35666+++ b/drivers/isdn/i4l/isdn_common.c
35667@@ -1290,6 +1290,8 @@ isdn_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg)
35668 } iocpar;
35669 void __user *argp = (void __user *)arg;
35670
35671+ pax_track_stack();
35672+
35673 #define name iocpar.name
35674 #define bname iocpar.bname
35675 #define iocts iocpar.iocts
35676diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
35677index bf7997a..cf091db 100644
35678--- a/drivers/isdn/icn/icn.c
35679+++ b/drivers/isdn/icn/icn.c
35680@@ -1044,7 +1044,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
35681 if (count > len)
35682 count = len;
35683 if (user) {
35684- if (copy_from_user(msg, buf, count))
35685+ if (count > sizeof msg || copy_from_user(msg, buf, count))
35686 return -EFAULT;
35687 } else
35688 memcpy(msg, buf, count);
35689diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c
35690index feb0fa4..f76f830 100644
35691--- a/drivers/isdn/mISDN/socket.c
35692+++ b/drivers/isdn/mISDN/socket.c
35693@@ -391,6 +391,7 @@ data_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
35694 if (dev) {
35695 struct mISDN_devinfo di;
35696
35697+ memset(&di, 0, sizeof(di));
35698 di.id = dev->id;
35699 di.Dprotocols = dev->Dprotocols;
35700 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
35701@@ -671,6 +672,7 @@ base_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
35702 if (dev) {
35703 struct mISDN_devinfo di;
35704
35705+ memset(&di, 0, sizeof(di));
35706 di.id = dev->id;
35707 di.Dprotocols = dev->Dprotocols;
35708 di.Bprotocols = dev->Bprotocols | get_all_Bprotocols();
35709diff --git a/drivers/isdn/sc/interrupt.c b/drivers/isdn/sc/interrupt.c
35710index 485be8b..f0225bc 100644
35711--- a/drivers/isdn/sc/interrupt.c
35712+++ b/drivers/isdn/sc/interrupt.c
35713@@ -112,11 +112,19 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
35714 }
35715 else if(callid>=0x0000 && callid<=0x7FFF)
35716 {
35717+ int len;
35718+
35719 pr_debug("%s: Got Incoming Call\n",
35720 sc_adapter[card]->devicename);
35721- strcpy(setup.phone,&(rcvmsg.msg_data.byte_array[4]));
35722- strcpy(setup.eazmsn,
35723- sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn);
35724+ len = strlcpy(setup.phone, &(rcvmsg.msg_data.byte_array[4]),
35725+ sizeof(setup.phone));
35726+ if (len >= sizeof(setup.phone))
35727+ continue;
35728+ len = strlcpy(setup.eazmsn,
35729+ sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
35730+ sizeof(setup.eazmsn));
35731+ if (len >= sizeof(setup.eazmsn))
35732+ continue;
35733 setup.si1 = 7;
35734 setup.si2 = 0;
35735 setup.plan = 0;
35736@@ -176,7 +184,9 @@ irqreturn_t interrupt_handler(int dummy, void *card_inst)
35737 * Handle a GetMyNumber Rsp
35738 */
35739 if (IS_CE_MESSAGE(rcvmsg,Call,0,GetMyNumber)){
35740- strcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no-1].dn,rcvmsg.msg_data.byte_array);
35741+ strlcpy(sc_adapter[card]->channel[rcvmsg.phy_link_no - 1].dn,
35742+ rcvmsg.msg_data.byte_array,
35743+ sizeof(rcvmsg.msg_data.byte_array));
35744 continue;
35745 }
35746
35747diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
35748index 8744d24..d1f9a9a 100644
35749--- a/drivers/lguest/core.c
35750+++ b/drivers/lguest/core.c
35751@@ -91,9 +91,17 @@ static __init int map_switcher(void)
35752 * it's worked so far. The end address needs +1 because __get_vm_area
35753 * allocates an extra guard page, so we need space for that.
35754 */
35755+
35756+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35757+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35758+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
35759+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35760+#else
35761 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35762 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
35763 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35764+#endif
35765+
35766 if (!switcher_vma) {
35767 err = -ENOMEM;
35768 printk("lguest: could not map switcher pages high\n");
35769@@ -118,7 +126,7 @@ static __init int map_switcher(void)
35770 * Now the Switcher is mapped at the right address, we can't fail!
35771 * Copy in the compiled-in Switcher code (from <arch>_switcher.S).
35772 */
35773- memcpy(switcher_vma->addr, start_switcher_text,
35774+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
35775 end_switcher_text - start_switcher_text);
35776
35777 printk(KERN_INFO "lguest: mapped switcher at %p\n",
35778diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
35779index 6ae3888..8b38145 100644
35780--- a/drivers/lguest/x86/core.c
35781+++ b/drivers/lguest/x86/core.c
35782@@ -59,7 +59,7 @@ static struct {
35783 /* Offset from where switcher.S was compiled to where we've copied it */
35784 static unsigned long switcher_offset(void)
35785 {
35786- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
35787+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
35788 }
35789
35790 /* This cpu's struct lguest_pages. */
35791@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
35792 * These copies are pretty cheap, so we do them unconditionally: */
35793 /* Save the current Host top-level page directory.
35794 */
35795+
35796+#ifdef CONFIG_PAX_PER_CPU_PGD
35797+ pages->state.host_cr3 = read_cr3();
35798+#else
35799 pages->state.host_cr3 = __pa(current->mm->pgd);
35800+#endif
35801+
35802 /*
35803 * Set up the Guest's page tables to see this CPU's pages (and no
35804 * other CPU's pages).
35805@@ -535,7 +541,7 @@ void __init lguest_arch_host_init(void)
35806 * compiled-in switcher code and the high-mapped copy we just made.
35807 */
35808 for (i = 0; i < IDT_ENTRIES; i++)
35809- default_idt_entries[i] += switcher_offset();
35810+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
35811
35812 /*
35813 * Set up the Switcher's per-cpu areas.
35814@@ -618,7 +624,7 @@ void __init lguest_arch_host_init(void)
35815 * it will be undisturbed when we switch. To change %cs and jump we
35816 * need this structure to feed to Intel's "lcall" instruction.
35817 */
35818- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
35819+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
35820 lguest_entry.segment = LGUEST_CS;
35821
35822 /*
35823diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35824index 40634b0..4f5855e 100644
35825--- a/drivers/lguest/x86/switcher_32.S
35826+++ b/drivers/lguest/x86/switcher_32.S
35827@@ -87,6 +87,7 @@
35828 #include <asm/page.h>
35829 #include <asm/segment.h>
35830 #include <asm/lguest.h>
35831+#include <asm/processor-flags.h>
35832
35833 // We mark the start of the code to copy
35834 // It's placed in .text tho it's never run here
35835@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35836 // Changes type when we load it: damn Intel!
35837 // For after we switch over our page tables
35838 // That entry will be read-only: we'd crash.
35839+
35840+#ifdef CONFIG_PAX_KERNEXEC
35841+ mov %cr0, %edx
35842+ xor $X86_CR0_WP, %edx
35843+ mov %edx, %cr0
35844+#endif
35845+
35846 movl $(GDT_ENTRY_TSS*8), %edx
35847 ltr %dx
35848
35849@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35850 // Let's clear it again for our return.
35851 // The GDT descriptor of the Host
35852 // Points to the table after two "size" bytes
35853- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35854+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35855 // Clear "used" from type field (byte 5, bit 2)
35856- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35857+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35858+
35859+#ifdef CONFIG_PAX_KERNEXEC
35860+ mov %cr0, %eax
35861+ xor $X86_CR0_WP, %eax
35862+ mov %eax, %cr0
35863+#endif
35864
35865 // Once our page table's switched, the Guest is live!
35866 // The Host fades as we run this final step.
35867@@ -295,13 +309,12 @@ deliver_to_host:
35868 // I consulted gcc, and it gave
35869 // These instructions, which I gladly credit:
35870 leal (%edx,%ebx,8), %eax
35871- movzwl (%eax),%edx
35872- movl 4(%eax), %eax
35873- xorw %ax, %ax
35874- orl %eax, %edx
35875+ movl 4(%eax), %edx
35876+ movw (%eax), %dx
35877 // Now the address of the handler's in %edx
35878 // We call it now: its "iret" drops us home.
35879- jmp *%edx
35880+ ljmp $__KERNEL_CS, $1f
35881+1: jmp *%edx
35882
35883 // Every interrupt can come to us here
35884 // But we must truly tell each apart.
35885diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
35886index 588a5b0..b71db89 100644
35887--- a/drivers/macintosh/macio_asic.c
35888+++ b/drivers/macintosh/macio_asic.c
35889@@ -701,7 +701,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
35890 * MacIO is matched against any Apple ID, it's probe() function
35891 * will then decide wether it applies or not
35892 */
35893-static const struct pci_device_id __devinitdata pci_ids [] = { {
35894+static const struct pci_device_id __devinitconst pci_ids [] = { {
35895 .vendor = PCI_VENDOR_ID_APPLE,
35896 .device = PCI_ANY_ID,
35897 .subvendor = PCI_ANY_ID,
35898diff --git a/drivers/macintosh/via-pmu-backlight.c b/drivers/macintosh/via-pmu-backlight.c
35899index a348bb0..ecd9b3f 100644
35900--- a/drivers/macintosh/via-pmu-backlight.c
35901+++ b/drivers/macintosh/via-pmu-backlight.c
35902@@ -15,7 +15,7 @@
35903
35904 #define MAX_PMU_LEVEL 0xFF
35905
35906-static struct backlight_ops pmu_backlight_data;
35907+static const struct backlight_ops pmu_backlight_data;
35908 static DEFINE_SPINLOCK(pmu_backlight_lock);
35909 static int sleeping, uses_pmu_bl;
35910 static u8 bl_curve[FB_BACKLIGHT_LEVELS];
35911@@ -115,7 +115,7 @@ static int pmu_backlight_get_brightness(struct backlight_device *bd)
35912 return bd->props.brightness;
35913 }
35914
35915-static struct backlight_ops pmu_backlight_data = {
35916+static const struct backlight_ops pmu_backlight_data = {
35917 .get_brightness = pmu_backlight_get_brightness,
35918 .update_status = pmu_backlight_update_status,
35919
35920diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
35921index 6f308a4..b5f7ff7 100644
35922--- a/drivers/macintosh/via-pmu.c
35923+++ b/drivers/macintosh/via-pmu.c
35924@@ -2232,7 +2232,7 @@ static int pmu_sleep_valid(suspend_state_t state)
35925 && (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
35926 }
35927
35928-static struct platform_suspend_ops pmu_pm_ops = {
35929+static const struct platform_suspend_ops pmu_pm_ops = {
35930 .enter = powerbook_sleep,
35931 .valid = pmu_sleep_valid,
35932 };
35933diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35934index 818b617..4656e38 100644
35935--- a/drivers/md/dm-ioctl.c
35936+++ b/drivers/md/dm-ioctl.c
35937@@ -1437,7 +1437,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35938 cmd == DM_LIST_VERSIONS_CMD)
35939 return 0;
35940
35941- if ((cmd == DM_DEV_CREATE_CMD)) {
35942+ if (cmd == DM_DEV_CREATE_CMD) {
35943 if (!*param->name) {
35944 DMWARN("name not supplied when creating device");
35945 return -EINVAL;
35946diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35947index 6021d0a..a878643 100644
35948--- a/drivers/md/dm-raid1.c
35949+++ b/drivers/md/dm-raid1.c
35950@@ -41,7 +41,7 @@ enum dm_raid1_error {
35951
35952 struct mirror {
35953 struct mirror_set *ms;
35954- atomic_t error_count;
35955+ atomic_unchecked_t error_count;
35956 unsigned long error_type;
35957 struct dm_dev *dev;
35958 sector_t offset;
35959@@ -203,7 +203,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35960 * simple way to tell if a device has encountered
35961 * errors.
35962 */
35963- atomic_inc(&m->error_count);
35964+ atomic_inc_unchecked(&m->error_count);
35965
35966 if (test_and_set_bit(error_type, &m->error_type))
35967 return;
35968@@ -225,7 +225,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35969 }
35970
35971 for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++)
35972- if (!atomic_read(&new->error_count)) {
35973+ if (!atomic_read_unchecked(&new->error_count)) {
35974 set_default_mirror(new);
35975 break;
35976 }
35977@@ -363,7 +363,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35978 struct mirror *m = get_default_mirror(ms);
35979
35980 do {
35981- if (likely(!atomic_read(&m->error_count)))
35982+ if (likely(!atomic_read_unchecked(&m->error_count)))
35983 return m;
35984
35985 if (m-- == ms->mirror)
35986@@ -377,7 +377,7 @@ static int default_ok(struct mirror *m)
35987 {
35988 struct mirror *default_mirror = get_default_mirror(m->ms);
35989
35990- return !atomic_read(&default_mirror->error_count);
35991+ return !atomic_read_unchecked(&default_mirror->error_count);
35992 }
35993
35994 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35995@@ -484,7 +484,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35996 */
35997 if (likely(region_in_sync(ms, region, 1)))
35998 m = choose_mirror(ms, bio->bi_sector);
35999- else if (m && atomic_read(&m->error_count))
36000+ else if (m && atomic_read_unchecked(&m->error_count))
36001 m = NULL;
36002
36003 if (likely(m))
36004@@ -855,7 +855,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
36005 }
36006
36007 ms->mirror[mirror].ms = ms;
36008- atomic_set(&(ms->mirror[mirror].error_count), 0);
36009+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
36010 ms->mirror[mirror].error_type = 0;
36011 ms->mirror[mirror].offset = offset;
36012
36013@@ -1241,7 +1241,7 @@ static void mirror_resume(struct dm_target *ti)
36014 */
36015 static char device_status_char(struct mirror *m)
36016 {
36017- if (!atomic_read(&(m->error_count)))
36018+ if (!atomic_read_unchecked(&(m->error_count)))
36019 return 'A';
36020
36021 return (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
36022diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
36023index bd58703..9f26571 100644
36024--- a/drivers/md/dm-stripe.c
36025+++ b/drivers/md/dm-stripe.c
36026@@ -20,7 +20,7 @@ struct stripe {
36027 struct dm_dev *dev;
36028 sector_t physical_start;
36029
36030- atomic_t error_count;
36031+ atomic_unchecked_t error_count;
36032 };
36033
36034 struct stripe_c {
36035@@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
36036 kfree(sc);
36037 return r;
36038 }
36039- atomic_set(&(sc->stripe[i].error_count), 0);
36040+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
36041 }
36042
36043 ti->private = sc;
36044@@ -257,7 +257,7 @@ static int stripe_status(struct dm_target *ti,
36045 DMEMIT("%d ", sc->stripes);
36046 for (i = 0; i < sc->stripes; i++) {
36047 DMEMIT("%s ", sc->stripe[i].dev->name);
36048- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
36049+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
36050 'D' : 'A';
36051 }
36052 buffer[i] = '\0';
36053@@ -304,8 +304,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
36054 */
36055 for (i = 0; i < sc->stripes; i++)
36056 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
36057- atomic_inc(&(sc->stripe[i].error_count));
36058- if (atomic_read(&(sc->stripe[i].error_count)) <
36059+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
36060+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
36061 DM_IO_ERROR_THRESHOLD)
36062 queue_work(kstriped, &sc->kstriped_ws);
36063 }
36064diff --git a/drivers/md/dm-sysfs.c b/drivers/md/dm-sysfs.c
36065index 4b04590..13a77b2 100644
36066--- a/drivers/md/dm-sysfs.c
36067+++ b/drivers/md/dm-sysfs.c
36068@@ -75,7 +75,7 @@ static struct attribute *dm_attrs[] = {
36069 NULL,
36070 };
36071
36072-static struct sysfs_ops dm_sysfs_ops = {
36073+static const struct sysfs_ops dm_sysfs_ops = {
36074 .show = dm_attr_show,
36075 };
36076
36077diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
36078index 03345bb..332250d 100644
36079--- a/drivers/md/dm-table.c
36080+++ b/drivers/md/dm-table.c
36081@@ -376,7 +376,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
36082 if (!dev_size)
36083 return 0;
36084
36085- if ((start >= dev_size) || (start + len > dev_size)) {
36086+ if ((start >= dev_size) || (len > dev_size - start)) {
36087 DMWARN("%s: %s too small for target: "
36088 "start=%llu, len=%llu, dev_size=%llu",
36089 dm_device_name(ti->table->md), bdevname(bdev, b),
36090diff --git a/drivers/md/dm.c b/drivers/md/dm.c
36091index c988ac2..c418141 100644
36092--- a/drivers/md/dm.c
36093+++ b/drivers/md/dm.c
36094@@ -165,9 +165,9 @@ struct mapped_device {
36095 /*
36096 * Event handling.
36097 */
36098- atomic_t event_nr;
36099+ atomic_unchecked_t event_nr;
36100 wait_queue_head_t eventq;
36101- atomic_t uevent_seq;
36102+ atomic_unchecked_t uevent_seq;
36103 struct list_head uevent_list;
36104 spinlock_t uevent_lock; /* Protect access to uevent_list */
36105
36106@@ -1776,8 +1776,8 @@ static struct mapped_device *alloc_dev(int minor)
36107 rwlock_init(&md->map_lock);
36108 atomic_set(&md->holders, 1);
36109 atomic_set(&md->open_count, 0);
36110- atomic_set(&md->event_nr, 0);
36111- atomic_set(&md->uevent_seq, 0);
36112+ atomic_set_unchecked(&md->event_nr, 0);
36113+ atomic_set_unchecked(&md->uevent_seq, 0);
36114 INIT_LIST_HEAD(&md->uevent_list);
36115 spin_lock_init(&md->uevent_lock);
36116
36117@@ -1927,7 +1927,7 @@ static void event_callback(void *context)
36118
36119 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
36120
36121- atomic_inc(&md->event_nr);
36122+ atomic_inc_unchecked(&md->event_nr);
36123 wake_up(&md->eventq);
36124 }
36125
36126@@ -2562,18 +2562,18 @@ void dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
36127
36128 uint32_t dm_next_uevent_seq(struct mapped_device *md)
36129 {
36130- return atomic_add_return(1, &md->uevent_seq);
36131+ return atomic_add_return_unchecked(1, &md->uevent_seq);
36132 }
36133
36134 uint32_t dm_get_event_nr(struct mapped_device *md)
36135 {
36136- return atomic_read(&md->event_nr);
36137+ return atomic_read_unchecked(&md->event_nr);
36138 }
36139
36140 int dm_wait_event(struct mapped_device *md, int event_nr)
36141 {
36142 return wait_event_interruptible(md->eventq,
36143- (event_nr != atomic_read(&md->event_nr)));
36144+ (event_nr != atomic_read_unchecked(&md->event_nr)));
36145 }
36146
36147 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
36148diff --git a/drivers/md/md.c b/drivers/md/md.c
36149index 4ce6e2f..7a9530a 100644
36150--- a/drivers/md/md.c
36151+++ b/drivers/md/md.c
36152@@ -153,10 +153,10 @@ static int start_readonly;
36153 * start build, activate spare
36154 */
36155 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
36156-static atomic_t md_event_count;
36157+static atomic_unchecked_t md_event_count;
36158 void md_new_event(mddev_t *mddev)
36159 {
36160- atomic_inc(&md_event_count);
36161+ atomic_inc_unchecked(&md_event_count);
36162 wake_up(&md_event_waiters);
36163 }
36164 EXPORT_SYMBOL_GPL(md_new_event);
36165@@ -166,7 +166,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
36166 */
36167 static void md_new_event_inintr(mddev_t *mddev)
36168 {
36169- atomic_inc(&md_event_count);
36170+ atomic_inc_unchecked(&md_event_count);
36171 wake_up(&md_event_waiters);
36172 }
36173
36174@@ -1226,7 +1226,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
36175
36176 rdev->preferred_minor = 0xffff;
36177 rdev->data_offset = le64_to_cpu(sb->data_offset);
36178- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36179+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36180
36181 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
36182 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
36183@@ -1400,7 +1400,7 @@ static void super_1_sync(mddev_t *mddev, mdk_rdev_t *rdev)
36184 else
36185 sb->resync_offset = cpu_to_le64(0);
36186
36187- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
36188+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
36189
36190 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
36191 sb->size = cpu_to_le64(mddev->dev_sectors);
36192@@ -2222,7 +2222,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
36193 static ssize_t
36194 errors_show(mdk_rdev_t *rdev, char *page)
36195 {
36196- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
36197+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
36198 }
36199
36200 static ssize_t
36201@@ -2231,7 +2231,7 @@ errors_store(mdk_rdev_t *rdev, const char *buf, size_t len)
36202 char *e;
36203 unsigned long n = simple_strtoul(buf, &e, 10);
36204 if (*buf && (*e == 0 || *e == '\n')) {
36205- atomic_set(&rdev->corrected_errors, n);
36206+ atomic_set_unchecked(&rdev->corrected_errors, n);
36207 return len;
36208 }
36209 return -EINVAL;
36210@@ -2525,7 +2525,7 @@ static void rdev_free(struct kobject *ko)
36211 mdk_rdev_t *rdev = container_of(ko, mdk_rdev_t, kobj);
36212 kfree(rdev);
36213 }
36214-static struct sysfs_ops rdev_sysfs_ops = {
36215+static const struct sysfs_ops rdev_sysfs_ops = {
36216 .show = rdev_attr_show,
36217 .store = rdev_attr_store,
36218 };
36219@@ -2574,8 +2574,8 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
36220 rdev->data_offset = 0;
36221 rdev->sb_events = 0;
36222 atomic_set(&rdev->nr_pending, 0);
36223- atomic_set(&rdev->read_errors, 0);
36224- atomic_set(&rdev->corrected_errors, 0);
36225+ atomic_set_unchecked(&rdev->read_errors, 0);
36226+ atomic_set_unchecked(&rdev->corrected_errors, 0);
36227
36228 size = rdev->bdev->bd_inode->i_size >> BLOCK_SIZE_BITS;
36229 if (!size) {
36230@@ -3895,7 +3895,7 @@ static void md_free(struct kobject *ko)
36231 kfree(mddev);
36232 }
36233
36234-static struct sysfs_ops md_sysfs_ops = {
36235+static const struct sysfs_ops md_sysfs_ops = {
36236 .show = md_attr_show,
36237 .store = md_attr_store,
36238 };
36239@@ -4482,7 +4482,8 @@ out:
36240 err = 0;
36241 blk_integrity_unregister(disk);
36242 md_new_event(mddev);
36243- sysfs_notify_dirent(mddev->sysfs_state);
36244+ if (mddev->sysfs_state)
36245+ sysfs_notify_dirent(mddev->sysfs_state);
36246 return err;
36247 }
36248
36249@@ -5962,7 +5963,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36250
36251 spin_unlock(&pers_lock);
36252 seq_printf(seq, "\n");
36253- mi->event = atomic_read(&md_event_count);
36254+ mi->event = atomic_read_unchecked(&md_event_count);
36255 return 0;
36256 }
36257 if (v == (void*)2) {
36258@@ -6051,7 +6052,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36259 chunk_kb ? "KB" : "B");
36260 if (bitmap->file) {
36261 seq_printf(seq, ", file: ");
36262- seq_path(seq, &bitmap->file->f_path, " \t\n");
36263+ seq_path(seq, &bitmap->file->f_path, " \t\n\\");
36264 }
36265
36266 seq_printf(seq, "\n");
36267@@ -6085,7 +6086,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
36268 else {
36269 struct seq_file *p = file->private_data;
36270 p->private = mi;
36271- mi->event = atomic_read(&md_event_count);
36272+ mi->event = atomic_read_unchecked(&md_event_count);
36273 }
36274 return error;
36275 }
36276@@ -6101,7 +6102,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
36277 /* always allow read */
36278 mask = POLLIN | POLLRDNORM;
36279
36280- if (mi->event != atomic_read(&md_event_count))
36281+ if (mi->event != atomic_read_unchecked(&md_event_count))
36282 mask |= POLLERR | POLLPRI;
36283 return mask;
36284 }
36285@@ -6145,7 +6146,7 @@ static int is_mddev_idle(mddev_t *mddev, int init)
36286 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
36287 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
36288 (int)part_stat_read(&disk->part0, sectors[1]) -
36289- atomic_read(&disk->sync_io);
36290+ atomic_read_unchecked(&disk->sync_io);
36291 /* sync IO will cause sync_io to increase before the disk_stats
36292 * as sync_io is counted when a request starts, and
36293 * disk_stats is counted when it completes.
36294diff --git a/drivers/md/md.h b/drivers/md/md.h
36295index 87430fe..0024a4c 100644
36296--- a/drivers/md/md.h
36297+++ b/drivers/md/md.h
36298@@ -94,10 +94,10 @@ struct mdk_rdev_s
36299 * only maintained for arrays that
36300 * support hot removal
36301 */
36302- atomic_t read_errors; /* number of consecutive read errors that
36303+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
36304 * we have tried to ignore.
36305 */
36306- atomic_t corrected_errors; /* number of corrected read errors,
36307+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
36308 * for reporting to userspace and storing
36309 * in superblock.
36310 */
36311@@ -304,7 +304,7 @@ static inline void rdev_dec_pending(mdk_rdev_t *rdev, mddev_t *mddev)
36312
36313 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
36314 {
36315- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36316+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36317 }
36318
36319 struct mdk_personality
36320diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
36321index 968cb14..f0ad2e4 100644
36322--- a/drivers/md/raid1.c
36323+++ b/drivers/md/raid1.c
36324@@ -1415,7 +1415,7 @@ static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
36325 if (r1_bio->bios[d]->bi_end_io != end_sync_read)
36326 continue;
36327 rdev = conf->mirrors[d].rdev;
36328- atomic_add(s, &rdev->corrected_errors);
36329+ atomic_add_unchecked(s, &rdev->corrected_errors);
36330 if (sync_page_io(rdev->bdev,
36331 sect + rdev->data_offset,
36332 s<<9,
36333@@ -1564,7 +1564,7 @@ static void fix_read_error(conf_t *conf, int read_disk,
36334 /* Well, this device is dead */
36335 md_error(mddev, rdev);
36336 else {
36337- atomic_add(s, &rdev->corrected_errors);
36338+ atomic_add_unchecked(s, &rdev->corrected_errors);
36339 printk(KERN_INFO
36340 "raid1:%s: read error corrected "
36341 "(%d sectors at %llu on %s)\n",
36342diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
36343index 1b4e232..cf0f534 100644
36344--- a/drivers/md/raid10.c
36345+++ b/drivers/md/raid10.c
36346@@ -1255,7 +1255,7 @@ static void end_sync_read(struct bio *bio, int error)
36347 if (test_bit(BIO_UPTODATE, &bio->bi_flags))
36348 set_bit(R10BIO_Uptodate, &r10_bio->state);
36349 else {
36350- atomic_add(r10_bio->sectors,
36351+ atomic_add_unchecked(r10_bio->sectors,
36352 &conf->mirrors[d].rdev->corrected_errors);
36353 if (!test_bit(MD_RECOVERY_SYNC, &conf->mddev->recovery))
36354 md_error(r10_bio->mddev,
36355@@ -1520,7 +1520,7 @@ static void fix_read_error(conf_t *conf, mddev_t *mddev, r10bio_t *r10_bio)
36356 test_bit(In_sync, &rdev->flags)) {
36357 atomic_inc(&rdev->nr_pending);
36358 rcu_read_unlock();
36359- atomic_add(s, &rdev->corrected_errors);
36360+ atomic_add_unchecked(s, &rdev->corrected_errors);
36361 if (sync_page_io(rdev->bdev,
36362 r10_bio->devs[sl].addr +
36363 sect + rdev->data_offset,
36364diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
36365index 883215d..675bf47 100644
36366--- a/drivers/md/raid5.c
36367+++ b/drivers/md/raid5.c
36368@@ -482,7 +482,7 @@ static void ops_run_io(struct stripe_head *sh, struct stripe_head_state *s)
36369 bi->bi_next = NULL;
36370 if ((rw & WRITE) &&
36371 test_bit(R5_ReWrite, &sh->dev[i].flags))
36372- atomic_add(STRIPE_SECTORS,
36373+ atomic_add_unchecked(STRIPE_SECTORS,
36374 &rdev->corrected_errors);
36375 generic_make_request(bi);
36376 } else {
36377@@ -1517,15 +1517,15 @@ static void raid5_end_read_request(struct bio * bi, int error)
36378 clear_bit(R5_ReadError, &sh->dev[i].flags);
36379 clear_bit(R5_ReWrite, &sh->dev[i].flags);
36380 }
36381- if (atomic_read(&conf->disks[i].rdev->read_errors))
36382- atomic_set(&conf->disks[i].rdev->read_errors, 0);
36383+ if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
36384+ atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
36385 } else {
36386 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
36387 int retry = 0;
36388 rdev = conf->disks[i].rdev;
36389
36390 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
36391- atomic_inc(&rdev->read_errors);
36392+ atomic_inc_unchecked(&rdev->read_errors);
36393 if (conf->mddev->degraded >= conf->max_degraded)
36394 printk_rl(KERN_WARNING
36395 "raid5:%s: read error not correctable "
36396@@ -1543,7 +1543,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
36397 (unsigned long long)(sh->sector
36398 + rdev->data_offset),
36399 bdn);
36400- else if (atomic_read(&rdev->read_errors)
36401+ else if (atomic_read_unchecked(&rdev->read_errors)
36402 > conf->max_nr_stripes)
36403 printk(KERN_WARNING
36404 "raid5:%s: Too many read errors, failing device %s.\n",
36405@@ -1870,6 +1870,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i, int previous)
36406 sector_t r_sector;
36407 struct stripe_head sh2;
36408
36409+ pax_track_stack();
36410
36411 chunk_offset = sector_div(new_sector, sectors_per_chunk);
36412 stripe = new_sector;
36413diff --git a/drivers/media/common/saa7146_hlp.c b/drivers/media/common/saa7146_hlp.c
36414index 05bde9c..2f31d40 100644
36415--- a/drivers/media/common/saa7146_hlp.c
36416+++ b/drivers/media/common/saa7146_hlp.c
36417@@ -353,6 +353,8 @@ static void calculate_clipping_registers_rect(struct saa7146_dev *dev, struct sa
36418
36419 int x[32], y[32], w[32], h[32];
36420
36421+ pax_track_stack();
36422+
36423 /* clear out memory */
36424 memset(&line_list[0], 0x00, sizeof(u32)*32);
36425 memset(&pixel_list[0], 0x00, sizeof(u32)*32);
36426diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36427index cb22da5..82b686e 100644
36428--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36429+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
36430@@ -590,6 +590,8 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, u8 * eb
36431 u8 buf[HOST_LINK_BUF_SIZE];
36432 int i;
36433
36434+ pax_track_stack();
36435+
36436 dprintk("%s\n", __func__);
36437
36438 /* check if we have space for a link buf in the rx_buffer */
36439@@ -1285,6 +1287,8 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
36440 unsigned long timeout;
36441 int written;
36442
36443+ pax_track_stack();
36444+
36445 dprintk("%s\n", __func__);
36446
36447 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
36448diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
36449index 2fe05d0..a3289c4 100644
36450--- a/drivers/media/dvb/dvb-core/dvb_demux.h
36451+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
36452@@ -71,7 +71,7 @@ struct dvb_demux_feed {
36453 union {
36454 dmx_ts_cb ts;
36455 dmx_section_cb sec;
36456- } cb;
36457+ } __no_const cb;
36458
36459 struct dvb_demux *demux;
36460 void *priv;
36461diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
36462index 94159b9..376bd8e 100644
36463--- a/drivers/media/dvb/dvb-core/dvbdev.c
36464+++ b/drivers/media/dvb/dvb-core/dvbdev.c
36465@@ -191,7 +191,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
36466 const struct dvb_device *template, void *priv, int type)
36467 {
36468 struct dvb_device *dvbdev;
36469- struct file_operations *dvbdevfops;
36470+ file_operations_no_const *dvbdevfops;
36471 struct device *clsdev;
36472 int minor;
36473 int id;
36474diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
36475index 2a53dd0..db8c07a 100644
36476--- a/drivers/media/dvb/dvb-usb/cxusb.c
36477+++ b/drivers/media/dvb/dvb-usb/cxusb.c
36478@@ -1040,7 +1040,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
36479 struct dib0700_adapter_state {
36480 int (*set_param_save) (struct dvb_frontend *,
36481 struct dvb_frontend_parameters *);
36482-};
36483+} __no_const;
36484
36485 static int dib7070_set_param_override(struct dvb_frontend *fe,
36486 struct dvb_frontend_parameters *fep)
36487diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
36488index db7f7f7..f55e96f 100644
36489--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
36490+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
36491@@ -332,6 +332,8 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
36492
36493 u8 buf[260];
36494
36495+ pax_track_stack();
36496+
36497 while ((ret = dvb_usb_get_hexline(fw, &hx, &pos)) > 0) {
36498 deb_fwdata("writing to address 0x%08x (buffer: 0x%02x %02x)\n",hx.addr, hx.len, hx.chk);
36499
36500diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
36501index 524acf5..5ffc403 100644
36502--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
36503+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
36504@@ -28,7 +28,7 @@ MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplif
36505
36506 struct dib0700_adapter_state {
36507 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *);
36508-};
36509+} __no_const;
36510
36511 /* Hauppauge Nova-T 500 (aka Bristol)
36512 * has a LNA on GPIO0 which is enabled by setting 1 */
36513diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
36514index ba91735..4261d84 100644
36515--- a/drivers/media/dvb/frontends/dib3000.h
36516+++ b/drivers/media/dvb/frontends/dib3000.h
36517@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
36518 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
36519 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
36520 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
36521-};
36522+} __no_const;
36523
36524 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
36525 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
36526diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
36527index c709ce6..b3fe620 100644
36528--- a/drivers/media/dvb/frontends/or51211.c
36529+++ b/drivers/media/dvb/frontends/or51211.c
36530@@ -113,6 +113,8 @@ static int or51211_load_firmware (struct dvb_frontend* fe,
36531 u8 tudata[585];
36532 int i;
36533
36534+ pax_track_stack();
36535+
36536 dprintk("Firmware is %zd bytes\n",fw->size);
36537
36538 /* Get eprom data */
36539diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
36540index 482d0f3..ee1e202 100644
36541--- a/drivers/media/radio/radio-cadet.c
36542+++ b/drivers/media/radio/radio-cadet.c
36543@@ -347,7 +347,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36544 while (i < count && dev->rdsin != dev->rdsout)
36545 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
36546
36547- if (copy_to_user(data, readbuf, i))
36548+ if (i > sizeof readbuf || copy_to_user(data, readbuf, i))
36549 return -EFAULT;
36550 return i;
36551 }
36552diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
36553index 6dd51e2..0359b92 100644
36554--- a/drivers/media/video/cx18/cx18-driver.c
36555+++ b/drivers/media/video/cx18/cx18-driver.c
36556@@ -56,7 +56,7 @@ static struct pci_device_id cx18_pci_tbl[] __devinitdata = {
36557
36558 MODULE_DEVICE_TABLE(pci, cx18_pci_tbl);
36559
36560-static atomic_t cx18_instance = ATOMIC_INIT(0);
36561+static atomic_unchecked_t cx18_instance = ATOMIC_INIT(0);
36562
36563 /* Parameter declarations */
36564 static int cardtype[CX18_MAX_CARDS];
36565@@ -288,6 +288,8 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv)
36566 struct i2c_client c;
36567 u8 eedata[256];
36568
36569+ pax_track_stack();
36570+
36571 memset(&c, 0, sizeof(c));
36572 strlcpy(c.name, "cx18 tveeprom tmp", sizeof(c.name));
36573 c.adapter = &cx->i2c_adap[0];
36574@@ -800,7 +802,7 @@ static int __devinit cx18_probe(struct pci_dev *pci_dev,
36575 struct cx18 *cx;
36576
36577 /* FIXME - module parameter arrays constrain max instances */
36578- i = atomic_inc_return(&cx18_instance) - 1;
36579+ i = atomic_inc_return_unchecked(&cx18_instance) - 1;
36580 if (i >= CX18_MAX_CARDS) {
36581 printk(KERN_ERR "cx18: cannot manage card %d, driver has a "
36582 "limit of 0 - %d\n", i, CX18_MAX_CARDS - 1);
36583diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
36584index 463ec34..2f4625a 100644
36585--- a/drivers/media/video/ivtv/ivtv-driver.c
36586+++ b/drivers/media/video/ivtv/ivtv-driver.c
36587@@ -79,7 +79,7 @@ static struct pci_device_id ivtv_pci_tbl[] __devinitdata = {
36588 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
36589
36590 /* ivtv instance counter */
36591-static atomic_t ivtv_instance = ATOMIC_INIT(0);
36592+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
36593
36594 /* Parameter declarations */
36595 static int cardtype[IVTV_MAX_CARDS];
36596diff --git a/drivers/media/video/omap24xxcam.c b/drivers/media/video/omap24xxcam.c
36597index 5fc4ac0..652a54a 100644
36598--- a/drivers/media/video/omap24xxcam.c
36599+++ b/drivers/media/video/omap24xxcam.c
36600@@ -401,7 +401,7 @@ static void omap24xxcam_vbq_complete(struct omap24xxcam_sgdma *sgdma,
36601 spin_unlock_irqrestore(&cam->core_enable_disable_lock, flags);
36602
36603 do_gettimeofday(&vb->ts);
36604- vb->field_count = atomic_add_return(2, &fh->field_count);
36605+ vb->field_count = atomic_add_return_unchecked(2, &fh->field_count);
36606 if (csr & csr_error) {
36607 vb->state = VIDEOBUF_ERROR;
36608 if (!atomic_read(&fh->cam->in_reset)) {
36609diff --git a/drivers/media/video/omap24xxcam.h b/drivers/media/video/omap24xxcam.h
36610index 2ce67f5..cf26a5b 100644
36611--- a/drivers/media/video/omap24xxcam.h
36612+++ b/drivers/media/video/omap24xxcam.h
36613@@ -533,7 +533,7 @@ struct omap24xxcam_fh {
36614 spinlock_t vbq_lock; /* spinlock for the videobuf queue */
36615 struct videobuf_queue vbq;
36616 struct v4l2_pix_format pix; /* serialise pix by vbq->lock */
36617- atomic_t field_count; /* field counter for videobuf_buffer */
36618+ atomic_unchecked_t field_count; /* field counter for videobuf_buffer */
36619 /* accessing cam here doesn't need serialisation: it's constant */
36620 struct omap24xxcam_device *cam;
36621 };
36622diff --git a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36623index 299afa4..eb47459 100644
36624--- a/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36625+++ b/drivers/media/video/pvrusb2/pvrusb2-eeprom.c
36626@@ -119,6 +119,8 @@ int pvr2_eeprom_analyze(struct pvr2_hdw *hdw)
36627 u8 *eeprom;
36628 struct tveeprom tvdata;
36629
36630+ pax_track_stack();
36631+
36632 memset(&tvdata,0,sizeof(tvdata));
36633
36634 eeprom = pvr2_eeprom_fetch(hdw);
36635diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36636index 5b152ff..3320638 100644
36637--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36638+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
36639@@ -195,7 +195,7 @@ struct pvr2_hdw {
36640
36641 /* I2C stuff */
36642 struct i2c_adapter i2c_adap;
36643- struct i2c_algorithm i2c_algo;
36644+ i2c_algorithm_no_const i2c_algo;
36645 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
36646 int i2c_cx25840_hack_state;
36647 int i2c_linked;
36648diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
36649index 1eabff6..8e2313a 100644
36650--- a/drivers/media/video/saa7134/saa6752hs.c
36651+++ b/drivers/media/video/saa7134/saa6752hs.c
36652@@ -683,6 +683,8 @@ static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
36653 unsigned char localPAT[256];
36654 unsigned char localPMT[256];
36655
36656+ pax_track_stack();
36657+
36658 /* Set video format - must be done first as it resets other settings */
36659 set_reg8(client, 0x41, h->video_format);
36660
36661diff --git a/drivers/media/video/saa7164/saa7164-cmd.c b/drivers/media/video/saa7164/saa7164-cmd.c
36662index 9c1d3ac..b1b49e9 100644
36663--- a/drivers/media/video/saa7164/saa7164-cmd.c
36664+++ b/drivers/media/video/saa7164/saa7164-cmd.c
36665@@ -87,6 +87,8 @@ int saa7164_irq_dequeue(struct saa7164_dev *dev)
36666 wait_queue_head_t *q = 0;
36667 dprintk(DBGLVL_CMD, "%s()\n", __func__);
36668
36669+ pax_track_stack();
36670+
36671 /* While any outstand message on the bus exists... */
36672 do {
36673
36674@@ -126,6 +128,8 @@ int saa7164_cmd_dequeue(struct saa7164_dev *dev)
36675 u8 tmp[512];
36676 dprintk(DBGLVL_CMD, "%s()\n", __func__);
36677
36678+ pax_track_stack();
36679+
36680 while (loop) {
36681
36682 tmComResInfo_t tRsp = { 0, 0, 0, 0, 0, 0 };
36683diff --git a/drivers/media/video/usbvideo/ibmcam.c b/drivers/media/video/usbvideo/ibmcam.c
36684index b085496..cde0270 100644
36685--- a/drivers/media/video/usbvideo/ibmcam.c
36686+++ b/drivers/media/video/usbvideo/ibmcam.c
36687@@ -3947,15 +3947,15 @@ static struct usb_device_id id_table[] = {
36688 static int __init ibmcam_init(void)
36689 {
36690 struct usbvideo_cb cbTbl;
36691- memset(&cbTbl, 0, sizeof(cbTbl));
36692- cbTbl.probe = ibmcam_probe;
36693- cbTbl.setupOnOpen = ibmcam_setup_on_open;
36694- cbTbl.videoStart = ibmcam_video_start;
36695- cbTbl.videoStop = ibmcam_video_stop;
36696- cbTbl.processData = ibmcam_ProcessIsocData;
36697- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36698- cbTbl.adjustPicture = ibmcam_adjust_picture;
36699- cbTbl.getFPS = ibmcam_calculate_fps;
36700+ memset((void *)&cbTbl, 0, sizeof(cbTbl));
36701+ *(void **)&cbTbl.probe = ibmcam_probe;
36702+ *(void **)&cbTbl.setupOnOpen = ibmcam_setup_on_open;
36703+ *(void **)&cbTbl.videoStart = ibmcam_video_start;
36704+ *(void **)&cbTbl.videoStop = ibmcam_video_stop;
36705+ *(void **)&cbTbl.processData = ibmcam_ProcessIsocData;
36706+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36707+ *(void **)&cbTbl.adjustPicture = ibmcam_adjust_picture;
36708+ *(void **)&cbTbl.getFPS = ibmcam_calculate_fps;
36709 return usbvideo_register(
36710 &cams,
36711 MAX_IBMCAM,
36712diff --git a/drivers/media/video/usbvideo/konicawc.c b/drivers/media/video/usbvideo/konicawc.c
36713index 31d57f2..600b735 100644
36714--- a/drivers/media/video/usbvideo/konicawc.c
36715+++ b/drivers/media/video/usbvideo/konicawc.c
36716@@ -225,7 +225,7 @@ static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev
36717 int error;
36718
36719 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
36720- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36721+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36722
36723 cam->input = input_dev = input_allocate_device();
36724 if (!input_dev) {
36725@@ -935,16 +935,16 @@ static int __init konicawc_init(void)
36726 struct usbvideo_cb cbTbl;
36727 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
36728 DRIVER_DESC "\n");
36729- memset(&cbTbl, 0, sizeof(cbTbl));
36730- cbTbl.probe = konicawc_probe;
36731- cbTbl.setupOnOpen = konicawc_setup_on_open;
36732- cbTbl.processData = konicawc_process_isoc;
36733- cbTbl.getFPS = konicawc_calculate_fps;
36734- cbTbl.setVideoMode = konicawc_set_video_mode;
36735- cbTbl.startDataPump = konicawc_start_data;
36736- cbTbl.stopDataPump = konicawc_stop_data;
36737- cbTbl.adjustPicture = konicawc_adjust_picture;
36738- cbTbl.userFree = konicawc_free_uvd;
36739+ memset((void * )&cbTbl, 0, sizeof(cbTbl));
36740+ *(void **)&cbTbl.probe = konicawc_probe;
36741+ *(void **)&cbTbl.setupOnOpen = konicawc_setup_on_open;
36742+ *(void **)&cbTbl.processData = konicawc_process_isoc;
36743+ *(void **)&cbTbl.getFPS = konicawc_calculate_fps;
36744+ *(void **)&cbTbl.setVideoMode = konicawc_set_video_mode;
36745+ *(void **)&cbTbl.startDataPump = konicawc_start_data;
36746+ *(void **)&cbTbl.stopDataPump = konicawc_stop_data;
36747+ *(void **)&cbTbl.adjustPicture = konicawc_adjust_picture;
36748+ *(void **)&cbTbl.userFree = konicawc_free_uvd;
36749 return usbvideo_register(
36750 &cams,
36751 MAX_CAMERAS,
36752diff --git a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
36753index 803d3e4..c4d1b96 100644
36754--- a/drivers/media/video/usbvideo/quickcam_messenger.c
36755+++ b/drivers/media/video/usbvideo/quickcam_messenger.c
36756@@ -89,7 +89,7 @@ static void qcm_register_input(struct qcm *cam, struct usb_device *dev)
36757 int error;
36758
36759 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
36760- strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36761+ strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
36762
36763 cam->input = input_dev = input_allocate_device();
36764 if (!input_dev) {
36765diff --git a/drivers/media/video/usbvideo/ultracam.c b/drivers/media/video/usbvideo/ultracam.c
36766index fbd1b63..292f9f0 100644
36767--- a/drivers/media/video/usbvideo/ultracam.c
36768+++ b/drivers/media/video/usbvideo/ultracam.c
36769@@ -655,14 +655,14 @@ static int __init ultracam_init(void)
36770 {
36771 struct usbvideo_cb cbTbl;
36772 memset(&cbTbl, 0, sizeof(cbTbl));
36773- cbTbl.probe = ultracam_probe;
36774- cbTbl.setupOnOpen = ultracam_setup_on_open;
36775- cbTbl.videoStart = ultracam_video_start;
36776- cbTbl.videoStop = ultracam_video_stop;
36777- cbTbl.processData = ultracam_ProcessIsocData;
36778- cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36779- cbTbl.adjustPicture = ultracam_adjust_picture;
36780- cbTbl.getFPS = ultracam_calculate_fps;
36781+ *(void **)&cbTbl.probe = ultracam_probe;
36782+ *(void **)&cbTbl.setupOnOpen = ultracam_setup_on_open;
36783+ *(void **)&cbTbl.videoStart = ultracam_video_start;
36784+ *(void **)&cbTbl.videoStop = ultracam_video_stop;
36785+ *(void **)&cbTbl.processData = ultracam_ProcessIsocData;
36786+ *(void **)&cbTbl.postProcess = usbvideo_DeinterlaceFrame;
36787+ *(void **)&cbTbl.adjustPicture = ultracam_adjust_picture;
36788+ *(void **)&cbTbl.getFPS = ultracam_calculate_fps;
36789 return usbvideo_register(
36790 &cams,
36791 MAX_CAMERAS,
36792diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
36793index dea8b32..34f6878 100644
36794--- a/drivers/media/video/usbvideo/usbvideo.c
36795+++ b/drivers/media/video/usbvideo/usbvideo.c
36796@@ -697,15 +697,15 @@ int usbvideo_register(
36797 __func__, cams, base_size, num_cams);
36798
36799 /* Copy callbacks, apply defaults for those that are not set */
36800- memmove(&cams->cb, cbTbl, sizeof(cams->cb));
36801+ memmove((void *)&cams->cb, cbTbl, sizeof(cams->cb));
36802 if (cams->cb.getFrame == NULL)
36803- cams->cb.getFrame = usbvideo_GetFrame;
36804+ *(void **)&cams->cb.getFrame = usbvideo_GetFrame;
36805 if (cams->cb.disconnect == NULL)
36806- cams->cb.disconnect = usbvideo_Disconnect;
36807+ *(void **)&cams->cb.disconnect = usbvideo_Disconnect;
36808 if (cams->cb.startDataPump == NULL)
36809- cams->cb.startDataPump = usbvideo_StartDataPump;
36810+ *(void **)&cams->cb.startDataPump = usbvideo_StartDataPump;
36811 if (cams->cb.stopDataPump == NULL)
36812- cams->cb.stopDataPump = usbvideo_StopDataPump;
36813+ *(void **)&cams->cb.stopDataPump = usbvideo_StopDataPump;
36814
36815 cams->num_cameras = num_cams;
36816 cams->cam = (struct uvd *) &cams[1];
36817diff --git a/drivers/media/video/usbvideo/usbvideo.h b/drivers/media/video/usbvideo/usbvideo.h
36818index c66985b..7fa143a 100644
36819--- a/drivers/media/video/usbvideo/usbvideo.h
36820+++ b/drivers/media/video/usbvideo/usbvideo.h
36821@@ -268,7 +268,7 @@ struct usbvideo_cb {
36822 int (*startDataPump)(struct uvd *uvd);
36823 void (*stopDataPump)(struct uvd *uvd);
36824 int (*setVideoMode)(struct uvd *uvd, struct video_window *vw);
36825-};
36826+} __no_const;
36827
36828 struct usbvideo {
36829 int num_cameras; /* As allocated */
36830diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
36831index e0f91e4..37554ea 100644
36832--- a/drivers/media/video/usbvision/usbvision-core.c
36833+++ b/drivers/media/video/usbvision/usbvision-core.c
36834@@ -820,6 +820,8 @@ static enum ParseState usbvision_parse_compress(struct usb_usbvision *usbvision,
36835 unsigned char rv, gv, bv;
36836 static unsigned char *Y, *U, *V;
36837
36838+ pax_track_stack();
36839+
36840 frame = usbvision->curFrame;
36841 imageSize = frame->frmwidth * frame->frmheight;
36842 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
36843diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
36844index 0d06e7c..3d17d24 100644
36845--- a/drivers/media/video/v4l2-device.c
36846+++ b/drivers/media/video/v4l2-device.c
36847@@ -50,9 +50,9 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
36848 EXPORT_SYMBOL_GPL(v4l2_device_register);
36849
36850 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
36851- atomic_t *instance)
36852+ atomic_unchecked_t *instance)
36853 {
36854- int num = atomic_inc_return(instance) - 1;
36855+ int num = atomic_inc_return_unchecked(instance) - 1;
36856 int len = strlen(basename);
36857
36858 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
36859diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
36860index 032ebae..6a3532c 100644
36861--- a/drivers/media/video/videobuf-dma-sg.c
36862+++ b/drivers/media/video/videobuf-dma-sg.c
36863@@ -693,6 +693,8 @@ void *videobuf_sg_alloc(size_t size)
36864 {
36865 struct videobuf_queue q;
36866
36867+ pax_track_stack();
36868+
36869 /* Required to make generic handler to call __videobuf_alloc */
36870 q.int_ops = &sg_ops;
36871
36872diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
36873index b6992b7..9fa7547 100644
36874--- a/drivers/message/fusion/mptbase.c
36875+++ b/drivers/message/fusion/mptbase.c
36876@@ -6709,8 +6709,14 @@ procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eo
36877 len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
36878 len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
36879
36880+#ifdef CONFIG_GRKERNSEC_HIDESYM
36881+ len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36882+ NULL, NULL);
36883+#else
36884 len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36885 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
36886+#endif
36887+
36888 /*
36889 * Rounding UP to nearest 4-kB boundary here...
36890 */
36891diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
36892index 83873e3..e360e9a 100644
36893--- a/drivers/message/fusion/mptsas.c
36894+++ b/drivers/message/fusion/mptsas.c
36895@@ -436,6 +436,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
36896 return 0;
36897 }
36898
36899+static inline void
36900+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36901+{
36902+ if (phy_info->port_details) {
36903+ phy_info->port_details->rphy = rphy;
36904+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36905+ ioc->name, rphy));
36906+ }
36907+
36908+ if (rphy) {
36909+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36910+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36911+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36912+ ioc->name, rphy, rphy->dev.release));
36913+ }
36914+}
36915+
36916 /* no mutex */
36917 static void
36918 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
36919@@ -474,23 +491,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
36920 return NULL;
36921 }
36922
36923-static inline void
36924-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36925-{
36926- if (phy_info->port_details) {
36927- phy_info->port_details->rphy = rphy;
36928- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36929- ioc->name, rphy));
36930- }
36931-
36932- if (rphy) {
36933- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36934- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36935- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36936- ioc->name, rphy, rphy->dev.release));
36937- }
36938-}
36939-
36940 static inline struct sas_port *
36941 mptsas_get_port(struct mptsas_phyinfo *phy_info)
36942 {
36943diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
36944index bd096ca..332cf76 100644
36945--- a/drivers/message/fusion/mptscsih.c
36946+++ b/drivers/message/fusion/mptscsih.c
36947@@ -1248,15 +1248,16 @@ mptscsih_info(struct Scsi_Host *SChost)
36948
36949 h = shost_priv(SChost);
36950
36951- if (h) {
36952- if (h->info_kbuf == NULL)
36953- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36954- return h->info_kbuf;
36955- h->info_kbuf[0] = '\0';
36956+ if (!h)
36957+ return NULL;
36958
36959- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36960- h->info_kbuf[size-1] = '\0';
36961- }
36962+ if (h->info_kbuf == NULL)
36963+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36964+ return h->info_kbuf;
36965+ h->info_kbuf[0] = '\0';
36966+
36967+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36968+ h->info_kbuf[size-1] = '\0';
36969
36970 return h->info_kbuf;
36971 }
36972diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
36973index efba702..59b2c0f 100644
36974--- a/drivers/message/i2o/i2o_config.c
36975+++ b/drivers/message/i2o/i2o_config.c
36976@@ -787,6 +787,8 @@ static int i2o_cfg_passthru(unsigned long arg)
36977 struct i2o_message *msg;
36978 unsigned int iop;
36979
36980+ pax_track_stack();
36981+
36982 if (get_user(iop, &cmd->iop) || get_user(user_msg, &cmd->msg))
36983 return -EFAULT;
36984
36985diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
36986index 7045c45..c07b170 100644
36987--- a/drivers/message/i2o/i2o_proc.c
36988+++ b/drivers/message/i2o/i2o_proc.c
36989@@ -259,13 +259,6 @@ static char *scsi_devices[] = {
36990 "Array Controller Device"
36991 };
36992
36993-static char *chtostr(u8 * chars, int n)
36994-{
36995- char tmp[256];
36996- tmp[0] = 0;
36997- return strncat(tmp, (char *)chars, n);
36998-}
36999-
37000 static int i2o_report_query_status(struct seq_file *seq, int block_status,
37001 char *group)
37002 {
37003@@ -842,8 +835,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
37004
37005 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
37006 seq_printf(seq, "%-#8x", ddm_table.module_id);
37007- seq_printf(seq, "%-29s",
37008- chtostr(ddm_table.module_name_version, 28));
37009+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
37010 seq_printf(seq, "%9d ", ddm_table.data_size);
37011 seq_printf(seq, "%8d", ddm_table.code_size);
37012
37013@@ -944,8 +936,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
37014
37015 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
37016 seq_printf(seq, "%-#8x", dst->module_id);
37017- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
37018- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
37019+ seq_printf(seq, "%-.28s", dst->module_name_version);
37020+ seq_printf(seq, "%-.8s", dst->date);
37021 seq_printf(seq, "%8d ", dst->module_size);
37022 seq_printf(seq, "%8d ", dst->mpb_size);
37023 seq_printf(seq, "0x%04x", dst->module_flags);
37024@@ -1276,14 +1268,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
37025 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
37026 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
37027 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
37028- seq_printf(seq, "Vendor info : %s\n",
37029- chtostr((u8 *) (work32 + 2), 16));
37030- seq_printf(seq, "Product info : %s\n",
37031- chtostr((u8 *) (work32 + 6), 16));
37032- seq_printf(seq, "Description : %s\n",
37033- chtostr((u8 *) (work32 + 10), 16));
37034- seq_printf(seq, "Product rev. : %s\n",
37035- chtostr((u8 *) (work32 + 14), 8));
37036+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
37037+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
37038+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
37039+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
37040
37041 seq_printf(seq, "Serial number : ");
37042 print_serial_number(seq, (u8 *) (work32 + 16),
37043@@ -1328,10 +1316,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
37044 }
37045
37046 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
37047- seq_printf(seq, "Module name : %s\n",
37048- chtostr(result.module_name, 24));
37049- seq_printf(seq, "Module revision : %s\n",
37050- chtostr(result.module_rev, 8));
37051+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
37052+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
37053
37054 seq_printf(seq, "Serial number : ");
37055 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
37056@@ -1362,14 +1348,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
37057 return 0;
37058 }
37059
37060- seq_printf(seq, "Device name : %s\n",
37061- chtostr(result.device_name, 64));
37062- seq_printf(seq, "Service name : %s\n",
37063- chtostr(result.service_name, 64));
37064- seq_printf(seq, "Physical name : %s\n",
37065- chtostr(result.physical_location, 64));
37066- seq_printf(seq, "Instance number : %s\n",
37067- chtostr(result.instance_number, 4));
37068+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
37069+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
37070+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
37071+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
37072
37073 return 0;
37074 }
37075diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
37076index 27cf4af..b1205b8 100644
37077--- a/drivers/message/i2o/iop.c
37078+++ b/drivers/message/i2o/iop.c
37079@@ -110,10 +110,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
37080
37081 spin_lock_irqsave(&c->context_list_lock, flags);
37082
37083- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
37084- atomic_inc(&c->context_list_counter);
37085+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
37086+ atomic_inc_unchecked(&c->context_list_counter);
37087
37088- entry->context = atomic_read(&c->context_list_counter);
37089+ entry->context = atomic_read_unchecked(&c->context_list_counter);
37090
37091 list_add(&entry->list, &c->context_list);
37092
37093@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
37094
37095 #if BITS_PER_LONG == 64
37096 spin_lock_init(&c->context_list_lock);
37097- atomic_set(&c->context_list_counter, 0);
37098+ atomic_set_unchecked(&c->context_list_counter, 0);
37099 INIT_LIST_HEAD(&c->context_list);
37100 #endif
37101
37102diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
37103index 78e3e85..66c9a0d 100644
37104--- a/drivers/mfd/ab3100-core.c
37105+++ b/drivers/mfd/ab3100-core.c
37106@@ -777,7 +777,7 @@ struct ab_family_id {
37107 char *name;
37108 };
37109
37110-static const struct ab_family_id ids[] __initdata = {
37111+static const struct ab_family_id ids[] __initconst = {
37112 /* AB3100 */
37113 {
37114 .id = 0xc0,
37115diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
37116index 8d8c932..8104515 100644
37117--- a/drivers/mfd/wm8350-i2c.c
37118+++ b/drivers/mfd/wm8350-i2c.c
37119@@ -43,6 +43,8 @@ static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg,
37120 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
37121 int ret;
37122
37123+ pax_track_stack();
37124+
37125 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
37126 return -EINVAL;
37127
37128diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
37129index e4ff50b..4cc3f04 100644
37130--- a/drivers/misc/kgdbts.c
37131+++ b/drivers/misc/kgdbts.c
37132@@ -118,7 +118,7 @@
37133 } while (0)
37134 #define MAX_CONFIG_LEN 40
37135
37136-static struct kgdb_io kgdbts_io_ops;
37137+static const struct kgdb_io kgdbts_io_ops;
37138 static char get_buf[BUFMAX];
37139 static int get_buf_cnt;
37140 static char put_buf[BUFMAX];
37141@@ -1102,7 +1102,7 @@ static void kgdbts_post_exp_handler(void)
37142 module_put(THIS_MODULE);
37143 }
37144
37145-static struct kgdb_io kgdbts_io_ops = {
37146+static const struct kgdb_io kgdbts_io_ops = {
37147 .name = "kgdbts",
37148 .read_char = kgdbts_get_char,
37149 .write_char = kgdbts_put_char,
37150diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
37151index 37e7cfc..67cfb76 100644
37152--- a/drivers/misc/sgi-gru/gruhandles.c
37153+++ b/drivers/misc/sgi-gru/gruhandles.c
37154@@ -39,8 +39,8 @@ struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37155
37156 static void update_mcs_stats(enum mcs_op op, unsigned long clks)
37157 {
37158- atomic_long_inc(&mcs_op_statistics[op].count);
37159- atomic_long_add(clks, &mcs_op_statistics[op].total);
37160+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
37161+ atomic_long_add_unchecked(clks, &mcs_op_statistics[op].total);
37162 if (mcs_op_statistics[op].max < clks)
37163 mcs_op_statistics[op].max = clks;
37164 }
37165diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
37166index 3f2375c..467c6e6 100644
37167--- a/drivers/misc/sgi-gru/gruprocfs.c
37168+++ b/drivers/misc/sgi-gru/gruprocfs.c
37169@@ -32,9 +32,9 @@
37170
37171 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
37172
37173-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
37174+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
37175 {
37176- unsigned long val = atomic_long_read(v);
37177+ unsigned long val = atomic_long_read_unchecked(v);
37178
37179 if (val)
37180 seq_printf(s, "%16lu %s\n", val, id);
37181@@ -136,8 +136,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
37182 "cch_interrupt_sync", "cch_deallocate", "tgh_invalidate"};
37183
37184 for (op = 0; op < mcsop_last; op++) {
37185- count = atomic_long_read(&mcs_op_statistics[op].count);
37186- total = atomic_long_read(&mcs_op_statistics[op].total);
37187+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
37188+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
37189 max = mcs_op_statistics[op].max;
37190 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
37191 count ? total / count : 0, max);
37192diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
37193index 46990bc..4a251b5 100644
37194--- a/drivers/misc/sgi-gru/grutables.h
37195+++ b/drivers/misc/sgi-gru/grutables.h
37196@@ -167,84 +167,84 @@ extern unsigned int gru_max_gids;
37197 * GRU statistics.
37198 */
37199 struct gru_stats_s {
37200- atomic_long_t vdata_alloc;
37201- atomic_long_t vdata_free;
37202- atomic_long_t gts_alloc;
37203- atomic_long_t gts_free;
37204- atomic_long_t vdata_double_alloc;
37205- atomic_long_t gts_double_allocate;
37206- atomic_long_t assign_context;
37207- atomic_long_t assign_context_failed;
37208- atomic_long_t free_context;
37209- atomic_long_t load_user_context;
37210- atomic_long_t load_kernel_context;
37211- atomic_long_t lock_kernel_context;
37212- atomic_long_t unlock_kernel_context;
37213- atomic_long_t steal_user_context;
37214- atomic_long_t steal_kernel_context;
37215- atomic_long_t steal_context_failed;
37216- atomic_long_t nopfn;
37217- atomic_long_t break_cow;
37218- atomic_long_t asid_new;
37219- atomic_long_t asid_next;
37220- atomic_long_t asid_wrap;
37221- atomic_long_t asid_reuse;
37222- atomic_long_t intr;
37223- atomic_long_t intr_mm_lock_failed;
37224- atomic_long_t call_os;
37225- atomic_long_t call_os_offnode_reference;
37226- atomic_long_t call_os_check_for_bug;
37227- atomic_long_t call_os_wait_queue;
37228- atomic_long_t user_flush_tlb;
37229- atomic_long_t user_unload_context;
37230- atomic_long_t user_exception;
37231- atomic_long_t set_context_option;
37232- atomic_long_t migrate_check;
37233- atomic_long_t migrated_retarget;
37234- atomic_long_t migrated_unload;
37235- atomic_long_t migrated_unload_delay;
37236- atomic_long_t migrated_nopfn_retarget;
37237- atomic_long_t migrated_nopfn_unload;
37238- atomic_long_t tlb_dropin;
37239- atomic_long_t tlb_dropin_fail_no_asid;
37240- atomic_long_t tlb_dropin_fail_upm;
37241- atomic_long_t tlb_dropin_fail_invalid;
37242- atomic_long_t tlb_dropin_fail_range_active;
37243- atomic_long_t tlb_dropin_fail_idle;
37244- atomic_long_t tlb_dropin_fail_fmm;
37245- atomic_long_t tlb_dropin_fail_no_exception;
37246- atomic_long_t tlb_dropin_fail_no_exception_war;
37247- atomic_long_t tfh_stale_on_fault;
37248- atomic_long_t mmu_invalidate_range;
37249- atomic_long_t mmu_invalidate_page;
37250- atomic_long_t mmu_clear_flush_young;
37251- atomic_long_t flush_tlb;
37252- atomic_long_t flush_tlb_gru;
37253- atomic_long_t flush_tlb_gru_tgh;
37254- atomic_long_t flush_tlb_gru_zero_asid;
37255+ atomic_long_unchecked_t vdata_alloc;
37256+ atomic_long_unchecked_t vdata_free;
37257+ atomic_long_unchecked_t gts_alloc;
37258+ atomic_long_unchecked_t gts_free;
37259+ atomic_long_unchecked_t vdata_double_alloc;
37260+ atomic_long_unchecked_t gts_double_allocate;
37261+ atomic_long_unchecked_t assign_context;
37262+ atomic_long_unchecked_t assign_context_failed;
37263+ atomic_long_unchecked_t free_context;
37264+ atomic_long_unchecked_t load_user_context;
37265+ atomic_long_unchecked_t load_kernel_context;
37266+ atomic_long_unchecked_t lock_kernel_context;
37267+ atomic_long_unchecked_t unlock_kernel_context;
37268+ atomic_long_unchecked_t steal_user_context;
37269+ atomic_long_unchecked_t steal_kernel_context;
37270+ atomic_long_unchecked_t steal_context_failed;
37271+ atomic_long_unchecked_t nopfn;
37272+ atomic_long_unchecked_t break_cow;
37273+ atomic_long_unchecked_t asid_new;
37274+ atomic_long_unchecked_t asid_next;
37275+ atomic_long_unchecked_t asid_wrap;
37276+ atomic_long_unchecked_t asid_reuse;
37277+ atomic_long_unchecked_t intr;
37278+ atomic_long_unchecked_t intr_mm_lock_failed;
37279+ atomic_long_unchecked_t call_os;
37280+ atomic_long_unchecked_t call_os_offnode_reference;
37281+ atomic_long_unchecked_t call_os_check_for_bug;
37282+ atomic_long_unchecked_t call_os_wait_queue;
37283+ atomic_long_unchecked_t user_flush_tlb;
37284+ atomic_long_unchecked_t user_unload_context;
37285+ atomic_long_unchecked_t user_exception;
37286+ atomic_long_unchecked_t set_context_option;
37287+ atomic_long_unchecked_t migrate_check;
37288+ atomic_long_unchecked_t migrated_retarget;
37289+ atomic_long_unchecked_t migrated_unload;
37290+ atomic_long_unchecked_t migrated_unload_delay;
37291+ atomic_long_unchecked_t migrated_nopfn_retarget;
37292+ atomic_long_unchecked_t migrated_nopfn_unload;
37293+ atomic_long_unchecked_t tlb_dropin;
37294+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
37295+ atomic_long_unchecked_t tlb_dropin_fail_upm;
37296+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
37297+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
37298+ atomic_long_unchecked_t tlb_dropin_fail_idle;
37299+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
37300+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
37301+ atomic_long_unchecked_t tlb_dropin_fail_no_exception_war;
37302+ atomic_long_unchecked_t tfh_stale_on_fault;
37303+ atomic_long_unchecked_t mmu_invalidate_range;
37304+ atomic_long_unchecked_t mmu_invalidate_page;
37305+ atomic_long_unchecked_t mmu_clear_flush_young;
37306+ atomic_long_unchecked_t flush_tlb;
37307+ atomic_long_unchecked_t flush_tlb_gru;
37308+ atomic_long_unchecked_t flush_tlb_gru_tgh;
37309+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
37310
37311- atomic_long_t copy_gpa;
37312+ atomic_long_unchecked_t copy_gpa;
37313
37314- atomic_long_t mesq_receive;
37315- atomic_long_t mesq_receive_none;
37316- atomic_long_t mesq_send;
37317- atomic_long_t mesq_send_failed;
37318- atomic_long_t mesq_noop;
37319- atomic_long_t mesq_send_unexpected_error;
37320- atomic_long_t mesq_send_lb_overflow;
37321- atomic_long_t mesq_send_qlimit_reached;
37322- atomic_long_t mesq_send_amo_nacked;
37323- atomic_long_t mesq_send_put_nacked;
37324- atomic_long_t mesq_qf_not_full;
37325- atomic_long_t mesq_qf_locked;
37326- atomic_long_t mesq_qf_noop_not_full;
37327- atomic_long_t mesq_qf_switch_head_failed;
37328- atomic_long_t mesq_qf_unexpected_error;
37329- atomic_long_t mesq_noop_unexpected_error;
37330- atomic_long_t mesq_noop_lb_overflow;
37331- atomic_long_t mesq_noop_qlimit_reached;
37332- atomic_long_t mesq_noop_amo_nacked;
37333- atomic_long_t mesq_noop_put_nacked;
37334+ atomic_long_unchecked_t mesq_receive;
37335+ atomic_long_unchecked_t mesq_receive_none;
37336+ atomic_long_unchecked_t mesq_send;
37337+ atomic_long_unchecked_t mesq_send_failed;
37338+ atomic_long_unchecked_t mesq_noop;
37339+ atomic_long_unchecked_t mesq_send_unexpected_error;
37340+ atomic_long_unchecked_t mesq_send_lb_overflow;
37341+ atomic_long_unchecked_t mesq_send_qlimit_reached;
37342+ atomic_long_unchecked_t mesq_send_amo_nacked;
37343+ atomic_long_unchecked_t mesq_send_put_nacked;
37344+ atomic_long_unchecked_t mesq_qf_not_full;
37345+ atomic_long_unchecked_t mesq_qf_locked;
37346+ atomic_long_unchecked_t mesq_qf_noop_not_full;
37347+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
37348+ atomic_long_unchecked_t mesq_qf_unexpected_error;
37349+ atomic_long_unchecked_t mesq_noop_unexpected_error;
37350+ atomic_long_unchecked_t mesq_noop_lb_overflow;
37351+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
37352+ atomic_long_unchecked_t mesq_noop_amo_nacked;
37353+ atomic_long_unchecked_t mesq_noop_put_nacked;
37354
37355 };
37356
37357@@ -252,8 +252,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
37358 cchop_deallocate, tghop_invalidate, mcsop_last};
37359
37360 struct mcs_op_statistic {
37361- atomic_long_t count;
37362- atomic_long_t total;
37363+ atomic_long_unchecked_t count;
37364+ atomic_long_unchecked_t total;
37365 unsigned long max;
37366 };
37367
37368@@ -276,7 +276,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37369
37370 #define STAT(id) do { \
37371 if (gru_options & OPT_STATS) \
37372- atomic_long_inc(&gru_stats.id); \
37373+ atomic_long_inc_unchecked(&gru_stats.id); \
37374 } while (0)
37375
37376 #ifdef CONFIG_SGI_GRU_DEBUG
37377diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
37378index 2275126..12a9dbfb 100644
37379--- a/drivers/misc/sgi-xp/xp.h
37380+++ b/drivers/misc/sgi-xp/xp.h
37381@@ -289,7 +289,7 @@ struct xpc_interface {
37382 xpc_notify_func, void *);
37383 void (*received) (short, int, void *);
37384 enum xp_retval (*partid_to_nasids) (short, void *);
37385-};
37386+} __no_const;
37387
37388 extern struct xpc_interface xpc_interface;
37389
37390diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
37391index b94d5f7..7f494c5 100644
37392--- a/drivers/misc/sgi-xp/xpc.h
37393+++ b/drivers/misc/sgi-xp/xpc.h
37394@@ -835,6 +835,7 @@ struct xpc_arch_operations {
37395 void (*received_payload) (struct xpc_channel *, void *);
37396 void (*notify_senders_of_disconnect) (struct xpc_channel *);
37397 };
37398+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
37399
37400 /* struct xpc_partition act_state values (for XPC HB) */
37401
37402@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
37403 /* found in xpc_main.c */
37404 extern struct device *xpc_part;
37405 extern struct device *xpc_chan;
37406-extern struct xpc_arch_operations xpc_arch_ops;
37407+extern xpc_arch_operations_no_const xpc_arch_ops;
37408 extern int xpc_disengage_timelimit;
37409 extern int xpc_disengage_timedout;
37410 extern int xpc_activate_IRQ_rcvd;
37411diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
37412index fd3688a..7e211a4 100644
37413--- a/drivers/misc/sgi-xp/xpc_main.c
37414+++ b/drivers/misc/sgi-xp/xpc_main.c
37415@@ -169,7 +169,7 @@ static struct notifier_block xpc_die_notifier = {
37416 .notifier_call = xpc_system_die,
37417 };
37418
37419-struct xpc_arch_operations xpc_arch_ops;
37420+xpc_arch_operations_no_const xpc_arch_ops;
37421
37422 /*
37423 * Timer function to enforce the timelimit on the partition disengage.
37424diff --git a/drivers/misc/sgi-xp/xpc_sn2.c b/drivers/misc/sgi-xp/xpc_sn2.c
37425index 8b70e03..700bda6 100644
37426--- a/drivers/misc/sgi-xp/xpc_sn2.c
37427+++ b/drivers/misc/sgi-xp/xpc_sn2.c
37428@@ -2350,7 +2350,7 @@ xpc_received_payload_sn2(struct xpc_channel *ch, void *payload)
37429 xpc_acknowledge_msgs_sn2(ch, get, msg->flags);
37430 }
37431
37432-static struct xpc_arch_operations xpc_arch_ops_sn2 = {
37433+static const struct xpc_arch_operations xpc_arch_ops_sn2 = {
37434 .setup_partitions = xpc_setup_partitions_sn2,
37435 .teardown_partitions = xpc_teardown_partitions_sn2,
37436 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_sn2,
37437@@ -2413,7 +2413,9 @@ xpc_init_sn2(void)
37438 int ret;
37439 size_t buf_size;
37440
37441- xpc_arch_ops = xpc_arch_ops_sn2;
37442+ pax_open_kernel();
37443+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_sn2, sizeof(xpc_arch_ops_sn2));
37444+ pax_close_kernel();
37445
37446 if (offsetof(struct xpc_msg_sn2, payload) > XPC_MSG_HDR_MAX_SIZE) {
37447 dev_err(xpc_part, "header portion of struct xpc_msg_sn2 is "
37448diff --git a/drivers/misc/sgi-xp/xpc_uv.c b/drivers/misc/sgi-xp/xpc_uv.c
37449index 8e08d71..7cb8c9b 100644
37450--- a/drivers/misc/sgi-xp/xpc_uv.c
37451+++ b/drivers/misc/sgi-xp/xpc_uv.c
37452@@ -1669,7 +1669,7 @@ xpc_received_payload_uv(struct xpc_channel *ch, void *payload)
37453 XPC_DEACTIVATE_PARTITION(&xpc_partitions[ch->partid], ret);
37454 }
37455
37456-static struct xpc_arch_operations xpc_arch_ops_uv = {
37457+static const struct xpc_arch_operations xpc_arch_ops_uv = {
37458 .setup_partitions = xpc_setup_partitions_uv,
37459 .teardown_partitions = xpc_teardown_partitions_uv,
37460 .process_activate_IRQ_rcvd = xpc_process_activate_IRQ_rcvd_uv,
37461@@ -1729,7 +1729,9 @@ static struct xpc_arch_operations xpc_arch_ops_uv = {
37462 int
37463 xpc_init_uv(void)
37464 {
37465- xpc_arch_ops = xpc_arch_ops_uv;
37466+ pax_open_kernel();
37467+ memcpy((void *)&xpc_arch_ops, &xpc_arch_ops_uv, sizeof(xpc_arch_ops_uv));
37468+ pax_close_kernel();
37469
37470 if (sizeof(struct xpc_notify_mq_msghdr_uv) > XPC_MSG_HDR_MAX_SIZE) {
37471 dev_err(xpc_part, "xpc_notify_mq_msghdr_uv is larger than %d\n",
37472diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
37473index 6fd20b42..650efe3 100644
37474--- a/drivers/mmc/host/sdhci-pci.c
37475+++ b/drivers/mmc/host/sdhci-pci.c
37476@@ -297,7 +297,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
37477 .probe = via_probe,
37478 };
37479
37480-static const struct pci_device_id pci_ids[] __devinitdata = {
37481+static const struct pci_device_id pci_ids[] __devinitconst = {
37482 {
37483 .vendor = PCI_VENDOR_ID_RICOH,
37484 .device = PCI_DEVICE_ID_RICOH_R5C822,
37485diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
37486index e7563a9..5f90ce5 100644
37487--- a/drivers/mtd/chips/cfi_cmdset_0001.c
37488+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
37489@@ -743,6 +743,8 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
37490 struct cfi_pri_intelext *cfip = cfi->cmdset_priv;
37491 unsigned long timeo = jiffies + HZ;
37492
37493+ pax_track_stack();
37494+
37495 /* Prevent setting state FL_SYNCING for chip in suspended state. */
37496 if (mode == FL_SYNCING && chip->oldstate != FL_READY)
37497 goto sleep;
37498@@ -1642,6 +1644,8 @@ static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
37499 unsigned long initial_adr;
37500 int initial_len = len;
37501
37502+ pax_track_stack();
37503+
37504 wbufsize = cfi_interleave(cfi) << cfi->cfiq->MaxBufWriteSize;
37505 adr += chip->start;
37506 initial_adr = adr;
37507@@ -1860,6 +1864,8 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
37508 int retries = 3;
37509 int ret;
37510
37511+ pax_track_stack();
37512+
37513 adr += chip->start;
37514
37515 retry:
37516diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
37517index 0667a67..3ab97ed 100644
37518--- a/drivers/mtd/chips/cfi_cmdset_0020.c
37519+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
37520@@ -255,6 +255,8 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
37521 unsigned long cmd_addr;
37522 struct cfi_private *cfi = map->fldrv_priv;
37523
37524+ pax_track_stack();
37525+
37526 adr += chip->start;
37527
37528 /* Ensure cmd read/writes are aligned. */
37529@@ -428,6 +430,8 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
37530 DECLARE_WAITQUEUE(wait, current);
37531 int wbufsize, z;
37532
37533+ pax_track_stack();
37534+
37535 /* M58LW064A requires bus alignment for buffer wriets -- saw */
37536 if (adr & (map_bankwidth(map)-1))
37537 return -EINVAL;
37538@@ -742,6 +746,8 @@ static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, u
37539 DECLARE_WAITQUEUE(wait, current);
37540 int ret = 0;
37541
37542+ pax_track_stack();
37543+
37544 adr += chip->start;
37545
37546 /* Let's determine this according to the interleave only once */
37547@@ -1047,6 +1053,8 @@ static inline int do_lock_oneblock(struct map_info *map, struct flchip *chip, un
37548 unsigned long timeo = jiffies + HZ;
37549 DECLARE_WAITQUEUE(wait, current);
37550
37551+ pax_track_stack();
37552+
37553 adr += chip->start;
37554
37555 /* Let's determine this according to the interleave only once */
37556@@ -1196,6 +1204,8 @@ static inline int do_unlock_oneblock(struct map_info *map, struct flchip *chip,
37557 unsigned long timeo = jiffies + HZ;
37558 DECLARE_WAITQUEUE(wait, current);
37559
37560+ pax_track_stack();
37561+
37562 adr += chip->start;
37563
37564 /* Let's determine this according to the interleave only once */
37565diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
37566index 5bf5f46..c5de373 100644
37567--- a/drivers/mtd/devices/doc2000.c
37568+++ b/drivers/mtd/devices/doc2000.c
37569@@ -776,7 +776,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
37570
37571 /* The ECC will not be calculated correctly if less than 512 is written */
37572 /* DBB-
37573- if (len != 0x200 && eccbuf)
37574+ if (len != 0x200)
37575 printk(KERN_WARNING
37576 "ECC needs a full sector write (adr: %lx size %lx)\n",
37577 (long) to, (long) len);
37578diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
37579index 0990f78..bb4e8a4 100644
37580--- a/drivers/mtd/devices/doc2001.c
37581+++ b/drivers/mtd/devices/doc2001.c
37582@@ -393,7 +393,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
37583 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
37584
37585 /* Don't allow read past end of device */
37586- if (from >= this->totlen)
37587+ if (from >= this->totlen || !len)
37588 return -EINVAL;
37589
37590 /* Don't allow a single read to cross a 512-byte block boundary */
37591diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
37592index e56d6b4..f07e6cf 100644
37593--- a/drivers/mtd/ftl.c
37594+++ b/drivers/mtd/ftl.c
37595@@ -474,6 +474,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit,
37596 loff_t offset;
37597 uint16_t srcunitswap = cpu_to_le16(srcunit);
37598
37599+ pax_track_stack();
37600+
37601 eun = &part->EUNInfo[srcunit];
37602 xfer = &part->XferInfo[xferunit];
37603 DEBUG(2, "ftl_cs: copying block 0x%x to 0x%x\n",
37604diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
37605index 8aca552..146446e 100755
37606--- a/drivers/mtd/inftlcore.c
37607+++ b/drivers/mtd/inftlcore.c
37608@@ -260,6 +260,8 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned
37609 struct inftl_oob oob;
37610 size_t retlen;
37611
37612+ pax_track_stack();
37613+
37614 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: INFTL_foldchain(inftl=%p,thisVUC=%d,"
37615 "pending=%d)\n", inftl, thisVUC, pendingblock);
37616
37617diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
37618index 32e82ae..ed50953 100644
37619--- a/drivers/mtd/inftlmount.c
37620+++ b/drivers/mtd/inftlmount.c
37621@@ -54,6 +54,8 @@ static int find_boot_record(struct INFTLrecord *inftl)
37622 struct INFTLPartition *ip;
37623 size_t retlen;
37624
37625+ pax_track_stack();
37626+
37627 DEBUG(MTD_DEBUG_LEVEL3, "INFTL: find_boot_record(inftl=%p)\n", inftl);
37628
37629 /*
37630diff --git a/drivers/mtd/lpddr/qinfo_probe.c b/drivers/mtd/lpddr/qinfo_probe.c
37631index 79bf40f..fe5f8fd 100644
37632--- a/drivers/mtd/lpddr/qinfo_probe.c
37633+++ b/drivers/mtd/lpddr/qinfo_probe.c
37634@@ -106,6 +106,8 @@ static int lpddr_pfow_present(struct map_info *map, struct lpddr_private *lpddr)
37635 {
37636 map_word pfow_val[4];
37637
37638+ pax_track_stack();
37639+
37640 /* Check identification string */
37641 pfow_val[0] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_P);
37642 pfow_val[1] = map_read(map, map->pfow_base + PFOW_QUERY_STRING_F);
37643diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
37644index 726a1b8..f46b460 100644
37645--- a/drivers/mtd/mtdchar.c
37646+++ b/drivers/mtd/mtdchar.c
37647@@ -461,6 +461,8 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
37648 u_long size;
37649 struct mtd_info_user info;
37650
37651+ pax_track_stack();
37652+
37653 DEBUG(MTD_DEBUG_LEVEL0, "MTD_ioctl\n");
37654
37655 size = (cmd & IOCSIZE_MASK) >> IOCSIZE_SHIFT;
37656diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
37657index 1002e18..26d82d5 100644
37658--- a/drivers/mtd/nftlcore.c
37659+++ b/drivers/mtd/nftlcore.c
37660@@ -254,6 +254,8 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p
37661 int inplace = 1;
37662 size_t retlen;
37663
37664+ pax_track_stack();
37665+
37666 memset(BlockMap, 0xff, sizeof(BlockMap));
37667 memset(BlockFreeFound, 0, sizeof(BlockFreeFound));
37668
37669diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
37670index 8b22b18..6fada85 100644
37671--- a/drivers/mtd/nftlmount.c
37672+++ b/drivers/mtd/nftlmount.c
37673@@ -23,6 +23,7 @@
37674 #include <asm/errno.h>
37675 #include <linux/delay.h>
37676 #include <linux/slab.h>
37677+#include <linux/sched.h>
37678 #include <linux/mtd/mtd.h>
37679 #include <linux/mtd/nand.h>
37680 #include <linux/mtd/nftl.h>
37681@@ -44,6 +45,8 @@ static int find_boot_record(struct NFTLrecord *nftl)
37682 struct mtd_info *mtd = nftl->mbd.mtd;
37683 unsigned int i;
37684
37685+ pax_track_stack();
37686+
37687 /* Assume logical EraseSize == physical erasesize for starting the scan.
37688 We'll sort it out later if we find a MediaHeader which says otherwise */
37689 /* Actually, we won't. The new DiskOnChip driver has already scanned
37690diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
37691index 14cec04..d775b87 100644
37692--- a/drivers/mtd/ubi/build.c
37693+++ b/drivers/mtd/ubi/build.c
37694@@ -1255,7 +1255,7 @@ module_exit(ubi_exit);
37695 static int __init bytes_str_to_int(const char *str)
37696 {
37697 char *endp;
37698- unsigned long result;
37699+ unsigned long result, scale = 1;
37700
37701 result = simple_strtoul(str, &endp, 0);
37702 if (str == endp || result >= INT_MAX) {
37703@@ -1266,11 +1266,11 @@ static int __init bytes_str_to_int(const char *str)
37704
37705 switch (*endp) {
37706 case 'G':
37707- result *= 1024;
37708+ scale *= 1024;
37709 case 'M':
37710- result *= 1024;
37711+ scale *= 1024;
37712 case 'K':
37713- result *= 1024;
37714+ scale *= 1024;
37715 if (endp[1] == 'i' && endp[2] == 'B')
37716 endp += 2;
37717 case '\0':
37718@@ -1281,7 +1281,13 @@ static int __init bytes_str_to_int(const char *str)
37719 return -EINVAL;
37720 }
37721
37722- return result;
37723+ if ((intoverflow_t)result*scale >= INT_MAX) {
37724+ printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
37725+ str);
37726+ return -EINVAL;
37727+ }
37728+
37729+ return result*scale;
37730 }
37731
37732 /**
37733diff --git a/drivers/net/atlx/atl2.c b/drivers/net/atlx/atl2.c
37734index ab68886..ca405e8 100644
37735--- a/drivers/net/atlx/atl2.c
37736+++ b/drivers/net/atlx/atl2.c
37737@@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
37738 */
37739
37740 #define ATL2_PARAM(X, desc) \
37741- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
37742+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
37743 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
37744 MODULE_PARM_DESC(X, desc);
37745 #else
37746diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
37747index 4874b2b..67f8526 100644
37748--- a/drivers/net/bnx2.c
37749+++ b/drivers/net/bnx2.c
37750@@ -5809,6 +5809,8 @@ bnx2_test_nvram(struct bnx2 *bp)
37751 int rc = 0;
37752 u32 magic, csum;
37753
37754+ pax_track_stack();
37755+
37756 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
37757 goto test_nvram_done;
37758
37759diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h
37760index fd3eb07..8a6978d 100644
37761--- a/drivers/net/cxgb3/l2t.h
37762+++ b/drivers/net/cxgb3/l2t.h
37763@@ -86,7 +86,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
37764 */
37765 struct l2t_skb_cb {
37766 arp_failure_handler_func arp_failure_handler;
37767-};
37768+} __no_const;
37769
37770 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
37771
37772diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c
37773index 032cfe0..411af379 100644
37774--- a/drivers/net/cxgb3/t3_hw.c
37775+++ b/drivers/net/cxgb3/t3_hw.c
37776@@ -699,6 +699,8 @@ static int get_vpd_params(struct adapter *adapter, struct vpd_params *p)
37777 int i, addr, ret;
37778 struct t3_vpd vpd;
37779
37780+ pax_track_stack();
37781+
37782 /*
37783 * Card information is normally at VPD_BASE but some early cards had
37784 * it at 0.
37785diff --git a/drivers/net/e1000e/82571.c b/drivers/net/e1000e/82571.c
37786index d1e0563..b9e129c 100644
37787--- a/drivers/net/e1000e/82571.c
37788+++ b/drivers/net/e1000e/82571.c
37789@@ -212,7 +212,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
37790 {
37791 struct e1000_hw *hw = &adapter->hw;
37792 struct e1000_mac_info *mac = &hw->mac;
37793- struct e1000_mac_operations *func = &mac->ops;
37794+ e1000_mac_operations_no_const *func = &mac->ops;
37795 u32 swsm = 0;
37796 u32 swsm2 = 0;
37797 bool force_clear_smbi = false;
37798@@ -1656,7 +1656,7 @@ static void e1000_clear_hw_cntrs_82571(struct e1000_hw *hw)
37799 temp = er32(ICRXDMTC);
37800 }
37801
37802-static struct e1000_mac_operations e82571_mac_ops = {
37803+static const struct e1000_mac_operations e82571_mac_ops = {
37804 /* .check_mng_mode: mac type dependent */
37805 /* .check_for_link: media type dependent */
37806 .id_led_init = e1000e_id_led_init,
37807@@ -1674,7 +1674,7 @@ static struct e1000_mac_operations e82571_mac_ops = {
37808 .setup_led = e1000e_setup_led_generic,
37809 };
37810
37811-static struct e1000_phy_operations e82_phy_ops_igp = {
37812+static const struct e1000_phy_operations e82_phy_ops_igp = {
37813 .acquire_phy = e1000_get_hw_semaphore_82571,
37814 .check_reset_block = e1000e_check_reset_block_generic,
37815 .commit_phy = NULL,
37816@@ -1691,7 +1691,7 @@ static struct e1000_phy_operations e82_phy_ops_igp = {
37817 .cfg_on_link_up = NULL,
37818 };
37819
37820-static struct e1000_phy_operations e82_phy_ops_m88 = {
37821+static const struct e1000_phy_operations e82_phy_ops_m88 = {
37822 .acquire_phy = e1000_get_hw_semaphore_82571,
37823 .check_reset_block = e1000e_check_reset_block_generic,
37824 .commit_phy = e1000e_phy_sw_reset,
37825@@ -1708,7 +1708,7 @@ static struct e1000_phy_operations e82_phy_ops_m88 = {
37826 .cfg_on_link_up = NULL,
37827 };
37828
37829-static struct e1000_phy_operations e82_phy_ops_bm = {
37830+static const struct e1000_phy_operations e82_phy_ops_bm = {
37831 .acquire_phy = e1000_get_hw_semaphore_82571,
37832 .check_reset_block = e1000e_check_reset_block_generic,
37833 .commit_phy = e1000e_phy_sw_reset,
37834@@ -1725,7 +1725,7 @@ static struct e1000_phy_operations e82_phy_ops_bm = {
37835 .cfg_on_link_up = NULL,
37836 };
37837
37838-static struct e1000_nvm_operations e82571_nvm_ops = {
37839+static const struct e1000_nvm_operations e82571_nvm_ops = {
37840 .acquire_nvm = e1000_acquire_nvm_82571,
37841 .read_nvm = e1000e_read_nvm_eerd,
37842 .release_nvm = e1000_release_nvm_82571,
37843diff --git a/drivers/net/e1000e/e1000.h b/drivers/net/e1000e/e1000.h
37844index 47db9bd..fa58ccd 100644
37845--- a/drivers/net/e1000e/e1000.h
37846+++ b/drivers/net/e1000e/e1000.h
37847@@ -375,9 +375,9 @@ struct e1000_info {
37848 u32 pba;
37849 u32 max_hw_frame_size;
37850 s32 (*get_variants)(struct e1000_adapter *);
37851- struct e1000_mac_operations *mac_ops;
37852- struct e1000_phy_operations *phy_ops;
37853- struct e1000_nvm_operations *nvm_ops;
37854+ const struct e1000_mac_operations *mac_ops;
37855+ const struct e1000_phy_operations *phy_ops;
37856+ const struct e1000_nvm_operations *nvm_ops;
37857 };
37858
37859 /* hardware capability, feature, and workaround flags */
37860diff --git a/drivers/net/e1000e/es2lan.c b/drivers/net/e1000e/es2lan.c
37861index ae5d736..e9a93a1 100644
37862--- a/drivers/net/e1000e/es2lan.c
37863+++ b/drivers/net/e1000e/es2lan.c
37864@@ -207,7 +207,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
37865 {
37866 struct e1000_hw *hw = &adapter->hw;
37867 struct e1000_mac_info *mac = &hw->mac;
37868- struct e1000_mac_operations *func = &mac->ops;
37869+ e1000_mac_operations_no_const *func = &mac->ops;
37870
37871 /* Set media type */
37872 switch (adapter->pdev->device) {
37873@@ -1365,7 +1365,7 @@ static void e1000_clear_hw_cntrs_80003es2lan(struct e1000_hw *hw)
37874 temp = er32(ICRXDMTC);
37875 }
37876
37877-static struct e1000_mac_operations es2_mac_ops = {
37878+static const struct e1000_mac_operations es2_mac_ops = {
37879 .id_led_init = e1000e_id_led_init,
37880 .check_mng_mode = e1000e_check_mng_mode_generic,
37881 /* check_for_link dependent on media type */
37882@@ -1383,7 +1383,7 @@ static struct e1000_mac_operations es2_mac_ops = {
37883 .setup_led = e1000e_setup_led_generic,
37884 };
37885
37886-static struct e1000_phy_operations es2_phy_ops = {
37887+static const struct e1000_phy_operations es2_phy_ops = {
37888 .acquire_phy = e1000_acquire_phy_80003es2lan,
37889 .check_reset_block = e1000e_check_reset_block_generic,
37890 .commit_phy = e1000e_phy_sw_reset,
37891@@ -1400,7 +1400,7 @@ static struct e1000_phy_operations es2_phy_ops = {
37892 .cfg_on_link_up = e1000_cfg_on_link_up_80003es2lan,
37893 };
37894
37895-static struct e1000_nvm_operations es2_nvm_ops = {
37896+static const struct e1000_nvm_operations es2_nvm_ops = {
37897 .acquire_nvm = e1000_acquire_nvm_80003es2lan,
37898 .read_nvm = e1000e_read_nvm_eerd,
37899 .release_nvm = e1000_release_nvm_80003es2lan,
37900diff --git a/drivers/net/e1000e/hw.h b/drivers/net/e1000e/hw.h
37901index 11f3b7c..6381887 100644
37902--- a/drivers/net/e1000e/hw.h
37903+++ b/drivers/net/e1000e/hw.h
37904@@ -753,6 +753,7 @@ struct e1000_mac_operations {
37905 s32 (*setup_physical_interface)(struct e1000_hw *);
37906 s32 (*setup_led)(struct e1000_hw *);
37907 };
37908+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
37909
37910 /* Function pointers for the PHY. */
37911 struct e1000_phy_operations {
37912@@ -774,6 +775,7 @@ struct e1000_phy_operations {
37913 s32 (*write_phy_reg_locked)(struct e1000_hw *, u32, u16);
37914 s32 (*cfg_on_link_up)(struct e1000_hw *);
37915 };
37916+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
37917
37918 /* Function pointers for the NVM. */
37919 struct e1000_nvm_operations {
37920@@ -785,9 +787,10 @@ struct e1000_nvm_operations {
37921 s32 (*validate_nvm)(struct e1000_hw *);
37922 s32 (*write_nvm)(struct e1000_hw *, u16, u16, u16 *);
37923 };
37924+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
37925
37926 struct e1000_mac_info {
37927- struct e1000_mac_operations ops;
37928+ e1000_mac_operations_no_const ops;
37929
37930 u8 addr[6];
37931 u8 perm_addr[6];
37932@@ -823,7 +826,7 @@ struct e1000_mac_info {
37933 };
37934
37935 struct e1000_phy_info {
37936- struct e1000_phy_operations ops;
37937+ e1000_phy_operations_no_const ops;
37938
37939 enum e1000_phy_type type;
37940
37941@@ -857,7 +860,7 @@ struct e1000_phy_info {
37942 };
37943
37944 struct e1000_nvm_info {
37945- struct e1000_nvm_operations ops;
37946+ e1000_nvm_operations_no_const ops;
37947
37948 enum e1000_nvm_type type;
37949 enum e1000_nvm_override override;
37950diff --git a/drivers/net/e1000e/ich8lan.c b/drivers/net/e1000e/ich8lan.c
37951index de39f9a..e28d3e0 100644
37952--- a/drivers/net/e1000e/ich8lan.c
37953+++ b/drivers/net/e1000e/ich8lan.c
37954@@ -3463,7 +3463,7 @@ static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
37955 }
37956 }
37957
37958-static struct e1000_mac_operations ich8_mac_ops = {
37959+static const struct e1000_mac_operations ich8_mac_ops = {
37960 .id_led_init = e1000e_id_led_init,
37961 .check_mng_mode = e1000_check_mng_mode_ich8lan,
37962 .check_for_link = e1000_check_for_copper_link_ich8lan,
37963@@ -3481,7 +3481,7 @@ static struct e1000_mac_operations ich8_mac_ops = {
37964 /* id_led_init dependent on mac type */
37965 };
37966
37967-static struct e1000_phy_operations ich8_phy_ops = {
37968+static const struct e1000_phy_operations ich8_phy_ops = {
37969 .acquire_phy = e1000_acquire_swflag_ich8lan,
37970 .check_reset_block = e1000_check_reset_block_ich8lan,
37971 .commit_phy = NULL,
37972@@ -3497,7 +3497,7 @@ static struct e1000_phy_operations ich8_phy_ops = {
37973 .write_phy_reg = e1000e_write_phy_reg_igp,
37974 };
37975
37976-static struct e1000_nvm_operations ich8_nvm_ops = {
37977+static const struct e1000_nvm_operations ich8_nvm_ops = {
37978 .acquire_nvm = e1000_acquire_nvm_ich8lan,
37979 .read_nvm = e1000_read_nvm_ich8lan,
37980 .release_nvm = e1000_release_nvm_ich8lan,
37981diff --git a/drivers/net/fealnx.c b/drivers/net/fealnx.c
37982index 18d5fbb..542d96d 100644
37983--- a/drivers/net/fealnx.c
37984+++ b/drivers/net/fealnx.c
37985@@ -151,7 +151,7 @@ struct chip_info {
37986 int flags;
37987 };
37988
37989-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
37990+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
37991 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
37992 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
37993 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
37994diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
37995index 0e5b54b..b503f82 100644
37996--- a/drivers/net/hamradio/6pack.c
37997+++ b/drivers/net/hamradio/6pack.c
37998@@ -461,6 +461,8 @@ static void sixpack_receive_buf(struct tty_struct *tty,
37999 unsigned char buf[512];
38000 int count1;
38001
38002+ pax_track_stack();
38003+
38004 if (!count)
38005 return;
38006
38007diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
38008index 5862282..7cce8cb 100644
38009--- a/drivers/net/ibmveth.c
38010+++ b/drivers/net/ibmveth.c
38011@@ -1577,7 +1577,7 @@ static struct attribute * veth_pool_attrs[] = {
38012 NULL,
38013 };
38014
38015-static struct sysfs_ops veth_pool_ops = {
38016+static const struct sysfs_ops veth_pool_ops = {
38017 .show = veth_pool_show,
38018 .store = veth_pool_store,
38019 };
38020diff --git a/drivers/net/igb/e1000_82575.c b/drivers/net/igb/e1000_82575.c
38021index d617f2d..57b5309 100644
38022--- a/drivers/net/igb/e1000_82575.c
38023+++ b/drivers/net/igb/e1000_82575.c
38024@@ -1411,7 +1411,7 @@ void igb_vmdq_set_replication_pf(struct e1000_hw *hw, bool enable)
38025 wr32(E1000_VT_CTL, vt_ctl);
38026 }
38027
38028-static struct e1000_mac_operations e1000_mac_ops_82575 = {
38029+static const struct e1000_mac_operations e1000_mac_ops_82575 = {
38030 .reset_hw = igb_reset_hw_82575,
38031 .init_hw = igb_init_hw_82575,
38032 .check_for_link = igb_check_for_link_82575,
38033@@ -1420,13 +1420,13 @@ static struct e1000_mac_operations e1000_mac_ops_82575 = {
38034 .get_speed_and_duplex = igb_get_speed_and_duplex_copper,
38035 };
38036
38037-static struct e1000_phy_operations e1000_phy_ops_82575 = {
38038+static const struct e1000_phy_operations e1000_phy_ops_82575 = {
38039 .acquire = igb_acquire_phy_82575,
38040 .get_cfg_done = igb_get_cfg_done_82575,
38041 .release = igb_release_phy_82575,
38042 };
38043
38044-static struct e1000_nvm_operations e1000_nvm_ops_82575 = {
38045+static const struct e1000_nvm_operations e1000_nvm_ops_82575 = {
38046 .acquire = igb_acquire_nvm_82575,
38047 .read = igb_read_nvm_eerd,
38048 .release = igb_release_nvm_82575,
38049diff --git a/drivers/net/igb/e1000_hw.h b/drivers/net/igb/e1000_hw.h
38050index 72081df..d855cf5 100644
38051--- a/drivers/net/igb/e1000_hw.h
38052+++ b/drivers/net/igb/e1000_hw.h
38053@@ -288,6 +288,7 @@ struct e1000_mac_operations {
38054 s32 (*read_mac_addr)(struct e1000_hw *);
38055 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
38056 };
38057+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
38058
38059 struct e1000_phy_operations {
38060 s32 (*acquire)(struct e1000_hw *);
38061@@ -303,6 +304,7 @@ struct e1000_phy_operations {
38062 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
38063 s32 (*write_reg)(struct e1000_hw *, u32, u16);
38064 };
38065+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
38066
38067 struct e1000_nvm_operations {
38068 s32 (*acquire)(struct e1000_hw *);
38069@@ -310,6 +312,7 @@ struct e1000_nvm_operations {
38070 void (*release)(struct e1000_hw *);
38071 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
38072 };
38073+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
38074
38075 struct e1000_info {
38076 s32 (*get_invariants)(struct e1000_hw *);
38077@@ -321,7 +324,7 @@ struct e1000_info {
38078 extern const struct e1000_info e1000_82575_info;
38079
38080 struct e1000_mac_info {
38081- struct e1000_mac_operations ops;
38082+ e1000_mac_operations_no_const ops;
38083
38084 u8 addr[6];
38085 u8 perm_addr[6];
38086@@ -365,7 +368,7 @@ struct e1000_mac_info {
38087 };
38088
38089 struct e1000_phy_info {
38090- struct e1000_phy_operations ops;
38091+ e1000_phy_operations_no_const ops;
38092
38093 enum e1000_phy_type type;
38094
38095@@ -400,7 +403,7 @@ struct e1000_phy_info {
38096 };
38097
38098 struct e1000_nvm_info {
38099- struct e1000_nvm_operations ops;
38100+ e1000_nvm_operations_no_const ops;
38101
38102 enum e1000_nvm_type type;
38103 enum e1000_nvm_override override;
38104@@ -446,6 +449,7 @@ struct e1000_mbx_operations {
38105 s32 (*check_for_ack)(struct e1000_hw *, u16);
38106 s32 (*check_for_rst)(struct e1000_hw *, u16);
38107 };
38108+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
38109
38110 struct e1000_mbx_stats {
38111 u32 msgs_tx;
38112@@ -457,7 +461,7 @@ struct e1000_mbx_stats {
38113 };
38114
38115 struct e1000_mbx_info {
38116- struct e1000_mbx_operations ops;
38117+ e1000_mbx_operations_no_const ops;
38118 struct e1000_mbx_stats stats;
38119 u32 timeout;
38120 u32 usec_delay;
38121diff --git a/drivers/net/igbvf/vf.h b/drivers/net/igbvf/vf.h
38122index 1e8ce37..549c453 100644
38123--- a/drivers/net/igbvf/vf.h
38124+++ b/drivers/net/igbvf/vf.h
38125@@ -187,9 +187,10 @@ struct e1000_mac_operations {
38126 s32 (*read_mac_addr)(struct e1000_hw *);
38127 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
38128 };
38129+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
38130
38131 struct e1000_mac_info {
38132- struct e1000_mac_operations ops;
38133+ e1000_mac_operations_no_const ops;
38134 u8 addr[6];
38135 u8 perm_addr[6];
38136
38137@@ -211,6 +212,7 @@ struct e1000_mbx_operations {
38138 s32 (*check_for_ack)(struct e1000_hw *);
38139 s32 (*check_for_rst)(struct e1000_hw *);
38140 };
38141+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
38142
38143 struct e1000_mbx_stats {
38144 u32 msgs_tx;
38145@@ -222,7 +224,7 @@ struct e1000_mbx_stats {
38146 };
38147
38148 struct e1000_mbx_info {
38149- struct e1000_mbx_operations ops;
38150+ e1000_mbx_operations_no_const ops;
38151 struct e1000_mbx_stats stats;
38152 u32 timeout;
38153 u32 usec_delay;
38154diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
38155index aa7286b..a61394f 100644
38156--- a/drivers/net/iseries_veth.c
38157+++ b/drivers/net/iseries_veth.c
38158@@ -384,7 +384,7 @@ static struct attribute *veth_cnx_default_attrs[] = {
38159 NULL
38160 };
38161
38162-static struct sysfs_ops veth_cnx_sysfs_ops = {
38163+static const struct sysfs_ops veth_cnx_sysfs_ops = {
38164 .show = veth_cnx_attribute_show
38165 };
38166
38167@@ -441,7 +441,7 @@ static struct attribute *veth_port_default_attrs[] = {
38168 NULL
38169 };
38170
38171-static struct sysfs_ops veth_port_sysfs_ops = {
38172+static const struct sysfs_ops veth_port_sysfs_ops = {
38173 .show = veth_port_attribute_show
38174 };
38175
38176diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
38177index 8aa44dc..fa1e797 100644
38178--- a/drivers/net/ixgb/ixgb_main.c
38179+++ b/drivers/net/ixgb/ixgb_main.c
38180@@ -1052,6 +1052,8 @@ ixgb_set_multi(struct net_device *netdev)
38181 u32 rctl;
38182 int i;
38183
38184+ pax_track_stack();
38185+
38186 /* Check for Promiscuous and All Multicast modes */
38187
38188 rctl = IXGB_READ_REG(hw, RCTL);
38189diff --git a/drivers/net/ixgb/ixgb_param.c b/drivers/net/ixgb/ixgb_param.c
38190index af35e1d..8781785 100644
38191--- a/drivers/net/ixgb/ixgb_param.c
38192+++ b/drivers/net/ixgb/ixgb_param.c
38193@@ -260,6 +260,9 @@ void __devinit
38194 ixgb_check_options(struct ixgb_adapter *adapter)
38195 {
38196 int bd = adapter->bd_number;
38197+
38198+ pax_track_stack();
38199+
38200 if (bd >= IXGB_MAX_NIC) {
38201 printk(KERN_NOTICE
38202 "Warning: no configuration for board #%i\n", bd);
38203diff --git a/drivers/net/ixgbe/ixgbe_type.h b/drivers/net/ixgbe/ixgbe_type.h
38204index b17aa73..ed74540 100644
38205--- a/drivers/net/ixgbe/ixgbe_type.h
38206+++ b/drivers/net/ixgbe/ixgbe_type.h
38207@@ -2327,6 +2327,7 @@ struct ixgbe_eeprom_operations {
38208 s32 (*validate_checksum)(struct ixgbe_hw *, u16 *);
38209 s32 (*update_checksum)(struct ixgbe_hw *);
38210 };
38211+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
38212
38213 struct ixgbe_mac_operations {
38214 s32 (*init_hw)(struct ixgbe_hw *);
38215@@ -2376,6 +2377,7 @@ struct ixgbe_mac_operations {
38216 /* Flow Control */
38217 s32 (*fc_enable)(struct ixgbe_hw *, s32);
38218 };
38219+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
38220
38221 struct ixgbe_phy_operations {
38222 s32 (*identify)(struct ixgbe_hw *);
38223@@ -2394,9 +2396,10 @@ struct ixgbe_phy_operations {
38224 s32 (*read_i2c_eeprom)(struct ixgbe_hw *, u8 , u8 *);
38225 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
38226 };
38227+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
38228
38229 struct ixgbe_eeprom_info {
38230- struct ixgbe_eeprom_operations ops;
38231+ ixgbe_eeprom_operations_no_const ops;
38232 enum ixgbe_eeprom_type type;
38233 u32 semaphore_delay;
38234 u16 word_size;
38235@@ -2404,7 +2407,7 @@ struct ixgbe_eeprom_info {
38236 };
38237
38238 struct ixgbe_mac_info {
38239- struct ixgbe_mac_operations ops;
38240+ ixgbe_mac_operations_no_const ops;
38241 enum ixgbe_mac_type type;
38242 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
38243 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
38244@@ -2423,7 +2426,7 @@ struct ixgbe_mac_info {
38245 };
38246
38247 struct ixgbe_phy_info {
38248- struct ixgbe_phy_operations ops;
38249+ ixgbe_phy_operations_no_const ops;
38250 struct mdio_if_info mdio;
38251 enum ixgbe_phy_type type;
38252 u32 id;
38253diff --git a/drivers/net/mlx4/main.c b/drivers/net/mlx4/main.c
38254index 291a505..2543756 100644
38255--- a/drivers/net/mlx4/main.c
38256+++ b/drivers/net/mlx4/main.c
38257@@ -38,6 +38,7 @@
38258 #include <linux/errno.h>
38259 #include <linux/pci.h>
38260 #include <linux/dma-mapping.h>
38261+#include <linux/sched.h>
38262
38263 #include <linux/mlx4/device.h>
38264 #include <linux/mlx4/doorbell.h>
38265@@ -730,6 +731,8 @@ static int mlx4_init_hca(struct mlx4_dev *dev)
38266 u64 icm_size;
38267 int err;
38268
38269+ pax_track_stack();
38270+
38271 err = mlx4_QUERY_FW(dev);
38272 if (err) {
38273 if (err == -EACCES)
38274diff --git a/drivers/net/niu.c b/drivers/net/niu.c
38275index 2dce134..fa5ce75 100644
38276--- a/drivers/net/niu.c
38277+++ b/drivers/net/niu.c
38278@@ -9128,6 +9128,8 @@ static void __devinit niu_try_msix(struct niu *np, u8 *ldg_num_map)
38279 int i, num_irqs, err;
38280 u8 first_ldg;
38281
38282+ pax_track_stack();
38283+
38284 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port;
38285 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++)
38286 ldg_num_map[i] = first_ldg + i;
38287diff --git a/drivers/net/pcnet32.c b/drivers/net/pcnet32.c
38288index c1b3f09..97cd8c4 100644
38289--- a/drivers/net/pcnet32.c
38290+++ b/drivers/net/pcnet32.c
38291@@ -79,7 +79,7 @@ static int cards_found;
38292 /*
38293 * VLB I/O addresses
38294 */
38295-static unsigned int pcnet32_portlist[] __initdata =
38296+static unsigned int pcnet32_portlist[] __devinitdata =
38297 { 0x300, 0x320, 0x340, 0x360, 0 };
38298
38299 static int pcnet32_debug = 0;
38300@@ -267,7 +267,7 @@ struct pcnet32_private {
38301 struct sk_buff **rx_skbuff;
38302 dma_addr_t *tx_dma_addr;
38303 dma_addr_t *rx_dma_addr;
38304- struct pcnet32_access a;
38305+ struct pcnet32_access *a;
38306 spinlock_t lock; /* Guard lock */
38307 unsigned int cur_rx, cur_tx; /* The next free ring entry */
38308 unsigned int rx_ring_size; /* current rx ring size */
38309@@ -457,9 +457,9 @@ static void pcnet32_netif_start(struct net_device *dev)
38310 u16 val;
38311
38312 netif_wake_queue(dev);
38313- val = lp->a.read_csr(ioaddr, CSR3);
38314+ val = lp->a->read_csr(ioaddr, CSR3);
38315 val &= 0x00ff;
38316- lp->a.write_csr(ioaddr, CSR3, val);
38317+ lp->a->write_csr(ioaddr, CSR3, val);
38318 napi_enable(&lp->napi);
38319 }
38320
38321@@ -744,7 +744,7 @@ static u32 pcnet32_get_link(struct net_device *dev)
38322 r = mii_link_ok(&lp->mii_if);
38323 } else if (lp->chip_version >= PCNET32_79C970A) {
38324 ulong ioaddr = dev->base_addr; /* card base I/O address */
38325- r = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
38326+ r = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
38327 } else { /* can not detect link on really old chips */
38328 r = 1;
38329 }
38330@@ -806,7 +806,7 @@ static int pcnet32_set_ringparam(struct net_device *dev,
38331 pcnet32_netif_stop(dev);
38332
38333 spin_lock_irqsave(&lp->lock, flags);
38334- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38335+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38336
38337 size = min(ering->tx_pending, (unsigned int)TX_MAX_RING_SIZE);
38338
38339@@ -886,7 +886,7 @@ static void pcnet32_ethtool_test(struct net_device *dev,
38340 static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38341 {
38342 struct pcnet32_private *lp = netdev_priv(dev);
38343- struct pcnet32_access *a = &lp->a; /* access to registers */
38344+ struct pcnet32_access *a = lp->a; /* access to registers */
38345 ulong ioaddr = dev->base_addr; /* card base I/O address */
38346 struct sk_buff *skb; /* sk buff */
38347 int x, i; /* counters */
38348@@ -906,21 +906,21 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38349 pcnet32_netif_stop(dev);
38350
38351 spin_lock_irqsave(&lp->lock, flags);
38352- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38353+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* stop the chip */
38354
38355 numbuffs = min(numbuffs, (int)min(lp->rx_ring_size, lp->tx_ring_size));
38356
38357 /* Reset the PCNET32 */
38358- lp->a.reset(ioaddr);
38359- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38360+ lp->a->reset(ioaddr);
38361+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38362
38363 /* switch pcnet32 to 32bit mode */
38364- lp->a.write_bcr(ioaddr, 20, 2);
38365+ lp->a->write_bcr(ioaddr, 20, 2);
38366
38367 /* purge & init rings but don't actually restart */
38368 pcnet32_restart(dev, 0x0000);
38369
38370- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38371+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38372
38373 /* Initialize Transmit buffers. */
38374 size = data_len + 15;
38375@@ -966,10 +966,10 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38376
38377 /* set int loopback in CSR15 */
38378 x = a->read_csr(ioaddr, CSR15) & 0xfffc;
38379- lp->a.write_csr(ioaddr, CSR15, x | 0x0044);
38380+ lp->a->write_csr(ioaddr, CSR15, x | 0x0044);
38381
38382 teststatus = cpu_to_le16(0x8000);
38383- lp->a.write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
38384+ lp->a->write_csr(ioaddr, CSR0, CSR0_START); /* Set STRT bit */
38385
38386 /* Check status of descriptors */
38387 for (x = 0; x < numbuffs; x++) {
38388@@ -990,7 +990,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38389 }
38390 }
38391
38392- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38393+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP); /* Set STOP bit */
38394 wmb();
38395 if (netif_msg_hw(lp) && netif_msg_pktdata(lp)) {
38396 printk(KERN_DEBUG "%s: RX loopback packets:\n", dev->name);
38397@@ -1039,7 +1039,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38398 pcnet32_restart(dev, CSR0_NORMAL);
38399 } else {
38400 pcnet32_purge_rx_ring(dev);
38401- lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
38402+ lp->a->write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
38403 }
38404 spin_unlock_irqrestore(&lp->lock, flags);
38405
38406@@ -1049,7 +1049,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
38407 static void pcnet32_led_blink_callback(struct net_device *dev)
38408 {
38409 struct pcnet32_private *lp = netdev_priv(dev);
38410- struct pcnet32_access *a = &lp->a;
38411+ struct pcnet32_access *a = lp->a;
38412 ulong ioaddr = dev->base_addr;
38413 unsigned long flags;
38414 int i;
38415@@ -1066,7 +1066,7 @@ static void pcnet32_led_blink_callback(struct net_device *dev)
38416 static int pcnet32_phys_id(struct net_device *dev, u32 data)
38417 {
38418 struct pcnet32_private *lp = netdev_priv(dev);
38419- struct pcnet32_access *a = &lp->a;
38420+ struct pcnet32_access *a = lp->a;
38421 ulong ioaddr = dev->base_addr;
38422 unsigned long flags;
38423 int i, regs[4];
38424@@ -1112,7 +1112,7 @@ static int pcnet32_suspend(struct net_device *dev, unsigned long *flags,
38425 {
38426 int csr5;
38427 struct pcnet32_private *lp = netdev_priv(dev);
38428- struct pcnet32_access *a = &lp->a;
38429+ struct pcnet32_access *a = lp->a;
38430 ulong ioaddr = dev->base_addr;
38431 int ticks;
38432
38433@@ -1388,8 +1388,8 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
38434 spin_lock_irqsave(&lp->lock, flags);
38435 if (pcnet32_tx(dev)) {
38436 /* reset the chip to clear the error condition, then restart */
38437- lp->a.reset(ioaddr);
38438- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38439+ lp->a->reset(ioaddr);
38440+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38441 pcnet32_restart(dev, CSR0_START);
38442 netif_wake_queue(dev);
38443 }
38444@@ -1401,12 +1401,12 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
38445 __napi_complete(napi);
38446
38447 /* clear interrupt masks */
38448- val = lp->a.read_csr(ioaddr, CSR3);
38449+ val = lp->a->read_csr(ioaddr, CSR3);
38450 val &= 0x00ff;
38451- lp->a.write_csr(ioaddr, CSR3, val);
38452+ lp->a->write_csr(ioaddr, CSR3, val);
38453
38454 /* Set interrupt enable. */
38455- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
38456+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN);
38457
38458 spin_unlock_irqrestore(&lp->lock, flags);
38459 }
38460@@ -1429,7 +1429,7 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
38461 int i, csr0;
38462 u16 *buff = ptr;
38463 struct pcnet32_private *lp = netdev_priv(dev);
38464- struct pcnet32_access *a = &lp->a;
38465+ struct pcnet32_access *a = lp->a;
38466 ulong ioaddr = dev->base_addr;
38467 unsigned long flags;
38468
38469@@ -1466,9 +1466,9 @@ static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
38470 for (j = 0; j < PCNET32_MAX_PHYS; j++) {
38471 if (lp->phymask & (1 << j)) {
38472 for (i = 0; i < PCNET32_REGS_PER_PHY; i++) {
38473- lp->a.write_bcr(ioaddr, 33,
38474+ lp->a->write_bcr(ioaddr, 33,
38475 (j << 5) | i);
38476- *buff++ = lp->a.read_bcr(ioaddr, 34);
38477+ *buff++ = lp->a->read_bcr(ioaddr, 34);
38478 }
38479 }
38480 }
38481@@ -1858,7 +1858,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38482 ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
38483 lp->options |= PCNET32_PORT_FD;
38484
38485- lp->a = *a;
38486+ lp->a = a;
38487
38488 /* prior to register_netdev, dev->name is not yet correct */
38489 if (pcnet32_alloc_ring(dev, pci_name(lp->pci_dev))) {
38490@@ -1917,7 +1917,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38491 if (lp->mii) {
38492 /* lp->phycount and lp->phymask are set to 0 by memset above */
38493
38494- lp->mii_if.phy_id = ((lp->a.read_bcr(ioaddr, 33)) >> 5) & 0x1f;
38495+ lp->mii_if.phy_id = ((lp->a->read_bcr(ioaddr, 33)) >> 5) & 0x1f;
38496 /* scan for PHYs */
38497 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
38498 unsigned short id1, id2;
38499@@ -1938,7 +1938,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
38500 "Found PHY %04x:%04x at address %d.\n",
38501 id1, id2, i);
38502 }
38503- lp->a.write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
38504+ lp->a->write_bcr(ioaddr, 33, (lp->mii_if.phy_id) << 5);
38505 if (lp->phycount > 1) {
38506 lp->options |= PCNET32_PORT_MII;
38507 }
38508@@ -2109,10 +2109,10 @@ static int pcnet32_open(struct net_device *dev)
38509 }
38510
38511 /* Reset the PCNET32 */
38512- lp->a.reset(ioaddr);
38513+ lp->a->reset(ioaddr);
38514
38515 /* switch pcnet32 to 32bit mode */
38516- lp->a.write_bcr(ioaddr, 20, 2);
38517+ lp->a->write_bcr(ioaddr, 20, 2);
38518
38519 if (netif_msg_ifup(lp))
38520 printk(KERN_DEBUG
38521@@ -2122,14 +2122,14 @@ static int pcnet32_open(struct net_device *dev)
38522 (u32) (lp->init_dma_addr));
38523
38524 /* set/reset autoselect bit */
38525- val = lp->a.read_bcr(ioaddr, 2) & ~2;
38526+ val = lp->a->read_bcr(ioaddr, 2) & ~2;
38527 if (lp->options & PCNET32_PORT_ASEL)
38528 val |= 2;
38529- lp->a.write_bcr(ioaddr, 2, val);
38530+ lp->a->write_bcr(ioaddr, 2, val);
38531
38532 /* handle full duplex setting */
38533 if (lp->mii_if.full_duplex) {
38534- val = lp->a.read_bcr(ioaddr, 9) & ~3;
38535+ val = lp->a->read_bcr(ioaddr, 9) & ~3;
38536 if (lp->options & PCNET32_PORT_FD) {
38537 val |= 1;
38538 if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
38539@@ -2139,14 +2139,14 @@ static int pcnet32_open(struct net_device *dev)
38540 if (lp->chip_version == 0x2627)
38541 val |= 3;
38542 }
38543- lp->a.write_bcr(ioaddr, 9, val);
38544+ lp->a->write_bcr(ioaddr, 9, val);
38545 }
38546
38547 /* set/reset GPSI bit in test register */
38548- val = lp->a.read_csr(ioaddr, 124) & ~0x10;
38549+ val = lp->a->read_csr(ioaddr, 124) & ~0x10;
38550 if ((lp->options & PCNET32_PORT_PORTSEL) == PCNET32_PORT_GPSI)
38551 val |= 0x10;
38552- lp->a.write_csr(ioaddr, 124, val);
38553+ lp->a->write_csr(ioaddr, 124, val);
38554
38555 /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
38556 if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
38557@@ -2167,24 +2167,24 @@ static int pcnet32_open(struct net_device *dev)
38558 * duplex, and/or enable auto negotiation, and clear DANAS
38559 */
38560 if (lp->mii && !(lp->options & PCNET32_PORT_ASEL)) {
38561- lp->a.write_bcr(ioaddr, 32,
38562- lp->a.read_bcr(ioaddr, 32) | 0x0080);
38563+ lp->a->write_bcr(ioaddr, 32,
38564+ lp->a->read_bcr(ioaddr, 32) | 0x0080);
38565 /* disable Auto Negotiation, set 10Mpbs, HD */
38566- val = lp->a.read_bcr(ioaddr, 32) & ~0xb8;
38567+ val = lp->a->read_bcr(ioaddr, 32) & ~0xb8;
38568 if (lp->options & PCNET32_PORT_FD)
38569 val |= 0x10;
38570 if (lp->options & PCNET32_PORT_100)
38571 val |= 0x08;
38572- lp->a.write_bcr(ioaddr, 32, val);
38573+ lp->a->write_bcr(ioaddr, 32, val);
38574 } else {
38575 if (lp->options & PCNET32_PORT_ASEL) {
38576- lp->a.write_bcr(ioaddr, 32,
38577- lp->a.read_bcr(ioaddr,
38578+ lp->a->write_bcr(ioaddr, 32,
38579+ lp->a->read_bcr(ioaddr,
38580 32) | 0x0080);
38581 /* enable auto negotiate, setup, disable fd */
38582- val = lp->a.read_bcr(ioaddr, 32) & ~0x98;
38583+ val = lp->a->read_bcr(ioaddr, 32) & ~0x98;
38584 val |= 0x20;
38585- lp->a.write_bcr(ioaddr, 32, val);
38586+ lp->a->write_bcr(ioaddr, 32, val);
38587 }
38588 }
38589 } else {
38590@@ -2197,10 +2197,10 @@ static int pcnet32_open(struct net_device *dev)
38591 * There is really no good other way to handle multiple PHYs
38592 * other than turning off all automatics
38593 */
38594- val = lp->a.read_bcr(ioaddr, 2);
38595- lp->a.write_bcr(ioaddr, 2, val & ~2);
38596- val = lp->a.read_bcr(ioaddr, 32);
38597- lp->a.write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
38598+ val = lp->a->read_bcr(ioaddr, 2);
38599+ lp->a->write_bcr(ioaddr, 2, val & ~2);
38600+ val = lp->a->read_bcr(ioaddr, 32);
38601+ lp->a->write_bcr(ioaddr, 32, val & ~(1 << 7)); /* stop MII manager */
38602
38603 if (!(lp->options & PCNET32_PORT_ASEL)) {
38604 /* setup ecmd */
38605@@ -2210,7 +2210,7 @@ static int pcnet32_open(struct net_device *dev)
38606 ecmd.speed =
38607 lp->
38608 options & PCNET32_PORT_100 ? SPEED_100 : SPEED_10;
38609- bcr9 = lp->a.read_bcr(ioaddr, 9);
38610+ bcr9 = lp->a->read_bcr(ioaddr, 9);
38611
38612 if (lp->options & PCNET32_PORT_FD) {
38613 ecmd.duplex = DUPLEX_FULL;
38614@@ -2219,7 +2219,7 @@ static int pcnet32_open(struct net_device *dev)
38615 ecmd.duplex = DUPLEX_HALF;
38616 bcr9 |= ~(1 << 0);
38617 }
38618- lp->a.write_bcr(ioaddr, 9, bcr9);
38619+ lp->a->write_bcr(ioaddr, 9, bcr9);
38620 }
38621
38622 for (i = 0; i < PCNET32_MAX_PHYS; i++) {
38623@@ -2252,9 +2252,9 @@ static int pcnet32_open(struct net_device *dev)
38624
38625 #ifdef DO_DXSUFLO
38626 if (lp->dxsuflo) { /* Disable transmit stop on underflow */
38627- val = lp->a.read_csr(ioaddr, CSR3);
38628+ val = lp->a->read_csr(ioaddr, CSR3);
38629 val |= 0x40;
38630- lp->a.write_csr(ioaddr, CSR3, val);
38631+ lp->a->write_csr(ioaddr, CSR3, val);
38632 }
38633 #endif
38634
38635@@ -2270,11 +2270,11 @@ static int pcnet32_open(struct net_device *dev)
38636 napi_enable(&lp->napi);
38637
38638 /* Re-initialize the PCNET32, and start it when done. */
38639- lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
38640- lp->a.write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
38641+ lp->a->write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
38642+ lp->a->write_csr(ioaddr, 2, (lp->init_dma_addr >> 16));
38643
38644- lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38645- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
38646+ lp->a->write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
38647+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
38648
38649 netif_start_queue(dev);
38650
38651@@ -2286,20 +2286,20 @@ static int pcnet32_open(struct net_device *dev)
38652
38653 i = 0;
38654 while (i++ < 100)
38655- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
38656+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
38657 break;
38658 /*
38659 * We used to clear the InitDone bit, 0x0100, here but Mark Stockton
38660 * reports that doing so triggers a bug in the '974.
38661 */
38662- lp->a.write_csr(ioaddr, CSR0, CSR0_NORMAL);
38663+ lp->a->write_csr(ioaddr, CSR0, CSR0_NORMAL);
38664
38665 if (netif_msg_ifup(lp))
38666 printk(KERN_DEBUG
38667 "%s: pcnet32 open after %d ticks, init block %#x csr0 %4.4x.\n",
38668 dev->name, i,
38669 (u32) (lp->init_dma_addr),
38670- lp->a.read_csr(ioaddr, CSR0));
38671+ lp->a->read_csr(ioaddr, CSR0));
38672
38673 spin_unlock_irqrestore(&lp->lock, flags);
38674
38675@@ -2313,7 +2313,7 @@ static int pcnet32_open(struct net_device *dev)
38676 * Switch back to 16bit mode to avoid problems with dumb
38677 * DOS packet driver after a warm reboot
38678 */
38679- lp->a.write_bcr(ioaddr, 20, 4);
38680+ lp->a->write_bcr(ioaddr, 20, 4);
38681
38682 err_free_irq:
38683 spin_unlock_irqrestore(&lp->lock, flags);
38684@@ -2420,7 +2420,7 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
38685
38686 /* wait for stop */
38687 for (i = 0; i < 100; i++)
38688- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_STOP)
38689+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_STOP)
38690 break;
38691
38692 if (i >= 100 && netif_msg_drv(lp))
38693@@ -2433,13 +2433,13 @@ static void pcnet32_restart(struct net_device *dev, unsigned int csr0_bits)
38694 return;
38695
38696 /* ReInit Ring */
38697- lp->a.write_csr(ioaddr, CSR0, CSR0_INIT);
38698+ lp->a->write_csr(ioaddr, CSR0, CSR0_INIT);
38699 i = 0;
38700 while (i++ < 1000)
38701- if (lp->a.read_csr(ioaddr, CSR0) & CSR0_IDON)
38702+ if (lp->a->read_csr(ioaddr, CSR0) & CSR0_IDON)
38703 break;
38704
38705- lp->a.write_csr(ioaddr, CSR0, csr0_bits);
38706+ lp->a->write_csr(ioaddr, CSR0, csr0_bits);
38707 }
38708
38709 static void pcnet32_tx_timeout(struct net_device *dev)
38710@@ -2452,8 +2452,8 @@ static void pcnet32_tx_timeout(struct net_device *dev)
38711 if (pcnet32_debug & NETIF_MSG_DRV)
38712 printk(KERN_ERR
38713 "%s: transmit timed out, status %4.4x, resetting.\n",
38714- dev->name, lp->a.read_csr(ioaddr, CSR0));
38715- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38716+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38717+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38718 dev->stats.tx_errors++;
38719 if (netif_msg_tx_err(lp)) {
38720 int i;
38721@@ -2497,7 +2497,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
38722 if (netif_msg_tx_queued(lp)) {
38723 printk(KERN_DEBUG
38724 "%s: pcnet32_start_xmit() called, csr0 %4.4x.\n",
38725- dev->name, lp->a.read_csr(ioaddr, CSR0));
38726+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38727 }
38728
38729 /* Default status -- will not enable Successful-TxDone
38730@@ -2528,7 +2528,7 @@ static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
38731 dev->stats.tx_bytes += skb->len;
38732
38733 /* Trigger an immediate send poll. */
38734- lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
38735+ lp->a->write_csr(ioaddr, CSR0, CSR0_INTEN | CSR0_TXPOLL);
38736
38737 dev->trans_start = jiffies;
38738
38739@@ -2555,18 +2555,18 @@ pcnet32_interrupt(int irq, void *dev_id)
38740
38741 spin_lock(&lp->lock);
38742
38743- csr0 = lp->a.read_csr(ioaddr, CSR0);
38744+ csr0 = lp->a->read_csr(ioaddr, CSR0);
38745 while ((csr0 & 0x8f00) && --boguscnt >= 0) {
38746 if (csr0 == 0xffff) {
38747 break; /* PCMCIA remove happened */
38748 }
38749 /* Acknowledge all of the current interrupt sources ASAP. */
38750- lp->a.write_csr(ioaddr, CSR0, csr0 & ~0x004f);
38751+ lp->a->write_csr(ioaddr, CSR0, csr0 & ~0x004f);
38752
38753 if (netif_msg_intr(lp))
38754 printk(KERN_DEBUG
38755 "%s: interrupt csr0=%#2.2x new csr=%#2.2x.\n",
38756- dev->name, csr0, lp->a.read_csr(ioaddr, CSR0));
38757+ dev->name, csr0, lp->a->read_csr(ioaddr, CSR0));
38758
38759 /* Log misc errors. */
38760 if (csr0 & 0x4000)
38761@@ -2595,19 +2595,19 @@ pcnet32_interrupt(int irq, void *dev_id)
38762 if (napi_schedule_prep(&lp->napi)) {
38763 u16 val;
38764 /* set interrupt masks */
38765- val = lp->a.read_csr(ioaddr, CSR3);
38766+ val = lp->a->read_csr(ioaddr, CSR3);
38767 val |= 0x5f00;
38768- lp->a.write_csr(ioaddr, CSR3, val);
38769+ lp->a->write_csr(ioaddr, CSR3, val);
38770
38771 __napi_schedule(&lp->napi);
38772 break;
38773 }
38774- csr0 = lp->a.read_csr(ioaddr, CSR0);
38775+ csr0 = lp->a->read_csr(ioaddr, CSR0);
38776 }
38777
38778 if (netif_msg_intr(lp))
38779 printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
38780- dev->name, lp->a.read_csr(ioaddr, CSR0));
38781+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38782
38783 spin_unlock(&lp->lock);
38784
38785@@ -2627,21 +2627,21 @@ static int pcnet32_close(struct net_device *dev)
38786
38787 spin_lock_irqsave(&lp->lock, flags);
38788
38789- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
38790+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
38791
38792 if (netif_msg_ifdown(lp))
38793 printk(KERN_DEBUG
38794 "%s: Shutting down ethercard, status was %2.2x.\n",
38795- dev->name, lp->a.read_csr(ioaddr, CSR0));
38796+ dev->name, lp->a->read_csr(ioaddr, CSR0));
38797
38798 /* We stop the PCNET32 here -- it occasionally polls memory if we don't. */
38799- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38800+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38801
38802 /*
38803 * Switch back to 16bit mode to avoid problems with dumb
38804 * DOS packet driver after a warm reboot
38805 */
38806- lp->a.write_bcr(ioaddr, 20, 4);
38807+ lp->a->write_bcr(ioaddr, 20, 4);
38808
38809 spin_unlock_irqrestore(&lp->lock, flags);
38810
38811@@ -2664,7 +2664,7 @@ static struct net_device_stats *pcnet32_get_stats(struct net_device *dev)
38812 unsigned long flags;
38813
38814 spin_lock_irqsave(&lp->lock, flags);
38815- dev->stats.rx_missed_errors = lp->a.read_csr(ioaddr, 112);
38816+ dev->stats.rx_missed_errors = lp->a->read_csr(ioaddr, 112);
38817 spin_unlock_irqrestore(&lp->lock, flags);
38818
38819 return &dev->stats;
38820@@ -2686,10 +2686,10 @@ static void pcnet32_load_multicast(struct net_device *dev)
38821 if (dev->flags & IFF_ALLMULTI) {
38822 ib->filter[0] = cpu_to_le32(~0U);
38823 ib->filter[1] = cpu_to_le32(~0U);
38824- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
38825- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
38826- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
38827- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
38828+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER, 0xffff);
38829+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+1, 0xffff);
38830+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+2, 0xffff);
38831+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER+3, 0xffff);
38832 return;
38833 }
38834 /* clear the multicast filter */
38835@@ -2710,7 +2710,7 @@ static void pcnet32_load_multicast(struct net_device *dev)
38836 mcast_table[crc >> 4] |= cpu_to_le16(1 << (crc & 0xf));
38837 }
38838 for (i = 0; i < 4; i++)
38839- lp->a.write_csr(ioaddr, PCNET32_MC_FILTER + i,
38840+ lp->a->write_csr(ioaddr, PCNET32_MC_FILTER + i,
38841 le16_to_cpu(mcast_table[i]));
38842 return;
38843 }
38844@@ -2726,7 +2726,7 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
38845
38846 spin_lock_irqsave(&lp->lock, flags);
38847 suspended = pcnet32_suspend(dev, &flags, 0);
38848- csr15 = lp->a.read_csr(ioaddr, CSR15);
38849+ csr15 = lp->a->read_csr(ioaddr, CSR15);
38850 if (dev->flags & IFF_PROMISC) {
38851 /* Log any net taps. */
38852 if (netif_msg_hw(lp))
38853@@ -2735,21 +2735,21 @@ static void pcnet32_set_multicast_list(struct net_device *dev)
38854 lp->init_block->mode =
38855 cpu_to_le16(0x8000 | (lp->options & PCNET32_PORT_PORTSEL) <<
38856 7);
38857- lp->a.write_csr(ioaddr, CSR15, csr15 | 0x8000);
38858+ lp->a->write_csr(ioaddr, CSR15, csr15 | 0x8000);
38859 } else {
38860 lp->init_block->mode =
38861 cpu_to_le16((lp->options & PCNET32_PORT_PORTSEL) << 7);
38862- lp->a.write_csr(ioaddr, CSR15, csr15 & 0x7fff);
38863+ lp->a->write_csr(ioaddr, CSR15, csr15 & 0x7fff);
38864 pcnet32_load_multicast(dev);
38865 }
38866
38867 if (suspended) {
38868 int csr5;
38869 /* clear SUSPEND (SPND) - CSR5 bit 0 */
38870- csr5 = lp->a.read_csr(ioaddr, CSR5);
38871- lp->a.write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
38872+ csr5 = lp->a->read_csr(ioaddr, CSR5);
38873+ lp->a->write_csr(ioaddr, CSR5, csr5 & (~CSR5_SUSPEND));
38874 } else {
38875- lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);
38876+ lp->a->write_csr(ioaddr, CSR0, CSR0_STOP);
38877 pcnet32_restart(dev, CSR0_NORMAL);
38878 netif_wake_queue(dev);
38879 }
38880@@ -2767,8 +2767,8 @@ static int mdio_read(struct net_device *dev, int phy_id, int reg_num)
38881 if (!lp->mii)
38882 return 0;
38883
38884- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38885- val_out = lp->a.read_bcr(ioaddr, 34);
38886+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38887+ val_out = lp->a->read_bcr(ioaddr, 34);
38888
38889 return val_out;
38890 }
38891@@ -2782,8 +2782,8 @@ static void mdio_write(struct net_device *dev, int phy_id, int reg_num, int val)
38892 if (!lp->mii)
38893 return;
38894
38895- lp->a.write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38896- lp->a.write_bcr(ioaddr, 34, val);
38897+ lp->a->write_bcr(ioaddr, 33, ((phy_id & 0x1f) << 5) | (reg_num & 0x1f));
38898+ lp->a->write_bcr(ioaddr, 34, val);
38899 }
38900
38901 static int pcnet32_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38902@@ -2862,7 +2862,7 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
38903 curr_link = mii_link_ok(&lp->mii_if);
38904 } else {
38905 ulong ioaddr = dev->base_addr; /* card base I/O address */
38906- curr_link = (lp->a.read_bcr(ioaddr, 4) != 0xc0);
38907+ curr_link = (lp->a->read_bcr(ioaddr, 4) != 0xc0);
38908 }
38909 if (!curr_link) {
38910 if (prev_link || verbose) {
38911@@ -2887,13 +2887,13 @@ static void pcnet32_check_media(struct net_device *dev, int verbose)
38912 (ecmd.duplex ==
38913 DUPLEX_FULL) ? "full" : "half");
38914 }
38915- bcr9 = lp->a.read_bcr(dev->base_addr, 9);
38916+ bcr9 = lp->a->read_bcr(dev->base_addr, 9);
38917 if ((bcr9 & (1 << 0)) != lp->mii_if.full_duplex) {
38918 if (lp->mii_if.full_duplex)
38919 bcr9 |= (1 << 0);
38920 else
38921 bcr9 &= ~(1 << 0);
38922- lp->a.write_bcr(dev->base_addr, 9, bcr9);
38923+ lp->a->write_bcr(dev->base_addr, 9, bcr9);
38924 }
38925 } else {
38926 if (netif_msg_link(lp))
38927diff --git a/drivers/net/sis190.c b/drivers/net/sis190.c
38928index 7cc9898..6eb50d3 100644
38929--- a/drivers/net/sis190.c
38930+++ b/drivers/net/sis190.c
38931@@ -1598,7 +1598,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
38932 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
38933 struct net_device *dev)
38934 {
38935- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
38936+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
38937 struct sis190_private *tp = netdev_priv(dev);
38938 struct pci_dev *isa_bridge;
38939 u8 reg, tmp8;
38940diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
38941index e13685a..60c948c 100644
38942--- a/drivers/net/sundance.c
38943+++ b/drivers/net/sundance.c
38944@@ -225,7 +225,7 @@ enum {
38945 struct pci_id_info {
38946 const char *name;
38947 };
38948-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
38949+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
38950 {"D-Link DFE-550TX FAST Ethernet Adapter"},
38951 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
38952 {"D-Link DFE-580TX 4 port Server Adapter"},
38953diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
38954index 529f55a..cccaa18 100644
38955--- a/drivers/net/tg3.h
38956+++ b/drivers/net/tg3.h
38957@@ -95,6 +95,7 @@
38958 #define CHIPREV_ID_5750_A0 0x4000
38959 #define CHIPREV_ID_5750_A1 0x4001
38960 #define CHIPREV_ID_5750_A3 0x4003
38961+#define CHIPREV_ID_5750_C1 0x4201
38962 #define CHIPREV_ID_5750_C2 0x4202
38963 #define CHIPREV_ID_5752_A0_HW 0x5000
38964 #define CHIPREV_ID_5752_A0 0x6000
38965diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
38966index b9db1b5..720f9ce 100644
38967--- a/drivers/net/tokenring/abyss.c
38968+++ b/drivers/net/tokenring/abyss.c
38969@@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
38970
38971 static int __init abyss_init (void)
38972 {
38973- abyss_netdev_ops = tms380tr_netdev_ops;
38974+ pax_open_kernel();
38975+ memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38976
38977- abyss_netdev_ops.ndo_open = abyss_open;
38978- abyss_netdev_ops.ndo_stop = abyss_close;
38979+ *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
38980+ *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
38981+ pax_close_kernel();
38982
38983 return pci_register_driver(&abyss_driver);
38984 }
38985diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
38986index 456f8bf..373e56d 100644
38987--- a/drivers/net/tokenring/madgemc.c
38988+++ b/drivers/net/tokenring/madgemc.c
38989@@ -755,9 +755,11 @@ static struct mca_driver madgemc_driver = {
38990
38991 static int __init madgemc_init (void)
38992 {
38993- madgemc_netdev_ops = tms380tr_netdev_ops;
38994- madgemc_netdev_ops.ndo_open = madgemc_open;
38995- madgemc_netdev_ops.ndo_stop = madgemc_close;
38996+ pax_open_kernel();
38997+ memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
38998+ *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
38999+ *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
39000+ pax_close_kernel();
39001
39002 return mca_register_driver (&madgemc_driver);
39003 }
39004diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
39005index 16e8783..925bd49 100644
39006--- a/drivers/net/tokenring/proteon.c
39007+++ b/drivers/net/tokenring/proteon.c
39008@@ -353,9 +353,11 @@ static int __init proteon_init(void)
39009 struct platform_device *pdev;
39010 int i, num = 0, err = 0;
39011
39012- proteon_netdev_ops = tms380tr_netdev_ops;
39013- proteon_netdev_ops.ndo_open = proteon_open;
39014- proteon_netdev_ops.ndo_stop = tms380tr_close;
39015+ pax_open_kernel();
39016+ memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
39017+ *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
39018+ *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
39019+ pax_close_kernel();
39020
39021 err = platform_driver_register(&proteon_driver);
39022 if (err)
39023diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
39024index 46db5c5..37c1536 100644
39025--- a/drivers/net/tokenring/skisa.c
39026+++ b/drivers/net/tokenring/skisa.c
39027@@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
39028 struct platform_device *pdev;
39029 int i, num = 0, err = 0;
39030
39031- sk_isa_netdev_ops = tms380tr_netdev_ops;
39032- sk_isa_netdev_ops.ndo_open = sk_isa_open;
39033- sk_isa_netdev_ops.ndo_stop = tms380tr_close;
39034+ pax_open_kernel();
39035+ memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
39036+ *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
39037+ *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
39038+ pax_close_kernel();
39039
39040 err = platform_driver_register(&sk_isa_driver);
39041 if (err)
39042diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
39043index 74e5ba4..5cf6bc9 100644
39044--- a/drivers/net/tulip/de2104x.c
39045+++ b/drivers/net/tulip/de2104x.c
39046@@ -1785,6 +1785,8 @@ static void __devinit de21041_get_srom_info (struct de_private *de)
39047 struct de_srom_info_leaf *il;
39048 void *bufp;
39049
39050+ pax_track_stack();
39051+
39052 /* download entire eeprom */
39053 for (i = 0; i < DE_EEPROM_WORDS; i++)
39054 ((__le16 *)ee_data)[i] =
39055diff --git a/drivers/net/tulip/de4x5.c b/drivers/net/tulip/de4x5.c
39056index a8349b7..90f9dfe 100644
39057--- a/drivers/net/tulip/de4x5.c
39058+++ b/drivers/net/tulip/de4x5.c
39059@@ -5472,7 +5472,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39060 for (i=0; i<ETH_ALEN; i++) {
39061 tmp.addr[i] = dev->dev_addr[i];
39062 }
39063- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39064+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39065 break;
39066
39067 case DE4X5_SET_HWADDR: /* Set the hardware address */
39068@@ -5512,7 +5512,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39069 spin_lock_irqsave(&lp->lock, flags);
39070 memcpy(&statbuf, &lp->pktStats, ioc->len);
39071 spin_unlock_irqrestore(&lp->lock, flags);
39072- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39073+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39074 return -EFAULT;
39075 break;
39076 }
39077diff --git a/drivers/net/tulip/eeprom.c b/drivers/net/tulip/eeprom.c
39078index 391acd3..56d11cd 100644
39079--- a/drivers/net/tulip/eeprom.c
39080+++ b/drivers/net/tulip/eeprom.c
39081@@ -80,7 +80,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
39082 {NULL}};
39083
39084
39085-static const char *block_name[] __devinitdata = {
39086+static const char *block_name[] __devinitconst = {
39087 "21140 non-MII",
39088 "21140 MII PHY",
39089 "21142 Serial PHY",
39090diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
39091index b38d3b7..b1cff23 100644
39092--- a/drivers/net/tulip/winbond-840.c
39093+++ b/drivers/net/tulip/winbond-840.c
39094@@ -235,7 +235,7 @@ struct pci_id_info {
39095 int drv_flags; /* Driver use, intended as capability flags. */
39096 };
39097
39098-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
39099+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
39100 { /* Sometime a Level-One switch card. */
39101 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
39102 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
39103diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39104index f450bc9..2b747c8 100644
39105--- a/drivers/net/usb/hso.c
39106+++ b/drivers/net/usb/hso.c
39107@@ -71,7 +71,7 @@
39108 #include <asm/byteorder.h>
39109 #include <linux/serial_core.h>
39110 #include <linux/serial.h>
39111-
39112+#include <asm/local.h>
39113
39114 #define DRIVER_VERSION "1.2"
39115 #define MOD_AUTHOR "Option Wireless"
39116@@ -258,7 +258,7 @@ struct hso_serial {
39117
39118 /* from usb_serial_port */
39119 struct tty_struct *tty;
39120- int open_count;
39121+ local_t open_count;
39122 spinlock_t serial_lock;
39123
39124 int (*write_data) (struct hso_serial *serial);
39125@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39126 struct urb *urb;
39127
39128 urb = serial->rx_urb[0];
39129- if (serial->open_count > 0) {
39130+ if (local_read(&serial->open_count) > 0) {
39131 count = put_rxbuf_data(urb, serial);
39132 if (count == -1)
39133 return;
39134@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39135 DUMP1(urb->transfer_buffer, urb->actual_length);
39136
39137 /* Anyone listening? */
39138- if (serial->open_count == 0)
39139+ if (local_read(&serial->open_count) == 0)
39140 return;
39141
39142 if (status == 0) {
39143@@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39144 spin_unlock_irq(&serial->serial_lock);
39145
39146 /* check for port already opened, if not set the termios */
39147- serial->open_count++;
39148- if (serial->open_count == 1) {
39149+ if (local_inc_return(&serial->open_count) == 1) {
39150 tty->low_latency = 1;
39151 serial->rx_state = RX_IDLE;
39152 /* Force default termio settings */
39153@@ -1325,7 +1324,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39154 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39155 if (result) {
39156 hso_stop_serial_device(serial->parent);
39157- serial->open_count--;
39158+ local_dec(&serial->open_count);
39159 kref_put(&serial->parent->ref, hso_serial_ref_free);
39160 }
39161 } else {
39162@@ -1362,10 +1361,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39163
39164 /* reset the rts and dtr */
39165 /* do the actual close */
39166- serial->open_count--;
39167+ local_dec(&serial->open_count);
39168
39169- if (serial->open_count <= 0) {
39170- serial->open_count = 0;
39171+ if (local_read(&serial->open_count) <= 0) {
39172+ local_set(&serial->open_count, 0);
39173 spin_lock_irq(&serial->serial_lock);
39174 if (serial->tty == tty) {
39175 serial->tty->driver_data = NULL;
39176@@ -1447,7 +1446,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39177
39178 /* the actual setup */
39179 spin_lock_irqsave(&serial->serial_lock, flags);
39180- if (serial->open_count)
39181+ if (local_read(&serial->open_count))
39182 _hso_serial_set_termios(tty, old);
39183 else
39184 tty->termios = old;
39185@@ -3097,7 +3096,7 @@ static int hso_resume(struct usb_interface *iface)
39186 /* Start all serial ports */
39187 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39188 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39189- if (dev2ser(serial_table[i])->open_count) {
39190+ if (local_read(&dev2ser(serial_table[i])->open_count)) {
39191 result =
39192 hso_start_serial_device(serial_table[i], GFP_NOIO);
39193 hso_kick_transmit(dev2ser(serial_table[i]));
39194diff --git a/drivers/net/vxge/vxge-config.h b/drivers/net/vxge/vxge-config.h
39195index 3e94f0c..ffdd926 100644
39196--- a/drivers/net/vxge/vxge-config.h
39197+++ b/drivers/net/vxge/vxge-config.h
39198@@ -474,7 +474,7 @@ struct vxge_hw_uld_cbs {
39199 void (*link_down)(struct __vxge_hw_device *devh);
39200 void (*crit_err)(struct __vxge_hw_device *devh,
39201 enum vxge_hw_event type, u64 ext_data);
39202-};
39203+} __no_const;
39204
39205 /*
39206 * struct __vxge_hw_blockpool_entry - Block private data structure
39207diff --git a/drivers/net/vxge/vxge-main.c b/drivers/net/vxge/vxge-main.c
39208index 068d7a9..35293de 100644
39209--- a/drivers/net/vxge/vxge-main.c
39210+++ b/drivers/net/vxge/vxge-main.c
39211@@ -93,6 +93,8 @@ static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
39212 struct sk_buff *completed[NR_SKB_COMPLETED];
39213 int more;
39214
39215+ pax_track_stack();
39216+
39217 do {
39218 more = 0;
39219 skb_ptr = completed;
39220@@ -1779,6 +1781,8 @@ static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
39221 u8 mtable[256] = {0}; /* CPU to vpath mapping */
39222 int index;
39223
39224+ pax_track_stack();
39225+
39226 /*
39227 * Filling
39228 * - itable with bucket numbers
39229diff --git a/drivers/net/vxge/vxge-traffic.h b/drivers/net/vxge/vxge-traffic.h
39230index 461742b..81be42e 100644
39231--- a/drivers/net/vxge/vxge-traffic.h
39232+++ b/drivers/net/vxge/vxge-traffic.h
39233@@ -2123,7 +2123,7 @@ struct vxge_hw_mempool_cbs {
39234 struct vxge_hw_mempool_dma *dma_object,
39235 u32 index,
39236 u32 is_last);
39237-};
39238+} __no_const;
39239
39240 void
39241 __vxge_hw_mempool_destroy(
39242diff --git a/drivers/net/wan/cycx_x25.c b/drivers/net/wan/cycx_x25.c
39243index cd8cb95..4153b79 100644
39244--- a/drivers/net/wan/cycx_x25.c
39245+++ b/drivers/net/wan/cycx_x25.c
39246@@ -1017,6 +1017,8 @@ static void hex_dump(char *msg, unsigned char *p, int len)
39247 unsigned char hex[1024],
39248 * phex = hex;
39249
39250+ pax_track_stack();
39251+
39252 if (len >= (sizeof(hex) / 2))
39253 len = (sizeof(hex) / 2) - 1;
39254
39255diff --git a/drivers/net/wan/hdlc_x25.c b/drivers/net/wan/hdlc_x25.c
39256index aa9248f..a4e3c3b 100644
39257--- a/drivers/net/wan/hdlc_x25.c
39258+++ b/drivers/net/wan/hdlc_x25.c
39259@@ -136,16 +136,16 @@ static netdev_tx_t x25_xmit(struct sk_buff *skb, struct net_device *dev)
39260
39261 static int x25_open(struct net_device *dev)
39262 {
39263- struct lapb_register_struct cb;
39264+ static struct lapb_register_struct cb = {
39265+ .connect_confirmation = x25_connected,
39266+ .connect_indication = x25_connected,
39267+ .disconnect_confirmation = x25_disconnected,
39268+ .disconnect_indication = x25_disconnected,
39269+ .data_indication = x25_data_indication,
39270+ .data_transmit = x25_data_transmit
39271+ };
39272 int result;
39273
39274- cb.connect_confirmation = x25_connected;
39275- cb.connect_indication = x25_connected;
39276- cb.disconnect_confirmation = x25_disconnected;
39277- cb.disconnect_indication = x25_disconnected;
39278- cb.data_indication = x25_data_indication;
39279- cb.data_transmit = x25_data_transmit;
39280-
39281 result = lapb_register(dev, &cb);
39282 if (result != LAPB_OK)
39283 return result;
39284diff --git a/drivers/net/wimax/i2400m/usb-fw.c b/drivers/net/wimax/i2400m/usb-fw.c
39285index 5ad287c..783b020 100644
39286--- a/drivers/net/wimax/i2400m/usb-fw.c
39287+++ b/drivers/net/wimax/i2400m/usb-fw.c
39288@@ -263,6 +263,8 @@ ssize_t i2400mu_bus_bm_wait_for_ack(struct i2400m *i2400m,
39289 int do_autopm = 1;
39290 DECLARE_COMPLETION_ONSTACK(notif_completion);
39291
39292+ pax_track_stack();
39293+
39294 d_fnstart(8, dev, "(i2400m %p ack %p size %zu)\n",
39295 i2400m, ack, ack_size);
39296 BUG_ON(_ack == i2400m->bm_ack_buf);
39297diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
39298index 6c26840..62c97c3 100644
39299--- a/drivers/net/wireless/airo.c
39300+++ b/drivers/net/wireless/airo.c
39301@@ -3003,6 +3003,8 @@ static void airo_process_scan_results (struct airo_info *ai) {
39302 BSSListElement * loop_net;
39303 BSSListElement * tmp_net;
39304
39305+ pax_track_stack();
39306+
39307 /* Blow away current list of scan results */
39308 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
39309 list_move_tail (&loop_net->list, &ai->network_free_list);
39310@@ -3783,6 +3785,8 @@ static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
39311 WepKeyRid wkr;
39312 int rc;
39313
39314+ pax_track_stack();
39315+
39316 memset( &mySsid, 0, sizeof( mySsid ) );
39317 kfree (ai->flash);
39318 ai->flash = NULL;
39319@@ -4758,6 +4762,8 @@ static int proc_stats_rid_open( struct inode *inode,
39320 __le32 *vals = stats.vals;
39321 int len;
39322
39323+ pax_track_stack();
39324+
39325 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
39326 return -ENOMEM;
39327 data = (struct proc_data *)file->private_data;
39328@@ -5487,6 +5493,8 @@ static int proc_BSSList_open( struct inode *inode, struct file *file ) {
39329 /* If doLoseSync is not 1, we won't do a Lose Sync */
39330 int doLoseSync = -1;
39331
39332+ pax_track_stack();
39333+
39334 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
39335 return -ENOMEM;
39336 data = (struct proc_data *)file->private_data;
39337@@ -7193,6 +7201,8 @@ static int airo_get_aplist(struct net_device *dev,
39338 int i;
39339 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
39340
39341+ pax_track_stack();
39342+
39343 qual = kmalloc(IW_MAX_AP * sizeof(*qual), GFP_KERNEL);
39344 if (!qual)
39345 return -ENOMEM;
39346@@ -7753,6 +7763,8 @@ static void airo_read_wireless_stats(struct airo_info *local)
39347 CapabilityRid cap_rid;
39348 __le32 *vals = stats_rid.vals;
39349
39350+ pax_track_stack();
39351+
39352 /* Get stats out of the card */
39353 clear_bit(JOB_WSTATS, &local->jobs);
39354 if (local->power.event) {
39355diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
39356index 747508c..82e965d 100644
39357--- a/drivers/net/wireless/ath/ath5k/debug.c
39358+++ b/drivers/net/wireless/ath/ath5k/debug.c
39359@@ -205,6 +205,8 @@ static ssize_t read_file_beacon(struct file *file, char __user *user_buf,
39360 unsigned int v;
39361 u64 tsf;
39362
39363+ pax_track_stack();
39364+
39365 v = ath5k_hw_reg_read(sc->ah, AR5K_BEACON);
39366 len += snprintf(buf+len, sizeof(buf)-len,
39367 "%-24s0x%08x\tintval: %d\tTIM: 0x%x\n",
39368@@ -318,6 +320,8 @@ static ssize_t read_file_debug(struct file *file, char __user *user_buf,
39369 unsigned int len = 0;
39370 unsigned int i;
39371
39372+ pax_track_stack();
39373+
39374 len += snprintf(buf+len, sizeof(buf)-len,
39375 "DEBUG LEVEL: 0x%08x\n\n", sc->debug.level);
39376
39377diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
39378index 2be4c22..593b1eb 100644
39379--- a/drivers/net/wireless/ath/ath9k/debug.c
39380+++ b/drivers/net/wireless/ath/ath9k/debug.c
39381@@ -220,6 +220,8 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
39382 char buf[512];
39383 unsigned int len = 0;
39384
39385+ pax_track_stack();
39386+
39387 len += snprintf(buf + len, sizeof(buf) - len,
39388 "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
39389 len += snprintf(buf + len, sizeof(buf) - len,
39390@@ -360,6 +362,8 @@ static ssize_t read_file_wiphy(struct file *file, char __user *user_buf,
39391 int i;
39392 u8 addr[ETH_ALEN];
39393
39394+ pax_track_stack();
39395+
39396 len += snprintf(buf + len, sizeof(buf) - len,
39397 "primary: %s (%s chan=%d ht=%d)\n",
39398 wiphy_name(sc->pri_wiphy->hw->wiphy),
39399diff --git a/drivers/net/wireless/b43/debugfs.c b/drivers/net/wireless/b43/debugfs.c
39400index 80b19a4..dab3a45 100644
39401--- a/drivers/net/wireless/b43/debugfs.c
39402+++ b/drivers/net/wireless/b43/debugfs.c
39403@@ -43,7 +43,7 @@ static struct dentry *rootdir;
39404 struct b43_debugfs_fops {
39405 ssize_t (*read)(struct b43_wldev *dev, char *buf, size_t bufsize);
39406 int (*write)(struct b43_wldev *dev, const char *buf, size_t count);
39407- struct file_operations fops;
39408+ const struct file_operations fops;
39409 /* Offset of struct b43_dfs_file in struct b43_dfsentry */
39410 size_t file_struct_offset;
39411 };
39412diff --git a/drivers/net/wireless/b43legacy/debugfs.c b/drivers/net/wireless/b43legacy/debugfs.c
39413index 1f85ac5..c99b4b4 100644
39414--- a/drivers/net/wireless/b43legacy/debugfs.c
39415+++ b/drivers/net/wireless/b43legacy/debugfs.c
39416@@ -44,7 +44,7 @@ static struct dentry *rootdir;
39417 struct b43legacy_debugfs_fops {
39418 ssize_t (*read)(struct b43legacy_wldev *dev, char *buf, size_t bufsize);
39419 int (*write)(struct b43legacy_wldev *dev, const char *buf, size_t count);
39420- struct file_operations fops;
39421+ const struct file_operations fops;
39422 /* Offset of struct b43legacy_dfs_file in struct b43legacy_dfsentry */
39423 size_t file_struct_offset;
39424 /* Take wl->irq_lock before calling read/write? */
39425diff --git a/drivers/net/wireless/ipw2x00/ipw2100.c b/drivers/net/wireless/ipw2x00/ipw2100.c
39426index 43102bf..3b569c3 100644
39427--- a/drivers/net/wireless/ipw2x00/ipw2100.c
39428+++ b/drivers/net/wireless/ipw2x00/ipw2100.c
39429@@ -2014,6 +2014,8 @@ static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
39430 int err;
39431 DECLARE_SSID_BUF(ssid);
39432
39433+ pax_track_stack();
39434+
39435 IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
39436
39437 if (ssid_len)
39438@@ -5380,6 +5382,8 @@ static int ipw2100_set_key(struct ipw2100_priv *priv,
39439 struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
39440 int err;
39441
39442+ pax_track_stack();
39443+
39444 IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
39445 idx, keylen, len);
39446
39447diff --git a/drivers/net/wireless/ipw2x00/libipw_rx.c b/drivers/net/wireless/ipw2x00/libipw_rx.c
39448index 282b1f7..169f0cf 100644
39449--- a/drivers/net/wireless/ipw2x00/libipw_rx.c
39450+++ b/drivers/net/wireless/ipw2x00/libipw_rx.c
39451@@ -1566,6 +1566,8 @@ static void libipw_process_probe_response(struct libipw_device
39452 unsigned long flags;
39453 DECLARE_SSID_BUF(ssid);
39454
39455+ pax_track_stack();
39456+
39457 LIBIPW_DEBUG_SCAN("'%s' (%pM"
39458 "): %c%c%c%c %c%c%c%c-%c%c%c%c %c%c%c%c\n",
39459 print_ssid(ssid, info_element->data, info_element->len),
39460diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
39461index 950267a..80d5fd2 100644
39462--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
39463+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
39464@@ -137,7 +137,7 @@ static struct iwl_lib_ops iwl1000_lib = {
39465 },
39466 };
39467
39468-static struct iwl_ops iwl1000_ops = {
39469+static const struct iwl_ops iwl1000_ops = {
39470 .ucode = &iwl5000_ucode,
39471 .lib = &iwl1000_lib,
39472 .hcmd = &iwl5000_hcmd,
39473diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
39474index 56bfcc3..b348020 100644
39475--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
39476+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
39477@@ -2874,7 +2874,7 @@ static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = {
39478 .build_addsta_hcmd = iwl3945_build_addsta_hcmd,
39479 };
39480
39481-static struct iwl_ops iwl3945_ops = {
39482+static const struct iwl_ops iwl3945_ops = {
39483 .ucode = &iwl3945_ucode,
39484 .lib = &iwl3945_lib,
39485 .hcmd = &iwl3945_hcmd,
39486diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
39487index 585b8d4..e142963 100644
39488--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
39489+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
39490@@ -2345,7 +2345,7 @@ static struct iwl_lib_ops iwl4965_lib = {
39491 },
39492 };
39493
39494-static struct iwl_ops iwl4965_ops = {
39495+static const struct iwl_ops iwl4965_ops = {
39496 .ucode = &iwl4965_ucode,
39497 .lib = &iwl4965_lib,
39498 .hcmd = &iwl4965_hcmd,
39499diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
39500index 1f423f2..e37c192 100644
39501--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
39502+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
39503@@ -1633,14 +1633,14 @@ static struct iwl_lib_ops iwl5150_lib = {
39504 },
39505 };
39506
39507-struct iwl_ops iwl5000_ops = {
39508+const struct iwl_ops iwl5000_ops = {
39509 .ucode = &iwl5000_ucode,
39510 .lib = &iwl5000_lib,
39511 .hcmd = &iwl5000_hcmd,
39512 .utils = &iwl5000_hcmd_utils,
39513 };
39514
39515-static struct iwl_ops iwl5150_ops = {
39516+static const struct iwl_ops iwl5150_ops = {
39517 .ucode = &iwl5000_ucode,
39518 .lib = &iwl5150_lib,
39519 .hcmd = &iwl5000_hcmd,
39520diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
39521index 1473452..f07d5e1 100644
39522--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
39523+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
39524@@ -146,7 +146,7 @@ static struct iwl_hcmd_utils_ops iwl6000_hcmd_utils = {
39525 .calc_rssi = iwl5000_calc_rssi,
39526 };
39527
39528-static struct iwl_ops iwl6000_ops = {
39529+static const struct iwl_ops iwl6000_ops = {
39530 .ucode = &iwl5000_ucode,
39531 .lib = &iwl6000_lib,
39532 .hcmd = &iwl5000_hcmd,
39533diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39534index 1a3dfa2..b3e0a61 100644
39535--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39536+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
39537@@ -857,6 +857,8 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
39538 u8 active_index = 0;
39539 s32 tpt = 0;
39540
39541+ pax_track_stack();
39542+
39543 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
39544
39545 if (!ieee80211_is_data(hdr->frame_control) ||
39546@@ -2722,6 +2724,8 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
39547 u8 valid_tx_ant = 0;
39548 struct iwl_link_quality_cmd *lq_cmd = &lq_sta->lq;
39549
39550+ pax_track_stack();
39551+
39552 /* Override starting rate (index 0) if needed for debug purposes */
39553 rs_dbgfs_set_mcs(lq_sta, &new_rate, index);
39554
39555diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
39556index 0e56d78..6a3c107 100644
39557--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
39558+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
39559@@ -2911,7 +2911,9 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39560 if (iwl_debug_level & IWL_DL_INFO)
39561 dev_printk(KERN_DEBUG, &(pdev->dev),
39562 "Disabling hw_scan\n");
39563- iwl_hw_ops.hw_scan = NULL;
39564+ pax_open_kernel();
39565+ *(void **)&iwl_hw_ops.hw_scan = NULL;
39566+ pax_close_kernel();
39567 }
39568
39569 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
39570diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
39571index cbc6290..eb323d7 100644
39572--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
39573+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
39574@@ -118,8 +118,8 @@ void iwl_dbgfs_unregister(struct iwl_priv *priv);
39575 #endif
39576
39577 #else
39578-#define IWL_DEBUG(__priv, level, fmt, args...)
39579-#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...)
39580+#define IWL_DEBUG(__priv, level, fmt, args...) do {} while (0)
39581+#define IWL_DEBUG_LIMIT(__priv, level, fmt, args...) do {} while (0)
39582 static inline void iwl_print_hex_dump(struct iwl_priv *priv, int level,
39583 void *p, u32 len)
39584 {}
39585diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39586index a198bcf..8e68233 100644
39587--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39588+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
39589@@ -524,6 +524,8 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
39590 int pos = 0;
39591 const size_t bufsz = sizeof(buf);
39592
39593+ pax_track_stack();
39594+
39595 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
39596 test_bit(STATUS_HCMD_ACTIVE, &priv->status));
39597 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_SYNC_ACTIVE: %d\n",
39598@@ -658,6 +660,8 @@ static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
39599 const size_t bufsz = sizeof(buf);
39600 ssize_t ret;
39601
39602+ pax_track_stack();
39603+
39604 for (i = 0; i < AC_NUM; i++) {
39605 pos += scnprintf(buf + pos, bufsz - pos,
39606 "\tcw_min\tcw_max\taifsn\ttxop\n");
39607diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
39608index 3539ea4..b174bfa 100644
39609--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
39610+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
39611@@ -68,7 +68,7 @@ struct iwl_tx_queue;
39612
39613 /* shared structures from iwl-5000.c */
39614 extern struct iwl_mod_params iwl50_mod_params;
39615-extern struct iwl_ops iwl5000_ops;
39616+extern const struct iwl_ops iwl5000_ops;
39617 extern struct iwl_ucode_ops iwl5000_ucode;
39618 extern struct iwl_lib_ops iwl5000_lib;
39619 extern struct iwl_hcmd_ops iwl5000_hcmd;
39620diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
39621index 619590d..69235ee 100644
39622--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
39623+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
39624@@ -3927,7 +3927,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
39625 */
39626 if (iwl3945_mod_params.disable_hw_scan) {
39627 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
39628- iwl3945_hw_ops.hw_scan = NULL;
39629+ pax_open_kernel();
39630+ *(void **)&iwl3945_hw_ops.hw_scan = NULL;
39631+ pax_close_kernel();
39632 }
39633
39634
39635diff --git a/drivers/net/wireless/iwmc3200wifi/debugfs.c b/drivers/net/wireless/iwmc3200wifi/debugfs.c
39636index 1465379..fe4d78b 100644
39637--- a/drivers/net/wireless/iwmc3200wifi/debugfs.c
39638+++ b/drivers/net/wireless/iwmc3200wifi/debugfs.c
39639@@ -299,6 +299,8 @@ static ssize_t iwm_debugfs_fw_err_read(struct file *filp,
39640 int buf_len = 512;
39641 size_t len = 0;
39642
39643+ pax_track_stack();
39644+
39645 if (*ppos != 0)
39646 return 0;
39647 if (count < sizeof(buf))
39648diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
39649index 893a55c..7f66a50 100644
39650--- a/drivers/net/wireless/libertas/debugfs.c
39651+++ b/drivers/net/wireless/libertas/debugfs.c
39652@@ -708,7 +708,7 @@ out_unlock:
39653 struct lbs_debugfs_files {
39654 const char *name;
39655 int perm;
39656- struct file_operations fops;
39657+ const struct file_operations fops;
39658 };
39659
39660 static const struct lbs_debugfs_files debugfs_files[] = {
39661diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
39662index 2ecbedb..42704f0 100644
39663--- a/drivers/net/wireless/rndis_wlan.c
39664+++ b/drivers/net/wireless/rndis_wlan.c
39665@@ -1176,7 +1176,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
39666
39667 devdbg(usbdev, "set_rts_threshold %i", rts_threshold);
39668
39669- if (rts_threshold < 0 || rts_threshold > 2347)
39670+ if (rts_threshold > 2347)
39671 rts_threshold = 2347;
39672
39673 tmp = cpu_to_le32(rts_threshold);
39674diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
39675index 334ccd6..47f8944 100644
39676--- a/drivers/oprofile/buffer_sync.c
39677+++ b/drivers/oprofile/buffer_sync.c
39678@@ -342,7 +342,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
39679 if (cookie == NO_COOKIE)
39680 offset = pc;
39681 if (cookie == INVALID_COOKIE) {
39682- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39683+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39684 offset = pc;
39685 }
39686 if (cookie != last_cookie) {
39687@@ -386,14 +386,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
39688 /* add userspace sample */
39689
39690 if (!mm) {
39691- atomic_inc(&oprofile_stats.sample_lost_no_mm);
39692+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
39693 return 0;
39694 }
39695
39696 cookie = lookup_dcookie(mm, s->eip, &offset);
39697
39698 if (cookie == INVALID_COOKIE) {
39699- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39700+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39701 return 0;
39702 }
39703
39704@@ -562,7 +562,7 @@ void sync_buffer(int cpu)
39705 /* ignore backtraces if failed to add a sample */
39706 if (state == sb_bt_start) {
39707 state = sb_bt_ignore;
39708- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
39709+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
39710 }
39711 }
39712 release_mm(mm);
39713diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
39714index 5df60a6..72f5c1c 100644
39715--- a/drivers/oprofile/event_buffer.c
39716+++ b/drivers/oprofile/event_buffer.c
39717@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
39718 }
39719
39720 if (buffer_pos == buffer_size) {
39721- atomic_inc(&oprofile_stats.event_lost_overflow);
39722+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
39723 return;
39724 }
39725
39726diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
39727index dc8a042..fe5f315 100644
39728--- a/drivers/oprofile/oprof.c
39729+++ b/drivers/oprofile/oprof.c
39730@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
39731 if (oprofile_ops.switch_events())
39732 return;
39733
39734- atomic_inc(&oprofile_stats.multiplex_counter);
39735+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
39736 start_switch_worker();
39737 }
39738
39739diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
39740index 61689e8..387f7f8 100644
39741--- a/drivers/oprofile/oprofile_stats.c
39742+++ b/drivers/oprofile/oprofile_stats.c
39743@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
39744 cpu_buf->sample_invalid_eip = 0;
39745 }
39746
39747- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
39748- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
39749- atomic_set(&oprofile_stats.event_lost_overflow, 0);
39750- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
39751- atomic_set(&oprofile_stats.multiplex_counter, 0);
39752+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
39753+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
39754+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
39755+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
39756+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
39757 }
39758
39759
39760diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
39761index 0b54e46..a37c527 100644
39762--- a/drivers/oprofile/oprofile_stats.h
39763+++ b/drivers/oprofile/oprofile_stats.h
39764@@ -13,11 +13,11 @@
39765 #include <asm/atomic.h>
39766
39767 struct oprofile_stat_struct {
39768- atomic_t sample_lost_no_mm;
39769- atomic_t sample_lost_no_mapping;
39770- atomic_t bt_lost_no_mapping;
39771- atomic_t event_lost_overflow;
39772- atomic_t multiplex_counter;
39773+ atomic_unchecked_t sample_lost_no_mm;
39774+ atomic_unchecked_t sample_lost_no_mapping;
39775+ atomic_unchecked_t bt_lost_no_mapping;
39776+ atomic_unchecked_t event_lost_overflow;
39777+ atomic_unchecked_t multiplex_counter;
39778 };
39779
39780 extern struct oprofile_stat_struct oprofile_stats;
39781diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
39782index 2766a6d..80c77e2 100644
39783--- a/drivers/oprofile/oprofilefs.c
39784+++ b/drivers/oprofile/oprofilefs.c
39785@@ -187,7 +187,7 @@ static const struct file_operations atomic_ro_fops = {
39786
39787
39788 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
39789- char const *name, atomic_t *val)
39790+ char const *name, atomic_unchecked_t *val)
39791 {
39792 struct dentry *d = __oprofilefs_create_file(sb, root, name,
39793 &atomic_ro_fops, 0444);
39794diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
39795index 13a64bc..ad62835 100644
39796--- a/drivers/parisc/pdc_stable.c
39797+++ b/drivers/parisc/pdc_stable.c
39798@@ -481,7 +481,7 @@ pdcspath_attr_store(struct kobject *kobj, struct attribute *attr,
39799 return ret;
39800 }
39801
39802-static struct sysfs_ops pdcspath_attr_ops = {
39803+static const struct sysfs_ops pdcspath_attr_ops = {
39804 .show = pdcspath_attr_show,
39805 .store = pdcspath_attr_store,
39806 };
39807diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
39808index 8eefe56..40751a7 100644
39809--- a/drivers/parport/procfs.c
39810+++ b/drivers/parport/procfs.c
39811@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
39812
39813 *ppos += len;
39814
39815- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
39816+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
39817 }
39818
39819 #ifdef CONFIG_PARPORT_1284
39820@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
39821
39822 *ppos += len;
39823
39824- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
39825+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
39826 }
39827 #endif /* IEEE1284.3 support. */
39828
39829diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
39830index 73e7d8e..c80f3d2 100644
39831--- a/drivers/pci/hotplug/acpiphp_glue.c
39832+++ b/drivers/pci/hotplug/acpiphp_glue.c
39833@@ -111,7 +111,7 @@ static int post_dock_fixups(struct notifier_block *nb, unsigned long val,
39834 }
39835
39836
39837-static struct acpi_dock_ops acpiphp_dock_ops = {
39838+static const struct acpi_dock_ops acpiphp_dock_ops = {
39839 .handler = handle_hotplug_event_func,
39840 };
39841
39842diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
39843index 9fff878..ad0ad53 100644
39844--- a/drivers/pci/hotplug/cpci_hotplug.h
39845+++ b/drivers/pci/hotplug/cpci_hotplug.h
39846@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
39847 int (*hardware_test) (struct slot* slot, u32 value);
39848 u8 (*get_power) (struct slot* slot);
39849 int (*set_power) (struct slot* slot, int value);
39850-};
39851+} __no_const;
39852
39853 struct cpci_hp_controller {
39854 unsigned int irq;
39855diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
39856index 76ba8a1..20ca857 100644
39857--- a/drivers/pci/hotplug/cpqphp_nvram.c
39858+++ b/drivers/pci/hotplug/cpqphp_nvram.c
39859@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
39860
39861 void compaq_nvram_init (void __iomem *rom_start)
39862 {
39863+
39864+#ifndef CONFIG_PAX_KERNEXEC
39865 if (rom_start) {
39866 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
39867 }
39868+#endif
39869+
39870 dbg("int15 entry = %p\n", compaq_int15_entry_point);
39871
39872 /* initialize our int15 lock */
39873diff --git a/drivers/pci/hotplug/fakephp.c b/drivers/pci/hotplug/fakephp.c
39874index 6151389..0a894ef 100644
39875--- a/drivers/pci/hotplug/fakephp.c
39876+++ b/drivers/pci/hotplug/fakephp.c
39877@@ -73,7 +73,7 @@ static void legacy_release(struct kobject *kobj)
39878 }
39879
39880 static struct kobj_type legacy_ktype = {
39881- .sysfs_ops = &(struct sysfs_ops){
39882+ .sysfs_ops = &(const struct sysfs_ops){
39883 .store = legacy_store, .show = legacy_show
39884 },
39885 .release = &legacy_release,
39886diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
39887index 5b680df..fe05b7e 100644
39888--- a/drivers/pci/intel-iommu.c
39889+++ b/drivers/pci/intel-iommu.c
39890@@ -2643,7 +2643,7 @@ error:
39891 return 0;
39892 }
39893
39894-static dma_addr_t intel_map_page(struct device *dev, struct page *page,
39895+dma_addr_t intel_map_page(struct device *dev, struct page *page,
39896 unsigned long offset, size_t size,
39897 enum dma_data_direction dir,
39898 struct dma_attrs *attrs)
39899@@ -2719,7 +2719,7 @@ static void add_unmap(struct dmar_domain *dom, struct iova *iova)
39900 spin_unlock_irqrestore(&async_umap_flush_lock, flags);
39901 }
39902
39903-static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39904+void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39905 size_t size, enum dma_data_direction dir,
39906 struct dma_attrs *attrs)
39907 {
39908@@ -2768,7 +2768,7 @@ static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
39909 }
39910 }
39911
39912-static void *intel_alloc_coherent(struct device *hwdev, size_t size,
39913+void *intel_alloc_coherent(struct device *hwdev, size_t size,
39914 dma_addr_t *dma_handle, gfp_t flags)
39915 {
39916 void *vaddr;
39917@@ -2800,7 +2800,7 @@ static void *intel_alloc_coherent(struct device *hwdev, size_t size,
39918 return NULL;
39919 }
39920
39921-static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39922+void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39923 dma_addr_t dma_handle)
39924 {
39925 int order;
39926@@ -2812,7 +2812,7 @@ static void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
39927 free_pages((unsigned long)vaddr, order);
39928 }
39929
39930-static void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
39931+void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
39932 int nelems, enum dma_data_direction dir,
39933 struct dma_attrs *attrs)
39934 {
39935@@ -2872,7 +2872,7 @@ static int intel_nontranslate_map_sg(struct device *hddev,
39936 return nelems;
39937 }
39938
39939-static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
39940+int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
39941 enum dma_data_direction dir, struct dma_attrs *attrs)
39942 {
39943 int i;
39944@@ -2941,12 +2941,12 @@ static int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int ne
39945 return nelems;
39946 }
39947
39948-static int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
39949+int intel_mapping_error(struct device *dev, dma_addr_t dma_addr)
39950 {
39951 return !dma_addr;
39952 }
39953
39954-struct dma_map_ops intel_dma_ops = {
39955+const struct dma_map_ops intel_dma_ops = {
39956 .alloc_coherent = intel_alloc_coherent,
39957 .free_coherent = intel_free_coherent,
39958 .map_sg = intel_map_sg,
39959diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
39960index 5b7056c..607bc94 100644
39961--- a/drivers/pci/pcie/aspm.c
39962+++ b/drivers/pci/pcie/aspm.c
39963@@ -27,9 +27,9 @@
39964 #define MODULE_PARAM_PREFIX "pcie_aspm."
39965
39966 /* Note: those are not register definitions */
39967-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
39968-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
39969-#define ASPM_STATE_L1 (4) /* L1 state */
39970+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
39971+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
39972+#define ASPM_STATE_L1 (4U) /* L1 state */
39973 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
39974 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
39975
39976diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
39977index 8105e32..ca10419 100644
39978--- a/drivers/pci/probe.c
39979+++ b/drivers/pci/probe.c
39980@@ -62,14 +62,14 @@ static ssize_t pci_bus_show_cpuaffinity(struct device *dev,
39981 return ret;
39982 }
39983
39984-static ssize_t inline pci_bus_show_cpumaskaffinity(struct device *dev,
39985+static inline ssize_t pci_bus_show_cpumaskaffinity(struct device *dev,
39986 struct device_attribute *attr,
39987 char *buf)
39988 {
39989 return pci_bus_show_cpuaffinity(dev, 0, attr, buf);
39990 }
39991
39992-static ssize_t inline pci_bus_show_cpulistaffinity(struct device *dev,
39993+static inline ssize_t pci_bus_show_cpulistaffinity(struct device *dev,
39994 struct device_attribute *attr,
39995 char *buf)
39996 {
39997diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
39998index a03ad8c..024b0da 100644
39999--- a/drivers/pci/proc.c
40000+++ b/drivers/pci/proc.c
40001@@ -480,7 +480,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
40002 static int __init pci_proc_init(void)
40003 {
40004 struct pci_dev *dev = NULL;
40005+
40006+#ifdef CONFIG_GRKERNSEC_PROC_ADD
40007+#ifdef CONFIG_GRKERNSEC_PROC_USER
40008+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
40009+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
40010+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
40011+#endif
40012+#else
40013 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
40014+#endif
40015 proc_create("devices", 0, proc_bus_pci_dir,
40016 &proc_bus_pci_dev_operations);
40017 proc_initialized = 1;
40018diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
40019index 8c02b6c..5584d8e 100644
40020--- a/drivers/pci/slot.c
40021+++ b/drivers/pci/slot.c
40022@@ -29,7 +29,7 @@ static ssize_t pci_slot_attr_store(struct kobject *kobj,
40023 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
40024 }
40025
40026-static struct sysfs_ops pci_slot_sysfs_ops = {
40027+static const struct sysfs_ops pci_slot_sysfs_ops = {
40028 .show = pci_slot_attr_show,
40029 .store = pci_slot_attr_store,
40030 };
40031diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
40032index 30cf71d2..50938f1 100644
40033--- a/drivers/pcmcia/pcmcia_ioctl.c
40034+++ b/drivers/pcmcia/pcmcia_ioctl.c
40035@@ -819,7 +819,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
40036 return -EFAULT;
40037 }
40038 }
40039- buf = kmalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
40040+ buf = kzalloc(sizeof(ds_ioctl_arg_t), GFP_KERNEL);
40041 if (!buf)
40042 return -ENOMEM;
40043
40044diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
40045index 52183c4..b224c69 100644
40046--- a/drivers/platform/x86/acer-wmi.c
40047+++ b/drivers/platform/x86/acer-wmi.c
40048@@ -918,7 +918,7 @@ static int update_bl_status(struct backlight_device *bd)
40049 return 0;
40050 }
40051
40052-static struct backlight_ops acer_bl_ops = {
40053+static const struct backlight_ops acer_bl_ops = {
40054 .get_brightness = read_brightness,
40055 .update_status = update_bl_status,
40056 };
40057diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
40058index 767cb61..a87380b 100644
40059--- a/drivers/platform/x86/asus-laptop.c
40060+++ b/drivers/platform/x86/asus-laptop.c
40061@@ -250,7 +250,7 @@ static struct backlight_device *asus_backlight_device;
40062 */
40063 static int read_brightness(struct backlight_device *bd);
40064 static int update_bl_status(struct backlight_device *bd);
40065-static struct backlight_ops asusbl_ops = {
40066+static const struct backlight_ops asusbl_ops = {
40067 .get_brightness = read_brightness,
40068 .update_status = update_bl_status,
40069 };
40070diff --git a/drivers/platform/x86/asus_acpi.c b/drivers/platform/x86/asus_acpi.c
40071index d66c07a..a4abaac 100644
40072--- a/drivers/platform/x86/asus_acpi.c
40073+++ b/drivers/platform/x86/asus_acpi.c
40074@@ -1396,7 +1396,7 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
40075 return 0;
40076 }
40077
40078-static struct backlight_ops asus_backlight_data = {
40079+static const struct backlight_ops asus_backlight_data = {
40080 .get_brightness = read_brightness,
40081 .update_status = set_brightness_status,
40082 };
40083diff --git a/drivers/platform/x86/compal-laptop.c b/drivers/platform/x86/compal-laptop.c
40084index 11003bb..550ff1b 100644
40085--- a/drivers/platform/x86/compal-laptop.c
40086+++ b/drivers/platform/x86/compal-laptop.c
40087@@ -163,7 +163,7 @@ static int bl_update_status(struct backlight_device *b)
40088 return set_lcd_level(b->props.brightness);
40089 }
40090
40091-static struct backlight_ops compalbl_ops = {
40092+static const struct backlight_ops compalbl_ops = {
40093 .get_brightness = bl_get_brightness,
40094 .update_status = bl_update_status,
40095 };
40096diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
40097index 07a74da..9dc99fa 100644
40098--- a/drivers/platform/x86/dell-laptop.c
40099+++ b/drivers/platform/x86/dell-laptop.c
40100@@ -318,7 +318,7 @@ static int dell_get_intensity(struct backlight_device *bd)
40101 return buffer.output[1];
40102 }
40103
40104-static struct backlight_ops dell_ops = {
40105+static const struct backlight_ops dell_ops = {
40106 .get_brightness = dell_get_intensity,
40107 .update_status = dell_send_intensity,
40108 };
40109diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
40110index c533b1c..5c81f22 100644
40111--- a/drivers/platform/x86/eeepc-laptop.c
40112+++ b/drivers/platform/x86/eeepc-laptop.c
40113@@ -245,7 +245,7 @@ static struct device *eeepc_hwmon_device;
40114 */
40115 static int read_brightness(struct backlight_device *bd);
40116 static int update_bl_status(struct backlight_device *bd);
40117-static struct backlight_ops eeepcbl_ops = {
40118+static const struct backlight_ops eeepcbl_ops = {
40119 .get_brightness = read_brightness,
40120 .update_status = update_bl_status,
40121 };
40122diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
40123index bcd4ba8..a249b35 100644
40124--- a/drivers/platform/x86/fujitsu-laptop.c
40125+++ b/drivers/platform/x86/fujitsu-laptop.c
40126@@ -436,7 +436,7 @@ static int bl_update_status(struct backlight_device *b)
40127 return ret;
40128 }
40129
40130-static struct backlight_ops fujitsubl_ops = {
40131+static const struct backlight_ops fujitsubl_ops = {
40132 .get_brightness = bl_get_brightness,
40133 .update_status = bl_update_status,
40134 };
40135diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40136index 759763d..1093ba2 100644
40137--- a/drivers/platform/x86/msi-laptop.c
40138+++ b/drivers/platform/x86/msi-laptop.c
40139@@ -161,7 +161,7 @@ static int bl_update_status(struct backlight_device *b)
40140 return set_lcd_level(b->props.brightness);
40141 }
40142
40143-static struct backlight_ops msibl_ops = {
40144+static const struct backlight_ops msibl_ops = {
40145 .get_brightness = bl_get_brightness,
40146 .update_status = bl_update_status,
40147 };
40148diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
40149index fe7cf01..9012d8d 100644
40150--- a/drivers/platform/x86/panasonic-laptop.c
40151+++ b/drivers/platform/x86/panasonic-laptop.c
40152@@ -352,7 +352,7 @@ static int bl_set_status(struct backlight_device *bd)
40153 return acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, bright);
40154 }
40155
40156-static struct backlight_ops pcc_backlight_ops = {
40157+static const struct backlight_ops pcc_backlight_ops = {
40158 .get_brightness = bl_get,
40159 .update_status = bl_set_status,
40160 };
40161diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40162index a2a742c..b37e25e 100644
40163--- a/drivers/platform/x86/sony-laptop.c
40164+++ b/drivers/platform/x86/sony-laptop.c
40165@@ -850,7 +850,7 @@ static int sony_backlight_get_brightness(struct backlight_device *bd)
40166 }
40167
40168 static struct backlight_device *sony_backlight_device;
40169-static struct backlight_ops sony_backlight_ops = {
40170+static const struct backlight_ops sony_backlight_ops = {
40171 .update_status = sony_backlight_update_status,
40172 .get_brightness = sony_backlight_get_brightness,
40173 };
40174diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40175index 68271ae..5e8fb10 100644
40176--- a/drivers/platform/x86/thinkpad_acpi.c
40177+++ b/drivers/platform/x86/thinkpad_acpi.c
40178@@ -2139,7 +2139,7 @@ static int hotkey_mask_get(void)
40179 return 0;
40180 }
40181
40182-void static hotkey_mask_warn_incomplete_mask(void)
40183+static void hotkey_mask_warn_incomplete_mask(void)
40184 {
40185 /* log only what the user can fix... */
40186 const u32 wantedmask = hotkey_driver_mask &
40187@@ -6125,7 +6125,7 @@ static void tpacpi_brightness_notify_change(void)
40188 BACKLIGHT_UPDATE_HOTKEY);
40189 }
40190
40191-static struct backlight_ops ibm_backlight_data = {
40192+static const struct backlight_ops ibm_backlight_data = {
40193 .get_brightness = brightness_get,
40194 .update_status = brightness_update_status,
40195 };
40196diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
40197index 51c0a8b..0786629 100644
40198--- a/drivers/platform/x86/toshiba_acpi.c
40199+++ b/drivers/platform/x86/toshiba_acpi.c
40200@@ -671,7 +671,7 @@ static acpi_status remove_device(void)
40201 return AE_OK;
40202 }
40203
40204-static struct backlight_ops toshiba_backlight_data = {
40205+static const struct backlight_ops toshiba_backlight_data = {
40206 .get_brightness = get_lcd,
40207 .update_status = set_lcd_status,
40208 };
40209diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40210index fc83783c..cf370d7 100644
40211--- a/drivers/pnp/pnpbios/bioscalls.c
40212+++ b/drivers/pnp/pnpbios/bioscalls.c
40213@@ -60,7 +60,7 @@ do { \
40214 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40215 } while(0)
40216
40217-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40218+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40219 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40220
40221 /*
40222@@ -97,7 +97,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40223
40224 cpu = get_cpu();
40225 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40226+
40227+ pax_open_kernel();
40228 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40229+ pax_close_kernel();
40230
40231 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40232 spin_lock_irqsave(&pnp_bios_lock, flags);
40233@@ -135,7 +138,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40234 :"memory");
40235 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40236
40237+ pax_open_kernel();
40238 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40239+ pax_close_kernel();
40240+
40241 put_cpu();
40242
40243 /* If we get here and this is set then the PnP BIOS faulted on us. */
40244@@ -469,7 +475,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40245 return status;
40246 }
40247
40248-void pnpbios_calls_init(union pnp_bios_install_struct *header)
40249+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40250 {
40251 int i;
40252
40253@@ -477,6 +483,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40254 pnp_bios_callpoint.offset = header->fields.pm16offset;
40255 pnp_bios_callpoint.segment = PNP_CS16;
40256
40257+ pax_open_kernel();
40258+
40259 for_each_possible_cpu(i) {
40260 struct desc_struct *gdt = get_cpu_gdt_table(i);
40261 if (!gdt)
40262@@ -488,4 +496,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40263 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40264 (unsigned long)__va(header->fields.pm16dseg));
40265 }
40266+
40267+ pax_close_kernel();
40268 }
40269diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40270index ba97654..66b99d4 100644
40271--- a/drivers/pnp/resource.c
40272+++ b/drivers/pnp/resource.c
40273@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40274 return 1;
40275
40276 /* check if the resource is valid */
40277- if (*irq < 0 || *irq > 15)
40278+ if (*irq > 15)
40279 return 0;
40280
40281 /* check if the resource is reserved */
40282@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40283 return 1;
40284
40285 /* check if the resource is valid */
40286- if (*dma < 0 || *dma == 4 || *dma > 7)
40287+ if (*dma == 4 || *dma > 7)
40288 return 0;
40289
40290 /* check if the resource is reserved */
40291diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
40292index 62bb981..24a2dc9 100644
40293--- a/drivers/power/bq27x00_battery.c
40294+++ b/drivers/power/bq27x00_battery.c
40295@@ -44,7 +44,7 @@ struct bq27x00_device_info;
40296 struct bq27x00_access_methods {
40297 int (*read)(u8 reg, int *rt_value, int b_single,
40298 struct bq27x00_device_info *di);
40299-};
40300+} __no_const;
40301
40302 struct bq27x00_device_info {
40303 struct device *dev;
40304diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
40305index 62227cd..b5b538b 100644
40306--- a/drivers/rtc/rtc-dev.c
40307+++ b/drivers/rtc/rtc-dev.c
40308@@ -14,6 +14,7 @@
40309 #include <linux/module.h>
40310 #include <linux/rtc.h>
40311 #include <linux/sched.h>
40312+#include <linux/grsecurity.h>
40313 #include "rtc-core.h"
40314
40315 static dev_t rtc_devt;
40316@@ -357,6 +358,8 @@ static long rtc_dev_ioctl(struct file *file,
40317 if (copy_from_user(&tm, uarg, sizeof(tm)))
40318 return -EFAULT;
40319
40320+ gr_log_timechange();
40321+
40322 return rtc_set_time(rtc, &tm);
40323
40324 case RTC_PIE_ON:
40325diff --git a/drivers/s390/cio/qdio_perf.c b/drivers/s390/cio/qdio_perf.c
40326index 968e3c7..fbc637a 100644
40327--- a/drivers/s390/cio/qdio_perf.c
40328+++ b/drivers/s390/cio/qdio_perf.c
40329@@ -31,51 +31,51 @@ static struct proc_dir_entry *qdio_perf_pde;
40330 static int qdio_perf_proc_show(struct seq_file *m, void *v)
40331 {
40332 seq_printf(m, "Number of qdio interrupts\t\t\t: %li\n",
40333- (long)atomic_long_read(&perf_stats.qdio_int));
40334+ (long)atomic_long_read_unchecked(&perf_stats.qdio_int));
40335 seq_printf(m, "Number of PCI interrupts\t\t\t: %li\n",
40336- (long)atomic_long_read(&perf_stats.pci_int));
40337+ (long)atomic_long_read_unchecked(&perf_stats.pci_int));
40338 seq_printf(m, "Number of adapter interrupts\t\t\t: %li\n",
40339- (long)atomic_long_read(&perf_stats.thin_int));
40340+ (long)atomic_long_read_unchecked(&perf_stats.thin_int));
40341 seq_printf(m, "\n");
40342 seq_printf(m, "Inbound tasklet runs\t\t\t\t: %li\n",
40343- (long)atomic_long_read(&perf_stats.tasklet_inbound));
40344+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_inbound));
40345 seq_printf(m, "Outbound tasklet runs\t\t\t\t: %li\n",
40346- (long)atomic_long_read(&perf_stats.tasklet_outbound));
40347+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_outbound));
40348 seq_printf(m, "Adapter interrupt tasklet runs/loops\t\t: %li/%li\n",
40349- (long)atomic_long_read(&perf_stats.tasklet_thinint),
40350- (long)atomic_long_read(&perf_stats.tasklet_thinint_loop));
40351+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint),
40352+ (long)atomic_long_read_unchecked(&perf_stats.tasklet_thinint_loop));
40353 seq_printf(m, "Adapter interrupt inbound tasklet runs/loops\t: %li/%li\n",
40354- (long)atomic_long_read(&perf_stats.thinint_inbound),
40355- (long)atomic_long_read(&perf_stats.thinint_inbound_loop));
40356+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound),
40357+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop));
40358 seq_printf(m, "\n");
40359 seq_printf(m, "Number of SIGA In issued\t\t\t: %li\n",
40360- (long)atomic_long_read(&perf_stats.siga_in));
40361+ (long)atomic_long_read_unchecked(&perf_stats.siga_in));
40362 seq_printf(m, "Number of SIGA Out issued\t\t\t: %li\n",
40363- (long)atomic_long_read(&perf_stats.siga_out));
40364+ (long)atomic_long_read_unchecked(&perf_stats.siga_out));
40365 seq_printf(m, "Number of SIGA Sync issued\t\t\t: %li\n",
40366- (long)atomic_long_read(&perf_stats.siga_sync));
40367+ (long)atomic_long_read_unchecked(&perf_stats.siga_sync));
40368 seq_printf(m, "\n");
40369 seq_printf(m, "Number of inbound transfers\t\t\t: %li\n",
40370- (long)atomic_long_read(&perf_stats.inbound_handler));
40371+ (long)atomic_long_read_unchecked(&perf_stats.inbound_handler));
40372 seq_printf(m, "Number of outbound transfers\t\t\t: %li\n",
40373- (long)atomic_long_read(&perf_stats.outbound_handler));
40374+ (long)atomic_long_read_unchecked(&perf_stats.outbound_handler));
40375 seq_printf(m, "\n");
40376 seq_printf(m, "Number of fast requeues (outg. SBAL w/o SIGA)\t: %li\n",
40377- (long)atomic_long_read(&perf_stats.fast_requeue));
40378+ (long)atomic_long_read_unchecked(&perf_stats.fast_requeue));
40379 seq_printf(m, "Number of outbound target full condition\t: %li\n",
40380- (long)atomic_long_read(&perf_stats.outbound_target_full));
40381+ (long)atomic_long_read_unchecked(&perf_stats.outbound_target_full));
40382 seq_printf(m, "Number of outbound tasklet mod_timer calls\t: %li\n",
40383- (long)atomic_long_read(&perf_stats.debug_tl_out_timer));
40384+ (long)atomic_long_read_unchecked(&perf_stats.debug_tl_out_timer));
40385 seq_printf(m, "Number of stop polling calls\t\t\t: %li\n",
40386- (long)atomic_long_read(&perf_stats.debug_stop_polling));
40387+ (long)atomic_long_read_unchecked(&perf_stats.debug_stop_polling));
40388 seq_printf(m, "AI inbound tasklet loops after stop polling\t: %li\n",
40389- (long)atomic_long_read(&perf_stats.thinint_inbound_loop2));
40390+ (long)atomic_long_read_unchecked(&perf_stats.thinint_inbound_loop2));
40391 seq_printf(m, "QEBSM EQBS total/incomplete\t\t\t: %li/%li\n",
40392- (long)atomic_long_read(&perf_stats.debug_eqbs_all),
40393- (long)atomic_long_read(&perf_stats.debug_eqbs_incomplete));
40394+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_all),
40395+ (long)atomic_long_read_unchecked(&perf_stats.debug_eqbs_incomplete));
40396 seq_printf(m, "QEBSM SQBS total/incomplete\t\t\t: %li/%li\n",
40397- (long)atomic_long_read(&perf_stats.debug_sqbs_all),
40398- (long)atomic_long_read(&perf_stats.debug_sqbs_incomplete));
40399+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_all),
40400+ (long)atomic_long_read_unchecked(&perf_stats.debug_sqbs_incomplete));
40401 seq_printf(m, "\n");
40402 return 0;
40403 }
40404diff --git a/drivers/s390/cio/qdio_perf.h b/drivers/s390/cio/qdio_perf.h
40405index ff4504c..b3604c3 100644
40406--- a/drivers/s390/cio/qdio_perf.h
40407+++ b/drivers/s390/cio/qdio_perf.h
40408@@ -13,46 +13,46 @@
40409
40410 struct qdio_perf_stats {
40411 /* interrupt handler calls */
40412- atomic_long_t qdio_int;
40413- atomic_long_t pci_int;
40414- atomic_long_t thin_int;
40415+ atomic_long_unchecked_t qdio_int;
40416+ atomic_long_unchecked_t pci_int;
40417+ atomic_long_unchecked_t thin_int;
40418
40419 /* tasklet runs */
40420- atomic_long_t tasklet_inbound;
40421- atomic_long_t tasklet_outbound;
40422- atomic_long_t tasklet_thinint;
40423- atomic_long_t tasklet_thinint_loop;
40424- atomic_long_t thinint_inbound;
40425- atomic_long_t thinint_inbound_loop;
40426- atomic_long_t thinint_inbound_loop2;
40427+ atomic_long_unchecked_t tasklet_inbound;
40428+ atomic_long_unchecked_t tasklet_outbound;
40429+ atomic_long_unchecked_t tasklet_thinint;
40430+ atomic_long_unchecked_t tasklet_thinint_loop;
40431+ atomic_long_unchecked_t thinint_inbound;
40432+ atomic_long_unchecked_t thinint_inbound_loop;
40433+ atomic_long_unchecked_t thinint_inbound_loop2;
40434
40435 /* signal adapter calls */
40436- atomic_long_t siga_out;
40437- atomic_long_t siga_in;
40438- atomic_long_t siga_sync;
40439+ atomic_long_unchecked_t siga_out;
40440+ atomic_long_unchecked_t siga_in;
40441+ atomic_long_unchecked_t siga_sync;
40442
40443 /* misc */
40444- atomic_long_t inbound_handler;
40445- atomic_long_t outbound_handler;
40446- atomic_long_t fast_requeue;
40447- atomic_long_t outbound_target_full;
40448+ atomic_long_unchecked_t inbound_handler;
40449+ atomic_long_unchecked_t outbound_handler;
40450+ atomic_long_unchecked_t fast_requeue;
40451+ atomic_long_unchecked_t outbound_target_full;
40452
40453 /* for debugging */
40454- atomic_long_t debug_tl_out_timer;
40455- atomic_long_t debug_stop_polling;
40456- atomic_long_t debug_eqbs_all;
40457- atomic_long_t debug_eqbs_incomplete;
40458- atomic_long_t debug_sqbs_all;
40459- atomic_long_t debug_sqbs_incomplete;
40460+ atomic_long_unchecked_t debug_tl_out_timer;
40461+ atomic_long_unchecked_t debug_stop_polling;
40462+ atomic_long_unchecked_t debug_eqbs_all;
40463+ atomic_long_unchecked_t debug_eqbs_incomplete;
40464+ atomic_long_unchecked_t debug_sqbs_all;
40465+ atomic_long_unchecked_t debug_sqbs_incomplete;
40466 };
40467
40468 extern struct qdio_perf_stats perf_stats;
40469 extern int qdio_performance_stats;
40470
40471-static inline void qdio_perf_stat_inc(atomic_long_t *count)
40472+static inline void qdio_perf_stat_inc(atomic_long_unchecked_t *count)
40473 {
40474 if (qdio_performance_stats)
40475- atomic_long_inc(count);
40476+ atomic_long_inc_unchecked(count);
40477 }
40478
40479 int qdio_setup_perf_stats(void);
40480diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
40481index 1ddcf40..a85f062 100644
40482--- a/drivers/scsi/BusLogic.c
40483+++ b/drivers/scsi/BusLogic.c
40484@@ -961,6 +961,8 @@ static int __init BusLogic_InitializeFlashPointProbeInfo(struct BusLogic_HostAda
40485 static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
40486 *PrototypeHostAdapter)
40487 {
40488+ pax_track_stack();
40489+
40490 /*
40491 If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
40492 Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
40493diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
40494index cdbdec9..b7d560b 100644
40495--- a/drivers/scsi/aacraid/aacraid.h
40496+++ b/drivers/scsi/aacraid/aacraid.h
40497@@ -471,7 +471,7 @@ struct adapter_ops
40498 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
40499 /* Administrative operations */
40500 int (*adapter_comm)(struct aac_dev * dev, int comm);
40501-};
40502+} __no_const;
40503
40504 /*
40505 * Define which interrupt handler needs to be installed
40506diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
40507index a5b8e7b..a6a0e43 100644
40508--- a/drivers/scsi/aacraid/commctrl.c
40509+++ b/drivers/scsi/aacraid/commctrl.c
40510@@ -481,6 +481,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
40511 u32 actual_fibsize64, actual_fibsize = 0;
40512 int i;
40513
40514+ pax_track_stack();
40515
40516 if (dev->in_reset) {
40517 dprintk((KERN_DEBUG"aacraid: send raw srb -EBUSY\n"));
40518diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
40519index 9b97c3e..f099725 100644
40520--- a/drivers/scsi/aacraid/linit.c
40521+++ b/drivers/scsi/aacraid/linit.c
40522@@ -91,7 +91,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
40523 #elif defined(__devinitconst)
40524 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
40525 #else
40526-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
40527+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
40528 #endif
40529 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
40530 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
40531diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
40532index 996f722..9127845 100644
40533--- a/drivers/scsi/aic94xx/aic94xx_init.c
40534+++ b/drivers/scsi/aic94xx/aic94xx_init.c
40535@@ -485,7 +485,7 @@ static ssize_t asd_show_update_bios(struct device *dev,
40536 flash_error_table[i].reason);
40537 }
40538
40539-static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUGO,
40540+static DEVICE_ATTR(update_bios, S_IRUGO|S_IWUSR,
40541 asd_show_update_bios, asd_store_update_bios);
40542
40543 static int asd_create_dev_attrs(struct asd_ha_struct *asd_ha)
40544@@ -1011,7 +1011,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
40545 .lldd_control_phy = asd_control_phy,
40546 };
40547
40548-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
40549+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
40550 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
40551 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
40552 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
40553diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
40554index 58efd4b..cb48dc7 100644
40555--- a/drivers/scsi/bfa/bfa_ioc.h
40556+++ b/drivers/scsi/bfa/bfa_ioc.h
40557@@ -127,7 +127,7 @@ struct bfa_ioc_cbfn_s {
40558 bfa_ioc_disable_cbfn_t disable_cbfn;
40559 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
40560 bfa_ioc_reset_cbfn_t reset_cbfn;
40561-};
40562+} __no_const;
40563
40564 /**
40565 * Heartbeat failure notification queue element.
40566diff --git a/drivers/scsi/bfa/bfa_iocfc.h b/drivers/scsi/bfa/bfa_iocfc.h
40567index 7ad177e..5503586 100644
40568--- a/drivers/scsi/bfa/bfa_iocfc.h
40569+++ b/drivers/scsi/bfa/bfa_iocfc.h
40570@@ -61,7 +61,7 @@ struct bfa_hwif_s {
40571 void (*hw_isr_mode_set)(struct bfa_s *bfa, bfa_boolean_t msix);
40572 void (*hw_msix_getvecs)(struct bfa_s *bfa, u32 *vecmap,
40573 u32 *nvecs, u32 *maxvec);
40574-};
40575+} __no_const;
40576 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
40577
40578 struct bfa_iocfc_s {
40579diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
40580index 4967643..cbec06b 100644
40581--- a/drivers/scsi/dpt_i2o.c
40582+++ b/drivers/scsi/dpt_i2o.c
40583@@ -1804,6 +1804,8 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
40584 dma_addr_t addr;
40585 ulong flags = 0;
40586
40587+ pax_track_stack();
40588+
40589 memset(&msg, 0, MAX_MESSAGE_SIZE*4);
40590 // get user msg size in u32s
40591 if(get_user(size, &user_msg[0])){
40592@@ -2297,6 +2299,8 @@ static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
40593 s32 rcode;
40594 dma_addr_t addr;
40595
40596+ pax_track_stack();
40597+
40598 memset(msg, 0 , sizeof(msg));
40599 len = scsi_bufflen(cmd);
40600 direction = 0x00000000;
40601diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
40602index c7076ce..e20c67c 100644
40603--- a/drivers/scsi/eata.c
40604+++ b/drivers/scsi/eata.c
40605@@ -1087,6 +1087,8 @@ static int port_detect(unsigned long port_base, unsigned int j,
40606 struct hostdata *ha;
40607 char name[16];
40608
40609+ pax_track_stack();
40610+
40611 sprintf(name, "%s%d", driver_name, j);
40612
40613 if (!request_region(port_base, REGION_SIZE, driver_name)) {
40614diff --git a/drivers/scsi/fcoe/libfcoe.c b/drivers/scsi/fcoe/libfcoe.c
40615index 11ae5c9..891daec 100644
40616--- a/drivers/scsi/fcoe/libfcoe.c
40617+++ b/drivers/scsi/fcoe/libfcoe.c
40618@@ -809,6 +809,8 @@ static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
40619 size_t rlen;
40620 size_t dlen;
40621
40622+ pax_track_stack();
40623+
40624 fiph = (struct fip_header *)skb->data;
40625 sub = fiph->fip_subcode;
40626 if (sub != FIP_SC_REQ && sub != FIP_SC_REP)
40627diff --git a/drivers/scsi/fnic/fnic_main.c b/drivers/scsi/fnic/fnic_main.c
40628index 71c7bbe..e93088a 100644
40629--- a/drivers/scsi/fnic/fnic_main.c
40630+++ b/drivers/scsi/fnic/fnic_main.c
40631@@ -669,7 +669,7 @@ static int __devinit fnic_probe(struct pci_dev *pdev,
40632 /* Start local port initiatialization */
40633
40634 lp->link_up = 0;
40635- lp->tt = fnic_transport_template;
40636+ memcpy((void *)&lp->tt, &fnic_transport_template, sizeof(fnic_transport_template));
40637
40638 lp->max_retry_count = fnic->config.flogi_retries;
40639 lp->max_rport_retry_count = fnic->config.plogi_retries;
40640diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
40641index bb96d74..9ec3ce4 100644
40642--- a/drivers/scsi/gdth.c
40643+++ b/drivers/scsi/gdth.c
40644@@ -4102,6 +4102,8 @@ static int ioc_lockdrv(void __user *arg)
40645 ulong flags;
40646 gdth_ha_str *ha;
40647
40648+ pax_track_stack();
40649+
40650 if (copy_from_user(&ldrv, arg, sizeof(gdth_ioctl_lockdrv)))
40651 return -EFAULT;
40652 ha = gdth_find_ha(ldrv.ionode);
40653@@ -4134,6 +4136,8 @@ static int ioc_resetdrv(void __user *arg, char *cmnd)
40654 gdth_ha_str *ha;
40655 int rval;
40656
40657+ pax_track_stack();
40658+
40659 if (copy_from_user(&res, arg, sizeof(gdth_ioctl_reset)) ||
40660 res.number >= MAX_HDRIVES)
40661 return -EFAULT;
40662@@ -4169,6 +4173,8 @@ static int ioc_general(void __user *arg, char *cmnd)
40663 gdth_ha_str *ha;
40664 int rval;
40665
40666+ pax_track_stack();
40667+
40668 if (copy_from_user(&gen, arg, sizeof(gdth_ioctl_general)))
40669 return -EFAULT;
40670 ha = gdth_find_ha(gen.ionode);
40671@@ -4625,6 +4631,9 @@ static void gdth_flush(gdth_ha_str *ha)
40672 int i;
40673 gdth_cmd_str gdtcmd;
40674 char cmnd[MAX_COMMAND_SIZE];
40675+
40676+ pax_track_stack();
40677+
40678 memset(cmnd, 0xff, MAX_COMMAND_SIZE);
40679
40680 TRACE2(("gdth_flush() hanum %d\n", ha->hanum));
40681diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
40682index 1258da3..20d8ae6 100644
40683--- a/drivers/scsi/gdth_proc.c
40684+++ b/drivers/scsi/gdth_proc.c
40685@@ -46,6 +46,9 @@ static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
40686 ulong64 paddr;
40687
40688 char cmnd[MAX_COMMAND_SIZE];
40689+
40690+ pax_track_stack();
40691+
40692 memset(cmnd, 0xff, 12);
40693 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
40694
40695@@ -174,6 +177,8 @@ static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
40696 gdth_hget_str *phg;
40697 char cmnd[MAX_COMMAND_SIZE];
40698
40699+ pax_track_stack();
40700+
40701 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
40702 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
40703 if (!gdtcmd || !estr)
40704diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
40705index d03a926..f324286 100644
40706--- a/drivers/scsi/hosts.c
40707+++ b/drivers/scsi/hosts.c
40708@@ -40,7 +40,7 @@
40709 #include "scsi_logging.h"
40710
40711
40712-static atomic_t scsi_host_next_hn; /* host_no for next new host */
40713+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
40714
40715
40716 static void scsi_host_cls_release(struct device *dev)
40717@@ -347,7 +347,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
40718 * subtract one because we increment first then return, but we need to
40719 * know what the next host number was before increment
40720 */
40721- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
40722+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
40723 shost->dma_channel = 0xff;
40724
40725 /* These three are default values which can be overridden */
40726diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
40727index a601159..55e19d2 100644
40728--- a/drivers/scsi/ipr.c
40729+++ b/drivers/scsi/ipr.c
40730@@ -5286,7 +5286,7 @@ static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
40731 return true;
40732 }
40733
40734-static struct ata_port_operations ipr_sata_ops = {
40735+static const struct ata_port_operations ipr_sata_ops = {
40736 .phy_reset = ipr_ata_phy_reset,
40737 .hardreset = ipr_sata_reset,
40738 .post_internal_cmd = ipr_ata_post_internal,
40739diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
40740index 4e49fbc..97907ff 100644
40741--- a/drivers/scsi/ips.h
40742+++ b/drivers/scsi/ips.h
40743@@ -1027,7 +1027,7 @@ typedef struct {
40744 int (*intr)(struct ips_ha *);
40745 void (*enableint)(struct ips_ha *);
40746 uint32_t (*statupd)(struct ips_ha *);
40747-} ips_hw_func_t;
40748+} __no_const ips_hw_func_t;
40749
40750 typedef struct ips_ha {
40751 uint8_t ha_id[IPS_MAX_CHANNELS+1];
40752diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
40753index c1c1574..a9c9348 100644
40754--- a/drivers/scsi/libfc/fc_exch.c
40755+++ b/drivers/scsi/libfc/fc_exch.c
40756@@ -86,12 +86,12 @@ struct fc_exch_mgr {
40757 * all together if not used XXX
40758 */
40759 struct {
40760- atomic_t no_free_exch;
40761- atomic_t no_free_exch_xid;
40762- atomic_t xid_not_found;
40763- atomic_t xid_busy;
40764- atomic_t seq_not_found;
40765- atomic_t non_bls_resp;
40766+ atomic_unchecked_t no_free_exch;
40767+ atomic_unchecked_t no_free_exch_xid;
40768+ atomic_unchecked_t xid_not_found;
40769+ atomic_unchecked_t xid_busy;
40770+ atomic_unchecked_t seq_not_found;
40771+ atomic_unchecked_t non_bls_resp;
40772 } stats;
40773 };
40774 #define fc_seq_exch(sp) container_of(sp, struct fc_exch, seq)
40775@@ -510,7 +510,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
40776 /* allocate memory for exchange */
40777 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
40778 if (!ep) {
40779- atomic_inc(&mp->stats.no_free_exch);
40780+ atomic_inc_unchecked(&mp->stats.no_free_exch);
40781 goto out;
40782 }
40783 memset(ep, 0, sizeof(*ep));
40784@@ -557,7 +557,7 @@ out:
40785 return ep;
40786 err:
40787 spin_unlock_bh(&pool->lock);
40788- atomic_inc(&mp->stats.no_free_exch_xid);
40789+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
40790 mempool_free(ep, mp->ep_pool);
40791 return NULL;
40792 }
40793@@ -690,7 +690,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40794 xid = ntohs(fh->fh_ox_id); /* we originated exch */
40795 ep = fc_exch_find(mp, xid);
40796 if (!ep) {
40797- atomic_inc(&mp->stats.xid_not_found);
40798+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40799 reject = FC_RJT_OX_ID;
40800 goto out;
40801 }
40802@@ -720,7 +720,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40803 ep = fc_exch_find(mp, xid);
40804 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
40805 if (ep) {
40806- atomic_inc(&mp->stats.xid_busy);
40807+ atomic_inc_unchecked(&mp->stats.xid_busy);
40808 reject = FC_RJT_RX_ID;
40809 goto rel;
40810 }
40811@@ -731,7 +731,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40812 }
40813 xid = ep->xid; /* get our XID */
40814 } else if (!ep) {
40815- atomic_inc(&mp->stats.xid_not_found);
40816+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40817 reject = FC_RJT_RX_ID; /* XID not found */
40818 goto out;
40819 }
40820@@ -752,7 +752,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
40821 } else {
40822 sp = &ep->seq;
40823 if (sp->id != fh->fh_seq_id) {
40824- atomic_inc(&mp->stats.seq_not_found);
40825+ atomic_inc_unchecked(&mp->stats.seq_not_found);
40826 reject = FC_RJT_SEQ_ID; /* sequence/exch should exist */
40827 goto rel;
40828 }
40829@@ -1163,22 +1163,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40830
40831 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
40832 if (!ep) {
40833- atomic_inc(&mp->stats.xid_not_found);
40834+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40835 goto out;
40836 }
40837 if (ep->esb_stat & ESB_ST_COMPLETE) {
40838- atomic_inc(&mp->stats.xid_not_found);
40839+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40840 goto out;
40841 }
40842 if (ep->rxid == FC_XID_UNKNOWN)
40843 ep->rxid = ntohs(fh->fh_rx_id);
40844 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
40845- atomic_inc(&mp->stats.xid_not_found);
40846+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40847 goto rel;
40848 }
40849 if (ep->did != ntoh24(fh->fh_s_id) &&
40850 ep->did != FC_FID_FLOGI) {
40851- atomic_inc(&mp->stats.xid_not_found);
40852+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40853 goto rel;
40854 }
40855 sof = fr_sof(fp);
40856@@ -1189,7 +1189,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40857 } else {
40858 sp = &ep->seq;
40859 if (sp->id != fh->fh_seq_id) {
40860- atomic_inc(&mp->stats.seq_not_found);
40861+ atomic_inc_unchecked(&mp->stats.seq_not_found);
40862 goto rel;
40863 }
40864 }
40865@@ -1249,9 +1249,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
40866 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
40867
40868 if (!sp)
40869- atomic_inc(&mp->stats.xid_not_found);
40870+ atomic_inc_unchecked(&mp->stats.xid_not_found);
40871 else
40872- atomic_inc(&mp->stats.non_bls_resp);
40873+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
40874
40875 fc_frame_free(fp);
40876 }
40877diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
40878index 0ee989f..a582241 100644
40879--- a/drivers/scsi/libsas/sas_ata.c
40880+++ b/drivers/scsi/libsas/sas_ata.c
40881@@ -343,7 +343,7 @@ static int sas_ata_scr_read(struct ata_link *link, unsigned int sc_reg_in,
40882 }
40883 }
40884
40885-static struct ata_port_operations sas_sata_ops = {
40886+static const struct ata_port_operations sas_sata_ops = {
40887 .phy_reset = sas_ata_phy_reset,
40888 .post_internal_cmd = sas_ata_post_internal,
40889 .qc_defer = ata_std_qc_defer,
40890diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
40891index aa10f79..5cc79e4 100644
40892--- a/drivers/scsi/lpfc/lpfc.h
40893+++ b/drivers/scsi/lpfc/lpfc.h
40894@@ -400,7 +400,7 @@ struct lpfc_vport {
40895 struct dentry *debug_nodelist;
40896 struct dentry *vport_debugfs_root;
40897 struct lpfc_debugfs_trc *disc_trc;
40898- atomic_t disc_trc_cnt;
40899+ atomic_unchecked_t disc_trc_cnt;
40900 #endif
40901 uint8_t stat_data_enabled;
40902 uint8_t stat_data_blocked;
40903@@ -725,8 +725,8 @@ struct lpfc_hba {
40904 struct timer_list fabric_block_timer;
40905 unsigned long bit_flags;
40906 #define FABRIC_COMANDS_BLOCKED 0
40907- atomic_t num_rsrc_err;
40908- atomic_t num_cmd_success;
40909+ atomic_unchecked_t num_rsrc_err;
40910+ atomic_unchecked_t num_cmd_success;
40911 unsigned long last_rsrc_error_time;
40912 unsigned long last_ramp_down_time;
40913 unsigned long last_ramp_up_time;
40914@@ -740,7 +740,7 @@ struct lpfc_hba {
40915 struct dentry *debug_dumpDif; /* BlockGuard BPL*/
40916 struct dentry *debug_slow_ring_trc;
40917 struct lpfc_debugfs_trc *slow_ring_trc;
40918- atomic_t slow_ring_trc_cnt;
40919+ atomic_unchecked_t slow_ring_trc_cnt;
40920 #endif
40921
40922 /* Used for deferred freeing of ELS data buffers */
40923diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
40924index 8d0f0de..7c77a62 100644
40925--- a/drivers/scsi/lpfc/lpfc_debugfs.c
40926+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
40927@@ -124,7 +124,7 @@ struct lpfc_debug {
40928 int len;
40929 };
40930
40931-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
40932+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
40933 static unsigned long lpfc_debugfs_start_time = 0L;
40934
40935 /**
40936@@ -158,7 +158,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
40937 lpfc_debugfs_enable = 0;
40938
40939 len = 0;
40940- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
40941+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
40942 (lpfc_debugfs_max_disc_trc - 1);
40943 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
40944 dtp = vport->disc_trc + i;
40945@@ -219,7 +219,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
40946 lpfc_debugfs_enable = 0;
40947
40948 len = 0;
40949- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
40950+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
40951 (lpfc_debugfs_max_slow_ring_trc - 1);
40952 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
40953 dtp = phba->slow_ring_trc + i;
40954@@ -397,6 +397,8 @@ lpfc_debugfs_dumpHBASlim_data(struct lpfc_hba *phba, char *buf, int size)
40955 uint32_t *ptr;
40956 char buffer[1024];
40957
40958+ pax_track_stack();
40959+
40960 off = 0;
40961 spin_lock_irq(&phba->hbalock);
40962
40963@@ -634,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
40964 !vport || !vport->disc_trc)
40965 return;
40966
40967- index = atomic_inc_return(&vport->disc_trc_cnt) &
40968+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
40969 (lpfc_debugfs_max_disc_trc - 1);
40970 dtp = vport->disc_trc + index;
40971 dtp->fmt = fmt;
40972 dtp->data1 = data1;
40973 dtp->data2 = data2;
40974 dtp->data3 = data3;
40975- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
40976+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
40977 dtp->jif = jiffies;
40978 #endif
40979 return;
40980@@ -672,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
40981 !phba || !phba->slow_ring_trc)
40982 return;
40983
40984- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
40985+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
40986 (lpfc_debugfs_max_slow_ring_trc - 1);
40987 dtp = phba->slow_ring_trc + index;
40988 dtp->fmt = fmt;
40989 dtp->data1 = data1;
40990 dtp->data2 = data2;
40991 dtp->data3 = data3;
40992- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
40993+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
40994 dtp->jif = jiffies;
40995 #endif
40996 return;
40997@@ -1364,7 +1366,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
40998 "slow_ring buffer\n");
40999 goto debug_failed;
41000 }
41001- atomic_set(&phba->slow_ring_trc_cnt, 0);
41002+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
41003 memset(phba->slow_ring_trc, 0,
41004 (sizeof(struct lpfc_debugfs_trc) *
41005 lpfc_debugfs_max_slow_ring_trc));
41006@@ -1410,7 +1412,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41007 "buffer\n");
41008 goto debug_failed;
41009 }
41010- atomic_set(&vport->disc_trc_cnt, 0);
41011+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
41012
41013 snprintf(name, sizeof(name), "discovery_trace");
41014 vport->debug_disc_trc =
41015diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
41016index 549bc7d..8189dbb 100644
41017--- a/drivers/scsi/lpfc/lpfc_init.c
41018+++ b/drivers/scsi/lpfc/lpfc_init.c
41019@@ -8021,8 +8021,10 @@ lpfc_init(void)
41020 printk(LPFC_COPYRIGHT "\n");
41021
41022 if (lpfc_enable_npiv) {
41023- lpfc_transport_functions.vport_create = lpfc_vport_create;
41024- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41025+ pax_open_kernel();
41026+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
41027+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41028+ pax_close_kernel();
41029 }
41030 lpfc_transport_template =
41031 fc_attach_transport(&lpfc_transport_functions);
41032diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
41033index c88f59f..ff2a42f 100644
41034--- a/drivers/scsi/lpfc/lpfc_scsi.c
41035+++ b/drivers/scsi/lpfc/lpfc_scsi.c
41036@@ -259,7 +259,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
41037 uint32_t evt_posted;
41038
41039 spin_lock_irqsave(&phba->hbalock, flags);
41040- atomic_inc(&phba->num_rsrc_err);
41041+ atomic_inc_unchecked(&phba->num_rsrc_err);
41042 phba->last_rsrc_error_time = jiffies;
41043
41044 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
41045@@ -300,7 +300,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
41046 unsigned long flags;
41047 struct lpfc_hba *phba = vport->phba;
41048 uint32_t evt_posted;
41049- atomic_inc(&phba->num_cmd_success);
41050+ atomic_inc_unchecked(&phba->num_cmd_success);
41051
41052 if (vport->cfg_lun_queue_depth <= queue_depth)
41053 return;
41054@@ -343,8 +343,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41055 int i;
41056 struct lpfc_rport_data *rdata;
41057
41058- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
41059- num_cmd_success = atomic_read(&phba->num_cmd_success);
41060+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
41061+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
41062
41063 vports = lpfc_create_vport_work_array(phba);
41064 if (vports != NULL)
41065@@ -378,8 +378,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41066 }
41067 }
41068 lpfc_destroy_vport_work_array(phba, vports);
41069- atomic_set(&phba->num_rsrc_err, 0);
41070- atomic_set(&phba->num_cmd_success, 0);
41071+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41072+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41073 }
41074
41075 /**
41076@@ -427,8 +427,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41077 }
41078 }
41079 lpfc_destroy_vport_work_array(phba, vports);
41080- atomic_set(&phba->num_rsrc_err, 0);
41081- atomic_set(&phba->num_cmd_success, 0);
41082+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41083+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41084 }
41085
41086 /**
41087diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
41088index 234f0b7..3020aea 100644
41089--- a/drivers/scsi/megaraid/megaraid_mbox.c
41090+++ b/drivers/scsi/megaraid/megaraid_mbox.c
41091@@ -3503,6 +3503,8 @@ megaraid_cmm_register(adapter_t *adapter)
41092 int rval;
41093 int i;
41094
41095+ pax_track_stack();
41096+
41097 // Allocate memory for the base list of scb for management module.
41098 adapter->uscb_list = kcalloc(MBOX_MAX_USER_CMDS, sizeof(scb_t), GFP_KERNEL);
41099
41100diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
41101index 7a117c1..ee01e9e 100644
41102--- a/drivers/scsi/osd/osd_initiator.c
41103+++ b/drivers/scsi/osd/osd_initiator.c
41104@@ -94,6 +94,8 @@ static int _osd_print_system_info(struct osd_dev *od, void *caps)
41105 int nelem = ARRAY_SIZE(get_attrs), a = 0;
41106 int ret;
41107
41108+ pax_track_stack();
41109+
41110 or = osd_start_request(od, GFP_KERNEL);
41111 if (!or)
41112 return -ENOMEM;
41113diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41114index 9ab8c86..9425ad3 100644
41115--- a/drivers/scsi/pmcraid.c
41116+++ b/drivers/scsi/pmcraid.c
41117@@ -189,8 +189,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41118 res->scsi_dev = scsi_dev;
41119 scsi_dev->hostdata = res;
41120 res->change_detected = 0;
41121- atomic_set(&res->read_failures, 0);
41122- atomic_set(&res->write_failures, 0);
41123+ atomic_set_unchecked(&res->read_failures, 0);
41124+ atomic_set_unchecked(&res->write_failures, 0);
41125 rc = 0;
41126 }
41127 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41128@@ -2396,9 +2396,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41129
41130 /* If this was a SCSI read/write command keep count of errors */
41131 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41132- atomic_inc(&res->read_failures);
41133+ atomic_inc_unchecked(&res->read_failures);
41134 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41135- atomic_inc(&res->write_failures);
41136+ atomic_inc_unchecked(&res->write_failures);
41137
41138 if (!RES_IS_GSCSI(res->cfg_entry) &&
41139 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41140@@ -4116,7 +4116,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41141
41142 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41143 /* add resources only after host is added into system */
41144- if (!atomic_read(&pinstance->expose_resources))
41145+ if (!atomic_read_unchecked(&pinstance->expose_resources))
41146 return;
41147
41148 spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
41149@@ -4850,7 +4850,7 @@ static int __devinit pmcraid_init_instance(
41150 init_waitqueue_head(&pinstance->reset_wait_q);
41151
41152 atomic_set(&pinstance->outstanding_cmds, 0);
41153- atomic_set(&pinstance->expose_resources, 0);
41154+ atomic_set_unchecked(&pinstance->expose_resources, 0);
41155
41156 INIT_LIST_HEAD(&pinstance->free_res_q);
41157 INIT_LIST_HEAD(&pinstance->used_res_q);
41158@@ -5502,7 +5502,7 @@ static int __devinit pmcraid_probe(
41159 /* Schedule worker thread to handle CCN and take care of adding and
41160 * removing devices to OS
41161 */
41162- atomic_set(&pinstance->expose_resources, 1);
41163+ atomic_set_unchecked(&pinstance->expose_resources, 1);
41164 schedule_work(&pinstance->worker_q);
41165 return rc;
41166
41167diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41168index 3441b3f..6cbe8f7 100644
41169--- a/drivers/scsi/pmcraid.h
41170+++ b/drivers/scsi/pmcraid.h
41171@@ -690,7 +690,7 @@ struct pmcraid_instance {
41172 atomic_t outstanding_cmds;
41173
41174 /* should add/delete resources to mid-layer now ?*/
41175- atomic_t expose_resources;
41176+ atomic_unchecked_t expose_resources;
41177
41178 /* Tasklet to handle deferred processing */
41179 struct tasklet_struct isr_tasklet[PMCRAID_NUM_MSIX_VECTORS];
41180@@ -727,8 +727,8 @@ struct pmcraid_resource_entry {
41181 struct list_head queue; /* link to "to be exposed" resources */
41182 struct pmcraid_config_table_entry cfg_entry;
41183 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41184- atomic_t read_failures; /* count of failed READ commands */
41185- atomic_t write_failures; /* count of failed WRITE commands */
41186+ atomic_unchecked_t read_failures; /* count of failed READ commands */
41187+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41188
41189 /* To indicate add/delete/modify during CCN */
41190 u8 change_detected;
41191diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
41192index 2150618..7034215 100644
41193--- a/drivers/scsi/qla2xxx/qla_def.h
41194+++ b/drivers/scsi/qla2xxx/qla_def.h
41195@@ -2089,7 +2089,7 @@ struct isp_operations {
41196
41197 int (*get_flash_version) (struct scsi_qla_host *, void *);
41198 int (*start_scsi) (srb_t *);
41199-};
41200+} __no_const;
41201
41202 /* MSI-X Support *************************************************************/
41203
41204diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41205index 81b5f29..2ae1fad 100644
41206--- a/drivers/scsi/qla4xxx/ql4_def.h
41207+++ b/drivers/scsi/qla4xxx/ql4_def.h
41208@@ -240,7 +240,7 @@ struct ddb_entry {
41209 atomic_t retry_relogin_timer; /* Min Time between relogins
41210 * (4000 only) */
41211 atomic_t relogin_timer; /* Max Time to wait for relogin to complete */
41212- atomic_t relogin_retry_count; /* Num of times relogin has been
41213+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41214 * retried */
41215
41216 uint16_t port;
41217diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
41218index af8c323..515dd51 100644
41219--- a/drivers/scsi/qla4xxx/ql4_init.c
41220+++ b/drivers/scsi/qla4xxx/ql4_init.c
41221@@ -482,7 +482,7 @@ static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
41222 atomic_set(&ddb_entry->port_down_timer, ha->port_down_retry_count);
41223 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41224 atomic_set(&ddb_entry->relogin_timer, 0);
41225- atomic_set(&ddb_entry->relogin_retry_count, 0);
41226+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41227 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
41228 list_add_tail(&ddb_entry->list, &ha->ddb_list);
41229 ha->fw_ddb_index_map[fw_ddb_index] = ddb_entry;
41230@@ -1308,7 +1308,7 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha,
41231 atomic_set(&ddb_entry->state, DDB_STATE_ONLINE);
41232 atomic_set(&ddb_entry->port_down_timer,
41233 ha->port_down_retry_count);
41234- atomic_set(&ddb_entry->relogin_retry_count, 0);
41235+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41236 atomic_set(&ddb_entry->relogin_timer, 0);
41237 clear_bit(DF_RELOGIN, &ddb_entry->flags);
41238 clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
41239diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41240index 83c8b5e..a82b348 100644
41241--- a/drivers/scsi/qla4xxx/ql4_os.c
41242+++ b/drivers/scsi/qla4xxx/ql4_os.c
41243@@ -641,13 +641,13 @@ static void qla4xxx_timer(struct scsi_qla_host *ha)
41244 ddb_entry->fw_ddb_device_state ==
41245 DDB_DS_SESSION_FAILED) {
41246 /* Reset retry relogin timer */
41247- atomic_inc(&ddb_entry->relogin_retry_count);
41248+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41249 DEBUG2(printk("scsi%ld: index[%d] relogin"
41250 " timed out-retrying"
41251 " relogin (%d)\n",
41252 ha->host_no,
41253 ddb_entry->fw_ddb_index,
41254- atomic_read(&ddb_entry->
41255+ atomic_read_unchecked(&ddb_entry->
41256 relogin_retry_count))
41257 );
41258 start_dpc++;
41259diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41260index dd098ca..686ce01 100644
41261--- a/drivers/scsi/scsi.c
41262+++ b/drivers/scsi/scsi.c
41263@@ -652,7 +652,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41264 unsigned long timeout;
41265 int rtn = 0;
41266
41267- atomic_inc(&cmd->device->iorequest_cnt);
41268+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41269
41270 /* check if the device is still usable */
41271 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41272diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
41273index bc3e363..e1a8e50 100644
41274--- a/drivers/scsi/scsi_debug.c
41275+++ b/drivers/scsi/scsi_debug.c
41276@@ -1395,6 +1395,8 @@ static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
41277 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
41278 unsigned char *cmd = (unsigned char *)scp->cmnd;
41279
41280+ pax_track_stack();
41281+
41282 if ((errsts = check_readiness(scp, 1, devip)))
41283 return errsts;
41284 memset(arr, 0, sizeof(arr));
41285@@ -1492,6 +1494,8 @@ static int resp_log_sense(struct scsi_cmnd * scp,
41286 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
41287 unsigned char *cmd = (unsigned char *)scp->cmnd;
41288
41289+ pax_track_stack();
41290+
41291 if ((errsts = check_readiness(scp, 1, devip)))
41292 return errsts;
41293 memset(arr, 0, sizeof(arr));
41294diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41295index 8df12522..c4c1472 100644
41296--- a/drivers/scsi/scsi_lib.c
41297+++ b/drivers/scsi/scsi_lib.c
41298@@ -1389,7 +1389,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41299 shost = sdev->host;
41300 scsi_init_cmd_errh(cmd);
41301 cmd->result = DID_NO_CONNECT << 16;
41302- atomic_inc(&cmd->device->iorequest_cnt);
41303+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41304
41305 /*
41306 * SCSI request completion path will do scsi_device_unbusy(),
41307@@ -1420,9 +1420,9 @@ static void scsi_softirq_done(struct request *rq)
41308 */
41309 cmd->serial_number = 0;
41310
41311- atomic_inc(&cmd->device->iodone_cnt);
41312+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
41313 if (cmd->result)
41314- atomic_inc(&cmd->device->ioerr_cnt);
41315+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41316
41317 disposition = scsi_decide_disposition(cmd);
41318 if (disposition != SUCCESS &&
41319diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41320index 91a93e0..eae0fe3 100644
41321--- a/drivers/scsi/scsi_sysfs.c
41322+++ b/drivers/scsi/scsi_sysfs.c
41323@@ -662,7 +662,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41324 char *buf) \
41325 { \
41326 struct scsi_device *sdev = to_scsi_device(dev); \
41327- unsigned long long count = atomic_read(&sdev->field); \
41328+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
41329 return snprintf(buf, 20, "0x%llx\n", count); \
41330 } \
41331 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41332diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41333index 1030327..f91fd30 100644
41334--- a/drivers/scsi/scsi_tgt_lib.c
41335+++ b/drivers/scsi/scsi_tgt_lib.c
41336@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41337 int err;
41338
41339 dprintk("%lx %u\n", uaddr, len);
41340- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41341+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41342 if (err) {
41343 /*
41344 * TODO: need to fixup sg_tablesize, max_segment_size,
41345diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41346index db02e31..1b42ea9 100644
41347--- a/drivers/scsi/scsi_transport_fc.c
41348+++ b/drivers/scsi/scsi_transport_fc.c
41349@@ -480,7 +480,7 @@ MODULE_PARM_DESC(dev_loss_tmo,
41350 * Netlink Infrastructure
41351 */
41352
41353-static atomic_t fc_event_seq;
41354+static atomic_unchecked_t fc_event_seq;
41355
41356 /**
41357 * fc_get_event_number - Obtain the next sequential FC event number
41358@@ -493,7 +493,7 @@ static atomic_t fc_event_seq;
41359 u32
41360 fc_get_event_number(void)
41361 {
41362- return atomic_add_return(1, &fc_event_seq);
41363+ return atomic_add_return_unchecked(1, &fc_event_seq);
41364 }
41365 EXPORT_SYMBOL(fc_get_event_number);
41366
41367@@ -641,7 +641,7 @@ static __init int fc_transport_init(void)
41368 {
41369 int error;
41370
41371- atomic_set(&fc_event_seq, 0);
41372+ atomic_set_unchecked(&fc_event_seq, 0);
41373
41374 error = transport_class_register(&fc_host_class);
41375 if (error)
41376diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
41377index de2f8c4..63c5278 100644
41378--- a/drivers/scsi/scsi_transport_iscsi.c
41379+++ b/drivers/scsi/scsi_transport_iscsi.c
41380@@ -81,7 +81,7 @@ struct iscsi_internal {
41381 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
41382 };
41383
41384-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
41385+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
41386 static struct workqueue_struct *iscsi_eh_timer_workq;
41387
41388 /*
41389@@ -728,7 +728,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
41390 int err;
41391
41392 ihost = shost->shost_data;
41393- session->sid = atomic_add_return(1, &iscsi_session_nr);
41394+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
41395
41396 if (id == ISCSI_MAX_TARGET) {
41397 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
41398@@ -2060,7 +2060,7 @@ static __init int iscsi_transport_init(void)
41399 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
41400 ISCSI_TRANSPORT_VERSION);
41401
41402- atomic_set(&iscsi_session_nr, 0);
41403+ atomic_set_unchecked(&iscsi_session_nr, 0);
41404
41405 err = class_register(&iscsi_transport_class);
41406 if (err)
41407diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
41408index 21a045e..ec89e03 100644
41409--- a/drivers/scsi/scsi_transport_srp.c
41410+++ b/drivers/scsi/scsi_transport_srp.c
41411@@ -33,7 +33,7 @@
41412 #include "scsi_transport_srp_internal.h"
41413
41414 struct srp_host_attrs {
41415- atomic_t next_port_id;
41416+ atomic_unchecked_t next_port_id;
41417 };
41418 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
41419
41420@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
41421 struct Scsi_Host *shost = dev_to_shost(dev);
41422 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
41423
41424- atomic_set(&srp_host->next_port_id, 0);
41425+ atomic_set_unchecked(&srp_host->next_port_id, 0);
41426 return 0;
41427 }
41428
41429@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
41430 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
41431 rport->roles = ids->roles;
41432
41433- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
41434+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
41435 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
41436
41437 transport_setup_device(&rport->dev);
41438diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
41439index 040f751..98a5ed2 100644
41440--- a/drivers/scsi/sg.c
41441+++ b/drivers/scsi/sg.c
41442@@ -1064,7 +1064,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
41443 sdp->disk->disk_name,
41444 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
41445 NULL,
41446- (char *)arg);
41447+ (char __user *)arg);
41448 case BLKTRACESTART:
41449 return blk_trace_startstop(sdp->device->request_queue, 1);
41450 case BLKTRACESTOP:
41451@@ -2292,7 +2292,7 @@ struct sg_proc_leaf {
41452 const struct file_operations * fops;
41453 };
41454
41455-static struct sg_proc_leaf sg_proc_leaf_arr[] = {
41456+static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
41457 {"allow_dio", &adio_fops},
41458 {"debug", &debug_fops},
41459 {"def_reserved_size", &dressz_fops},
41460@@ -2307,7 +2307,7 @@ sg_proc_init(void)
41461 {
41462 int k, mask;
41463 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
41464- struct sg_proc_leaf * leaf;
41465+ const struct sg_proc_leaf * leaf;
41466
41467 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
41468 if (!sg_proc_sgp)
41469diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
41470index 45374d6..61ee484 100644
41471--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
41472+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
41473@@ -1754,6 +1754,8 @@ static int __devinit sym2_probe(struct pci_dev *pdev,
41474 int do_iounmap = 0;
41475 int do_disable_device = 1;
41476
41477+ pax_track_stack();
41478+
41479 memset(&sym_dev, 0, sizeof(sym_dev));
41480 memset(&nvram, 0, sizeof(nvram));
41481 sym_dev.pdev = pdev;
41482diff --git a/drivers/serial/kgdboc.c b/drivers/serial/kgdboc.c
41483index eadc1ab..2d81457 100644
41484--- a/drivers/serial/kgdboc.c
41485+++ b/drivers/serial/kgdboc.c
41486@@ -18,7 +18,7 @@
41487
41488 #define MAX_CONFIG_LEN 40
41489
41490-static struct kgdb_io kgdboc_io_ops;
41491+static const struct kgdb_io kgdboc_io_ops;
41492
41493 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
41494 static int configured = -1;
41495@@ -154,7 +154,7 @@ static void kgdboc_post_exp_handler(void)
41496 module_put(THIS_MODULE);
41497 }
41498
41499-static struct kgdb_io kgdboc_io_ops = {
41500+static const struct kgdb_io kgdboc_io_ops = {
41501 .name = "kgdboc",
41502 .read_char = kgdboc_get_char,
41503 .write_char = kgdboc_put_char,
41504diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
41505index b76f246..7f41af7 100644
41506--- a/drivers/spi/spi.c
41507+++ b/drivers/spi/spi.c
41508@@ -774,7 +774,7 @@ int spi_sync(struct spi_device *spi, struct spi_message *message)
41509 EXPORT_SYMBOL_GPL(spi_sync);
41510
41511 /* portable code must never pass more than 32 bytes */
41512-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
41513+#define SPI_BUFSIZ max(32U,SMP_CACHE_BYTES)
41514
41515 static u8 *buf;
41516
41517diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
41518index 99010d4..6bad87b 100644
41519--- a/drivers/staging/android/binder.c
41520+++ b/drivers/staging/android/binder.c
41521@@ -2756,7 +2756,7 @@ static void binder_vma_close(struct vm_area_struct *vma)
41522 binder_defer_work(proc, BINDER_DEFERRED_PUT_FILES);
41523 }
41524
41525-static struct vm_operations_struct binder_vm_ops = {
41526+static const struct vm_operations_struct binder_vm_ops = {
41527 .open = binder_vma_open,
41528 .close = binder_vma_close,
41529 };
41530diff --git a/drivers/staging/b3dfg/b3dfg.c b/drivers/staging/b3dfg/b3dfg.c
41531index cda26bb..39fed3f 100644
41532--- a/drivers/staging/b3dfg/b3dfg.c
41533+++ b/drivers/staging/b3dfg/b3dfg.c
41534@@ -455,7 +455,7 @@ static int b3dfg_vma_fault(struct vm_area_struct *vma,
41535 return VM_FAULT_NOPAGE;
41536 }
41537
41538-static struct vm_operations_struct b3dfg_vm_ops = {
41539+static const struct vm_operations_struct b3dfg_vm_ops = {
41540 .fault = b3dfg_vma_fault,
41541 };
41542
41543@@ -848,7 +848,7 @@ static int b3dfg_mmap(struct file *filp, struct vm_area_struct *vma)
41544 return r;
41545 }
41546
41547-static struct file_operations b3dfg_fops = {
41548+static const struct file_operations b3dfg_fops = {
41549 .owner = THIS_MODULE,
41550 .open = b3dfg_open,
41551 .release = b3dfg_release,
41552diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
41553index 908f25a..c9a579b 100644
41554--- a/drivers/staging/comedi/comedi_fops.c
41555+++ b/drivers/staging/comedi/comedi_fops.c
41556@@ -1389,7 +1389,7 @@ void comedi_unmap(struct vm_area_struct *area)
41557 mutex_unlock(&dev->mutex);
41558 }
41559
41560-static struct vm_operations_struct comedi_vm_ops = {
41561+static const struct vm_operations_struct comedi_vm_ops = {
41562 .close = comedi_unmap,
41563 };
41564
41565diff --git a/drivers/staging/dream/qdsp5/adsp_driver.c b/drivers/staging/dream/qdsp5/adsp_driver.c
41566index e55a0db..577b776 100644
41567--- a/drivers/staging/dream/qdsp5/adsp_driver.c
41568+++ b/drivers/staging/dream/qdsp5/adsp_driver.c
41569@@ -576,7 +576,7 @@ static struct adsp_device *inode_to_device(struct inode *inode)
41570 static dev_t adsp_devno;
41571 static struct class *adsp_class;
41572
41573-static struct file_operations adsp_fops = {
41574+static const struct file_operations adsp_fops = {
41575 .owner = THIS_MODULE,
41576 .open = adsp_open,
41577 .unlocked_ioctl = adsp_ioctl,
41578diff --git a/drivers/staging/dream/qdsp5/audio_aac.c b/drivers/staging/dream/qdsp5/audio_aac.c
41579index ad2390f..4116ee8 100644
41580--- a/drivers/staging/dream/qdsp5/audio_aac.c
41581+++ b/drivers/staging/dream/qdsp5/audio_aac.c
41582@@ -1022,7 +1022,7 @@ done:
41583 return rc;
41584 }
41585
41586-static struct file_operations audio_aac_fops = {
41587+static const struct file_operations audio_aac_fops = {
41588 .owner = THIS_MODULE,
41589 .open = audio_open,
41590 .release = audio_release,
41591diff --git a/drivers/staging/dream/qdsp5/audio_amrnb.c b/drivers/staging/dream/qdsp5/audio_amrnb.c
41592index cd818a5..870b37b 100644
41593--- a/drivers/staging/dream/qdsp5/audio_amrnb.c
41594+++ b/drivers/staging/dream/qdsp5/audio_amrnb.c
41595@@ -833,7 +833,7 @@ done:
41596 return rc;
41597 }
41598
41599-static struct file_operations audio_amrnb_fops = {
41600+static const struct file_operations audio_amrnb_fops = {
41601 .owner = THIS_MODULE,
41602 .open = audamrnb_open,
41603 .release = audamrnb_release,
41604diff --git a/drivers/staging/dream/qdsp5/audio_evrc.c b/drivers/staging/dream/qdsp5/audio_evrc.c
41605index 4b43e18..cedafda 100644
41606--- a/drivers/staging/dream/qdsp5/audio_evrc.c
41607+++ b/drivers/staging/dream/qdsp5/audio_evrc.c
41608@@ -805,7 +805,7 @@ dma_fail:
41609 return rc;
41610 }
41611
41612-static struct file_operations audio_evrc_fops = {
41613+static const struct file_operations audio_evrc_fops = {
41614 .owner = THIS_MODULE,
41615 .open = audevrc_open,
41616 .release = audevrc_release,
41617diff --git a/drivers/staging/dream/qdsp5/audio_in.c b/drivers/staging/dream/qdsp5/audio_in.c
41618index 3d950a2..9431118 100644
41619--- a/drivers/staging/dream/qdsp5/audio_in.c
41620+++ b/drivers/staging/dream/qdsp5/audio_in.c
41621@@ -913,7 +913,7 @@ static int audpre_open(struct inode *inode, struct file *file)
41622 return 0;
41623 }
41624
41625-static struct file_operations audio_fops = {
41626+static const struct file_operations audio_fops = {
41627 .owner = THIS_MODULE,
41628 .open = audio_in_open,
41629 .release = audio_in_release,
41630@@ -922,7 +922,7 @@ static struct file_operations audio_fops = {
41631 .unlocked_ioctl = audio_in_ioctl,
41632 };
41633
41634-static struct file_operations audpre_fops = {
41635+static const struct file_operations audpre_fops = {
41636 .owner = THIS_MODULE,
41637 .open = audpre_open,
41638 .unlocked_ioctl = audpre_ioctl,
41639diff --git a/drivers/staging/dream/qdsp5/audio_mp3.c b/drivers/staging/dream/qdsp5/audio_mp3.c
41640index b95574f..286c2f4 100644
41641--- a/drivers/staging/dream/qdsp5/audio_mp3.c
41642+++ b/drivers/staging/dream/qdsp5/audio_mp3.c
41643@@ -941,7 +941,7 @@ done:
41644 return rc;
41645 }
41646
41647-static struct file_operations audio_mp3_fops = {
41648+static const struct file_operations audio_mp3_fops = {
41649 .owner = THIS_MODULE,
41650 .open = audio_open,
41651 .release = audio_release,
41652diff --git a/drivers/staging/dream/qdsp5/audio_out.c b/drivers/staging/dream/qdsp5/audio_out.c
41653index d1adcf6..f8f9833 100644
41654--- a/drivers/staging/dream/qdsp5/audio_out.c
41655+++ b/drivers/staging/dream/qdsp5/audio_out.c
41656@@ -810,7 +810,7 @@ static int audpp_open(struct inode *inode, struct file *file)
41657 return 0;
41658 }
41659
41660-static struct file_operations audio_fops = {
41661+static const struct file_operations audio_fops = {
41662 .owner = THIS_MODULE,
41663 .open = audio_open,
41664 .release = audio_release,
41665@@ -819,7 +819,7 @@ static struct file_operations audio_fops = {
41666 .unlocked_ioctl = audio_ioctl,
41667 };
41668
41669-static struct file_operations audpp_fops = {
41670+static const struct file_operations audpp_fops = {
41671 .owner = THIS_MODULE,
41672 .open = audpp_open,
41673 .unlocked_ioctl = audpp_ioctl,
41674diff --git a/drivers/staging/dream/qdsp5/audio_qcelp.c b/drivers/staging/dream/qdsp5/audio_qcelp.c
41675index f0f50e3..f6b9dbc 100644
41676--- a/drivers/staging/dream/qdsp5/audio_qcelp.c
41677+++ b/drivers/staging/dream/qdsp5/audio_qcelp.c
41678@@ -816,7 +816,7 @@ err:
41679 return rc;
41680 }
41681
41682-static struct file_operations audio_qcelp_fops = {
41683+static const struct file_operations audio_qcelp_fops = {
41684 .owner = THIS_MODULE,
41685 .open = audqcelp_open,
41686 .release = audqcelp_release,
41687diff --git a/drivers/staging/dream/qdsp5/snd.c b/drivers/staging/dream/qdsp5/snd.c
41688index 037d7ff..5469ec3 100644
41689--- a/drivers/staging/dream/qdsp5/snd.c
41690+++ b/drivers/staging/dream/qdsp5/snd.c
41691@@ -242,7 +242,7 @@ err:
41692 return rc;
41693 }
41694
41695-static struct file_operations snd_fops = {
41696+static const struct file_operations snd_fops = {
41697 .owner = THIS_MODULE,
41698 .open = snd_open,
41699 .release = snd_release,
41700diff --git a/drivers/staging/dream/smd/smd_qmi.c b/drivers/staging/dream/smd/smd_qmi.c
41701index d4e7d88..0ea632a 100644
41702--- a/drivers/staging/dream/smd/smd_qmi.c
41703+++ b/drivers/staging/dream/smd/smd_qmi.c
41704@@ -793,7 +793,7 @@ static int qmi_release(struct inode *ip, struct file *fp)
41705 return 0;
41706 }
41707
41708-static struct file_operations qmi_fops = {
41709+static const struct file_operations qmi_fops = {
41710 .owner = THIS_MODULE,
41711 .read = qmi_read,
41712 .write = qmi_write,
41713diff --git a/drivers/staging/dream/smd/smd_rpcrouter_device.c b/drivers/staging/dream/smd/smd_rpcrouter_device.c
41714index cd3910b..ff053d3 100644
41715--- a/drivers/staging/dream/smd/smd_rpcrouter_device.c
41716+++ b/drivers/staging/dream/smd/smd_rpcrouter_device.c
41717@@ -214,7 +214,7 @@ static long rpcrouter_ioctl(struct file *filp, unsigned int cmd,
41718 return rc;
41719 }
41720
41721-static struct file_operations rpcrouter_server_fops = {
41722+static const struct file_operations rpcrouter_server_fops = {
41723 .owner = THIS_MODULE,
41724 .open = rpcrouter_open,
41725 .release = rpcrouter_release,
41726@@ -224,7 +224,7 @@ static struct file_operations rpcrouter_server_fops = {
41727 .unlocked_ioctl = rpcrouter_ioctl,
41728 };
41729
41730-static struct file_operations rpcrouter_router_fops = {
41731+static const struct file_operations rpcrouter_router_fops = {
41732 .owner = THIS_MODULE,
41733 .open = rpcrouter_open,
41734 .release = rpcrouter_release,
41735diff --git a/drivers/staging/dst/dcore.c b/drivers/staging/dst/dcore.c
41736index c24e4e0..07665be 100644
41737--- a/drivers/staging/dst/dcore.c
41738+++ b/drivers/staging/dst/dcore.c
41739@@ -149,7 +149,7 @@ static int dst_bdev_release(struct gendisk *disk, fmode_t mode)
41740 return 0;
41741 }
41742
41743-static struct block_device_operations dst_blk_ops = {
41744+static const struct block_device_operations dst_blk_ops = {
41745 .open = dst_bdev_open,
41746 .release = dst_bdev_release,
41747 .owner = THIS_MODULE,
41748@@ -588,7 +588,7 @@ static struct dst_node *dst_alloc_node(struct dst_ctl *ctl,
41749 n->size = ctl->size;
41750
41751 atomic_set(&n->refcnt, 1);
41752- atomic_long_set(&n->gen, 0);
41753+ atomic_long_set_unchecked(&n->gen, 0);
41754 snprintf(n->name, sizeof(n->name), "%s", ctl->name);
41755
41756 err = dst_node_sysfs_init(n);
41757diff --git a/drivers/staging/dst/trans.c b/drivers/staging/dst/trans.c
41758index 557d372..8d84422 100644
41759--- a/drivers/staging/dst/trans.c
41760+++ b/drivers/staging/dst/trans.c
41761@@ -169,7 +169,7 @@ int dst_process_bio(struct dst_node *n, struct bio *bio)
41762 t->error = 0;
41763 t->retries = 0;
41764 atomic_set(&t->refcnt, 1);
41765- t->gen = atomic_long_inc_return(&n->gen);
41766+ t->gen = atomic_long_inc_return_unchecked(&n->gen);
41767
41768 t->enc = bio_data_dir(bio);
41769 dst_bio_to_cmd(bio, &t->cmd, DST_IO, t->gen);
41770diff --git a/drivers/staging/et131x/et1310_tx.c b/drivers/staging/et131x/et1310_tx.c
41771index 94f7752..d051514 100644
41772--- a/drivers/staging/et131x/et1310_tx.c
41773+++ b/drivers/staging/et131x/et1310_tx.c
41774@@ -710,11 +710,11 @@ inline void et131x_free_send_packet(struct et131x_adapter *etdev,
41775 struct net_device_stats *stats = &etdev->net_stats;
41776
41777 if (pMpTcb->Flags & fMP_DEST_BROAD)
41778- atomic_inc(&etdev->Stats.brdcstxmt);
41779+ atomic_inc_unchecked(&etdev->Stats.brdcstxmt);
41780 else if (pMpTcb->Flags & fMP_DEST_MULTI)
41781- atomic_inc(&etdev->Stats.multixmt);
41782+ atomic_inc_unchecked(&etdev->Stats.multixmt);
41783 else
41784- atomic_inc(&etdev->Stats.unixmt);
41785+ atomic_inc_unchecked(&etdev->Stats.unixmt);
41786
41787 if (pMpTcb->Packet) {
41788 stats->tx_bytes += pMpTcb->Packet->len;
41789diff --git a/drivers/staging/et131x/et131x_adapter.h b/drivers/staging/et131x/et131x_adapter.h
41790index 1dfe06f..f469b4d 100644
41791--- a/drivers/staging/et131x/et131x_adapter.h
41792+++ b/drivers/staging/et131x/et131x_adapter.h
41793@@ -145,11 +145,11 @@ typedef struct _ce_stats_t {
41794 * operations
41795 */
41796 u32 unircv; /* # multicast packets received */
41797- atomic_t unixmt; /* # multicast packets for Tx */
41798+ atomic_unchecked_t unixmt; /* # multicast packets for Tx */
41799 u32 multircv; /* # multicast packets received */
41800- atomic_t multixmt; /* # multicast packets for Tx */
41801+ atomic_unchecked_t multixmt; /* # multicast packets for Tx */
41802 u32 brdcstrcv; /* # broadcast packets received */
41803- atomic_t brdcstxmt; /* # broadcast packets for Tx */
41804+ atomic_unchecked_t brdcstxmt; /* # broadcast packets for Tx */
41805 u32 norcvbuf; /* # Rx packets discarded */
41806 u32 noxmtbuf; /* # Tx packets discarded */
41807
41808diff --git a/drivers/staging/go7007/go7007-v4l2.c b/drivers/staging/go7007/go7007-v4l2.c
41809index 4bd353a..e28f455 100644
41810--- a/drivers/staging/go7007/go7007-v4l2.c
41811+++ b/drivers/staging/go7007/go7007-v4l2.c
41812@@ -1700,7 +1700,7 @@ static int go7007_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41813 return 0;
41814 }
41815
41816-static struct vm_operations_struct go7007_vm_ops = {
41817+static const struct vm_operations_struct go7007_vm_ops = {
41818 .open = go7007_vm_open,
41819 .close = go7007_vm_close,
41820 .fault = go7007_vm_fault,
41821diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c
41822index 366dc95..b974d87 100644
41823--- a/drivers/staging/hv/Channel.c
41824+++ b/drivers/staging/hv/Channel.c
41825@@ -464,8 +464,8 @@ int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, void *Kbuffer,
41826
41827 DPRINT_ENTER(VMBUS);
41828
41829- nextGpadlHandle = atomic_read(&gVmbusConnection.NextGpadlHandle);
41830- atomic_inc(&gVmbusConnection.NextGpadlHandle);
41831+ nextGpadlHandle = atomic_read_unchecked(&gVmbusConnection.NextGpadlHandle);
41832+ atomic_inc_unchecked(&gVmbusConnection.NextGpadlHandle);
41833
41834 VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
41835 ASSERT(msgInfo != NULL);
41836diff --git a/drivers/staging/hv/Hv.c b/drivers/staging/hv/Hv.c
41837index b12237f..01ae28a 100644
41838--- a/drivers/staging/hv/Hv.c
41839+++ b/drivers/staging/hv/Hv.c
41840@@ -161,7 +161,7 @@ static u64 HvDoHypercall(u64 Control, void *Input, void *Output)
41841 u64 outputAddress = (Output) ? virt_to_phys(Output) : 0;
41842 u32 outputAddressHi = outputAddress >> 32;
41843 u32 outputAddressLo = outputAddress & 0xFFFFFFFF;
41844- volatile void *hypercallPage = gHvContext.HypercallPage;
41845+ volatile void *hypercallPage = ktva_ktla(gHvContext.HypercallPage);
41846
41847 DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>",
41848 Control, Input, Output);
41849diff --git a/drivers/staging/hv/VmbusApi.h b/drivers/staging/hv/VmbusApi.h
41850index d089bb1..2ebc158 100644
41851--- a/drivers/staging/hv/VmbusApi.h
41852+++ b/drivers/staging/hv/VmbusApi.h
41853@@ -109,7 +109,7 @@ struct vmbus_channel_interface {
41854 u32 *GpadlHandle);
41855 int (*TeardownGpadl)(struct hv_device *device, u32 GpadlHandle);
41856 void (*GetInfo)(struct hv_device *dev, struct hv_device_info *devinfo);
41857-};
41858+} __no_const;
41859
41860 /* Base driver object */
41861 struct hv_driver {
41862diff --git a/drivers/staging/hv/VmbusPrivate.h b/drivers/staging/hv/VmbusPrivate.h
41863index 5a37cce..6ecc88c 100644
41864--- a/drivers/staging/hv/VmbusPrivate.h
41865+++ b/drivers/staging/hv/VmbusPrivate.h
41866@@ -59,7 +59,7 @@ enum VMBUS_CONNECT_STATE {
41867 struct VMBUS_CONNECTION {
41868 enum VMBUS_CONNECT_STATE ConnectState;
41869
41870- atomic_t NextGpadlHandle;
41871+ atomic_unchecked_t NextGpadlHandle;
41872
41873 /*
41874 * Represents channel interrupts. Each bit position represents a
41875diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c
41876index 871a202..ca50ddf 100644
41877--- a/drivers/staging/hv/blkvsc_drv.c
41878+++ b/drivers/staging/hv/blkvsc_drv.c
41879@@ -153,7 +153,7 @@ static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE;
41880 /* The one and only one */
41881 static struct blkvsc_driver_context g_blkvsc_drv;
41882
41883-static struct block_device_operations block_ops = {
41884+static const struct block_device_operations block_ops = {
41885 .owner = THIS_MODULE,
41886 .open = blkvsc_open,
41887 .release = blkvsc_release,
41888diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c
41889index 6acc49a..fbc8d46 100644
41890--- a/drivers/staging/hv/vmbus_drv.c
41891+++ b/drivers/staging/hv/vmbus_drv.c
41892@@ -532,7 +532,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
41893 to_device_context(root_device_obj);
41894 struct device_context *child_device_ctx =
41895 to_device_context(child_device_obj);
41896- static atomic_t device_num = ATOMIC_INIT(0);
41897+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41898
41899 DPRINT_ENTER(VMBUS_DRV);
41900
41901@@ -541,7 +541,7 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj,
41902
41903 /* Set the device name. Otherwise, device_register() will fail. */
41904 dev_set_name(&child_device_ctx->device, "vmbus_0_%d",
41905- atomic_inc_return(&device_num));
41906+ atomic_inc_return_unchecked(&device_num));
41907
41908 /* The new device belongs to this bus */
41909 child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */
41910diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h
41911index d926189..17b19fd 100644
41912--- a/drivers/staging/iio/ring_generic.h
41913+++ b/drivers/staging/iio/ring_generic.h
41914@@ -87,7 +87,7 @@ struct iio_ring_access_funcs {
41915
41916 int (*is_enabled)(struct iio_ring_buffer *ring);
41917 int (*enable)(struct iio_ring_buffer *ring);
41918-};
41919+} __no_const;
41920
41921 /**
41922 * struct iio_ring_buffer - general ring buffer structure
41923diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
41924index 1b237b7..88c624e 100644
41925--- a/drivers/staging/octeon/ethernet-rx.c
41926+++ b/drivers/staging/octeon/ethernet-rx.c
41927@@ -406,11 +406,11 @@ void cvm_oct_tasklet_rx(unsigned long unused)
41928 /* Increment RX stats for virtual ports */
41929 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
41930 #ifdef CONFIG_64BIT
41931- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
41932- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
41933+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
41934+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
41935 #else
41936- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
41937- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
41938+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
41939+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
41940 #endif
41941 }
41942 netif_receive_skb(skb);
41943@@ -424,9 +424,9 @@ void cvm_oct_tasklet_rx(unsigned long unused)
41944 dev->name);
41945 */
41946 #ifdef CONFIG_64BIT
41947- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
41948+ atomic64_add_unchecked(1, (atomic64_t *)&priv->stats.rx_dropped);
41949 #else
41950- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
41951+ atomic_add_unchecked(1, (atomic_t *)&priv->stats.rx_dropped);
41952 #endif
41953 dev_kfree_skb_irq(skb);
41954 }
41955diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
41956index 492c502..d9909f1 100644
41957--- a/drivers/staging/octeon/ethernet.c
41958+++ b/drivers/staging/octeon/ethernet.c
41959@@ -294,11 +294,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
41960 * since the RX tasklet also increments it.
41961 */
41962 #ifdef CONFIG_64BIT
41963- atomic64_add(rx_status.dropped_packets,
41964- (atomic64_t *)&priv->stats.rx_dropped);
41965+ atomic64_add_unchecked(rx_status.dropped_packets,
41966+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41967 #else
41968- atomic_add(rx_status.dropped_packets,
41969- (atomic_t *)&priv->stats.rx_dropped);
41970+ atomic_add_unchecked(rx_status.dropped_packets,
41971+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
41972 #endif
41973 }
41974
41975diff --git a/drivers/staging/otus/80211core/pub_zfi.h b/drivers/staging/otus/80211core/pub_zfi.h
41976index a35bd5d..28fff45 100644
41977--- a/drivers/staging/otus/80211core/pub_zfi.h
41978+++ b/drivers/staging/otus/80211core/pub_zfi.h
41979@@ -531,7 +531,7 @@ struct zsCbFuncTbl
41980 u8_t (*zfcbClassifyTxPacket)(zdev_t* dev, zbuf_t* buf);
41981
41982 void (*zfcbHwWatchDogNotify)(zdev_t* dev);
41983-};
41984+} __no_const;
41985
41986 extern void zfZeroMemory(u8_t* va, u16_t length);
41987 #define ZM_INIT_CB_FUNC_TABLE(p) zfZeroMemory((u8_t *)p, sizeof(struct zsCbFuncTbl));
41988diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c
41989index c39a25f..696f5aa 100644
41990--- a/drivers/staging/panel/panel.c
41991+++ b/drivers/staging/panel/panel.c
41992@@ -1305,7 +1305,7 @@ static int lcd_release(struct inode *inode, struct file *file)
41993 return 0;
41994 }
41995
41996-static struct file_operations lcd_fops = {
41997+static const struct file_operations lcd_fops = {
41998 .write = lcd_write,
41999 .open = lcd_open,
42000 .release = lcd_release,
42001@@ -1565,7 +1565,7 @@ static int keypad_release(struct inode *inode, struct file *file)
42002 return 0;
42003 }
42004
42005-static struct file_operations keypad_fops = {
42006+static const struct file_operations keypad_fops = {
42007 .read = keypad_read, /* read */
42008 .open = keypad_open, /* open */
42009 .release = keypad_release, /* close */
42010diff --git a/drivers/staging/phison/phison.c b/drivers/staging/phison/phison.c
42011index 270ebcb..37e46af 100644
42012--- a/drivers/staging/phison/phison.c
42013+++ b/drivers/staging/phison/phison.c
42014@@ -43,7 +43,7 @@ static struct scsi_host_template phison_sht = {
42015 ATA_BMDMA_SHT(DRV_NAME),
42016 };
42017
42018-static struct ata_port_operations phison_ops = {
42019+static const struct ata_port_operations phison_ops = {
42020 .inherits = &ata_bmdma_port_ops,
42021 .prereset = phison_pre_reset,
42022 };
42023diff --git a/drivers/staging/poch/poch.c b/drivers/staging/poch/poch.c
42024index 2eb8e3d..57616a7 100644
42025--- a/drivers/staging/poch/poch.c
42026+++ b/drivers/staging/poch/poch.c
42027@@ -1057,7 +1057,7 @@ static int poch_ioctl(struct inode *inode, struct file *filp,
42028 return 0;
42029 }
42030
42031-static struct file_operations poch_fops = {
42032+static const struct file_operations poch_fops = {
42033 .owner = THIS_MODULE,
42034 .open = poch_open,
42035 .release = poch_release,
42036diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
42037index c94de31..19402bc 100644
42038--- a/drivers/staging/pohmelfs/inode.c
42039+++ b/drivers/staging/pohmelfs/inode.c
42040@@ -1850,7 +1850,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
42041 mutex_init(&psb->mcache_lock);
42042 psb->mcache_root = RB_ROOT;
42043 psb->mcache_timeout = msecs_to_jiffies(5000);
42044- atomic_long_set(&psb->mcache_gen, 0);
42045+ atomic_long_set_unchecked(&psb->mcache_gen, 0);
42046
42047 psb->trans_max_pages = 100;
42048
42049@@ -1865,7 +1865,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
42050 INIT_LIST_HEAD(&psb->crypto_ready_list);
42051 INIT_LIST_HEAD(&psb->crypto_active_list);
42052
42053- atomic_set(&psb->trans_gen, 1);
42054+ atomic_set_unchecked(&psb->trans_gen, 1);
42055 atomic_long_set(&psb->total_inodes, 0);
42056
42057 mutex_init(&psb->state_lock);
42058diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
42059index e22665c..a2a9390 100644
42060--- a/drivers/staging/pohmelfs/mcache.c
42061+++ b/drivers/staging/pohmelfs/mcache.c
42062@@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
42063 m->data = data;
42064 m->start = start;
42065 m->size = size;
42066- m->gen = atomic_long_inc_return(&psb->mcache_gen);
42067+ m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
42068
42069 mutex_lock(&psb->mcache_lock);
42070 err = pohmelfs_mcache_insert(psb, m);
42071diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
42072index 623a07d..4035c19 100644
42073--- a/drivers/staging/pohmelfs/netfs.h
42074+++ b/drivers/staging/pohmelfs/netfs.h
42075@@ -570,14 +570,14 @@ struct pohmelfs_config;
42076 struct pohmelfs_sb {
42077 struct rb_root mcache_root;
42078 struct mutex mcache_lock;
42079- atomic_long_t mcache_gen;
42080+ atomic_long_unchecked_t mcache_gen;
42081 unsigned long mcache_timeout;
42082
42083 unsigned int idx;
42084
42085 unsigned int trans_retries;
42086
42087- atomic_t trans_gen;
42088+ atomic_unchecked_t trans_gen;
42089
42090 unsigned int crypto_attached_size;
42091 unsigned int crypto_align_size;
42092diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
42093index 36a2535..0591bf4 100644
42094--- a/drivers/staging/pohmelfs/trans.c
42095+++ b/drivers/staging/pohmelfs/trans.c
42096@@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
42097 int err;
42098 struct netfs_cmd *cmd = t->iovec.iov_base;
42099
42100- t->gen = atomic_inc_return(&psb->trans_gen);
42101+ t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
42102
42103 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
42104 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
42105diff --git a/drivers/staging/sep/sep_driver.c b/drivers/staging/sep/sep_driver.c
42106index f890a16..509ece8 100644
42107--- a/drivers/staging/sep/sep_driver.c
42108+++ b/drivers/staging/sep/sep_driver.c
42109@@ -2603,7 +2603,7 @@ static struct pci_driver sep_pci_driver = {
42110 static dev_t sep_devno;
42111
42112 /* the files operations structure of the driver */
42113-static struct file_operations sep_file_operations = {
42114+static const struct file_operations sep_file_operations = {
42115 .owner = THIS_MODULE,
42116 .ioctl = sep_ioctl,
42117 .poll = sep_poll,
42118diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
42119index 5e16bc3..7655b10 100644
42120--- a/drivers/staging/usbip/usbip_common.h
42121+++ b/drivers/staging/usbip/usbip_common.h
42122@@ -374,7 +374,7 @@ struct usbip_device {
42123 void (*shutdown)(struct usbip_device *);
42124 void (*reset)(struct usbip_device *);
42125 void (*unusable)(struct usbip_device *);
42126- } eh_ops;
42127+ } __no_const eh_ops;
42128 };
42129
42130
42131diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42132index 57f7946..d9df23d 100644
42133--- a/drivers/staging/usbip/vhci.h
42134+++ b/drivers/staging/usbip/vhci.h
42135@@ -92,7 +92,7 @@ struct vhci_hcd {
42136 unsigned resuming:1;
42137 unsigned long re_timeout;
42138
42139- atomic_t seqnum;
42140+ atomic_unchecked_t seqnum;
42141
42142 /*
42143 * NOTE:
42144diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42145index 20cd7db..c2693ff 100644
42146--- a/drivers/staging/usbip/vhci_hcd.c
42147+++ b/drivers/staging/usbip/vhci_hcd.c
42148@@ -534,7 +534,7 @@ static void vhci_tx_urb(struct urb *urb)
42149 return;
42150 }
42151
42152- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42153+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42154 if (priv->seqnum == 0xffff)
42155 usbip_uinfo("seqnum max\n");
42156
42157@@ -793,7 +793,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42158 return -ENOMEM;
42159 }
42160
42161- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42162+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42163 if (unlink->seqnum == 0xffff)
42164 usbip_uinfo("seqnum max\n");
42165
42166@@ -988,7 +988,7 @@ static int vhci_start(struct usb_hcd *hcd)
42167 vdev->rhport = rhport;
42168 }
42169
42170- atomic_set(&vhci->seqnum, 0);
42171+ atomic_set_unchecked(&vhci->seqnum, 0);
42172 spin_lock_init(&vhci->lock);
42173
42174
42175diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42176index 7fd76fe..673695a 100644
42177--- a/drivers/staging/usbip/vhci_rx.c
42178+++ b/drivers/staging/usbip/vhci_rx.c
42179@@ -79,7 +79,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42180 usbip_uerr("cannot find a urb of seqnum %u\n",
42181 pdu->base.seqnum);
42182 usbip_uinfo("max seqnum %d\n",
42183- atomic_read(&the_controller->seqnum));
42184+ atomic_read_unchecked(&the_controller->seqnum));
42185 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42186 return;
42187 }
42188diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
42189index 7891288..8e31300 100644
42190--- a/drivers/staging/vme/devices/vme_user.c
42191+++ b/drivers/staging/vme/devices/vme_user.c
42192@@ -136,7 +136,7 @@ static int vme_user_ioctl(struct inode *, struct file *, unsigned int,
42193 static int __init vme_user_probe(struct device *, int, int);
42194 static int __exit vme_user_remove(struct device *, int, int);
42195
42196-static struct file_operations vme_user_fops = {
42197+static const struct file_operations vme_user_fops = {
42198 .open = vme_user_open,
42199 .release = vme_user_release,
42200 .read = vme_user_read,
42201diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42202index 58abf44..00c1fc8 100644
42203--- a/drivers/staging/vt6655/hostap.c
42204+++ b/drivers/staging/vt6655/hostap.c
42205@@ -84,7 +84,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42206 PSDevice apdev_priv;
42207 struct net_device *dev = pDevice->dev;
42208 int ret;
42209- const struct net_device_ops apdev_netdev_ops = {
42210+ net_device_ops_no_const apdev_netdev_ops = {
42211 .ndo_start_xmit = pDevice->tx_80211,
42212 };
42213
42214diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42215index 0c8267a..db1f363 100644
42216--- a/drivers/staging/vt6656/hostap.c
42217+++ b/drivers/staging/vt6656/hostap.c
42218@@ -86,7 +86,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42219 PSDevice apdev_priv;
42220 struct net_device *dev = pDevice->dev;
42221 int ret;
42222- const struct net_device_ops apdev_netdev_ops = {
42223+ net_device_ops_no_const apdev_netdev_ops = {
42224 .ndo_start_xmit = pDevice->tx_80211,
42225 };
42226
42227diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
42228index 925678b..da7f5ed 100644
42229--- a/drivers/staging/wlan-ng/hfa384x_usb.c
42230+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
42231@@ -205,7 +205,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
42232
42233 struct usbctlx_completor {
42234 int (*complete) (struct usbctlx_completor *);
42235-};
42236+} __no_const;
42237 typedef struct usbctlx_completor usbctlx_completor_t;
42238
42239 static int
42240diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
42241index 40de151..924f268 100644
42242--- a/drivers/telephony/ixj.c
42243+++ b/drivers/telephony/ixj.c
42244@@ -4976,6 +4976,8 @@ static int ixj_daa_cid_read(IXJ *j)
42245 bool mContinue;
42246 char *pIn, *pOut;
42247
42248+ pax_track_stack();
42249+
42250 if (!SCI_Prepare(j))
42251 return 0;
42252
42253diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
42254index e941367..b631f5a 100644
42255--- a/drivers/uio/uio.c
42256+++ b/drivers/uio/uio.c
42257@@ -23,6 +23,7 @@
42258 #include <linux/string.h>
42259 #include <linux/kobject.h>
42260 #include <linux/uio_driver.h>
42261+#include <asm/local.h>
42262
42263 #define UIO_MAX_DEVICES 255
42264
42265@@ -30,10 +31,10 @@ struct uio_device {
42266 struct module *owner;
42267 struct device *dev;
42268 int minor;
42269- atomic_t event;
42270+ atomic_unchecked_t event;
42271 struct fasync_struct *async_queue;
42272 wait_queue_head_t wait;
42273- int vma_count;
42274+ local_t vma_count;
42275 struct uio_info *info;
42276 struct kobject *map_dir;
42277 struct kobject *portio_dir;
42278@@ -129,7 +130,7 @@ static ssize_t map_type_show(struct kobject *kobj, struct attribute *attr,
42279 return entry->show(mem, buf);
42280 }
42281
42282-static struct sysfs_ops map_sysfs_ops = {
42283+static const struct sysfs_ops map_sysfs_ops = {
42284 .show = map_type_show,
42285 };
42286
42287@@ -217,7 +218,7 @@ static ssize_t portio_type_show(struct kobject *kobj, struct attribute *attr,
42288 return entry->show(port, buf);
42289 }
42290
42291-static struct sysfs_ops portio_sysfs_ops = {
42292+static const struct sysfs_ops portio_sysfs_ops = {
42293 .show = portio_type_show,
42294 };
42295
42296@@ -255,7 +256,7 @@ static ssize_t show_event(struct device *dev,
42297 struct uio_device *idev = dev_get_drvdata(dev);
42298 if (idev)
42299 return sprintf(buf, "%u\n",
42300- (unsigned int)atomic_read(&idev->event));
42301+ (unsigned int)atomic_read_unchecked(&idev->event));
42302 else
42303 return -ENODEV;
42304 }
42305@@ -424,7 +425,7 @@ void uio_event_notify(struct uio_info *info)
42306 {
42307 struct uio_device *idev = info->uio_dev;
42308
42309- atomic_inc(&idev->event);
42310+ atomic_inc_unchecked(&idev->event);
42311 wake_up_interruptible(&idev->wait);
42312 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
42313 }
42314@@ -477,7 +478,7 @@ static int uio_open(struct inode *inode, struct file *filep)
42315 }
42316
42317 listener->dev = idev;
42318- listener->event_count = atomic_read(&idev->event);
42319+ listener->event_count = atomic_read_unchecked(&idev->event);
42320 filep->private_data = listener;
42321
42322 if (idev->info->open) {
42323@@ -528,7 +529,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
42324 return -EIO;
42325
42326 poll_wait(filep, &idev->wait, wait);
42327- if (listener->event_count != atomic_read(&idev->event))
42328+ if (listener->event_count != atomic_read_unchecked(&idev->event))
42329 return POLLIN | POLLRDNORM;
42330 return 0;
42331 }
42332@@ -553,7 +554,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
42333 do {
42334 set_current_state(TASK_INTERRUPTIBLE);
42335
42336- event_count = atomic_read(&idev->event);
42337+ event_count = atomic_read_unchecked(&idev->event);
42338 if (event_count != listener->event_count) {
42339 if (copy_to_user(buf, &event_count, count))
42340 retval = -EFAULT;
42341@@ -624,13 +625,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
42342 static void uio_vma_open(struct vm_area_struct *vma)
42343 {
42344 struct uio_device *idev = vma->vm_private_data;
42345- idev->vma_count++;
42346+ local_inc(&idev->vma_count);
42347 }
42348
42349 static void uio_vma_close(struct vm_area_struct *vma)
42350 {
42351 struct uio_device *idev = vma->vm_private_data;
42352- idev->vma_count--;
42353+ local_dec(&idev->vma_count);
42354 }
42355
42356 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42357@@ -840,7 +841,7 @@ int __uio_register_device(struct module *owner,
42358 idev->owner = owner;
42359 idev->info = info;
42360 init_waitqueue_head(&idev->wait);
42361- atomic_set(&idev->event, 0);
42362+ atomic_set_unchecked(&idev->event, 0);
42363
42364 ret = uio_get_minor(idev);
42365 if (ret)
42366diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
42367index fbea856..06efea6 100644
42368--- a/drivers/usb/atm/usbatm.c
42369+++ b/drivers/usb/atm/usbatm.c
42370@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42371 if (printk_ratelimit())
42372 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
42373 __func__, vpi, vci);
42374- atomic_inc(&vcc->stats->rx_err);
42375+ atomic_inc_unchecked(&vcc->stats->rx_err);
42376 return;
42377 }
42378
42379@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42380 if (length > ATM_MAX_AAL5_PDU) {
42381 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
42382 __func__, length, vcc);
42383- atomic_inc(&vcc->stats->rx_err);
42384+ atomic_inc_unchecked(&vcc->stats->rx_err);
42385 goto out;
42386 }
42387
42388@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42389 if (sarb->len < pdu_length) {
42390 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
42391 __func__, pdu_length, sarb->len, vcc);
42392- atomic_inc(&vcc->stats->rx_err);
42393+ atomic_inc_unchecked(&vcc->stats->rx_err);
42394 goto out;
42395 }
42396
42397 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
42398 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
42399 __func__, vcc);
42400- atomic_inc(&vcc->stats->rx_err);
42401+ atomic_inc_unchecked(&vcc->stats->rx_err);
42402 goto out;
42403 }
42404
42405@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42406 if (printk_ratelimit())
42407 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
42408 __func__, length);
42409- atomic_inc(&vcc->stats->rx_drop);
42410+ atomic_inc_unchecked(&vcc->stats->rx_drop);
42411 goto out;
42412 }
42413
42414@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
42415
42416 vcc->push(vcc, skb);
42417
42418- atomic_inc(&vcc->stats->rx);
42419+ atomic_inc_unchecked(&vcc->stats->rx);
42420 out:
42421 skb_trim(sarb, 0);
42422 }
42423@@ -616,7 +616,7 @@ static void usbatm_tx_process(unsigned long data)
42424 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
42425
42426 usbatm_pop(vcc, skb);
42427- atomic_inc(&vcc->stats->tx);
42428+ atomic_inc_unchecked(&vcc->stats->tx);
42429
42430 skb = skb_dequeue(&instance->sndqueue);
42431 }
42432@@ -775,11 +775,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
42433 if (!left--)
42434 return sprintf(page,
42435 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
42436- atomic_read(&atm_dev->stats.aal5.tx),
42437- atomic_read(&atm_dev->stats.aal5.tx_err),
42438- atomic_read(&atm_dev->stats.aal5.rx),
42439- atomic_read(&atm_dev->stats.aal5.rx_err),
42440- atomic_read(&atm_dev->stats.aal5.rx_drop));
42441+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
42442+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
42443+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
42444+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
42445+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
42446
42447 if (!left--) {
42448 if (instance->disconnected)
42449diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
42450index 3e564bf..949b448 100644
42451--- a/drivers/usb/class/cdc-wdm.c
42452+++ b/drivers/usb/class/cdc-wdm.c
42453@@ -314,7 +314,7 @@ static ssize_t wdm_write
42454 if (r < 0)
42455 goto outnp;
42456
42457- if (!file->f_flags && O_NONBLOCK)
42458+ if (!(file->f_flags & O_NONBLOCK))
42459 r = wait_event_interruptible(desc->wait, !test_bit(WDM_IN_USE,
42460 &desc->flags));
42461 else
42462diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
42463index 24e6205..fe5a5d4 100644
42464--- a/drivers/usb/core/hcd.c
42465+++ b/drivers/usb/core/hcd.c
42466@@ -2216,7 +2216,7 @@ EXPORT_SYMBOL_GPL(usb_hcd_platform_shutdown);
42467
42468 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42469
42470-struct usb_mon_operations *mon_ops;
42471+const struct usb_mon_operations *mon_ops;
42472
42473 /*
42474 * The registration is unlocked.
42475@@ -2226,7 +2226,7 @@ struct usb_mon_operations *mon_ops;
42476 * symbols from usbcore, usbcore gets referenced and cannot be unloaded first.
42477 */
42478
42479-int usb_mon_register (struct usb_mon_operations *ops)
42480+int usb_mon_register (const struct usb_mon_operations *ops)
42481 {
42482
42483 if (mon_ops)
42484diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
42485index bcbe104..9cfd1c6 100644
42486--- a/drivers/usb/core/hcd.h
42487+++ b/drivers/usb/core/hcd.h
42488@@ -486,13 +486,13 @@ static inline void usbfs_cleanup(void) { }
42489 #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)
42490
42491 struct usb_mon_operations {
42492- void (*urb_submit)(struct usb_bus *bus, struct urb *urb);
42493- void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
42494- void (*urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
42495+ void (* const urb_submit)(struct usb_bus *bus, struct urb *urb);
42496+ void (* const urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err);
42497+ void (* const urb_complete)(struct usb_bus *bus, struct urb *urb, int status);
42498 /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */
42499 };
42500
42501-extern struct usb_mon_operations *mon_ops;
42502+extern const struct usb_mon_operations *mon_ops;
42503
42504 static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb)
42505 {
42506@@ -514,7 +514,7 @@ static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb,
42507 (*mon_ops->urb_complete)(bus, urb, status);
42508 }
42509
42510-int usb_mon_register(struct usb_mon_operations *ops);
42511+int usb_mon_register(const struct usb_mon_operations *ops);
42512 void usb_mon_deregister(void);
42513
42514 #else
42515diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
42516index 409cc94..a673bad 100644
42517--- a/drivers/usb/core/message.c
42518+++ b/drivers/usb/core/message.c
42519@@ -914,8 +914,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
42520 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
42521 if (buf) {
42522 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
42523- if (len > 0) {
42524- smallbuf = kmalloc(++len, GFP_NOIO);
42525+ if (len++ > 0) {
42526+ smallbuf = kmalloc(len, GFP_NOIO);
42527 if (!smallbuf)
42528 return buf;
42529 memcpy(smallbuf, buf, len);
42530diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
42531index 62ff5e7..530b74e 100644
42532--- a/drivers/usb/misc/appledisplay.c
42533+++ b/drivers/usb/misc/appledisplay.c
42534@@ -178,7 +178,7 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd)
42535 return pdata->msgdata[1];
42536 }
42537
42538-static struct backlight_ops appledisplay_bl_data = {
42539+static const struct backlight_ops appledisplay_bl_data = {
42540 .get_brightness = appledisplay_bl_get_brightness,
42541 .update_status = appledisplay_bl_update_status,
42542 };
42543diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
42544index e0c2db3..bd8cb66 100644
42545--- a/drivers/usb/mon/mon_main.c
42546+++ b/drivers/usb/mon/mon_main.c
42547@@ -238,7 +238,7 @@ static struct notifier_block mon_nb = {
42548 /*
42549 * Ops
42550 */
42551-static struct usb_mon_operations mon_ops_0 = {
42552+static const struct usb_mon_operations mon_ops_0 = {
42553 .urb_submit = mon_submit,
42554 .urb_submit_error = mon_submit_error,
42555 .urb_complete = mon_complete,
42556diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
42557index d6bea3e..60b250e 100644
42558--- a/drivers/usb/wusbcore/wa-hc.h
42559+++ b/drivers/usb/wusbcore/wa-hc.h
42560@@ -192,7 +192,7 @@ struct wahc {
42561 struct list_head xfer_delayed_list;
42562 spinlock_t xfer_list_lock;
42563 struct work_struct xfer_work;
42564- atomic_t xfer_id_count;
42565+ atomic_unchecked_t xfer_id_count;
42566 };
42567
42568
42569@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
42570 INIT_LIST_HEAD(&wa->xfer_delayed_list);
42571 spin_lock_init(&wa->xfer_list_lock);
42572 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
42573- atomic_set(&wa->xfer_id_count, 1);
42574+ atomic_set_unchecked(&wa->xfer_id_count, 1);
42575 }
42576
42577 /**
42578diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
42579index 613a5fc..3174865 100644
42580--- a/drivers/usb/wusbcore/wa-xfer.c
42581+++ b/drivers/usb/wusbcore/wa-xfer.c
42582@@ -293,7 +293,7 @@ out:
42583 */
42584 static void wa_xfer_id_init(struct wa_xfer *xfer)
42585 {
42586- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
42587+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
42588 }
42589
42590 /*
42591diff --git a/drivers/uwb/wlp/messages.c b/drivers/uwb/wlp/messages.c
42592index aa42fce..f8a828c 100644
42593--- a/drivers/uwb/wlp/messages.c
42594+++ b/drivers/uwb/wlp/messages.c
42595@@ -903,7 +903,7 @@ int wlp_parse_f0(struct wlp *wlp, struct sk_buff *skb)
42596 size_t len = skb->len;
42597 size_t used;
42598 ssize_t result;
42599- struct wlp_nonce enonce, rnonce;
42600+ struct wlp_nonce enonce = {{0}}, rnonce = {{0}};
42601 enum wlp_assc_error assc_err;
42602 char enonce_buf[WLP_WSS_NONCE_STRSIZE];
42603 char rnonce_buf[WLP_WSS_NONCE_STRSIZE];
42604diff --git a/drivers/uwb/wlp/sysfs.c b/drivers/uwb/wlp/sysfs.c
42605index 0370399..6627c94 100644
42606--- a/drivers/uwb/wlp/sysfs.c
42607+++ b/drivers/uwb/wlp/sysfs.c
42608@@ -615,8 +615,7 @@ ssize_t wlp_wss_attr_store(struct kobject *kobj, struct attribute *attr,
42609 return ret;
42610 }
42611
42612-static
42613-struct sysfs_ops wss_sysfs_ops = {
42614+static const struct sysfs_ops wss_sysfs_ops = {
42615 .show = wlp_wss_attr_show,
42616 .store = wlp_wss_attr_store,
42617 };
42618diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
42619index d5e8010..5687b56 100644
42620--- a/drivers/video/atmel_lcdfb.c
42621+++ b/drivers/video/atmel_lcdfb.c
42622@@ -110,7 +110,7 @@ static int atmel_bl_get_brightness(struct backlight_device *bl)
42623 return lcdc_readl(sinfo, ATMEL_LCDC_CONTRAST_VAL);
42624 }
42625
42626-static struct backlight_ops atmel_lcdc_bl_ops = {
42627+static const struct backlight_ops atmel_lcdc_bl_ops = {
42628 .update_status = atmel_bl_update_status,
42629 .get_brightness = atmel_bl_get_brightness,
42630 };
42631diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
42632index e4e4d43..66bcbcc 100644
42633--- a/drivers/video/aty/aty128fb.c
42634+++ b/drivers/video/aty/aty128fb.c
42635@@ -149,7 +149,7 @@ enum {
42636 };
42637
42638 /* Must match above enum */
42639-static const char *r128_family[] __devinitdata = {
42640+static const char *r128_family[] __devinitconst = {
42641 "AGP",
42642 "PCI",
42643 "PRO AGP",
42644@@ -1787,7 +1787,7 @@ static int aty128_bl_get_brightness(struct backlight_device *bd)
42645 return bd->props.brightness;
42646 }
42647
42648-static struct backlight_ops aty128_bl_data = {
42649+static const struct backlight_ops aty128_bl_data = {
42650 .get_brightness = aty128_bl_get_brightness,
42651 .update_status = aty128_bl_update_status,
42652 };
42653diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
42654index 913b4a4..9295a38 100644
42655--- a/drivers/video/aty/atyfb_base.c
42656+++ b/drivers/video/aty/atyfb_base.c
42657@@ -2225,7 +2225,7 @@ static int aty_bl_get_brightness(struct backlight_device *bd)
42658 return bd->props.brightness;
42659 }
42660
42661-static struct backlight_ops aty_bl_data = {
42662+static const struct backlight_ops aty_bl_data = {
42663 .get_brightness = aty_bl_get_brightness,
42664 .update_status = aty_bl_update_status,
42665 };
42666diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
42667index 1a056ad..221bd6a 100644
42668--- a/drivers/video/aty/radeon_backlight.c
42669+++ b/drivers/video/aty/radeon_backlight.c
42670@@ -127,7 +127,7 @@ static int radeon_bl_get_brightness(struct backlight_device *bd)
42671 return bd->props.brightness;
42672 }
42673
42674-static struct backlight_ops radeon_bl_data = {
42675+static const struct backlight_ops radeon_bl_data = {
42676 .get_brightness = radeon_bl_get_brightness,
42677 .update_status = radeon_bl_update_status,
42678 };
42679diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c
42680index ad05da5..3cb2cb9 100644
42681--- a/drivers/video/backlight/adp5520_bl.c
42682+++ b/drivers/video/backlight/adp5520_bl.c
42683@@ -84,7 +84,7 @@ static int adp5520_bl_get_brightness(struct backlight_device *bl)
42684 return error ? data->current_brightness : reg_val;
42685 }
42686
42687-static struct backlight_ops adp5520_bl_ops = {
42688+static const struct backlight_ops adp5520_bl_ops = {
42689 .update_status = adp5520_bl_update_status,
42690 .get_brightness = adp5520_bl_get_brightness,
42691 };
42692diff --git a/drivers/video/backlight/adx_bl.c b/drivers/video/backlight/adx_bl.c
42693index 2c3bdfc..d769b0b 100644
42694--- a/drivers/video/backlight/adx_bl.c
42695+++ b/drivers/video/backlight/adx_bl.c
42696@@ -61,7 +61,7 @@ static int adx_backlight_check_fb(struct fb_info *fb)
42697 return 1;
42698 }
42699
42700-static struct backlight_ops adx_backlight_ops = {
42701+static const struct backlight_ops adx_backlight_ops = {
42702 .options = 0,
42703 .update_status = adx_backlight_update_status,
42704 .get_brightness = adx_backlight_get_brightness,
42705diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
42706index 505c082..6b6b3cc 100644
42707--- a/drivers/video/backlight/atmel-pwm-bl.c
42708+++ b/drivers/video/backlight/atmel-pwm-bl.c
42709@@ -113,7 +113,7 @@ static int atmel_pwm_bl_init_pwm(struct atmel_pwm_bl *pwmbl)
42710 return pwm_channel_enable(&pwmbl->pwmc);
42711 }
42712
42713-static struct backlight_ops atmel_pwm_bl_ops = {
42714+static const struct backlight_ops atmel_pwm_bl_ops = {
42715 .get_brightness = atmel_pwm_bl_get_intensity,
42716 .update_status = atmel_pwm_bl_set_intensity,
42717 };
42718diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
42719index 5e20e6e..89025e6 100644
42720--- a/drivers/video/backlight/backlight.c
42721+++ b/drivers/video/backlight/backlight.c
42722@@ -269,7 +269,7 @@ EXPORT_SYMBOL(backlight_force_update);
42723 * ERR_PTR() or a pointer to the newly allocated device.
42724 */
42725 struct backlight_device *backlight_device_register(const char *name,
42726- struct device *parent, void *devdata, struct backlight_ops *ops)
42727+ struct device *parent, void *devdata, const struct backlight_ops *ops)
42728 {
42729 struct backlight_device *new_bd;
42730 int rc;
42731diff --git a/drivers/video/backlight/corgi_lcd.c b/drivers/video/backlight/corgi_lcd.c
42732index 9677494..b4bcf80 100644
42733--- a/drivers/video/backlight/corgi_lcd.c
42734+++ b/drivers/video/backlight/corgi_lcd.c
42735@@ -451,7 +451,7 @@ void corgi_lcd_limit_intensity(int limit)
42736 }
42737 EXPORT_SYMBOL(corgi_lcd_limit_intensity);
42738
42739-static struct backlight_ops corgi_bl_ops = {
42740+static const struct backlight_ops corgi_bl_ops = {
42741 .get_brightness = corgi_bl_get_intensity,
42742 .update_status = corgi_bl_update_status,
42743 };
42744diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c
42745index b9fe62b..2914bf1 100644
42746--- a/drivers/video/backlight/cr_bllcd.c
42747+++ b/drivers/video/backlight/cr_bllcd.c
42748@@ -108,7 +108,7 @@ static int cr_backlight_get_intensity(struct backlight_device *bd)
42749 return intensity;
42750 }
42751
42752-static struct backlight_ops cr_backlight_ops = {
42753+static const struct backlight_ops cr_backlight_ops = {
42754 .get_brightness = cr_backlight_get_intensity,
42755 .update_status = cr_backlight_set_intensity,
42756 };
42757diff --git a/drivers/video/backlight/da903x_bl.c b/drivers/video/backlight/da903x_bl.c
42758index 701a108..feacfd5 100644
42759--- a/drivers/video/backlight/da903x_bl.c
42760+++ b/drivers/video/backlight/da903x_bl.c
42761@@ -94,7 +94,7 @@ static int da903x_backlight_get_brightness(struct backlight_device *bl)
42762 return data->current_brightness;
42763 }
42764
42765-static struct backlight_ops da903x_backlight_ops = {
42766+static const struct backlight_ops da903x_backlight_ops = {
42767 .update_status = da903x_backlight_update_status,
42768 .get_brightness = da903x_backlight_get_brightness,
42769 };
42770diff --git a/drivers/video/backlight/generic_bl.c b/drivers/video/backlight/generic_bl.c
42771index 6d27f62..e6d348e 100644
42772--- a/drivers/video/backlight/generic_bl.c
42773+++ b/drivers/video/backlight/generic_bl.c
42774@@ -70,7 +70,7 @@ void corgibl_limit_intensity(int limit)
42775 }
42776 EXPORT_SYMBOL(corgibl_limit_intensity);
42777
42778-static struct backlight_ops genericbl_ops = {
42779+static const struct backlight_ops genericbl_ops = {
42780 .options = BL_CORE_SUSPENDRESUME,
42781 .get_brightness = genericbl_get_intensity,
42782 .update_status = genericbl_send_intensity,
42783diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
42784index 7fb4eef..f7cc528 100644
42785--- a/drivers/video/backlight/hp680_bl.c
42786+++ b/drivers/video/backlight/hp680_bl.c
42787@@ -98,7 +98,7 @@ static int hp680bl_get_intensity(struct backlight_device *bd)
42788 return current_intensity;
42789 }
42790
42791-static struct backlight_ops hp680bl_ops = {
42792+static const struct backlight_ops hp680bl_ops = {
42793 .get_brightness = hp680bl_get_intensity,
42794 .update_status = hp680bl_set_intensity,
42795 };
42796diff --git a/drivers/video/backlight/jornada720_bl.c b/drivers/video/backlight/jornada720_bl.c
42797index 7aed256..db9071f 100644
42798--- a/drivers/video/backlight/jornada720_bl.c
42799+++ b/drivers/video/backlight/jornada720_bl.c
42800@@ -93,7 +93,7 @@ out:
42801 return ret;
42802 }
42803
42804-static struct backlight_ops jornada_bl_ops = {
42805+static const struct backlight_ops jornada_bl_ops = {
42806 .get_brightness = jornada_bl_get_brightness,
42807 .update_status = jornada_bl_update_status,
42808 .options = BL_CORE_SUSPENDRESUME,
42809diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
42810index a38fda1..939e7b8 100644
42811--- a/drivers/video/backlight/kb3886_bl.c
42812+++ b/drivers/video/backlight/kb3886_bl.c
42813@@ -134,7 +134,7 @@ static int kb3886bl_get_intensity(struct backlight_device *bd)
42814 return kb3886bl_intensity;
42815 }
42816
42817-static struct backlight_ops kb3886bl_ops = {
42818+static const struct backlight_ops kb3886bl_ops = {
42819 .get_brightness = kb3886bl_get_intensity,
42820 .update_status = kb3886bl_send_intensity,
42821 };
42822diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
42823index 6b488b8..00a9591 100644
42824--- a/drivers/video/backlight/locomolcd.c
42825+++ b/drivers/video/backlight/locomolcd.c
42826@@ -141,7 +141,7 @@ static int locomolcd_get_intensity(struct backlight_device *bd)
42827 return current_intensity;
42828 }
42829
42830-static struct backlight_ops locomobl_data = {
42831+static const struct backlight_ops locomobl_data = {
42832 .get_brightness = locomolcd_get_intensity,
42833 .update_status = locomolcd_set_intensity,
42834 };
42835diff --git a/drivers/video/backlight/mbp_nvidia_bl.c b/drivers/video/backlight/mbp_nvidia_bl.c
42836index 99bdfa8..3dac448 100644
42837--- a/drivers/video/backlight/mbp_nvidia_bl.c
42838+++ b/drivers/video/backlight/mbp_nvidia_bl.c
42839@@ -33,7 +33,7 @@ struct dmi_match_data {
42840 unsigned long iostart;
42841 unsigned long iolen;
42842 /* Backlight operations structure. */
42843- struct backlight_ops backlight_ops;
42844+ const struct backlight_ops backlight_ops;
42845 };
42846
42847 /* Module parameters. */
42848diff --git a/drivers/video/backlight/omap1_bl.c b/drivers/video/backlight/omap1_bl.c
42849index cbad67e..3cf900e 100644
42850--- a/drivers/video/backlight/omap1_bl.c
42851+++ b/drivers/video/backlight/omap1_bl.c
42852@@ -125,7 +125,7 @@ static int omapbl_get_intensity(struct backlight_device *dev)
42853 return bl->current_intensity;
42854 }
42855
42856-static struct backlight_ops omapbl_ops = {
42857+static const struct backlight_ops omapbl_ops = {
42858 .get_brightness = omapbl_get_intensity,
42859 .update_status = omapbl_update_status,
42860 };
42861diff --git a/drivers/video/backlight/progear_bl.c b/drivers/video/backlight/progear_bl.c
42862index 9edaf24..075786e 100644
42863--- a/drivers/video/backlight/progear_bl.c
42864+++ b/drivers/video/backlight/progear_bl.c
42865@@ -54,7 +54,7 @@ static int progearbl_get_intensity(struct backlight_device *bd)
42866 return intensity - HW_LEVEL_MIN;
42867 }
42868
42869-static struct backlight_ops progearbl_ops = {
42870+static const struct backlight_ops progearbl_ops = {
42871 .get_brightness = progearbl_get_intensity,
42872 .update_status = progearbl_set_intensity,
42873 };
42874diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
42875index 8871662..df9e0b3 100644
42876--- a/drivers/video/backlight/pwm_bl.c
42877+++ b/drivers/video/backlight/pwm_bl.c
42878@@ -56,7 +56,7 @@ static int pwm_backlight_get_brightness(struct backlight_device *bl)
42879 return bl->props.brightness;
42880 }
42881
42882-static struct backlight_ops pwm_backlight_ops = {
42883+static const struct backlight_ops pwm_backlight_ops = {
42884 .update_status = pwm_backlight_update_status,
42885 .get_brightness = pwm_backlight_get_brightness,
42886 };
42887diff --git a/drivers/video/backlight/tosa_bl.c b/drivers/video/backlight/tosa_bl.c
42888index 43edbad..e14ce4d 100644
42889--- a/drivers/video/backlight/tosa_bl.c
42890+++ b/drivers/video/backlight/tosa_bl.c
42891@@ -72,7 +72,7 @@ static int tosa_bl_get_brightness(struct backlight_device *dev)
42892 return props->brightness;
42893 }
42894
42895-static struct backlight_ops bl_ops = {
42896+static const struct backlight_ops bl_ops = {
42897 .get_brightness = tosa_bl_get_brightness,
42898 .update_status = tosa_bl_update_status,
42899 };
42900diff --git a/drivers/video/backlight/wm831x_bl.c b/drivers/video/backlight/wm831x_bl.c
42901index 467bdb7..e32add3 100644
42902--- a/drivers/video/backlight/wm831x_bl.c
42903+++ b/drivers/video/backlight/wm831x_bl.c
42904@@ -112,7 +112,7 @@ static int wm831x_backlight_get_brightness(struct backlight_device *bl)
42905 return data->current_brightness;
42906 }
42907
42908-static struct backlight_ops wm831x_backlight_ops = {
42909+static const struct backlight_ops wm831x_backlight_ops = {
42910 .options = BL_CORE_SUSPENDRESUME,
42911 .update_status = wm831x_backlight_update_status,
42912 .get_brightness = wm831x_backlight_get_brightness,
42913diff --git a/drivers/video/bf54x-lq043fb.c b/drivers/video/bf54x-lq043fb.c
42914index e49ae5e..db4e6f7 100644
42915--- a/drivers/video/bf54x-lq043fb.c
42916+++ b/drivers/video/bf54x-lq043fb.c
42917@@ -463,7 +463,7 @@ static int bl_get_brightness(struct backlight_device *bd)
42918 return 0;
42919 }
42920
42921-static struct backlight_ops bfin_lq043fb_bl_ops = {
42922+static const struct backlight_ops bfin_lq043fb_bl_ops = {
42923 .get_brightness = bl_get_brightness,
42924 };
42925
42926diff --git a/drivers/video/bfin-t350mcqb-fb.c b/drivers/video/bfin-t350mcqb-fb.c
42927index 2c72a7c..d523e52 100644
42928--- a/drivers/video/bfin-t350mcqb-fb.c
42929+++ b/drivers/video/bfin-t350mcqb-fb.c
42930@@ -381,7 +381,7 @@ static int bl_get_brightness(struct backlight_device *bd)
42931 return 0;
42932 }
42933
42934-static struct backlight_ops bfin_lq043fb_bl_ops = {
42935+static const struct backlight_ops bfin_lq043fb_bl_ops = {
42936 .get_brightness = bl_get_brightness,
42937 };
42938
42939diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
42940index f53b9f1..958bf4e 100644
42941--- a/drivers/video/fbcmap.c
42942+++ b/drivers/video/fbcmap.c
42943@@ -266,8 +266,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
42944 rc = -ENODEV;
42945 goto out;
42946 }
42947- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42948- !info->fbops->fb_setcmap)) {
42949+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42950 rc = -EINVAL;
42951 goto out1;
42952 }
42953diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
42954index 99bbd28..ad3829e 100644
42955--- a/drivers/video/fbmem.c
42956+++ b/drivers/video/fbmem.c
42957@@ -403,7 +403,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42958 image->dx += image->width + 8;
42959 }
42960 } else if (rotate == FB_ROTATE_UD) {
42961- for (x = 0; x < num && image->dx >= 0; x++) {
42962+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42963 info->fbops->fb_imageblit(info, image);
42964 image->dx -= image->width + 8;
42965 }
42966@@ -415,7 +415,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42967 image->dy += image->height + 8;
42968 }
42969 } else if (rotate == FB_ROTATE_CCW) {
42970- for (x = 0; x < num && image->dy >= 0; x++) {
42971+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42972 info->fbops->fb_imageblit(info, image);
42973 image->dy -= image->height + 8;
42974 }
42975@@ -915,6 +915,8 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
42976 int flags = info->flags;
42977 int ret = 0;
42978
42979+ pax_track_stack();
42980+
42981 if (var->activate & FB_ACTIVATE_INV_MODE) {
42982 struct fb_videomode mode1, mode2;
42983
42984@@ -1040,6 +1042,8 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42985 void __user *argp = (void __user *)arg;
42986 long ret = 0;
42987
42988+ pax_track_stack();
42989+
42990 switch (cmd) {
42991 case FBIOGET_VSCREENINFO:
42992 if (!lock_fb_info(info))
42993@@ -1119,7 +1123,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42994 return -EFAULT;
42995 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42996 return -EINVAL;
42997- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42998+ if (con2fb.framebuffer >= FB_MAX)
42999 return -EINVAL;
43000 if (!registered_fb[con2fb.framebuffer])
43001 request_module("fb%d", con2fb.framebuffer);
43002diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
43003index f20eff8..3e4f622 100644
43004--- a/drivers/video/geode/gx1fb_core.c
43005+++ b/drivers/video/geode/gx1fb_core.c
43006@@ -30,7 +30,7 @@ static int crt_option = 1;
43007 static char panel_option[32] = "";
43008
43009 /* Modes relevant to the GX1 (taken from modedb.c) */
43010-static const struct fb_videomode __initdata gx1_modedb[] = {
43011+static const struct fb_videomode __initconst gx1_modedb[] = {
43012 /* 640x480-60 VESA */
43013 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
43014 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
43015diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
43016index 896e53d..4d87d0b 100644
43017--- a/drivers/video/gxt4500.c
43018+++ b/drivers/video/gxt4500.c
43019@@ -156,7 +156,7 @@ struct gxt4500_par {
43020 static char *mode_option;
43021
43022 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
43023-static const struct fb_videomode defaultmode __devinitdata = {
43024+static const struct fb_videomode defaultmode __devinitconst = {
43025 .refresh = 60,
43026 .xres = 1280,
43027 .yres = 1024,
43028@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
43029 return 0;
43030 }
43031
43032-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
43033+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
43034 .id = "IBM GXT4500P",
43035 .type = FB_TYPE_PACKED_PIXELS,
43036 .visual = FB_VISUAL_PSEUDOCOLOR,
43037diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
43038index f5bedee..28c6028 100644
43039--- a/drivers/video/i810/i810_accel.c
43040+++ b/drivers/video/i810/i810_accel.c
43041@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
43042 }
43043 }
43044 printk("ringbuffer lockup!!!\n");
43045+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
43046 i810_report_error(mmio);
43047 par->dev_flags |= LOCKUP;
43048 info->pixmap.scan_align = 1;
43049diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
43050index 5743ea2..457f82c 100644
43051--- a/drivers/video/i810/i810_main.c
43052+++ b/drivers/video/i810/i810_main.c
43053@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
43054 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
43055
43056 /* PCI */
43057-static const char *i810_pci_list[] __devinitdata = {
43058+static const char *i810_pci_list[] __devinitconst = {
43059 "Intel(R) 810 Framebuffer Device" ,
43060 "Intel(R) 810-DC100 Framebuffer Device" ,
43061 "Intel(R) 810E Framebuffer Device" ,
43062diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
43063index 3c14e43..eafa544 100644
43064--- a/drivers/video/logo/logo_linux_clut224.ppm
43065+++ b/drivers/video/logo/logo_linux_clut224.ppm
43066@@ -1,1604 +1,1123 @@
43067 P3
43068-# Standard 224-color Linux logo
43069 80 80
43070 255
43071- 0 0 0 0 0 0 0 0 0 0 0 0
43072- 0 0 0 0 0 0 0 0 0 0 0 0
43073- 0 0 0 0 0 0 0 0 0 0 0 0
43074- 0 0 0 0 0 0 0 0 0 0 0 0
43075- 0 0 0 0 0 0 0 0 0 0 0 0
43076- 0 0 0 0 0 0 0 0 0 0 0 0
43077- 0 0 0 0 0 0 0 0 0 0 0 0
43078- 0 0 0 0 0 0 0 0 0 0 0 0
43079- 0 0 0 0 0 0 0 0 0 0 0 0
43080- 6 6 6 6 6 6 10 10 10 10 10 10
43081- 10 10 10 6 6 6 6 6 6 6 6 6
43082- 0 0 0 0 0 0 0 0 0 0 0 0
43083- 0 0 0 0 0 0 0 0 0 0 0 0
43084- 0 0 0 0 0 0 0 0 0 0 0 0
43085- 0 0 0 0 0 0 0 0 0 0 0 0
43086- 0 0 0 0 0 0 0 0 0 0 0 0
43087- 0 0 0 0 0 0 0 0 0 0 0 0
43088- 0 0 0 0 0 0 0 0 0 0 0 0
43089- 0 0 0 0 0 0 0 0 0 0 0 0
43090- 0 0 0 0 0 0 0 0 0 0 0 0
43091- 0 0 0 0 0 0 0 0 0 0 0 0
43092- 0 0 0 0 0 0 0 0 0 0 0 0
43093- 0 0 0 0 0 0 0 0 0 0 0 0
43094- 0 0 0 0 0 0 0 0 0 0 0 0
43095- 0 0 0 0 0 0 0 0 0 0 0 0
43096- 0 0 0 0 0 0 0 0 0 0 0 0
43097- 0 0 0 0 0 0 0 0 0 0 0 0
43098- 0 0 0 0 0 0 0 0 0 0 0 0
43099- 0 0 0 6 6 6 10 10 10 14 14 14
43100- 22 22 22 26 26 26 30 30 30 34 34 34
43101- 30 30 30 30 30 30 26 26 26 18 18 18
43102- 14 14 14 10 10 10 6 6 6 0 0 0
43103- 0 0 0 0 0 0 0 0 0 0 0 0
43104- 0 0 0 0 0 0 0 0 0 0 0 0
43105- 0 0 0 0 0 0 0 0 0 0 0 0
43106- 0 0 0 0 0 0 0 0 0 0 0 0
43107- 0 0 0 0 0 0 0 0 0 0 0 0
43108- 0 0 0 0 0 0 0 0 0 0 0 0
43109- 0 0 0 0 0 0 0 0 0 0 0 0
43110- 0 0 0 0 0 0 0 0 0 0 0 0
43111- 0 0 0 0 0 0 0 0 0 0 0 0
43112- 0 0 0 0 0 1 0 0 1 0 0 0
43113- 0 0 0 0 0 0 0 0 0 0 0 0
43114- 0 0 0 0 0 0 0 0 0 0 0 0
43115- 0 0 0 0 0 0 0 0 0 0 0 0
43116- 0 0 0 0 0 0 0 0 0 0 0 0
43117- 0 0 0 0 0 0 0 0 0 0 0 0
43118- 0 0 0 0 0 0 0 0 0 0 0 0
43119- 6 6 6 14 14 14 26 26 26 42 42 42
43120- 54 54 54 66 66 66 78 78 78 78 78 78
43121- 78 78 78 74 74 74 66 66 66 54 54 54
43122- 42 42 42 26 26 26 18 18 18 10 10 10
43123- 6 6 6 0 0 0 0 0 0 0 0 0
43124- 0 0 0 0 0 0 0 0 0 0 0 0
43125- 0 0 0 0 0 0 0 0 0 0 0 0
43126- 0 0 0 0 0 0 0 0 0 0 0 0
43127- 0 0 0 0 0 0 0 0 0 0 0 0
43128- 0 0 0 0 0 0 0 0 0 0 0 0
43129- 0 0 0 0 0 0 0 0 0 0 0 0
43130- 0 0 0 0 0 0 0 0 0 0 0 0
43131- 0 0 0 0 0 0 0 0 0 0 0 0
43132- 0 0 1 0 0 0 0 0 0 0 0 0
43133- 0 0 0 0 0 0 0 0 0 0 0 0
43134- 0 0 0 0 0 0 0 0 0 0 0 0
43135- 0 0 0 0 0 0 0 0 0 0 0 0
43136- 0 0 0 0 0 0 0 0 0 0 0 0
43137- 0 0 0 0 0 0 0 0 0 0 0 0
43138- 0 0 0 0 0 0 0 0 0 10 10 10
43139- 22 22 22 42 42 42 66 66 66 86 86 86
43140- 66 66 66 38 38 38 38 38 38 22 22 22
43141- 26 26 26 34 34 34 54 54 54 66 66 66
43142- 86 86 86 70 70 70 46 46 46 26 26 26
43143- 14 14 14 6 6 6 0 0 0 0 0 0
43144- 0 0 0 0 0 0 0 0 0 0 0 0
43145- 0 0 0 0 0 0 0 0 0 0 0 0
43146- 0 0 0 0 0 0 0 0 0 0 0 0
43147- 0 0 0 0 0 0 0 0 0 0 0 0
43148- 0 0 0 0 0 0 0 0 0 0 0 0
43149- 0 0 0 0 0 0 0 0 0 0 0 0
43150- 0 0 0 0 0 0 0 0 0 0 0 0
43151- 0 0 0 0 0 0 0 0 0 0 0 0
43152- 0 0 1 0 0 1 0 0 1 0 0 0
43153- 0 0 0 0 0 0 0 0 0 0 0 0
43154- 0 0 0 0 0 0 0 0 0 0 0 0
43155- 0 0 0 0 0 0 0 0 0 0 0 0
43156- 0 0 0 0 0 0 0 0 0 0 0 0
43157- 0 0 0 0 0 0 0 0 0 0 0 0
43158- 0 0 0 0 0 0 10 10 10 26 26 26
43159- 50 50 50 82 82 82 58 58 58 6 6 6
43160- 2 2 6 2 2 6 2 2 6 2 2 6
43161- 2 2 6 2 2 6 2 2 6 2 2 6
43162- 6 6 6 54 54 54 86 86 86 66 66 66
43163- 38 38 38 18 18 18 6 6 6 0 0 0
43164- 0 0 0 0 0 0 0 0 0 0 0 0
43165- 0 0 0 0 0 0 0 0 0 0 0 0
43166- 0 0 0 0 0 0 0 0 0 0 0 0
43167- 0 0 0 0 0 0 0 0 0 0 0 0
43168- 0 0 0 0 0 0 0 0 0 0 0 0
43169- 0 0 0 0 0 0 0 0 0 0 0 0
43170- 0 0 0 0 0 0 0 0 0 0 0 0
43171- 0 0 0 0 0 0 0 0 0 0 0 0
43172- 0 0 0 0 0 0 0 0 0 0 0 0
43173- 0 0 0 0 0 0 0 0 0 0 0 0
43174- 0 0 0 0 0 0 0 0 0 0 0 0
43175- 0 0 0 0 0 0 0 0 0 0 0 0
43176- 0 0 0 0 0 0 0 0 0 0 0 0
43177- 0 0 0 0 0 0 0 0 0 0 0 0
43178- 0 0 0 6 6 6 22 22 22 50 50 50
43179- 78 78 78 34 34 34 2 2 6 2 2 6
43180- 2 2 6 2 2 6 2 2 6 2 2 6
43181- 2 2 6 2 2 6 2 2 6 2 2 6
43182- 2 2 6 2 2 6 6 6 6 70 70 70
43183- 78 78 78 46 46 46 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
43192- 0 0 1 0 0 1 0 0 1 0 0 0
43193- 0 0 0 0 0 0 0 0 0 0 0 0
43194- 0 0 0 0 0 0 0 0 0 0 0 0
43195- 0 0 0 0 0 0 0 0 0 0 0 0
43196- 0 0 0 0 0 0 0 0 0 0 0 0
43197- 0 0 0 0 0 0 0 0 0 0 0 0
43198- 6 6 6 18 18 18 42 42 42 82 82 82
43199- 26 26 26 2 2 6 2 2 6 2 2 6
43200- 2 2 6 2 2 6 2 2 6 2 2 6
43201- 2 2 6 2 2 6 2 2 6 14 14 14
43202- 46 46 46 34 34 34 6 6 6 2 2 6
43203- 42 42 42 78 78 78 42 42 42 18 18 18
43204- 6 6 6 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 0 0 0 0 0 0 0 0 0
43211- 0 0 0 0 0 0 0 0 0 0 0 0
43212- 0 0 1 0 0 0 0 0 1 0 0 0
43213- 0 0 0 0 0 0 0 0 0 0 0 0
43214- 0 0 0 0 0 0 0 0 0 0 0 0
43215- 0 0 0 0 0 0 0 0 0 0 0 0
43216- 0 0 0 0 0 0 0 0 0 0 0 0
43217- 0 0 0 0 0 0 0 0 0 0 0 0
43218- 10 10 10 30 30 30 66 66 66 58 58 58
43219- 2 2 6 2 2 6 2 2 6 2 2 6
43220- 2 2 6 2 2 6 2 2 6 2 2 6
43221- 2 2 6 2 2 6 2 2 6 26 26 26
43222- 86 86 86 101 101 101 46 46 46 10 10 10
43223- 2 2 6 58 58 58 70 70 70 34 34 34
43224- 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
43231- 0 0 0 0 0 0 0 0 0 0 0 0
43232- 0 0 1 0 0 1 0 0 1 0 0 0
43233- 0 0 0 0 0 0 0 0 0 0 0 0
43234- 0 0 0 0 0 0 0 0 0 0 0 0
43235- 0 0 0 0 0 0 0 0 0 0 0 0
43236- 0 0 0 0 0 0 0 0 0 0 0 0
43237- 0 0 0 0 0 0 0 0 0 0 0 0
43238- 14 14 14 42 42 42 86 86 86 10 10 10
43239- 2 2 6 2 2 6 2 2 6 2 2 6
43240- 2 2 6 2 2 6 2 2 6 2 2 6
43241- 2 2 6 2 2 6 2 2 6 30 30 30
43242- 94 94 94 94 94 94 58 58 58 26 26 26
43243- 2 2 6 6 6 6 78 78 78 54 54 54
43244- 22 22 22 6 6 6 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 0 0 0
43250- 0 0 0 0 0 0 0 0 0 0 0 0
43251- 0 0 0 0 0 0 0 0 0 0 0 0
43252- 0 0 0 0 0 0 0 0 0 0 0 0
43253- 0 0 0 0 0 0 0 0 0 0 0 0
43254- 0 0 0 0 0 0 0 0 0 0 0 0
43255- 0 0 0 0 0 0 0 0 0 0 0 0
43256- 0 0 0 0 0 0 0 0 0 0 0 0
43257- 0 0 0 0 0 0 0 0 0 6 6 6
43258- 22 22 22 62 62 62 62 62 62 2 2 6
43259- 2 2 6 2 2 6 2 2 6 2 2 6
43260- 2 2 6 2 2 6 2 2 6 2 2 6
43261- 2 2 6 2 2 6 2 2 6 26 26 26
43262- 54 54 54 38 38 38 18 18 18 10 10 10
43263- 2 2 6 2 2 6 34 34 34 82 82 82
43264- 38 38 38 14 14 14 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 0 0 0 0 0 0
43270- 0 0 0 0 0 0 0 0 0 0 0 0
43271- 0 0 0 0 0 0 0 0 0 0 0 0
43272- 0 0 0 0 0 1 0 0 1 0 0 0
43273- 0 0 0 0 0 0 0 0 0 0 0 0
43274- 0 0 0 0 0 0 0 0 0 0 0 0
43275- 0 0 0 0 0 0 0 0 0 0 0 0
43276- 0 0 0 0 0 0 0 0 0 0 0 0
43277- 0 0 0 0 0 0 0 0 0 6 6 6
43278- 30 30 30 78 78 78 30 30 30 2 2 6
43279- 2 2 6 2 2 6 2 2 6 2 2 6
43280- 2 2 6 2 2 6 2 2 6 2 2 6
43281- 2 2 6 2 2 6 2 2 6 10 10 10
43282- 10 10 10 2 2 6 2 2 6 2 2 6
43283- 2 2 6 2 2 6 2 2 6 78 78 78
43284- 50 50 50 18 18 18 6 6 6 0 0 0
43285- 0 0 0 0 0 0 0 0 0 0 0 0
43286- 0 0 0 0 0 0 0 0 0 0 0 0
43287- 0 0 0 0 0 0 0 0 0 0 0 0
43288- 0 0 0 0 0 0 0 0 0 0 0 0
43289- 0 0 0 0 0 0 0 0 0 0 0 0
43290- 0 0 0 0 0 0 0 0 0 0 0 0
43291- 0 0 0 0 0 0 0 0 0 0 0 0
43292- 0 0 1 0 0 0 0 0 0 0 0 0
43293- 0 0 0 0 0 0 0 0 0 0 0 0
43294- 0 0 0 0 0 0 0 0 0 0 0 0
43295- 0 0 0 0 0 0 0 0 0 0 0 0
43296- 0 0 0 0 0 0 0 0 0 0 0 0
43297- 0 0 0 0 0 0 0 0 0 10 10 10
43298- 38 38 38 86 86 86 14 14 14 2 2 6
43299- 2 2 6 2 2 6 2 2 6 2 2 6
43300- 2 2 6 2 2 6 2 2 6 2 2 6
43301- 2 2 6 2 2 6 2 2 6 2 2 6
43302- 2 2 6 2 2 6 2 2 6 2 2 6
43303- 2 2 6 2 2 6 2 2 6 54 54 54
43304- 66 66 66 26 26 26 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
43310- 0 0 0 0 0 0 0 0 0 0 0 0
43311- 0 0 0 0 0 0 0 0 0 0 0 0
43312- 0 0 0 0 0 1 0 0 1 0 0 0
43313- 0 0 0 0 0 0 0 0 0 0 0 0
43314- 0 0 0 0 0 0 0 0 0 0 0 0
43315- 0 0 0 0 0 0 0 0 0 0 0 0
43316- 0 0 0 0 0 0 0 0 0 0 0 0
43317- 0 0 0 0 0 0 0 0 0 14 14 14
43318- 42 42 42 82 82 82 2 2 6 2 2 6
43319- 2 2 6 6 6 6 10 10 10 2 2 6
43320- 2 2 6 2 2 6 2 2 6 2 2 6
43321- 2 2 6 2 2 6 2 2 6 6 6 6
43322- 14 14 14 10 10 10 2 2 6 2 2 6
43323- 2 2 6 2 2 6 2 2 6 18 18 18
43324- 82 82 82 34 34 34 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
43330- 0 0 0 0 0 0 0 0 0 0 0 0
43331- 0 0 0 0 0 0 0 0 0 0 0 0
43332- 0 0 1 0 0 0 0 0 0 0 0 0
43333- 0 0 0 0 0 0 0 0 0 0 0 0
43334- 0 0 0 0 0 0 0 0 0 0 0 0
43335- 0 0 0 0 0 0 0 0 0 0 0 0
43336- 0 0 0 0 0 0 0 0 0 0 0 0
43337- 0 0 0 0 0 0 0 0 0 14 14 14
43338- 46 46 46 86 86 86 2 2 6 2 2 6
43339- 6 6 6 6 6 6 22 22 22 34 34 34
43340- 6 6 6 2 2 6 2 2 6 2 2 6
43341- 2 2 6 2 2 6 18 18 18 34 34 34
43342- 10 10 10 50 50 50 22 22 22 2 2 6
43343- 2 2 6 2 2 6 2 2 6 10 10 10
43344- 86 86 86 42 42 42 14 14 14 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- 0 0 0 0 0 0 0 0 0 0 0 0
43350- 0 0 0 0 0 0 0 0 0 0 0 0
43351- 0 0 0 0 0 0 0 0 0 0 0 0
43352- 0 0 1 0 0 1 0 0 1 0 0 0
43353- 0 0 0 0 0 0 0 0 0 0 0 0
43354- 0 0 0 0 0 0 0 0 0 0 0 0
43355- 0 0 0 0 0 0 0 0 0 0 0 0
43356- 0 0 0 0 0 0 0 0 0 0 0 0
43357- 0 0 0 0 0 0 0 0 0 14 14 14
43358- 46 46 46 86 86 86 2 2 6 2 2 6
43359- 38 38 38 116 116 116 94 94 94 22 22 22
43360- 22 22 22 2 2 6 2 2 6 2 2 6
43361- 14 14 14 86 86 86 138 138 138 162 162 162
43362-154 154 154 38 38 38 26 26 26 6 6 6
43363- 2 2 6 2 2 6 2 2 6 2 2 6
43364- 86 86 86 46 46 46 14 14 14 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 0 0 0
43369- 0 0 0 0 0 0 0 0 0 0 0 0
43370- 0 0 0 0 0 0 0 0 0 0 0 0
43371- 0 0 0 0 0 0 0 0 0 0 0 0
43372- 0 0 0 0 0 0 0 0 0 0 0 0
43373- 0 0 0 0 0 0 0 0 0 0 0 0
43374- 0 0 0 0 0 0 0 0 0 0 0 0
43375- 0 0 0 0 0 0 0 0 0 0 0 0
43376- 0 0 0 0 0 0 0 0 0 0 0 0
43377- 0 0 0 0 0 0 0 0 0 14 14 14
43378- 46 46 46 86 86 86 2 2 6 14 14 14
43379-134 134 134 198 198 198 195 195 195 116 116 116
43380- 10 10 10 2 2 6 2 2 6 6 6 6
43381-101 98 89 187 187 187 210 210 210 218 218 218
43382-214 214 214 134 134 134 14 14 14 6 6 6
43383- 2 2 6 2 2 6 2 2 6 2 2 6
43384- 86 86 86 50 50 50 18 18 18 6 6 6
43385- 0 0 0 0 0 0 0 0 0 0 0 0
43386- 0 0 0 0 0 0 0 0 0 0 0 0
43387- 0 0 0 0 0 0 0 0 0 0 0 0
43388- 0 0 0 0 0 0 0 0 0 0 0 0
43389- 0 0 0 0 0 0 0 0 0 0 0 0
43390- 0 0 0 0 0 0 0 0 0 0 0 0
43391- 0 0 0 0 0 0 0 0 1 0 0 0
43392- 0 0 1 0 0 1 0 0 1 0 0 0
43393- 0 0 0 0 0 0 0 0 0 0 0 0
43394- 0 0 0 0 0 0 0 0 0 0 0 0
43395- 0 0 0 0 0 0 0 0 0 0 0 0
43396- 0 0 0 0 0 0 0 0 0 0 0 0
43397- 0 0 0 0 0 0 0 0 0 14 14 14
43398- 46 46 46 86 86 86 2 2 6 54 54 54
43399-218 218 218 195 195 195 226 226 226 246 246 246
43400- 58 58 58 2 2 6 2 2 6 30 30 30
43401-210 210 210 253 253 253 174 174 174 123 123 123
43402-221 221 221 234 234 234 74 74 74 2 2 6
43403- 2 2 6 2 2 6 2 2 6 2 2 6
43404- 70 70 70 58 58 58 22 22 22 6 6 6
43405- 0 0 0 0 0 0 0 0 0 0 0 0
43406- 0 0 0 0 0 0 0 0 0 0 0 0
43407- 0 0 0 0 0 0 0 0 0 0 0 0
43408- 0 0 0 0 0 0 0 0 0 0 0 0
43409- 0 0 0 0 0 0 0 0 0 0 0 0
43410- 0 0 0 0 0 0 0 0 0 0 0 0
43411- 0 0 0 0 0 0 0 0 0 0 0 0
43412- 0 0 0 0 0 0 0 0 0 0 0 0
43413- 0 0 0 0 0 0 0 0 0 0 0 0
43414- 0 0 0 0 0 0 0 0 0 0 0 0
43415- 0 0 0 0 0 0 0 0 0 0 0 0
43416- 0 0 0 0 0 0 0 0 0 0 0 0
43417- 0 0 0 0 0 0 0 0 0 14 14 14
43418- 46 46 46 82 82 82 2 2 6 106 106 106
43419-170 170 170 26 26 26 86 86 86 226 226 226
43420-123 123 123 10 10 10 14 14 14 46 46 46
43421-231 231 231 190 190 190 6 6 6 70 70 70
43422- 90 90 90 238 238 238 158 158 158 2 2 6
43423- 2 2 6 2 2 6 2 2 6 2 2 6
43424- 70 70 70 58 58 58 22 22 22 6 6 6
43425- 0 0 0 0 0 0 0 0 0 0 0 0
43426- 0 0 0 0 0 0 0 0 0 0 0 0
43427- 0 0 0 0 0 0 0 0 0 0 0 0
43428- 0 0 0 0 0 0 0 0 0 0 0 0
43429- 0 0 0 0 0 0 0 0 0 0 0 0
43430- 0 0 0 0 0 0 0 0 0 0 0 0
43431- 0 0 0 0 0 0 0 0 1 0 0 0
43432- 0 0 1 0 0 1 0 0 1 0 0 0
43433- 0 0 0 0 0 0 0 0 0 0 0 0
43434- 0 0 0 0 0 0 0 0 0 0 0 0
43435- 0 0 0 0 0 0 0 0 0 0 0 0
43436- 0 0 0 0 0 0 0 0 0 0 0 0
43437- 0 0 0 0 0 0 0 0 0 14 14 14
43438- 42 42 42 86 86 86 6 6 6 116 116 116
43439-106 106 106 6 6 6 70 70 70 149 149 149
43440-128 128 128 18 18 18 38 38 38 54 54 54
43441-221 221 221 106 106 106 2 2 6 14 14 14
43442- 46 46 46 190 190 190 198 198 198 2 2 6
43443- 2 2 6 2 2 6 2 2 6 2 2 6
43444- 74 74 74 62 62 62 22 22 22 6 6 6
43445- 0 0 0 0 0 0 0 0 0 0 0 0
43446- 0 0 0 0 0 0 0 0 0 0 0 0
43447- 0 0 0 0 0 0 0 0 0 0 0 0
43448- 0 0 0 0 0 0 0 0 0 0 0 0
43449- 0 0 0 0 0 0 0 0 0 0 0 0
43450- 0 0 0 0 0 0 0 0 0 0 0 0
43451- 0 0 0 0 0 0 0 0 1 0 0 0
43452- 0 0 1 0 0 0 0 0 1 0 0 0
43453- 0 0 0 0 0 0 0 0 0 0 0 0
43454- 0 0 0 0 0 0 0 0 0 0 0 0
43455- 0 0 0 0 0 0 0 0 0 0 0 0
43456- 0 0 0 0 0 0 0 0 0 0 0 0
43457- 0 0 0 0 0 0 0 0 0 14 14 14
43458- 42 42 42 94 94 94 14 14 14 101 101 101
43459-128 128 128 2 2 6 18 18 18 116 116 116
43460-118 98 46 121 92 8 121 92 8 98 78 10
43461-162 162 162 106 106 106 2 2 6 2 2 6
43462- 2 2 6 195 195 195 195 195 195 6 6 6
43463- 2 2 6 2 2 6 2 2 6 2 2 6
43464- 74 74 74 62 62 62 22 22 22 6 6 6
43465- 0 0 0 0 0 0 0 0 0 0 0 0
43466- 0 0 0 0 0 0 0 0 0 0 0 0
43467- 0 0 0 0 0 0 0 0 0 0 0 0
43468- 0 0 0 0 0 0 0 0 0 0 0 0
43469- 0 0 0 0 0 0 0 0 0 0 0 0
43470- 0 0 0 0 0 0 0 0 0 0 0 0
43471- 0 0 0 0 0 0 0 0 1 0 0 1
43472- 0 0 1 0 0 0 0 0 1 0 0 0
43473- 0 0 0 0 0 0 0 0 0 0 0 0
43474- 0 0 0 0 0 0 0 0 0 0 0 0
43475- 0 0 0 0 0 0 0 0 0 0 0 0
43476- 0 0 0 0 0 0 0 0 0 0 0 0
43477- 0 0 0 0 0 0 0 0 0 10 10 10
43478- 38 38 38 90 90 90 14 14 14 58 58 58
43479-210 210 210 26 26 26 54 38 6 154 114 10
43480-226 170 11 236 186 11 225 175 15 184 144 12
43481-215 174 15 175 146 61 37 26 9 2 2 6
43482- 70 70 70 246 246 246 138 138 138 2 2 6
43483- 2 2 6 2 2 6 2 2 6 2 2 6
43484- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
43489- 0 0 0 0 0 0 0 0 0 0 0 0
43490- 0 0 0 0 0 0 0 0 0 0 0 0
43491- 0 0 0 0 0 0 0 0 0 0 0 0
43492- 0 0 0 0 0 0 0 0 0 0 0 0
43493- 0 0 0 0 0 0 0 0 0 0 0 0
43494- 0 0 0 0 0 0 0 0 0 0 0 0
43495- 0 0 0 0 0 0 0 0 0 0 0 0
43496- 0 0 0 0 0 0 0 0 0 0 0 0
43497- 0 0 0 0 0 0 0 0 0 10 10 10
43498- 38 38 38 86 86 86 14 14 14 10 10 10
43499-195 195 195 188 164 115 192 133 9 225 175 15
43500-239 182 13 234 190 10 232 195 16 232 200 30
43501-245 207 45 241 208 19 232 195 16 184 144 12
43502-218 194 134 211 206 186 42 42 42 2 2 6
43503- 2 2 6 2 2 6 2 2 6 2 2 6
43504- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
43509- 0 0 0 0 0 0 0 0 0 0 0 0
43510- 0 0 0 0 0 0 0 0 0 0 0 0
43511- 0 0 0 0 0 0 0 0 0 0 0 0
43512- 0 0 0 0 0 0 0 0 0 0 0 0
43513- 0 0 0 0 0 0 0 0 0 0 0 0
43514- 0 0 0 0 0 0 0 0 0 0 0 0
43515- 0 0 0 0 0 0 0 0 0 0 0 0
43516- 0 0 0 0 0 0 0 0 0 0 0 0
43517- 0 0 0 0 0 0 0 0 0 10 10 10
43518- 34 34 34 86 86 86 14 14 14 2 2 6
43519-121 87 25 192 133 9 219 162 10 239 182 13
43520-236 186 11 232 195 16 241 208 19 244 214 54
43521-246 218 60 246 218 38 246 215 20 241 208 19
43522-241 208 19 226 184 13 121 87 25 2 2 6
43523- 2 2 6 2 2 6 2 2 6 2 2 6
43524- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
43529- 0 0 0 0 0 0 0 0 0 0 0 0
43530- 0 0 0 0 0 0 0 0 0 0 0 0
43531- 0 0 0 0 0 0 0 0 0 0 0 0
43532- 0 0 0 0 0 0 0 0 0 0 0 0
43533- 0 0 0 0 0 0 0 0 0 0 0 0
43534- 0 0 0 0 0 0 0 0 0 0 0 0
43535- 0 0 0 0 0 0 0 0 0 0 0 0
43536- 0 0 0 0 0 0 0 0 0 0 0 0
43537- 0 0 0 0 0 0 0 0 0 10 10 10
43538- 34 34 34 82 82 82 30 30 30 61 42 6
43539-180 123 7 206 145 10 230 174 11 239 182 13
43540-234 190 10 238 202 15 241 208 19 246 218 74
43541-246 218 38 246 215 20 246 215 20 246 215 20
43542-226 184 13 215 174 15 184 144 12 6 6 6
43543- 2 2 6 2 2 6 2 2 6 2 2 6
43544- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
43549- 0 0 0 0 0 0 0 0 0 0 0 0
43550- 0 0 0 0 0 0 0 0 0 0 0 0
43551- 0 0 0 0 0 0 0 0 0 0 0 0
43552- 0 0 0 0 0 0 0 0 0 0 0 0
43553- 0 0 0 0 0 0 0 0 0 0 0 0
43554- 0 0 0 0 0 0 0 0 0 0 0 0
43555- 0 0 0 0 0 0 0 0 0 0 0 0
43556- 0 0 0 0 0 0 0 0 0 0 0 0
43557- 0 0 0 0 0 0 0 0 0 10 10 10
43558- 30 30 30 78 78 78 50 50 50 104 69 6
43559-192 133 9 216 158 10 236 178 12 236 186 11
43560-232 195 16 241 208 19 244 214 54 245 215 43
43561-246 215 20 246 215 20 241 208 19 198 155 10
43562-200 144 11 216 158 10 156 118 10 2 2 6
43563- 2 2 6 2 2 6 2 2 6 2 2 6
43564- 6 6 6 90 90 90 54 54 54 18 18 18
43565- 6 6 6 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 0 0 0
43569- 0 0 0 0 0 0 0 0 0 0 0 0
43570- 0 0 0 0 0 0 0 0 0 0 0 0
43571- 0 0 0 0 0 0 0 0 0 0 0 0
43572- 0 0 0 0 0 0 0 0 0 0 0 0
43573- 0 0 0 0 0 0 0 0 0 0 0 0
43574- 0 0 0 0 0 0 0 0 0 0 0 0
43575- 0 0 0 0 0 0 0 0 0 0 0 0
43576- 0 0 0 0 0 0 0 0 0 0 0 0
43577- 0 0 0 0 0 0 0 0 0 10 10 10
43578- 30 30 30 78 78 78 46 46 46 22 22 22
43579-137 92 6 210 162 10 239 182 13 238 190 10
43580-238 202 15 241 208 19 246 215 20 246 215 20
43581-241 208 19 203 166 17 185 133 11 210 150 10
43582-216 158 10 210 150 10 102 78 10 2 2 6
43583- 6 6 6 54 54 54 14 14 14 2 2 6
43584- 2 2 6 62 62 62 74 74 74 30 30 30
43585- 10 10 10 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 0 0 0
43589- 0 0 0 0 0 0 0 0 0 0 0 0
43590- 0 0 0 0 0 0 0 0 0 0 0 0
43591- 0 0 0 0 0 0 0 0 0 0 0 0
43592- 0 0 0 0 0 0 0 0 0 0 0 0
43593- 0 0 0 0 0 0 0 0 0 0 0 0
43594- 0 0 0 0 0 0 0 0 0 0 0 0
43595- 0 0 0 0 0 0 0 0 0 0 0 0
43596- 0 0 0 0 0 0 0 0 0 0 0 0
43597- 0 0 0 0 0 0 0 0 0 10 10 10
43598- 34 34 34 78 78 78 50 50 50 6 6 6
43599- 94 70 30 139 102 15 190 146 13 226 184 13
43600-232 200 30 232 195 16 215 174 15 190 146 13
43601-168 122 10 192 133 9 210 150 10 213 154 11
43602-202 150 34 182 157 106 101 98 89 2 2 6
43603- 2 2 6 78 78 78 116 116 116 58 58 58
43604- 2 2 6 22 22 22 90 90 90 46 46 46
43605- 18 18 18 6 6 6 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 0 0 0
43609- 0 0 0 0 0 0 0 0 0 0 0 0
43610- 0 0 0 0 0 0 0 0 0 0 0 0
43611- 0 0 0 0 0 0 0 0 0 0 0 0
43612- 0 0 0 0 0 0 0 0 0 0 0 0
43613- 0 0 0 0 0 0 0 0 0 0 0 0
43614- 0 0 0 0 0 0 0 0 0 0 0 0
43615- 0 0 0 0 0 0 0 0 0 0 0 0
43616- 0 0 0 0 0 0 0 0 0 0 0 0
43617- 0 0 0 0 0 0 0 0 0 10 10 10
43618- 38 38 38 86 86 86 50 50 50 6 6 6
43619-128 128 128 174 154 114 156 107 11 168 122 10
43620-198 155 10 184 144 12 197 138 11 200 144 11
43621-206 145 10 206 145 10 197 138 11 188 164 115
43622-195 195 195 198 198 198 174 174 174 14 14 14
43623- 2 2 6 22 22 22 116 116 116 116 116 116
43624- 22 22 22 2 2 6 74 74 74 70 70 70
43625- 30 30 30 10 10 10 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 0 0 0
43629- 0 0 0 0 0 0 0 0 0 0 0 0
43630- 0 0 0 0 0 0 0 0 0 0 0 0
43631- 0 0 0 0 0 0 0 0 0 0 0 0
43632- 0 0 0 0 0 0 0 0 0 0 0 0
43633- 0 0 0 0 0 0 0 0 0 0 0 0
43634- 0 0 0 0 0 0 0 0 0 0 0 0
43635- 0 0 0 0 0 0 0 0 0 0 0 0
43636- 0 0 0 0 0 0 0 0 0 0 0 0
43637- 0 0 0 0 0 0 6 6 6 18 18 18
43638- 50 50 50 101 101 101 26 26 26 10 10 10
43639-138 138 138 190 190 190 174 154 114 156 107 11
43640-197 138 11 200 144 11 197 138 11 192 133 9
43641-180 123 7 190 142 34 190 178 144 187 187 187
43642-202 202 202 221 221 221 214 214 214 66 66 66
43643- 2 2 6 2 2 6 50 50 50 62 62 62
43644- 6 6 6 2 2 6 10 10 10 90 90 90
43645- 50 50 50 18 18 18 6 6 6 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 0 0 0
43649- 0 0 0 0 0 0 0 0 0 0 0 0
43650- 0 0 0 0 0 0 0 0 0 0 0 0
43651- 0 0 0 0 0 0 0 0 0 0 0 0
43652- 0 0 0 0 0 0 0 0 0 0 0 0
43653- 0 0 0 0 0 0 0 0 0 0 0 0
43654- 0 0 0 0 0 0 0 0 0 0 0 0
43655- 0 0 0 0 0 0 0 0 0 0 0 0
43656- 0 0 0 0 0 0 0 0 0 0 0 0
43657- 0 0 0 0 0 0 10 10 10 34 34 34
43658- 74 74 74 74 74 74 2 2 6 6 6 6
43659-144 144 144 198 198 198 190 190 190 178 166 146
43660-154 121 60 156 107 11 156 107 11 168 124 44
43661-174 154 114 187 187 187 190 190 190 210 210 210
43662-246 246 246 253 253 253 253 253 253 182 182 182
43663- 6 6 6 2 2 6 2 2 6 2 2 6
43664- 2 2 6 2 2 6 2 2 6 62 62 62
43665- 74 74 74 34 34 34 14 14 14 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 0 0 0
43669- 0 0 0 0 0 0 0 0 0 0 0 0
43670- 0 0 0 0 0 0 0 0 0 0 0 0
43671- 0 0 0 0 0 0 0 0 0 0 0 0
43672- 0 0 0 0 0 0 0 0 0 0 0 0
43673- 0 0 0 0 0 0 0 0 0 0 0 0
43674- 0 0 0 0 0 0 0 0 0 0 0 0
43675- 0 0 0 0 0 0 0 0 0 0 0 0
43676- 0 0 0 0 0 0 0 0 0 0 0 0
43677- 0 0 0 10 10 10 22 22 22 54 54 54
43678- 94 94 94 18 18 18 2 2 6 46 46 46
43679-234 234 234 221 221 221 190 190 190 190 190 190
43680-190 190 190 187 187 187 187 187 187 190 190 190
43681-190 190 190 195 195 195 214 214 214 242 242 242
43682-253 253 253 253 253 253 253 253 253 253 253 253
43683- 82 82 82 2 2 6 2 2 6 2 2 6
43684- 2 2 6 2 2 6 2 2 6 14 14 14
43685- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
43689- 0 0 0 0 0 0 0 0 0 0 0 0
43690- 0 0 0 0 0 0 0 0 0 0 0 0
43691- 0 0 0 0 0 0 0 0 0 0 0 0
43692- 0 0 0 0 0 0 0 0 0 0 0 0
43693- 0 0 0 0 0 0 0 0 0 0 0 0
43694- 0 0 0 0 0 0 0 0 0 0 0 0
43695- 0 0 0 0 0 0 0 0 0 0 0 0
43696- 0 0 0 0 0 0 0 0 0 0 0 0
43697- 6 6 6 18 18 18 46 46 46 90 90 90
43698- 46 46 46 18 18 18 6 6 6 182 182 182
43699-253 253 253 246 246 246 206 206 206 190 190 190
43700-190 190 190 190 190 190 190 190 190 190 190 190
43701-206 206 206 231 231 231 250 250 250 253 253 253
43702-253 253 253 253 253 253 253 253 253 253 253 253
43703-202 202 202 14 14 14 2 2 6 2 2 6
43704- 2 2 6 2 2 6 2 2 6 2 2 6
43705- 42 42 42 86 86 86 42 42 42 18 18 18
43706- 6 6 6 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 0 0 0
43709- 0 0 0 0 0 0 0 0 0 0 0 0
43710- 0 0 0 0 0 0 0 0 0 0 0 0
43711- 0 0 0 0 0 0 0 0 0 0 0 0
43712- 0 0 0 0 0 0 0 0 0 0 0 0
43713- 0 0 0 0 0 0 0 0 0 0 0 0
43714- 0 0 0 0 0 0 0 0 0 0 0 0
43715- 0 0 0 0 0 0 0 0 0 0 0 0
43716- 0 0 0 0 0 0 0 0 0 6 6 6
43717- 14 14 14 38 38 38 74 74 74 66 66 66
43718- 2 2 6 6 6 6 90 90 90 250 250 250
43719-253 253 253 253 253 253 238 238 238 198 198 198
43720-190 190 190 190 190 190 195 195 195 221 221 221
43721-246 246 246 253 253 253 253 253 253 253 253 253
43722-253 253 253 253 253 253 253 253 253 253 253 253
43723-253 253 253 82 82 82 2 2 6 2 2 6
43724- 2 2 6 2 2 6 2 2 6 2 2 6
43725- 2 2 6 78 78 78 70 70 70 34 34 34
43726- 14 14 14 6 6 6 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 0 0 0
43729- 0 0 0 0 0 0 0 0 0 0 0 0
43730- 0 0 0 0 0 0 0 0 0 0 0 0
43731- 0 0 0 0 0 0 0 0 0 0 0 0
43732- 0 0 0 0 0 0 0 0 0 0 0 0
43733- 0 0 0 0 0 0 0 0 0 0 0 0
43734- 0 0 0 0 0 0 0 0 0 0 0 0
43735- 0 0 0 0 0 0 0 0 0 0 0 0
43736- 0 0 0 0 0 0 0 0 0 14 14 14
43737- 34 34 34 66 66 66 78 78 78 6 6 6
43738- 2 2 6 18 18 18 218 218 218 253 253 253
43739-253 253 253 253 253 253 253 253 253 246 246 246
43740-226 226 226 231 231 231 246 246 246 253 253 253
43741-253 253 253 253 253 253 253 253 253 253 253 253
43742-253 253 253 253 253 253 253 253 253 253 253 253
43743-253 253 253 178 178 178 2 2 6 2 2 6
43744- 2 2 6 2 2 6 2 2 6 2 2 6
43745- 2 2 6 18 18 18 90 90 90 62 62 62
43746- 30 30 30 10 10 10 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 0 0 0 0 0 0
43749- 0 0 0 0 0 0 0 0 0 0 0 0
43750- 0 0 0 0 0 0 0 0 0 0 0 0
43751- 0 0 0 0 0 0 0 0 0 0 0 0
43752- 0 0 0 0 0 0 0 0 0 0 0 0
43753- 0 0 0 0 0 0 0 0 0 0 0 0
43754- 0 0 0 0 0 0 0 0 0 0 0 0
43755- 0 0 0 0 0 0 0 0 0 0 0 0
43756- 0 0 0 0 0 0 10 10 10 26 26 26
43757- 58 58 58 90 90 90 18 18 18 2 2 6
43758- 2 2 6 110 110 110 253 253 253 253 253 253
43759-253 253 253 253 253 253 253 253 253 253 253 253
43760-250 250 250 253 253 253 253 253 253 253 253 253
43761-253 253 253 253 253 253 253 253 253 253 253 253
43762-253 253 253 253 253 253 253 253 253 253 253 253
43763-253 253 253 231 231 231 18 18 18 2 2 6
43764- 2 2 6 2 2 6 2 2 6 2 2 6
43765- 2 2 6 2 2 6 18 18 18 94 94 94
43766- 54 54 54 26 26 26 10 10 10 0 0 0
43767- 0 0 0 0 0 0 0 0 0 0 0 0
43768- 0 0 0 0 0 0 0 0 0 0 0 0
43769- 0 0 0 0 0 0 0 0 0 0 0 0
43770- 0 0 0 0 0 0 0 0 0 0 0 0
43771- 0 0 0 0 0 0 0 0 0 0 0 0
43772- 0 0 0 0 0 0 0 0 0 0 0 0
43773- 0 0 0 0 0 0 0 0 0 0 0 0
43774- 0 0 0 0 0 0 0 0 0 0 0 0
43775- 0 0 0 0 0 0 0 0 0 0 0 0
43776- 0 0 0 6 6 6 22 22 22 50 50 50
43777- 90 90 90 26 26 26 2 2 6 2 2 6
43778- 14 14 14 195 195 195 250 250 250 253 253 253
43779-253 253 253 253 253 253 253 253 253 253 253 253
43780-253 253 253 253 253 253 253 253 253 253 253 253
43781-253 253 253 253 253 253 253 253 253 253 253 253
43782-253 253 253 253 253 253 253 253 253 253 253 253
43783-250 250 250 242 242 242 54 54 54 2 2 6
43784- 2 2 6 2 2 6 2 2 6 2 2 6
43785- 2 2 6 2 2 6 2 2 6 38 38 38
43786- 86 86 86 50 50 50 22 22 22 6 6 6
43787- 0 0 0 0 0 0 0 0 0 0 0 0
43788- 0 0 0 0 0 0 0 0 0 0 0 0
43789- 0 0 0 0 0 0 0 0 0 0 0 0
43790- 0 0 0 0 0 0 0 0 0 0 0 0
43791- 0 0 0 0 0 0 0 0 0 0 0 0
43792- 0 0 0 0 0 0 0 0 0 0 0 0
43793- 0 0 0 0 0 0 0 0 0 0 0 0
43794- 0 0 0 0 0 0 0 0 0 0 0 0
43795- 0 0 0 0 0 0 0 0 0 0 0 0
43796- 6 6 6 14 14 14 38 38 38 82 82 82
43797- 34 34 34 2 2 6 2 2 6 2 2 6
43798- 42 42 42 195 195 195 246 246 246 253 253 253
43799-253 253 253 253 253 253 253 253 253 250 250 250
43800-242 242 242 242 242 242 250 250 250 253 253 253
43801-253 253 253 253 253 253 253 253 253 253 253 253
43802-253 253 253 250 250 250 246 246 246 238 238 238
43803-226 226 226 231 231 231 101 101 101 6 6 6
43804- 2 2 6 2 2 6 2 2 6 2 2 6
43805- 2 2 6 2 2 6 2 2 6 2 2 6
43806- 38 38 38 82 82 82 42 42 42 14 14 14
43807- 6 6 6 0 0 0 0 0 0 0 0 0
43808- 0 0 0 0 0 0 0 0 0 0 0 0
43809- 0 0 0 0 0 0 0 0 0 0 0 0
43810- 0 0 0 0 0 0 0 0 0 0 0 0
43811- 0 0 0 0 0 0 0 0 0 0 0 0
43812- 0 0 0 0 0 0 0 0 0 0 0 0
43813- 0 0 0 0 0 0 0 0 0 0 0 0
43814- 0 0 0 0 0 0 0 0 0 0 0 0
43815- 0 0 0 0 0 0 0 0 0 0 0 0
43816- 10 10 10 26 26 26 62 62 62 66 66 66
43817- 2 2 6 2 2 6 2 2 6 6 6 6
43818- 70 70 70 170 170 170 206 206 206 234 234 234
43819-246 246 246 250 250 250 250 250 250 238 238 238
43820-226 226 226 231 231 231 238 238 238 250 250 250
43821-250 250 250 250 250 250 246 246 246 231 231 231
43822-214 214 214 206 206 206 202 202 202 202 202 202
43823-198 198 198 202 202 202 182 182 182 18 18 18
43824- 2 2 6 2 2 6 2 2 6 2 2 6
43825- 2 2 6 2 2 6 2 2 6 2 2 6
43826- 2 2 6 62 62 62 66 66 66 30 30 30
43827- 10 10 10 0 0 0 0 0 0 0 0 0
43828- 0 0 0 0 0 0 0 0 0 0 0 0
43829- 0 0 0 0 0 0 0 0 0 0 0 0
43830- 0 0 0 0 0 0 0 0 0 0 0 0
43831- 0 0 0 0 0 0 0 0 0 0 0 0
43832- 0 0 0 0 0 0 0 0 0 0 0 0
43833- 0 0 0 0 0 0 0 0 0 0 0 0
43834- 0 0 0 0 0 0 0 0 0 0 0 0
43835- 0 0 0 0 0 0 0 0 0 0 0 0
43836- 14 14 14 42 42 42 82 82 82 18 18 18
43837- 2 2 6 2 2 6 2 2 6 10 10 10
43838- 94 94 94 182 182 182 218 218 218 242 242 242
43839-250 250 250 253 253 253 253 253 253 250 250 250
43840-234 234 234 253 253 253 253 253 253 253 253 253
43841-253 253 253 253 253 253 253 253 253 246 246 246
43842-238 238 238 226 226 226 210 210 210 202 202 202
43843-195 195 195 195 195 195 210 210 210 158 158 158
43844- 6 6 6 14 14 14 50 50 50 14 14 14
43845- 2 2 6 2 2 6 2 2 6 2 2 6
43846- 2 2 6 6 6 6 86 86 86 46 46 46
43847- 18 18 18 6 6 6 0 0 0 0 0 0
43848- 0 0 0 0 0 0 0 0 0 0 0 0
43849- 0 0 0 0 0 0 0 0 0 0 0 0
43850- 0 0 0 0 0 0 0 0 0 0 0 0
43851- 0 0 0 0 0 0 0 0 0 0 0 0
43852- 0 0 0 0 0 0 0 0 0 0 0 0
43853- 0 0 0 0 0 0 0 0 0 0 0 0
43854- 0 0 0 0 0 0 0 0 0 0 0 0
43855- 0 0 0 0 0 0 0 0 0 6 6 6
43856- 22 22 22 54 54 54 70 70 70 2 2 6
43857- 2 2 6 10 10 10 2 2 6 22 22 22
43858-166 166 166 231 231 231 250 250 250 253 253 253
43859-253 253 253 253 253 253 253 253 253 250 250 250
43860-242 242 242 253 253 253 253 253 253 253 253 253
43861-253 253 253 253 253 253 253 253 253 253 253 253
43862-253 253 253 253 253 253 253 253 253 246 246 246
43863-231 231 231 206 206 206 198 198 198 226 226 226
43864- 94 94 94 2 2 6 6 6 6 38 38 38
43865- 30 30 30 2 2 6 2 2 6 2 2 6
43866- 2 2 6 2 2 6 62 62 62 66 66 66
43867- 26 26 26 10 10 10 0 0 0 0 0 0
43868- 0 0 0 0 0 0 0 0 0 0 0 0
43869- 0 0 0 0 0 0 0 0 0 0 0 0
43870- 0 0 0 0 0 0 0 0 0 0 0 0
43871- 0 0 0 0 0 0 0 0 0 0 0 0
43872- 0 0 0 0 0 0 0 0 0 0 0 0
43873- 0 0 0 0 0 0 0 0 0 0 0 0
43874- 0 0 0 0 0 0 0 0 0 0 0 0
43875- 0 0 0 0 0 0 0 0 0 10 10 10
43876- 30 30 30 74 74 74 50 50 50 2 2 6
43877- 26 26 26 26 26 26 2 2 6 106 106 106
43878-238 238 238 253 253 253 253 253 253 253 253 253
43879-253 253 253 253 253 253 253 253 253 253 253 253
43880-253 253 253 253 253 253 253 253 253 253 253 253
43881-253 253 253 253 253 253 253 253 253 253 253 253
43882-253 253 253 253 253 253 253 253 253 253 253 253
43883-253 253 253 246 246 246 218 218 218 202 202 202
43884-210 210 210 14 14 14 2 2 6 2 2 6
43885- 30 30 30 22 22 22 2 2 6 2 2 6
43886- 2 2 6 2 2 6 18 18 18 86 86 86
43887- 42 42 42 14 14 14 0 0 0 0 0 0
43888- 0 0 0 0 0 0 0 0 0 0 0 0
43889- 0 0 0 0 0 0 0 0 0 0 0 0
43890- 0 0 0 0 0 0 0 0 0 0 0 0
43891- 0 0 0 0 0 0 0 0 0 0 0 0
43892- 0 0 0 0 0 0 0 0 0 0 0 0
43893- 0 0 0 0 0 0 0 0 0 0 0 0
43894- 0 0 0 0 0 0 0 0 0 0 0 0
43895- 0 0 0 0 0 0 0 0 0 14 14 14
43896- 42 42 42 90 90 90 22 22 22 2 2 6
43897- 42 42 42 2 2 6 18 18 18 218 218 218
43898-253 253 253 253 253 253 253 253 253 253 253 253
43899-253 253 253 253 253 253 253 253 253 253 253 253
43900-253 253 253 253 253 253 253 253 253 253 253 253
43901-253 253 253 253 253 253 253 253 253 253 253 253
43902-253 253 253 253 253 253 253 253 253 253 253 253
43903-253 253 253 253 253 253 250 250 250 221 221 221
43904-218 218 218 101 101 101 2 2 6 14 14 14
43905- 18 18 18 38 38 38 10 10 10 2 2 6
43906- 2 2 6 2 2 6 2 2 6 78 78 78
43907- 58 58 58 22 22 22 6 6 6 0 0 0
43908- 0 0 0 0 0 0 0 0 0 0 0 0
43909- 0 0 0 0 0 0 0 0 0 0 0 0
43910- 0 0 0 0 0 0 0 0 0 0 0 0
43911- 0 0 0 0 0 0 0 0 0 0 0 0
43912- 0 0 0 0 0 0 0 0 0 0 0 0
43913- 0 0 0 0 0 0 0 0 0 0 0 0
43914- 0 0 0 0 0 0 0 0 0 0 0 0
43915- 0 0 0 0 0 0 6 6 6 18 18 18
43916- 54 54 54 82 82 82 2 2 6 26 26 26
43917- 22 22 22 2 2 6 123 123 123 253 253 253
43918-253 253 253 253 253 253 253 253 253 253 253 253
43919-253 253 253 253 253 253 253 253 253 253 253 253
43920-253 253 253 253 253 253 253 253 253 253 253 253
43921-253 253 253 253 253 253 253 253 253 253 253 253
43922-253 253 253 253 253 253 253 253 253 253 253 253
43923-253 253 253 253 253 253 253 253 253 250 250 250
43924-238 238 238 198 198 198 6 6 6 38 38 38
43925- 58 58 58 26 26 26 38 38 38 2 2 6
43926- 2 2 6 2 2 6 2 2 6 46 46 46
43927- 78 78 78 30 30 30 10 10 10 0 0 0
43928- 0 0 0 0 0 0 0 0 0 0 0 0
43929- 0 0 0 0 0 0 0 0 0 0 0 0
43930- 0 0 0 0 0 0 0 0 0 0 0 0
43931- 0 0 0 0 0 0 0 0 0 0 0 0
43932- 0 0 0 0 0 0 0 0 0 0 0 0
43933- 0 0 0 0 0 0 0 0 0 0 0 0
43934- 0 0 0 0 0 0 0 0 0 0 0 0
43935- 0 0 0 0 0 0 10 10 10 30 30 30
43936- 74 74 74 58 58 58 2 2 6 42 42 42
43937- 2 2 6 22 22 22 231 231 231 253 253 253
43938-253 253 253 253 253 253 253 253 253 253 253 253
43939-253 253 253 253 253 253 253 253 253 250 250 250
43940-253 253 253 253 253 253 253 253 253 253 253 253
43941-253 253 253 253 253 253 253 253 253 253 253 253
43942-253 253 253 253 253 253 253 253 253 253 253 253
43943-253 253 253 253 253 253 253 253 253 253 253 253
43944-253 253 253 246 246 246 46 46 46 38 38 38
43945- 42 42 42 14 14 14 38 38 38 14 14 14
43946- 2 2 6 2 2 6 2 2 6 6 6 6
43947- 86 86 86 46 46 46 14 14 14 0 0 0
43948- 0 0 0 0 0 0 0 0 0 0 0 0
43949- 0 0 0 0 0 0 0 0 0 0 0 0
43950- 0 0 0 0 0 0 0 0 0 0 0 0
43951- 0 0 0 0 0 0 0 0 0 0 0 0
43952- 0 0 0 0 0 0 0 0 0 0 0 0
43953- 0 0 0 0 0 0 0 0 0 0 0 0
43954- 0 0 0 0 0 0 0 0 0 0 0 0
43955- 0 0 0 6 6 6 14 14 14 42 42 42
43956- 90 90 90 18 18 18 18 18 18 26 26 26
43957- 2 2 6 116 116 116 253 253 253 253 253 253
43958-253 253 253 253 253 253 253 253 253 253 253 253
43959-253 253 253 253 253 253 250 250 250 238 238 238
43960-253 253 253 253 253 253 253 253 253 253 253 253
43961-253 253 253 253 253 253 253 253 253 253 253 253
43962-253 253 253 253 253 253 253 253 253 253 253 253
43963-253 253 253 253 253 253 253 253 253 253 253 253
43964-253 253 253 253 253 253 94 94 94 6 6 6
43965- 2 2 6 2 2 6 10 10 10 34 34 34
43966- 2 2 6 2 2 6 2 2 6 2 2 6
43967- 74 74 74 58 58 58 22 22 22 6 6 6
43968- 0 0 0 0 0 0 0 0 0 0 0 0
43969- 0 0 0 0 0 0 0 0 0 0 0 0
43970- 0 0 0 0 0 0 0 0 0 0 0 0
43971- 0 0 0 0 0 0 0 0 0 0 0 0
43972- 0 0 0 0 0 0 0 0 0 0 0 0
43973- 0 0 0 0 0 0 0 0 0 0 0 0
43974- 0 0 0 0 0 0 0 0 0 0 0 0
43975- 0 0 0 10 10 10 26 26 26 66 66 66
43976- 82 82 82 2 2 6 38 38 38 6 6 6
43977- 14 14 14 210 210 210 253 253 253 253 253 253
43978-253 253 253 253 253 253 253 253 253 253 253 253
43979-253 253 253 253 253 253 246 246 246 242 242 242
43980-253 253 253 253 253 253 253 253 253 253 253 253
43981-253 253 253 253 253 253 253 253 253 253 253 253
43982-253 253 253 253 253 253 253 253 253 253 253 253
43983-253 253 253 253 253 253 253 253 253 253 253 253
43984-253 253 253 253 253 253 144 144 144 2 2 6
43985- 2 2 6 2 2 6 2 2 6 46 46 46
43986- 2 2 6 2 2 6 2 2 6 2 2 6
43987- 42 42 42 74 74 74 30 30 30 10 10 10
43988- 0 0 0 0 0 0 0 0 0 0 0 0
43989- 0 0 0 0 0 0 0 0 0 0 0 0
43990- 0 0 0 0 0 0 0 0 0 0 0 0
43991- 0 0 0 0 0 0 0 0 0 0 0 0
43992- 0 0 0 0 0 0 0 0 0 0 0 0
43993- 0 0 0 0 0 0 0 0 0 0 0 0
43994- 0 0 0 0 0 0 0 0 0 0 0 0
43995- 6 6 6 14 14 14 42 42 42 90 90 90
43996- 26 26 26 6 6 6 42 42 42 2 2 6
43997- 74 74 74 250 250 250 253 253 253 253 253 253
43998-253 253 253 253 253 253 253 253 253 253 253 253
43999-253 253 253 253 253 253 242 242 242 242 242 242
44000-253 253 253 253 253 253 253 253 253 253 253 253
44001-253 253 253 253 253 253 253 253 253 253 253 253
44002-253 253 253 253 253 253 253 253 253 253 253 253
44003-253 253 253 253 253 253 253 253 253 253 253 253
44004-253 253 253 253 253 253 182 182 182 2 2 6
44005- 2 2 6 2 2 6 2 2 6 46 46 46
44006- 2 2 6 2 2 6 2 2 6 2 2 6
44007- 10 10 10 86 86 86 38 38 38 10 10 10
44008- 0 0 0 0 0 0 0 0 0 0 0 0
44009- 0 0 0 0 0 0 0 0 0 0 0 0
44010- 0 0 0 0 0 0 0 0 0 0 0 0
44011- 0 0 0 0 0 0 0 0 0 0 0 0
44012- 0 0 0 0 0 0 0 0 0 0 0 0
44013- 0 0 0 0 0 0 0 0 0 0 0 0
44014- 0 0 0 0 0 0 0 0 0 0 0 0
44015- 10 10 10 26 26 26 66 66 66 82 82 82
44016- 2 2 6 22 22 22 18 18 18 2 2 6
44017-149 149 149 253 253 253 253 253 253 253 253 253
44018-253 253 253 253 253 253 253 253 253 253 253 253
44019-253 253 253 253 253 253 234 234 234 242 242 242
44020-253 253 253 253 253 253 253 253 253 253 253 253
44021-253 253 253 253 253 253 253 253 253 253 253 253
44022-253 253 253 253 253 253 253 253 253 253 253 253
44023-253 253 253 253 253 253 253 253 253 253 253 253
44024-253 253 253 253 253 253 206 206 206 2 2 6
44025- 2 2 6 2 2 6 2 2 6 38 38 38
44026- 2 2 6 2 2 6 2 2 6 2 2 6
44027- 6 6 6 86 86 86 46 46 46 14 14 14
44028- 0 0 0 0 0 0 0 0 0 0 0 0
44029- 0 0 0 0 0 0 0 0 0 0 0 0
44030- 0 0 0 0 0 0 0 0 0 0 0 0
44031- 0 0 0 0 0 0 0 0 0 0 0 0
44032- 0 0 0 0 0 0 0 0 0 0 0 0
44033- 0 0 0 0 0 0 0 0 0 0 0 0
44034- 0 0 0 0 0 0 0 0 0 6 6 6
44035- 18 18 18 46 46 46 86 86 86 18 18 18
44036- 2 2 6 34 34 34 10 10 10 6 6 6
44037-210 210 210 253 253 253 253 253 253 253 253 253
44038-253 253 253 253 253 253 253 253 253 253 253 253
44039-253 253 253 253 253 253 234 234 234 242 242 242
44040-253 253 253 253 253 253 253 253 253 253 253 253
44041-253 253 253 253 253 253 253 253 253 253 253 253
44042-253 253 253 253 253 253 253 253 253 253 253 253
44043-253 253 253 253 253 253 253 253 253 253 253 253
44044-253 253 253 253 253 253 221 221 221 6 6 6
44045- 2 2 6 2 2 6 6 6 6 30 30 30
44046- 2 2 6 2 2 6 2 2 6 2 2 6
44047- 2 2 6 82 82 82 54 54 54 18 18 18
44048- 6 6 6 0 0 0 0 0 0 0 0 0
44049- 0 0 0 0 0 0 0 0 0 0 0 0
44050- 0 0 0 0 0 0 0 0 0 0 0 0
44051- 0 0 0 0 0 0 0 0 0 0 0 0
44052- 0 0 0 0 0 0 0 0 0 0 0 0
44053- 0 0 0 0 0 0 0 0 0 0 0 0
44054- 0 0 0 0 0 0 0 0 0 10 10 10
44055- 26 26 26 66 66 66 62 62 62 2 2 6
44056- 2 2 6 38 38 38 10 10 10 26 26 26
44057-238 238 238 253 253 253 253 253 253 253 253 253
44058-253 253 253 253 253 253 253 253 253 253 253 253
44059-253 253 253 253 253 253 231 231 231 238 238 238
44060-253 253 253 253 253 253 253 253 253 253 253 253
44061-253 253 253 253 253 253 253 253 253 253 253 253
44062-253 253 253 253 253 253 253 253 253 253 253 253
44063-253 253 253 253 253 253 253 253 253 253 253 253
44064-253 253 253 253 253 253 231 231 231 6 6 6
44065- 2 2 6 2 2 6 10 10 10 30 30 30
44066- 2 2 6 2 2 6 2 2 6 2 2 6
44067- 2 2 6 66 66 66 58 58 58 22 22 22
44068- 6 6 6 0 0 0 0 0 0 0 0 0
44069- 0 0 0 0 0 0 0 0 0 0 0 0
44070- 0 0 0 0 0 0 0 0 0 0 0 0
44071- 0 0 0 0 0 0 0 0 0 0 0 0
44072- 0 0 0 0 0 0 0 0 0 0 0 0
44073- 0 0 0 0 0 0 0 0 0 0 0 0
44074- 0 0 0 0 0 0 0 0 0 10 10 10
44075- 38 38 38 78 78 78 6 6 6 2 2 6
44076- 2 2 6 46 46 46 14 14 14 42 42 42
44077-246 246 246 253 253 253 253 253 253 253 253 253
44078-253 253 253 253 253 253 253 253 253 253 253 253
44079-253 253 253 253 253 253 231 231 231 242 242 242
44080-253 253 253 253 253 253 253 253 253 253 253 253
44081-253 253 253 253 253 253 253 253 253 253 253 253
44082-253 253 253 253 253 253 253 253 253 253 253 253
44083-253 253 253 253 253 253 253 253 253 253 253 253
44084-253 253 253 253 253 253 234 234 234 10 10 10
44085- 2 2 6 2 2 6 22 22 22 14 14 14
44086- 2 2 6 2 2 6 2 2 6 2 2 6
44087- 2 2 6 66 66 66 62 62 62 22 22 22
44088- 6 6 6 0 0 0 0 0 0 0 0 0
44089- 0 0 0 0 0 0 0 0 0 0 0 0
44090- 0 0 0 0 0 0 0 0 0 0 0 0
44091- 0 0 0 0 0 0 0 0 0 0 0 0
44092- 0 0 0 0 0 0 0 0 0 0 0 0
44093- 0 0 0 0 0 0 0 0 0 0 0 0
44094- 0 0 0 0 0 0 6 6 6 18 18 18
44095- 50 50 50 74 74 74 2 2 6 2 2 6
44096- 14 14 14 70 70 70 34 34 34 62 62 62
44097-250 250 250 253 253 253 253 253 253 253 253 253
44098-253 253 253 253 253 253 253 253 253 253 253 253
44099-253 253 253 253 253 253 231 231 231 246 246 246
44100-253 253 253 253 253 253 253 253 253 253 253 253
44101-253 253 253 253 253 253 253 253 253 253 253 253
44102-253 253 253 253 253 253 253 253 253 253 253 253
44103-253 253 253 253 253 253 253 253 253 253 253 253
44104-253 253 253 253 253 253 234 234 234 14 14 14
44105- 2 2 6 2 2 6 30 30 30 2 2 6
44106- 2 2 6 2 2 6 2 2 6 2 2 6
44107- 2 2 6 66 66 66 62 62 62 22 22 22
44108- 6 6 6 0 0 0 0 0 0 0 0 0
44109- 0 0 0 0 0 0 0 0 0 0 0 0
44110- 0 0 0 0 0 0 0 0 0 0 0 0
44111- 0 0 0 0 0 0 0 0 0 0 0 0
44112- 0 0 0 0 0 0 0 0 0 0 0 0
44113- 0 0 0 0 0 0 0 0 0 0 0 0
44114- 0 0 0 0 0 0 6 6 6 18 18 18
44115- 54 54 54 62 62 62 2 2 6 2 2 6
44116- 2 2 6 30 30 30 46 46 46 70 70 70
44117-250 250 250 253 253 253 253 253 253 253 253 253
44118-253 253 253 253 253 253 253 253 253 253 253 253
44119-253 253 253 253 253 253 231 231 231 246 246 246
44120-253 253 253 253 253 253 253 253 253 253 253 253
44121-253 253 253 253 253 253 253 253 253 253 253 253
44122-253 253 253 253 253 253 253 253 253 253 253 253
44123-253 253 253 253 253 253 253 253 253 253 253 253
44124-253 253 253 253 253 253 226 226 226 10 10 10
44125- 2 2 6 6 6 6 30 30 30 2 2 6
44126- 2 2 6 2 2 6 2 2 6 2 2 6
44127- 2 2 6 66 66 66 58 58 58 22 22 22
44128- 6 6 6 0 0 0 0 0 0 0 0 0
44129- 0 0 0 0 0 0 0 0 0 0 0 0
44130- 0 0 0 0 0 0 0 0 0 0 0 0
44131- 0 0 0 0 0 0 0 0 0 0 0 0
44132- 0 0 0 0 0 0 0 0 0 0 0 0
44133- 0 0 0 0 0 0 0 0 0 0 0 0
44134- 0 0 0 0 0 0 6 6 6 22 22 22
44135- 58 58 58 62 62 62 2 2 6 2 2 6
44136- 2 2 6 2 2 6 30 30 30 78 78 78
44137-250 250 250 253 253 253 253 253 253 253 253 253
44138-253 253 253 253 253 253 253 253 253 253 253 253
44139-253 253 253 253 253 253 231 231 231 246 246 246
44140-253 253 253 253 253 253 253 253 253 253 253 253
44141-253 253 253 253 253 253 253 253 253 253 253 253
44142-253 253 253 253 253 253 253 253 253 253 253 253
44143-253 253 253 253 253 253 253 253 253 253 253 253
44144-253 253 253 253 253 253 206 206 206 2 2 6
44145- 22 22 22 34 34 34 18 14 6 22 22 22
44146- 26 26 26 18 18 18 6 6 6 2 2 6
44147- 2 2 6 82 82 82 54 54 54 18 18 18
44148- 6 6 6 0 0 0 0 0 0 0 0 0
44149- 0 0 0 0 0 0 0 0 0 0 0 0
44150- 0 0 0 0 0 0 0 0 0 0 0 0
44151- 0 0 0 0 0 0 0 0 0 0 0 0
44152- 0 0 0 0 0 0 0 0 0 0 0 0
44153- 0 0 0 0 0 0 0 0 0 0 0 0
44154- 0 0 0 0 0 0 6 6 6 26 26 26
44155- 62 62 62 106 106 106 74 54 14 185 133 11
44156-210 162 10 121 92 8 6 6 6 62 62 62
44157-238 238 238 253 253 253 253 253 253 253 253 253
44158-253 253 253 253 253 253 253 253 253 253 253 253
44159-253 253 253 253 253 253 231 231 231 246 246 246
44160-253 253 253 253 253 253 253 253 253 253 253 253
44161-253 253 253 253 253 253 253 253 253 253 253 253
44162-253 253 253 253 253 253 253 253 253 253 253 253
44163-253 253 253 253 253 253 253 253 253 253 253 253
44164-253 253 253 253 253 253 158 158 158 18 18 18
44165- 14 14 14 2 2 6 2 2 6 2 2 6
44166- 6 6 6 18 18 18 66 66 66 38 38 38
44167- 6 6 6 94 94 94 50 50 50 18 18 18
44168- 6 6 6 0 0 0 0 0 0 0 0 0
44169- 0 0 0 0 0 0 0 0 0 0 0 0
44170- 0 0 0 0 0 0 0 0 0 0 0 0
44171- 0 0 0 0 0 0 0 0 0 0 0 0
44172- 0 0 0 0 0 0 0 0 0 0 0 0
44173- 0 0 0 0 0 0 0 0 0 6 6 6
44174- 10 10 10 10 10 10 18 18 18 38 38 38
44175- 78 78 78 142 134 106 216 158 10 242 186 14
44176-246 190 14 246 190 14 156 118 10 10 10 10
44177- 90 90 90 238 238 238 253 253 253 253 253 253
44178-253 253 253 253 253 253 253 253 253 253 253 253
44179-253 253 253 253 253 253 231 231 231 250 250 250
44180-253 253 253 253 253 253 253 253 253 253 253 253
44181-253 253 253 253 253 253 253 253 253 253 253 253
44182-253 253 253 253 253 253 253 253 253 253 253 253
44183-253 253 253 253 253 253 253 253 253 246 230 190
44184-238 204 91 238 204 91 181 142 44 37 26 9
44185- 2 2 6 2 2 6 2 2 6 2 2 6
44186- 2 2 6 2 2 6 38 38 38 46 46 46
44187- 26 26 26 106 106 106 54 54 54 18 18 18
44188- 6 6 6 0 0 0 0 0 0 0 0 0
44189- 0 0 0 0 0 0 0 0 0 0 0 0
44190- 0 0 0 0 0 0 0 0 0 0 0 0
44191- 0 0 0 0 0 0 0 0 0 0 0 0
44192- 0 0 0 0 0 0 0 0 0 0 0 0
44193- 0 0 0 6 6 6 14 14 14 22 22 22
44194- 30 30 30 38 38 38 50 50 50 70 70 70
44195-106 106 106 190 142 34 226 170 11 242 186 14
44196-246 190 14 246 190 14 246 190 14 154 114 10
44197- 6 6 6 74 74 74 226 226 226 253 253 253
44198-253 253 253 253 253 253 253 253 253 253 253 253
44199-253 253 253 253 253 253 231 231 231 250 250 250
44200-253 253 253 253 253 253 253 253 253 253 253 253
44201-253 253 253 253 253 253 253 253 253 253 253 253
44202-253 253 253 253 253 253 253 253 253 253 253 253
44203-253 253 253 253 253 253 253 253 253 228 184 62
44204-241 196 14 241 208 19 232 195 16 38 30 10
44205- 2 2 6 2 2 6 2 2 6 2 2 6
44206- 2 2 6 6 6 6 30 30 30 26 26 26
44207-203 166 17 154 142 90 66 66 66 26 26 26
44208- 6 6 6 0 0 0 0 0 0 0 0 0
44209- 0 0 0 0 0 0 0 0 0 0 0 0
44210- 0 0 0 0 0 0 0 0 0 0 0 0
44211- 0 0 0 0 0 0 0 0 0 0 0 0
44212- 0 0 0 0 0 0 0 0 0 0 0 0
44213- 6 6 6 18 18 18 38 38 38 58 58 58
44214- 78 78 78 86 86 86 101 101 101 123 123 123
44215-175 146 61 210 150 10 234 174 13 246 186 14
44216-246 190 14 246 190 14 246 190 14 238 190 10
44217-102 78 10 2 2 6 46 46 46 198 198 198
44218-253 253 253 253 253 253 253 253 253 253 253 253
44219-253 253 253 253 253 253 234 234 234 242 242 242
44220-253 253 253 253 253 253 253 253 253 253 253 253
44221-253 253 253 253 253 253 253 253 253 253 253 253
44222-253 253 253 253 253 253 253 253 253 253 253 253
44223-253 253 253 253 253 253 253 253 253 224 178 62
44224-242 186 14 241 196 14 210 166 10 22 18 6
44225- 2 2 6 2 2 6 2 2 6 2 2 6
44226- 2 2 6 2 2 6 6 6 6 121 92 8
44227-238 202 15 232 195 16 82 82 82 34 34 34
44228- 10 10 10 0 0 0 0 0 0 0 0 0
44229- 0 0 0 0 0 0 0 0 0 0 0 0
44230- 0 0 0 0 0 0 0 0 0 0 0 0
44231- 0 0 0 0 0 0 0 0 0 0 0 0
44232- 0 0 0 0 0 0 0 0 0 0 0 0
44233- 14 14 14 38 38 38 70 70 70 154 122 46
44234-190 142 34 200 144 11 197 138 11 197 138 11
44235-213 154 11 226 170 11 242 186 14 246 190 14
44236-246 190 14 246 190 14 246 190 14 246 190 14
44237-225 175 15 46 32 6 2 2 6 22 22 22
44238-158 158 158 250 250 250 253 253 253 253 253 253
44239-253 253 253 253 253 253 253 253 253 253 253 253
44240-253 253 253 253 253 253 253 253 253 253 253 253
44241-253 253 253 253 253 253 253 253 253 253 253 253
44242-253 253 253 253 253 253 253 253 253 253 253 253
44243-253 253 253 250 250 250 242 242 242 224 178 62
44244-239 182 13 236 186 11 213 154 11 46 32 6
44245- 2 2 6 2 2 6 2 2 6 2 2 6
44246- 2 2 6 2 2 6 61 42 6 225 175 15
44247-238 190 10 236 186 11 112 100 78 42 42 42
44248- 14 14 14 0 0 0 0 0 0 0 0 0
44249- 0 0 0 0 0 0 0 0 0 0 0 0
44250- 0 0 0 0 0 0 0 0 0 0 0 0
44251- 0 0 0 0 0 0 0 0 0 0 0 0
44252- 0 0 0 0 0 0 0 0 0 6 6 6
44253- 22 22 22 54 54 54 154 122 46 213 154 11
44254-226 170 11 230 174 11 226 170 11 226 170 11
44255-236 178 12 242 186 14 246 190 14 246 190 14
44256-246 190 14 246 190 14 246 190 14 246 190 14
44257-241 196 14 184 144 12 10 10 10 2 2 6
44258- 6 6 6 116 116 116 242 242 242 253 253 253
44259-253 253 253 253 253 253 253 253 253 253 253 253
44260-253 253 253 253 253 253 253 253 253 253 253 253
44261-253 253 253 253 253 253 253 253 253 253 253 253
44262-253 253 253 253 253 253 253 253 253 253 253 253
44263-253 253 253 231 231 231 198 198 198 214 170 54
44264-236 178 12 236 178 12 210 150 10 137 92 6
44265- 18 14 6 2 2 6 2 2 6 2 2 6
44266- 6 6 6 70 47 6 200 144 11 236 178 12
44267-239 182 13 239 182 13 124 112 88 58 58 58
44268- 22 22 22 6 6 6 0 0 0 0 0 0
44269- 0 0 0 0 0 0 0 0 0 0 0 0
44270- 0 0 0 0 0 0 0 0 0 0 0 0
44271- 0 0 0 0 0 0 0 0 0 0 0 0
44272- 0 0 0 0 0 0 0 0 0 10 10 10
44273- 30 30 30 70 70 70 180 133 36 226 170 11
44274-239 182 13 242 186 14 242 186 14 246 186 14
44275-246 190 14 246 190 14 246 190 14 246 190 14
44276-246 190 14 246 190 14 246 190 14 246 190 14
44277-246 190 14 232 195 16 98 70 6 2 2 6
44278- 2 2 6 2 2 6 66 66 66 221 221 221
44279-253 253 253 253 253 253 253 253 253 253 253 253
44280-253 253 253 253 253 253 253 253 253 253 253 253
44281-253 253 253 253 253 253 253 253 253 253 253 253
44282-253 253 253 253 253 253 253 253 253 253 253 253
44283-253 253 253 206 206 206 198 198 198 214 166 58
44284-230 174 11 230 174 11 216 158 10 192 133 9
44285-163 110 8 116 81 8 102 78 10 116 81 8
44286-167 114 7 197 138 11 226 170 11 239 182 13
44287-242 186 14 242 186 14 162 146 94 78 78 78
44288- 34 34 34 14 14 14 6 6 6 0 0 0
44289- 0 0 0 0 0 0 0 0 0 0 0 0
44290- 0 0 0 0 0 0 0 0 0 0 0 0
44291- 0 0 0 0 0 0 0 0 0 0 0 0
44292- 0 0 0 0 0 0 0 0 0 6 6 6
44293- 30 30 30 78 78 78 190 142 34 226 170 11
44294-239 182 13 246 190 14 246 190 14 246 190 14
44295-246 190 14 246 190 14 246 190 14 246 190 14
44296-246 190 14 246 190 14 246 190 14 246 190 14
44297-246 190 14 241 196 14 203 166 17 22 18 6
44298- 2 2 6 2 2 6 2 2 6 38 38 38
44299-218 218 218 253 253 253 253 253 253 253 253 253
44300-253 253 253 253 253 253 253 253 253 253 253 253
44301-253 253 253 253 253 253 253 253 253 253 253 253
44302-253 253 253 253 253 253 253 253 253 253 253 253
44303-250 250 250 206 206 206 198 198 198 202 162 69
44304-226 170 11 236 178 12 224 166 10 210 150 10
44305-200 144 11 197 138 11 192 133 9 197 138 11
44306-210 150 10 226 170 11 242 186 14 246 190 14
44307-246 190 14 246 186 14 225 175 15 124 112 88
44308- 62 62 62 30 30 30 14 14 14 6 6 6
44309- 0 0 0 0 0 0 0 0 0 0 0 0
44310- 0 0 0 0 0 0 0 0 0 0 0 0
44311- 0 0 0 0 0 0 0 0 0 0 0 0
44312- 0 0 0 0 0 0 0 0 0 10 10 10
44313- 30 30 30 78 78 78 174 135 50 224 166 10
44314-239 182 13 246 190 14 246 190 14 246 190 14
44315-246 190 14 246 190 14 246 190 14 246 190 14
44316-246 190 14 246 190 14 246 190 14 246 190 14
44317-246 190 14 246 190 14 241 196 14 139 102 15
44318- 2 2 6 2 2 6 2 2 6 2 2 6
44319- 78 78 78 250 250 250 253 253 253 253 253 253
44320-253 253 253 253 253 253 253 253 253 253 253 253
44321-253 253 253 253 253 253 253 253 253 253 253 253
44322-253 253 253 253 253 253 253 253 253 253 253 253
44323-250 250 250 214 214 214 198 198 198 190 150 46
44324-219 162 10 236 178 12 234 174 13 224 166 10
44325-216 158 10 213 154 11 213 154 11 216 158 10
44326-226 170 11 239 182 13 246 190 14 246 190 14
44327-246 190 14 246 190 14 242 186 14 206 162 42
44328-101 101 101 58 58 58 30 30 30 14 14 14
44329- 6 6 6 0 0 0 0 0 0 0 0 0
44330- 0 0 0 0 0 0 0 0 0 0 0 0
44331- 0 0 0 0 0 0 0 0 0 0 0 0
44332- 0 0 0 0 0 0 0 0 0 10 10 10
44333- 30 30 30 74 74 74 174 135 50 216 158 10
44334-236 178 12 246 190 14 246 190 14 246 190 14
44335-246 190 14 246 190 14 246 190 14 246 190 14
44336-246 190 14 246 190 14 246 190 14 246 190 14
44337-246 190 14 246 190 14 241 196 14 226 184 13
44338- 61 42 6 2 2 6 2 2 6 2 2 6
44339- 22 22 22 238 238 238 253 253 253 253 253 253
44340-253 253 253 253 253 253 253 253 253 253 253 253
44341-253 253 253 253 253 253 253 253 253 253 253 253
44342-253 253 253 253 253 253 253 253 253 253 253 253
44343-253 253 253 226 226 226 187 187 187 180 133 36
44344-216 158 10 236 178 12 239 182 13 236 178 12
44345-230 174 11 226 170 11 226 170 11 230 174 11
44346-236 178 12 242 186 14 246 190 14 246 190 14
44347-246 190 14 246 190 14 246 186 14 239 182 13
44348-206 162 42 106 106 106 66 66 66 34 34 34
44349- 14 14 14 6 6 6 0 0 0 0 0 0
44350- 0 0 0 0 0 0 0 0 0 0 0 0
44351- 0 0 0 0 0 0 0 0 0 0 0 0
44352- 0 0 0 0 0 0 0 0 0 6 6 6
44353- 26 26 26 70 70 70 163 133 67 213 154 11
44354-236 178 12 246 190 14 246 190 14 246 190 14
44355-246 190 14 246 190 14 246 190 14 246 190 14
44356-246 190 14 246 190 14 246 190 14 246 190 14
44357-246 190 14 246 190 14 246 190 14 241 196 14
44358-190 146 13 18 14 6 2 2 6 2 2 6
44359- 46 46 46 246 246 246 253 253 253 253 253 253
44360-253 253 253 253 253 253 253 253 253 253 253 253
44361-253 253 253 253 253 253 253 253 253 253 253 253
44362-253 253 253 253 253 253 253 253 253 253 253 253
44363-253 253 253 221 221 221 86 86 86 156 107 11
44364-216 158 10 236 178 12 242 186 14 246 186 14
44365-242 186 14 239 182 13 239 182 13 242 186 14
44366-242 186 14 246 186 14 246 190 14 246 190 14
44367-246 190 14 246 190 14 246 190 14 246 190 14
44368-242 186 14 225 175 15 142 122 72 66 66 66
44369- 30 30 30 10 10 10 0 0 0 0 0 0
44370- 0 0 0 0 0 0 0 0 0 0 0 0
44371- 0 0 0 0 0 0 0 0 0 0 0 0
44372- 0 0 0 0 0 0 0 0 0 6 6 6
44373- 26 26 26 70 70 70 163 133 67 210 150 10
44374-236 178 12 246 190 14 246 190 14 246 190 14
44375-246 190 14 246 190 14 246 190 14 246 190 14
44376-246 190 14 246 190 14 246 190 14 246 190 14
44377-246 190 14 246 190 14 246 190 14 246 190 14
44378-232 195 16 121 92 8 34 34 34 106 106 106
44379-221 221 221 253 253 253 253 253 253 253 253 253
44380-253 253 253 253 253 253 253 253 253 253 253 253
44381-253 253 253 253 253 253 253 253 253 253 253 253
44382-253 253 253 253 253 253 253 253 253 253 253 253
44383-242 242 242 82 82 82 18 14 6 163 110 8
44384-216 158 10 236 178 12 242 186 14 246 190 14
44385-246 190 14 246 190 14 246 190 14 246 190 14
44386-246 190 14 246 190 14 246 190 14 246 190 14
44387-246 190 14 246 190 14 246 190 14 246 190 14
44388-246 190 14 246 190 14 242 186 14 163 133 67
44389- 46 46 46 18 18 18 6 6 6 0 0 0
44390- 0 0 0 0 0 0 0 0 0 0 0 0
44391- 0 0 0 0 0 0 0 0 0 0 0 0
44392- 0 0 0 0 0 0 0 0 0 10 10 10
44393- 30 30 30 78 78 78 163 133 67 210 150 10
44394-236 178 12 246 186 14 246 190 14 246 190 14
44395-246 190 14 246 190 14 246 190 14 246 190 14
44396-246 190 14 246 190 14 246 190 14 246 190 14
44397-246 190 14 246 190 14 246 190 14 246 190 14
44398-241 196 14 215 174 15 190 178 144 253 253 253
44399-253 253 253 253 253 253 253 253 253 253 253 253
44400-253 253 253 253 253 253 253 253 253 253 253 253
44401-253 253 253 253 253 253 253 253 253 253 253 253
44402-253 253 253 253 253 253 253 253 253 218 218 218
44403- 58 58 58 2 2 6 22 18 6 167 114 7
44404-216 158 10 236 178 12 246 186 14 246 190 14
44405-246 190 14 246 190 14 246 190 14 246 190 14
44406-246 190 14 246 190 14 246 190 14 246 190 14
44407-246 190 14 246 190 14 246 190 14 246 190 14
44408-246 190 14 246 186 14 242 186 14 190 150 46
44409- 54 54 54 22 22 22 6 6 6 0 0 0
44410- 0 0 0 0 0 0 0 0 0 0 0 0
44411- 0 0 0 0 0 0 0 0 0 0 0 0
44412- 0 0 0 0 0 0 0 0 0 14 14 14
44413- 38 38 38 86 86 86 180 133 36 213 154 11
44414-236 178 12 246 186 14 246 190 14 246 190 14
44415-246 190 14 246 190 14 246 190 14 246 190 14
44416-246 190 14 246 190 14 246 190 14 246 190 14
44417-246 190 14 246 190 14 246 190 14 246 190 14
44418-246 190 14 232 195 16 190 146 13 214 214 214
44419-253 253 253 253 253 253 253 253 253 253 253 253
44420-253 253 253 253 253 253 253 253 253 253 253 253
44421-253 253 253 253 253 253 253 253 253 253 253 253
44422-253 253 253 250 250 250 170 170 170 26 26 26
44423- 2 2 6 2 2 6 37 26 9 163 110 8
44424-219 162 10 239 182 13 246 186 14 246 190 14
44425-246 190 14 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 186 14 236 178 12 224 166 10 142 122 72
44429- 46 46 46 18 18 18 6 6 6 0 0 0
44430- 0 0 0 0 0 0 0 0 0 0 0 0
44431- 0 0 0 0 0 0 0 0 0 0 0 0
44432- 0 0 0 0 0 0 6 6 6 18 18 18
44433- 50 50 50 109 106 95 192 133 9 224 166 10
44434-242 186 14 246 190 14 246 190 14 246 190 14
44435-246 190 14 246 190 14 246 190 14 246 190 14
44436-246 190 14 246 190 14 246 190 14 246 190 14
44437-246 190 14 246 190 14 246 190 14 246 190 14
44438-242 186 14 226 184 13 210 162 10 142 110 46
44439-226 226 226 253 253 253 253 253 253 253 253 253
44440-253 253 253 253 253 253 253 253 253 253 253 253
44441-253 253 253 253 253 253 253 253 253 253 253 253
44442-198 198 198 66 66 66 2 2 6 2 2 6
44443- 2 2 6 2 2 6 50 34 6 156 107 11
44444-219 162 10 239 182 13 246 186 14 246 190 14
44445-246 190 14 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 242 186 14
44448-234 174 13 213 154 11 154 122 46 66 66 66
44449- 30 30 30 10 10 10 0 0 0 0 0 0
44450- 0 0 0 0 0 0 0 0 0 0 0 0
44451- 0 0 0 0 0 0 0 0 0 0 0 0
44452- 0 0 0 0 0 0 6 6 6 22 22 22
44453- 58 58 58 154 121 60 206 145 10 234 174 13
44454-242 186 14 246 186 14 246 190 14 246 190 14
44455-246 190 14 246 190 14 246 190 14 246 190 14
44456-246 190 14 246 190 14 246 190 14 246 190 14
44457-246 190 14 246 190 14 246 190 14 246 190 14
44458-246 186 14 236 178 12 210 162 10 163 110 8
44459- 61 42 6 138 138 138 218 218 218 250 250 250
44460-253 253 253 253 253 253 253 253 253 250 250 250
44461-242 242 242 210 210 210 144 144 144 66 66 66
44462- 6 6 6 2 2 6 2 2 6 2 2 6
44463- 2 2 6 2 2 6 61 42 6 163 110 8
44464-216 158 10 236 178 12 246 190 14 246 190 14
44465-246 190 14 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 239 182 13 230 174 11 216 158 10
44468-190 142 34 124 112 88 70 70 70 38 38 38
44469- 18 18 18 6 6 6 0 0 0 0 0 0
44470- 0 0 0 0 0 0 0 0 0 0 0 0
44471- 0 0 0 0 0 0 0 0 0 0 0 0
44472- 0 0 0 0 0 0 6 6 6 22 22 22
44473- 62 62 62 168 124 44 206 145 10 224 166 10
44474-236 178 12 239 182 13 242 186 14 242 186 14
44475-246 186 14 246 190 14 246 190 14 246 190 14
44476-246 190 14 246 190 14 246 190 14 246 190 14
44477-246 190 14 246 190 14 246 190 14 246 190 14
44478-246 190 14 236 178 12 216 158 10 175 118 6
44479- 80 54 7 2 2 6 6 6 6 30 30 30
44480- 54 54 54 62 62 62 50 50 50 38 38 38
44481- 14 14 14 2 2 6 2 2 6 2 2 6
44482- 2 2 6 2 2 6 2 2 6 2 2 6
44483- 2 2 6 6 6 6 80 54 7 167 114 7
44484-213 154 11 236 178 12 246 190 14 246 190 14
44485-246 190 14 246 190 14 246 190 14 246 190 14
44486-246 190 14 242 186 14 239 182 13 239 182 13
44487-230 174 11 210 150 10 174 135 50 124 112 88
44488- 82 82 82 54 54 54 34 34 34 18 18 18
44489- 6 6 6 0 0 0 0 0 0 0 0 0
44490- 0 0 0 0 0 0 0 0 0 0 0 0
44491- 0 0 0 0 0 0 0 0 0 0 0 0
44492- 0 0 0 0 0 0 6 6 6 18 18 18
44493- 50 50 50 158 118 36 192 133 9 200 144 11
44494-216 158 10 219 162 10 224 166 10 226 170 11
44495-230 174 11 236 178 12 239 182 13 239 182 13
44496-242 186 14 246 186 14 246 190 14 246 190 14
44497-246 190 14 246 190 14 246 190 14 246 190 14
44498-246 186 14 230 174 11 210 150 10 163 110 8
44499-104 69 6 10 10 10 2 2 6 2 2 6
44500- 2 2 6 2 2 6 2 2 6 2 2 6
44501- 2 2 6 2 2 6 2 2 6 2 2 6
44502- 2 2 6 2 2 6 2 2 6 2 2 6
44503- 2 2 6 6 6 6 91 60 6 167 114 7
44504-206 145 10 230 174 11 242 186 14 246 190 14
44505-246 190 14 246 190 14 246 186 14 242 186 14
44506-239 182 13 230 174 11 224 166 10 213 154 11
44507-180 133 36 124 112 88 86 86 86 58 58 58
44508- 38 38 38 22 22 22 10 10 10 6 6 6
44509- 0 0 0 0 0 0 0 0 0 0 0 0
44510- 0 0 0 0 0 0 0 0 0 0 0 0
44511- 0 0 0 0 0 0 0 0 0 0 0 0
44512- 0 0 0 0 0 0 0 0 0 14 14 14
44513- 34 34 34 70 70 70 138 110 50 158 118 36
44514-167 114 7 180 123 7 192 133 9 197 138 11
44515-200 144 11 206 145 10 213 154 11 219 162 10
44516-224 166 10 230 174 11 239 182 13 242 186 14
44517-246 186 14 246 186 14 246 186 14 246 186 14
44518-239 182 13 216 158 10 185 133 11 152 99 6
44519-104 69 6 18 14 6 2 2 6 2 2 6
44520- 2 2 6 2 2 6 2 2 6 2 2 6
44521- 2 2 6 2 2 6 2 2 6 2 2 6
44522- 2 2 6 2 2 6 2 2 6 2 2 6
44523- 2 2 6 6 6 6 80 54 7 152 99 6
44524-192 133 9 219 162 10 236 178 12 239 182 13
44525-246 186 14 242 186 14 239 182 13 236 178 12
44526-224 166 10 206 145 10 192 133 9 154 121 60
44527- 94 94 94 62 62 62 42 42 42 22 22 22
44528- 14 14 14 6 6 6 0 0 0 0 0 0
44529- 0 0 0 0 0 0 0 0 0 0 0 0
44530- 0 0 0 0 0 0 0 0 0 0 0 0
44531- 0 0 0 0 0 0 0 0 0 0 0 0
44532- 0 0 0 0 0 0 0 0 0 6 6 6
44533- 18 18 18 34 34 34 58 58 58 78 78 78
44534-101 98 89 124 112 88 142 110 46 156 107 11
44535-163 110 8 167 114 7 175 118 6 180 123 7
44536-185 133 11 197 138 11 210 150 10 219 162 10
44537-226 170 11 236 178 12 236 178 12 234 174 13
44538-219 162 10 197 138 11 163 110 8 130 83 6
44539- 91 60 6 10 10 10 2 2 6 2 2 6
44540- 18 18 18 38 38 38 38 38 38 38 38 38
44541- 38 38 38 38 38 38 38 38 38 38 38 38
44542- 38 38 38 38 38 38 26 26 26 2 2 6
44543- 2 2 6 6 6 6 70 47 6 137 92 6
44544-175 118 6 200 144 11 219 162 10 230 174 11
44545-234 174 13 230 174 11 219 162 10 210 150 10
44546-192 133 9 163 110 8 124 112 88 82 82 82
44547- 50 50 50 30 30 30 14 14 14 6 6 6
44548- 0 0 0 0 0 0 0 0 0 0 0 0
44549- 0 0 0 0 0 0 0 0 0 0 0 0
44550- 0 0 0 0 0 0 0 0 0 0 0 0
44551- 0 0 0 0 0 0 0 0 0 0 0 0
44552- 0 0 0 0 0 0 0 0 0 0 0 0
44553- 6 6 6 14 14 14 22 22 22 34 34 34
44554- 42 42 42 58 58 58 74 74 74 86 86 86
44555-101 98 89 122 102 70 130 98 46 121 87 25
44556-137 92 6 152 99 6 163 110 8 180 123 7
44557-185 133 11 197 138 11 206 145 10 200 144 11
44558-180 123 7 156 107 11 130 83 6 104 69 6
44559- 50 34 6 54 54 54 110 110 110 101 98 89
44560- 86 86 86 82 82 82 78 78 78 78 78 78
44561- 78 78 78 78 78 78 78 78 78 78 78 78
44562- 78 78 78 82 82 82 86 86 86 94 94 94
44563-106 106 106 101 101 101 86 66 34 124 80 6
44564-156 107 11 180 123 7 192 133 9 200 144 11
44565-206 145 10 200 144 11 192 133 9 175 118 6
44566-139 102 15 109 106 95 70 70 70 42 42 42
44567- 22 22 22 10 10 10 0 0 0 0 0 0
44568- 0 0 0 0 0 0 0 0 0 0 0 0
44569- 0 0 0 0 0 0 0 0 0 0 0 0
44570- 0 0 0 0 0 0 0 0 0 0 0 0
44571- 0 0 0 0 0 0 0 0 0 0 0 0
44572- 0 0 0 0 0 0 0 0 0 0 0 0
44573- 0 0 0 0 0 0 6 6 6 10 10 10
44574- 14 14 14 22 22 22 30 30 30 38 38 38
44575- 50 50 50 62 62 62 74 74 74 90 90 90
44576-101 98 89 112 100 78 121 87 25 124 80 6
44577-137 92 6 152 99 6 152 99 6 152 99 6
44578-138 86 6 124 80 6 98 70 6 86 66 30
44579-101 98 89 82 82 82 58 58 58 46 46 46
44580- 38 38 38 34 34 34 34 34 34 34 34 34
44581- 34 34 34 34 34 34 34 34 34 34 34 34
44582- 34 34 34 34 34 34 38 38 38 42 42 42
44583- 54 54 54 82 82 82 94 86 76 91 60 6
44584-134 86 6 156 107 11 167 114 7 175 118 6
44585-175 118 6 167 114 7 152 99 6 121 87 25
44586-101 98 89 62 62 62 34 34 34 18 18 18
44587- 6 6 6 0 0 0 0 0 0 0 0 0
44588- 0 0 0 0 0 0 0 0 0 0 0 0
44589- 0 0 0 0 0 0 0 0 0 0 0 0
44590- 0 0 0 0 0 0 0 0 0 0 0 0
44591- 0 0 0 0 0 0 0 0 0 0 0 0
44592- 0 0 0 0 0 0 0 0 0 0 0 0
44593- 0 0 0 0 0 0 0 0 0 0 0 0
44594- 0 0 0 6 6 6 6 6 6 10 10 10
44595- 18 18 18 22 22 22 30 30 30 42 42 42
44596- 50 50 50 66 66 66 86 86 86 101 98 89
44597-106 86 58 98 70 6 104 69 6 104 69 6
44598-104 69 6 91 60 6 82 62 34 90 90 90
44599- 62 62 62 38 38 38 22 22 22 14 14 14
44600- 10 10 10 10 10 10 10 10 10 10 10 10
44601- 10 10 10 10 10 10 6 6 6 10 10 10
44602- 10 10 10 10 10 10 10 10 10 14 14 14
44603- 22 22 22 42 42 42 70 70 70 89 81 66
44604- 80 54 7 104 69 6 124 80 6 137 92 6
44605-134 86 6 116 81 8 100 82 52 86 86 86
44606- 58 58 58 30 30 30 14 14 14 6 6 6
44607- 0 0 0 0 0 0 0 0 0 0 0 0
44608- 0 0 0 0 0 0 0 0 0 0 0 0
44609- 0 0 0 0 0 0 0 0 0 0 0 0
44610- 0 0 0 0 0 0 0 0 0 0 0 0
44611- 0 0 0 0 0 0 0 0 0 0 0 0
44612- 0 0 0 0 0 0 0 0 0 0 0 0
44613- 0 0 0 0 0 0 0 0 0 0 0 0
44614- 0 0 0 0 0 0 0 0 0 0 0 0
44615- 0 0 0 6 6 6 10 10 10 14 14 14
44616- 18 18 18 26 26 26 38 38 38 54 54 54
44617- 70 70 70 86 86 86 94 86 76 89 81 66
44618- 89 81 66 86 86 86 74 74 74 50 50 50
44619- 30 30 30 14 14 14 6 6 6 0 0 0
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- 6 6 6 18 18 18 34 34 34 58 58 58
44624- 82 82 82 89 81 66 89 81 66 89 81 66
44625- 94 86 66 94 86 76 74 74 74 50 50 50
44626- 26 26 26 14 14 14 6 6 6 0 0 0
44627- 0 0 0 0 0 0 0 0 0 0 0 0
44628- 0 0 0 0 0 0 0 0 0 0 0 0
44629- 0 0 0 0 0 0 0 0 0 0 0 0
44630- 0 0 0 0 0 0 0 0 0 0 0 0
44631- 0 0 0 0 0 0 0 0 0 0 0 0
44632- 0 0 0 0 0 0 0 0 0 0 0 0
44633- 0 0 0 0 0 0 0 0 0 0 0 0
44634- 0 0 0 0 0 0 0 0 0 0 0 0
44635- 0 0 0 0 0 0 0 0 0 0 0 0
44636- 6 6 6 6 6 6 14 14 14 18 18 18
44637- 30 30 30 38 38 38 46 46 46 54 54 54
44638- 50 50 50 42 42 42 30 30 30 18 18 18
44639- 10 10 10 0 0 0 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 6 6 6 14 14 14 26 26 26
44644- 38 38 38 50 50 50 58 58 58 58 58 58
44645- 54 54 54 42 42 42 30 30 30 18 18 18
44646- 10 10 10 0 0 0 0 0 0 0 0 0
44647- 0 0 0 0 0 0 0 0 0 0 0 0
44648- 0 0 0 0 0 0 0 0 0 0 0 0
44649- 0 0 0 0 0 0 0 0 0 0 0 0
44650- 0 0 0 0 0 0 0 0 0 0 0 0
44651- 0 0 0 0 0 0 0 0 0 0 0 0
44652- 0 0 0 0 0 0 0 0 0 0 0 0
44653- 0 0 0 0 0 0 0 0 0 0 0 0
44654- 0 0 0 0 0 0 0 0 0 0 0 0
44655- 0 0 0 0 0 0 0 0 0 0 0 0
44656- 0 0 0 0 0 0 0 0 0 6 6 6
44657- 6 6 6 10 10 10 14 14 14 18 18 18
44658- 18 18 18 14 14 14 10 10 10 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 6 6 6
44664- 14 14 14 18 18 18 22 22 22 22 22 22
44665- 18 18 18 14 14 14 10 10 10 6 6 6
44666- 0 0 0 0 0 0 0 0 0 0 0 0
44667- 0 0 0 0 0 0 0 0 0 0 0 0
44668- 0 0 0 0 0 0 0 0 0 0 0 0
44669- 0 0 0 0 0 0 0 0 0 0 0 0
44670- 0 0 0 0 0 0 0 0 0 0 0 0
44671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44684+4 4 4 4 4 4
44685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44698+4 4 4 4 4 4
44699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44712+4 4 4 4 4 4
44713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44726+4 4 4 4 4 4
44727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44740+4 4 4 4 4 4
44741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44754+4 4 4 4 4 4
44755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44759+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
44760+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
44761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44764+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
44765+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44766+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
44767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44768+4 4 4 4 4 4
44769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44773+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
44774+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
44775+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44778+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
44779+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
44780+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
44781+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44782+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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
44788+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
44789+0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
44793+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
44794+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
44795+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
44796+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 5 5 5 5 5 5 2 2 2 0 0 0
44801+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
44802+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
44803+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
44806+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
44807+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
44808+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
44809+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
44810+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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
44815+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
44816+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
44817+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
44818+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44819+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
44820+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
44821+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
44822+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
44823+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
44824+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 5 5 5
44828+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
44829+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
44830+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
44831+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
44832+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44833+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
44834+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
44835+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
44836+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
44837+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
44838+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 5 5 5 3 3 3
44842+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
44843+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
44844+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
44845+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
44846+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
44847+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
44848+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
44849+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
44850+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
44851+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
44852+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 2 2 2 0 0 0 4 0 0
44856+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
44857+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
44858+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
44859+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
44860+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
44861+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
44862+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
44863+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
44864+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
44865+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
44866+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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
44870+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
44871+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
44872+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
44873+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
44874+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
44875+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
44876+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
44877+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
44878+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
44879+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
44880+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+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
44884+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
44885+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
44886+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
44887+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
44888+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
44889+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
44890+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
44891+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
44892+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
44893+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
44894+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 3 3 3 0 0 0
44897+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
44898+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
44899+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
44900+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
44901+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
44902+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
44903+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
44904+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
44905+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
44906+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
44907+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
44908+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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
44911+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
44912+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
44913+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
44914+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
44915+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
44916+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
44917+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
44918+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
44919+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
44920+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
44921+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
44922+0 0 0 4 4 4
44923+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
44924+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
44925+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
44926+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
44927+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
44928+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
44929+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
44930+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
44931+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
44932+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
44933+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
44934+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
44935+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
44936+2 0 0 0 0 0
44937+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
44938+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
44939+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
44940+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
44941+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
44942+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
44943+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
44944+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
44945+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
44946+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
44947+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
44948+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
44949+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
44950+37 38 37 0 0 0
44951+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44952+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
44953+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
44954+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
44955+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
44956+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
44957+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
44958+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
44959+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
44960+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
44961+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
44962+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
44963+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
44964+85 115 134 4 0 0
44965+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
44966+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
44967+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
44968+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
44969+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
44970+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
44971+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
44972+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
44973+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
44974+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
44975+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
44976+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
44977+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
44978+60 73 81 4 0 0
44979+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
44980+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
44981+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
44982+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
44983+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
44984+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
44985+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
44986+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
44987+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
44988+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
44989+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
44990+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
44991+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
44992+16 19 21 4 0 0
44993+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
44994+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
44995+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
44996+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
44997+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
44998+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
44999+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
45000+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
45001+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
45002+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
45003+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
45004+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
45005+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
45006+4 0 0 4 3 3
45007+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
45008+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
45009+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
45010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
45011+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
45012+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
45013+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
45014+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
45015+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
45016+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
45017+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
45018+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
45019+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
45020+3 2 2 4 4 4
45021+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
45022+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
45023+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
45024+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
45025+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
45026+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
45027+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
45028+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
45029+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
45030+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
45031+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
45032+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
45033+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
45034+4 4 4 4 4 4
45035+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
45036+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
45037+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
45038+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
45039+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
45040+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
45041+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
45042+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
45043+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
45044+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
45045+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
45046+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
45047+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
45048+4 4 4 4 4 4
45049+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
45050+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
45051+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
45052+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
45053+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
45054+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45055+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
45056+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
45057+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
45058+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
45059+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
45060+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
45061+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
45062+5 5 5 5 5 5
45063+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
45064+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
45065+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
45066+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
45067+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
45068+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45069+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
45070+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
45071+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
45072+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
45073+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
45074+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
45075+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
45076+5 5 5 4 4 4
45077+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
45078+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
45079+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
45080+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
45081+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45082+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
45083+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
45084+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
45085+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
45086+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
45087+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
45088+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
45089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45090+4 4 4 4 4 4
45091+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
45092+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
45093+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
45094+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
45095+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
45096+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45097+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45098+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
45099+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
45100+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
45101+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
45102+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
45103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45104+4 4 4 4 4 4
45105+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
45106+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
45107+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
45108+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
45109+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45110+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
45111+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
45112+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
45113+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
45114+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
45115+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
45116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45118+4 4 4 4 4 4
45119+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
45120+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
45121+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
45122+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
45123+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45124+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45125+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
45126+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
45127+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
45128+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
45129+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
45130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45132+4 4 4 4 4 4
45133+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
45134+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
45135+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
45136+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
45137+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45138+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
45139+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45140+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
45141+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
45142+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
45143+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45146+4 4 4 4 4 4
45147+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
45148+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
45149+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
45150+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
45151+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
45152+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
45153+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
45154+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
45155+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
45156+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
45157+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
45158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45160+4 4 4 4 4 4
45161+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
45162+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
45163+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
45164+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
45165+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
45166+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
45167+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
45168+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
45169+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
45170+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
45171+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
45172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45174+4 4 4 4 4 4
45175+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
45176+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
45177+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
45178+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45179+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
45180+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
45181+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
45182+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
45183+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
45184+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
45185+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45188+4 4 4 4 4 4
45189+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
45190+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
45191+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
45192+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
45193+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45194+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
45195+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
45196+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
45197+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
45198+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
45199+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
45200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45202+4 4 4 4 4 4
45203+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
45204+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
45205+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
45206+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
45207+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45208+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
45209+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
45210+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
45211+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
45212+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
45213+4 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45216+4 4 4 4 4 4
45217+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
45218+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
45219+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
45220+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
45221+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45222+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
45223+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
45224+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
45225+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
45226+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45227+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45230+4 4 4 4 4 4
45231+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
45232+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
45233+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
45234+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
45235+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
45236+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
45237+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
45238+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
45239+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45240+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45241+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45244+4 4 4 4 4 4
45245+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
45246+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
45247+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
45248+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
45249+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45250+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
45251+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
45252+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
45253+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45254+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45255+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45258+4 4 4 4 4 4
45259+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
45260+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
45261+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
45262+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
45263+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
45264+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
45265+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
45266+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
45267+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45268+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45269+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45272+4 4 4 4 4 4
45273+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
45274+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
45275+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45276+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
45277+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
45278+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
45279+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
45280+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
45281+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
45282+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45283+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45286+4 4 4 4 4 4
45287+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
45288+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
45289+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
45290+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
45291+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
45292+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
45293+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
45294+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
45295+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45296+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45297+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45300+4 4 4 4 4 4
45301+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
45302+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
45303+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45304+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
45305+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
45306+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
45307+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
45308+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
45309+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
45310+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45311+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45314+4 4 4 4 4 4
45315+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
45316+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
45317+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
45318+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
45319+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
45320+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
45321+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
45322+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
45323+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45324+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45325+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45328+4 4 4 4 4 4
45329+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45330+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
45331+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
45332+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
45333+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
45334+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
45335+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
45336+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
45337+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45338+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45339+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45342+4 4 4 4 4 4
45343+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
45344+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
45345+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
45346+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
45347+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
45348+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
45349+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45350+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
45351+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
45352+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45353+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45356+4 4 4 4 4 4
45357+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45358+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
45359+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
45360+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
45361+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
45362+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
45363+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
45364+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
45365+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
45366+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45367+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45370+4 4 4 4 4 4
45371+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
45372+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
45373+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
45374+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
45375+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
45376+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
45377+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
45378+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
45379+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
45380+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45381+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45384+4 4 4 4 4 4
45385+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45386+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
45387+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
45388+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
45389+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
45390+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
45391+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
45392+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
45393+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
45394+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45395+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45398+4 4 4 4 4 4
45399+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
45400+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
45401+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
45402+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
45403+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
45404+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
45405+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
45406+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
45407+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
45408+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45409+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45412+4 4 4 4 4 4
45413+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
45414+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
45415+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
45416+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
45417+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
45418+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
45419+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
45420+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
45421+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
45422+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
45423+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45426+4 4 4 4 4 4
45427+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
45428+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
45429+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
45430+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
45431+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
45432+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
45433+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
45434+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
45435+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
45436+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
45437+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45440+4 4 4 4 4 4
45441+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
45442+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
45443+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
45444+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
45445+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
45446+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
45447+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
45448+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
45449+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
45450+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
45451+0 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
45454+4 4 4 4 4 4
45455+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
45456+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
45457+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
45458+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
45459+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
45460+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
45461+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45462+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
45463+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
45464+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
45465+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45468+4 4 4 4 4 4
45469+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
45470+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
45471+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
45472+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
45473+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
45474+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
45475+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
45476+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
45477+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
45478+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
45479+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45482+4 4 4 4 4 4
45483+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
45484+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
45485+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
45486+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
45487+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
45488+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
45489+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
45490+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
45491+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
45492+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
45496+4 4 4 4 4 4
45497+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45498+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
45499+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
45500+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
45501+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
45502+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
45503+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
45504+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
45505+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
45506+13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
45510+4 4 4 4 4 4
45511+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
45512+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
45513+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
45514+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
45515+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
45516+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
45517+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
45518+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
45519+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
45520+4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45524+4 4 4 4 4 4
45525+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
45526+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
45527+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
45528+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
45529+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
45530+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
45531+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
45532+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
45533+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
45534+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45538+4 4 4 4 4 4
45539+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
45540+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45541+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
45542+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
45543+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
45544+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
45545+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
45546+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
45547+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
45548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45552+4 4 4 4 4 4
45553+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
45554+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
45555+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
45556+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
45557+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
45558+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
45559+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
45560+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
45561+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
45562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45566+4 4 4 4 4 4
45567+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
45568+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
45569+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
45570+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
45571+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
45572+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
45573+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
45574+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
45575+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45580+4 4 4 4 4 4
45581+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
45582+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
45583+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
45584+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
45585+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
45586+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
45587+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
45588+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
45589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45594+4 4 4 4 4 4
45595+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
45596+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
45597+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
45598+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
45599+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
45600+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
45601+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
45602+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
45603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45608+4 4 4 4 4 4
45609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45610+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
45611+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45612+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
45613+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
45614+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
45615+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
45616+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
45617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45622+4 4 4 4 4 4
45623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45624+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
45625+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
45626+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
45627+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
45628+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
45629+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
45630+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
45631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45636+4 4 4 4 4 4
45637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45638+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
45639+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
45640+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
45641+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
45642+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
45643+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
45644+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45650+4 4 4 4 4 4
45651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45653+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
45654+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
45655+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
45656+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
45657+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
45658+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45664+4 4 4 4 4 4
45665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45668+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45669+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
45670+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
45671+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
45672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45678+4 4 4 4 4 4
45679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45682+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
45683+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
45684+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
45685+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
45686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45692+4 4 4 4 4 4
45693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45696+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
45697+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
45698+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
45699+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
45700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45706+4 4 4 4 4 4
45707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45710+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
45711+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
45712+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
45713+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45720+4 4 4 4 4 4
45721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45725+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
45726+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
45727+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
45734+4 4 4 4 4 4
45735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45739+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
45740+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
45741+4 3 3 5 5 5 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
45748+4 4 4 4 4 4
45749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45753+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
45754+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
45755+5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
45762+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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45767+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
45768+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
45769+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
45776+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 4 4 4
45779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45781+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
45782+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
45790+4 4 4 4 4 4
45791diff --git a/drivers/video/nvidia/nv_backlight.c b/drivers/video/nvidia/nv_backlight.c
45792index 443e3c8..c443d6a 100644
45793--- a/drivers/video/nvidia/nv_backlight.c
45794+++ b/drivers/video/nvidia/nv_backlight.c
45795@@ -87,7 +87,7 @@ static int nvidia_bl_get_brightness(struct backlight_device *bd)
45796 return bd->props.brightness;
45797 }
45798
45799-static struct backlight_ops nvidia_bl_ops = {
45800+static const struct backlight_ops nvidia_bl_ops = {
45801 .get_brightness = nvidia_bl_get_brightness,
45802 .update_status = nvidia_bl_update_status,
45803 };
45804diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
45805index d94c57f..912984c 100644
45806--- a/drivers/video/riva/fbdev.c
45807+++ b/drivers/video/riva/fbdev.c
45808@@ -331,7 +331,7 @@ static int riva_bl_get_brightness(struct backlight_device *bd)
45809 return bd->props.brightness;
45810 }
45811
45812-static struct backlight_ops riva_bl_ops = {
45813+static const struct backlight_ops riva_bl_ops = {
45814 .get_brightness = riva_bl_get_brightness,
45815 .update_status = riva_bl_update_status,
45816 };
45817diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
45818index 54fbb29..2c108fc 100644
45819--- a/drivers/video/uvesafb.c
45820+++ b/drivers/video/uvesafb.c
45821@@ -18,6 +18,7 @@
45822 #include <linux/fb.h>
45823 #include <linux/io.h>
45824 #include <linux/mutex.h>
45825+#include <linux/moduleloader.h>
45826 #include <video/edid.h>
45827 #include <video/uvesafb.h>
45828 #ifdef CONFIG_X86
45829@@ -120,7 +121,7 @@ static int uvesafb_helper_start(void)
45830 NULL,
45831 };
45832
45833- return call_usermodehelper(v86d_path, argv, envp, 1);
45834+ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
45835 }
45836
45837 /*
45838@@ -568,10 +569,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
45839 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
45840 par->pmi_setpal = par->ypan = 0;
45841 } else {
45842+
45843+#ifdef CONFIG_PAX_KERNEXEC
45844+#ifdef CONFIG_MODULES
45845+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
45846+#endif
45847+ if (!par->pmi_code) {
45848+ par->pmi_setpal = par->ypan = 0;
45849+ return 0;
45850+ }
45851+#endif
45852+
45853 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
45854 + task->t.regs.edi);
45855+
45856+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45857+ pax_open_kernel();
45858+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
45859+ pax_close_kernel();
45860+
45861+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
45862+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
45863+#else
45864 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
45865 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
45866+#endif
45867+
45868 printk(KERN_INFO "uvesafb: protected mode interface info at "
45869 "%04x:%04x\n",
45870 (u16)task->t.regs.es, (u16)task->t.regs.edi);
45871@@ -1799,6 +1822,11 @@ out:
45872 if (par->vbe_modes)
45873 kfree(par->vbe_modes);
45874
45875+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45876+ if (par->pmi_code)
45877+ module_free_exec(NULL, par->pmi_code);
45878+#endif
45879+
45880 framebuffer_release(info);
45881 return err;
45882 }
45883@@ -1825,6 +1853,12 @@ static int uvesafb_remove(struct platform_device *dev)
45884 kfree(par->vbe_state_orig);
45885 if (par->vbe_state_saved)
45886 kfree(par->vbe_state_saved);
45887+
45888+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45889+ if (par->pmi_code)
45890+ module_free_exec(NULL, par->pmi_code);
45891+#endif
45892+
45893 }
45894
45895 framebuffer_release(info);
45896diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
45897index bd37ee1..cb827e8 100644
45898--- a/drivers/video/vesafb.c
45899+++ b/drivers/video/vesafb.c
45900@@ -9,6 +9,7 @@
45901 */
45902
45903 #include <linux/module.h>
45904+#include <linux/moduleloader.h>
45905 #include <linux/kernel.h>
45906 #include <linux/errno.h>
45907 #include <linux/string.h>
45908@@ -53,8 +54,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
45909 static int vram_total __initdata; /* Set total amount of memory */
45910 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
45911 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
45912-static void (*pmi_start)(void) __read_mostly;
45913-static void (*pmi_pal) (void) __read_mostly;
45914+static void (*pmi_start)(void) __read_only;
45915+static void (*pmi_pal) (void) __read_only;
45916 static int depth __read_mostly;
45917 static int vga_compat __read_mostly;
45918 /* --------------------------------------------------------------------- */
45919@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
45920 unsigned int size_vmode;
45921 unsigned int size_remap;
45922 unsigned int size_total;
45923+ void *pmi_code = NULL;
45924
45925 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
45926 return -ENODEV;
45927@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
45928 size_remap = size_total;
45929 vesafb_fix.smem_len = size_remap;
45930
45931-#ifndef __i386__
45932- screen_info.vesapm_seg = 0;
45933-#endif
45934-
45935 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
45936 printk(KERN_WARNING
45937 "vesafb: cannot reserve video memory at 0x%lx\n",
45938@@ -315,9 +313,21 @@ static int __init vesafb_probe(struct platform_device *dev)
45939 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
45940 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
45941
45942+#ifdef __i386__
45943+
45944+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45945+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
45946+ if (!pmi_code)
45947+#elif !defined(CONFIG_PAX_KERNEXEC)
45948+ if (0)
45949+#endif
45950+
45951+#endif
45952+ screen_info.vesapm_seg = 0;
45953+
45954 if (screen_info.vesapm_seg) {
45955- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
45956- screen_info.vesapm_seg,screen_info.vesapm_off);
45957+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
45958+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
45959 }
45960
45961 if (screen_info.vesapm_seg < 0xc000)
45962@@ -325,9 +335,25 @@ static int __init vesafb_probe(struct platform_device *dev)
45963
45964 if (ypan || pmi_setpal) {
45965 unsigned short *pmi_base;
45966+
45967 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
45968- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
45969- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
45970+
45971+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45972+ pax_open_kernel();
45973+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
45974+#else
45975+ pmi_code = pmi_base;
45976+#endif
45977+
45978+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
45979+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
45980+
45981+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45982+ pmi_start = ktva_ktla(pmi_start);
45983+ pmi_pal = ktva_ktla(pmi_pal);
45984+ pax_close_kernel();
45985+#endif
45986+
45987 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
45988 if (pmi_base[3]) {
45989 printk(KERN_INFO "vesafb: pmi: ports = ");
45990@@ -469,6 +495,11 @@ static int __init vesafb_probe(struct platform_device *dev)
45991 info->node, info->fix.id);
45992 return 0;
45993 err:
45994+
45995+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45996+ module_free_exec(NULL, pmi_code);
45997+#endif
45998+
45999 if (info->screen_base)
46000 iounmap(info->screen_base);
46001 framebuffer_release(info);
46002diff --git a/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c
46003index 88a60e0..6783cc2 100644
46004--- a/drivers/xen/sys-hypervisor.c
46005+++ b/drivers/xen/sys-hypervisor.c
46006@@ -425,7 +425,7 @@ static ssize_t hyp_sysfs_store(struct kobject *kobj,
46007 return 0;
46008 }
46009
46010-static struct sysfs_ops hyp_sysfs_ops = {
46011+static const struct sysfs_ops hyp_sysfs_ops = {
46012 .show = hyp_sysfs_show,
46013 .store = hyp_sysfs_store,
46014 };
46015diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
46016index 18f74ec..3227009 100644
46017--- a/fs/9p/vfs_inode.c
46018+++ b/fs/9p/vfs_inode.c
46019@@ -1079,7 +1079,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
46020 static void
46021 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46022 {
46023- char *s = nd_get_link(nd);
46024+ const char *s = nd_get_link(nd);
46025
46026 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
46027 IS_ERR(s) ? "<error>" : s);
46028diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
46029index bb4cc5b..df5eaa0 100644
46030--- a/fs/Kconfig.binfmt
46031+++ b/fs/Kconfig.binfmt
46032@@ -86,7 +86,7 @@ config HAVE_AOUT
46033
46034 config BINFMT_AOUT
46035 tristate "Kernel support for a.out and ECOFF binaries"
46036- depends on HAVE_AOUT
46037+ depends on HAVE_AOUT && BROKEN
46038 ---help---
46039 A.out (Assembler.OUTput) is a set of formats for libraries and
46040 executables used in the earliest versions of UNIX. Linux used
46041diff --git a/fs/aio.c b/fs/aio.c
46042index 22a19ad..d484e5b 100644
46043--- a/fs/aio.c
46044+++ b/fs/aio.c
46045@@ -115,7 +115,7 @@ static int aio_setup_ring(struct kioctx *ctx)
46046 size += sizeof(struct io_event) * nr_events;
46047 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
46048
46049- if (nr_pages < 0)
46050+ if (nr_pages <= 0)
46051 return -EINVAL;
46052
46053 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
46054@@ -1089,6 +1089,8 @@ static int read_events(struct kioctx *ctx,
46055 struct aio_timeout to;
46056 int retry = 0;
46057
46058+ pax_track_stack();
46059+
46060 /* needed to zero any padding within an entry (there shouldn't be
46061 * any, but C is fun!
46062 */
46063@@ -1382,13 +1384,18 @@ static ssize_t aio_fsync(struct kiocb *iocb)
46064 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb)
46065 {
46066 ssize_t ret;
46067+ struct iovec iovstack;
46068
46069 ret = rw_copy_check_uvector(type, (struct iovec __user *)kiocb->ki_buf,
46070 kiocb->ki_nbytes, 1,
46071- &kiocb->ki_inline_vec, &kiocb->ki_iovec);
46072+ &iovstack, &kiocb->ki_iovec);
46073 if (ret < 0)
46074 goto out;
46075
46076+ if (kiocb->ki_iovec == &iovstack) {
46077+ kiocb->ki_inline_vec = iovstack;
46078+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
46079+ }
46080 kiocb->ki_nr_segs = kiocb->ki_nbytes;
46081 kiocb->ki_cur_seg = 0;
46082 /* ki_nbytes/left now reflect bytes instead of segs */
46083diff --git a/fs/attr.c b/fs/attr.c
46084index 96d394b..33cf5b4 100644
46085--- a/fs/attr.c
46086+++ b/fs/attr.c
46087@@ -83,6 +83,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
46088 unsigned long limit;
46089
46090 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
46091+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
46092 if (limit != RLIM_INFINITY && offset > limit)
46093 goto out_sig;
46094 if (offset > inode->i_sb->s_maxbytes)
46095diff --git a/fs/autofs/root.c b/fs/autofs/root.c
46096index 4a1401c..05eb5ca 100644
46097--- a/fs/autofs/root.c
46098+++ b/fs/autofs/root.c
46099@@ -299,7 +299,8 @@ static int autofs_root_symlink(struct inode *dir, struct dentry *dentry, const c
46100 set_bit(n,sbi->symlink_bitmap);
46101 sl = &sbi->symlink[n];
46102 sl->len = strlen(symname);
46103- sl->data = kmalloc(slsize = sl->len+1, GFP_KERNEL);
46104+ slsize = sl->len+1;
46105+ sl->data = kmalloc(slsize, GFP_KERNEL);
46106 if (!sl->data) {
46107 clear_bit(n,sbi->symlink_bitmap);
46108 unlock_kernel();
46109diff --git a/fs/autofs4/symlink.c b/fs/autofs4/symlink.c
46110index b4ea829..e63ef18 100644
46111--- a/fs/autofs4/symlink.c
46112+++ b/fs/autofs4/symlink.c
46113@@ -15,7 +15,7 @@
46114 static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
46115 {
46116 struct autofs_info *ino = autofs4_dentry_ino(dentry);
46117- nd_set_link(nd, (char *)ino->u.symlink);
46118+ nd_set_link(nd, ino->u.symlink);
46119 return NULL;
46120 }
46121
46122diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
46123index 2341375..df9d1c2 100644
46124--- a/fs/autofs4/waitq.c
46125+++ b/fs/autofs4/waitq.c
46126@@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
46127 {
46128 unsigned long sigpipe, flags;
46129 mm_segment_t fs;
46130- const char *data = (const char *)addr;
46131+ const char __user *data = (const char __force_user *)addr;
46132 ssize_t wr = 0;
46133
46134 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
46135diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
46136index 9158c07..3f06659 100644
46137--- a/fs/befs/linuxvfs.c
46138+++ b/fs/befs/linuxvfs.c
46139@@ -498,7 +498,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46140 {
46141 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
46142 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
46143- char *link = nd_get_link(nd);
46144+ const char *link = nd_get_link(nd);
46145 if (!IS_ERR(link))
46146 kfree(link);
46147 }
46148diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
46149index 0133b5a..b3baa9f 100644
46150--- a/fs/binfmt_aout.c
46151+++ b/fs/binfmt_aout.c
46152@@ -16,6 +16,7 @@
46153 #include <linux/string.h>
46154 #include <linux/fs.h>
46155 #include <linux/file.h>
46156+#include <linux/security.h>
46157 #include <linux/stat.h>
46158 #include <linux/fcntl.h>
46159 #include <linux/ptrace.h>
46160@@ -102,6 +103,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46161 #endif
46162 # define START_STACK(u) (u.start_stack)
46163
46164+ memset(&dump, 0, sizeof(dump));
46165+
46166 fs = get_fs();
46167 set_fs(KERNEL_DS);
46168 has_dumped = 1;
46169@@ -113,10 +116,12 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46170
46171 /* If the size of the dump file exceeds the rlimit, then see what would happen
46172 if we wrote the stack, but not the data area. */
46173+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
46174 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
46175 dump.u_dsize = 0;
46176
46177 /* Make sure we have enough room to write the stack and data areas. */
46178+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
46179 if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
46180 dump.u_ssize = 0;
46181
46182@@ -146,9 +151,7 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
46183 dump_size = dump.u_ssize << PAGE_SHIFT;
46184 DUMP_WRITE(dump_start,dump_size);
46185 }
46186-/* Finally dump the task struct. Not be used by gdb, but could be useful */
46187- set_fs(KERNEL_DS);
46188- DUMP_WRITE(current,sizeof(*current));
46189+/* Finally, let's not dump the task struct. Not be used by gdb, but could be useful to an attacker */
46190 end_coredump:
46191 set_fs(fs);
46192 return has_dumped;
46193@@ -249,6 +252,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46194 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
46195 if (rlim >= RLIM_INFINITY)
46196 rlim = ~0;
46197+
46198+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
46199 if (ex.a_data + ex.a_bss > rlim)
46200 return -ENOMEM;
46201
46202@@ -277,6 +282,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46203 install_exec_creds(bprm);
46204 current->flags &= ~PF_FORKNOEXEC;
46205
46206+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46207+ current->mm->pax_flags = 0UL;
46208+#endif
46209+
46210+#ifdef CONFIG_PAX_PAGEEXEC
46211+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
46212+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
46213+
46214+#ifdef CONFIG_PAX_EMUTRAMP
46215+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
46216+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
46217+#endif
46218+
46219+#ifdef CONFIG_PAX_MPROTECT
46220+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
46221+ current->mm->pax_flags |= MF_PAX_MPROTECT;
46222+#endif
46223+
46224+ }
46225+#endif
46226+
46227 if (N_MAGIC(ex) == OMAGIC) {
46228 unsigned long text_addr, map_size;
46229 loff_t pos;
46230@@ -349,7 +375,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
46231
46232 down_write(&current->mm->mmap_sem);
46233 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
46234- PROT_READ | PROT_WRITE | PROT_EXEC,
46235+ PROT_READ | PROT_WRITE,
46236 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
46237 fd_offset + ex.a_text);
46238 up_write(&current->mm->mmap_sem);
46239diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
46240index 1ed37ba..b9c035f 100644
46241--- a/fs/binfmt_elf.c
46242+++ b/fs/binfmt_elf.c
46243@@ -31,6 +31,7 @@
46244 #include <linux/random.h>
46245 #include <linux/elf.h>
46246 #include <linux/utsname.h>
46247+#include <linux/xattr.h>
46248 #include <asm/uaccess.h>
46249 #include <asm/param.h>
46250 #include <asm/page.h>
46251@@ -50,6 +51,10 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46252 #define elf_core_dump NULL
46253 #endif
46254
46255+#ifdef CONFIG_PAX_MPROTECT
46256+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
46257+#endif
46258+
46259 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
46260 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
46261 #else
46262@@ -69,6 +74,11 @@ static struct linux_binfmt elf_format = {
46263 .load_binary = load_elf_binary,
46264 .load_shlib = load_elf_library,
46265 .core_dump = elf_core_dump,
46266+
46267+#ifdef CONFIG_PAX_MPROTECT
46268+ .handle_mprotect= elf_handle_mprotect,
46269+#endif
46270+
46271 .min_coredump = ELF_EXEC_PAGESIZE,
46272 .hasvdso = 1
46273 };
46274@@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
46275
46276 static int set_brk(unsigned long start, unsigned long end)
46277 {
46278+ unsigned long e = end;
46279+
46280 start = ELF_PAGEALIGN(start);
46281 end = ELF_PAGEALIGN(end);
46282 if (end > start) {
46283@@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
46284 if (BAD_ADDR(addr))
46285 return addr;
46286 }
46287- current->mm->start_brk = current->mm->brk = end;
46288+ current->mm->start_brk = current->mm->brk = e;
46289 return 0;
46290 }
46291
46292@@ -148,12 +160,15 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46293 elf_addr_t __user *u_rand_bytes;
46294 const char *k_platform = ELF_PLATFORM;
46295 const char *k_base_platform = ELF_BASE_PLATFORM;
46296- unsigned char k_rand_bytes[16];
46297+ u32 k_rand_bytes[4];
46298 int items;
46299 elf_addr_t *elf_info;
46300 int ei_index = 0;
46301 const struct cred *cred = current_cred();
46302 struct vm_area_struct *vma;
46303+ unsigned long saved_auxv[AT_VECTOR_SIZE];
46304+
46305+ pax_track_stack();
46306
46307 /*
46308 * In some cases (e.g. Hyper-Threading), we want to avoid L1
46309@@ -195,8 +210,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46310 * Generate 16 random bytes for userspace PRNG seeding.
46311 */
46312 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
46313- u_rand_bytes = (elf_addr_t __user *)
46314- STACK_ALLOC(p, sizeof(k_rand_bytes));
46315+ srandom32(k_rand_bytes[0] ^ random32());
46316+ srandom32(k_rand_bytes[1] ^ random32());
46317+ srandom32(k_rand_bytes[2] ^ random32());
46318+ srandom32(k_rand_bytes[3] ^ random32());
46319+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
46320+ u_rand_bytes = (elf_addr_t __user *) p;
46321 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
46322 return -EFAULT;
46323
46324@@ -308,9 +327,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
46325 return -EFAULT;
46326 current->mm->env_end = p;
46327
46328+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
46329+
46330 /* Put the elf_info on the stack in the right place. */
46331 sp = (elf_addr_t __user *)envp + 1;
46332- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
46333+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
46334 return -EFAULT;
46335 return 0;
46336 }
46337@@ -385,10 +406,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46338 {
46339 struct elf_phdr *elf_phdata;
46340 struct elf_phdr *eppnt;
46341- unsigned long load_addr = 0;
46342+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
46343 int load_addr_set = 0;
46344 unsigned long last_bss = 0, elf_bss = 0;
46345- unsigned long error = ~0UL;
46346+ unsigned long error = -EINVAL;
46347 unsigned long total_size;
46348 int retval, i, size;
46349
46350@@ -434,6 +455,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46351 goto out_close;
46352 }
46353
46354+#ifdef CONFIG_PAX_SEGMEXEC
46355+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
46356+ pax_task_size = SEGMEXEC_TASK_SIZE;
46357+#endif
46358+
46359 eppnt = elf_phdata;
46360 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
46361 if (eppnt->p_type == PT_LOAD) {
46362@@ -477,8 +503,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
46363 k = load_addr + eppnt->p_vaddr;
46364 if (BAD_ADDR(k) ||
46365 eppnt->p_filesz > eppnt->p_memsz ||
46366- eppnt->p_memsz > TASK_SIZE ||
46367- TASK_SIZE - eppnt->p_memsz < k) {
46368+ eppnt->p_memsz > pax_task_size ||
46369+ pax_task_size - eppnt->p_memsz < k) {
46370 error = -ENOMEM;
46371 goto out_close;
46372 }
46373@@ -532,6 +558,348 @@ out:
46374 return error;
46375 }
46376
46377+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
46378+{
46379+ unsigned long pax_flags = 0UL;
46380+
46381+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46382+
46383+#ifdef CONFIG_PAX_PAGEEXEC
46384+ if (elf_phdata->p_flags & PF_PAGEEXEC)
46385+ pax_flags |= MF_PAX_PAGEEXEC;
46386+#endif
46387+
46388+#ifdef CONFIG_PAX_SEGMEXEC
46389+ if (elf_phdata->p_flags & PF_SEGMEXEC)
46390+ pax_flags |= MF_PAX_SEGMEXEC;
46391+#endif
46392+
46393+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46394+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46395+ if (nx_enabled)
46396+ pax_flags &= ~MF_PAX_SEGMEXEC;
46397+ else
46398+ pax_flags &= ~MF_PAX_PAGEEXEC;
46399+ }
46400+#endif
46401+
46402+#ifdef CONFIG_PAX_EMUTRAMP
46403+ if (elf_phdata->p_flags & PF_EMUTRAMP)
46404+ pax_flags |= MF_PAX_EMUTRAMP;
46405+#endif
46406+
46407+#ifdef CONFIG_PAX_MPROTECT
46408+ if (elf_phdata->p_flags & PF_MPROTECT)
46409+ pax_flags |= MF_PAX_MPROTECT;
46410+#endif
46411+
46412+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46413+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
46414+ pax_flags |= MF_PAX_RANDMMAP;
46415+#endif
46416+
46417+#endif
46418+
46419+ return pax_flags;
46420+}
46421+
46422+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
46423+{
46424+ unsigned long pax_flags = 0UL;
46425+
46426+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46427+
46428+#ifdef CONFIG_PAX_PAGEEXEC
46429+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
46430+ pax_flags |= MF_PAX_PAGEEXEC;
46431+#endif
46432+
46433+#ifdef CONFIG_PAX_SEGMEXEC
46434+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
46435+ pax_flags |= MF_PAX_SEGMEXEC;
46436+#endif
46437+
46438+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46439+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46440+ if (nx_enabled)
46441+ pax_flags &= ~MF_PAX_SEGMEXEC;
46442+ else
46443+ pax_flags &= ~MF_PAX_PAGEEXEC;
46444+ }
46445+#endif
46446+
46447+#ifdef CONFIG_PAX_EMUTRAMP
46448+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
46449+ pax_flags |= MF_PAX_EMUTRAMP;
46450+#endif
46451+
46452+#ifdef CONFIG_PAX_MPROTECT
46453+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
46454+ pax_flags |= MF_PAX_MPROTECT;
46455+#endif
46456+
46457+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46458+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
46459+ pax_flags |= MF_PAX_RANDMMAP;
46460+#endif
46461+
46462+#endif
46463+
46464+ return pax_flags;
46465+}
46466+
46467+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
46468+{
46469+ unsigned long pax_flags = 0UL;
46470+
46471+#ifdef CONFIG_PAX_EI_PAX
46472+
46473+#ifdef CONFIG_PAX_PAGEEXEC
46474+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
46475+ pax_flags |= MF_PAX_PAGEEXEC;
46476+#endif
46477+
46478+#ifdef CONFIG_PAX_SEGMEXEC
46479+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
46480+ pax_flags |= MF_PAX_SEGMEXEC;
46481+#endif
46482+
46483+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46484+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46485+ if (nx_enabled)
46486+ pax_flags &= ~MF_PAX_SEGMEXEC;
46487+ else
46488+ pax_flags &= ~MF_PAX_PAGEEXEC;
46489+ }
46490+#endif
46491+
46492+#ifdef CONFIG_PAX_EMUTRAMP
46493+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
46494+ pax_flags |= MF_PAX_EMUTRAMP;
46495+#endif
46496+
46497+#ifdef CONFIG_PAX_MPROTECT
46498+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
46499+ pax_flags |= MF_PAX_MPROTECT;
46500+#endif
46501+
46502+#ifdef CONFIG_PAX_ASLR
46503+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
46504+ pax_flags |= MF_PAX_RANDMMAP;
46505+#endif
46506+
46507+#else
46508+
46509+#ifdef CONFIG_PAX_PAGEEXEC
46510+ pax_flags |= MF_PAX_PAGEEXEC;
46511+#endif
46512+
46513+#ifdef CONFIG_PAX_MPROTECT
46514+ pax_flags |= MF_PAX_MPROTECT;
46515+#endif
46516+
46517+#ifdef CONFIG_PAX_RANDMMAP
46518+ pax_flags |= MF_PAX_RANDMMAP;
46519+#endif
46520+
46521+#ifdef CONFIG_PAX_SEGMEXEC
46522+ if (!(__supported_pte_mask & _PAGE_NX)) {
46523+ pax_flags &= ~MF_PAX_PAGEEXEC;
46524+ pax_flags |= MF_PAX_SEGMEXEC;
46525+ }
46526+#endif
46527+
46528+#endif
46529+
46530+ return pax_flags;
46531+}
46532+
46533+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
46534+{
46535+
46536+#ifdef CONFIG_PAX_PT_PAX_FLAGS
46537+ unsigned long i;
46538+
46539+ for (i = 0UL; i < elf_ex->e_phnum; i++)
46540+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
46541+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
46542+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
46543+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
46544+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
46545+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
46546+ return ~0UL;
46547+
46548+#ifdef CONFIG_PAX_SOFTMODE
46549+ if (pax_softmode)
46550+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
46551+ else
46552+#endif
46553+
46554+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
46555+ break;
46556+ }
46557+#endif
46558+
46559+ return ~0UL;
46560+}
46561+
46562+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
46563+{
46564+ unsigned long pax_flags = 0UL;
46565+
46566+#ifdef CONFIG_PAX_PAGEEXEC
46567+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
46568+ pax_flags |= MF_PAX_PAGEEXEC;
46569+#endif
46570+
46571+#ifdef CONFIG_PAX_SEGMEXEC
46572+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
46573+ pax_flags |= MF_PAX_SEGMEXEC;
46574+#endif
46575+
46576+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46577+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46578+ if ((__supported_pte_mask & _PAGE_NX))
46579+ pax_flags &= ~MF_PAX_SEGMEXEC;
46580+ else
46581+ pax_flags &= ~MF_PAX_PAGEEXEC;
46582+ }
46583+#endif
46584+
46585+#ifdef CONFIG_PAX_EMUTRAMP
46586+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
46587+ pax_flags |= MF_PAX_EMUTRAMP;
46588+#endif
46589+
46590+#ifdef CONFIG_PAX_MPROTECT
46591+ if (pax_flags_softmode & MF_PAX_MPROTECT)
46592+ pax_flags |= MF_PAX_MPROTECT;
46593+#endif
46594+
46595+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46596+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
46597+ pax_flags |= MF_PAX_RANDMMAP;
46598+#endif
46599+
46600+ return pax_flags;
46601+}
46602+
46603+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
46604+{
46605+ unsigned long pax_flags = 0UL;
46606+
46607+#ifdef CONFIG_PAX_PAGEEXEC
46608+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
46609+ pax_flags |= MF_PAX_PAGEEXEC;
46610+#endif
46611+
46612+#ifdef CONFIG_PAX_SEGMEXEC
46613+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
46614+ pax_flags |= MF_PAX_SEGMEXEC;
46615+#endif
46616+
46617+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
46618+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46619+ if ((__supported_pte_mask & _PAGE_NX))
46620+ pax_flags &= ~MF_PAX_SEGMEXEC;
46621+ else
46622+ pax_flags &= ~MF_PAX_PAGEEXEC;
46623+ }
46624+#endif
46625+
46626+#ifdef CONFIG_PAX_EMUTRAMP
46627+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
46628+ pax_flags |= MF_PAX_EMUTRAMP;
46629+#endif
46630+
46631+#ifdef CONFIG_PAX_MPROTECT
46632+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
46633+ pax_flags |= MF_PAX_MPROTECT;
46634+#endif
46635+
46636+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
46637+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
46638+ pax_flags |= MF_PAX_RANDMMAP;
46639+#endif
46640+
46641+ return pax_flags;
46642+}
46643+
46644+static unsigned long pax_parse_xattr_pax(struct file * const file)
46645+{
46646+
46647+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
46648+ ssize_t xattr_size, i;
46649+ unsigned char xattr_value[5];
46650+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
46651+
46652+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
46653+ if (xattr_size <= 0)
46654+ return ~0UL;
46655+
46656+ for (i = 0; i < xattr_size; i++)
46657+ switch (xattr_value[i]) {
46658+ default:
46659+ return ~0UL;
46660+
46661+#define parse_flag(option1, option2, flag) \
46662+ case option1: \
46663+ pax_flags_hardmode |= MF_PAX_##flag; \
46664+ break; \
46665+ case option2: \
46666+ pax_flags_softmode |= MF_PAX_##flag; \
46667+ break;
46668+
46669+ parse_flag('p', 'P', PAGEEXEC);
46670+ parse_flag('e', 'E', EMUTRAMP);
46671+ parse_flag('m', 'M', MPROTECT);
46672+ parse_flag('r', 'R', RANDMMAP);
46673+ parse_flag('s', 'S', SEGMEXEC);
46674+
46675+#undef parse_flag
46676+ }
46677+
46678+ if (pax_flags_hardmode & pax_flags_softmode)
46679+ return ~0UL;
46680+
46681+#ifdef CONFIG_PAX_SOFTMODE
46682+ if (pax_softmode)
46683+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
46684+ else
46685+#endif
46686+
46687+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
46688+#else
46689+ return ~0UL;
46690+#endif
46691+}
46692+
46693+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
46694+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
46695+{
46696+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
46697+
46698+ pax_flags = pax_parse_ei_pax(elf_ex);
46699+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
46700+ xattr_pax_flags = pax_parse_xattr_pax(file);
46701+
46702+ if (pt_pax_flags == ~0UL)
46703+ pt_pax_flags = xattr_pax_flags;
46704+ else if (xattr_pax_flags == ~0UL)
46705+ xattr_pax_flags = pt_pax_flags;
46706+ if (pt_pax_flags != xattr_pax_flags)
46707+ return -EINVAL;
46708+ if (pt_pax_flags != ~0UL)
46709+ pax_flags = pt_pax_flags;
46710+
46711+ if (0 > pax_check_flags(&pax_flags))
46712+ return -EINVAL;
46713+
46714+ current->mm->pax_flags = pax_flags;
46715+ return 0;
46716+}
46717+#endif
46718+
46719 /*
46720 * These are the functions used to load ELF style executables and shared
46721 * libraries. There is no binary dependent code anywhere else.
46722@@ -548,6 +916,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
46723 {
46724 unsigned int random_variable = 0;
46725
46726+#ifdef CONFIG_PAX_RANDUSTACK
46727+ if (randomize_va_space)
46728+ return stack_top - current->mm->delta_stack;
46729+#endif
46730+
46731 if ((current->flags & PF_RANDOMIZE) &&
46732 !(current->personality & ADDR_NO_RANDOMIZE)) {
46733 random_variable = get_random_int() & STACK_RND_MASK;
46734@@ -566,7 +939,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46735 unsigned long load_addr = 0, load_bias = 0;
46736 int load_addr_set = 0;
46737 char * elf_interpreter = NULL;
46738- unsigned long error;
46739+ unsigned long error = 0;
46740 struct elf_phdr *elf_ppnt, *elf_phdata;
46741 unsigned long elf_bss, elf_brk;
46742 int retval, i;
46743@@ -576,11 +949,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46744 unsigned long start_code, end_code, start_data, end_data;
46745 unsigned long reloc_func_desc = 0;
46746 int executable_stack = EXSTACK_DEFAULT;
46747- unsigned long def_flags = 0;
46748 struct {
46749 struct elfhdr elf_ex;
46750 struct elfhdr interp_elf_ex;
46751 } *loc;
46752+ unsigned long pax_task_size = TASK_SIZE;
46753
46754 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
46755 if (!loc) {
46756@@ -718,11 +1091,80 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46757
46758 /* OK, This is the point of no return */
46759 current->flags &= ~PF_FORKNOEXEC;
46760- current->mm->def_flags = def_flags;
46761+
46762+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
46763+ current->mm->pax_flags = 0UL;
46764+#endif
46765+
46766+#ifdef CONFIG_PAX_DLRESOLVE
46767+ current->mm->call_dl_resolve = 0UL;
46768+#endif
46769+
46770+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
46771+ current->mm->call_syscall = 0UL;
46772+#endif
46773+
46774+#ifdef CONFIG_PAX_ASLR
46775+ current->mm->delta_mmap = 0UL;
46776+ current->mm->delta_stack = 0UL;
46777+#endif
46778+
46779+ current->mm->def_flags = 0;
46780+
46781+#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
46782+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
46783+ send_sig(SIGKILL, current, 0);
46784+ goto out_free_dentry;
46785+ }
46786+#endif
46787+
46788+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46789+ pax_set_initial_flags(bprm);
46790+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
46791+ if (pax_set_initial_flags_func)
46792+ (pax_set_initial_flags_func)(bprm);
46793+#endif
46794+
46795+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46796+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
46797+ current->mm->context.user_cs_limit = PAGE_SIZE;
46798+ current->mm->def_flags |= VM_PAGEEXEC;
46799+ }
46800+#endif
46801+
46802+#ifdef CONFIG_PAX_SEGMEXEC
46803+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
46804+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
46805+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
46806+ pax_task_size = SEGMEXEC_TASK_SIZE;
46807+ }
46808+#endif
46809+
46810+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
46811+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46812+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
46813+ put_cpu();
46814+ }
46815+#endif
46816
46817 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
46818 may depend on the personality. */
46819 SET_PERSONALITY(loc->elf_ex);
46820+
46821+#ifdef CONFIG_PAX_ASLR
46822+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
46823+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
46824+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
46825+ }
46826+#endif
46827+
46828+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46829+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46830+ executable_stack = EXSTACK_DISABLE_X;
46831+ current->personality &= ~READ_IMPLIES_EXEC;
46832+ } else
46833+#endif
46834+
46835 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
46836 current->personality |= READ_IMPLIES_EXEC;
46837
46838@@ -800,10 +1242,27 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46839 * might try to exec. This is because the brk will
46840 * follow the loader, and is not movable. */
46841 #ifdef CONFIG_X86
46842- load_bias = 0;
46843+ if (current->flags & PF_RANDOMIZE)
46844+ load_bias = 0;
46845+ else
46846+ load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
46847 #else
46848 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
46849 #endif
46850+
46851+#ifdef CONFIG_PAX_RANDMMAP
46852+ /* PaX: randomize base address at the default exe base if requested */
46853+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
46854+#ifdef CONFIG_SPARC64
46855+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
46856+#else
46857+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
46858+#endif
46859+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
46860+ elf_flags |= MAP_FIXED;
46861+ }
46862+#endif
46863+
46864 }
46865
46866 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
46867@@ -836,9 +1295,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46868 * allowed task size. Note that p_filesz must always be
46869 * <= p_memsz so it is only necessary to check p_memsz.
46870 */
46871- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46872- elf_ppnt->p_memsz > TASK_SIZE ||
46873- TASK_SIZE - elf_ppnt->p_memsz < k) {
46874+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
46875+ elf_ppnt->p_memsz > pax_task_size ||
46876+ pax_task_size - elf_ppnt->p_memsz < k) {
46877 /* set_brk can never work. Avoid overflows. */
46878 send_sig(SIGKILL, current, 0);
46879 retval = -EINVAL;
46880@@ -866,6 +1325,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46881 start_data += load_bias;
46882 end_data += load_bias;
46883
46884+#ifdef CONFIG_PAX_RANDMMAP
46885+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
46886+ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
46887+#endif
46888+
46889 /* Calling set_brk effectively mmaps the pages that we need
46890 * for the bss and break sections. We must do this before
46891 * mapping in the interpreter, to make sure it doesn't wind
46892@@ -877,9 +1341,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
46893 goto out_free_dentry;
46894 }
46895 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
46896- send_sig(SIGSEGV, current, 0);
46897- retval = -EFAULT; /* Nobody gets to see this, but.. */
46898- goto out_free_dentry;
46899+ /*
46900+ * This bss-zeroing can fail if the ELF
46901+ * file specifies odd protections. So
46902+ * we don't check the return value
46903+ */
46904 }
46905
46906 if (elf_interpreter) {
46907@@ -1112,8 +1578,10 @@ static int dump_seek(struct file *file, loff_t off)
46908 unsigned long n = off;
46909 if (n > PAGE_SIZE)
46910 n = PAGE_SIZE;
46911- if (!dump_write(file, buf, n))
46912+ if (!dump_write(file, buf, n)) {
46913+ free_page((unsigned long)buf);
46914 return 0;
46915+ }
46916 off -= n;
46917 }
46918 free_page((unsigned long)buf);
46919@@ -1125,7 +1593,7 @@ static int dump_seek(struct file *file, loff_t off)
46920 * Decide what to dump of a segment, part, all or none.
46921 */
46922 static unsigned long vma_dump_size(struct vm_area_struct *vma,
46923- unsigned long mm_flags)
46924+ unsigned long mm_flags, long signr)
46925 {
46926 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
46927
46928@@ -1159,7 +1627,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
46929 if (vma->vm_file == NULL)
46930 return 0;
46931
46932- if (FILTER(MAPPED_PRIVATE))
46933+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
46934 goto whole;
46935
46936 /*
46937@@ -1255,8 +1723,11 @@ static int writenote(struct memelfnote *men, struct file *file,
46938 #undef DUMP_WRITE
46939
46940 #define DUMP_WRITE(addr, nr) \
46941+ do { \
46942+ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
46943 if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
46944- goto end_coredump;
46945+ goto end_coredump; \
46946+ } while (0);
46947
46948 static void fill_elf_header(struct elfhdr *elf, int segs,
46949 u16 machine, u32 flags, u8 osabi)
46950@@ -1385,9 +1856,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
46951 {
46952 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
46953 int i = 0;
46954- do
46955+ do {
46956 i += 2;
46957- while (auxv[i - 2] != AT_NULL);
46958+ } while (auxv[i - 2] != AT_NULL);
46959 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
46960 }
46961
46962@@ -1973,7 +2444,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46963 phdr.p_offset = offset;
46964 phdr.p_vaddr = vma->vm_start;
46965 phdr.p_paddr = 0;
46966- phdr.p_filesz = vma_dump_size(vma, mm_flags);
46967+ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
46968 phdr.p_memsz = vma->vm_end - vma->vm_start;
46969 offset += phdr.p_filesz;
46970 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
46971@@ -2006,7 +2477,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46972 unsigned long addr;
46973 unsigned long end;
46974
46975- end = vma->vm_start + vma_dump_size(vma, mm_flags);
46976+ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
46977
46978 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
46979 struct page *page;
46980@@ -2015,6 +2486,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file, un
46981 page = get_dump_page(addr);
46982 if (page) {
46983 void *kaddr = kmap(page);
46984+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
46985 stop = ((size += PAGE_SIZE) > limit) ||
46986 !dump_write(file, kaddr, PAGE_SIZE);
46987 kunmap(page);
46988@@ -2042,6 +2514,97 @@ out:
46989
46990 #endif /* USE_ELF_CORE_DUMP */
46991
46992+#ifdef CONFIG_PAX_MPROTECT
46993+/* PaX: non-PIC ELF libraries need relocations on their executable segments
46994+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
46995+ * we'll remove VM_MAYWRITE for good on RELRO segments.
46996+ *
46997+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
46998+ * basis because we want to allow the common case and not the special ones.
46999+ */
47000+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
47001+{
47002+ struct elfhdr elf_h;
47003+ struct elf_phdr elf_p;
47004+ unsigned long i;
47005+ unsigned long oldflags;
47006+ bool is_textrel_rw, is_textrel_rx, is_relro;
47007+
47008+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
47009+ return;
47010+
47011+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
47012+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
47013+
47014+#ifdef CONFIG_PAX_ELFRELOCS
47015+ /* possible TEXTREL */
47016+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
47017+ 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);
47018+#else
47019+ is_textrel_rw = false;
47020+ is_textrel_rx = false;
47021+#endif
47022+
47023+ /* possible RELRO */
47024+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
47025+
47026+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
47027+ return;
47028+
47029+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
47030+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
47031+
47032+#ifdef CONFIG_PAX_ETEXECRELOCS
47033+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
47034+#else
47035+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
47036+#endif
47037+
47038+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
47039+ !elf_check_arch(&elf_h) ||
47040+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
47041+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
47042+ return;
47043+
47044+ for (i = 0UL; i < elf_h.e_phnum; i++) {
47045+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
47046+ return;
47047+ switch (elf_p.p_type) {
47048+ case PT_DYNAMIC:
47049+ if (!is_textrel_rw && !is_textrel_rx)
47050+ continue;
47051+ i = 0UL;
47052+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
47053+ elf_dyn dyn;
47054+
47055+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
47056+ return;
47057+ if (dyn.d_tag == DT_NULL)
47058+ return;
47059+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
47060+ gr_log_textrel(vma);
47061+ if (is_textrel_rw)
47062+ vma->vm_flags |= VM_MAYWRITE;
47063+ else
47064+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
47065+ vma->vm_flags &= ~VM_MAYWRITE;
47066+ return;
47067+ }
47068+ i++;
47069+ }
47070+ return;
47071+
47072+ case PT_GNU_RELRO:
47073+ if (!is_relro)
47074+ continue;
47075+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
47076+ vma->vm_flags &= ~VM_MAYWRITE;
47077+ return;
47078+ }
47079+ }
47080+}
47081+#endif
47082+
47083 static int __init init_elf_binfmt(void)
47084 {
47085 return register_binfmt(&elf_format);
47086diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
47087index ca88c46..f155a60 100644
47088--- a/fs/binfmt_flat.c
47089+++ b/fs/binfmt_flat.c
47090@@ -564,7 +564,9 @@ static int load_flat_file(struct linux_binprm * bprm,
47091 realdatastart = (unsigned long) -ENOMEM;
47092 printk("Unable to allocate RAM for process data, errno %d\n",
47093 (int)-realdatastart);
47094+ down_write(&current->mm->mmap_sem);
47095 do_munmap(current->mm, textpos, text_len);
47096+ up_write(&current->mm->mmap_sem);
47097 ret = realdatastart;
47098 goto err;
47099 }
47100@@ -588,8 +590,10 @@ static int load_flat_file(struct linux_binprm * bprm,
47101 }
47102 if (IS_ERR_VALUE(result)) {
47103 printk("Unable to read data+bss, errno %d\n", (int)-result);
47104+ down_write(&current->mm->mmap_sem);
47105 do_munmap(current->mm, textpos, text_len);
47106 do_munmap(current->mm, realdatastart, data_len + extra);
47107+ up_write(&current->mm->mmap_sem);
47108 ret = result;
47109 goto err;
47110 }
47111@@ -658,8 +662,10 @@ static int load_flat_file(struct linux_binprm * bprm,
47112 }
47113 if (IS_ERR_VALUE(result)) {
47114 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
47115+ down_write(&current->mm->mmap_sem);
47116 do_munmap(current->mm, textpos, text_len + data_len + extra +
47117 MAX_SHARED_LIBS * sizeof(unsigned long));
47118+ up_write(&current->mm->mmap_sem);
47119 ret = result;
47120 goto err;
47121 }
47122diff --git a/fs/bio.c b/fs/bio.c
47123index e696713..83de133 100644
47124--- a/fs/bio.c
47125+++ b/fs/bio.c
47126@@ -78,7 +78,7 @@ static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
47127
47128 i = 0;
47129 while (i < bio_slab_nr) {
47130- struct bio_slab *bslab = &bio_slabs[i];
47131+ bslab = &bio_slabs[i];
47132
47133 if (!bslab->slab && entry == -1)
47134 entry = i;
47135@@ -1236,7 +1236,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
47136 const int read = bio_data_dir(bio) == READ;
47137 struct bio_map_data *bmd = bio->bi_private;
47138 int i;
47139- char *p = bmd->sgvecs[0].iov_base;
47140+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
47141
47142 __bio_for_each_segment(bvec, bio, i, 0) {
47143 char *addr = page_address(bvec->bv_page);
47144diff --git a/fs/block_dev.c b/fs/block_dev.c
47145index e65efa2..04fae57 100644
47146--- a/fs/block_dev.c
47147+++ b/fs/block_dev.c
47148@@ -664,7 +664,7 @@ int bd_claim(struct block_device *bdev, void *holder)
47149 else if (bdev->bd_contains == bdev)
47150 res = 0; /* is a whole device which isn't held */
47151
47152- else if (bdev->bd_contains->bd_holder == bd_claim)
47153+ else if (bdev->bd_contains->bd_holder == (void *)bd_claim)
47154 res = 0; /* is a partition of a device that is being partitioned */
47155 else if (bdev->bd_contains->bd_holder != NULL)
47156 res = -EBUSY; /* is a partition of a held device */
47157diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
47158index c4bc570..42acd8d 100644
47159--- a/fs/btrfs/ctree.c
47160+++ b/fs/btrfs/ctree.c
47161@@ -461,9 +461,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
47162 free_extent_buffer(buf);
47163 add_root_to_dirty_list(root);
47164 } else {
47165- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
47166- parent_start = parent->start;
47167- else
47168+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
47169+ if (parent)
47170+ parent_start = parent->start;
47171+ else
47172+ parent_start = 0;
47173+ } else
47174 parent_start = 0;
47175
47176 WARN_ON(trans->transid != btrfs_header_generation(parent));
47177@@ -3645,7 +3648,6 @@ setup_items_for_insert(struct btrfs_trans_handle *trans,
47178
47179 ret = 0;
47180 if (slot == 0) {
47181- struct btrfs_disk_key disk_key;
47182 btrfs_cpu_key_to_disk(&disk_key, cpu_key);
47183 ret = fixup_low_keys(trans, root, path, &disk_key, 1);
47184 }
47185diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
47186index f447188..59c17c5 100644
47187--- a/fs/btrfs/disk-io.c
47188+++ b/fs/btrfs/disk-io.c
47189@@ -39,7 +39,7 @@
47190 #include "tree-log.h"
47191 #include "free-space-cache.h"
47192
47193-static struct extent_io_ops btree_extent_io_ops;
47194+static const struct extent_io_ops btree_extent_io_ops;
47195 static void end_workqueue_fn(struct btrfs_work *work);
47196 static void free_fs_root(struct btrfs_root *root);
47197
47198@@ -2607,7 +2607,7 @@ out:
47199 return 0;
47200 }
47201
47202-static struct extent_io_ops btree_extent_io_ops = {
47203+static const struct extent_io_ops btree_extent_io_ops = {
47204 .write_cache_pages_lock_hook = btree_lock_page_hook,
47205 .readpage_end_io_hook = btree_readpage_end_io_hook,
47206 .submit_bio_hook = btree_submit_bio_hook,
47207diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
47208index 559f724..a026171 100644
47209--- a/fs/btrfs/extent-tree.c
47210+++ b/fs/btrfs/extent-tree.c
47211@@ -7141,6 +7141,10 @@ static noinline int relocate_one_extent(struct btrfs_root *extent_root,
47212 u64 group_start = group->key.objectid;
47213 new_extents = kmalloc(sizeof(*new_extents),
47214 GFP_NOFS);
47215+ if (!new_extents) {
47216+ ret = -ENOMEM;
47217+ goto out;
47218+ }
47219 nr_extents = 1;
47220 ret = get_new_locations(reloc_inode,
47221 extent_key,
47222diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
47223index 36de250..7ec75c7 100644
47224--- a/fs/btrfs/extent_io.h
47225+++ b/fs/btrfs/extent_io.h
47226@@ -49,36 +49,36 @@ typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
47227 struct bio *bio, int mirror_num,
47228 unsigned long bio_flags);
47229 struct extent_io_ops {
47230- int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
47231+ int (* const fill_delalloc)(struct inode *inode, struct page *locked_page,
47232 u64 start, u64 end, int *page_started,
47233 unsigned long *nr_written);
47234- int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
47235- int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
47236+ int (* const writepage_start_hook)(struct page *page, u64 start, u64 end);
47237+ int (* const writepage_io_hook)(struct page *page, u64 start, u64 end);
47238 extent_submit_bio_hook_t *submit_bio_hook;
47239- int (*merge_bio_hook)(struct page *page, unsigned long offset,
47240+ int (* const merge_bio_hook)(struct page *page, unsigned long offset,
47241 size_t size, struct bio *bio,
47242 unsigned long bio_flags);
47243- int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
47244- int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
47245+ int (* const readpage_io_hook)(struct page *page, u64 start, u64 end);
47246+ int (* const readpage_io_failed_hook)(struct bio *bio, struct page *page,
47247 u64 start, u64 end,
47248 struct extent_state *state);
47249- int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
47250+ int (* const writepage_io_failed_hook)(struct bio *bio, struct page *page,
47251 u64 start, u64 end,
47252 struct extent_state *state);
47253- int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
47254+ int (* const readpage_end_io_hook)(struct page *page, u64 start, u64 end,
47255 struct extent_state *state);
47256- int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
47257+ int (* const writepage_end_io_hook)(struct page *page, u64 start, u64 end,
47258 struct extent_state *state, int uptodate);
47259- int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
47260+ int (* const set_bit_hook)(struct inode *inode, u64 start, u64 end,
47261 unsigned long old, unsigned long bits);
47262- int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
47263+ int (* const clear_bit_hook)(struct inode *inode, struct extent_state *state,
47264 unsigned long bits);
47265- int (*merge_extent_hook)(struct inode *inode,
47266+ int (* const merge_extent_hook)(struct inode *inode,
47267 struct extent_state *new,
47268 struct extent_state *other);
47269- int (*split_extent_hook)(struct inode *inode,
47270+ int (* const split_extent_hook)(struct inode *inode,
47271 struct extent_state *orig, u64 split);
47272- int (*write_cache_pages_lock_hook)(struct page *page);
47273+ int (* const write_cache_pages_lock_hook)(struct page *page);
47274 };
47275
47276 struct extent_io_tree {
47277@@ -88,7 +88,7 @@ struct extent_io_tree {
47278 u64 dirty_bytes;
47279 spinlock_t lock;
47280 spinlock_t buffer_lock;
47281- struct extent_io_ops *ops;
47282+ const struct extent_io_ops *ops;
47283 };
47284
47285 struct extent_state {
47286diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
47287index cb2849f..3718fb4 100644
47288--- a/fs/btrfs/free-space-cache.c
47289+++ b/fs/btrfs/free-space-cache.c
47290@@ -1074,8 +1074,6 @@ u64 btrfs_alloc_from_cluster(struct btrfs_block_group_cache *block_group,
47291
47292 while(1) {
47293 if (entry->bytes < bytes || entry->offset < min_start) {
47294- struct rb_node *node;
47295-
47296 node = rb_next(&entry->offset_index);
47297 if (!node)
47298 break;
47299@@ -1226,7 +1224,7 @@ again:
47300 */
47301 while (entry->bitmap || found_bitmap ||
47302 (!entry->bitmap && entry->bytes < min_bytes)) {
47303- struct rb_node *node = rb_next(&entry->offset_index);
47304+ node = rb_next(&entry->offset_index);
47305
47306 if (entry->bitmap && entry->bytes > bytes + empty_size) {
47307 ret = btrfs_bitmap_cluster(block_group, entry, cluster,
47308diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
47309index e03a836..323837e 100644
47310--- a/fs/btrfs/inode.c
47311+++ b/fs/btrfs/inode.c
47312@@ -63,7 +63,7 @@ static const struct inode_operations btrfs_file_inode_operations;
47313 static const struct address_space_operations btrfs_aops;
47314 static const struct address_space_operations btrfs_symlink_aops;
47315 static const struct file_operations btrfs_dir_file_operations;
47316-static struct extent_io_ops btrfs_extent_io_ops;
47317+static const struct extent_io_ops btrfs_extent_io_ops;
47318
47319 static struct kmem_cache *btrfs_inode_cachep;
47320 struct kmem_cache *btrfs_trans_handle_cachep;
47321@@ -925,6 +925,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
47322 1, 0, NULL, GFP_NOFS);
47323 while (start < end) {
47324 async_cow = kmalloc(sizeof(*async_cow), GFP_NOFS);
47325+ BUG_ON(!async_cow);
47326 async_cow->inode = inode;
47327 async_cow->root = root;
47328 async_cow->locked_page = locked_page;
47329@@ -4591,6 +4592,8 @@ static noinline int uncompress_inline(struct btrfs_path *path,
47330 inline_size = btrfs_file_extent_inline_item_len(leaf,
47331 btrfs_item_nr(leaf, path->slots[0]));
47332 tmp = kmalloc(inline_size, GFP_NOFS);
47333+ if (!tmp)
47334+ return -ENOMEM;
47335 ptr = btrfs_file_extent_inline_start(item);
47336
47337 read_extent_buffer(leaf, tmp, ptr, inline_size);
47338@@ -5410,7 +5413,7 @@ fail:
47339 return -ENOMEM;
47340 }
47341
47342-static int btrfs_getattr(struct vfsmount *mnt,
47343+int btrfs_getattr(struct vfsmount *mnt,
47344 struct dentry *dentry, struct kstat *stat)
47345 {
47346 struct inode *inode = dentry->d_inode;
47347@@ -5422,6 +5425,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
47348 return 0;
47349 }
47350
47351+EXPORT_SYMBOL(btrfs_getattr);
47352+
47353+dev_t get_btrfs_dev_from_inode(struct inode *inode)
47354+{
47355+ return BTRFS_I(inode)->root->anon_super.s_dev;
47356+}
47357+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
47358+
47359 static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
47360 struct inode *new_dir, struct dentry *new_dentry)
47361 {
47362@@ -5972,7 +5983,7 @@ static const struct file_operations btrfs_dir_file_operations = {
47363 .fsync = btrfs_sync_file,
47364 };
47365
47366-static struct extent_io_ops btrfs_extent_io_ops = {
47367+static const struct extent_io_ops btrfs_extent_io_ops = {
47368 .fill_delalloc = run_delalloc_range,
47369 .submit_bio_hook = btrfs_submit_bio_hook,
47370 .merge_bio_hook = btrfs_merge_bio_hook,
47371diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
47372index ab7ab53..94e0781 100644
47373--- a/fs/btrfs/relocation.c
47374+++ b/fs/btrfs/relocation.c
47375@@ -884,7 +884,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
47376 }
47377 spin_unlock(&rc->reloc_root_tree.lock);
47378
47379- BUG_ON((struct btrfs_root *)node->data != root);
47380+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
47381
47382 if (!del) {
47383 spin_lock(&rc->reloc_root_tree.lock);
47384diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
47385index a240b6f..4ce16ef 100644
47386--- a/fs/btrfs/sysfs.c
47387+++ b/fs/btrfs/sysfs.c
47388@@ -164,12 +164,12 @@ static void btrfs_root_release(struct kobject *kobj)
47389 complete(&root->kobj_unregister);
47390 }
47391
47392-static struct sysfs_ops btrfs_super_attr_ops = {
47393+static const struct sysfs_ops btrfs_super_attr_ops = {
47394 .show = btrfs_super_attr_show,
47395 .store = btrfs_super_attr_store,
47396 };
47397
47398-static struct sysfs_ops btrfs_root_attr_ops = {
47399+static const struct sysfs_ops btrfs_root_attr_ops = {
47400 .show = btrfs_root_attr_show,
47401 .store = btrfs_root_attr_store,
47402 };
47403diff --git a/fs/buffer.c b/fs/buffer.c
47404index 6fa5302..395d9f6 100644
47405--- a/fs/buffer.c
47406+++ b/fs/buffer.c
47407@@ -25,6 +25,7 @@
47408 #include <linux/percpu.h>
47409 #include <linux/slab.h>
47410 #include <linux/capability.h>
47411+#include <linux/security.h>
47412 #include <linux/blkdev.h>
47413 #include <linux/file.h>
47414 #include <linux/quotaops.h>
47415diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
47416index 3797e00..ce776f6 100644
47417--- a/fs/cachefiles/bind.c
47418+++ b/fs/cachefiles/bind.c
47419@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
47420 args);
47421
47422 /* start by checking things over */
47423- ASSERT(cache->fstop_percent >= 0 &&
47424- cache->fstop_percent < cache->fcull_percent &&
47425+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
47426 cache->fcull_percent < cache->frun_percent &&
47427 cache->frun_percent < 100);
47428
47429- ASSERT(cache->bstop_percent >= 0 &&
47430- cache->bstop_percent < cache->bcull_percent &&
47431+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
47432 cache->bcull_percent < cache->brun_percent &&
47433 cache->brun_percent < 100);
47434
47435diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
47436index 4618516..bb30d01 100644
47437--- a/fs/cachefiles/daemon.c
47438+++ b/fs/cachefiles/daemon.c
47439@@ -220,7 +220,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
47440 if (test_bit(CACHEFILES_DEAD, &cache->flags))
47441 return -EIO;
47442
47443- if (datalen < 0 || datalen > PAGE_SIZE - 1)
47444+ if (datalen > PAGE_SIZE - 1)
47445 return -EOPNOTSUPP;
47446
47447 /* drag the command string into the kernel so we can parse it */
47448@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
47449 if (args[0] != '%' || args[1] != '\0')
47450 return -EINVAL;
47451
47452- if (fstop < 0 || fstop >= cache->fcull_percent)
47453+ if (fstop >= cache->fcull_percent)
47454 return cachefiles_daemon_range_error(cache, args);
47455
47456 cache->fstop_percent = fstop;
47457@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
47458 if (args[0] != '%' || args[1] != '\0')
47459 return -EINVAL;
47460
47461- if (bstop < 0 || bstop >= cache->bcull_percent)
47462+ if (bstop >= cache->bcull_percent)
47463 return cachefiles_daemon_range_error(cache, args);
47464
47465 cache->bstop_percent = bstop;
47466diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
47467index f7c255f..fcd61de 100644
47468--- a/fs/cachefiles/internal.h
47469+++ b/fs/cachefiles/internal.h
47470@@ -56,7 +56,7 @@ struct cachefiles_cache {
47471 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
47472 struct rb_root active_nodes; /* active nodes (can't be culled) */
47473 rwlock_t active_lock; /* lock for active_nodes */
47474- atomic_t gravecounter; /* graveyard uniquifier */
47475+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
47476 unsigned frun_percent; /* when to stop culling (% files) */
47477 unsigned fcull_percent; /* when to start culling (% files) */
47478 unsigned fstop_percent; /* when to stop allocating (% files) */
47479@@ -168,19 +168,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
47480 * proc.c
47481 */
47482 #ifdef CONFIG_CACHEFILES_HISTOGRAM
47483-extern atomic_t cachefiles_lookup_histogram[HZ];
47484-extern atomic_t cachefiles_mkdir_histogram[HZ];
47485-extern atomic_t cachefiles_create_histogram[HZ];
47486+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
47487+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
47488+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
47489
47490 extern int __init cachefiles_proc_init(void);
47491 extern void cachefiles_proc_cleanup(void);
47492 static inline
47493-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
47494+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
47495 {
47496 unsigned long jif = jiffies - start_jif;
47497 if (jif >= HZ)
47498 jif = HZ - 1;
47499- atomic_inc(&histogram[jif]);
47500+ atomic_inc_unchecked(&histogram[jif]);
47501 }
47502
47503 #else
47504diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
47505index 14ac480..a62766c 100644
47506--- a/fs/cachefiles/namei.c
47507+++ b/fs/cachefiles/namei.c
47508@@ -250,7 +250,7 @@ try_again:
47509 /* first step is to make up a grave dentry in the graveyard */
47510 sprintf(nbuffer, "%08x%08x",
47511 (uint32_t) get_seconds(),
47512- (uint32_t) atomic_inc_return(&cache->gravecounter));
47513+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
47514
47515 /* do the multiway lock magic */
47516 trap = lock_rename(cache->graveyard, dir);
47517diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
47518index eccd339..4c1d995 100644
47519--- a/fs/cachefiles/proc.c
47520+++ b/fs/cachefiles/proc.c
47521@@ -14,9 +14,9 @@
47522 #include <linux/seq_file.h>
47523 #include "internal.h"
47524
47525-atomic_t cachefiles_lookup_histogram[HZ];
47526-atomic_t cachefiles_mkdir_histogram[HZ];
47527-atomic_t cachefiles_create_histogram[HZ];
47528+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
47529+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
47530+atomic_unchecked_t cachefiles_create_histogram[HZ];
47531
47532 /*
47533 * display the latency histogram
47534@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
47535 return 0;
47536 default:
47537 index = (unsigned long) v - 3;
47538- x = atomic_read(&cachefiles_lookup_histogram[index]);
47539- y = atomic_read(&cachefiles_mkdir_histogram[index]);
47540- z = atomic_read(&cachefiles_create_histogram[index]);
47541+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
47542+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
47543+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
47544 if (x == 0 && y == 0 && z == 0)
47545 return 0;
47546
47547diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
47548index a6c8c6f..5cf8517 100644
47549--- a/fs/cachefiles/rdwr.c
47550+++ b/fs/cachefiles/rdwr.c
47551@@ -946,7 +946,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
47552 old_fs = get_fs();
47553 set_fs(KERNEL_DS);
47554 ret = file->f_op->write(
47555- file, (const void __user *) data, len, &pos);
47556+ file, (const void __force_user *) data, len, &pos);
47557 set_fs(old_fs);
47558 kunmap(page);
47559 if (ret != len)
47560diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
47561index 42cec2a..2aba466 100644
47562--- a/fs/cifs/cifs_debug.c
47563+++ b/fs/cifs/cifs_debug.c
47564@@ -256,25 +256,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
47565 tcon = list_entry(tmp3,
47566 struct cifsTconInfo,
47567 tcon_list);
47568- atomic_set(&tcon->num_smbs_sent, 0);
47569- atomic_set(&tcon->num_writes, 0);
47570- atomic_set(&tcon->num_reads, 0);
47571- atomic_set(&tcon->num_oplock_brks, 0);
47572- atomic_set(&tcon->num_opens, 0);
47573- atomic_set(&tcon->num_posixopens, 0);
47574- atomic_set(&tcon->num_posixmkdirs, 0);
47575- atomic_set(&tcon->num_closes, 0);
47576- atomic_set(&tcon->num_deletes, 0);
47577- atomic_set(&tcon->num_mkdirs, 0);
47578- atomic_set(&tcon->num_rmdirs, 0);
47579- atomic_set(&tcon->num_renames, 0);
47580- atomic_set(&tcon->num_t2renames, 0);
47581- atomic_set(&tcon->num_ffirst, 0);
47582- atomic_set(&tcon->num_fnext, 0);
47583- atomic_set(&tcon->num_fclose, 0);
47584- atomic_set(&tcon->num_hardlinks, 0);
47585- atomic_set(&tcon->num_symlinks, 0);
47586- atomic_set(&tcon->num_locks, 0);
47587+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
47588+ atomic_set_unchecked(&tcon->num_writes, 0);
47589+ atomic_set_unchecked(&tcon->num_reads, 0);
47590+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
47591+ atomic_set_unchecked(&tcon->num_opens, 0);
47592+ atomic_set_unchecked(&tcon->num_posixopens, 0);
47593+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
47594+ atomic_set_unchecked(&tcon->num_closes, 0);
47595+ atomic_set_unchecked(&tcon->num_deletes, 0);
47596+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
47597+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
47598+ atomic_set_unchecked(&tcon->num_renames, 0);
47599+ atomic_set_unchecked(&tcon->num_t2renames, 0);
47600+ atomic_set_unchecked(&tcon->num_ffirst, 0);
47601+ atomic_set_unchecked(&tcon->num_fnext, 0);
47602+ atomic_set_unchecked(&tcon->num_fclose, 0);
47603+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
47604+ atomic_set_unchecked(&tcon->num_symlinks, 0);
47605+ atomic_set_unchecked(&tcon->num_locks, 0);
47606 }
47607 }
47608 }
47609@@ -334,41 +334,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
47610 if (tcon->need_reconnect)
47611 seq_puts(m, "\tDISCONNECTED ");
47612 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
47613- atomic_read(&tcon->num_smbs_sent),
47614- atomic_read(&tcon->num_oplock_brks));
47615+ atomic_read_unchecked(&tcon->num_smbs_sent),
47616+ atomic_read_unchecked(&tcon->num_oplock_brks));
47617 seq_printf(m, "\nReads: %d Bytes: %lld",
47618- atomic_read(&tcon->num_reads),
47619+ atomic_read_unchecked(&tcon->num_reads),
47620 (long long)(tcon->bytes_read));
47621 seq_printf(m, "\nWrites: %d Bytes: %lld",
47622- atomic_read(&tcon->num_writes),
47623+ atomic_read_unchecked(&tcon->num_writes),
47624 (long long)(tcon->bytes_written));
47625 seq_printf(m, "\nFlushes: %d",
47626- atomic_read(&tcon->num_flushes));
47627+ atomic_read_unchecked(&tcon->num_flushes));
47628 seq_printf(m, "\nLocks: %d HardLinks: %d "
47629 "Symlinks: %d",
47630- atomic_read(&tcon->num_locks),
47631- atomic_read(&tcon->num_hardlinks),
47632- atomic_read(&tcon->num_symlinks));
47633+ atomic_read_unchecked(&tcon->num_locks),
47634+ atomic_read_unchecked(&tcon->num_hardlinks),
47635+ atomic_read_unchecked(&tcon->num_symlinks));
47636 seq_printf(m, "\nOpens: %d Closes: %d "
47637 "Deletes: %d",
47638- atomic_read(&tcon->num_opens),
47639- atomic_read(&tcon->num_closes),
47640- atomic_read(&tcon->num_deletes));
47641+ atomic_read_unchecked(&tcon->num_opens),
47642+ atomic_read_unchecked(&tcon->num_closes),
47643+ atomic_read_unchecked(&tcon->num_deletes));
47644 seq_printf(m, "\nPosix Opens: %d "
47645 "Posix Mkdirs: %d",
47646- atomic_read(&tcon->num_posixopens),
47647- atomic_read(&tcon->num_posixmkdirs));
47648+ atomic_read_unchecked(&tcon->num_posixopens),
47649+ atomic_read_unchecked(&tcon->num_posixmkdirs));
47650 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
47651- atomic_read(&tcon->num_mkdirs),
47652- atomic_read(&tcon->num_rmdirs));
47653+ atomic_read_unchecked(&tcon->num_mkdirs),
47654+ atomic_read_unchecked(&tcon->num_rmdirs));
47655 seq_printf(m, "\nRenames: %d T2 Renames %d",
47656- atomic_read(&tcon->num_renames),
47657- atomic_read(&tcon->num_t2renames));
47658+ atomic_read_unchecked(&tcon->num_renames),
47659+ atomic_read_unchecked(&tcon->num_t2renames));
47660 seq_printf(m, "\nFindFirst: %d FNext %d "
47661 "FClose %d",
47662- atomic_read(&tcon->num_ffirst),
47663- atomic_read(&tcon->num_fnext),
47664- atomic_read(&tcon->num_fclose));
47665+ atomic_read_unchecked(&tcon->num_ffirst),
47666+ atomic_read_unchecked(&tcon->num_fnext),
47667+ atomic_read_unchecked(&tcon->num_fclose));
47668 }
47669 }
47670 }
47671diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
47672index 1445407..68cb0dc 100644
47673--- a/fs/cifs/cifsfs.c
47674+++ b/fs/cifs/cifsfs.c
47675@@ -869,7 +869,7 @@ cifs_init_request_bufs(void)
47676 cifs_req_cachep = kmem_cache_create("cifs_request",
47677 CIFSMaxBufSize +
47678 MAX_CIFS_HDR_SIZE, 0,
47679- SLAB_HWCACHE_ALIGN, NULL);
47680+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
47681 if (cifs_req_cachep == NULL)
47682 return -ENOMEM;
47683
47684@@ -896,7 +896,7 @@ cifs_init_request_bufs(void)
47685 efficient to alloc 1 per page off the slab compared to 17K (5page)
47686 alloc of large cifs buffers even when page debugging is on */
47687 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
47688- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
47689+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
47690 NULL);
47691 if (cifs_sm_req_cachep == NULL) {
47692 mempool_destroy(cifs_req_poolp);
47693@@ -991,8 +991,8 @@ init_cifs(void)
47694 atomic_set(&bufAllocCount, 0);
47695 atomic_set(&smBufAllocCount, 0);
47696 #ifdef CONFIG_CIFS_STATS2
47697- atomic_set(&totBufAllocCount, 0);
47698- atomic_set(&totSmBufAllocCount, 0);
47699+ atomic_set_unchecked(&totBufAllocCount, 0);
47700+ atomic_set_unchecked(&totSmBufAllocCount, 0);
47701 #endif /* CONFIG_CIFS_STATS2 */
47702
47703 atomic_set(&midCount, 0);
47704diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
47705index e29581e..1c22bab 100644
47706--- a/fs/cifs/cifsglob.h
47707+++ b/fs/cifs/cifsglob.h
47708@@ -252,28 +252,28 @@ struct cifsTconInfo {
47709 __u16 Flags; /* optional support bits */
47710 enum statusEnum tidStatus;
47711 #ifdef CONFIG_CIFS_STATS
47712- atomic_t num_smbs_sent;
47713- atomic_t num_writes;
47714- atomic_t num_reads;
47715- atomic_t num_flushes;
47716- atomic_t num_oplock_brks;
47717- atomic_t num_opens;
47718- atomic_t num_closes;
47719- atomic_t num_deletes;
47720- atomic_t num_mkdirs;
47721- atomic_t num_posixopens;
47722- atomic_t num_posixmkdirs;
47723- atomic_t num_rmdirs;
47724- atomic_t num_renames;
47725- atomic_t num_t2renames;
47726- atomic_t num_ffirst;
47727- atomic_t num_fnext;
47728- atomic_t num_fclose;
47729- atomic_t num_hardlinks;
47730- atomic_t num_symlinks;
47731- atomic_t num_locks;
47732- atomic_t num_acl_get;
47733- atomic_t num_acl_set;
47734+ atomic_unchecked_t num_smbs_sent;
47735+ atomic_unchecked_t num_writes;
47736+ atomic_unchecked_t num_reads;
47737+ atomic_unchecked_t num_flushes;
47738+ atomic_unchecked_t num_oplock_brks;
47739+ atomic_unchecked_t num_opens;
47740+ atomic_unchecked_t num_closes;
47741+ atomic_unchecked_t num_deletes;
47742+ atomic_unchecked_t num_mkdirs;
47743+ atomic_unchecked_t num_posixopens;
47744+ atomic_unchecked_t num_posixmkdirs;
47745+ atomic_unchecked_t num_rmdirs;
47746+ atomic_unchecked_t num_renames;
47747+ atomic_unchecked_t num_t2renames;
47748+ atomic_unchecked_t num_ffirst;
47749+ atomic_unchecked_t num_fnext;
47750+ atomic_unchecked_t num_fclose;
47751+ atomic_unchecked_t num_hardlinks;
47752+ atomic_unchecked_t num_symlinks;
47753+ atomic_unchecked_t num_locks;
47754+ atomic_unchecked_t num_acl_get;
47755+ atomic_unchecked_t num_acl_set;
47756 #ifdef CONFIG_CIFS_STATS2
47757 unsigned long long time_writes;
47758 unsigned long long time_reads;
47759@@ -414,7 +414,7 @@ static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
47760 }
47761
47762 #ifdef CONFIG_CIFS_STATS
47763-#define cifs_stats_inc atomic_inc
47764+#define cifs_stats_inc atomic_inc_unchecked
47765
47766 static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
47767 unsigned int bytes)
47768@@ -701,8 +701,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
47769 /* Various Debug counters */
47770 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
47771 #ifdef CONFIG_CIFS_STATS2
47772-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
47773-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
47774+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
47775+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
47776 #endif
47777 GLOBAL_EXTERN atomic_t smBufAllocCount;
47778 GLOBAL_EXTERN atomic_t midCount;
47779diff --git a/fs/cifs/link.c b/fs/cifs/link.c
47780index fc1e048..28b3441 100644
47781--- a/fs/cifs/link.c
47782+++ b/fs/cifs/link.c
47783@@ -215,7 +215,7 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
47784
47785 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
47786 {
47787- char *p = nd_get_link(nd);
47788+ const char *p = nd_get_link(nd);
47789 if (!IS_ERR(p))
47790 kfree(p);
47791 }
47792diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
47793index 95b82e8..12a538d 100644
47794--- a/fs/cifs/misc.c
47795+++ b/fs/cifs/misc.c
47796@@ -155,7 +155,7 @@ cifs_buf_get(void)
47797 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
47798 atomic_inc(&bufAllocCount);
47799 #ifdef CONFIG_CIFS_STATS2
47800- atomic_inc(&totBufAllocCount);
47801+ atomic_inc_unchecked(&totBufAllocCount);
47802 #endif /* CONFIG_CIFS_STATS2 */
47803 }
47804
47805@@ -190,7 +190,7 @@ cifs_small_buf_get(void)
47806 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
47807 atomic_inc(&smBufAllocCount);
47808 #ifdef CONFIG_CIFS_STATS2
47809- atomic_inc(&totSmBufAllocCount);
47810+ atomic_inc_unchecked(&totSmBufAllocCount);
47811 #endif /* CONFIG_CIFS_STATS2 */
47812
47813 }
47814diff --git a/fs/coda/cache.c b/fs/coda/cache.c
47815index a5bf577..6d19845 100644
47816--- a/fs/coda/cache.c
47817+++ b/fs/coda/cache.c
47818@@ -24,14 +24,14 @@
47819 #include <linux/coda_fs_i.h>
47820 #include <linux/coda_cache.h>
47821
47822-static atomic_t permission_epoch = ATOMIC_INIT(0);
47823+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
47824
47825 /* replace or extend an acl cache hit */
47826 void coda_cache_enter(struct inode *inode, int mask)
47827 {
47828 struct coda_inode_info *cii = ITOC(inode);
47829
47830- cii->c_cached_epoch = atomic_read(&permission_epoch);
47831+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
47832 if (cii->c_uid != current_fsuid()) {
47833 cii->c_uid = current_fsuid();
47834 cii->c_cached_perm = mask;
47835@@ -43,13 +43,13 @@ void coda_cache_enter(struct inode *inode, int mask)
47836 void coda_cache_clear_inode(struct inode *inode)
47837 {
47838 struct coda_inode_info *cii = ITOC(inode);
47839- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
47840+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
47841 }
47842
47843 /* remove all acl caches */
47844 void coda_cache_clear_all(struct super_block *sb)
47845 {
47846- atomic_inc(&permission_epoch);
47847+ atomic_inc_unchecked(&permission_epoch);
47848 }
47849
47850
47851@@ -61,7 +61,7 @@ int coda_cache_check(struct inode *inode, int mask)
47852
47853 hit = (mask & cii->c_cached_perm) == mask &&
47854 cii->c_uid == current_fsuid() &&
47855- cii->c_cached_epoch == atomic_read(&permission_epoch);
47856+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
47857
47858 return hit;
47859 }
47860diff --git a/fs/compat.c b/fs/compat.c
47861index d1e2411..27064e4 100644
47862--- a/fs/compat.c
47863+++ b/fs/compat.c
47864@@ -133,8 +133,8 @@ asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval _
47865 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
47866 {
47867 compat_ino_t ino = stat->ino;
47868- typeof(ubuf->st_uid) uid = 0;
47869- typeof(ubuf->st_gid) gid = 0;
47870+ typeof(((struct compat_stat *)0)->st_uid) uid = 0;
47871+ typeof(((struct compat_stat *)0)->st_gid) gid = 0;
47872 int err;
47873
47874 SET_UID(uid, stat->uid);
47875@@ -533,7 +533,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
47876
47877 set_fs(KERNEL_DS);
47878 /* The __user pointer cast is valid because of the set_fs() */
47879- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
47880+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
47881 set_fs(oldfs);
47882 /* truncating is ok because it's a user address */
47883 if (!ret)
47884@@ -830,6 +830,7 @@ struct compat_old_linux_dirent {
47885
47886 struct compat_readdir_callback {
47887 struct compat_old_linux_dirent __user *dirent;
47888+ struct file * file;
47889 int result;
47890 };
47891
47892@@ -847,6 +848,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
47893 buf->result = -EOVERFLOW;
47894 return -EOVERFLOW;
47895 }
47896+
47897+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47898+ return 0;
47899+
47900 buf->result++;
47901 dirent = buf->dirent;
47902 if (!access_ok(VERIFY_WRITE, dirent,
47903@@ -879,6 +884,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
47904
47905 buf.result = 0;
47906 buf.dirent = dirent;
47907+ buf.file = file;
47908
47909 error = vfs_readdir(file, compat_fillonedir, &buf);
47910 if (buf.result)
47911@@ -899,6 +905,7 @@ struct compat_linux_dirent {
47912 struct compat_getdents_callback {
47913 struct compat_linux_dirent __user *current_dir;
47914 struct compat_linux_dirent __user *previous;
47915+ struct file * file;
47916 int count;
47917 int error;
47918 };
47919@@ -919,6 +926,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
47920 buf->error = -EOVERFLOW;
47921 return -EOVERFLOW;
47922 }
47923+
47924+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47925+ return 0;
47926+
47927 dirent = buf->previous;
47928 if (dirent) {
47929 if (__put_user(offset, &dirent->d_off))
47930@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47931 buf.previous = NULL;
47932 buf.count = count;
47933 buf.error = 0;
47934+ buf.file = file;
47935
47936 error = vfs_readdir(file, compat_filldir, &buf);
47937 if (error >= 0)
47938@@ -987,6 +999,7 @@ out:
47939 struct compat_getdents_callback64 {
47940 struct linux_dirent64 __user *current_dir;
47941 struct linux_dirent64 __user *previous;
47942+ struct file * file;
47943 int count;
47944 int error;
47945 };
47946@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
47947 buf->error = -EINVAL; /* only used if we fail.. */
47948 if (reclen > buf->count)
47949 return -EINVAL;
47950+
47951+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47952+ return 0;
47953+
47954 dirent = buf->previous;
47955
47956 if (dirent) {
47957@@ -1054,13 +1071,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
47958 buf.previous = NULL;
47959 buf.count = count;
47960 buf.error = 0;
47961+ buf.file = file;
47962
47963 error = vfs_readdir(file, compat_filldir64, &buf);
47964 if (error >= 0)
47965 error = buf.error;
47966 lastdirent = buf.previous;
47967 if (lastdirent) {
47968- typeof(lastdirent->d_off) d_off = file->f_pos;
47969+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
47970 if (__put_user_unaligned(d_off, &lastdirent->d_off))
47971 error = -EFAULT;
47972 else
47973@@ -1098,7 +1116,7 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
47974 * verify all the pointers
47975 */
47976 ret = -EINVAL;
47977- if ((nr_segs > UIO_MAXIOV) || (nr_segs <= 0))
47978+ if (nr_segs > UIO_MAXIOV)
47979 goto out;
47980 if (!file->f_op)
47981 goto out;
47982@@ -1463,11 +1481,35 @@ int compat_do_execve(char * filename,
47983 compat_uptr_t __user *envp,
47984 struct pt_regs * regs)
47985 {
47986+#ifdef CONFIG_GRKERNSEC
47987+ struct file *old_exec_file;
47988+ struct acl_subject_label *old_acl;
47989+ struct rlimit old_rlim[RLIM_NLIMITS];
47990+#endif
47991 struct linux_binprm *bprm;
47992 struct file *file;
47993 struct files_struct *displaced;
47994 bool clear_in_exec;
47995 int retval;
47996+ const struct cred *cred = current_cred();
47997+
47998+ /*
47999+ * We move the actual failure in case of RLIMIT_NPROC excess from
48000+ * set*uid() to execve() because too many poorly written programs
48001+ * don't check setuid() return code. Here we additionally recheck
48002+ * whether NPROC limit is still exceeded.
48003+ */
48004+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
48005+
48006+ if ((current->flags & PF_NPROC_EXCEEDED) &&
48007+ atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
48008+ retval = -EAGAIN;
48009+ goto out_ret;
48010+ }
48011+
48012+ /* We're below the limit (still or again), so we don't want to make
48013+ * further execve() calls fail. */
48014+ current->flags &= ~PF_NPROC_EXCEEDED;
48015
48016 retval = unshare_files(&displaced);
48017 if (retval)
48018@@ -1499,6 +1541,15 @@ int compat_do_execve(char * filename,
48019 bprm->filename = filename;
48020 bprm->interp = filename;
48021
48022+ if (gr_process_user_ban()) {
48023+ retval = -EPERM;
48024+ goto out_file;
48025+ }
48026+
48027+ retval = -EACCES;
48028+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
48029+ goto out_file;
48030+
48031 retval = bprm_mm_init(bprm);
48032 if (retval)
48033 goto out_file;
48034@@ -1528,9 +1579,40 @@ int compat_do_execve(char * filename,
48035 if (retval < 0)
48036 goto out;
48037
48038+ if (!gr_tpe_allow(file)) {
48039+ retval = -EACCES;
48040+ goto out;
48041+ }
48042+
48043+ if (gr_check_crash_exec(file)) {
48044+ retval = -EACCES;
48045+ goto out;
48046+ }
48047+
48048+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
48049+
48050+ gr_handle_exec_args_compat(bprm, argv);
48051+
48052+#ifdef CONFIG_GRKERNSEC
48053+ old_acl = current->acl;
48054+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
48055+ old_exec_file = current->exec_file;
48056+ get_file(file);
48057+ current->exec_file = file;
48058+#endif
48059+
48060+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
48061+ bprm->unsafe & LSM_UNSAFE_SHARE);
48062+ if (retval < 0)
48063+ goto out_fail;
48064+
48065 retval = search_binary_handler(bprm, regs);
48066 if (retval < 0)
48067- goto out;
48068+ goto out_fail;
48069+#ifdef CONFIG_GRKERNSEC
48070+ if (old_exec_file)
48071+ fput(old_exec_file);
48072+#endif
48073
48074 /* execve succeeded */
48075 current->fs->in_exec = 0;
48076@@ -1541,6 +1623,14 @@ int compat_do_execve(char * filename,
48077 put_files_struct(displaced);
48078 return retval;
48079
48080+out_fail:
48081+#ifdef CONFIG_GRKERNSEC
48082+ current->acl = old_acl;
48083+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
48084+ fput(current->exec_file);
48085+ current->exec_file = old_exec_file;
48086+#endif
48087+
48088 out:
48089 if (bprm->mm) {
48090 acct_arg_size(bprm, 0);
48091@@ -1711,6 +1801,8 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp,
48092 struct fdtable *fdt;
48093 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
48094
48095+ pax_track_stack();
48096+
48097 if (n < 0)
48098 goto out_nofds;
48099
48100@@ -2151,7 +2243,7 @@ asmlinkage long compat_sys_nfsservctl(int cmd,
48101 oldfs = get_fs();
48102 set_fs(KERNEL_DS);
48103 /* The __user pointer casts are valid because of the set_fs() */
48104- err = sys_nfsservctl(cmd, (void __user *) karg, (void __user *) kres);
48105+ err = sys_nfsservctl(cmd, (void __force_user *) karg, (void __force_user *) kres);
48106 set_fs(oldfs);
48107
48108 if (err)
48109diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
48110index 0adced2..bbb1b0d 100644
48111--- a/fs/compat_binfmt_elf.c
48112+++ b/fs/compat_binfmt_elf.c
48113@@ -29,10 +29,12 @@
48114 #undef elfhdr
48115 #undef elf_phdr
48116 #undef elf_note
48117+#undef elf_dyn
48118 #undef elf_addr_t
48119 #define elfhdr elf32_hdr
48120 #define elf_phdr elf32_phdr
48121 #define elf_note elf32_note
48122+#define elf_dyn Elf32_Dyn
48123 #define elf_addr_t Elf32_Addr
48124
48125 /*
48126diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
48127index d84e705..d8c364c 100644
48128--- a/fs/compat_ioctl.c
48129+++ b/fs/compat_ioctl.c
48130@@ -234,6 +234,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd, unsigned
48131 up = (struct compat_video_spu_palette __user *) arg;
48132 err = get_user(palp, &up->palette);
48133 err |= get_user(length, &up->length);
48134+ if (err)
48135+ return -EFAULT;
48136
48137 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
48138 err = put_user(compat_ptr(palp), &up_native->palette);
48139@@ -1513,7 +1515,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd, unsigned long arg)
48140 return -EFAULT;
48141 if (__get_user(udata, &ss32->iomem_base))
48142 return -EFAULT;
48143- ss.iomem_base = compat_ptr(udata);
48144+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
48145 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
48146 __get_user(ss.port_high, &ss32->port_high))
48147 return -EFAULT;
48148@@ -1809,7 +1811,7 @@ static int compat_ioctl_preallocate(struct file *file, unsigned long arg)
48149 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
48150 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
48151 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
48152- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
48153+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
48154 return -EFAULT;
48155
48156 return ioctl_preallocate(file, p);
48157diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
48158index 8e48b52..f01ed91 100644
48159--- a/fs/configfs/dir.c
48160+++ b/fs/configfs/dir.c
48161@@ -1572,7 +1572,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
48162 }
48163 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
48164 struct configfs_dirent *next;
48165- const char * name;
48166+ const unsigned char * name;
48167+ char d_name[sizeof(next->s_dentry->d_iname)];
48168 int len;
48169
48170 next = list_entry(p, struct configfs_dirent,
48171@@ -1581,7 +1582,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
48172 continue;
48173
48174 name = configfs_get_name(next);
48175- len = strlen(name);
48176+ if (next->s_dentry && name == next->s_dentry->d_iname) {
48177+ len = next->s_dentry->d_name.len;
48178+ memcpy(d_name, name, len);
48179+ name = d_name;
48180+ } else
48181+ len = strlen(name);
48182 if (next->s_dentry)
48183 ino = next->s_dentry->d_inode->i_ino;
48184 else
48185diff --git a/fs/dcache.c b/fs/dcache.c
48186index 44c0aea..2529092 100644
48187--- a/fs/dcache.c
48188+++ b/fs/dcache.c
48189@@ -45,8 +45,6 @@ EXPORT_SYMBOL(dcache_lock);
48190
48191 static struct kmem_cache *dentry_cache __read_mostly;
48192
48193-#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
48194-
48195 /*
48196 * This is the single most critical data structure when it comes
48197 * to the dcache: the hashtable for lookups. Somebody should try
48198@@ -2319,7 +2317,7 @@ void __init vfs_caches_init(unsigned long mempages)
48199 mempages -= reserve;
48200
48201 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
48202- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
48203+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
48204
48205 dcache_init();
48206 inode_init();
48207diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
48208index c010ecf..a8d8c59 100644
48209--- a/fs/dlm/lockspace.c
48210+++ b/fs/dlm/lockspace.c
48211@@ -148,7 +148,7 @@ static void lockspace_kobj_release(struct kobject *k)
48212 kfree(ls);
48213 }
48214
48215-static struct sysfs_ops dlm_attr_ops = {
48216+static const struct sysfs_ops dlm_attr_ops = {
48217 .show = dlm_attr_show,
48218 .store = dlm_attr_store,
48219 };
48220diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
48221index 88ba4d4..073f003 100644
48222--- a/fs/ecryptfs/inode.c
48223+++ b/fs/ecryptfs/inode.c
48224@@ -660,7 +660,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
48225 old_fs = get_fs();
48226 set_fs(get_ds());
48227 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
48228- (char __user *)lower_buf,
48229+ (char __force_user *)lower_buf,
48230 lower_bufsiz);
48231 set_fs(old_fs);
48232 if (rc < 0)
48233@@ -706,7 +706,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48234 }
48235 old_fs = get_fs();
48236 set_fs(get_ds());
48237- rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
48238+ rc = dentry->d_inode->i_op->readlink(dentry, (__force char __user *)buf, len);
48239 set_fs(old_fs);
48240 if (rc < 0)
48241 goto out_free;
48242diff --git a/fs/exec.c b/fs/exec.c
48243index 86fafc6..6d33cbb 100644
48244--- a/fs/exec.c
48245+++ b/fs/exec.c
48246@@ -56,12 +56,28 @@
48247 #include <linux/fsnotify.h>
48248 #include <linux/fs_struct.h>
48249 #include <linux/pipe_fs_i.h>
48250+#include <linux/random.h>
48251+#include <linux/seq_file.h>
48252+
48253+#ifdef CONFIG_PAX_REFCOUNT
48254+#include <linux/kallsyms.h>
48255+#include <linux/kdebug.h>
48256+#endif
48257
48258 #include <asm/uaccess.h>
48259 #include <asm/mmu_context.h>
48260 #include <asm/tlb.h>
48261 #include "internal.h"
48262
48263+#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
48264+void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
48265+#endif
48266+
48267+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
48268+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
48269+EXPORT_SYMBOL(pax_set_initial_flags_func);
48270+#endif
48271+
48272 int core_uses_pid;
48273 char core_pattern[CORENAME_MAX_SIZE] = "core";
48274 unsigned int core_pipe_limit;
48275@@ -178,18 +194,10 @@ struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
48276 int write)
48277 {
48278 struct page *page;
48279- int ret;
48280
48281-#ifdef CONFIG_STACK_GROWSUP
48282- if (write) {
48283- ret = expand_stack_downwards(bprm->vma, pos);
48284- if (ret < 0)
48285- return NULL;
48286- }
48287-#endif
48288- ret = get_user_pages(current, bprm->mm, pos,
48289- 1, write, 1, &page, NULL);
48290- if (ret <= 0)
48291+ if (0 > expand_stack_downwards(bprm->vma, pos))
48292+ return NULL;
48293+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
48294 return NULL;
48295
48296 if (write) {
48297@@ -263,6 +271,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
48298 vma->vm_end = STACK_TOP_MAX;
48299 vma->vm_start = vma->vm_end - PAGE_SIZE;
48300 vma->vm_flags = VM_STACK_FLAGS;
48301+
48302+#ifdef CONFIG_PAX_SEGMEXEC
48303+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
48304+#endif
48305+
48306 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
48307
48308 err = security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1);
48309@@ -276,6 +289,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
48310 mm->stack_vm = mm->total_vm = 1;
48311 up_write(&mm->mmap_sem);
48312 bprm->p = vma->vm_end - sizeof(void *);
48313+
48314+#ifdef CONFIG_PAX_RANDUSTACK
48315+ if (randomize_va_space)
48316+ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
48317+#endif
48318+
48319 return 0;
48320 err:
48321 up_write(&mm->mmap_sem);
48322@@ -510,7 +529,7 @@ int copy_strings_kernel(int argc,char ** argv, struct linux_binprm *bprm)
48323 int r;
48324 mm_segment_t oldfs = get_fs();
48325 set_fs(KERNEL_DS);
48326- r = copy_strings(argc, (char __user * __user *)argv, bprm);
48327+ r = copy_strings(argc, (__force char __user * __user *)argv, bprm);
48328 set_fs(oldfs);
48329 return r;
48330 }
48331@@ -540,7 +559,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
48332 unsigned long new_end = old_end - shift;
48333 struct mmu_gather *tlb;
48334
48335- BUG_ON(new_start > new_end);
48336+ if (new_start >= new_end || new_start < mmap_min_addr)
48337+ return -ENOMEM;
48338
48339 /*
48340 * ensure there are no vmas between where we want to go
48341@@ -549,6 +569,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
48342 if (vma != find_vma(mm, new_start))
48343 return -EFAULT;
48344
48345+#ifdef CONFIG_PAX_SEGMEXEC
48346+ BUG_ON(pax_find_mirror_vma(vma));
48347+#endif
48348+
48349 /*
48350 * cover the whole range: [new_start, old_end)
48351 */
48352@@ -630,10 +654,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
48353 stack_top = arch_align_stack(stack_top);
48354 stack_top = PAGE_ALIGN(stack_top);
48355
48356- if (unlikely(stack_top < mmap_min_addr) ||
48357- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
48358- return -ENOMEM;
48359-
48360 stack_shift = vma->vm_end - stack_top;
48361
48362 bprm->p -= stack_shift;
48363@@ -645,6 +665,14 @@ int setup_arg_pages(struct linux_binprm *bprm,
48364 bprm->exec -= stack_shift;
48365
48366 down_write(&mm->mmap_sem);
48367+
48368+ /* Move stack pages down in memory. */
48369+ if (stack_shift) {
48370+ ret = shift_arg_pages(vma, stack_shift);
48371+ if (ret)
48372+ goto out_unlock;
48373+ }
48374+
48375 vm_flags = VM_STACK_FLAGS;
48376
48377 /*
48378@@ -658,19 +686,24 @@ int setup_arg_pages(struct linux_binprm *bprm,
48379 vm_flags &= ~VM_EXEC;
48380 vm_flags |= mm->def_flags;
48381
48382+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48383+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48384+ vm_flags &= ~VM_EXEC;
48385+
48386+#ifdef CONFIG_PAX_MPROTECT
48387+ if (mm->pax_flags & MF_PAX_MPROTECT)
48388+ vm_flags &= ~VM_MAYEXEC;
48389+#endif
48390+
48391+ }
48392+#endif
48393+
48394 ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
48395 vm_flags);
48396 if (ret)
48397 goto out_unlock;
48398 BUG_ON(prev != vma);
48399
48400- /* Move stack pages down in memory. */
48401- if (stack_shift) {
48402- ret = shift_arg_pages(vma, stack_shift);
48403- if (ret)
48404- goto out_unlock;
48405- }
48406-
48407 stack_expand = EXTRA_STACK_VM_PAGES * PAGE_SIZE;
48408 stack_size = vma->vm_end - vma->vm_start;
48409 /*
48410@@ -744,7 +777,7 @@ int kernel_read(struct file *file, loff_t offset,
48411 old_fs = get_fs();
48412 set_fs(get_ds());
48413 /* The cast to a user pointer is valid due to the set_fs() */
48414- result = vfs_read(file, (void __user *)addr, count, &pos);
48415+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
48416 set_fs(old_fs);
48417 return result;
48418 }
48419@@ -1152,7 +1185,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
48420 }
48421 rcu_read_unlock();
48422
48423- if (p->fs->users > n_fs) {
48424+ if (atomic_read(&p->fs->users) > n_fs) {
48425 bprm->unsafe |= LSM_UNSAFE_SHARE;
48426 } else {
48427 res = -EAGAIN;
48428@@ -1347,11 +1380,35 @@ int do_execve(char * filename,
48429 char __user *__user *envp,
48430 struct pt_regs * regs)
48431 {
48432+#ifdef CONFIG_GRKERNSEC
48433+ struct file *old_exec_file;
48434+ struct acl_subject_label *old_acl;
48435+ struct rlimit old_rlim[RLIM_NLIMITS];
48436+#endif
48437 struct linux_binprm *bprm;
48438 struct file *file;
48439 struct files_struct *displaced;
48440 bool clear_in_exec;
48441 int retval;
48442+ const struct cred *cred = current_cred();
48443+
48444+ /*
48445+ * We move the actual failure in case of RLIMIT_NPROC excess from
48446+ * set*uid() to execve() because too many poorly written programs
48447+ * don't check setuid() return code. Here we additionally recheck
48448+ * whether NPROC limit is still exceeded.
48449+ */
48450+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
48451+
48452+ if ((current->flags & PF_NPROC_EXCEEDED) &&
48453+ atomic_read(&cred->user->processes) > current->signal->rlim[RLIMIT_NPROC].rlim_cur) {
48454+ retval = -EAGAIN;
48455+ goto out_ret;
48456+ }
48457+
48458+ /* We're below the limit (still or again), so we don't want to make
48459+ * further execve() calls fail. */
48460+ current->flags &= ~PF_NPROC_EXCEEDED;
48461
48462 retval = unshare_files(&displaced);
48463 if (retval)
48464@@ -1383,6 +1440,16 @@ int do_execve(char * filename,
48465 bprm->filename = filename;
48466 bprm->interp = filename;
48467
48468+ if (gr_process_user_ban()) {
48469+ retval = -EPERM;
48470+ goto out_file;
48471+ }
48472+
48473+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
48474+ retval = -EACCES;
48475+ goto out_file;
48476+ }
48477+
48478 retval = bprm_mm_init(bprm);
48479 if (retval)
48480 goto out_file;
48481@@ -1412,10 +1479,41 @@ int do_execve(char * filename,
48482 if (retval < 0)
48483 goto out;
48484
48485+ if (!gr_tpe_allow(file)) {
48486+ retval = -EACCES;
48487+ goto out;
48488+ }
48489+
48490+ if (gr_check_crash_exec(file)) {
48491+ retval = -EACCES;
48492+ goto out;
48493+ }
48494+
48495+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
48496+
48497+ gr_handle_exec_args(bprm, (const char __user *const __user *)argv);
48498+
48499+#ifdef CONFIG_GRKERNSEC
48500+ old_acl = current->acl;
48501+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
48502+ old_exec_file = current->exec_file;
48503+ get_file(file);
48504+ current->exec_file = file;
48505+#endif
48506+
48507+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
48508+ bprm->unsafe & LSM_UNSAFE_SHARE);
48509+ if (retval < 0)
48510+ goto out_fail;
48511+
48512 current->flags &= ~PF_KTHREAD;
48513 retval = search_binary_handler(bprm,regs);
48514 if (retval < 0)
48515- goto out;
48516+ goto out_fail;
48517+#ifdef CONFIG_GRKERNSEC
48518+ if (old_exec_file)
48519+ fput(old_exec_file);
48520+#endif
48521
48522 /* execve succeeded */
48523 current->fs->in_exec = 0;
48524@@ -1426,6 +1524,14 @@ int do_execve(char * filename,
48525 put_files_struct(displaced);
48526 return retval;
48527
48528+out_fail:
48529+#ifdef CONFIG_GRKERNSEC
48530+ current->acl = old_acl;
48531+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
48532+ fput(current->exec_file);
48533+ current->exec_file = old_exec_file;
48534+#endif
48535+
48536 out:
48537 if (bprm->mm) {
48538 acct_arg_size(bprm, 0);
48539@@ -1591,6 +1697,220 @@ out:
48540 return ispipe;
48541 }
48542
48543+int pax_check_flags(unsigned long *flags)
48544+{
48545+ int retval = 0;
48546+
48547+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
48548+ if (*flags & MF_PAX_SEGMEXEC)
48549+ {
48550+ *flags &= ~MF_PAX_SEGMEXEC;
48551+ retval = -EINVAL;
48552+ }
48553+#endif
48554+
48555+ if ((*flags & MF_PAX_PAGEEXEC)
48556+
48557+#ifdef CONFIG_PAX_PAGEEXEC
48558+ && (*flags & MF_PAX_SEGMEXEC)
48559+#endif
48560+
48561+ )
48562+ {
48563+ *flags &= ~MF_PAX_PAGEEXEC;
48564+ retval = -EINVAL;
48565+ }
48566+
48567+ if ((*flags & MF_PAX_MPROTECT)
48568+
48569+#ifdef CONFIG_PAX_MPROTECT
48570+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48571+#endif
48572+
48573+ )
48574+ {
48575+ *flags &= ~MF_PAX_MPROTECT;
48576+ retval = -EINVAL;
48577+ }
48578+
48579+ if ((*flags & MF_PAX_EMUTRAMP)
48580+
48581+#ifdef CONFIG_PAX_EMUTRAMP
48582+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
48583+#endif
48584+
48585+ )
48586+ {
48587+ *flags &= ~MF_PAX_EMUTRAMP;
48588+ retval = -EINVAL;
48589+ }
48590+
48591+ return retval;
48592+}
48593+
48594+EXPORT_SYMBOL(pax_check_flags);
48595+
48596+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
48597+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
48598+{
48599+ struct task_struct *tsk = current;
48600+ struct mm_struct *mm = current->mm;
48601+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
48602+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
48603+ char *path_exec = NULL;
48604+ char *path_fault = NULL;
48605+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
48606+
48607+ if (buffer_exec && buffer_fault) {
48608+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
48609+
48610+ down_read(&mm->mmap_sem);
48611+ vma = mm->mmap;
48612+ while (vma && (!vma_exec || !vma_fault)) {
48613+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
48614+ vma_exec = vma;
48615+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
48616+ vma_fault = vma;
48617+ vma = vma->vm_next;
48618+ }
48619+ if (vma_exec) {
48620+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
48621+ if (IS_ERR(path_exec))
48622+ path_exec = "<path too long>";
48623+ else {
48624+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
48625+ if (path_exec) {
48626+ *path_exec = 0;
48627+ path_exec = buffer_exec;
48628+ } else
48629+ path_exec = "<path too long>";
48630+ }
48631+ }
48632+ if (vma_fault) {
48633+ start = vma_fault->vm_start;
48634+ end = vma_fault->vm_end;
48635+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
48636+ if (vma_fault->vm_file) {
48637+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
48638+ if (IS_ERR(path_fault))
48639+ path_fault = "<path too long>";
48640+ else {
48641+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
48642+ if (path_fault) {
48643+ *path_fault = 0;
48644+ path_fault = buffer_fault;
48645+ } else
48646+ path_fault = "<path too long>";
48647+ }
48648+ } else
48649+ path_fault = "<anonymous mapping>";
48650+ }
48651+ up_read(&mm->mmap_sem);
48652+ }
48653+ if (tsk->signal->curr_ip)
48654+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
48655+ else
48656+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
48657+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
48658+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
48659+ task_uid(tsk), task_euid(tsk), pc, sp);
48660+ free_page((unsigned long)buffer_exec);
48661+ free_page((unsigned long)buffer_fault);
48662+ pax_report_insns(regs, pc, sp);
48663+ do_coredump(SIGKILL, SIGKILL, regs);
48664+}
48665+#endif
48666+
48667+#ifdef CONFIG_PAX_REFCOUNT
48668+void pax_report_refcount_overflow(struct pt_regs *regs)
48669+{
48670+ if (current->signal->curr_ip)
48671+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48672+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
48673+ else
48674+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48675+ current->comm, task_pid_nr(current), current_uid(), current_euid());
48676+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
48677+ show_regs(regs);
48678+ force_sig_specific(SIGKILL, current);
48679+}
48680+#endif
48681+
48682+#ifdef CONFIG_PAX_USERCOPY
48683+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
48684+int object_is_on_stack(const void *obj, unsigned long len)
48685+{
48686+ const void * const stack = task_stack_page(current);
48687+ const void * const stackend = stack + THREAD_SIZE;
48688+
48689+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48690+ const void *frame = NULL;
48691+ const void *oldframe;
48692+#endif
48693+
48694+ if (obj + len < obj)
48695+ return -1;
48696+
48697+ if (obj + len <= stack || stackend <= obj)
48698+ return 0;
48699+
48700+ if (obj < stack || stackend < obj + len)
48701+ return -1;
48702+
48703+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48704+ oldframe = __builtin_frame_address(1);
48705+ if (oldframe)
48706+ frame = __builtin_frame_address(2);
48707+ /*
48708+ low ----------------------------------------------> high
48709+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
48710+ ^----------------^
48711+ allow copies only within here
48712+ */
48713+ while (stack <= frame && frame < stackend) {
48714+ /* if obj + len extends past the last frame, this
48715+ check won't pass and the next frame will be 0,
48716+ causing us to bail out and correctly report
48717+ the copy as invalid
48718+ */
48719+ if (obj + len <= frame)
48720+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
48721+ oldframe = frame;
48722+ frame = *(const void * const *)frame;
48723+ }
48724+ return -1;
48725+#else
48726+ return 1;
48727+#endif
48728+}
48729+
48730+
48731+NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
48732+{
48733+ if (current->signal->curr_ip)
48734+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48735+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48736+ else
48737+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48738+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48739+
48740+ dump_stack();
48741+ gr_handle_kernel_exploit();
48742+ do_group_exit(SIGKILL);
48743+}
48744+#endif
48745+
48746+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
48747+void pax_track_stack(void)
48748+{
48749+ unsigned long sp = (unsigned long)&sp;
48750+ if (sp < current_thread_info()->lowest_stack &&
48751+ sp > (unsigned long)task_stack_page(current))
48752+ current_thread_info()->lowest_stack = sp;
48753+}
48754+EXPORT_SYMBOL(pax_track_stack);
48755+#endif
48756+
48757 static int zap_process(struct task_struct *start)
48758 {
48759 struct task_struct *t;
48760@@ -1793,17 +2113,17 @@ static void wait_for_dump_helpers(struct file *file)
48761 pipe = file->f_path.dentry->d_inode->i_pipe;
48762
48763 pipe_lock(pipe);
48764- pipe->readers++;
48765- pipe->writers--;
48766+ atomic_inc(&pipe->readers);
48767+ atomic_dec(&pipe->writers);
48768
48769- while ((pipe->readers > 1) && (!signal_pending(current))) {
48770+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
48771 wake_up_interruptible_sync(&pipe->wait);
48772 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48773 pipe_wait(pipe);
48774 }
48775
48776- pipe->readers--;
48777- pipe->writers++;
48778+ atomic_dec(&pipe->readers);
48779+ atomic_inc(&pipe->writers);
48780 pipe_unlock(pipe);
48781
48782 }
48783@@ -1826,10 +2146,13 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48784 char **helper_argv = NULL;
48785 int helper_argc = 0;
48786 int dump_count = 0;
48787- static atomic_t core_dump_count = ATOMIC_INIT(0);
48788+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
48789
48790 audit_core_dumps(signr);
48791
48792+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
48793+ gr_handle_brute_attach(current, mm->flags);
48794+
48795 binfmt = mm->binfmt;
48796 if (!binfmt || !binfmt->core_dump)
48797 goto fail;
48798@@ -1874,6 +2197,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48799 */
48800 clear_thread_flag(TIF_SIGPENDING);
48801
48802+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
48803+
48804 /*
48805 * lock_kernel() because format_corename() is controlled by sysctl, which
48806 * uses lock_kernel()
48807@@ -1908,7 +2233,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
48808 goto fail_unlock;
48809 }
48810
48811- dump_count = atomic_inc_return(&core_dump_count);
48812+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
48813 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
48814 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
48815 task_tgid_vnr(current), current->comm);
48816@@ -1972,7 +2297,7 @@ close_fail:
48817 filp_close(file, NULL);
48818 fail_dropcount:
48819 if (dump_count)
48820- atomic_dec(&core_dump_count);
48821+ atomic_dec_unchecked(&core_dump_count);
48822 fail_unlock:
48823 if (helper_argv)
48824 argv_free(helper_argv);
48825diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
48826index 7f8d2e5..a1abdbb 100644
48827--- a/fs/ext2/balloc.c
48828+++ b/fs/ext2/balloc.c
48829@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
48830
48831 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48832 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48833- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48834+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
48835 sbi->s_resuid != current_fsuid() &&
48836 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
48837 return 0;
48838diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
48839index 27967f9..9f2a5fb 100644
48840--- a/fs/ext3/balloc.c
48841+++ b/fs/ext3/balloc.c
48842@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
48843
48844 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48845 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48846- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48847+ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
48848 sbi->s_resuid != current_fsuid() &&
48849 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
48850 return 0;
48851diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
48852index e85b63c..80398e6 100644
48853--- a/fs/ext4/balloc.c
48854+++ b/fs/ext4/balloc.c
48855@@ -570,7 +570,7 @@ int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks)
48856 /* Hm, nope. Are (enough) root reserved blocks available? */
48857 if (sbi->s_resuid == current_fsuid() ||
48858 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
48859- capable(CAP_SYS_RESOURCE)) {
48860+ capable_nolog(CAP_SYS_RESOURCE)) {
48861 if (free_blocks >= (nblocks + dirty_blocks))
48862 return 1;
48863 }
48864diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
48865index 67c46ed..1f237e5 100644
48866--- a/fs/ext4/ext4.h
48867+++ b/fs/ext4/ext4.h
48868@@ -1077,19 +1077,19 @@ struct ext4_sb_info {
48869
48870 /* stats for buddy allocator */
48871 spinlock_t s_mb_pa_lock;
48872- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
48873- atomic_t s_bal_success; /* we found long enough chunks */
48874- atomic_t s_bal_allocated; /* in blocks */
48875- atomic_t s_bal_ex_scanned; /* total extents scanned */
48876- atomic_t s_bal_goals; /* goal hits */
48877- atomic_t s_bal_breaks; /* too long searches */
48878- atomic_t s_bal_2orders; /* 2^order hits */
48879+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
48880+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
48881+ atomic_unchecked_t s_bal_allocated; /* in blocks */
48882+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
48883+ atomic_unchecked_t s_bal_goals; /* goal hits */
48884+ atomic_unchecked_t s_bal_breaks; /* too long searches */
48885+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
48886 spinlock_t s_bal_lock;
48887 unsigned long s_mb_buddies_generated;
48888 unsigned long long s_mb_generation_time;
48889- atomic_t s_mb_lost_chunks;
48890- atomic_t s_mb_preallocated;
48891- atomic_t s_mb_discarded;
48892+ atomic_unchecked_t s_mb_lost_chunks;
48893+ atomic_unchecked_t s_mb_preallocated;
48894+ atomic_unchecked_t s_mb_discarded;
48895 atomic_t s_lock_busy;
48896
48897 /* locality groups */
48898diff --git a/fs/ext4/file.c b/fs/ext4/file.c
48899index 2a60541..7439d61 100644
48900--- a/fs/ext4/file.c
48901+++ b/fs/ext4/file.c
48902@@ -122,8 +122,8 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
48903 cp = d_path(&path, buf, sizeof(buf));
48904 path_put(&path);
48905 if (!IS_ERR(cp)) {
48906- memcpy(sbi->s_es->s_last_mounted, cp,
48907- sizeof(sbi->s_es->s_last_mounted));
48908+ strlcpy(sbi->s_es->s_last_mounted, cp,
48909+ sizeof(sbi->s_es->s_last_mounted));
48910 sb->s_dirt = 1;
48911 }
48912 }
48913diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
48914index 42bac1b..0aab9d8 100644
48915--- a/fs/ext4/mballoc.c
48916+++ b/fs/ext4/mballoc.c
48917@@ -1755,7 +1755,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
48918 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
48919
48920 if (EXT4_SB(sb)->s_mb_stats)
48921- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
48922+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
48923
48924 break;
48925 }
48926@@ -2131,7 +2131,7 @@ repeat:
48927 ac->ac_status = AC_STATUS_CONTINUE;
48928 ac->ac_flags |= EXT4_MB_HINT_FIRST;
48929 cr = 3;
48930- atomic_inc(&sbi->s_mb_lost_chunks);
48931+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
48932 goto repeat;
48933 }
48934 }
48935@@ -2174,6 +2174,8 @@ static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
48936 ext4_grpblk_t counters[16];
48937 } sg;
48938
48939+ pax_track_stack();
48940+
48941 group--;
48942 if (group == 0)
48943 seq_printf(seq, "#%-5s: %-5s %-5s %-5s "
48944@@ -2534,25 +2536,25 @@ int ext4_mb_release(struct super_block *sb)
48945 if (sbi->s_mb_stats) {
48946 printk(KERN_INFO
48947 "EXT4-fs: mballoc: %u blocks %u reqs (%u success)\n",
48948- atomic_read(&sbi->s_bal_allocated),
48949- atomic_read(&sbi->s_bal_reqs),
48950- atomic_read(&sbi->s_bal_success));
48951+ atomic_read_unchecked(&sbi->s_bal_allocated),
48952+ atomic_read_unchecked(&sbi->s_bal_reqs),
48953+ atomic_read_unchecked(&sbi->s_bal_success));
48954 printk(KERN_INFO
48955 "EXT4-fs: mballoc: %u extents scanned, %u goal hits, "
48956 "%u 2^N hits, %u breaks, %u lost\n",
48957- atomic_read(&sbi->s_bal_ex_scanned),
48958- atomic_read(&sbi->s_bal_goals),
48959- atomic_read(&sbi->s_bal_2orders),
48960- atomic_read(&sbi->s_bal_breaks),
48961- atomic_read(&sbi->s_mb_lost_chunks));
48962+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
48963+ atomic_read_unchecked(&sbi->s_bal_goals),
48964+ atomic_read_unchecked(&sbi->s_bal_2orders),
48965+ atomic_read_unchecked(&sbi->s_bal_breaks),
48966+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
48967 printk(KERN_INFO
48968 "EXT4-fs: mballoc: %lu generated and it took %Lu\n",
48969 sbi->s_mb_buddies_generated++,
48970 sbi->s_mb_generation_time);
48971 printk(KERN_INFO
48972 "EXT4-fs: mballoc: %u preallocated, %u discarded\n",
48973- atomic_read(&sbi->s_mb_preallocated),
48974- atomic_read(&sbi->s_mb_discarded));
48975+ atomic_read_unchecked(&sbi->s_mb_preallocated),
48976+ atomic_read_unchecked(&sbi->s_mb_discarded));
48977 }
48978
48979 free_percpu(sbi->s_locality_groups);
48980@@ -3034,16 +3036,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
48981 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
48982
48983 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
48984- atomic_inc(&sbi->s_bal_reqs);
48985- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48986+ atomic_inc_unchecked(&sbi->s_bal_reqs);
48987+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48988 if (ac->ac_o_ex.fe_len >= ac->ac_g_ex.fe_len)
48989- atomic_inc(&sbi->s_bal_success);
48990- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
48991+ atomic_inc_unchecked(&sbi->s_bal_success);
48992+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
48993 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
48994 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
48995- atomic_inc(&sbi->s_bal_goals);
48996+ atomic_inc_unchecked(&sbi->s_bal_goals);
48997 if (ac->ac_found > sbi->s_mb_max_to_scan)
48998- atomic_inc(&sbi->s_bal_breaks);
48999+ atomic_inc_unchecked(&sbi->s_bal_breaks);
49000 }
49001
49002 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
49003@@ -3443,7 +3445,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
49004 trace_ext4_mb_new_inode_pa(ac, pa);
49005
49006 ext4_mb_use_inode_pa(ac, pa);
49007- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
49008+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
49009
49010 ei = EXT4_I(ac->ac_inode);
49011 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
49012@@ -3503,7 +3505,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
49013 trace_ext4_mb_new_group_pa(ac, pa);
49014
49015 ext4_mb_use_group_pa(ac, pa);
49016- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
49017+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
49018
49019 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
49020 lg = ac->ac_lg;
49021@@ -3607,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
49022 * from the bitmap and continue.
49023 */
49024 }
49025- atomic_add(free, &sbi->s_mb_discarded);
49026+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
49027
49028 return err;
49029 }
49030@@ -3626,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
49031 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
49032 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
49033 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
49034- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
49035+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
49036
49037 if (ac) {
49038 ac->ac_sb = sb;
49039diff --git a/fs/ext4/super.c b/fs/ext4/super.c
49040index f27e045..be5a1c3 100644
49041--- a/fs/ext4/super.c
49042+++ b/fs/ext4/super.c
49043@@ -2287,7 +2287,7 @@ static void ext4_sb_release(struct kobject *kobj)
49044 }
49045
49046
49047-static struct sysfs_ops ext4_attr_ops = {
49048+static const struct sysfs_ops ext4_attr_ops = {
49049 .show = ext4_attr_show,
49050 .store = ext4_attr_store,
49051 };
49052diff --git a/fs/fcntl.c b/fs/fcntl.c
49053index 97e01dc..e9aab2d 100644
49054--- a/fs/fcntl.c
49055+++ b/fs/fcntl.c
49056@@ -223,6 +223,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
49057 if (err)
49058 return err;
49059
49060+ if (gr_handle_chroot_fowner(pid, type))
49061+ return -ENOENT;
49062+ if (gr_check_protected_task_fowner(pid, type))
49063+ return -EACCES;
49064+
49065 f_modown(filp, pid, type, force);
49066 return 0;
49067 }
49068@@ -265,7 +270,7 @@ pid_t f_getown(struct file *filp)
49069
49070 static int f_setown_ex(struct file *filp, unsigned long arg)
49071 {
49072- struct f_owner_ex * __user owner_p = (void * __user)arg;
49073+ struct f_owner_ex __user *owner_p = (void __user *)arg;
49074 struct f_owner_ex owner;
49075 struct pid *pid;
49076 int type;
49077@@ -305,7 +310,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
49078
49079 static int f_getown_ex(struct file *filp, unsigned long arg)
49080 {
49081- struct f_owner_ex * __user owner_p = (void * __user)arg;
49082+ struct f_owner_ex __user *owner_p = (void __user *)arg;
49083 struct f_owner_ex owner;
49084 int ret = 0;
49085
49086@@ -344,6 +349,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
49087 switch (cmd) {
49088 case F_DUPFD:
49089 case F_DUPFD_CLOEXEC:
49090+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
49091 if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
49092 break;
49093 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
49094diff --git a/fs/fifo.c b/fs/fifo.c
49095index f8f97b8..b1f2259 100644
49096--- a/fs/fifo.c
49097+++ b/fs/fifo.c
49098@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
49099 */
49100 filp->f_op = &read_pipefifo_fops;
49101 pipe->r_counter++;
49102- if (pipe->readers++ == 0)
49103+ if (atomic_inc_return(&pipe->readers) == 1)
49104 wake_up_partner(inode);
49105
49106- if (!pipe->writers) {
49107+ if (!atomic_read(&pipe->writers)) {
49108 if ((filp->f_flags & O_NONBLOCK)) {
49109 /* suppress POLLHUP until we have
49110 * seen a writer */
49111@@ -83,15 +83,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
49112 * errno=ENXIO when there is no process reading the FIFO.
49113 */
49114 ret = -ENXIO;
49115- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
49116+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
49117 goto err;
49118
49119 filp->f_op = &write_pipefifo_fops;
49120 pipe->w_counter++;
49121- if (!pipe->writers++)
49122+ if (atomic_inc_return(&pipe->writers) == 1)
49123 wake_up_partner(inode);
49124
49125- if (!pipe->readers) {
49126+ if (!atomic_read(&pipe->readers)) {
49127 wait_for_partner(inode, &pipe->r_counter);
49128 if (signal_pending(current))
49129 goto err_wr;
49130@@ -107,11 +107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
49131 */
49132 filp->f_op = &rdwr_pipefifo_fops;
49133
49134- pipe->readers++;
49135- pipe->writers++;
49136+ atomic_inc(&pipe->readers);
49137+ atomic_inc(&pipe->writers);
49138 pipe->r_counter++;
49139 pipe->w_counter++;
49140- if (pipe->readers == 1 || pipe->writers == 1)
49141+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
49142 wake_up_partner(inode);
49143 break;
49144
49145@@ -125,19 +125,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
49146 return 0;
49147
49148 err_rd:
49149- if (!--pipe->readers)
49150+ if (atomic_dec_and_test(&pipe->readers))
49151 wake_up_interruptible(&pipe->wait);
49152 ret = -ERESTARTSYS;
49153 goto err;
49154
49155 err_wr:
49156- if (!--pipe->writers)
49157+ if (atomic_dec_and_test(&pipe->writers))
49158 wake_up_interruptible(&pipe->wait);
49159 ret = -ERESTARTSYS;
49160 goto err;
49161
49162 err:
49163- if (!pipe->readers && !pipe->writers)
49164+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
49165 free_pipe_info(inode);
49166
49167 err_nocleanup:
49168diff --git a/fs/file.c b/fs/file.c
49169index 87e1290..a930cc4 100644
49170--- a/fs/file.c
49171+++ b/fs/file.c
49172@@ -14,6 +14,7 @@
49173 #include <linux/slab.h>
49174 #include <linux/vmalloc.h>
49175 #include <linux/file.h>
49176+#include <linux/security.h>
49177 #include <linux/fdtable.h>
49178 #include <linux/bitops.h>
49179 #include <linux/interrupt.h>
49180@@ -257,6 +258,8 @@ int expand_files(struct files_struct *files, int nr)
49181 * N.B. For clone tasks sharing a files structure, this test
49182 * will limit the total number of files that can be opened.
49183 */
49184+
49185+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
49186 if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
49187 return -EMFILE;
49188
49189diff --git a/fs/filesystems.c b/fs/filesystems.c
49190index a24c58e..53f91ee 100644
49191--- a/fs/filesystems.c
49192+++ b/fs/filesystems.c
49193@@ -272,7 +272,12 @@ struct file_system_type *get_fs_type(const char *name)
49194 int len = dot ? dot - name : strlen(name);
49195
49196 fs = __get_fs_type(name, len);
49197+
49198+#ifdef CONFIG_GRKERNSEC_MODHARDEN
49199+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
49200+#else
49201 if (!fs && (request_module("%.*s", len, name) == 0))
49202+#endif
49203 fs = __get_fs_type(name, len);
49204
49205 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
49206diff --git a/fs/fs_struct.c b/fs/fs_struct.c
49207index eee0590..ef5bc0e 100644
49208--- a/fs/fs_struct.c
49209+++ b/fs/fs_struct.c
49210@@ -4,6 +4,7 @@
49211 #include <linux/path.h>
49212 #include <linux/slab.h>
49213 #include <linux/fs_struct.h>
49214+#include <linux/grsecurity.h>
49215
49216 /*
49217 * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
49218@@ -17,6 +18,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
49219 old_root = fs->root;
49220 fs->root = *path;
49221 path_get(path);
49222+ gr_set_chroot_entries(current, path);
49223 write_unlock(&fs->lock);
49224 if (old_root.dentry)
49225 path_put(&old_root);
49226@@ -56,6 +58,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
49227 && fs->root.mnt == old_root->mnt) {
49228 path_get(new_root);
49229 fs->root = *new_root;
49230+ gr_set_chroot_entries(p, new_root);
49231 count++;
49232 }
49233 if (fs->pwd.dentry == old_root->dentry
49234@@ -89,7 +92,8 @@ void exit_fs(struct task_struct *tsk)
49235 task_lock(tsk);
49236 write_lock(&fs->lock);
49237 tsk->fs = NULL;
49238- kill = !--fs->users;
49239+ gr_clear_chroot_entries(tsk);
49240+ kill = !atomic_dec_return(&fs->users);
49241 write_unlock(&fs->lock);
49242 task_unlock(tsk);
49243 if (kill)
49244@@ -102,7 +106,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
49245 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
49246 /* We don't need to lock fs - think why ;-) */
49247 if (fs) {
49248- fs->users = 1;
49249+ atomic_set(&fs->users, 1);
49250 fs->in_exec = 0;
49251 rwlock_init(&fs->lock);
49252 fs->umask = old->umask;
49253@@ -127,8 +131,9 @@ int unshare_fs_struct(void)
49254
49255 task_lock(current);
49256 write_lock(&fs->lock);
49257- kill = !--fs->users;
49258+ kill = !atomic_dec_return(&fs->users);
49259 current->fs = new_fs;
49260+ gr_set_chroot_entries(current, &new_fs->root);
49261 write_unlock(&fs->lock);
49262 task_unlock(current);
49263
49264@@ -147,7 +152,7 @@ EXPORT_SYMBOL(current_umask);
49265
49266 /* to be mentioned only in INIT_TASK */
49267 struct fs_struct init_fs = {
49268- .users = 1,
49269+ .users = ATOMIC_INIT(1),
49270 .lock = __RW_LOCK_UNLOCKED(init_fs.lock),
49271 .umask = 0022,
49272 };
49273@@ -162,12 +167,13 @@ void daemonize_fs_struct(void)
49274 task_lock(current);
49275
49276 write_lock(&init_fs.lock);
49277- init_fs.users++;
49278+ atomic_inc(&init_fs.users);
49279 write_unlock(&init_fs.lock);
49280
49281 write_lock(&fs->lock);
49282 current->fs = &init_fs;
49283- kill = !--fs->users;
49284+ gr_set_chroot_entries(current, &current->fs->root);
49285+ kill = !atomic_dec_return(&fs->users);
49286 write_unlock(&fs->lock);
49287
49288 task_unlock(current);
49289diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
49290index 9905350..02eaec4 100644
49291--- a/fs/fscache/cookie.c
49292+++ b/fs/fscache/cookie.c
49293@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
49294 parent ? (char *) parent->def->name : "<no-parent>",
49295 def->name, netfs_data);
49296
49297- fscache_stat(&fscache_n_acquires);
49298+ fscache_stat_unchecked(&fscache_n_acquires);
49299
49300 /* if there's no parent cookie, then we don't create one here either */
49301 if (!parent) {
49302- fscache_stat(&fscache_n_acquires_null);
49303+ fscache_stat_unchecked(&fscache_n_acquires_null);
49304 _leave(" [no parent]");
49305 return NULL;
49306 }
49307@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
49308 /* allocate and initialise a cookie */
49309 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
49310 if (!cookie) {
49311- fscache_stat(&fscache_n_acquires_oom);
49312+ fscache_stat_unchecked(&fscache_n_acquires_oom);
49313 _leave(" [ENOMEM]");
49314 return NULL;
49315 }
49316@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
49317
49318 switch (cookie->def->type) {
49319 case FSCACHE_COOKIE_TYPE_INDEX:
49320- fscache_stat(&fscache_n_cookie_index);
49321+ fscache_stat_unchecked(&fscache_n_cookie_index);
49322 break;
49323 case FSCACHE_COOKIE_TYPE_DATAFILE:
49324- fscache_stat(&fscache_n_cookie_data);
49325+ fscache_stat_unchecked(&fscache_n_cookie_data);
49326 break;
49327 default:
49328- fscache_stat(&fscache_n_cookie_special);
49329+ fscache_stat_unchecked(&fscache_n_cookie_special);
49330 break;
49331 }
49332
49333@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
49334 if (fscache_acquire_non_index_cookie(cookie) < 0) {
49335 atomic_dec(&parent->n_children);
49336 __fscache_cookie_put(cookie);
49337- fscache_stat(&fscache_n_acquires_nobufs);
49338+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
49339 _leave(" = NULL");
49340 return NULL;
49341 }
49342 }
49343
49344- fscache_stat(&fscache_n_acquires_ok);
49345+ fscache_stat_unchecked(&fscache_n_acquires_ok);
49346 _leave(" = %p", cookie);
49347 return cookie;
49348 }
49349@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
49350 cache = fscache_select_cache_for_object(cookie->parent);
49351 if (!cache) {
49352 up_read(&fscache_addremove_sem);
49353- fscache_stat(&fscache_n_acquires_no_cache);
49354+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
49355 _leave(" = -ENOMEDIUM [no cache]");
49356 return -ENOMEDIUM;
49357 }
49358@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
49359 object = cache->ops->alloc_object(cache, cookie);
49360 fscache_stat_d(&fscache_n_cop_alloc_object);
49361 if (IS_ERR(object)) {
49362- fscache_stat(&fscache_n_object_no_alloc);
49363+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
49364 ret = PTR_ERR(object);
49365 goto error;
49366 }
49367
49368- fscache_stat(&fscache_n_object_alloc);
49369+ fscache_stat_unchecked(&fscache_n_object_alloc);
49370
49371 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
49372
49373@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
49374 struct fscache_object *object;
49375 struct hlist_node *_p;
49376
49377- fscache_stat(&fscache_n_updates);
49378+ fscache_stat_unchecked(&fscache_n_updates);
49379
49380 if (!cookie) {
49381- fscache_stat(&fscache_n_updates_null);
49382+ fscache_stat_unchecked(&fscache_n_updates_null);
49383 _leave(" [no cookie]");
49384 return;
49385 }
49386@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
49387 struct fscache_object *object;
49388 unsigned long event;
49389
49390- fscache_stat(&fscache_n_relinquishes);
49391+ fscache_stat_unchecked(&fscache_n_relinquishes);
49392 if (retire)
49393- fscache_stat(&fscache_n_relinquishes_retire);
49394+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
49395
49396 if (!cookie) {
49397- fscache_stat(&fscache_n_relinquishes_null);
49398+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
49399 _leave(" [no cookie]");
49400 return;
49401 }
49402@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
49403
49404 /* wait for the cookie to finish being instantiated (or to fail) */
49405 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
49406- fscache_stat(&fscache_n_relinquishes_waitcrt);
49407+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
49408 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
49409 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
49410 }
49411diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
49412index edd7434..0725e66 100644
49413--- a/fs/fscache/internal.h
49414+++ b/fs/fscache/internal.h
49415@@ -136,94 +136,94 @@ extern void fscache_proc_cleanup(void);
49416 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
49417 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
49418
49419-extern atomic_t fscache_n_op_pend;
49420-extern atomic_t fscache_n_op_run;
49421-extern atomic_t fscache_n_op_enqueue;
49422-extern atomic_t fscache_n_op_deferred_release;
49423-extern atomic_t fscache_n_op_release;
49424-extern atomic_t fscache_n_op_gc;
49425-extern atomic_t fscache_n_op_cancelled;
49426-extern atomic_t fscache_n_op_rejected;
49427+extern atomic_unchecked_t fscache_n_op_pend;
49428+extern atomic_unchecked_t fscache_n_op_run;
49429+extern atomic_unchecked_t fscache_n_op_enqueue;
49430+extern atomic_unchecked_t fscache_n_op_deferred_release;
49431+extern atomic_unchecked_t fscache_n_op_release;
49432+extern atomic_unchecked_t fscache_n_op_gc;
49433+extern atomic_unchecked_t fscache_n_op_cancelled;
49434+extern atomic_unchecked_t fscache_n_op_rejected;
49435
49436-extern atomic_t fscache_n_attr_changed;
49437-extern atomic_t fscache_n_attr_changed_ok;
49438-extern atomic_t fscache_n_attr_changed_nobufs;
49439-extern atomic_t fscache_n_attr_changed_nomem;
49440-extern atomic_t fscache_n_attr_changed_calls;
49441+extern atomic_unchecked_t fscache_n_attr_changed;
49442+extern atomic_unchecked_t fscache_n_attr_changed_ok;
49443+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
49444+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
49445+extern atomic_unchecked_t fscache_n_attr_changed_calls;
49446
49447-extern atomic_t fscache_n_allocs;
49448-extern atomic_t fscache_n_allocs_ok;
49449-extern atomic_t fscache_n_allocs_wait;
49450-extern atomic_t fscache_n_allocs_nobufs;
49451-extern atomic_t fscache_n_allocs_intr;
49452-extern atomic_t fscache_n_allocs_object_dead;
49453-extern atomic_t fscache_n_alloc_ops;
49454-extern atomic_t fscache_n_alloc_op_waits;
49455+extern atomic_unchecked_t fscache_n_allocs;
49456+extern atomic_unchecked_t fscache_n_allocs_ok;
49457+extern atomic_unchecked_t fscache_n_allocs_wait;
49458+extern atomic_unchecked_t fscache_n_allocs_nobufs;
49459+extern atomic_unchecked_t fscache_n_allocs_intr;
49460+extern atomic_unchecked_t fscache_n_allocs_object_dead;
49461+extern atomic_unchecked_t fscache_n_alloc_ops;
49462+extern atomic_unchecked_t fscache_n_alloc_op_waits;
49463
49464-extern atomic_t fscache_n_retrievals;
49465-extern atomic_t fscache_n_retrievals_ok;
49466-extern atomic_t fscache_n_retrievals_wait;
49467-extern atomic_t fscache_n_retrievals_nodata;
49468-extern atomic_t fscache_n_retrievals_nobufs;
49469-extern atomic_t fscache_n_retrievals_intr;
49470-extern atomic_t fscache_n_retrievals_nomem;
49471-extern atomic_t fscache_n_retrievals_object_dead;
49472-extern atomic_t fscache_n_retrieval_ops;
49473-extern atomic_t fscache_n_retrieval_op_waits;
49474+extern atomic_unchecked_t fscache_n_retrievals;
49475+extern atomic_unchecked_t fscache_n_retrievals_ok;
49476+extern atomic_unchecked_t fscache_n_retrievals_wait;
49477+extern atomic_unchecked_t fscache_n_retrievals_nodata;
49478+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
49479+extern atomic_unchecked_t fscache_n_retrievals_intr;
49480+extern atomic_unchecked_t fscache_n_retrievals_nomem;
49481+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
49482+extern atomic_unchecked_t fscache_n_retrieval_ops;
49483+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
49484
49485-extern atomic_t fscache_n_stores;
49486-extern atomic_t fscache_n_stores_ok;
49487-extern atomic_t fscache_n_stores_again;
49488-extern atomic_t fscache_n_stores_nobufs;
49489-extern atomic_t fscache_n_stores_oom;
49490-extern atomic_t fscache_n_store_ops;
49491-extern atomic_t fscache_n_store_calls;
49492-extern atomic_t fscache_n_store_pages;
49493-extern atomic_t fscache_n_store_radix_deletes;
49494-extern atomic_t fscache_n_store_pages_over_limit;
49495+extern atomic_unchecked_t fscache_n_stores;
49496+extern atomic_unchecked_t fscache_n_stores_ok;
49497+extern atomic_unchecked_t fscache_n_stores_again;
49498+extern atomic_unchecked_t fscache_n_stores_nobufs;
49499+extern atomic_unchecked_t fscache_n_stores_oom;
49500+extern atomic_unchecked_t fscache_n_store_ops;
49501+extern atomic_unchecked_t fscache_n_store_calls;
49502+extern atomic_unchecked_t fscache_n_store_pages;
49503+extern atomic_unchecked_t fscache_n_store_radix_deletes;
49504+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
49505
49506-extern atomic_t fscache_n_store_vmscan_not_storing;
49507-extern atomic_t fscache_n_store_vmscan_gone;
49508-extern atomic_t fscache_n_store_vmscan_busy;
49509-extern atomic_t fscache_n_store_vmscan_cancelled;
49510+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49511+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
49512+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
49513+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49514
49515-extern atomic_t fscache_n_marks;
49516-extern atomic_t fscache_n_uncaches;
49517+extern atomic_unchecked_t fscache_n_marks;
49518+extern atomic_unchecked_t fscache_n_uncaches;
49519
49520-extern atomic_t fscache_n_acquires;
49521-extern atomic_t fscache_n_acquires_null;
49522-extern atomic_t fscache_n_acquires_no_cache;
49523-extern atomic_t fscache_n_acquires_ok;
49524-extern atomic_t fscache_n_acquires_nobufs;
49525-extern atomic_t fscache_n_acquires_oom;
49526+extern atomic_unchecked_t fscache_n_acquires;
49527+extern atomic_unchecked_t fscache_n_acquires_null;
49528+extern atomic_unchecked_t fscache_n_acquires_no_cache;
49529+extern atomic_unchecked_t fscache_n_acquires_ok;
49530+extern atomic_unchecked_t fscache_n_acquires_nobufs;
49531+extern atomic_unchecked_t fscache_n_acquires_oom;
49532
49533-extern atomic_t fscache_n_updates;
49534-extern atomic_t fscache_n_updates_null;
49535-extern atomic_t fscache_n_updates_run;
49536+extern atomic_unchecked_t fscache_n_updates;
49537+extern atomic_unchecked_t fscache_n_updates_null;
49538+extern atomic_unchecked_t fscache_n_updates_run;
49539
49540-extern atomic_t fscache_n_relinquishes;
49541-extern atomic_t fscache_n_relinquishes_null;
49542-extern atomic_t fscache_n_relinquishes_waitcrt;
49543-extern atomic_t fscache_n_relinquishes_retire;
49544+extern atomic_unchecked_t fscache_n_relinquishes;
49545+extern atomic_unchecked_t fscache_n_relinquishes_null;
49546+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49547+extern atomic_unchecked_t fscache_n_relinquishes_retire;
49548
49549-extern atomic_t fscache_n_cookie_index;
49550-extern atomic_t fscache_n_cookie_data;
49551-extern atomic_t fscache_n_cookie_special;
49552+extern atomic_unchecked_t fscache_n_cookie_index;
49553+extern atomic_unchecked_t fscache_n_cookie_data;
49554+extern atomic_unchecked_t fscache_n_cookie_special;
49555
49556-extern atomic_t fscache_n_object_alloc;
49557-extern atomic_t fscache_n_object_no_alloc;
49558-extern atomic_t fscache_n_object_lookups;
49559-extern atomic_t fscache_n_object_lookups_negative;
49560-extern atomic_t fscache_n_object_lookups_positive;
49561-extern atomic_t fscache_n_object_lookups_timed_out;
49562-extern atomic_t fscache_n_object_created;
49563-extern atomic_t fscache_n_object_avail;
49564-extern atomic_t fscache_n_object_dead;
49565+extern atomic_unchecked_t fscache_n_object_alloc;
49566+extern atomic_unchecked_t fscache_n_object_no_alloc;
49567+extern atomic_unchecked_t fscache_n_object_lookups;
49568+extern atomic_unchecked_t fscache_n_object_lookups_negative;
49569+extern atomic_unchecked_t fscache_n_object_lookups_positive;
49570+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
49571+extern atomic_unchecked_t fscache_n_object_created;
49572+extern atomic_unchecked_t fscache_n_object_avail;
49573+extern atomic_unchecked_t fscache_n_object_dead;
49574
49575-extern atomic_t fscache_n_checkaux_none;
49576-extern atomic_t fscache_n_checkaux_okay;
49577-extern atomic_t fscache_n_checkaux_update;
49578-extern atomic_t fscache_n_checkaux_obsolete;
49579+extern atomic_unchecked_t fscache_n_checkaux_none;
49580+extern atomic_unchecked_t fscache_n_checkaux_okay;
49581+extern atomic_unchecked_t fscache_n_checkaux_update;
49582+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
49583
49584 extern atomic_t fscache_n_cop_alloc_object;
49585 extern atomic_t fscache_n_cop_lookup_object;
49586@@ -247,6 +247,11 @@ static inline void fscache_stat(atomic_t *stat)
49587 atomic_inc(stat);
49588 }
49589
49590+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
49591+{
49592+ atomic_inc_unchecked(stat);
49593+}
49594+
49595 static inline void fscache_stat_d(atomic_t *stat)
49596 {
49597 atomic_dec(stat);
49598@@ -259,6 +264,7 @@ extern const struct file_operations fscache_stats_fops;
49599
49600 #define __fscache_stat(stat) (NULL)
49601 #define fscache_stat(stat) do {} while (0)
49602+#define fscache_stat_unchecked(stat) do {} while (0)
49603 #define fscache_stat_d(stat) do {} while (0)
49604 #endif
49605
49606diff --git a/fs/fscache/object.c b/fs/fscache/object.c
49607index e513ac5..e888d34 100644
49608--- a/fs/fscache/object.c
49609+++ b/fs/fscache/object.c
49610@@ -144,7 +144,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49611 /* update the object metadata on disk */
49612 case FSCACHE_OBJECT_UPDATING:
49613 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
49614- fscache_stat(&fscache_n_updates_run);
49615+ fscache_stat_unchecked(&fscache_n_updates_run);
49616 fscache_stat(&fscache_n_cop_update_object);
49617 object->cache->ops->update_object(object);
49618 fscache_stat_d(&fscache_n_cop_update_object);
49619@@ -233,7 +233,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49620 spin_lock(&object->lock);
49621 object->state = FSCACHE_OBJECT_DEAD;
49622 spin_unlock(&object->lock);
49623- fscache_stat(&fscache_n_object_dead);
49624+ fscache_stat_unchecked(&fscache_n_object_dead);
49625 goto terminal_transit;
49626
49627 /* handle the parent cache of this object being withdrawn from
49628@@ -248,7 +248,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
49629 spin_lock(&object->lock);
49630 object->state = FSCACHE_OBJECT_DEAD;
49631 spin_unlock(&object->lock);
49632- fscache_stat(&fscache_n_object_dead);
49633+ fscache_stat_unchecked(&fscache_n_object_dead);
49634 goto terminal_transit;
49635
49636 /* complain about the object being woken up once it is
49637@@ -492,7 +492,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49638 parent->cookie->def->name, cookie->def->name,
49639 object->cache->tag->name);
49640
49641- fscache_stat(&fscache_n_object_lookups);
49642+ fscache_stat_unchecked(&fscache_n_object_lookups);
49643 fscache_stat(&fscache_n_cop_lookup_object);
49644 ret = object->cache->ops->lookup_object(object);
49645 fscache_stat_d(&fscache_n_cop_lookup_object);
49646@@ -503,7 +503,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49647 if (ret == -ETIMEDOUT) {
49648 /* probably stuck behind another object, so move this one to
49649 * the back of the queue */
49650- fscache_stat(&fscache_n_object_lookups_timed_out);
49651+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
49652 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49653 }
49654
49655@@ -526,7 +526,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
49656
49657 spin_lock(&object->lock);
49658 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49659- fscache_stat(&fscache_n_object_lookups_negative);
49660+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
49661
49662 /* transit here to allow write requests to begin stacking up
49663 * and read requests to begin returning ENODATA */
49664@@ -572,7 +572,7 @@ void fscache_obtained_object(struct fscache_object *object)
49665 * result, in which case there may be data available */
49666 spin_lock(&object->lock);
49667 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49668- fscache_stat(&fscache_n_object_lookups_positive);
49669+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
49670
49671 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
49672
49673@@ -586,7 +586,7 @@ void fscache_obtained_object(struct fscache_object *object)
49674 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49675 } else {
49676 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
49677- fscache_stat(&fscache_n_object_created);
49678+ fscache_stat_unchecked(&fscache_n_object_created);
49679
49680 object->state = FSCACHE_OBJECT_AVAILABLE;
49681 spin_unlock(&object->lock);
49682@@ -633,7 +633,7 @@ static void fscache_object_available(struct fscache_object *object)
49683 fscache_enqueue_dependents(object);
49684
49685 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
49686- fscache_stat(&fscache_n_object_avail);
49687+ fscache_stat_unchecked(&fscache_n_object_avail);
49688
49689 _leave("");
49690 }
49691@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49692 enum fscache_checkaux result;
49693
49694 if (!object->cookie->def->check_aux) {
49695- fscache_stat(&fscache_n_checkaux_none);
49696+ fscache_stat_unchecked(&fscache_n_checkaux_none);
49697 return FSCACHE_CHECKAUX_OKAY;
49698 }
49699
49700@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49701 switch (result) {
49702 /* entry okay as is */
49703 case FSCACHE_CHECKAUX_OKAY:
49704- fscache_stat(&fscache_n_checkaux_okay);
49705+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
49706 break;
49707
49708 /* entry requires update */
49709 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
49710- fscache_stat(&fscache_n_checkaux_update);
49711+ fscache_stat_unchecked(&fscache_n_checkaux_update);
49712 break;
49713
49714 /* entry requires deletion */
49715 case FSCACHE_CHECKAUX_OBSOLETE:
49716- fscache_stat(&fscache_n_checkaux_obsolete);
49717+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
49718 break;
49719
49720 default:
49721diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
49722index 313e79a..775240f 100644
49723--- a/fs/fscache/operation.c
49724+++ b/fs/fscache/operation.c
49725@@ -16,7 +16,7 @@
49726 #include <linux/seq_file.h>
49727 #include "internal.h"
49728
49729-atomic_t fscache_op_debug_id;
49730+atomic_unchecked_t fscache_op_debug_id;
49731 EXPORT_SYMBOL(fscache_op_debug_id);
49732
49733 /**
49734@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
49735 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
49736 ASSERTCMP(atomic_read(&op->usage), >, 0);
49737
49738- fscache_stat(&fscache_n_op_enqueue);
49739+ fscache_stat_unchecked(&fscache_n_op_enqueue);
49740 switch (op->flags & FSCACHE_OP_TYPE) {
49741 case FSCACHE_OP_FAST:
49742 _debug("queue fast");
49743@@ -76,7 +76,7 @@ static void fscache_run_op(struct fscache_object *object,
49744 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
49745 if (op->processor)
49746 fscache_enqueue_operation(op);
49747- fscache_stat(&fscache_n_op_run);
49748+ fscache_stat_unchecked(&fscache_n_op_run);
49749 }
49750
49751 /*
49752@@ -107,11 +107,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49753 if (object->n_ops > 0) {
49754 atomic_inc(&op->usage);
49755 list_add_tail(&op->pend_link, &object->pending_ops);
49756- fscache_stat(&fscache_n_op_pend);
49757+ fscache_stat_unchecked(&fscache_n_op_pend);
49758 } else if (!list_empty(&object->pending_ops)) {
49759 atomic_inc(&op->usage);
49760 list_add_tail(&op->pend_link, &object->pending_ops);
49761- fscache_stat(&fscache_n_op_pend);
49762+ fscache_stat_unchecked(&fscache_n_op_pend);
49763 fscache_start_operations(object);
49764 } else {
49765 ASSERTCMP(object->n_in_progress, ==, 0);
49766@@ -127,7 +127,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49767 object->n_exclusive++; /* reads and writes must wait */
49768 atomic_inc(&op->usage);
49769 list_add_tail(&op->pend_link, &object->pending_ops);
49770- fscache_stat(&fscache_n_op_pend);
49771+ fscache_stat_unchecked(&fscache_n_op_pend);
49772 ret = 0;
49773 } else {
49774 /* not allowed to submit ops in any other state */
49775@@ -214,11 +214,11 @@ int fscache_submit_op(struct fscache_object *object,
49776 if (object->n_exclusive > 0) {
49777 atomic_inc(&op->usage);
49778 list_add_tail(&op->pend_link, &object->pending_ops);
49779- fscache_stat(&fscache_n_op_pend);
49780+ fscache_stat_unchecked(&fscache_n_op_pend);
49781 } else if (!list_empty(&object->pending_ops)) {
49782 atomic_inc(&op->usage);
49783 list_add_tail(&op->pend_link, &object->pending_ops);
49784- fscache_stat(&fscache_n_op_pend);
49785+ fscache_stat_unchecked(&fscache_n_op_pend);
49786 fscache_start_operations(object);
49787 } else {
49788 ASSERTCMP(object->n_exclusive, ==, 0);
49789@@ -230,12 +230,12 @@ int fscache_submit_op(struct fscache_object *object,
49790 object->n_ops++;
49791 atomic_inc(&op->usage);
49792 list_add_tail(&op->pend_link, &object->pending_ops);
49793- fscache_stat(&fscache_n_op_pend);
49794+ fscache_stat_unchecked(&fscache_n_op_pend);
49795 ret = 0;
49796 } else if (object->state == FSCACHE_OBJECT_DYING ||
49797 object->state == FSCACHE_OBJECT_LC_DYING ||
49798 object->state == FSCACHE_OBJECT_WITHDRAWING) {
49799- fscache_stat(&fscache_n_op_rejected);
49800+ fscache_stat_unchecked(&fscache_n_op_rejected);
49801 ret = -ENOBUFS;
49802 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
49803 fscache_report_unexpected_submission(object, op, ostate);
49804@@ -305,7 +305,7 @@ int fscache_cancel_op(struct fscache_operation *op)
49805
49806 ret = -EBUSY;
49807 if (!list_empty(&op->pend_link)) {
49808- fscache_stat(&fscache_n_op_cancelled);
49809+ fscache_stat_unchecked(&fscache_n_op_cancelled);
49810 list_del_init(&op->pend_link);
49811 object->n_ops--;
49812 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
49813@@ -344,7 +344,7 @@ void fscache_put_operation(struct fscache_operation *op)
49814 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
49815 BUG();
49816
49817- fscache_stat(&fscache_n_op_release);
49818+ fscache_stat_unchecked(&fscache_n_op_release);
49819
49820 if (op->release) {
49821 op->release(op);
49822@@ -361,7 +361,7 @@ void fscache_put_operation(struct fscache_operation *op)
49823 * lock, and defer it otherwise */
49824 if (!spin_trylock(&object->lock)) {
49825 _debug("defer put");
49826- fscache_stat(&fscache_n_op_deferred_release);
49827+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
49828
49829 cache = object->cache;
49830 spin_lock(&cache->op_gc_list_lock);
49831@@ -423,7 +423,7 @@ void fscache_operation_gc(struct work_struct *work)
49832
49833 _debug("GC DEFERRED REL OBJ%x OP%x",
49834 object->debug_id, op->debug_id);
49835- fscache_stat(&fscache_n_op_gc);
49836+ fscache_stat_unchecked(&fscache_n_op_gc);
49837
49838 ASSERTCMP(atomic_read(&op->usage), ==, 0);
49839
49840diff --git a/fs/fscache/page.c b/fs/fscache/page.c
49841index c598ea4..6aac13e 100644
49842--- a/fs/fscache/page.c
49843+++ b/fs/fscache/page.c
49844@@ -59,7 +59,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
49845 val = radix_tree_lookup(&cookie->stores, page->index);
49846 if (!val) {
49847 rcu_read_unlock();
49848- fscache_stat(&fscache_n_store_vmscan_not_storing);
49849+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
49850 __fscache_uncache_page(cookie, page);
49851 return true;
49852 }
49853@@ -89,11 +89,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
49854 spin_unlock(&cookie->stores_lock);
49855
49856 if (xpage) {
49857- fscache_stat(&fscache_n_store_vmscan_cancelled);
49858- fscache_stat(&fscache_n_store_radix_deletes);
49859+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
49860+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49861 ASSERTCMP(xpage, ==, page);
49862 } else {
49863- fscache_stat(&fscache_n_store_vmscan_gone);
49864+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
49865 }
49866
49867 wake_up_bit(&cookie->flags, 0);
49868@@ -106,7 +106,7 @@ page_busy:
49869 /* we might want to wait here, but that could deadlock the allocator as
49870 * the slow-work threads writing to the cache may all end up sleeping
49871 * on memory allocation */
49872- fscache_stat(&fscache_n_store_vmscan_busy);
49873+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
49874 return false;
49875 }
49876 EXPORT_SYMBOL(__fscache_maybe_release_page);
49877@@ -130,7 +130,7 @@ static void fscache_end_page_write(struct fscache_object *object,
49878 FSCACHE_COOKIE_STORING_TAG);
49879 if (!radix_tree_tag_get(&cookie->stores, page->index,
49880 FSCACHE_COOKIE_PENDING_TAG)) {
49881- fscache_stat(&fscache_n_store_radix_deletes);
49882+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49883 xpage = radix_tree_delete(&cookie->stores, page->index);
49884 }
49885 spin_unlock(&cookie->stores_lock);
49886@@ -151,7 +151,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
49887
49888 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
49889
49890- fscache_stat(&fscache_n_attr_changed_calls);
49891+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
49892
49893 if (fscache_object_is_active(object)) {
49894 fscache_set_op_state(op, "CallFS");
49895@@ -178,11 +178,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49896
49897 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49898
49899- fscache_stat(&fscache_n_attr_changed);
49900+ fscache_stat_unchecked(&fscache_n_attr_changed);
49901
49902 op = kzalloc(sizeof(*op), GFP_KERNEL);
49903 if (!op) {
49904- fscache_stat(&fscache_n_attr_changed_nomem);
49905+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
49906 _leave(" = -ENOMEM");
49907 return -ENOMEM;
49908 }
49909@@ -202,7 +202,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49910 if (fscache_submit_exclusive_op(object, op) < 0)
49911 goto nobufs;
49912 spin_unlock(&cookie->lock);
49913- fscache_stat(&fscache_n_attr_changed_ok);
49914+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
49915 fscache_put_operation(op);
49916 _leave(" = 0");
49917 return 0;
49918@@ -210,7 +210,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49919 nobufs:
49920 spin_unlock(&cookie->lock);
49921 kfree(op);
49922- fscache_stat(&fscache_n_attr_changed_nobufs);
49923+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
49924 _leave(" = %d", -ENOBUFS);
49925 return -ENOBUFS;
49926 }
49927@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
49928 /* allocate a retrieval operation and attempt to submit it */
49929 op = kzalloc(sizeof(*op), GFP_NOIO);
49930 if (!op) {
49931- fscache_stat(&fscache_n_retrievals_nomem);
49932+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49933 return NULL;
49934 }
49935
49936@@ -294,13 +294,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49937 return 0;
49938 }
49939
49940- fscache_stat(&fscache_n_retrievals_wait);
49941+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
49942
49943 jif = jiffies;
49944 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
49945 fscache_wait_bit_interruptible,
49946 TASK_INTERRUPTIBLE) != 0) {
49947- fscache_stat(&fscache_n_retrievals_intr);
49948+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
49949 _leave(" = -ERESTARTSYS");
49950 return -ERESTARTSYS;
49951 }
49952@@ -318,8 +318,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49953 */
49954 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49955 struct fscache_retrieval *op,
49956- atomic_t *stat_op_waits,
49957- atomic_t *stat_object_dead)
49958+ atomic_unchecked_t *stat_op_waits,
49959+ atomic_unchecked_t *stat_object_dead)
49960 {
49961 int ret;
49962
49963@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49964 goto check_if_dead;
49965
49966 _debug(">>> WT");
49967- fscache_stat(stat_op_waits);
49968+ fscache_stat_unchecked(stat_op_waits);
49969 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
49970 fscache_wait_bit_interruptible,
49971 TASK_INTERRUPTIBLE) < 0) {
49972@@ -344,7 +344,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49973
49974 check_if_dead:
49975 if (unlikely(fscache_object_is_dead(object))) {
49976- fscache_stat(stat_object_dead);
49977+ fscache_stat_unchecked(stat_object_dead);
49978 return -ENOBUFS;
49979 }
49980 return 0;
49981@@ -371,7 +371,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49982
49983 _enter("%p,%p,,,", cookie, page);
49984
49985- fscache_stat(&fscache_n_retrievals);
49986+ fscache_stat_unchecked(&fscache_n_retrievals);
49987
49988 if (hlist_empty(&cookie->backing_objects))
49989 goto nobufs;
49990@@ -405,7 +405,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49991 goto nobufs_unlock;
49992 spin_unlock(&cookie->lock);
49993
49994- fscache_stat(&fscache_n_retrieval_ops);
49995+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
49996
49997 /* pin the netfs read context in case we need to do the actual netfs
49998 * read because we've encountered a cache read failure */
49999@@ -435,15 +435,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
50000
50001 error:
50002 if (ret == -ENOMEM)
50003- fscache_stat(&fscache_n_retrievals_nomem);
50004+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
50005 else if (ret == -ERESTARTSYS)
50006- fscache_stat(&fscache_n_retrievals_intr);
50007+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
50008 else if (ret == -ENODATA)
50009- fscache_stat(&fscache_n_retrievals_nodata);
50010+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
50011 else if (ret < 0)
50012- fscache_stat(&fscache_n_retrievals_nobufs);
50013+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
50014 else
50015- fscache_stat(&fscache_n_retrievals_ok);
50016+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
50017
50018 fscache_put_retrieval(op);
50019 _leave(" = %d", ret);
50020@@ -453,7 +453,7 @@ nobufs_unlock:
50021 spin_unlock(&cookie->lock);
50022 kfree(op);
50023 nobufs:
50024- fscache_stat(&fscache_n_retrievals_nobufs);
50025+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
50026 _leave(" = -ENOBUFS");
50027 return -ENOBUFS;
50028 }
50029@@ -491,7 +491,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
50030
50031 _enter("%p,,%d,,,", cookie, *nr_pages);
50032
50033- fscache_stat(&fscache_n_retrievals);
50034+ fscache_stat_unchecked(&fscache_n_retrievals);
50035
50036 if (hlist_empty(&cookie->backing_objects))
50037 goto nobufs;
50038@@ -522,7 +522,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
50039 goto nobufs_unlock;
50040 spin_unlock(&cookie->lock);
50041
50042- fscache_stat(&fscache_n_retrieval_ops);
50043+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
50044
50045 /* pin the netfs read context in case we need to do the actual netfs
50046 * read because we've encountered a cache read failure */
50047@@ -552,15 +552,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
50048
50049 error:
50050 if (ret == -ENOMEM)
50051- fscache_stat(&fscache_n_retrievals_nomem);
50052+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
50053 else if (ret == -ERESTARTSYS)
50054- fscache_stat(&fscache_n_retrievals_intr);
50055+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
50056 else if (ret == -ENODATA)
50057- fscache_stat(&fscache_n_retrievals_nodata);
50058+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
50059 else if (ret < 0)
50060- fscache_stat(&fscache_n_retrievals_nobufs);
50061+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
50062 else
50063- fscache_stat(&fscache_n_retrievals_ok);
50064+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
50065
50066 fscache_put_retrieval(op);
50067 _leave(" = %d", ret);
50068@@ -570,7 +570,7 @@ nobufs_unlock:
50069 spin_unlock(&cookie->lock);
50070 kfree(op);
50071 nobufs:
50072- fscache_stat(&fscache_n_retrievals_nobufs);
50073+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
50074 _leave(" = -ENOBUFS");
50075 return -ENOBUFS;
50076 }
50077@@ -594,7 +594,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
50078
50079 _enter("%p,%p,,,", cookie, page);
50080
50081- fscache_stat(&fscache_n_allocs);
50082+ fscache_stat_unchecked(&fscache_n_allocs);
50083
50084 if (hlist_empty(&cookie->backing_objects))
50085 goto nobufs;
50086@@ -621,7 +621,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
50087 goto nobufs_unlock;
50088 spin_unlock(&cookie->lock);
50089
50090- fscache_stat(&fscache_n_alloc_ops);
50091+ fscache_stat_unchecked(&fscache_n_alloc_ops);
50092
50093 ret = fscache_wait_for_retrieval_activation(
50094 object, op,
50095@@ -637,11 +637,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
50096
50097 error:
50098 if (ret == -ERESTARTSYS)
50099- fscache_stat(&fscache_n_allocs_intr);
50100+ fscache_stat_unchecked(&fscache_n_allocs_intr);
50101 else if (ret < 0)
50102- fscache_stat(&fscache_n_allocs_nobufs);
50103+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
50104 else
50105- fscache_stat(&fscache_n_allocs_ok);
50106+ fscache_stat_unchecked(&fscache_n_allocs_ok);
50107
50108 fscache_put_retrieval(op);
50109 _leave(" = %d", ret);
50110@@ -651,7 +651,7 @@ nobufs_unlock:
50111 spin_unlock(&cookie->lock);
50112 kfree(op);
50113 nobufs:
50114- fscache_stat(&fscache_n_allocs_nobufs);
50115+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
50116 _leave(" = -ENOBUFS");
50117 return -ENOBUFS;
50118 }
50119@@ -694,7 +694,7 @@ static void fscache_write_op(struct fscache_operation *_op)
50120
50121 spin_lock(&cookie->stores_lock);
50122
50123- fscache_stat(&fscache_n_store_calls);
50124+ fscache_stat_unchecked(&fscache_n_store_calls);
50125
50126 /* find a page to store */
50127 page = NULL;
50128@@ -705,7 +705,7 @@ static void fscache_write_op(struct fscache_operation *_op)
50129 page = results[0];
50130 _debug("gang %d [%lx]", n, page->index);
50131 if (page->index > op->store_limit) {
50132- fscache_stat(&fscache_n_store_pages_over_limit);
50133+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
50134 goto superseded;
50135 }
50136
50137@@ -721,7 +721,7 @@ static void fscache_write_op(struct fscache_operation *_op)
50138
50139 if (page) {
50140 fscache_set_op_state(&op->op, "Store");
50141- fscache_stat(&fscache_n_store_pages);
50142+ fscache_stat_unchecked(&fscache_n_store_pages);
50143 fscache_stat(&fscache_n_cop_write_page);
50144 ret = object->cache->ops->write_page(op, page);
50145 fscache_stat_d(&fscache_n_cop_write_page);
50146@@ -792,7 +792,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
50147 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
50148 ASSERT(PageFsCache(page));
50149
50150- fscache_stat(&fscache_n_stores);
50151+ fscache_stat_unchecked(&fscache_n_stores);
50152
50153 op = kzalloc(sizeof(*op), GFP_NOIO);
50154 if (!op)
50155@@ -844,7 +844,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
50156 spin_unlock(&cookie->stores_lock);
50157 spin_unlock(&object->lock);
50158
50159- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
50160+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
50161 op->store_limit = object->store_limit;
50162
50163 if (fscache_submit_op(object, &op->op) < 0)
50164@@ -852,8 +852,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
50165
50166 spin_unlock(&cookie->lock);
50167 radix_tree_preload_end();
50168- fscache_stat(&fscache_n_store_ops);
50169- fscache_stat(&fscache_n_stores_ok);
50170+ fscache_stat_unchecked(&fscache_n_store_ops);
50171+ fscache_stat_unchecked(&fscache_n_stores_ok);
50172
50173 /* the slow work queue now carries its own ref on the object */
50174 fscache_put_operation(&op->op);
50175@@ -861,14 +861,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
50176 return 0;
50177
50178 already_queued:
50179- fscache_stat(&fscache_n_stores_again);
50180+ fscache_stat_unchecked(&fscache_n_stores_again);
50181 already_pending:
50182 spin_unlock(&cookie->stores_lock);
50183 spin_unlock(&object->lock);
50184 spin_unlock(&cookie->lock);
50185 radix_tree_preload_end();
50186 kfree(op);
50187- fscache_stat(&fscache_n_stores_ok);
50188+ fscache_stat_unchecked(&fscache_n_stores_ok);
50189 _leave(" = 0");
50190 return 0;
50191
50192@@ -886,14 +886,14 @@ nobufs:
50193 spin_unlock(&cookie->lock);
50194 radix_tree_preload_end();
50195 kfree(op);
50196- fscache_stat(&fscache_n_stores_nobufs);
50197+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
50198 _leave(" = -ENOBUFS");
50199 return -ENOBUFS;
50200
50201 nomem_free:
50202 kfree(op);
50203 nomem:
50204- fscache_stat(&fscache_n_stores_oom);
50205+ fscache_stat_unchecked(&fscache_n_stores_oom);
50206 _leave(" = -ENOMEM");
50207 return -ENOMEM;
50208 }
50209@@ -911,7 +911,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
50210 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
50211 ASSERTCMP(page, !=, NULL);
50212
50213- fscache_stat(&fscache_n_uncaches);
50214+ fscache_stat_unchecked(&fscache_n_uncaches);
50215
50216 /* cache withdrawal may beat us to it */
50217 if (!PageFsCache(page))
50218@@ -964,7 +964,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
50219 unsigned long loop;
50220
50221 #ifdef CONFIG_FSCACHE_STATS
50222- atomic_add(pagevec->nr, &fscache_n_marks);
50223+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
50224 #endif
50225
50226 for (loop = 0; loop < pagevec->nr; loop++) {
50227diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
50228index 46435f3..8cddf18 100644
50229--- a/fs/fscache/stats.c
50230+++ b/fs/fscache/stats.c
50231@@ -18,95 +18,95 @@
50232 /*
50233 * operation counters
50234 */
50235-atomic_t fscache_n_op_pend;
50236-atomic_t fscache_n_op_run;
50237-atomic_t fscache_n_op_enqueue;
50238-atomic_t fscache_n_op_requeue;
50239-atomic_t fscache_n_op_deferred_release;
50240-atomic_t fscache_n_op_release;
50241-atomic_t fscache_n_op_gc;
50242-atomic_t fscache_n_op_cancelled;
50243-atomic_t fscache_n_op_rejected;
50244+atomic_unchecked_t fscache_n_op_pend;
50245+atomic_unchecked_t fscache_n_op_run;
50246+atomic_unchecked_t fscache_n_op_enqueue;
50247+atomic_unchecked_t fscache_n_op_requeue;
50248+atomic_unchecked_t fscache_n_op_deferred_release;
50249+atomic_unchecked_t fscache_n_op_release;
50250+atomic_unchecked_t fscache_n_op_gc;
50251+atomic_unchecked_t fscache_n_op_cancelled;
50252+atomic_unchecked_t fscache_n_op_rejected;
50253
50254-atomic_t fscache_n_attr_changed;
50255-atomic_t fscache_n_attr_changed_ok;
50256-atomic_t fscache_n_attr_changed_nobufs;
50257-atomic_t fscache_n_attr_changed_nomem;
50258-atomic_t fscache_n_attr_changed_calls;
50259+atomic_unchecked_t fscache_n_attr_changed;
50260+atomic_unchecked_t fscache_n_attr_changed_ok;
50261+atomic_unchecked_t fscache_n_attr_changed_nobufs;
50262+atomic_unchecked_t fscache_n_attr_changed_nomem;
50263+atomic_unchecked_t fscache_n_attr_changed_calls;
50264
50265-atomic_t fscache_n_allocs;
50266-atomic_t fscache_n_allocs_ok;
50267-atomic_t fscache_n_allocs_wait;
50268-atomic_t fscache_n_allocs_nobufs;
50269-atomic_t fscache_n_allocs_intr;
50270-atomic_t fscache_n_allocs_object_dead;
50271-atomic_t fscache_n_alloc_ops;
50272-atomic_t fscache_n_alloc_op_waits;
50273+atomic_unchecked_t fscache_n_allocs;
50274+atomic_unchecked_t fscache_n_allocs_ok;
50275+atomic_unchecked_t fscache_n_allocs_wait;
50276+atomic_unchecked_t fscache_n_allocs_nobufs;
50277+atomic_unchecked_t fscache_n_allocs_intr;
50278+atomic_unchecked_t fscache_n_allocs_object_dead;
50279+atomic_unchecked_t fscache_n_alloc_ops;
50280+atomic_unchecked_t fscache_n_alloc_op_waits;
50281
50282-atomic_t fscache_n_retrievals;
50283-atomic_t fscache_n_retrievals_ok;
50284-atomic_t fscache_n_retrievals_wait;
50285-atomic_t fscache_n_retrievals_nodata;
50286-atomic_t fscache_n_retrievals_nobufs;
50287-atomic_t fscache_n_retrievals_intr;
50288-atomic_t fscache_n_retrievals_nomem;
50289-atomic_t fscache_n_retrievals_object_dead;
50290-atomic_t fscache_n_retrieval_ops;
50291-atomic_t fscache_n_retrieval_op_waits;
50292+atomic_unchecked_t fscache_n_retrievals;
50293+atomic_unchecked_t fscache_n_retrievals_ok;
50294+atomic_unchecked_t fscache_n_retrievals_wait;
50295+atomic_unchecked_t fscache_n_retrievals_nodata;
50296+atomic_unchecked_t fscache_n_retrievals_nobufs;
50297+atomic_unchecked_t fscache_n_retrievals_intr;
50298+atomic_unchecked_t fscache_n_retrievals_nomem;
50299+atomic_unchecked_t fscache_n_retrievals_object_dead;
50300+atomic_unchecked_t fscache_n_retrieval_ops;
50301+atomic_unchecked_t fscache_n_retrieval_op_waits;
50302
50303-atomic_t fscache_n_stores;
50304-atomic_t fscache_n_stores_ok;
50305-atomic_t fscache_n_stores_again;
50306-atomic_t fscache_n_stores_nobufs;
50307-atomic_t fscache_n_stores_oom;
50308-atomic_t fscache_n_store_ops;
50309-atomic_t fscache_n_store_calls;
50310-atomic_t fscache_n_store_pages;
50311-atomic_t fscache_n_store_radix_deletes;
50312-atomic_t fscache_n_store_pages_over_limit;
50313+atomic_unchecked_t fscache_n_stores;
50314+atomic_unchecked_t fscache_n_stores_ok;
50315+atomic_unchecked_t fscache_n_stores_again;
50316+atomic_unchecked_t fscache_n_stores_nobufs;
50317+atomic_unchecked_t fscache_n_stores_oom;
50318+atomic_unchecked_t fscache_n_store_ops;
50319+atomic_unchecked_t fscache_n_store_calls;
50320+atomic_unchecked_t fscache_n_store_pages;
50321+atomic_unchecked_t fscache_n_store_radix_deletes;
50322+atomic_unchecked_t fscache_n_store_pages_over_limit;
50323
50324-atomic_t fscache_n_store_vmscan_not_storing;
50325-atomic_t fscache_n_store_vmscan_gone;
50326-atomic_t fscache_n_store_vmscan_busy;
50327-atomic_t fscache_n_store_vmscan_cancelled;
50328+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
50329+atomic_unchecked_t fscache_n_store_vmscan_gone;
50330+atomic_unchecked_t fscache_n_store_vmscan_busy;
50331+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
50332
50333-atomic_t fscache_n_marks;
50334-atomic_t fscache_n_uncaches;
50335+atomic_unchecked_t fscache_n_marks;
50336+atomic_unchecked_t fscache_n_uncaches;
50337
50338-atomic_t fscache_n_acquires;
50339-atomic_t fscache_n_acquires_null;
50340-atomic_t fscache_n_acquires_no_cache;
50341-atomic_t fscache_n_acquires_ok;
50342-atomic_t fscache_n_acquires_nobufs;
50343-atomic_t fscache_n_acquires_oom;
50344+atomic_unchecked_t fscache_n_acquires;
50345+atomic_unchecked_t fscache_n_acquires_null;
50346+atomic_unchecked_t fscache_n_acquires_no_cache;
50347+atomic_unchecked_t fscache_n_acquires_ok;
50348+atomic_unchecked_t fscache_n_acquires_nobufs;
50349+atomic_unchecked_t fscache_n_acquires_oom;
50350
50351-atomic_t fscache_n_updates;
50352-atomic_t fscache_n_updates_null;
50353-atomic_t fscache_n_updates_run;
50354+atomic_unchecked_t fscache_n_updates;
50355+atomic_unchecked_t fscache_n_updates_null;
50356+atomic_unchecked_t fscache_n_updates_run;
50357
50358-atomic_t fscache_n_relinquishes;
50359-atomic_t fscache_n_relinquishes_null;
50360-atomic_t fscache_n_relinquishes_waitcrt;
50361-atomic_t fscache_n_relinquishes_retire;
50362+atomic_unchecked_t fscache_n_relinquishes;
50363+atomic_unchecked_t fscache_n_relinquishes_null;
50364+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
50365+atomic_unchecked_t fscache_n_relinquishes_retire;
50366
50367-atomic_t fscache_n_cookie_index;
50368-atomic_t fscache_n_cookie_data;
50369-atomic_t fscache_n_cookie_special;
50370+atomic_unchecked_t fscache_n_cookie_index;
50371+atomic_unchecked_t fscache_n_cookie_data;
50372+atomic_unchecked_t fscache_n_cookie_special;
50373
50374-atomic_t fscache_n_object_alloc;
50375-atomic_t fscache_n_object_no_alloc;
50376-atomic_t fscache_n_object_lookups;
50377-atomic_t fscache_n_object_lookups_negative;
50378-atomic_t fscache_n_object_lookups_positive;
50379-atomic_t fscache_n_object_lookups_timed_out;
50380-atomic_t fscache_n_object_created;
50381-atomic_t fscache_n_object_avail;
50382-atomic_t fscache_n_object_dead;
50383+atomic_unchecked_t fscache_n_object_alloc;
50384+atomic_unchecked_t fscache_n_object_no_alloc;
50385+atomic_unchecked_t fscache_n_object_lookups;
50386+atomic_unchecked_t fscache_n_object_lookups_negative;
50387+atomic_unchecked_t fscache_n_object_lookups_positive;
50388+atomic_unchecked_t fscache_n_object_lookups_timed_out;
50389+atomic_unchecked_t fscache_n_object_created;
50390+atomic_unchecked_t fscache_n_object_avail;
50391+atomic_unchecked_t fscache_n_object_dead;
50392
50393-atomic_t fscache_n_checkaux_none;
50394-atomic_t fscache_n_checkaux_okay;
50395-atomic_t fscache_n_checkaux_update;
50396-atomic_t fscache_n_checkaux_obsolete;
50397+atomic_unchecked_t fscache_n_checkaux_none;
50398+atomic_unchecked_t fscache_n_checkaux_okay;
50399+atomic_unchecked_t fscache_n_checkaux_update;
50400+atomic_unchecked_t fscache_n_checkaux_obsolete;
50401
50402 atomic_t fscache_n_cop_alloc_object;
50403 atomic_t fscache_n_cop_lookup_object;
50404@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
50405 seq_puts(m, "FS-Cache statistics\n");
50406
50407 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
50408- atomic_read(&fscache_n_cookie_index),
50409- atomic_read(&fscache_n_cookie_data),
50410- atomic_read(&fscache_n_cookie_special));
50411+ atomic_read_unchecked(&fscache_n_cookie_index),
50412+ atomic_read_unchecked(&fscache_n_cookie_data),
50413+ atomic_read_unchecked(&fscache_n_cookie_special));
50414
50415 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
50416- atomic_read(&fscache_n_object_alloc),
50417- atomic_read(&fscache_n_object_no_alloc),
50418- atomic_read(&fscache_n_object_avail),
50419- atomic_read(&fscache_n_object_dead));
50420+ atomic_read_unchecked(&fscache_n_object_alloc),
50421+ atomic_read_unchecked(&fscache_n_object_no_alloc),
50422+ atomic_read_unchecked(&fscache_n_object_avail),
50423+ atomic_read_unchecked(&fscache_n_object_dead));
50424 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
50425- atomic_read(&fscache_n_checkaux_none),
50426- atomic_read(&fscache_n_checkaux_okay),
50427- atomic_read(&fscache_n_checkaux_update),
50428- atomic_read(&fscache_n_checkaux_obsolete));
50429+ atomic_read_unchecked(&fscache_n_checkaux_none),
50430+ atomic_read_unchecked(&fscache_n_checkaux_okay),
50431+ atomic_read_unchecked(&fscache_n_checkaux_update),
50432+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
50433
50434 seq_printf(m, "Pages : mrk=%u unc=%u\n",
50435- atomic_read(&fscache_n_marks),
50436- atomic_read(&fscache_n_uncaches));
50437+ atomic_read_unchecked(&fscache_n_marks),
50438+ atomic_read_unchecked(&fscache_n_uncaches));
50439
50440 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
50441 " oom=%u\n",
50442- atomic_read(&fscache_n_acquires),
50443- atomic_read(&fscache_n_acquires_null),
50444- atomic_read(&fscache_n_acquires_no_cache),
50445- atomic_read(&fscache_n_acquires_ok),
50446- atomic_read(&fscache_n_acquires_nobufs),
50447- atomic_read(&fscache_n_acquires_oom));
50448+ atomic_read_unchecked(&fscache_n_acquires),
50449+ atomic_read_unchecked(&fscache_n_acquires_null),
50450+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
50451+ atomic_read_unchecked(&fscache_n_acquires_ok),
50452+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
50453+ atomic_read_unchecked(&fscache_n_acquires_oom));
50454
50455 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
50456- atomic_read(&fscache_n_object_lookups),
50457- atomic_read(&fscache_n_object_lookups_negative),
50458- atomic_read(&fscache_n_object_lookups_positive),
50459- atomic_read(&fscache_n_object_lookups_timed_out),
50460- atomic_read(&fscache_n_object_created));
50461+ atomic_read_unchecked(&fscache_n_object_lookups),
50462+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
50463+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
50464+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out),
50465+ atomic_read_unchecked(&fscache_n_object_created));
50466
50467 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
50468- atomic_read(&fscache_n_updates),
50469- atomic_read(&fscache_n_updates_null),
50470- atomic_read(&fscache_n_updates_run));
50471+ atomic_read_unchecked(&fscache_n_updates),
50472+ atomic_read_unchecked(&fscache_n_updates_null),
50473+ atomic_read_unchecked(&fscache_n_updates_run));
50474
50475 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
50476- atomic_read(&fscache_n_relinquishes),
50477- atomic_read(&fscache_n_relinquishes_null),
50478- atomic_read(&fscache_n_relinquishes_waitcrt),
50479- atomic_read(&fscache_n_relinquishes_retire));
50480+ atomic_read_unchecked(&fscache_n_relinquishes),
50481+ atomic_read_unchecked(&fscache_n_relinquishes_null),
50482+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
50483+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
50484
50485 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
50486- atomic_read(&fscache_n_attr_changed),
50487- atomic_read(&fscache_n_attr_changed_ok),
50488- atomic_read(&fscache_n_attr_changed_nobufs),
50489- atomic_read(&fscache_n_attr_changed_nomem),
50490- atomic_read(&fscache_n_attr_changed_calls));
50491+ atomic_read_unchecked(&fscache_n_attr_changed),
50492+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
50493+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
50494+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
50495+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
50496
50497 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
50498- atomic_read(&fscache_n_allocs),
50499- atomic_read(&fscache_n_allocs_ok),
50500- atomic_read(&fscache_n_allocs_wait),
50501- atomic_read(&fscache_n_allocs_nobufs),
50502- atomic_read(&fscache_n_allocs_intr));
50503+ atomic_read_unchecked(&fscache_n_allocs),
50504+ atomic_read_unchecked(&fscache_n_allocs_ok),
50505+ atomic_read_unchecked(&fscache_n_allocs_wait),
50506+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
50507+ atomic_read_unchecked(&fscache_n_allocs_intr));
50508 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
50509- atomic_read(&fscache_n_alloc_ops),
50510- atomic_read(&fscache_n_alloc_op_waits),
50511- atomic_read(&fscache_n_allocs_object_dead));
50512+ atomic_read_unchecked(&fscache_n_alloc_ops),
50513+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
50514+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
50515
50516 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
50517 " int=%u oom=%u\n",
50518- atomic_read(&fscache_n_retrievals),
50519- atomic_read(&fscache_n_retrievals_ok),
50520- atomic_read(&fscache_n_retrievals_wait),
50521- atomic_read(&fscache_n_retrievals_nodata),
50522- atomic_read(&fscache_n_retrievals_nobufs),
50523- atomic_read(&fscache_n_retrievals_intr),
50524- atomic_read(&fscache_n_retrievals_nomem));
50525+ atomic_read_unchecked(&fscache_n_retrievals),
50526+ atomic_read_unchecked(&fscache_n_retrievals_ok),
50527+ atomic_read_unchecked(&fscache_n_retrievals_wait),
50528+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
50529+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
50530+ atomic_read_unchecked(&fscache_n_retrievals_intr),
50531+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
50532 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
50533- atomic_read(&fscache_n_retrieval_ops),
50534- atomic_read(&fscache_n_retrieval_op_waits),
50535- atomic_read(&fscache_n_retrievals_object_dead));
50536+ atomic_read_unchecked(&fscache_n_retrieval_ops),
50537+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
50538+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
50539
50540 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
50541- atomic_read(&fscache_n_stores),
50542- atomic_read(&fscache_n_stores_ok),
50543- atomic_read(&fscache_n_stores_again),
50544- atomic_read(&fscache_n_stores_nobufs),
50545- atomic_read(&fscache_n_stores_oom));
50546+ atomic_read_unchecked(&fscache_n_stores),
50547+ atomic_read_unchecked(&fscache_n_stores_ok),
50548+ atomic_read_unchecked(&fscache_n_stores_again),
50549+ atomic_read_unchecked(&fscache_n_stores_nobufs),
50550+ atomic_read_unchecked(&fscache_n_stores_oom));
50551 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
50552- atomic_read(&fscache_n_store_ops),
50553- atomic_read(&fscache_n_store_calls),
50554- atomic_read(&fscache_n_store_pages),
50555- atomic_read(&fscache_n_store_radix_deletes),
50556- atomic_read(&fscache_n_store_pages_over_limit));
50557+ atomic_read_unchecked(&fscache_n_store_ops),
50558+ atomic_read_unchecked(&fscache_n_store_calls),
50559+ atomic_read_unchecked(&fscache_n_store_pages),
50560+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
50561+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
50562
50563 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
50564- atomic_read(&fscache_n_store_vmscan_not_storing),
50565- atomic_read(&fscache_n_store_vmscan_gone),
50566- atomic_read(&fscache_n_store_vmscan_busy),
50567- atomic_read(&fscache_n_store_vmscan_cancelled));
50568+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
50569+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
50570+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
50571+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
50572
50573 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
50574- atomic_read(&fscache_n_op_pend),
50575- atomic_read(&fscache_n_op_run),
50576- atomic_read(&fscache_n_op_enqueue),
50577- atomic_read(&fscache_n_op_cancelled),
50578- atomic_read(&fscache_n_op_rejected));
50579+ atomic_read_unchecked(&fscache_n_op_pend),
50580+ atomic_read_unchecked(&fscache_n_op_run),
50581+ atomic_read_unchecked(&fscache_n_op_enqueue),
50582+ atomic_read_unchecked(&fscache_n_op_cancelled),
50583+ atomic_read_unchecked(&fscache_n_op_rejected));
50584 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
50585- atomic_read(&fscache_n_op_deferred_release),
50586- atomic_read(&fscache_n_op_release),
50587- atomic_read(&fscache_n_op_gc));
50588+ atomic_read_unchecked(&fscache_n_op_deferred_release),
50589+ atomic_read_unchecked(&fscache_n_op_release),
50590+ atomic_read_unchecked(&fscache_n_op_gc));
50591
50592 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
50593 atomic_read(&fscache_n_cop_alloc_object),
50594diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
50595index de792dc..448b532 100644
50596--- a/fs/fuse/cuse.c
50597+++ b/fs/fuse/cuse.c
50598@@ -576,10 +576,12 @@ static int __init cuse_init(void)
50599 INIT_LIST_HEAD(&cuse_conntbl[i]);
50600
50601 /* inherit and extend fuse_dev_operations */
50602- cuse_channel_fops = fuse_dev_operations;
50603- cuse_channel_fops.owner = THIS_MODULE;
50604- cuse_channel_fops.open = cuse_channel_open;
50605- cuse_channel_fops.release = cuse_channel_release;
50606+ pax_open_kernel();
50607+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
50608+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
50609+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
50610+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
50611+ pax_close_kernel();
50612
50613 cuse_class = class_create(THIS_MODULE, "cuse");
50614 if (IS_ERR(cuse_class))
50615diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
50616index 1facb39..7f48557 100644
50617--- a/fs/fuse/dev.c
50618+++ b/fs/fuse/dev.c
50619@@ -885,7 +885,7 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50620 {
50621 struct fuse_notify_inval_entry_out outarg;
50622 int err = -EINVAL;
50623- char buf[FUSE_NAME_MAX+1];
50624+ char *buf = NULL;
50625 struct qstr name;
50626
50627 if (size < sizeof(outarg))
50628@@ -899,6 +899,11 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50629 if (outarg.namelen > FUSE_NAME_MAX)
50630 goto err;
50631
50632+ err = -ENOMEM;
50633+ buf = kmalloc(FUSE_NAME_MAX+1, GFP_KERNEL);
50634+ if (!buf)
50635+ goto err;
50636+
50637 err = -EINVAL;
50638 if (size != sizeof(outarg) + outarg.namelen + 1)
50639 goto err;
50640@@ -914,17 +919,15 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
50641
50642 down_read(&fc->killsb);
50643 err = -ENOENT;
50644- if (!fc->sb)
50645- goto err_unlock;
50646-
50647- err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
50648-
50649-err_unlock:
50650+ if (fc->sb)
50651+ err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
50652 up_read(&fc->killsb);
50653+ kfree(buf);
50654 return err;
50655
50656 err:
50657 fuse_copy_finish(cs);
50658+ kfree(buf);
50659 return err;
50660 }
50661
50662diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
50663index 4787ae6..73efff7 100644
50664--- a/fs/fuse/dir.c
50665+++ b/fs/fuse/dir.c
50666@@ -1127,7 +1127,7 @@ static char *read_link(struct dentry *dentry)
50667 return link;
50668 }
50669
50670-static void free_link(char *link)
50671+static void free_link(const char *link)
50672 {
50673 if (!IS_ERR(link))
50674 free_page((unsigned long) link);
50675diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
50676index 247436c..e650ccb 100644
50677--- a/fs/gfs2/ops_inode.c
50678+++ b/fs/gfs2/ops_inode.c
50679@@ -752,6 +752,8 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
50680 unsigned int x;
50681 int error;
50682
50683+ pax_track_stack();
50684+
50685 if (ndentry->d_inode) {
50686 nip = GFS2_I(ndentry->d_inode);
50687 if (ip == nip)
50688diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
50689index 4463297..4fed53b 100644
50690--- a/fs/gfs2/sys.c
50691+++ b/fs/gfs2/sys.c
50692@@ -49,7 +49,7 @@ static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr,
50693 return a->store ? a->store(sdp, buf, len) : len;
50694 }
50695
50696-static struct sysfs_ops gfs2_attr_ops = {
50697+static const struct sysfs_ops gfs2_attr_ops = {
50698 .show = gfs2_attr_show,
50699 .store = gfs2_attr_store,
50700 };
50701@@ -584,7 +584,7 @@ static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
50702 return 0;
50703 }
50704
50705-static struct kset_uevent_ops gfs2_uevent_ops = {
50706+static const struct kset_uevent_ops gfs2_uevent_ops = {
50707 .uevent = gfs2_uevent,
50708 };
50709
50710diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
50711index f6874ac..7cd98a8 100644
50712--- a/fs/hfsplus/catalog.c
50713+++ b/fs/hfsplus/catalog.c
50714@@ -157,6 +157,8 @@ int hfsplus_find_cat(struct super_block *sb, u32 cnid,
50715 int err;
50716 u16 type;
50717
50718+ pax_track_stack();
50719+
50720 hfsplus_cat_build_key(sb, fd->search_key, cnid, NULL);
50721 err = hfs_brec_read(fd, &tmp, sizeof(hfsplus_cat_entry));
50722 if (err)
50723@@ -186,6 +188,8 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir, struct qstr *str, struct ino
50724 int entry_size;
50725 int err;
50726
50727+ pax_track_stack();
50728+
50729 dprint(DBG_CAT_MOD, "create_cat: %s,%u(%d)\n", str->name, cnid, inode->i_nlink);
50730 sb = dir->i_sb;
50731 hfs_find_init(HFSPLUS_SB(sb).cat_tree, &fd);
50732@@ -318,6 +322,8 @@ int hfsplus_rename_cat(u32 cnid,
50733 int entry_size, type;
50734 int err = 0;
50735
50736+ pax_track_stack();
50737+
50738 dprint(DBG_CAT_MOD, "rename_cat: %u - %lu,%s - %lu,%s\n", cnid, src_dir->i_ino, src_name->name,
50739 dst_dir->i_ino, dst_name->name);
50740 sb = src_dir->i_sb;
50741diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
50742index 5f40236..dac3421 100644
50743--- a/fs/hfsplus/dir.c
50744+++ b/fs/hfsplus/dir.c
50745@@ -121,6 +121,8 @@ static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
50746 struct hfsplus_readdir_data *rd;
50747 u16 type;
50748
50749+ pax_track_stack();
50750+
50751 if (filp->f_pos >= inode->i_size)
50752 return 0;
50753
50754diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
50755index 1bcf597..905a251 100644
50756--- a/fs/hfsplus/inode.c
50757+++ b/fs/hfsplus/inode.c
50758@@ -399,6 +399,8 @@ int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd)
50759 int res = 0;
50760 u16 type;
50761
50762+ pax_track_stack();
50763+
50764 type = hfs_bnode_read_u16(fd->bnode, fd->entryoffset);
50765
50766 HFSPLUS_I(inode).dev = 0;
50767@@ -461,6 +463,8 @@ int hfsplus_cat_write_inode(struct inode *inode)
50768 struct hfs_find_data fd;
50769 hfsplus_cat_entry entry;
50770
50771+ pax_track_stack();
50772+
50773 if (HFSPLUS_IS_RSRC(inode))
50774 main_inode = HFSPLUS_I(inode).rsrc_inode;
50775
50776diff --git a/fs/hfsplus/ioctl.c b/fs/hfsplus/ioctl.c
50777index f457d2c..7ef4ad5 100644
50778--- a/fs/hfsplus/ioctl.c
50779+++ b/fs/hfsplus/ioctl.c
50780@@ -101,6 +101,8 @@ int hfsplus_setxattr(struct dentry *dentry, const char *name,
50781 struct hfsplus_cat_file *file;
50782 int res;
50783
50784+ pax_track_stack();
50785+
50786 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
50787 return -EOPNOTSUPP;
50788
50789@@ -143,6 +145,8 @@ ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
50790 struct hfsplus_cat_file *file;
50791 ssize_t res = 0;
50792
50793+ pax_track_stack();
50794+
50795 if (!S_ISREG(inode->i_mode) || HFSPLUS_IS_RSRC(inode))
50796 return -EOPNOTSUPP;
50797
50798diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
50799index 43022f3..7298079 100644
50800--- a/fs/hfsplus/super.c
50801+++ b/fs/hfsplus/super.c
50802@@ -312,6 +312,8 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent)
50803 struct nls_table *nls = NULL;
50804 int err = -EINVAL;
50805
50806+ pax_track_stack();
50807+
50808 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
50809 if (!sbi)
50810 return -ENOMEM;
50811diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
50812index 87a1258..5694d91 100644
50813--- a/fs/hugetlbfs/inode.c
50814+++ b/fs/hugetlbfs/inode.c
50815@@ -909,7 +909,7 @@ static struct file_system_type hugetlbfs_fs_type = {
50816 .kill_sb = kill_litter_super,
50817 };
50818
50819-static struct vfsmount *hugetlbfs_vfsmount;
50820+struct vfsmount *hugetlbfs_vfsmount;
50821
50822 static int can_do_hugetlb_shm(void)
50823 {
50824diff --git a/fs/ioctl.c b/fs/ioctl.c
50825index 6c75110..19d2c3c 100644
50826--- a/fs/ioctl.c
50827+++ b/fs/ioctl.c
50828@@ -97,7 +97,7 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical,
50829 u64 phys, u64 len, u32 flags)
50830 {
50831 struct fiemap_extent extent;
50832- struct fiemap_extent *dest = fieinfo->fi_extents_start;
50833+ struct fiemap_extent __user *dest = fieinfo->fi_extents_start;
50834
50835 /* only count the extents */
50836 if (fieinfo->fi_extents_max == 0) {
50837@@ -207,7 +207,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
50838
50839 fieinfo.fi_flags = fiemap.fm_flags;
50840 fieinfo.fi_extents_max = fiemap.fm_extent_count;
50841- fieinfo.fi_extents_start = (struct fiemap_extent *)(arg + sizeof(fiemap));
50842+ fieinfo.fi_extents_start = (struct fiemap_extent __user *)(arg + sizeof(fiemap));
50843
50844 if (fiemap.fm_extent_count != 0 &&
50845 !access_ok(VERIFY_WRITE, fieinfo.fi_extents_start,
50846@@ -220,7 +220,7 @@ static int ioctl_fiemap(struct file *filp, unsigned long arg)
50847 error = inode->i_op->fiemap(inode, &fieinfo, fiemap.fm_start, len);
50848 fiemap.fm_flags = fieinfo.fi_flags;
50849 fiemap.fm_mapped_extents = fieinfo.fi_extents_mapped;
50850- if (copy_to_user((char *)arg, &fiemap, sizeof(fiemap)))
50851+ if (copy_to_user((__force char __user *)arg, &fiemap, sizeof(fiemap)))
50852 error = -EFAULT;
50853
50854 return error;
50855diff --git a/fs/jbd/checkpoint.c b/fs/jbd/checkpoint.c
50856index b0435dd..81ee0be 100644
50857--- a/fs/jbd/checkpoint.c
50858+++ b/fs/jbd/checkpoint.c
50859@@ -348,6 +348,8 @@ int log_do_checkpoint(journal_t *journal)
50860 tid_t this_tid;
50861 int result;
50862
50863+ pax_track_stack();
50864+
50865 jbd_debug(1, "Start checkpoint\n");
50866
50867 /*
50868diff --git a/fs/jffs2/compr_rtime.c b/fs/jffs2/compr_rtime.c
50869index 546d153..736896c 100644
50870--- a/fs/jffs2/compr_rtime.c
50871+++ b/fs/jffs2/compr_rtime.c
50872@@ -37,6 +37,8 @@ static int jffs2_rtime_compress(unsigned char *data_in,
50873 int outpos = 0;
50874 int pos=0;
50875
50876+ pax_track_stack();
50877+
50878 memset(positions,0,sizeof(positions));
50879
50880 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
50881@@ -79,6 +81,8 @@ static int jffs2_rtime_decompress(unsigned char *data_in,
50882 int outpos = 0;
50883 int pos=0;
50884
50885+ pax_track_stack();
50886+
50887 memset(positions,0,sizeof(positions));
50888
50889 while (outpos<destlen) {
50890diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c
50891index 170d289..3254b98 100644
50892--- a/fs/jffs2/compr_rubin.c
50893+++ b/fs/jffs2/compr_rubin.c
50894@@ -314,6 +314,8 @@ static int jffs2_dynrubin_compress(unsigned char *data_in,
50895 int ret;
50896 uint32_t mysrclen, mydstlen;
50897
50898+ pax_track_stack();
50899+
50900 mysrclen = *sourcelen;
50901 mydstlen = *dstlen - 8;
50902
50903diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
50904index b47679b..00d65d3 100644
50905--- a/fs/jffs2/erase.c
50906+++ b/fs/jffs2/erase.c
50907@@ -434,7 +434,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
50908 struct jffs2_unknown_node marker = {
50909 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
50910 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50911- .totlen = cpu_to_je32(c->cleanmarker_size)
50912+ .totlen = cpu_to_je32(c->cleanmarker_size),
50913+ .hdr_crc = cpu_to_je32(0)
50914 };
50915
50916 jffs2_prealloc_raw_node_refs(c, jeb, 1);
50917diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
50918index 5ef7bac..4fd1e3c 100644
50919--- a/fs/jffs2/wbuf.c
50920+++ b/fs/jffs2/wbuf.c
50921@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
50922 {
50923 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
50924 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50925- .totlen = constant_cpu_to_je32(8)
50926+ .totlen = constant_cpu_to_je32(8),
50927+ .hdr_crc = constant_cpu_to_je32(0)
50928 };
50929
50930 /*
50931diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
50932index 082e844..52012a1 100644
50933--- a/fs/jffs2/xattr.c
50934+++ b/fs/jffs2/xattr.c
50935@@ -773,6 +773,8 @@ void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
50936
50937 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
50938
50939+ pax_track_stack();
50940+
50941 /* Phase.1 : Merge same xref */
50942 for (i=0; i < XREF_TMPHASH_SIZE; i++)
50943 xref_tmphash[i] = NULL;
50944diff --git a/fs/jfs/super.c b/fs/jfs/super.c
50945index 2234c73..f6e6e6b 100644
50946--- a/fs/jfs/super.c
50947+++ b/fs/jfs/super.c
50948@@ -793,7 +793,7 @@ static int __init init_jfs_fs(void)
50949
50950 jfs_inode_cachep =
50951 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
50952- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
50953+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
50954 init_once);
50955 if (jfs_inode_cachep == NULL)
50956 return -ENOMEM;
50957diff --git a/fs/libfs.c b/fs/libfs.c
50958index ba36e93..3153fce 100644
50959--- a/fs/libfs.c
50960+++ b/fs/libfs.c
50961@@ -157,12 +157,20 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50962
50963 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
50964 struct dentry *next;
50965+ char d_name[sizeof(next->d_iname)];
50966+ const unsigned char *name;
50967+
50968 next = list_entry(p, struct dentry, d_u.d_child);
50969 if (d_unhashed(next) || !next->d_inode)
50970 continue;
50971
50972 spin_unlock(&dcache_lock);
50973- if (filldir(dirent, next->d_name.name,
50974+ name = next->d_name.name;
50975+ if (name == next->d_iname) {
50976+ memcpy(d_name, name, next->d_name.len);
50977+ name = d_name;
50978+ }
50979+ if (filldir(dirent, name,
50980 next->d_name.len, filp->f_pos,
50981 next->d_inode->i_ino,
50982 dt_type(next->d_inode)) < 0)
50983diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
50984index c325a83..d15b07b 100644
50985--- a/fs/lockd/clntproc.c
50986+++ b/fs/lockd/clntproc.c
50987@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
50988 /*
50989 * Cookie counter for NLM requests
50990 */
50991-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
50992+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
50993
50994 void nlmclnt_next_cookie(struct nlm_cookie *c)
50995 {
50996- u32 cookie = atomic_inc_return(&nlm_cookie);
50997+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
50998
50999 memcpy(c->data, &cookie, 4);
51000 c->len=4;
51001@@ -621,6 +621,8 @@ nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl)
51002 struct nlm_rqst reqst, *req;
51003 int status;
51004
51005+ pax_track_stack();
51006+
51007 req = &reqst;
51008 memset(req, 0, sizeof(*req));
51009 locks_init_lock(&req->a_args.lock.fl);
51010diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
51011index 1a54ae1..6a16c27 100644
51012--- a/fs/lockd/svc.c
51013+++ b/fs/lockd/svc.c
51014@@ -43,7 +43,7 @@
51015
51016 static struct svc_program nlmsvc_program;
51017
51018-struct nlmsvc_binding * nlmsvc_ops;
51019+const struct nlmsvc_binding * nlmsvc_ops;
51020 EXPORT_SYMBOL_GPL(nlmsvc_ops);
51021
51022 static DEFINE_MUTEX(nlmsvc_mutex);
51023diff --git a/fs/locks.c b/fs/locks.c
51024index a8794f2..4041e55 100644
51025--- a/fs/locks.c
51026+++ b/fs/locks.c
51027@@ -145,10 +145,28 @@ static LIST_HEAD(blocked_list);
51028
51029 static struct kmem_cache *filelock_cache __read_mostly;
51030
51031+static void locks_init_lock_always(struct file_lock *fl)
51032+{
51033+ fl->fl_next = NULL;
51034+ fl->fl_fasync = NULL;
51035+ fl->fl_owner = NULL;
51036+ fl->fl_pid = 0;
51037+ fl->fl_nspid = NULL;
51038+ fl->fl_file = NULL;
51039+ fl->fl_flags = 0;
51040+ fl->fl_type = 0;
51041+ fl->fl_start = fl->fl_end = 0;
51042+}
51043+
51044 /* Allocate an empty lock structure. */
51045 static struct file_lock *locks_alloc_lock(void)
51046 {
51047- return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
51048+ struct file_lock *fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
51049+
51050+ if (fl)
51051+ locks_init_lock_always(fl);
51052+
51053+ return fl;
51054 }
51055
51056 void locks_release_private(struct file_lock *fl)
51057@@ -183,17 +201,9 @@ void locks_init_lock(struct file_lock *fl)
51058 INIT_LIST_HEAD(&fl->fl_link);
51059 INIT_LIST_HEAD(&fl->fl_block);
51060 init_waitqueue_head(&fl->fl_wait);
51061- fl->fl_next = NULL;
51062- fl->fl_fasync = NULL;
51063- fl->fl_owner = NULL;
51064- fl->fl_pid = 0;
51065- fl->fl_nspid = NULL;
51066- fl->fl_file = NULL;
51067- fl->fl_flags = 0;
51068- fl->fl_type = 0;
51069- fl->fl_start = fl->fl_end = 0;
51070 fl->fl_ops = NULL;
51071 fl->fl_lmops = NULL;
51072+ locks_init_lock_always(fl);
51073 }
51074
51075 EXPORT_SYMBOL(locks_init_lock);
51076@@ -2007,16 +2017,16 @@ void locks_remove_flock(struct file *filp)
51077 return;
51078
51079 if (filp->f_op && filp->f_op->flock) {
51080- struct file_lock fl = {
51081+ struct file_lock flock = {
51082 .fl_pid = current->tgid,
51083 .fl_file = filp,
51084 .fl_flags = FL_FLOCK,
51085 .fl_type = F_UNLCK,
51086 .fl_end = OFFSET_MAX,
51087 };
51088- filp->f_op->flock(filp, F_SETLKW, &fl);
51089- if (fl.fl_ops && fl.fl_ops->fl_release_private)
51090- fl.fl_ops->fl_release_private(&fl);
51091+ filp->f_op->flock(filp, F_SETLKW, &flock);
51092+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
51093+ flock.fl_ops->fl_release_private(&flock);
51094 }
51095
51096 lock_kernel();
51097diff --git a/fs/mbcache.c b/fs/mbcache.c
51098index ec88ff3..b843a82 100644
51099--- a/fs/mbcache.c
51100+++ b/fs/mbcache.c
51101@@ -266,9 +266,9 @@ mb_cache_create(const char *name, struct mb_cache_op *cache_op,
51102 if (!cache)
51103 goto fail;
51104 cache->c_name = name;
51105- cache->c_op.free = NULL;
51106+ *(void **)&cache->c_op.free = NULL;
51107 if (cache_op)
51108- cache->c_op.free = cache_op->free;
51109+ *(void **)&cache->c_op.free = cache_op->free;
51110 atomic_set(&cache->c_entry_count, 0);
51111 cache->c_bucket_bits = bucket_bits;
51112 #ifdef MB_CACHE_INDEXES_COUNT
51113diff --git a/fs/namei.c b/fs/namei.c
51114index b0afbd4..8d065a1 100644
51115--- a/fs/namei.c
51116+++ b/fs/namei.c
51117@@ -224,6 +224,14 @@ int generic_permission(struct inode *inode, int mask,
51118 return ret;
51119
51120 /*
51121+ * Searching includes executable on directories, else just read.
51122+ */
51123+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
51124+ if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
51125+ if (capable(CAP_DAC_READ_SEARCH))
51126+ return 0;
51127+
51128+ /*
51129 * Read/write DACs are always overridable.
51130 * Executable DACs are overridable if at least one exec bit is set.
51131 */
51132@@ -231,14 +239,6 @@ int generic_permission(struct inode *inode, int mask,
51133 if (capable(CAP_DAC_OVERRIDE))
51134 return 0;
51135
51136- /*
51137- * Searching includes executable on directories, else just read.
51138- */
51139- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
51140- if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
51141- if (capable(CAP_DAC_READ_SEARCH))
51142- return 0;
51143-
51144 return -EACCES;
51145 }
51146
51147@@ -458,7 +458,8 @@ static int exec_permission_lite(struct inode *inode)
51148 if (!ret)
51149 goto ok;
51150
51151- if (capable(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH))
51152+ if (capable_nolog(CAP_DAC_OVERRIDE) || capable(CAP_DAC_READ_SEARCH) ||
51153+ capable(CAP_DAC_OVERRIDE))
51154 goto ok;
51155
51156 return ret;
51157@@ -638,7 +639,7 @@ static __always_inline int __do_follow_link(struct path *path, struct nameidata
51158 cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
51159 error = PTR_ERR(cookie);
51160 if (!IS_ERR(cookie)) {
51161- char *s = nd_get_link(nd);
51162+ const char *s = nd_get_link(nd);
51163 error = 0;
51164 if (s)
51165 error = __vfs_follow_link(nd, s);
51166@@ -669,6 +670,13 @@ static inline int do_follow_link(struct path *path, struct nameidata *nd)
51167 err = security_inode_follow_link(path->dentry, nd);
51168 if (err)
51169 goto loop;
51170+
51171+ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
51172+ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
51173+ err = -EACCES;
51174+ goto loop;
51175+ }
51176+
51177 current->link_count++;
51178 current->total_link_count++;
51179 nd->depth++;
51180@@ -1016,11 +1024,19 @@ return_reval:
51181 break;
51182 }
51183 return_base:
51184+ if (!(nd->flags & (LOOKUP_CONTINUE | LOOKUP_PARENT)) &&
51185+ !gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
51186+ path_put(&nd->path);
51187+ return -ENOENT;
51188+ }
51189 return 0;
51190 out_dput:
51191 path_put_conditional(&next, nd);
51192 break;
51193 }
51194+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
51195+ err = -ENOENT;
51196+
51197 path_put(&nd->path);
51198 return_err:
51199 return err;
51200@@ -1091,13 +1107,20 @@ static int do_path_lookup(int dfd, const char *name,
51201 int retval = path_init(dfd, name, flags, nd);
51202 if (!retval)
51203 retval = path_walk(name, nd);
51204- if (unlikely(!retval && !audit_dummy_context() && nd->path.dentry &&
51205- nd->path.dentry->d_inode))
51206- audit_inode(name, nd->path.dentry);
51207+
51208+ if (likely(!retval)) {
51209+ if (nd->path.dentry && nd->path.dentry->d_inode) {
51210+ if (*name != '/' && !gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
51211+ retval = -ENOENT;
51212+ if (!audit_dummy_context())
51213+ audit_inode(name, nd->path.dentry);
51214+ }
51215+ }
51216 if (nd->root.mnt) {
51217 path_put(&nd->root);
51218 nd->root.mnt = NULL;
51219 }
51220+
51221 return retval;
51222 }
51223
51224@@ -1576,6 +1599,20 @@ int may_open(struct path *path, int acc_mode, int flag)
51225 if (error)
51226 goto err_out;
51227
51228+
51229+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode)) {
51230+ error = -EPERM;
51231+ goto err_out;
51232+ }
51233+ if (gr_handle_rawio(inode)) {
51234+ error = -EPERM;
51235+ goto err_out;
51236+ }
51237+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode)) {
51238+ error = -EACCES;
51239+ goto err_out;
51240+ }
51241+
51242 if (flag & O_TRUNC) {
51243 error = get_write_access(inode);
51244 if (error)
51245@@ -1620,6 +1657,17 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
51246 {
51247 int error;
51248 struct dentry *dir = nd->path.dentry;
51249+ int acc_mode = ACC_MODE(flag);
51250+
51251+ if (flag & O_TRUNC)
51252+ acc_mode |= MAY_WRITE;
51253+ if (flag & O_APPEND)
51254+ acc_mode |= MAY_APPEND;
51255+
51256+ if (!gr_acl_handle_creat(path->dentry, dir, nd->path.mnt, flag, acc_mode, mode)) {
51257+ error = -EACCES;
51258+ goto out_unlock;
51259+ }
51260
51261 if (!IS_POSIXACL(dir->d_inode))
51262 mode &= ~current_umask();
51263@@ -1627,6 +1675,8 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
51264 if (error)
51265 goto out_unlock;
51266 error = vfs_create(dir->d_inode, path->dentry, mode, nd);
51267+ if (!error)
51268+ gr_handle_create(path->dentry, nd->path.mnt);
51269 out_unlock:
51270 mutex_unlock(&dir->d_inode->i_mutex);
51271 dput(nd->path.dentry);
51272@@ -1709,6 +1759,22 @@ struct file *do_filp_open(int dfd, const char *pathname,
51273 &nd, flag);
51274 if (error)
51275 return ERR_PTR(error);
51276+
51277+ if (gr_handle_rofs_blockwrite(nd.path.dentry, nd.path.mnt, acc_mode)) {
51278+ error = -EPERM;
51279+ goto exit;
51280+ }
51281+
51282+ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
51283+ error = -EPERM;
51284+ goto exit;
51285+ }
51286+
51287+ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, acc_mode)) {
51288+ error = -EACCES;
51289+ goto exit;
51290+ }
51291+
51292 goto ok;
51293 }
51294
51295@@ -1795,6 +1861,19 @@ do_last:
51296 /*
51297 * It already exists.
51298 */
51299+
51300+ if (!gr_acl_handle_hidden_file(path.dentry, path.mnt)) {
51301+ error = -ENOENT;
51302+ goto exit_mutex_unlock;
51303+ }
51304+
51305+ /* only check if O_CREAT is specified, all other checks need
51306+ to go into may_open */
51307+ if (gr_handle_fifo(path.dentry, path.mnt, dir, flag, acc_mode)) {
51308+ error = -EACCES;
51309+ goto exit_mutex_unlock;
51310+ }
51311+
51312 mutex_unlock(&dir->d_inode->i_mutex);
51313 audit_inode(pathname, path.dentry);
51314
51315@@ -1887,6 +1966,13 @@ do_link:
51316 error = security_inode_follow_link(path.dentry, &nd);
51317 if (error)
51318 goto exit_dput;
51319+
51320+ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
51321+ path.dentry, nd.path.mnt)) {
51322+ error = -EACCES;
51323+ goto exit_dput;
51324+ }
51325+
51326 error = __do_follow_link(&path, &nd);
51327 if (error) {
51328 /* Does someone understand code flow here? Or it is only
51329@@ -1984,6 +2070,10 @@ struct dentry *lookup_create(struct nameidata *nd, int is_dir)
51330 }
51331 return dentry;
51332 eexist:
51333+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
51334+ dput(dentry);
51335+ return ERR_PTR(-ENOENT);
51336+ }
51337 dput(dentry);
51338 dentry = ERR_PTR(-EEXIST);
51339 fail:
51340@@ -2061,6 +2151,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
51341 error = may_mknod(mode);
51342 if (error)
51343 goto out_dput;
51344+
51345+ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
51346+ error = -EPERM;
51347+ goto out_dput;
51348+ }
51349+
51350+ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
51351+ error = -EACCES;
51352+ goto out_dput;
51353+ }
51354+
51355 error = mnt_want_write(nd.path.mnt);
51356 if (error)
51357 goto out_dput;
51358@@ -2081,6 +2182,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
51359 }
51360 out_drop_write:
51361 mnt_drop_write(nd.path.mnt);
51362+
51363+ if (!error)
51364+ gr_handle_create(dentry, nd.path.mnt);
51365 out_dput:
51366 dput(dentry);
51367 out_unlock:
51368@@ -2134,6 +2238,11 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
51369 if (IS_ERR(dentry))
51370 goto out_unlock;
51371
51372+ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
51373+ error = -EACCES;
51374+ goto out_dput;
51375+ }
51376+
51377 if (!IS_POSIXACL(nd.path.dentry->d_inode))
51378 mode &= ~current_umask();
51379 error = mnt_want_write(nd.path.mnt);
51380@@ -2145,6 +2254,10 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
51381 error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
51382 out_drop_write:
51383 mnt_drop_write(nd.path.mnt);
51384+
51385+ if (!error)
51386+ gr_handle_create(dentry, nd.path.mnt);
51387+
51388 out_dput:
51389 dput(dentry);
51390 out_unlock:
51391@@ -2226,6 +2339,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
51392 char * name;
51393 struct dentry *dentry;
51394 struct nameidata nd;
51395+ ino_t saved_ino = 0;
51396+ dev_t saved_dev = 0;
51397
51398 error = user_path_parent(dfd, pathname, &nd, &name);
51399 if (error)
51400@@ -2250,6 +2365,17 @@ static long do_rmdir(int dfd, const char __user *pathname)
51401 error = PTR_ERR(dentry);
51402 if (IS_ERR(dentry))
51403 goto exit2;
51404+
51405+ if (dentry->d_inode != NULL) {
51406+ saved_ino = dentry->d_inode->i_ino;
51407+ saved_dev = gr_get_dev_from_dentry(dentry);
51408+
51409+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
51410+ error = -EACCES;
51411+ goto exit3;
51412+ }
51413+ }
51414+
51415 error = mnt_want_write(nd.path.mnt);
51416 if (error)
51417 goto exit3;
51418@@ -2257,6 +2383,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
51419 if (error)
51420 goto exit4;
51421 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
51422+ if (!error && (saved_dev || saved_ino))
51423+ gr_handle_delete(saved_ino, saved_dev);
51424 exit4:
51425 mnt_drop_write(nd.path.mnt);
51426 exit3:
51427@@ -2318,6 +2446,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51428 struct dentry *dentry;
51429 struct nameidata nd;
51430 struct inode *inode = NULL;
51431+ ino_t saved_ino = 0;
51432+ dev_t saved_dev = 0;
51433
51434 error = user_path_parent(dfd, pathname, &nd, &name);
51435 if (error)
51436@@ -2337,8 +2467,19 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51437 if (nd.last.name[nd.last.len])
51438 goto slashes;
51439 inode = dentry->d_inode;
51440- if (inode)
51441+ if (inode) {
51442+ if (inode->i_nlink <= 1) {
51443+ saved_ino = inode->i_ino;
51444+ saved_dev = gr_get_dev_from_dentry(dentry);
51445+ }
51446+
51447 atomic_inc(&inode->i_count);
51448+
51449+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
51450+ error = -EACCES;
51451+ goto exit2;
51452+ }
51453+ }
51454 error = mnt_want_write(nd.path.mnt);
51455 if (error)
51456 goto exit2;
51457@@ -2346,6 +2487,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
51458 if (error)
51459 goto exit3;
51460 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
51461+ if (!error && (saved_ino || saved_dev))
51462+ gr_handle_delete(saved_ino, saved_dev);
51463 exit3:
51464 mnt_drop_write(nd.path.mnt);
51465 exit2:
51466@@ -2424,6 +2567,11 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
51467 if (IS_ERR(dentry))
51468 goto out_unlock;
51469
51470+ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
51471+ error = -EACCES;
51472+ goto out_dput;
51473+ }
51474+
51475 error = mnt_want_write(nd.path.mnt);
51476 if (error)
51477 goto out_dput;
51478@@ -2431,6 +2579,8 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
51479 if (error)
51480 goto out_drop_write;
51481 error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
51482+ if (!error)
51483+ gr_handle_create(dentry, nd.path.mnt);
51484 out_drop_write:
51485 mnt_drop_write(nd.path.mnt);
51486 out_dput:
51487@@ -2524,6 +2674,20 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
51488 error = PTR_ERR(new_dentry);
51489 if (IS_ERR(new_dentry))
51490 goto out_unlock;
51491+
51492+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
51493+ old_path.dentry->d_inode,
51494+ old_path.dentry->d_inode->i_mode, to)) {
51495+ error = -EACCES;
51496+ goto out_dput;
51497+ }
51498+
51499+ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
51500+ old_path.dentry, old_path.mnt, to)) {
51501+ error = -EACCES;
51502+ goto out_dput;
51503+ }
51504+
51505 error = mnt_want_write(nd.path.mnt);
51506 if (error)
51507 goto out_dput;
51508@@ -2531,6 +2695,8 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
51509 if (error)
51510 goto out_drop_write;
51511 error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
51512+ if (!error)
51513+ gr_handle_create(new_dentry, nd.path.mnt);
51514 out_drop_write:
51515 mnt_drop_write(nd.path.mnt);
51516 out_dput:
51517@@ -2708,6 +2874,8 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51518 char *to;
51519 int error;
51520
51521+ pax_track_stack();
51522+
51523 error = user_path_parent(olddfd, oldname, &oldnd, &from);
51524 if (error)
51525 goto exit;
51526@@ -2764,6 +2932,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51527 if (new_dentry == trap)
51528 goto exit5;
51529
51530+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
51531+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
51532+ to);
51533+ if (error)
51534+ goto exit5;
51535+
51536 error = mnt_want_write(oldnd.path.mnt);
51537 if (error)
51538 goto exit5;
51539@@ -2773,6 +2947,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
51540 goto exit6;
51541 error = vfs_rename(old_dir->d_inode, old_dentry,
51542 new_dir->d_inode, new_dentry);
51543+ if (!error)
51544+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
51545+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
51546 exit6:
51547 mnt_drop_write(oldnd.path.mnt);
51548 exit5:
51549@@ -2798,6 +2975,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
51550
51551 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
51552 {
51553+ char tmpbuf[64];
51554+ const char *newlink;
51555 int len;
51556
51557 len = PTR_ERR(link);
51558@@ -2807,7 +2986,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
51559 len = strlen(link);
51560 if (len > (unsigned) buflen)
51561 len = buflen;
51562- if (copy_to_user(buffer, link, len))
51563+
51564+ if (len < sizeof(tmpbuf)) {
51565+ memcpy(tmpbuf, link, len);
51566+ newlink = tmpbuf;
51567+ } else
51568+ newlink = link;
51569+
51570+ if (copy_to_user(buffer, newlink, len))
51571 len = -EFAULT;
51572 out:
51573 return len;
51574diff --git a/fs/namespace.c b/fs/namespace.c
51575index 2beb0fb..11a95a5 100644
51576--- a/fs/namespace.c
51577+++ b/fs/namespace.c
51578@@ -1083,6 +1083,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
51579 if (!(sb->s_flags & MS_RDONLY))
51580 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
51581 up_write(&sb->s_umount);
51582+
51583+ gr_log_remount(mnt->mnt_devname, retval);
51584+
51585 return retval;
51586 }
51587
51588@@ -1104,6 +1107,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
51589 security_sb_umount_busy(mnt);
51590 up_write(&namespace_sem);
51591 release_mounts(&umount_list);
51592+
51593+ gr_log_unmount(mnt->mnt_devname, retval);
51594+
51595 return retval;
51596 }
51597
51598@@ -1962,6 +1968,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
51599 if (retval)
51600 goto dput_out;
51601
51602+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
51603+ retval = -EPERM;
51604+ goto dput_out;
51605+ }
51606+
51607+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
51608+ retval = -EPERM;
51609+ goto dput_out;
51610+ }
51611+
51612 if (flags & MS_REMOUNT)
51613 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
51614 data_page);
51615@@ -1976,6 +1992,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
51616 dev_name, data_page);
51617 dput_out:
51618 path_put(&path);
51619+
51620+ gr_log_mount(dev_name, dir_name, retval);
51621+
51622 return retval;
51623 }
51624
51625@@ -2182,6 +2201,12 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
51626 goto out1;
51627 }
51628
51629+ if (gr_handle_chroot_pivot()) {
51630+ error = -EPERM;
51631+ path_put(&old);
51632+ goto out1;
51633+ }
51634+
51635 read_lock(&current->fs->lock);
51636 root = current->fs->root;
51637 path_get(&current->fs->root);
51638diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
51639index b8b5b30..2bd9ccb 100644
51640--- a/fs/ncpfs/dir.c
51641+++ b/fs/ncpfs/dir.c
51642@@ -275,6 +275,8 @@ __ncp_lookup_validate(struct dentry *dentry)
51643 int res, val = 0, len;
51644 __u8 __name[NCP_MAXPATHLEN + 1];
51645
51646+ pax_track_stack();
51647+
51648 parent = dget_parent(dentry);
51649 dir = parent->d_inode;
51650
51651@@ -799,6 +801,8 @@ static struct dentry *ncp_lookup(struct inode *dir, struct dentry *dentry, struc
51652 int error, res, len;
51653 __u8 __name[NCP_MAXPATHLEN + 1];
51654
51655+ pax_track_stack();
51656+
51657 lock_kernel();
51658 error = -EIO;
51659 if (!ncp_conn_valid(server))
51660@@ -883,10 +887,12 @@ int ncp_create_new(struct inode *dir, struct dentry *dentry, int mode,
51661 int error, result, len;
51662 int opmode;
51663 __u8 __name[NCP_MAXPATHLEN + 1];
51664-
51665+
51666 PPRINTK("ncp_create_new: creating %s/%s, mode=%x\n",
51667 dentry->d_parent->d_name.name, dentry->d_name.name, mode);
51668
51669+ pax_track_stack();
51670+
51671 error = -EIO;
51672 lock_kernel();
51673 if (!ncp_conn_valid(server))
51674@@ -952,6 +958,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
51675 int error, len;
51676 __u8 __name[NCP_MAXPATHLEN + 1];
51677
51678+ pax_track_stack();
51679+
51680 DPRINTK("ncp_mkdir: making %s/%s\n",
51681 dentry->d_parent->d_name.name, dentry->d_name.name);
51682
51683@@ -960,6 +968,8 @@ static int ncp_mkdir(struct inode *dir, struct dentry *dentry, int mode)
51684 if (!ncp_conn_valid(server))
51685 goto out;
51686
51687+ pax_track_stack();
51688+
51689 ncp_age_dentry(server, dentry);
51690 len = sizeof(__name);
51691 error = ncp_io2vol(server, __name, &len, dentry->d_name.name,
51692@@ -1114,6 +1124,8 @@ static int ncp_rename(struct inode *old_dir, struct dentry *old_dentry,
51693 int old_len, new_len;
51694 __u8 __old_name[NCP_MAXPATHLEN + 1], __new_name[NCP_MAXPATHLEN + 1];
51695
51696+ pax_track_stack();
51697+
51698 DPRINTK("ncp_rename: %s/%s to %s/%s\n",
51699 old_dentry->d_parent->d_name.name, old_dentry->d_name.name,
51700 new_dentry->d_parent->d_name.name, new_dentry->d_name.name);
51701diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
51702index cf98da1..da890a9 100644
51703--- a/fs/ncpfs/inode.c
51704+++ b/fs/ncpfs/inode.c
51705@@ -445,6 +445,8 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
51706 #endif
51707 struct ncp_entry_info finfo;
51708
51709+ pax_track_stack();
51710+
51711 data.wdog_pid = NULL;
51712 server = kzalloc(sizeof(struct ncp_server), GFP_KERNEL);
51713 if (!server)
51714diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
51715index bfaef7b..e9d03ca 100644
51716--- a/fs/nfs/inode.c
51717+++ b/fs/nfs/inode.c
51718@@ -156,7 +156,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
51719 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
51720 nfsi->attrtimeo_timestamp = jiffies;
51721
51722- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
51723+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
51724 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
51725 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
51726 else
51727@@ -973,16 +973,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
51728 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
51729 }
51730
51731-static atomic_long_t nfs_attr_generation_counter;
51732+static atomic_long_unchecked_t nfs_attr_generation_counter;
51733
51734 static unsigned long nfs_read_attr_generation_counter(void)
51735 {
51736- return atomic_long_read(&nfs_attr_generation_counter);
51737+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
51738 }
51739
51740 unsigned long nfs_inc_attr_generation_counter(void)
51741 {
51742- return atomic_long_inc_return(&nfs_attr_generation_counter);
51743+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
51744 }
51745
51746 void nfs_fattr_init(struct nfs_fattr *fattr)
51747diff --git a/fs/nfsd/lockd.c b/fs/nfsd/lockd.c
51748index cc2f505..f6a236f 100644
51749--- a/fs/nfsd/lockd.c
51750+++ b/fs/nfsd/lockd.c
51751@@ -66,7 +66,7 @@ nlm_fclose(struct file *filp)
51752 fput(filp);
51753 }
51754
51755-static struct nlmsvc_binding nfsd_nlm_ops = {
51756+static const struct nlmsvc_binding nfsd_nlm_ops = {
51757 .fopen = nlm_fopen, /* open file for locking */
51758 .fclose = nlm_fclose, /* close file */
51759 };
51760diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
51761index cfc3391..dcc083a 100644
51762--- a/fs/nfsd/nfs4state.c
51763+++ b/fs/nfsd/nfs4state.c
51764@@ -3459,6 +3459,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
51765 unsigned int cmd;
51766 int err;
51767
51768+ pax_track_stack();
51769+
51770 dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
51771 (long long) lock->lk_offset,
51772 (long long) lock->lk_length);
51773diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
51774index 4a82a96..0d5fb49 100644
51775--- a/fs/nfsd/nfs4xdr.c
51776+++ b/fs/nfsd/nfs4xdr.c
51777@@ -1751,6 +1751,8 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
51778 struct nfsd4_compoundres *resp = rqstp->rq_resp;
51779 u32 minorversion = resp->cstate.minorversion;
51780
51781+ pax_track_stack();
51782+
51783 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
51784 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
51785 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
51786diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
51787index 2e09588..596421d 100644
51788--- a/fs/nfsd/vfs.c
51789+++ b/fs/nfsd/vfs.c
51790@@ -937,7 +937,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51791 } else {
51792 oldfs = get_fs();
51793 set_fs(KERNEL_DS);
51794- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
51795+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
51796 set_fs(oldfs);
51797 }
51798
51799@@ -1060,7 +1060,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51800
51801 /* Write the data. */
51802 oldfs = get_fs(); set_fs(KERNEL_DS);
51803- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
51804+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
51805 set_fs(oldfs);
51806 if (host_err < 0)
51807 goto out_nfserr;
51808@@ -1542,7 +1542,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
51809 */
51810
51811 oldfs = get_fs(); set_fs(KERNEL_DS);
51812- host_err = inode->i_op->readlink(dentry, buf, *lenp);
51813+ host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
51814 set_fs(oldfs);
51815
51816 if (host_err < 0)
51817diff --git a/fs/nilfs2/ioctl.c b/fs/nilfs2/ioctl.c
51818index f6af760..d6b2b83 100644
51819--- a/fs/nilfs2/ioctl.c
51820+++ b/fs/nilfs2/ioctl.c
51821@@ -480,7 +480,7 @@ static int nilfs_ioctl_clean_segments(struct inode *inode, struct file *filp,
51822 unsigned int cmd, void __user *argp)
51823 {
51824 struct nilfs_argv argv[5];
51825- const static size_t argsz[5] = {
51826+ static const size_t argsz[5] = {
51827 sizeof(struct nilfs_vdesc),
51828 sizeof(struct nilfs_period),
51829 sizeof(__u64),
51830diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c
51831index 7e54e52..9337248 100644
51832--- a/fs/notify/dnotify/dnotify.c
51833+++ b/fs/notify/dnotify/dnotify.c
51834@@ -173,7 +173,7 @@ static void dnotify_free_mark(struct fsnotify_mark_entry *entry)
51835 kmem_cache_free(dnotify_mark_entry_cache, dnentry);
51836 }
51837
51838-static struct fsnotify_ops dnotify_fsnotify_ops = {
51839+static const struct fsnotify_ops dnotify_fsnotify_ops = {
51840 .handle_event = dnotify_handle_event,
51841 .should_send_event = dnotify_should_send_event,
51842 .free_group_priv = NULL,
51843diff --git a/fs/notify/notification.c b/fs/notify/notification.c
51844index b8bf53b..c518688 100644
51845--- a/fs/notify/notification.c
51846+++ b/fs/notify/notification.c
51847@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
51848 * get set to 0 so it will never get 'freed'
51849 */
51850 static struct fsnotify_event q_overflow_event;
51851-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51852+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51853
51854 /**
51855 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
51856@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51857 */
51858 u32 fsnotify_get_cookie(void)
51859 {
51860- return atomic_inc_return(&fsnotify_sync_cookie);
51861+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
51862 }
51863 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
51864
51865diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
51866index 5a9e344..0f8cd28 100644
51867--- a/fs/ntfs/dir.c
51868+++ b/fs/ntfs/dir.c
51869@@ -1328,7 +1328,7 @@ find_next_index_buffer:
51870 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
51871 ~(s64)(ndir->itype.index.block_size - 1)));
51872 /* Bounds checks. */
51873- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51874+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51875 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
51876 "inode 0x%lx or driver bug.", vdir->i_ino);
51877 goto err_out;
51878diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
51879index 663c0e3..b6868e9 100644
51880--- a/fs/ntfs/file.c
51881+++ b/fs/ntfs/file.c
51882@@ -2243,6 +2243,6 @@ const struct inode_operations ntfs_file_inode_ops = {
51883 #endif /* NTFS_RW */
51884 };
51885
51886-const struct file_operations ntfs_empty_file_ops = {};
51887+const struct file_operations ntfs_empty_file_ops __read_only;
51888
51889-const struct inode_operations ntfs_empty_inode_ops = {};
51890+const struct inode_operations ntfs_empty_inode_ops __read_only;
51891diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
51892index 1cd2934..880b5d2 100644
51893--- a/fs/ocfs2/cluster/masklog.c
51894+++ b/fs/ocfs2/cluster/masklog.c
51895@@ -135,7 +135,7 @@ static ssize_t mlog_store(struct kobject *obj, struct attribute *attr,
51896 return mlog_mask_store(mlog_attr->mask, buf, count);
51897 }
51898
51899-static struct sysfs_ops mlog_attr_ops = {
51900+static const struct sysfs_ops mlog_attr_ops = {
51901 .show = mlog_show,
51902 .store = mlog_store,
51903 };
51904diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
51905index ac10f83..2cd2607 100644
51906--- a/fs/ocfs2/localalloc.c
51907+++ b/fs/ocfs2/localalloc.c
51908@@ -1188,7 +1188,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
51909 goto bail;
51910 }
51911
51912- atomic_inc(&osb->alloc_stats.moves);
51913+ atomic_inc_unchecked(&osb->alloc_stats.moves);
51914
51915 status = 0;
51916 bail:
51917diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
51918index f010b22..9f9ed34 100644
51919--- a/fs/ocfs2/namei.c
51920+++ b/fs/ocfs2/namei.c
51921@@ -1043,6 +1043,8 @@ static int ocfs2_rename(struct inode *old_dir,
51922 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
51923 struct ocfs2_dir_lookup_result target_insert = { NULL, };
51924
51925+ pax_track_stack();
51926+
51927 /* At some point it might be nice to break this function up a
51928 * bit. */
51929
51930diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
51931index d963d86..914cfbd 100644
51932--- a/fs/ocfs2/ocfs2.h
51933+++ b/fs/ocfs2/ocfs2.h
51934@@ -217,11 +217,11 @@ enum ocfs2_vol_state
51935
51936 struct ocfs2_alloc_stats
51937 {
51938- atomic_t moves;
51939- atomic_t local_data;
51940- atomic_t bitmap_data;
51941- atomic_t bg_allocs;
51942- atomic_t bg_extends;
51943+ atomic_unchecked_t moves;
51944+ atomic_unchecked_t local_data;
51945+ atomic_unchecked_t bitmap_data;
51946+ atomic_unchecked_t bg_allocs;
51947+ atomic_unchecked_t bg_extends;
51948 };
51949
51950 enum ocfs2_local_alloc_state
51951diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
51952index 79b5dac..d322952 100644
51953--- a/fs/ocfs2/suballoc.c
51954+++ b/fs/ocfs2/suballoc.c
51955@@ -623,7 +623,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
51956 mlog_errno(status);
51957 goto bail;
51958 }
51959- atomic_inc(&osb->alloc_stats.bg_extends);
51960+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
51961
51962 /* You should never ask for this much metadata */
51963 BUG_ON(bits_wanted >
51964@@ -1654,7 +1654,7 @@ int ocfs2_claim_metadata(struct ocfs2_super *osb,
51965 mlog_errno(status);
51966 goto bail;
51967 }
51968- atomic_inc(&osb->alloc_stats.bg_allocs);
51969+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
51970
51971 *blkno_start = bg_blkno + (u64) *suballoc_bit_start;
51972 ac->ac_bits_given += (*num_bits);
51973@@ -1728,7 +1728,7 @@ int ocfs2_claim_new_inode(struct ocfs2_super *osb,
51974 mlog_errno(status);
51975 goto bail;
51976 }
51977- atomic_inc(&osb->alloc_stats.bg_allocs);
51978+ atomic_inc_unchecked(&osb->alloc_stats.bg_allocs);
51979
51980 BUG_ON(num_bits != 1);
51981
51982@@ -1830,7 +1830,7 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb,
51983 cluster_start,
51984 num_clusters);
51985 if (!status)
51986- atomic_inc(&osb->alloc_stats.local_data);
51987+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
51988 } else {
51989 if (min_clusters > (osb->bitmap_cpg - 1)) {
51990 /* The only paths asking for contiguousness
51991@@ -1858,7 +1858,7 @@ int __ocfs2_claim_clusters(struct ocfs2_super *osb,
51992 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
51993 bg_blkno,
51994 bg_bit_off);
51995- atomic_inc(&osb->alloc_stats.bitmap_data);
51996+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
51997 }
51998 }
51999 if (status < 0) {
52000diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
52001index 9f55be4..a3f8048 100644
52002--- a/fs/ocfs2/super.c
52003+++ b/fs/ocfs2/super.c
52004@@ -284,11 +284,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
52005 "%10s => GlobalAllocs: %d LocalAllocs: %d "
52006 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
52007 "Stats",
52008- atomic_read(&osb->alloc_stats.bitmap_data),
52009- atomic_read(&osb->alloc_stats.local_data),
52010- atomic_read(&osb->alloc_stats.bg_allocs),
52011- atomic_read(&osb->alloc_stats.moves),
52012- atomic_read(&osb->alloc_stats.bg_extends));
52013+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
52014+ atomic_read_unchecked(&osb->alloc_stats.local_data),
52015+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
52016+ atomic_read_unchecked(&osb->alloc_stats.moves),
52017+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
52018
52019 out += snprintf(buf + out, len - out,
52020 "%10s => State: %u Descriptor: %llu Size: %u bits "
52021@@ -2002,11 +2002,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
52022 spin_lock_init(&osb->osb_xattr_lock);
52023 ocfs2_init_inode_steal_slot(osb);
52024
52025- atomic_set(&osb->alloc_stats.moves, 0);
52026- atomic_set(&osb->alloc_stats.local_data, 0);
52027- atomic_set(&osb->alloc_stats.bitmap_data, 0);
52028- atomic_set(&osb->alloc_stats.bg_allocs, 0);
52029- atomic_set(&osb->alloc_stats.bg_extends, 0);
52030+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
52031+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
52032+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
52033+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
52034+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
52035
52036 /* Copy the blockcheck stats from the superblock probe */
52037 osb->osb_ecc_stats = *stats;
52038diff --git a/fs/open.c b/fs/open.c
52039index 4f01e06..091f6c3 100644
52040--- a/fs/open.c
52041+++ b/fs/open.c
52042@@ -275,6 +275,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
52043 error = locks_verify_truncate(inode, NULL, length);
52044 if (!error)
52045 error = security_path_truncate(&path, length, 0);
52046+
52047+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
52048+ error = -EACCES;
52049+
52050 if (!error) {
52051 vfs_dq_init(inode);
52052 error = do_truncate(path.dentry, length, 0, NULL);
52053@@ -511,6 +515,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
52054 if (__mnt_is_readonly(path.mnt))
52055 res = -EROFS;
52056
52057+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
52058+ res = -EACCES;
52059+
52060 out_path_release:
52061 path_put(&path);
52062 out:
52063@@ -537,6 +544,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
52064 if (error)
52065 goto dput_and_out;
52066
52067+ gr_log_chdir(path.dentry, path.mnt);
52068+
52069 set_fs_pwd(current->fs, &path);
52070
52071 dput_and_out:
52072@@ -563,6 +572,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
52073 goto out_putf;
52074
52075 error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
52076+
52077+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
52078+ error = -EPERM;
52079+
52080+ if (!error)
52081+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
52082+
52083 if (!error)
52084 set_fs_pwd(current->fs, &file->f_path);
52085 out_putf:
52086@@ -588,7 +604,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
52087 if (!capable(CAP_SYS_CHROOT))
52088 goto dput_and_out;
52089
52090+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
52091+ goto dput_and_out;
52092+
52093 set_fs_root(current->fs, &path);
52094+
52095+ gr_handle_chroot_chdir(&path);
52096+
52097 error = 0;
52098 dput_and_out:
52099 path_put(&path);
52100@@ -616,12 +638,27 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
52101 err = mnt_want_write_file(file);
52102 if (err)
52103 goto out_putf;
52104+
52105 mutex_lock(&inode->i_mutex);
52106+
52107+ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
52108+ err = -EACCES;
52109+ goto out_unlock;
52110+ }
52111+
52112 if (mode == (mode_t) -1)
52113 mode = inode->i_mode;
52114+
52115+ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
52116+ err = -EPERM;
52117+ goto out_unlock;
52118+ }
52119+
52120 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
52121 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
52122 err = notify_change(dentry, &newattrs);
52123+
52124+out_unlock:
52125 mutex_unlock(&inode->i_mutex);
52126 mnt_drop_write(file->f_path.mnt);
52127 out_putf:
52128@@ -645,12 +682,27 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode)
52129 error = mnt_want_write(path.mnt);
52130 if (error)
52131 goto dput_and_out;
52132+
52133 mutex_lock(&inode->i_mutex);
52134+
52135+ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
52136+ error = -EACCES;
52137+ goto out_unlock;
52138+ }
52139+
52140 if (mode == (mode_t) -1)
52141 mode = inode->i_mode;
52142+
52143+ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
52144+ error = -EACCES;
52145+ goto out_unlock;
52146+ }
52147+
52148 newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
52149 newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
52150 error = notify_change(path.dentry, &newattrs);
52151+
52152+out_unlock:
52153 mutex_unlock(&inode->i_mutex);
52154 mnt_drop_write(path.mnt);
52155 dput_and_out:
52156@@ -664,12 +716,15 @@ SYSCALL_DEFINE2(chmod, const char __user *, filename, mode_t, mode)
52157 return sys_fchmodat(AT_FDCWD, filename, mode);
52158 }
52159
52160-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
52161+static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
52162 {
52163 struct inode *inode = dentry->d_inode;
52164 int error;
52165 struct iattr newattrs;
52166
52167+ if (!gr_acl_handle_chown(dentry, mnt))
52168+ return -EACCES;
52169+
52170 newattrs.ia_valid = ATTR_CTIME;
52171 if (user != (uid_t) -1) {
52172 newattrs.ia_valid |= ATTR_UID;
52173@@ -700,7 +755,7 @@ SYSCALL_DEFINE3(chown, const char __user *, filename, uid_t, user, gid_t, group)
52174 error = mnt_want_write(path.mnt);
52175 if (error)
52176 goto out_release;
52177- error = chown_common(path.dentry, user, group);
52178+ error = chown_common(path.dentry, user, group, path.mnt);
52179 mnt_drop_write(path.mnt);
52180 out_release:
52181 path_put(&path);
52182@@ -725,7 +780,7 @@ SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user,
52183 error = mnt_want_write(path.mnt);
52184 if (error)
52185 goto out_release;
52186- error = chown_common(path.dentry, user, group);
52187+ error = chown_common(path.dentry, user, group, path.mnt);
52188 mnt_drop_write(path.mnt);
52189 out_release:
52190 path_put(&path);
52191@@ -744,7 +799,7 @@ SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group
52192 error = mnt_want_write(path.mnt);
52193 if (error)
52194 goto out_release;
52195- error = chown_common(path.dentry, user, group);
52196+ error = chown_common(path.dentry, user, group, path.mnt);
52197 mnt_drop_write(path.mnt);
52198 out_release:
52199 path_put(&path);
52200@@ -767,7 +822,7 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
52201 goto out_fput;
52202 dentry = file->f_path.dentry;
52203 audit_inode(NULL, dentry);
52204- error = chown_common(dentry, user, group);
52205+ error = chown_common(dentry, user, group, file->f_path.mnt);
52206 mnt_drop_write(file->f_path.mnt);
52207 out_fput:
52208 fput(file);
52209@@ -1036,7 +1091,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, int mode)
52210 if (!IS_ERR(tmp)) {
52211 fd = get_unused_fd_flags(flags);
52212 if (fd >= 0) {
52213- struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
52214+ struct file *f = do_filp_open(dfd, tmp, flags, mode, 0);
52215 if (IS_ERR(f)) {
52216 put_unused_fd(fd);
52217 fd = PTR_ERR(f);
52218diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
52219index 6ab70f4..f4103d1 100644
52220--- a/fs/partitions/efi.c
52221+++ b/fs/partitions/efi.c
52222@@ -231,14 +231,14 @@ alloc_read_gpt_entries(struct block_device *bdev, gpt_header *gpt)
52223 if (!bdev || !gpt)
52224 return NULL;
52225
52226+ if (!le32_to_cpu(gpt->num_partition_entries))
52227+ return NULL;
52228+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
52229+ if (!pte)
52230+ return NULL;
52231+
52232 count = le32_to_cpu(gpt->num_partition_entries) *
52233 le32_to_cpu(gpt->sizeof_partition_entry);
52234- if (!count)
52235- return NULL;
52236- pte = kzalloc(count, GFP_KERNEL);
52237- if (!pte)
52238- return NULL;
52239-
52240 if (read_lba(bdev, le64_to_cpu(gpt->partition_entry_lba),
52241 (u8 *) pte,
52242 count) < count) {
52243diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
52244index dd6efdb..3babc6c 100644
52245--- a/fs/partitions/ldm.c
52246+++ b/fs/partitions/ldm.c
52247@@ -1311,6 +1311,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
52248 ldm_error ("A VBLK claims to have %d parts.", num);
52249 return false;
52250 }
52251+
52252 if (rec >= num) {
52253 ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num);
52254 return false;
52255@@ -1322,7 +1323,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
52256 goto found;
52257 }
52258
52259- f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
52260+ f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
52261 if (!f) {
52262 ldm_crit ("Out of memory.");
52263 return false;
52264diff --git a/fs/partitions/mac.c b/fs/partitions/mac.c
52265index 5765198..7f8e9e0 100644
52266--- a/fs/partitions/mac.c
52267+++ b/fs/partitions/mac.c
52268@@ -59,11 +59,11 @@ int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
52269 return 0; /* not a MacOS disk */
52270 }
52271 blocks_in_map = be32_to_cpu(part->map_count);
52272- if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
52273- put_dev_sector(sect);
52274- return 0;
52275- }
52276 printk(" [mac]");
52277+ if (blocks_in_map < 0 || blocks_in_map >= DISK_MAX_PARTS) {
52278+ put_dev_sector(sect);
52279+ return 0;
52280+ }
52281 for (slot = 1; slot <= blocks_in_map; ++slot) {
52282 int pos = slot * secsize;
52283 put_dev_sector(sect);
52284diff --git a/fs/pipe.c b/fs/pipe.c
52285index d0cc080..8a6f211 100644
52286--- a/fs/pipe.c
52287+++ b/fs/pipe.c
52288@@ -401,9 +401,9 @@ redo:
52289 }
52290 if (bufs) /* More to do? */
52291 continue;
52292- if (!pipe->writers)
52293+ if (!atomic_read(&pipe->writers))
52294 break;
52295- if (!pipe->waiting_writers) {
52296+ if (!atomic_read(&pipe->waiting_writers)) {
52297 /* syscall merging: Usually we must not sleep
52298 * if O_NONBLOCK is set, or if we got some data.
52299 * But if a writer sleeps in kernel space, then
52300@@ -462,7 +462,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
52301 mutex_lock(&inode->i_mutex);
52302 pipe = inode->i_pipe;
52303
52304- if (!pipe->readers) {
52305+ if (!atomic_read(&pipe->readers)) {
52306 send_sig(SIGPIPE, current, 0);
52307 ret = -EPIPE;
52308 goto out;
52309@@ -511,7 +511,7 @@ redo1:
52310 for (;;) {
52311 int bufs;
52312
52313- if (!pipe->readers) {
52314+ if (!atomic_read(&pipe->readers)) {
52315 send_sig(SIGPIPE, current, 0);
52316 if (!ret)
52317 ret = -EPIPE;
52318@@ -597,9 +597,9 @@ redo2:
52319 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
52320 do_wakeup = 0;
52321 }
52322- pipe->waiting_writers++;
52323+ atomic_inc(&pipe->waiting_writers);
52324 pipe_wait(pipe);
52325- pipe->waiting_writers--;
52326+ atomic_dec(&pipe->waiting_writers);
52327 }
52328 out:
52329 mutex_unlock(&inode->i_mutex);
52330@@ -666,7 +666,7 @@ pipe_poll(struct file *filp, poll_table *wait)
52331 mask = 0;
52332 if (filp->f_mode & FMODE_READ) {
52333 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
52334- if (!pipe->writers && filp->f_version != pipe->w_counter)
52335+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
52336 mask |= POLLHUP;
52337 }
52338
52339@@ -676,7 +676,7 @@ pipe_poll(struct file *filp, poll_table *wait)
52340 * Most Unices do not set POLLERR for FIFOs but on Linux they
52341 * behave exactly like pipes for poll().
52342 */
52343- if (!pipe->readers)
52344+ if (!atomic_read(&pipe->readers))
52345 mask |= POLLERR;
52346 }
52347
52348@@ -690,10 +690,10 @@ pipe_release(struct inode *inode, int decr, int decw)
52349
52350 mutex_lock(&inode->i_mutex);
52351 pipe = inode->i_pipe;
52352- pipe->readers -= decr;
52353- pipe->writers -= decw;
52354+ atomic_sub(decr, &pipe->readers);
52355+ atomic_sub(decw, &pipe->writers);
52356
52357- if (!pipe->readers && !pipe->writers) {
52358+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
52359 free_pipe_info(inode);
52360 } else {
52361 wake_up_interruptible_sync(&pipe->wait);
52362@@ -783,7 +783,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
52363
52364 if (inode->i_pipe) {
52365 ret = 0;
52366- inode->i_pipe->readers++;
52367+ atomic_inc(&inode->i_pipe->readers);
52368 }
52369
52370 mutex_unlock(&inode->i_mutex);
52371@@ -800,7 +800,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
52372
52373 if (inode->i_pipe) {
52374 ret = 0;
52375- inode->i_pipe->writers++;
52376+ atomic_inc(&inode->i_pipe->writers);
52377 }
52378
52379 mutex_unlock(&inode->i_mutex);
52380@@ -818,9 +818,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
52381 if (inode->i_pipe) {
52382 ret = 0;
52383 if (filp->f_mode & FMODE_READ)
52384- inode->i_pipe->readers++;
52385+ atomic_inc(&inode->i_pipe->readers);
52386 if (filp->f_mode & FMODE_WRITE)
52387- inode->i_pipe->writers++;
52388+ atomic_inc(&inode->i_pipe->writers);
52389 }
52390
52391 mutex_unlock(&inode->i_mutex);
52392@@ -905,7 +905,7 @@ void free_pipe_info(struct inode *inode)
52393 inode->i_pipe = NULL;
52394 }
52395
52396-static struct vfsmount *pipe_mnt __read_mostly;
52397+struct vfsmount *pipe_mnt __read_mostly;
52398 static int pipefs_delete_dentry(struct dentry *dentry)
52399 {
52400 /*
52401@@ -945,7 +945,8 @@ static struct inode * get_pipe_inode(void)
52402 goto fail_iput;
52403 inode->i_pipe = pipe;
52404
52405- pipe->readers = pipe->writers = 1;
52406+ atomic_set(&pipe->readers, 1);
52407+ atomic_set(&pipe->writers, 1);
52408 inode->i_fop = &rdwr_pipefifo_fops;
52409
52410 /*
52411diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
52412index 50f8f06..c5755df 100644
52413--- a/fs/proc/Kconfig
52414+++ b/fs/proc/Kconfig
52415@@ -30,12 +30,12 @@ config PROC_FS
52416
52417 config PROC_KCORE
52418 bool "/proc/kcore support" if !ARM
52419- depends on PROC_FS && MMU
52420+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
52421
52422 config PROC_VMCORE
52423 bool "/proc/vmcore support (EXPERIMENTAL)"
52424- depends on PROC_FS && CRASH_DUMP
52425- default y
52426+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
52427+ default n
52428 help
52429 Exports the dump image of crashed kernel in ELF format.
52430
52431@@ -59,8 +59,8 @@ config PROC_SYSCTL
52432 limited in memory.
52433
52434 config PROC_PAGE_MONITOR
52435- default y
52436- depends on PROC_FS && MMU
52437+ default n
52438+ depends on PROC_FS && MMU && !GRKERNSEC
52439 bool "Enable /proc page monitoring" if EMBEDDED
52440 help
52441 Various /proc files exist to monitor process memory utilization:
52442diff --git a/fs/proc/array.c b/fs/proc/array.c
52443index c5ef152..1363194 100644
52444--- a/fs/proc/array.c
52445+++ b/fs/proc/array.c
52446@@ -60,6 +60,7 @@
52447 #include <linux/tty.h>
52448 #include <linux/string.h>
52449 #include <linux/mman.h>
52450+#include <linux/grsecurity.h>
52451 #include <linux/proc_fs.h>
52452 #include <linux/ioport.h>
52453 #include <linux/uaccess.h>
52454@@ -321,6 +322,21 @@ static inline void task_context_switch_counts(struct seq_file *m,
52455 p->nivcsw);
52456 }
52457
52458+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52459+static inline void task_pax(struct seq_file *m, struct task_struct *p)
52460+{
52461+ if (p->mm)
52462+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
52463+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
52464+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
52465+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
52466+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
52467+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
52468+ else
52469+ seq_printf(m, "PaX:\t-----\n");
52470+}
52471+#endif
52472+
52473 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52474 struct pid *pid, struct task_struct *task)
52475 {
52476@@ -337,9 +353,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52477 task_cap(m, task);
52478 cpuset_task_status_allowed(m, task);
52479 task_context_switch_counts(m, task);
52480+
52481+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52482+ task_pax(m, task);
52483+#endif
52484+
52485+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
52486+ task_grsec_rbac(m, task);
52487+#endif
52488+
52489 return 0;
52490 }
52491
52492+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52493+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52494+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52495+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52496+#endif
52497+
52498 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52499 struct pid *pid, struct task_struct *task, int whole)
52500 {
52501@@ -358,9 +389,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52502 cputime_t cutime, cstime, utime, stime;
52503 cputime_t cgtime, gtime;
52504 unsigned long rsslim = 0;
52505- char tcomm[sizeof(task->comm)];
52506+ char tcomm[sizeof(task->comm)] = { 0 };
52507 unsigned long flags;
52508
52509+ pax_track_stack();
52510+
52511 state = *get_task_state(task);
52512 vsize = eip = esp = 0;
52513 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
52514@@ -433,6 +466,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52515 gtime = task_gtime(task);
52516 }
52517
52518+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52519+ if (PAX_RAND_FLAGS(mm)) {
52520+ eip = 0;
52521+ esp = 0;
52522+ wchan = 0;
52523+ }
52524+#endif
52525+#ifdef CONFIG_GRKERNSEC_HIDESYM
52526+ wchan = 0;
52527+ eip =0;
52528+ esp =0;
52529+#endif
52530+
52531 /* scale priority and nice values from timeslices to -20..20 */
52532 /* to make it look like a "normal" Unix priority/nice value */
52533 priority = task_prio(task);
52534@@ -473,9 +519,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
52535 vsize,
52536 mm ? get_mm_rss(mm) : 0,
52537 rsslim,
52538+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52539+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
52540+ PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
52541+ PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
52542+#else
52543 mm ? (permitted ? mm->start_code : 1) : 0,
52544 mm ? (permitted ? mm->end_code : 1) : 0,
52545 (permitted && mm) ? mm->start_stack : 0,
52546+#endif
52547 esp,
52548 eip,
52549 /* The signal information here is obsolete.
52550@@ -528,3 +580,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52551
52552 return 0;
52553 }
52554+
52555+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52556+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
52557+{
52558+ u32 curr_ip = 0;
52559+ unsigned long flags;
52560+
52561+ if (lock_task_sighand(task, &flags)) {
52562+ curr_ip = task->signal->curr_ip;
52563+ unlock_task_sighand(task, &flags);
52564+ }
52565+
52566+ return sprintf(buffer, "%pI4\n", &curr_ip);
52567+}
52568+#endif
52569diff --git a/fs/proc/base.c b/fs/proc/base.c
52570index 67f7dc0..e95ea4f 100644
52571--- a/fs/proc/base.c
52572+++ b/fs/proc/base.c
52573@@ -102,6 +102,22 @@ struct pid_entry {
52574 union proc_op op;
52575 };
52576
52577+struct getdents_callback {
52578+ struct linux_dirent __user * current_dir;
52579+ struct linux_dirent __user * previous;
52580+ struct file * file;
52581+ int count;
52582+ int error;
52583+};
52584+
52585+static int gr_fake_filldir(void * __buf, const char *name, int namlen,
52586+ loff_t offset, u64 ino, unsigned int d_type)
52587+{
52588+ struct getdents_callback * buf = (struct getdents_callback *) __buf;
52589+ buf->error = -EINVAL;
52590+ return 0;
52591+}
52592+
52593 #define NOD(NAME, MODE, IOP, FOP, OP) { \
52594 .name = (NAME), \
52595 .len = sizeof(NAME) - 1, \
52596@@ -213,6 +229,9 @@ static int check_mem_permission(struct task_struct *task)
52597 if (task == current)
52598 return 0;
52599
52600+ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
52601+ return -EPERM;
52602+
52603 /*
52604 * If current is actively ptrace'ing, and would also be
52605 * permitted to freshly attach with ptrace now, permit it.
52606@@ -260,6 +279,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
52607 if (!mm->arg_end)
52608 goto out_mm; /* Shh! No looking before we're done */
52609
52610+ if (gr_acl_handle_procpidmem(task))
52611+ goto out_mm;
52612+
52613 len = mm->arg_end - mm->arg_start;
52614
52615 if (len > PAGE_SIZE)
52616@@ -287,12 +309,28 @@ out:
52617 return res;
52618 }
52619
52620+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52621+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52622+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
52623+ _mm->pax_flags & MF_PAX_SEGMEXEC))
52624+#endif
52625+
52626 static int proc_pid_auxv(struct task_struct *task, char *buffer)
52627 {
52628 int res = 0;
52629 struct mm_struct *mm = get_task_mm(task);
52630 if (mm) {
52631 unsigned int nwords = 0;
52632+
52633+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52634+ /* allow if we're currently ptracing this task */
52635+ if (PAX_RAND_FLAGS(mm) &&
52636+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
52637+ mmput(mm);
52638+ return 0;
52639+ }
52640+#endif
52641+
52642 do {
52643 nwords += 2;
52644 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
52645@@ -306,7 +344,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
52646 }
52647
52648
52649-#ifdef CONFIG_KALLSYMS
52650+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52651 /*
52652 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
52653 * Returns the resolved symbol. If that fails, simply return the address.
52654@@ -345,7 +383,7 @@ static void unlock_trace(struct task_struct *task)
52655 mutex_unlock(&task->cred_guard_mutex);
52656 }
52657
52658-#ifdef CONFIG_STACKTRACE
52659+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52660
52661 #define MAX_STACK_TRACE_DEPTH 64
52662
52663@@ -545,7 +583,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
52664 return count;
52665 }
52666
52667-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52668+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52669 static int proc_pid_syscall(struct task_struct *task, char *buffer)
52670 {
52671 long nr;
52672@@ -574,7 +612,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
52673 /************************************************************************/
52674
52675 /* permission checks */
52676-static int proc_fd_access_allowed(struct inode *inode)
52677+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
52678 {
52679 struct task_struct *task;
52680 int allowed = 0;
52681@@ -584,7 +622,10 @@ static int proc_fd_access_allowed(struct inode *inode)
52682 */
52683 task = get_proc_task(inode);
52684 if (task) {
52685- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
52686+ if (log)
52687+ allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
52688+ else
52689+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
52690 put_task_struct(task);
52691 }
52692 return allowed;
52693@@ -963,6 +1004,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
52694 if (!task)
52695 goto out_no_task;
52696
52697+ if (gr_acl_handle_procpidmem(task))
52698+ goto out;
52699+
52700 if (!ptrace_may_access(task, PTRACE_MODE_READ))
52701 goto out;
52702
52703@@ -1377,7 +1421,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
52704 path_put(&nd->path);
52705
52706 /* Are we allowed to snoop on the tasks file descriptors? */
52707- if (!proc_fd_access_allowed(inode))
52708+ if (!proc_fd_access_allowed(inode,0))
52709 goto out;
52710
52711 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
52712@@ -1417,8 +1461,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
52713 struct path path;
52714
52715 /* Are we allowed to snoop on the tasks file descriptors? */
52716- if (!proc_fd_access_allowed(inode))
52717- goto out;
52718+ /* logging this is needed for learning on chromium to work properly,
52719+ but we don't want to flood the logs from 'ps' which does a readlink
52720+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
52721+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
52722+ */
52723+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
52724+ if (!proc_fd_access_allowed(inode,0))
52725+ goto out;
52726+ } else {
52727+ if (!proc_fd_access_allowed(inode,1))
52728+ goto out;
52729+ }
52730
52731 error = PROC_I(inode)->op.proc_get_link(inode, &path);
52732 if (error)
52733@@ -1483,7 +1537,11 @@ static struct inode *proc_pid_make_inode(struct super_block * sb, struct task_st
52734 rcu_read_lock();
52735 cred = __task_cred(task);
52736 inode->i_uid = cred->euid;
52737+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52738+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52739+#else
52740 inode->i_gid = cred->egid;
52741+#endif
52742 rcu_read_unlock();
52743 }
52744 security_task_to_inode(task, inode);
52745@@ -1501,6 +1559,9 @@ static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat
52746 struct inode *inode = dentry->d_inode;
52747 struct task_struct *task;
52748 const struct cred *cred;
52749+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52750+ const struct cred *tmpcred = current_cred();
52751+#endif
52752
52753 generic_fillattr(inode, stat);
52754
52755@@ -1508,13 +1569,41 @@ static int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat
52756 stat->uid = 0;
52757 stat->gid = 0;
52758 task = pid_task(proc_pid(inode), PIDTYPE_PID);
52759+
52760+ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
52761+ rcu_read_unlock();
52762+ return -ENOENT;
52763+ }
52764+
52765 if (task) {
52766+ cred = __task_cred(task);
52767+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52768+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
52769+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52770+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
52771+#endif
52772+ ) {
52773+#endif
52774 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
52775+#ifdef CONFIG_GRKERNSEC_PROC_USER
52776+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
52777+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52778+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
52779+#endif
52780 task_dumpable(task)) {
52781- cred = __task_cred(task);
52782 stat->uid = cred->euid;
52783+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52784+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
52785+#else
52786 stat->gid = cred->egid;
52787+#endif
52788 }
52789+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52790+ } else {
52791+ rcu_read_unlock();
52792+ return -ENOENT;
52793+ }
52794+#endif
52795 }
52796 rcu_read_unlock();
52797 return 0;
52798@@ -1545,11 +1634,20 @@ static int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
52799
52800 if (task) {
52801 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
52802+#ifdef CONFIG_GRKERNSEC_PROC_USER
52803+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
52804+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52805+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
52806+#endif
52807 task_dumpable(task)) {
52808 rcu_read_lock();
52809 cred = __task_cred(task);
52810 inode->i_uid = cred->euid;
52811+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52812+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52813+#else
52814 inode->i_gid = cred->egid;
52815+#endif
52816 rcu_read_unlock();
52817 } else {
52818 inode->i_uid = 0;
52819@@ -1670,7 +1768,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
52820 int fd = proc_fd(inode);
52821
52822 if (task) {
52823- files = get_files_struct(task);
52824+ if (!gr_acl_handle_procpidmem(task))
52825+ files = get_files_struct(task);
52826 put_task_struct(task);
52827 }
52828 if (files) {
52829@@ -1922,12 +2021,22 @@ static const struct file_operations proc_fd_operations = {
52830 static int proc_fd_permission(struct inode *inode, int mask)
52831 {
52832 int rv;
52833+ struct task_struct *task;
52834
52835 rv = generic_permission(inode, mask, NULL);
52836- if (rv == 0)
52837- return 0;
52838+
52839 if (task_pid(current) == proc_pid(inode))
52840 rv = 0;
52841+
52842+ task = get_proc_task(inode);
52843+ if (task == NULL)
52844+ return rv;
52845+
52846+ if (gr_acl_handle_procpidmem(task))
52847+ rv = -EACCES;
52848+
52849+ put_task_struct(task);
52850+
52851 return rv;
52852 }
52853
52854@@ -2036,6 +2145,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
52855 if (!task)
52856 goto out_no_task;
52857
52858+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52859+ goto out;
52860+
52861 /*
52862 * Yes, it does not scale. And it should not. Don't add
52863 * new entries into /proc/<tgid>/ without very good reasons.
52864@@ -2080,6 +2192,9 @@ static int proc_pident_readdir(struct file *filp,
52865 if (!task)
52866 goto out_no_task;
52867
52868+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52869+ goto out;
52870+
52871 ret = 0;
52872 i = filp->f_pos;
52873 switch (i) {
52874@@ -2347,7 +2462,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
52875 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
52876 void *cookie)
52877 {
52878- char *s = nd_get_link(nd);
52879+ const char *s = nd_get_link(nd);
52880 if (!IS_ERR(s))
52881 __putname(s);
52882 }
52883@@ -2553,7 +2668,7 @@ static const struct pid_entry tgid_base_stuff[] = {
52884 #ifdef CONFIG_SCHED_DEBUG
52885 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52886 #endif
52887-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52888+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52889 INF("syscall", S_IRUGO, proc_pid_syscall),
52890 #endif
52891 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52892@@ -2578,10 +2693,10 @@ static const struct pid_entry tgid_base_stuff[] = {
52893 #ifdef CONFIG_SECURITY
52894 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52895 #endif
52896-#ifdef CONFIG_KALLSYMS
52897+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52898 INF("wchan", S_IRUGO, proc_pid_wchan),
52899 #endif
52900-#ifdef CONFIG_STACKTRACE
52901+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52902 ONE("stack", S_IRUGO, proc_pid_stack),
52903 #endif
52904 #ifdef CONFIG_SCHEDSTATS
52905@@ -2611,6 +2726,9 @@ static const struct pid_entry tgid_base_stuff[] = {
52906 #ifdef CONFIG_TASK_IO_ACCOUNTING
52907 INF("io", S_IRUSR, proc_tgid_io_accounting),
52908 #endif
52909+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52910+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
52911+#endif
52912 };
52913
52914 static int proc_tgid_base_readdir(struct file * filp,
52915@@ -2735,7 +2853,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
52916 if (!inode)
52917 goto out;
52918
52919+#ifdef CONFIG_GRKERNSEC_PROC_USER
52920+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
52921+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52922+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
52923+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
52924+#else
52925 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
52926+#endif
52927 inode->i_op = &proc_tgid_base_inode_operations;
52928 inode->i_fop = &proc_tgid_base_operations;
52929 inode->i_flags|=S_IMMUTABLE;
52930@@ -2777,7 +2902,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
52931 if (!task)
52932 goto out;
52933
52934+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52935+ goto out_put_task;
52936+
52937 result = proc_pid_instantiate(dir, dentry, task, NULL);
52938+out_put_task:
52939 put_task_struct(task);
52940 out:
52941 return result;
52942@@ -2842,6 +2971,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
52943 {
52944 unsigned int nr;
52945 struct task_struct *reaper;
52946+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52947+ const struct cred *tmpcred = current_cred();
52948+ const struct cred *itercred;
52949+#endif
52950+ filldir_t __filldir = filldir;
52951 struct tgid_iter iter;
52952 struct pid_namespace *ns;
52953
52954@@ -2865,8 +2999,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
52955 for (iter = next_tgid(ns, iter);
52956 iter.task;
52957 iter.tgid += 1, iter = next_tgid(ns, iter)) {
52958+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52959+ rcu_read_lock();
52960+ itercred = __task_cred(iter.task);
52961+#endif
52962+ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
52963+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52964+ || (tmpcred->uid && (itercred->uid != tmpcred->uid)
52965+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52966+ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
52967+#endif
52968+ )
52969+#endif
52970+ )
52971+ __filldir = &gr_fake_filldir;
52972+ else
52973+ __filldir = filldir;
52974+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52975+ rcu_read_unlock();
52976+#endif
52977 filp->f_pos = iter.tgid + TGID_OFFSET;
52978- if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
52979+ if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
52980 put_task_struct(iter.task);
52981 goto out;
52982 }
52983@@ -2892,7 +3045,7 @@ static const struct pid_entry tid_base_stuff[] = {
52984 #ifdef CONFIG_SCHED_DEBUG
52985 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52986 #endif
52987-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52988+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52989 INF("syscall", S_IRUGO, proc_pid_syscall),
52990 #endif
52991 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52992@@ -2916,10 +3069,10 @@ static const struct pid_entry tid_base_stuff[] = {
52993 #ifdef CONFIG_SECURITY
52994 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52995 #endif
52996-#ifdef CONFIG_KALLSYMS
52997+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52998 INF("wchan", S_IRUGO, proc_pid_wchan),
52999 #endif
53000-#ifdef CONFIG_STACKTRACE
53001+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53002 ONE("stack", S_IRUGO, proc_pid_stack),
53003 #endif
53004 #ifdef CONFIG_SCHEDSTATS
53005diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
53006index 82676e3..5f8518a 100644
53007--- a/fs/proc/cmdline.c
53008+++ b/fs/proc/cmdline.c
53009@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
53010
53011 static int __init proc_cmdline_init(void)
53012 {
53013+#ifdef CONFIG_GRKERNSEC_PROC_ADD
53014+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
53015+#else
53016 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
53017+#endif
53018 return 0;
53019 }
53020 module_init(proc_cmdline_init);
53021diff --git a/fs/proc/devices.c b/fs/proc/devices.c
53022index 59ee7da..469b4b6 100644
53023--- a/fs/proc/devices.c
53024+++ b/fs/proc/devices.c
53025@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
53026
53027 static int __init proc_devices_init(void)
53028 {
53029+#ifdef CONFIG_GRKERNSEC_PROC_ADD
53030+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
53031+#else
53032 proc_create("devices", 0, NULL, &proc_devinfo_operations);
53033+#endif
53034 return 0;
53035 }
53036 module_init(proc_devices_init);
53037diff --git a/fs/proc/inode.c b/fs/proc/inode.c
53038index d78ade3..81767f9 100644
53039--- a/fs/proc/inode.c
53040+++ b/fs/proc/inode.c
53041@@ -18,12 +18,19 @@
53042 #include <linux/module.h>
53043 #include <linux/smp_lock.h>
53044 #include <linux/sysctl.h>
53045+#include <linux/grsecurity.h>
53046
53047 #include <asm/system.h>
53048 #include <asm/uaccess.h>
53049
53050 #include "internal.h"
53051
53052+#ifdef CONFIG_PROC_SYSCTL
53053+extern const struct inode_operations proc_sys_inode_operations;
53054+extern const struct inode_operations proc_sys_dir_operations;
53055+#endif
53056+
53057+
53058 struct proc_dir_entry *de_get(struct proc_dir_entry *de)
53059 {
53060 atomic_inc(&de->count);
53061@@ -62,6 +69,13 @@ static void proc_delete_inode(struct inode *inode)
53062 de_put(de);
53063 if (PROC_I(inode)->sysctl)
53064 sysctl_head_put(PROC_I(inode)->sysctl);
53065+
53066+#ifdef CONFIG_PROC_SYSCTL
53067+ if (inode->i_op == &proc_sys_inode_operations ||
53068+ inode->i_op == &proc_sys_dir_operations)
53069+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
53070+#endif
53071+
53072 clear_inode(inode);
53073 }
53074
53075@@ -457,7 +471,11 @@ struct inode *proc_get_inode(struct super_block *sb, unsigned int ino,
53076 if (de->mode) {
53077 inode->i_mode = de->mode;
53078 inode->i_uid = de->uid;
53079+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
53080+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
53081+#else
53082 inode->i_gid = de->gid;
53083+#endif
53084 }
53085 if (de->size)
53086 inode->i_size = de->size;
53087diff --git a/fs/proc/internal.h b/fs/proc/internal.h
53088index 753ca37..26bcf3b 100644
53089--- a/fs/proc/internal.h
53090+++ b/fs/proc/internal.h
53091@@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53092 struct pid *pid, struct task_struct *task);
53093 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53094 struct pid *pid, struct task_struct *task);
53095+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
53096+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
53097+#endif
53098 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
53099
53100 extern const struct file_operations proc_maps_operations;
53101diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
53102index b442dac..aab29cb 100644
53103--- a/fs/proc/kcore.c
53104+++ b/fs/proc/kcore.c
53105@@ -320,6 +320,8 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
53106 off_t offset = 0;
53107 struct kcore_list *m;
53108
53109+ pax_track_stack();
53110+
53111 /* setup ELF header */
53112 elf = (struct elfhdr *) bufp;
53113 bufp += sizeof(struct elfhdr);
53114@@ -477,9 +479,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
53115 * the addresses in the elf_phdr on our list.
53116 */
53117 start = kc_offset_to_vaddr(*fpos - elf_buflen);
53118- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
53119+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
53120+ if (tsz > buflen)
53121 tsz = buflen;
53122-
53123+
53124 while (buflen) {
53125 struct kcore_list *m;
53126
53127@@ -508,20 +511,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
53128 kfree(elf_buf);
53129 } else {
53130 if (kern_addr_valid(start)) {
53131- unsigned long n;
53132+ char *elf_buf;
53133+ mm_segment_t oldfs;
53134
53135- n = copy_to_user(buffer, (char *)start, tsz);
53136- /*
53137- * We cannot distingush between fault on source
53138- * and fault on destination. When this happens
53139- * we clear too and hope it will trigger the
53140- * EFAULT again.
53141- */
53142- if (n) {
53143- if (clear_user(buffer + tsz - n,
53144- n))
53145+ elf_buf = kmalloc(tsz, GFP_KERNEL);
53146+ if (!elf_buf)
53147+ return -ENOMEM;
53148+ oldfs = get_fs();
53149+ set_fs(KERNEL_DS);
53150+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
53151+ set_fs(oldfs);
53152+ if (copy_to_user(buffer, elf_buf, tsz)) {
53153+ kfree(elf_buf);
53154 return -EFAULT;
53155+ }
53156 }
53157+ set_fs(oldfs);
53158+ kfree(elf_buf);
53159 } else {
53160 if (clear_user(buffer, tsz))
53161 return -EFAULT;
53162@@ -541,6 +547,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
53163
53164 static int open_kcore(struct inode *inode, struct file *filp)
53165 {
53166+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
53167+ return -EPERM;
53168+#endif
53169 if (!capable(CAP_SYS_RAWIO))
53170 return -EPERM;
53171 if (kcore_need_update)
53172diff --git a/fs/proc/kmsg.c b/fs/proc/kmsg.c
53173index 7ca7834..cfe90a4 100644
53174--- a/fs/proc/kmsg.c
53175+++ b/fs/proc/kmsg.c
53176@@ -12,37 +12,37 @@
53177 #include <linux/poll.h>
53178 #include <linux/proc_fs.h>
53179 #include <linux/fs.h>
53180+#include <linux/syslog.h>
53181
53182 #include <asm/uaccess.h>
53183 #include <asm/io.h>
53184
53185 extern wait_queue_head_t log_wait;
53186
53187-extern int do_syslog(int type, char __user *bug, int count);
53188-
53189 static int kmsg_open(struct inode * inode, struct file * file)
53190 {
53191- return do_syslog(1,NULL,0);
53192+ return do_syslog(SYSLOG_ACTION_OPEN, NULL, 0, SYSLOG_FROM_FILE);
53193 }
53194
53195 static int kmsg_release(struct inode * inode, struct file * file)
53196 {
53197- (void) do_syslog(0,NULL,0);
53198+ (void) do_syslog(SYSLOG_ACTION_CLOSE, NULL, 0, SYSLOG_FROM_FILE);
53199 return 0;
53200 }
53201
53202 static ssize_t kmsg_read(struct file *file, char __user *buf,
53203 size_t count, loff_t *ppos)
53204 {
53205- if ((file->f_flags & O_NONBLOCK) && !do_syslog(9, NULL, 0))
53206+ if ((file->f_flags & O_NONBLOCK) &&
53207+ !do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE))
53208 return -EAGAIN;
53209- return do_syslog(2, buf, count);
53210+ return do_syslog(SYSLOG_ACTION_READ, buf, count, SYSLOG_FROM_FILE);
53211 }
53212
53213 static unsigned int kmsg_poll(struct file *file, poll_table *wait)
53214 {
53215 poll_wait(file, &log_wait, wait);
53216- if (do_syslog(9, NULL, 0))
53217+ if (do_syslog(SYSLOG_ACTION_SIZE_UNREAD, NULL, 0, SYSLOG_FROM_FILE))
53218 return POLLIN | POLLRDNORM;
53219 return 0;
53220 }
53221diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
53222index a65239c..ad1182a 100644
53223--- a/fs/proc/meminfo.c
53224+++ b/fs/proc/meminfo.c
53225@@ -29,6 +29,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
53226 unsigned long pages[NR_LRU_LISTS];
53227 int lru;
53228
53229+ pax_track_stack();
53230+
53231 /*
53232 * display in kilobytes.
53233 */
53234@@ -149,7 +151,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
53235 vmi.used >> 10,
53236 vmi.largest_chunk >> 10
53237 #ifdef CONFIG_MEMORY_FAILURE
53238- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
53239+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
53240 #endif
53241 );
53242
53243diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
53244index 9fe7d7e..cdb62c9 100644
53245--- a/fs/proc/nommu.c
53246+++ b/fs/proc/nommu.c
53247@@ -67,7 +67,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
53248 if (len < 1)
53249 len = 1;
53250 seq_printf(m, "%*c", len, ' ');
53251- seq_path(m, &file->f_path, "");
53252+ seq_path(m, &file->f_path, "\n\\");
53253 }
53254
53255 seq_putc(m, '\n');
53256diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
53257index 04d1270..25e1173 100644
53258--- a/fs/proc/proc_net.c
53259+++ b/fs/proc/proc_net.c
53260@@ -104,6 +104,17 @@ static struct net *get_proc_task_net(struct inode *dir)
53261 struct task_struct *task;
53262 struct nsproxy *ns;
53263 struct net *net = NULL;
53264+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53265+ const struct cred *cred = current_cred();
53266+#endif
53267+
53268+#ifdef CONFIG_GRKERNSEC_PROC_USER
53269+ if (cred->fsuid)
53270+ return net;
53271+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53272+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
53273+ return net;
53274+#endif
53275
53276 rcu_read_lock();
53277 task = pid_task(proc_pid(dir), PIDTYPE_PID);
53278diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
53279index f667e8a..55f4d96 100644
53280--- a/fs/proc/proc_sysctl.c
53281+++ b/fs/proc/proc_sysctl.c
53282@@ -7,11 +7,13 @@
53283 #include <linux/security.h>
53284 #include "internal.h"
53285
53286+extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
53287+
53288 static const struct dentry_operations proc_sys_dentry_operations;
53289 static const struct file_operations proc_sys_file_operations;
53290-static const struct inode_operations proc_sys_inode_operations;
53291+const struct inode_operations proc_sys_inode_operations;
53292 static const struct file_operations proc_sys_dir_file_operations;
53293-static const struct inode_operations proc_sys_dir_operations;
53294+const struct inode_operations proc_sys_dir_operations;
53295
53296 static struct inode *proc_sys_make_inode(struct super_block *sb,
53297 struct ctl_table_header *head, struct ctl_table *table)
53298@@ -109,6 +111,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
53299 if (!p)
53300 goto out;
53301
53302+ if (gr_handle_sysctl(p, MAY_EXEC))
53303+ goto out;
53304+
53305 err = ERR_PTR(-ENOMEM);
53306 inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
53307 if (h)
53308@@ -119,6 +124,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
53309
53310 err = NULL;
53311 dentry->d_op = &proc_sys_dentry_operations;
53312+
53313+ gr_handle_proc_create(dentry, inode);
53314+
53315 d_add(dentry, inode);
53316
53317 out:
53318@@ -200,6 +208,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
53319 return -ENOMEM;
53320 } else {
53321 child->d_op = &proc_sys_dentry_operations;
53322+
53323+ gr_handle_proc_create(child, inode);
53324+
53325 d_add(child, inode);
53326 }
53327 } else {
53328@@ -228,6 +239,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
53329 if (*pos < file->f_pos)
53330 continue;
53331
53332+ if (gr_handle_sysctl(table, 0))
53333+ continue;
53334+
53335 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
53336 if (res)
53337 return res;
53338@@ -344,6 +358,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
53339 if (IS_ERR(head))
53340 return PTR_ERR(head);
53341
53342+ if (table && gr_handle_sysctl(table, MAY_EXEC))
53343+ return -ENOENT;
53344+
53345 generic_fillattr(inode, stat);
53346 if (table)
53347 stat->mode = (stat->mode & S_IFMT) | table->mode;
53348@@ -358,17 +375,18 @@ static const struct file_operations proc_sys_file_operations = {
53349 };
53350
53351 static const struct file_operations proc_sys_dir_file_operations = {
53352+ .read = generic_read_dir,
53353 .readdir = proc_sys_readdir,
53354 .llseek = generic_file_llseek,
53355 };
53356
53357-static const struct inode_operations proc_sys_inode_operations = {
53358+const struct inode_operations proc_sys_inode_operations = {
53359 .permission = proc_sys_permission,
53360 .setattr = proc_sys_setattr,
53361 .getattr = proc_sys_getattr,
53362 };
53363
53364-static const struct inode_operations proc_sys_dir_operations = {
53365+const struct inode_operations proc_sys_dir_operations = {
53366 .lookup = proc_sys_lookup,
53367 .permission = proc_sys_permission,
53368 .setattr = proc_sys_setattr,
53369diff --git a/fs/proc/root.c b/fs/proc/root.c
53370index b080b79..d957e63 100644
53371--- a/fs/proc/root.c
53372+++ b/fs/proc/root.c
53373@@ -134,7 +134,15 @@ void __init proc_root_init(void)
53374 #ifdef CONFIG_PROC_DEVICETREE
53375 proc_device_tree_init();
53376 #endif
53377+#ifdef CONFIG_GRKERNSEC_PROC_ADD
53378+#ifdef CONFIG_GRKERNSEC_PROC_USER
53379+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
53380+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53381+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
53382+#endif
53383+#else
53384 proc_mkdir("bus", NULL);
53385+#endif
53386 proc_sys_init();
53387 }
53388
53389diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
53390index 3b7b82a..7dbb571 100644
53391--- a/fs/proc/task_mmu.c
53392+++ b/fs/proc/task_mmu.c
53393@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
53394 "VmStk:\t%8lu kB\n"
53395 "VmExe:\t%8lu kB\n"
53396 "VmLib:\t%8lu kB\n"
53397- "VmPTE:\t%8lu kB\n",
53398- hiwater_vm << (PAGE_SHIFT-10),
53399+ "VmPTE:\t%8lu kB\n"
53400+
53401+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53402+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
53403+#endif
53404+
53405+ ,hiwater_vm << (PAGE_SHIFT-10),
53406 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
53407 mm->locked_vm << (PAGE_SHIFT-10),
53408 hiwater_rss << (PAGE_SHIFT-10),
53409 total_rss << (PAGE_SHIFT-10),
53410 data << (PAGE_SHIFT-10),
53411 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
53412- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
53413+ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
53414+
53415+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53416+ , mm->context.user_cs_base, mm->context.user_cs_limit
53417+#endif
53418+
53419+ );
53420 }
53421
53422 unsigned long task_vsize(struct mm_struct *mm)
53423@@ -175,7 +186,8 @@ static void m_stop(struct seq_file *m, void *v)
53424 struct proc_maps_private *priv = m->private;
53425 struct vm_area_struct *vma = v;
53426
53427- vma_stop(priv, vma);
53428+ if (!IS_ERR(vma))
53429+ vma_stop(priv, vma);
53430 if (priv->task)
53431 put_task_struct(priv->task);
53432 }
53433@@ -199,6 +211,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
53434 return ret;
53435 }
53436
53437+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53438+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53439+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
53440+ _mm->pax_flags & MF_PAX_SEGMEXEC))
53441+#endif
53442+
53443 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53444 {
53445 struct mm_struct *mm = vma->vm_mm;
53446@@ -206,7 +224,6 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53447 int flags = vma->vm_flags;
53448 unsigned long ino = 0;
53449 unsigned long long pgoff = 0;
53450- unsigned long start;
53451 dev_t dev = 0;
53452 int len;
53453
53454@@ -217,20 +234,23 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53455 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
53456 }
53457
53458- /* We don't show the stack guard page in /proc/maps */
53459- start = vma->vm_start;
53460- if (vma->vm_flags & VM_GROWSDOWN)
53461- if (!vma_stack_continue(vma->vm_prev, vma->vm_start))
53462- start += PAGE_SIZE;
53463-
53464 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
53465- start,
53466+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53467+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
53468+ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
53469+#else
53470+ vma->vm_start,
53471 vma->vm_end,
53472+#endif
53473 flags & VM_READ ? 'r' : '-',
53474 flags & VM_WRITE ? 'w' : '-',
53475 flags & VM_EXEC ? 'x' : '-',
53476 flags & VM_MAYSHARE ? 's' : 'p',
53477+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53478+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
53479+#else
53480 pgoff,
53481+#endif
53482 MAJOR(dev), MINOR(dev), ino, &len);
53483
53484 /*
53485@@ -239,7 +259,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53486 */
53487 if (file) {
53488 pad_len_spaces(m, len);
53489- seq_path(m, &file->f_path, "\n");
53490+ seq_path(m, &file->f_path, "\n\\");
53491 } else {
53492 const char *name = arch_vma_name(vma);
53493 if (!name) {
53494@@ -247,8 +267,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
53495 if (vma->vm_start <= mm->brk &&
53496 vma->vm_end >= mm->start_brk) {
53497 name = "[heap]";
53498- } else if (vma->vm_start <= mm->start_stack &&
53499- vma->vm_end >= mm->start_stack) {
53500+ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
53501+ (vma->vm_start <= mm->start_stack &&
53502+ vma->vm_end >= mm->start_stack)) {
53503 name = "[stack]";
53504 }
53505 } else {
53506@@ -391,9 +412,16 @@ static int show_smap(struct seq_file *m, void *v)
53507 };
53508
53509 memset(&mss, 0, sizeof mss);
53510- mss.vma = vma;
53511- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
53512- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
53513+
53514+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53515+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
53516+#endif
53517+ mss.vma = vma;
53518+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
53519+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
53520+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53521+ }
53522+#endif
53523
53524 show_map_vma(m, vma);
53525
53526@@ -409,7 +437,11 @@ static int show_smap(struct seq_file *m, void *v)
53527 "Swap: %8lu kB\n"
53528 "KernelPageSize: %8lu kB\n"
53529 "MMUPageSize: %8lu kB\n",
53530+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53531+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
53532+#else
53533 (vma->vm_end - vma->vm_start) >> 10,
53534+#endif
53535 mss.resident >> 10,
53536 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
53537 mss.shared_clean >> 10,
53538diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
53539index 8f5c05d..c99c76d 100644
53540--- a/fs/proc/task_nommu.c
53541+++ b/fs/proc/task_nommu.c
53542@@ -50,7 +50,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
53543 else
53544 bytes += kobjsize(mm);
53545
53546- if (current->fs && current->fs->users > 1)
53547+ if (current->fs && atomic_read(&current->fs->users) > 1)
53548 sbytes += kobjsize(current->fs);
53549 else
53550 bytes += kobjsize(current->fs);
53551@@ -154,7 +154,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
53552 if (len < 1)
53553 len = 1;
53554 seq_printf(m, "%*c", len, ' ');
53555- seq_path(m, &file->f_path, "");
53556+ seq_path(m, &file->f_path, "\n\\");
53557 }
53558
53559 seq_putc(m, '\n');
53560diff --git a/fs/readdir.c b/fs/readdir.c
53561index 7723401..30059a6 100644
53562--- a/fs/readdir.c
53563+++ b/fs/readdir.c
53564@@ -16,6 +16,7 @@
53565 #include <linux/security.h>
53566 #include <linux/syscalls.h>
53567 #include <linux/unistd.h>
53568+#include <linux/namei.h>
53569
53570 #include <asm/uaccess.h>
53571
53572@@ -67,6 +68,7 @@ struct old_linux_dirent {
53573
53574 struct readdir_callback {
53575 struct old_linux_dirent __user * dirent;
53576+ struct file * file;
53577 int result;
53578 };
53579
53580@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
53581 buf->result = -EOVERFLOW;
53582 return -EOVERFLOW;
53583 }
53584+
53585+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53586+ return 0;
53587+
53588 buf->result++;
53589 dirent = buf->dirent;
53590 if (!access_ok(VERIFY_WRITE, dirent,
53591@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
53592
53593 buf.result = 0;
53594 buf.dirent = dirent;
53595+ buf.file = file;
53596
53597 error = vfs_readdir(file, fillonedir, &buf);
53598 if (buf.result)
53599@@ -142,6 +149,7 @@ struct linux_dirent {
53600 struct getdents_callback {
53601 struct linux_dirent __user * current_dir;
53602 struct linux_dirent __user * previous;
53603+ struct file * file;
53604 int count;
53605 int error;
53606 };
53607@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
53608 buf->error = -EOVERFLOW;
53609 return -EOVERFLOW;
53610 }
53611+
53612+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53613+ return 0;
53614+
53615 dirent = buf->previous;
53616 if (dirent) {
53617 if (__put_user(offset, &dirent->d_off))
53618@@ -209,6 +221,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
53619 buf.previous = NULL;
53620 buf.count = count;
53621 buf.error = 0;
53622+ buf.file = file;
53623
53624 error = vfs_readdir(file, filldir, &buf);
53625 if (error >= 0)
53626@@ -228,6 +241,7 @@ out:
53627 struct getdents_callback64 {
53628 struct linux_dirent64 __user * current_dir;
53629 struct linux_dirent64 __user * previous;
53630+ struct file *file;
53631 int count;
53632 int error;
53633 };
53634@@ -242,6 +256,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
53635 buf->error = -EINVAL; /* only used if we fail.. */
53636 if (reclen > buf->count)
53637 return -EINVAL;
53638+
53639+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
53640+ return 0;
53641+
53642 dirent = buf->previous;
53643 if (dirent) {
53644 if (__put_user(offset, &dirent->d_off))
53645@@ -289,6 +307,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
53646
53647 buf.current_dir = dirent;
53648 buf.previous = NULL;
53649+ buf.file = file;
53650 buf.count = count;
53651 buf.error = 0;
53652
53653@@ -297,7 +316,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
53654 error = buf.error;
53655 lastdirent = buf.previous;
53656 if (lastdirent) {
53657- typeof(lastdirent->d_off) d_off = file->f_pos;
53658+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
53659 if (__put_user(d_off, &lastdirent->d_off))
53660 error = -EFAULT;
53661 else
53662diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
53663index d42c30c..4fd8718 100644
53664--- a/fs/reiserfs/dir.c
53665+++ b/fs/reiserfs/dir.c
53666@@ -66,6 +66,8 @@ int reiserfs_readdir_dentry(struct dentry *dentry, void *dirent,
53667 struct reiserfs_dir_entry de;
53668 int ret = 0;
53669
53670+ pax_track_stack();
53671+
53672 reiserfs_write_lock(inode->i_sb);
53673
53674 reiserfs_check_lock_depth(inode->i_sb, "readdir");
53675diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
53676index 128d3f7..8840d44 100644
53677--- a/fs/reiserfs/do_balan.c
53678+++ b/fs/reiserfs/do_balan.c
53679@@ -2058,7 +2058,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
53680 return;
53681 }
53682
53683- atomic_inc(&(fs_generation(tb->tb_sb)));
53684+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
53685 do_balance_starts(tb);
53686
53687 /* balance leaf returns 0 except if combining L R and S into
53688diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
53689index 72cb1cc..d0e3181 100644
53690--- a/fs/reiserfs/item_ops.c
53691+++ b/fs/reiserfs/item_ops.c
53692@@ -102,7 +102,7 @@ static void sd_print_vi(struct virtual_item *vi)
53693 vi->vi_index, vi->vi_type, vi->vi_ih);
53694 }
53695
53696-static struct item_operations stat_data_ops = {
53697+static const struct item_operations stat_data_ops = {
53698 .bytes_number = sd_bytes_number,
53699 .decrement_key = sd_decrement_key,
53700 .is_left_mergeable = sd_is_left_mergeable,
53701@@ -196,7 +196,7 @@ static void direct_print_vi(struct virtual_item *vi)
53702 vi->vi_index, vi->vi_type, vi->vi_ih);
53703 }
53704
53705-static struct item_operations direct_ops = {
53706+static const struct item_operations direct_ops = {
53707 .bytes_number = direct_bytes_number,
53708 .decrement_key = direct_decrement_key,
53709 .is_left_mergeable = direct_is_left_mergeable,
53710@@ -341,7 +341,7 @@ static void indirect_print_vi(struct virtual_item *vi)
53711 vi->vi_index, vi->vi_type, vi->vi_ih);
53712 }
53713
53714-static struct item_operations indirect_ops = {
53715+static const struct item_operations indirect_ops = {
53716 .bytes_number = indirect_bytes_number,
53717 .decrement_key = indirect_decrement_key,
53718 .is_left_mergeable = indirect_is_left_mergeable,
53719@@ -628,7 +628,7 @@ static void direntry_print_vi(struct virtual_item *vi)
53720 printk("\n");
53721 }
53722
53723-static struct item_operations direntry_ops = {
53724+static const struct item_operations direntry_ops = {
53725 .bytes_number = direntry_bytes_number,
53726 .decrement_key = direntry_decrement_key,
53727 .is_left_mergeable = direntry_is_left_mergeable,
53728@@ -724,7 +724,7 @@ static void errcatch_print_vi(struct virtual_item *vi)
53729 "Invalid item type observed, run fsck ASAP");
53730 }
53731
53732-static struct item_operations errcatch_ops = {
53733+static const struct item_operations errcatch_ops = {
53734 errcatch_bytes_number,
53735 errcatch_decrement_key,
53736 errcatch_is_left_mergeable,
53737@@ -746,7 +746,7 @@ static struct item_operations errcatch_ops = {
53738 #error Item types must use disk-format assigned values.
53739 #endif
53740
53741-struct item_operations *item_ops[TYPE_ANY + 1] = {
53742+const struct item_operations * const item_ops[TYPE_ANY + 1] = {
53743 &stat_data_ops,
53744 &indirect_ops,
53745 &direct_ops,
53746diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
53747index b5fe0aa..e0e25c4 100644
53748--- a/fs/reiserfs/journal.c
53749+++ b/fs/reiserfs/journal.c
53750@@ -2329,6 +2329,8 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
53751 struct buffer_head *bh;
53752 int i, j;
53753
53754+ pax_track_stack();
53755+
53756 bh = __getblk(dev, block, bufsize);
53757 if (buffer_uptodate(bh))
53758 return (bh);
53759diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
53760index 2715791..b8996db 100644
53761--- a/fs/reiserfs/namei.c
53762+++ b/fs/reiserfs/namei.c
53763@@ -1214,6 +1214,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
53764 unsigned long savelink = 1;
53765 struct timespec ctime;
53766
53767+ pax_track_stack();
53768+
53769 /* three balancings: (1) old name removal, (2) new name insertion
53770 and (3) maybe "save" link insertion
53771 stat data updates: (1) old directory,
53772diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
53773index 9229e55..3d2e3b7 100644
53774--- a/fs/reiserfs/procfs.c
53775+++ b/fs/reiserfs/procfs.c
53776@@ -123,7 +123,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
53777 "SMALL_TAILS " : "NO_TAILS ",
53778 replay_only(sb) ? "REPLAY_ONLY " : "",
53779 convert_reiserfs(sb) ? "CONV " : "",
53780- atomic_read(&r->s_generation_counter),
53781+ atomic_read_unchecked(&r->s_generation_counter),
53782 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
53783 SF(s_do_balance), SF(s_unneeded_left_neighbor),
53784 SF(s_good_search_by_key_reada), SF(s_bmaps),
53785@@ -309,6 +309,8 @@ static int show_journal(struct seq_file *m, struct super_block *sb)
53786 struct journal_params *jp = &rs->s_v1.s_journal;
53787 char b[BDEVNAME_SIZE];
53788
53789+ pax_track_stack();
53790+
53791 seq_printf(m, /* on-disk fields */
53792 "jp_journal_1st_block: \t%i\n"
53793 "jp_journal_dev: \t%s[%x]\n"
53794diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
53795index d036ee5..4c7dca1 100644
53796--- a/fs/reiserfs/stree.c
53797+++ b/fs/reiserfs/stree.c
53798@@ -1159,6 +1159,8 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
53799 int iter = 0;
53800 #endif
53801
53802+ pax_track_stack();
53803+
53804 BUG_ON(!th->t_trans_id);
53805
53806 init_tb_struct(th, &s_del_balance, sb, path,
53807@@ -1296,6 +1298,8 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
53808 int retval;
53809 int quota_cut_bytes = 0;
53810
53811+ pax_track_stack();
53812+
53813 BUG_ON(!th->t_trans_id);
53814
53815 le_key2cpu_key(&cpu_key, key);
53816@@ -1525,6 +1529,8 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
53817 int quota_cut_bytes;
53818 loff_t tail_pos = 0;
53819
53820+ pax_track_stack();
53821+
53822 BUG_ON(!th->t_trans_id);
53823
53824 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
53825@@ -1920,6 +1926,8 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
53826 int retval;
53827 int fs_gen;
53828
53829+ pax_track_stack();
53830+
53831 BUG_ON(!th->t_trans_id);
53832
53833 fs_gen = get_generation(inode->i_sb);
53834@@ -2007,6 +2015,8 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
53835 int fs_gen = 0;
53836 int quota_bytes = 0;
53837
53838+ pax_track_stack();
53839+
53840 BUG_ON(!th->t_trans_id);
53841
53842 if (inode) { /* Do we count quotas for item? */
53843diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
53844index f0ad05f..af3306f 100644
53845--- a/fs/reiserfs/super.c
53846+++ b/fs/reiserfs/super.c
53847@@ -912,6 +912,8 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
53848 {.option_name = NULL}
53849 };
53850
53851+ pax_track_stack();
53852+
53853 *blocks = 0;
53854 if (!options || !*options)
53855 /* use default configuration: create tails, journaling on, no
53856diff --git a/fs/select.c b/fs/select.c
53857index fd38ce2..f5381b8 100644
53858--- a/fs/select.c
53859+++ b/fs/select.c
53860@@ -20,6 +20,7 @@
53861 #include <linux/module.h>
53862 #include <linux/slab.h>
53863 #include <linux/poll.h>
53864+#include <linux/security.h>
53865 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
53866 #include <linux/file.h>
53867 #include <linux/fdtable.h>
53868@@ -401,6 +402,8 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
53869 int retval, i, timed_out = 0;
53870 unsigned long slack = 0;
53871
53872+ pax_track_stack();
53873+
53874 rcu_read_lock();
53875 retval = max_select_fd(n, fds);
53876 rcu_read_unlock();
53877@@ -529,6 +532,8 @@ int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
53878 /* Allocate small arguments on the stack to save memory and be faster */
53879 long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
53880
53881+ pax_track_stack();
53882+
53883 ret = -EINVAL;
53884 if (n < 0)
53885 goto out_nofds;
53886@@ -821,6 +826,9 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
53887 struct poll_list *walk = head;
53888 unsigned long todo = nfds;
53889
53890+ pax_track_stack();
53891+
53892+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
53893 if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
53894 return -EINVAL;
53895
53896diff --git a/fs/seq_file.c b/fs/seq_file.c
53897index eae7d9d..679f099 100644
53898--- a/fs/seq_file.c
53899+++ b/fs/seq_file.c
53900@@ -76,7 +76,8 @@ static int traverse(struct seq_file *m, loff_t offset)
53901 return 0;
53902 }
53903 if (!m->buf) {
53904- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
53905+ m->size = PAGE_SIZE;
53906+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
53907 if (!m->buf)
53908 return -ENOMEM;
53909 }
53910@@ -116,7 +117,8 @@ static int traverse(struct seq_file *m, loff_t offset)
53911 Eoverflow:
53912 m->op->stop(m, p);
53913 kfree(m->buf);
53914- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
53915+ m->size <<= 1;
53916+ m->buf = kmalloc(m->size, GFP_KERNEL);
53917 return !m->buf ? -ENOMEM : -EAGAIN;
53918 }
53919
53920@@ -169,7 +171,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
53921 m->version = file->f_version;
53922 /* grab buffer if we didn't have one */
53923 if (!m->buf) {
53924- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
53925+ m->size = PAGE_SIZE;
53926+ m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
53927 if (!m->buf)
53928 goto Enomem;
53929 }
53930@@ -210,7 +213,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
53931 goto Fill;
53932 m->op->stop(m, p);
53933 kfree(m->buf);
53934- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
53935+ m->size <<= 1;
53936+ m->buf = kmalloc(m->size, GFP_KERNEL);
53937 if (!m->buf)
53938 goto Enomem;
53939 m->count = 0;
53940@@ -551,7 +555,7 @@ static void single_stop(struct seq_file *p, void *v)
53941 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
53942 void *data)
53943 {
53944- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
53945+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
53946 int res = -ENOMEM;
53947
53948 if (op) {
53949diff --git a/fs/smbfs/proc.c b/fs/smbfs/proc.c
53950index 71c29b6..54694dd 100644
53951--- a/fs/smbfs/proc.c
53952+++ b/fs/smbfs/proc.c
53953@@ -266,9 +266,9 @@ int smb_setcodepage(struct smb_sb_info *server, struct smb_nls_codepage *cp)
53954
53955 out:
53956 if (server->local_nls != NULL && server->remote_nls != NULL)
53957- server->ops->convert = convert_cp;
53958+ *(void **)&server->ops->convert = convert_cp;
53959 else
53960- server->ops->convert = convert_memcpy;
53961+ *(void **)&server->ops->convert = convert_memcpy;
53962
53963 smb_unlock_server(server);
53964 return n;
53965@@ -933,9 +933,9 @@ smb_newconn(struct smb_sb_info *server, struct smb_conn_opt *opt)
53966
53967 /* FIXME: the win9x code wants to modify these ... (seek/trunc bug) */
53968 if (server->mnt->flags & SMB_MOUNT_OLDATTR) {
53969- server->ops->getattr = smb_proc_getattr_core;
53970+ *(void **)&server->ops->getattr = smb_proc_getattr_core;
53971 } else if (server->mnt->flags & SMB_MOUNT_DIRATTR) {
53972- server->ops->getattr = smb_proc_getattr_ff;
53973+ *(void **)&server->ops->getattr = smb_proc_getattr_ff;
53974 }
53975
53976 /* Decode server capabilities */
53977@@ -3439,7 +3439,7 @@ out:
53978 static void
53979 install_ops(struct smb_ops *dst, struct smb_ops *src)
53980 {
53981- memcpy(dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
53982+ memcpy((void *)dst, src, sizeof(void *) * SMB_OPS_NUM_STATIC);
53983 }
53984
53985 /* < LANMAN2 */
53986diff --git a/fs/smbfs/symlink.c b/fs/smbfs/symlink.c
53987index 00b2909..2ace383 100644
53988--- a/fs/smbfs/symlink.c
53989+++ b/fs/smbfs/symlink.c
53990@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dentry *dentry, struct nameidata *nd)
53991
53992 static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53993 {
53994- char *s = nd_get_link(nd);
53995+ const char *s = nd_get_link(nd);
53996 if (!IS_ERR(s))
53997 __putname(s);
53998 }
53999diff --git a/fs/splice.c b/fs/splice.c
54000index bb92b7c..5aa72b0 100644
54001--- a/fs/splice.c
54002+++ b/fs/splice.c
54003@@ -185,7 +185,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
54004 pipe_lock(pipe);
54005
54006 for (;;) {
54007- if (!pipe->readers) {
54008+ if (!atomic_read(&pipe->readers)) {
54009 send_sig(SIGPIPE, current, 0);
54010 if (!ret)
54011 ret = -EPIPE;
54012@@ -239,9 +239,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
54013 do_wakeup = 0;
54014 }
54015
54016- pipe->waiting_writers++;
54017+ atomic_inc(&pipe->waiting_writers);
54018 pipe_wait(pipe);
54019- pipe->waiting_writers--;
54020+ atomic_dec(&pipe->waiting_writers);
54021 }
54022
54023 pipe_unlock(pipe);
54024@@ -285,6 +285,8 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
54025 .spd_release = spd_release_page,
54026 };
54027
54028+ pax_track_stack();
54029+
54030 index = *ppos >> PAGE_CACHE_SHIFT;
54031 loff = *ppos & ~PAGE_CACHE_MASK;
54032 req_pages = (len + loff + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
54033@@ -521,7 +523,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
54034 old_fs = get_fs();
54035 set_fs(get_ds());
54036 /* The cast to a user pointer is valid due to the set_fs() */
54037- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
54038+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
54039 set_fs(old_fs);
54040
54041 return res;
54042@@ -536,7 +538,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
54043 old_fs = get_fs();
54044 set_fs(get_ds());
54045 /* The cast to a user pointer is valid due to the set_fs() */
54046- res = vfs_write(file, (const char __user *)buf, count, &pos);
54047+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
54048 set_fs(old_fs);
54049
54050 return res;
54051@@ -565,6 +567,8 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
54052 .spd_release = spd_release_page,
54053 };
54054
54055+ pax_track_stack();
54056+
54057 index = *ppos >> PAGE_CACHE_SHIFT;
54058 offset = *ppos & ~PAGE_CACHE_MASK;
54059 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
54060@@ -578,7 +582,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
54061 goto err;
54062
54063 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
54064- vec[i].iov_base = (void __user *) page_address(page);
54065+ vec[i].iov_base = (__force void __user *) page_address(page);
54066 vec[i].iov_len = this_len;
54067 pages[i] = page;
54068 spd.nr_pages++;
54069@@ -800,10 +804,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
54070 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
54071 {
54072 while (!pipe->nrbufs) {
54073- if (!pipe->writers)
54074+ if (!atomic_read(&pipe->writers))
54075 return 0;
54076
54077- if (!pipe->waiting_writers && sd->num_spliced)
54078+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
54079 return 0;
54080
54081 if (sd->flags & SPLICE_F_NONBLOCK)
54082@@ -1140,7 +1144,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
54083 * out of the pipe right after the splice_to_pipe(). So set
54084 * PIPE_READERS appropriately.
54085 */
54086- pipe->readers = 1;
54087+ atomic_set(&pipe->readers, 1);
54088
54089 current->splice_pipe = pipe;
54090 }
54091@@ -1593,6 +1597,8 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov,
54092 .spd_release = spd_release_page,
54093 };
54094
54095+ pax_track_stack();
54096+
54097 pipe = pipe_info(file->f_path.dentry->d_inode);
54098 if (!pipe)
54099 return -EBADF;
54100@@ -1701,9 +1707,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
54101 ret = -ERESTARTSYS;
54102 break;
54103 }
54104- if (!pipe->writers)
54105+ if (!atomic_read(&pipe->writers))
54106 break;
54107- if (!pipe->waiting_writers) {
54108+ if (!atomic_read(&pipe->waiting_writers)) {
54109 if (flags & SPLICE_F_NONBLOCK) {
54110 ret = -EAGAIN;
54111 break;
54112@@ -1735,7 +1741,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
54113 pipe_lock(pipe);
54114
54115 while (pipe->nrbufs >= PIPE_BUFFERS) {
54116- if (!pipe->readers) {
54117+ if (!atomic_read(&pipe->readers)) {
54118 send_sig(SIGPIPE, current, 0);
54119 ret = -EPIPE;
54120 break;
54121@@ -1748,9 +1754,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
54122 ret = -ERESTARTSYS;
54123 break;
54124 }
54125- pipe->waiting_writers++;
54126+ atomic_inc(&pipe->waiting_writers);
54127 pipe_wait(pipe);
54128- pipe->waiting_writers--;
54129+ atomic_dec(&pipe->waiting_writers);
54130 }
54131
54132 pipe_unlock(pipe);
54133@@ -1786,14 +1792,14 @@ retry:
54134 pipe_double_lock(ipipe, opipe);
54135
54136 do {
54137- if (!opipe->readers) {
54138+ if (!atomic_read(&opipe->readers)) {
54139 send_sig(SIGPIPE, current, 0);
54140 if (!ret)
54141 ret = -EPIPE;
54142 break;
54143 }
54144
54145- if (!ipipe->nrbufs && !ipipe->writers)
54146+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
54147 break;
54148
54149 /*
54150@@ -1893,7 +1899,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
54151 pipe_double_lock(ipipe, opipe);
54152
54153 do {
54154- if (!opipe->readers) {
54155+ if (!atomic_read(&opipe->readers)) {
54156 send_sig(SIGPIPE, current, 0);
54157 if (!ret)
54158 ret = -EPIPE;
54159@@ -1938,7 +1944,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
54160 * return EAGAIN if we have the potential of some data in the
54161 * future, otherwise just return 0
54162 */
54163- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
54164+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
54165 ret = -EAGAIN;
54166
54167 pipe_unlock(ipipe);
54168diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
54169index 7118a38..70af853 100644
54170--- a/fs/sysfs/file.c
54171+++ b/fs/sysfs/file.c
54172@@ -44,7 +44,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
54173
54174 struct sysfs_open_dirent {
54175 atomic_t refcnt;
54176- atomic_t event;
54177+ atomic_unchecked_t event;
54178 wait_queue_head_t poll;
54179 struct list_head buffers; /* goes through sysfs_buffer.list */
54180 };
54181@@ -53,7 +53,7 @@ struct sysfs_buffer {
54182 size_t count;
54183 loff_t pos;
54184 char * page;
54185- struct sysfs_ops * ops;
54186+ const struct sysfs_ops * ops;
54187 struct mutex mutex;
54188 int needs_read_fill;
54189 int event;
54190@@ -75,7 +75,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
54191 {
54192 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
54193 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
54194- struct sysfs_ops * ops = buffer->ops;
54195+ const struct sysfs_ops * ops = buffer->ops;
54196 int ret = 0;
54197 ssize_t count;
54198
54199@@ -88,7 +88,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
54200 if (!sysfs_get_active_two(attr_sd))
54201 return -ENODEV;
54202
54203- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
54204+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
54205 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
54206
54207 sysfs_put_active_two(attr_sd);
54208@@ -199,7 +199,7 @@ flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t
54209 {
54210 struct sysfs_dirent *attr_sd = dentry->d_fsdata;
54211 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
54212- struct sysfs_ops * ops = buffer->ops;
54213+ const struct sysfs_ops * ops = buffer->ops;
54214 int rc;
54215
54216 /* need attr_sd for attr and ops, its parent for kobj */
54217@@ -294,7 +294,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
54218 return -ENOMEM;
54219
54220 atomic_set(&new_od->refcnt, 0);
54221- atomic_set(&new_od->event, 1);
54222+ atomic_set_unchecked(&new_od->event, 1);
54223 init_waitqueue_head(&new_od->poll);
54224 INIT_LIST_HEAD(&new_od->buffers);
54225 goto retry;
54226@@ -335,7 +335,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
54227 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
54228 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
54229 struct sysfs_buffer *buffer;
54230- struct sysfs_ops *ops;
54231+ const struct sysfs_ops *ops;
54232 int error = -EACCES;
54233 char *p;
54234
54235@@ -444,7 +444,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
54236
54237 sysfs_put_active_two(attr_sd);
54238
54239- if (buffer->event != atomic_read(&od->event))
54240+ if (buffer->event != atomic_read_unchecked(&od->event))
54241 goto trigger;
54242
54243 return DEFAULT_POLLMASK;
54244@@ -463,7 +463,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
54245
54246 od = sd->s_attr.open;
54247 if (od) {
54248- atomic_inc(&od->event);
54249+ atomic_inc_unchecked(&od->event);
54250 wake_up_interruptible(&od->poll);
54251 }
54252
54253diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
54254index 4974995..c26609c 100644
54255--- a/fs/sysfs/mount.c
54256+++ b/fs/sysfs/mount.c
54257@@ -36,7 +36,11 @@ struct sysfs_dirent sysfs_root = {
54258 .s_name = "",
54259 .s_count = ATOMIC_INIT(1),
54260 .s_flags = SYSFS_DIR,
54261+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54262+ .s_mode = S_IFDIR | S_IRWXU,
54263+#else
54264 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54265+#endif
54266 .s_ino = 1,
54267 };
54268
54269diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
54270index c5081ad..342ea86 100644
54271--- a/fs/sysfs/symlink.c
54272+++ b/fs/sysfs/symlink.c
54273@@ -204,7 +204,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
54274
54275 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
54276 {
54277- char *page = nd_get_link(nd);
54278+ const char *page = nd_get_link(nd);
54279 if (!IS_ERR(page))
54280 free_page((unsigned long)page);
54281 }
54282diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
54283index 1e06853..b06d325 100644
54284--- a/fs/udf/balloc.c
54285+++ b/fs/udf/balloc.c
54286@@ -172,9 +172,7 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
54287
54288 mutex_lock(&sbi->s_alloc_mutex);
54289 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
54290- if (bloc->logicalBlockNum < 0 ||
54291- (bloc->logicalBlockNum + count) >
54292- partmap->s_partition_len) {
54293+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
54294 udf_debug("%d < %d || %d + %d > %d\n",
54295 bloc->logicalBlockNum, 0, bloc->logicalBlockNum,
54296 count, partmap->s_partition_len);
54297@@ -436,9 +434,7 @@ static void udf_table_free_blocks(struct super_block *sb,
54298
54299 mutex_lock(&sbi->s_alloc_mutex);
54300 partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
54301- if (bloc->logicalBlockNum < 0 ||
54302- (bloc->logicalBlockNum + count) >
54303- partmap->s_partition_len) {
54304+ if ((bloc->logicalBlockNum + count) > partmap->s_partition_len) {
54305 udf_debug("%d < %d || %d + %d > %d\n",
54306 bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
54307 partmap->s_partition_len);
54308diff --git a/fs/udf/inode.c b/fs/udf/inode.c
54309index 6d24c2c..fff470f 100644
54310--- a/fs/udf/inode.c
54311+++ b/fs/udf/inode.c
54312@@ -484,6 +484,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
54313 int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
54314 int lastblock = 0;
54315
54316+ pax_track_stack();
54317+
54318 prev_epos.offset = udf_file_entry_alloc_offset(inode);
54319 prev_epos.block = iinfo->i_location;
54320 prev_epos.bh = NULL;
54321diff --git a/fs/udf/misc.c b/fs/udf/misc.c
54322index 9215700..bf1f68e 100644
54323--- a/fs/udf/misc.c
54324+++ b/fs/udf/misc.c
54325@@ -286,7 +286,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
54326
54327 u8 udf_tag_checksum(const struct tag *t)
54328 {
54329- u8 *data = (u8 *)t;
54330+ const u8 *data = (const u8 *)t;
54331 u8 checksum = 0;
54332 int i;
54333 for (i = 0; i < sizeof(struct tag); ++i)
54334diff --git a/fs/utimes.c b/fs/utimes.c
54335index e4c75db..b4df0e0 100644
54336--- a/fs/utimes.c
54337+++ b/fs/utimes.c
54338@@ -1,6 +1,7 @@
54339 #include <linux/compiler.h>
54340 #include <linux/file.h>
54341 #include <linux/fs.h>
54342+#include <linux/security.h>
54343 #include <linux/linkage.h>
54344 #include <linux/mount.h>
54345 #include <linux/namei.h>
54346@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
54347 goto mnt_drop_write_and_out;
54348 }
54349 }
54350+
54351+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
54352+ error = -EACCES;
54353+ goto mnt_drop_write_and_out;
54354+ }
54355+
54356 mutex_lock(&inode->i_mutex);
54357 error = notify_change(path->dentry, &newattrs);
54358 mutex_unlock(&inode->i_mutex);
54359diff --git a/fs/xattr.c b/fs/xattr.c
54360index 6d4f6d3..cda3958 100644
54361--- a/fs/xattr.c
54362+++ b/fs/xattr.c
54363@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
54364 * Extended attribute SET operations
54365 */
54366 static long
54367-setxattr(struct dentry *d, const char __user *name, const void __user *value,
54368+setxattr(struct path *path, const char __user *name, const void __user *value,
54369 size_t size, int flags)
54370 {
54371 int error;
54372@@ -271,7 +271,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
54373 return PTR_ERR(kvalue);
54374 }
54375
54376- error = vfs_setxattr(d, kname, kvalue, size, flags);
54377+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
54378+ error = -EACCES;
54379+ goto out;
54380+ }
54381+
54382+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
54383+out:
54384 kfree(kvalue);
54385 return error;
54386 }
54387@@ -288,7 +294,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
54388 return error;
54389 error = mnt_want_write(path.mnt);
54390 if (!error) {
54391- error = setxattr(path.dentry, name, value, size, flags);
54392+ error = setxattr(&path, name, value, size, flags);
54393 mnt_drop_write(path.mnt);
54394 }
54395 path_put(&path);
54396@@ -307,7 +313,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
54397 return error;
54398 error = mnt_want_write(path.mnt);
54399 if (!error) {
54400- error = setxattr(path.dentry, name, value, size, flags);
54401+ error = setxattr(&path, name, value, size, flags);
54402 mnt_drop_write(path.mnt);
54403 }
54404 path_put(&path);
54405@@ -318,17 +324,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
54406 const void __user *,value, size_t, size, int, flags)
54407 {
54408 struct file *f;
54409- struct dentry *dentry;
54410 int error = -EBADF;
54411
54412 f = fget(fd);
54413 if (!f)
54414 return error;
54415- dentry = f->f_path.dentry;
54416- audit_inode(NULL, dentry);
54417+ audit_inode(NULL, f->f_path.dentry);
54418 error = mnt_want_write_file(f);
54419 if (!error) {
54420- error = setxattr(dentry, name, value, size, flags);
54421+ error = setxattr(&f->f_path, name, value, size, flags);
54422 mnt_drop_write(f->f_path.mnt);
54423 }
54424 fput(f);
54425diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
54426index c6ad7c7..f2847a7 100644
54427--- a/fs/xattr_acl.c
54428+++ b/fs/xattr_acl.c
54429@@ -17,8 +17,8 @@
54430 struct posix_acl *
54431 posix_acl_from_xattr(const void *value, size_t size)
54432 {
54433- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
54434- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
54435+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
54436+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
54437 int count;
54438 struct posix_acl *acl;
54439 struct posix_acl_entry *acl_e;
54440diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
54441index 942362f..88f96f5 100644
54442--- a/fs/xfs/linux-2.6/xfs_ioctl.c
54443+++ b/fs/xfs/linux-2.6/xfs_ioctl.c
54444@@ -134,7 +134,7 @@ xfs_find_handle(
54445 }
54446
54447 error = -EFAULT;
54448- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
54449+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
54450 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
54451 goto out_put;
54452
54453@@ -423,7 +423,7 @@ xfs_attrlist_by_handle(
54454 if (IS_ERR(dentry))
54455 return PTR_ERR(dentry);
54456
54457- kbuf = kmalloc(al_hreq.buflen, GFP_KERNEL);
54458+ kbuf = kzalloc(al_hreq.buflen, GFP_KERNEL);
54459 if (!kbuf)
54460 goto out_dput;
54461
54462@@ -697,7 +697,7 @@ xfs_ioc_fsgeometry_v1(
54463 xfs_mount_t *mp,
54464 void __user *arg)
54465 {
54466- xfs_fsop_geom_t fsgeo;
54467+ xfs_fsop_geom_t fsgeo;
54468 int error;
54469
54470 error = xfs_fs_geometry(mp, &fsgeo, 3);
54471diff --git a/fs/xfs/linux-2.6/xfs_ioctl32.c b/fs/xfs/linux-2.6/xfs_ioctl32.c
54472index bad485a..479bd32 100644
54473--- a/fs/xfs/linux-2.6/xfs_ioctl32.c
54474+++ b/fs/xfs/linux-2.6/xfs_ioctl32.c
54475@@ -75,6 +75,7 @@ xfs_compat_ioc_fsgeometry_v1(
54476 xfs_fsop_geom_t fsgeo;
54477 int error;
54478
54479+ memset(&fsgeo, 0, sizeof(fsgeo));
54480 error = xfs_fs_geometry(mp, &fsgeo, 3);
54481 if (error)
54482 return -error;
54483diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c
54484index 1f3b4b8..6102f6d 100644
54485--- a/fs/xfs/linux-2.6/xfs_iops.c
54486+++ b/fs/xfs/linux-2.6/xfs_iops.c
54487@@ -468,7 +468,7 @@ xfs_vn_put_link(
54488 struct nameidata *nd,
54489 void *p)
54490 {
54491- char *s = nd_get_link(nd);
54492+ const char *s = nd_get_link(nd);
54493
54494 if (!IS_ERR(s))
54495 kfree(s);
54496diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
54497index 8971fb0..5fc1eb2 100644
54498--- a/fs/xfs/xfs_bmap.c
54499+++ b/fs/xfs/xfs_bmap.c
54500@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
54501 int nmap,
54502 int ret_nmap);
54503 #else
54504-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
54505+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
54506 #endif /* DEBUG */
54507
54508 #if defined(XFS_RW_TRACE)
54509diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
54510index e89734e..5e84d8d 100644
54511--- a/fs/xfs/xfs_dir2_sf.c
54512+++ b/fs/xfs/xfs_dir2_sf.c
54513@@ -779,7 +779,15 @@ xfs_dir2_sf_getdents(
54514 }
54515
54516 ino = xfs_dir2_sf_get_inumber(sfp, xfs_dir2_sf_inumberp(sfep));
54517- if (filldir(dirent, sfep->name, sfep->namelen,
54518+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
54519+ char name[sfep->namelen];
54520+ memcpy(name, sfep->name, sfep->namelen);
54521+ if (filldir(dirent, name, sfep->namelen,
54522+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
54523+ *offset = off & 0x7fffffff;
54524+ return 0;
54525+ }
54526+ } else if (filldir(dirent, sfep->name, sfep->namelen,
54527 off & 0x7fffffff, ino, DT_UNKNOWN)) {
54528 *offset = off & 0x7fffffff;
54529 return 0;
54530diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
54531index 8f32f50..859e8a3 100644
54532--- a/fs/xfs/xfs_vnodeops.c
54533+++ b/fs/xfs/xfs_vnodeops.c
54534@@ -564,13 +564,17 @@ xfs_readlink(
54535
54536 xfs_ilock(ip, XFS_ILOCK_SHARED);
54537
54538- ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFLNK);
54539- ASSERT(ip->i_d.di_size <= MAXPATHLEN);
54540-
54541 pathlen = ip->i_d.di_size;
54542 if (!pathlen)
54543 goto out;
54544
54545+ if (pathlen > MAXPATHLEN) {
54546+ xfs_fs_cmn_err(CE_ALERT, mp, "%s: inode (%llu) symlink length (%d) too long",
54547+ __func__, (unsigned long long)ip->i_ino, pathlen);
54548+ ASSERT(0);
54549+ return XFS_ERROR(EFSCORRUPTED);
54550+ }
54551+
54552 if (ip->i_df.if_flags & XFS_IFINLINE) {
54553 memcpy(link, ip->i_df.if_u1.if_data, pathlen);
54554 link[pathlen] = '\0';
54555diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
54556new file mode 100644
54557index 0000000..f27a8e8
54558--- /dev/null
54559+++ b/grsecurity/Kconfig
54560@@ -0,0 +1,1036 @@
54561+#
54562+# grecurity configuration
54563+#
54564+
54565+menu "Grsecurity"
54566+
54567+config GRKERNSEC
54568+ bool "Grsecurity"
54569+ select CRYPTO
54570+ select CRYPTO_SHA256
54571+ help
54572+ If you say Y here, you will be able to configure many features
54573+ that will enhance the security of your system. It is highly
54574+ recommended that you say Y here and read through the help
54575+ for each option so that you fully understand the features and
54576+ can evaluate their usefulness for your machine.
54577+
54578+choice
54579+ prompt "Security Level"
54580+ depends on GRKERNSEC
54581+ default GRKERNSEC_CUSTOM
54582+
54583+config GRKERNSEC_LOW
54584+ bool "Low"
54585+ select GRKERNSEC_LINK
54586+ select GRKERNSEC_FIFO
54587+ select GRKERNSEC_RANDNET
54588+ select GRKERNSEC_DMESG
54589+ select GRKERNSEC_CHROOT
54590+ select GRKERNSEC_CHROOT_CHDIR
54591+
54592+ help
54593+ If you choose this option, several of the grsecurity options will
54594+ be enabled that will give you greater protection against a number
54595+ of attacks, while assuring that none of your software will have any
54596+ conflicts with the additional security measures. If you run a lot
54597+ of unusual software, or you are having problems with the higher
54598+ security levels, you should say Y here. With this option, the
54599+ following features are enabled:
54600+
54601+ - Linking restrictions
54602+ - FIFO restrictions
54603+ - Restricted dmesg
54604+ - Enforced chdir("/") on chroot
54605+ - Runtime module disabling
54606+
54607+config GRKERNSEC_MEDIUM
54608+ bool "Medium"
54609+ select PAX
54610+ select PAX_EI_PAX
54611+ select PAX_PT_PAX_FLAGS
54612+ select PAX_HAVE_ACL_FLAGS
54613+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
54614+ select GRKERNSEC_CHROOT
54615+ select GRKERNSEC_CHROOT_SYSCTL
54616+ select GRKERNSEC_LINK
54617+ select GRKERNSEC_FIFO
54618+ select GRKERNSEC_DMESG
54619+ select GRKERNSEC_RANDNET
54620+ select GRKERNSEC_FORKFAIL
54621+ select GRKERNSEC_TIME
54622+ select GRKERNSEC_SIGNAL
54623+ select GRKERNSEC_CHROOT
54624+ select GRKERNSEC_CHROOT_UNIX
54625+ select GRKERNSEC_CHROOT_MOUNT
54626+ select GRKERNSEC_CHROOT_PIVOT
54627+ select GRKERNSEC_CHROOT_DOUBLE
54628+ select GRKERNSEC_CHROOT_CHDIR
54629+ select GRKERNSEC_CHROOT_MKNOD
54630+ select GRKERNSEC_PROC
54631+ select GRKERNSEC_PROC_USERGROUP
54632+ select PAX_RANDUSTACK
54633+ select PAX_ASLR
54634+ select PAX_RANDMMAP
54635+ select PAX_REFCOUNT if (X86 || SPARC64)
54636+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
54637+
54638+ help
54639+ If you say Y here, several features in addition to those included
54640+ in the low additional security level will be enabled. These
54641+ features provide even more security to your system, though in rare
54642+ cases they may be incompatible with very old or poorly written
54643+ software. If you enable this option, make sure that your auth
54644+ service (identd) is running as gid 1001. With this option,
54645+ the following features (in addition to those provided in the
54646+ low additional security level) will be enabled:
54647+
54648+ - Failed fork logging
54649+ - Time change logging
54650+ - Signal logging
54651+ - Deny mounts in chroot
54652+ - Deny double chrooting
54653+ - Deny sysctl writes in chroot
54654+ - Deny mknod in chroot
54655+ - Deny access to abstract AF_UNIX sockets out of chroot
54656+ - Deny pivot_root in chroot
54657+ - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
54658+ - /proc restrictions with special GID set to 10 (usually wheel)
54659+ - Address Space Layout Randomization (ASLR)
54660+ - Prevent exploitation of most refcount overflows
54661+ - Bounds checking of copying between the kernel and userland
54662+
54663+config GRKERNSEC_HIGH
54664+ bool "High"
54665+ select GRKERNSEC_LINK
54666+ select GRKERNSEC_FIFO
54667+ select GRKERNSEC_DMESG
54668+ select GRKERNSEC_FORKFAIL
54669+ select GRKERNSEC_TIME
54670+ select GRKERNSEC_SIGNAL
54671+ select GRKERNSEC_CHROOT
54672+ select GRKERNSEC_CHROOT_SHMAT
54673+ select GRKERNSEC_CHROOT_UNIX
54674+ select GRKERNSEC_CHROOT_MOUNT
54675+ select GRKERNSEC_CHROOT_FCHDIR
54676+ select GRKERNSEC_CHROOT_PIVOT
54677+ select GRKERNSEC_CHROOT_DOUBLE
54678+ select GRKERNSEC_CHROOT_CHDIR
54679+ select GRKERNSEC_CHROOT_MKNOD
54680+ select GRKERNSEC_CHROOT_CAPS
54681+ select GRKERNSEC_CHROOT_SYSCTL
54682+ select GRKERNSEC_CHROOT_FINDTASK
54683+ select GRKERNSEC_SYSFS_RESTRICT
54684+ select GRKERNSEC_PROC
54685+ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
54686+ select GRKERNSEC_HIDESYM
54687+ select GRKERNSEC_BRUTE
54688+ select GRKERNSEC_PROC_USERGROUP
54689+ select GRKERNSEC_KMEM
54690+ select GRKERNSEC_RESLOG
54691+ select GRKERNSEC_RANDNET
54692+ select GRKERNSEC_PROC_ADD
54693+ select GRKERNSEC_CHROOT_CHMOD
54694+ select GRKERNSEC_CHROOT_NICE
54695+ select GRKERNSEC_AUDIT_MOUNT
54696+ select GRKERNSEC_MODHARDEN if (MODULES)
54697+ select GRKERNSEC_HARDEN_PTRACE
54698+ select GRKERNSEC_VM86 if (X86_32)
54699+ select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
54700+ select PAX
54701+ select PAX_RANDUSTACK
54702+ select PAX_ASLR
54703+ select PAX_RANDMMAP
54704+ select PAX_NOEXEC
54705+ select PAX_MPROTECT
54706+ select PAX_EI_PAX
54707+ select PAX_PT_PAX_FLAGS
54708+ select PAX_HAVE_ACL_FLAGS
54709+ select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
54710+ select PAX_MEMORY_UDEREF if (X86 && !XEN)
54711+ select PAX_RANDKSTACK if (X86_TSC && X86)
54712+ select PAX_SEGMEXEC if (X86_32)
54713+ select PAX_PAGEEXEC
54714+ select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
54715+ select PAX_EMUTRAMP if (PARISC)
54716+ select PAX_EMUSIGRT if (PARISC)
54717+ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
54718+ select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
54719+ select PAX_REFCOUNT if (X86 || SPARC64)
54720+ select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
54721+ help
54722+ If you say Y here, many of the features of grsecurity will be
54723+ enabled, which will protect you against many kinds of attacks
54724+ against your system. The heightened security comes at a cost
54725+ of an increased chance of incompatibilities with rare software
54726+ on your machine. Since this security level enables PaX, you should
54727+ view <http://pax.grsecurity.net> and read about the PaX
54728+ project. While you are there, download chpax and run it on
54729+ binaries that cause problems with PaX. Also remember that
54730+ since the /proc restrictions are enabled, you must run your
54731+ identd as gid 1001. This security level enables the following
54732+ features in addition to those listed in the low and medium
54733+ security levels:
54734+
54735+ - Additional /proc restrictions
54736+ - Chmod restrictions in chroot
54737+ - No signals, ptrace, or viewing of processes outside of chroot
54738+ - Capability restrictions in chroot
54739+ - Deny fchdir out of chroot
54740+ - Priority restrictions in chroot
54741+ - Segmentation-based implementation of PaX
54742+ - Mprotect restrictions
54743+ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
54744+ - Kernel stack randomization
54745+ - Mount/unmount/remount logging
54746+ - Kernel symbol hiding
54747+ - Hardening of module auto-loading
54748+ - Ptrace restrictions
54749+ - Restricted vm86 mode
54750+ - Restricted sysfs/debugfs
54751+ - Active kernel exploit response
54752+
54753+config GRKERNSEC_CUSTOM
54754+ bool "Custom"
54755+ help
54756+ If you say Y here, you will be able to configure every grsecurity
54757+ option, which allows you to enable many more features that aren't
54758+ covered in the basic security levels. These additional features
54759+ include TPE, socket restrictions, and the sysctl system for
54760+ grsecurity. It is advised that you read through the help for
54761+ each option to determine its usefulness in your situation.
54762+
54763+endchoice
54764+
54765+menu "Address Space Protection"
54766+depends on GRKERNSEC
54767+
54768+config GRKERNSEC_KMEM
54769+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
54770+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
54771+ help
54772+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
54773+ be written to or read from to modify or leak the contents of the running
54774+ kernel. /dev/port will also not be allowed to be opened. If you have module
54775+ support disabled, enabling this will close up four ways that are
54776+ currently used to insert malicious code into the running kernel.
54777+ Even with all these features enabled, we still highly recommend that
54778+ you use the RBAC system, as it is still possible for an attacker to
54779+ modify the running kernel through privileged I/O granted by ioperm/iopl.
54780+ If you are not using XFree86, you may be able to stop this additional
54781+ case by enabling the 'Disable privileged I/O' option. Though nothing
54782+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
54783+ but only to video memory, which is the only writing we allow in this
54784+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
54785+ not be allowed to mprotect it with PROT_WRITE later.
54786+ It is highly recommended that you say Y here if you meet all the
54787+ conditions above.
54788+
54789+config GRKERNSEC_VM86
54790+ bool "Restrict VM86 mode"
54791+ depends on X86_32
54792+
54793+ help
54794+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
54795+ make use of a special execution mode on 32bit x86 processors called
54796+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
54797+ video cards and will still work with this option enabled. The purpose
54798+ of the option is to prevent exploitation of emulation errors in
54799+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
54800+ Nearly all users should be able to enable this option.
54801+
54802+config GRKERNSEC_IO
54803+ bool "Disable privileged I/O"
54804+ depends on X86
54805+ select RTC_CLASS
54806+ select RTC_INTF_DEV
54807+ select RTC_DRV_CMOS
54808+
54809+ help
54810+ If you say Y here, all ioperm and iopl calls will return an error.
54811+ Ioperm and iopl can be used to modify the running kernel.
54812+ Unfortunately, some programs need this access to operate properly,
54813+ the most notable of which are XFree86 and hwclock. hwclock can be
54814+ remedied by having RTC support in the kernel, so real-time
54815+ clock support is enabled if this option is enabled, to ensure
54816+ that hwclock operates correctly. XFree86 still will not
54817+ operate correctly with this option enabled, so DO NOT CHOOSE Y
54818+ IF YOU USE XFree86. If you use XFree86 and you still want to
54819+ protect your kernel against modification, use the RBAC system.
54820+
54821+config GRKERNSEC_PROC_MEMMAP
54822+ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
54823+ default y if (PAX_NOEXEC || PAX_ASLR)
54824+ depends on PAX_NOEXEC || PAX_ASLR
54825+ help
54826+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
54827+ give no information about the addresses of its mappings if
54828+ PaX features that rely on random addresses are enabled on the task.
54829+ If you use PaX it is greatly recommended that you say Y here as it
54830+ closes up a hole that makes the full ASLR useless for suid
54831+ binaries.
54832+
54833+config GRKERNSEC_BRUTE
54834+ bool "Deter exploit bruteforcing"
54835+ help
54836+ If you say Y here, attempts to bruteforce exploits against forking
54837+ daemons such as apache or sshd, as well as against suid/sgid binaries
54838+ will be deterred. When a child of a forking daemon is killed by PaX
54839+ or crashes due to an illegal instruction or other suspicious signal,
54840+ the parent process will be delayed 30 seconds upon every subsequent
54841+ fork until the administrator is able to assess the situation and
54842+ restart the daemon.
54843+ In the suid/sgid case, the attempt is logged, the user has all their
54844+ processes terminated, and they are prevented from executing any further
54845+ processes for 15 minutes.
54846+ It is recommended that you also enable signal logging in the auditing
54847+ section so that logs are generated when a process triggers a suspicious
54848+ signal.
54849+ If the sysctl option is enabled, a sysctl option with name
54850+ "deter_bruteforce" is created.
54851+
54852+config GRKERNSEC_MODHARDEN
54853+ bool "Harden module auto-loading"
54854+ depends on MODULES
54855+ help
54856+ If you say Y here, module auto-loading in response to use of some
54857+ feature implemented by an unloaded module will be restricted to
54858+ root users. Enabling this option helps defend against attacks
54859+ by unprivileged users who abuse the auto-loading behavior to
54860+ cause a vulnerable module to load that is then exploited.
54861+
54862+ If this option prevents a legitimate use of auto-loading for a
54863+ non-root user, the administrator can execute modprobe manually
54864+ with the exact name of the module mentioned in the alert log.
54865+ Alternatively, the administrator can add the module to the list
54866+ of modules loaded at boot by modifying init scripts.
54867+
54868+ Modification of init scripts will most likely be needed on
54869+ Ubuntu servers with encrypted home directory support enabled,
54870+ as the first non-root user logging in will cause the ecb(aes),
54871+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
54872+
54873+config GRKERNSEC_HIDESYM
54874+ bool "Hide kernel symbols"
54875+ help
54876+ If you say Y here, getting information on loaded modules, and
54877+ displaying all kernel symbols through a syscall will be restricted
54878+ to users with CAP_SYS_MODULE. For software compatibility reasons,
54879+ /proc/kallsyms will be restricted to the root user. The RBAC
54880+ system can hide that entry even from root.
54881+
54882+ This option also prevents leaking of kernel addresses through
54883+ several /proc entries.
54884+
54885+ Note that this option is only effective provided the following
54886+ conditions are met:
54887+ 1) The kernel using grsecurity is not precompiled by some distribution
54888+ 2) You have also enabled GRKERNSEC_DMESG
54889+ 3) You are using the RBAC system and hiding other files such as your
54890+ kernel image and System.map. Alternatively, enabling this option
54891+ causes the permissions on /boot, /lib/modules, and the kernel
54892+ source directory to change at compile time to prevent
54893+ reading by non-root users.
54894+ If the above conditions are met, this option will aid in providing a
54895+ useful protection against local kernel exploitation of overflows
54896+ and arbitrary read/write vulnerabilities.
54897+
54898+config GRKERNSEC_KERN_LOCKOUT
54899+ bool "Active kernel exploit response"
54900+ depends on X86 || ARM || PPC || SPARC
54901+ help
54902+ If you say Y here, when a PaX alert is triggered due to suspicious
54903+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
54904+ or an OOPs occurs due to bad memory accesses, instead of just
54905+ terminating the offending process (and potentially allowing
54906+ a subsequent exploit from the same user), we will take one of two
54907+ actions:
54908+ If the user was root, we will panic the system
54909+ If the user was non-root, we will log the attempt, terminate
54910+ all processes owned by the user, then prevent them from creating
54911+ any new processes until the system is restarted
54912+ This deters repeated kernel exploitation/bruteforcing attempts
54913+ and is useful for later forensics.
54914+
54915+endmenu
54916+menu "Role Based Access Control Options"
54917+depends on GRKERNSEC
54918+
54919+config GRKERNSEC_RBAC_DEBUG
54920+ bool
54921+
54922+config GRKERNSEC_NO_RBAC
54923+ bool "Disable RBAC system"
54924+ help
54925+ If you say Y here, the /dev/grsec device will be removed from the kernel,
54926+ preventing the RBAC system from being enabled. You should only say Y
54927+ here if you have no intention of using the RBAC system, so as to prevent
54928+ an attacker with root access from misusing the RBAC system to hide files
54929+ and processes when loadable module support and /dev/[k]mem have been
54930+ locked down.
54931+
54932+config GRKERNSEC_ACL_HIDEKERN
54933+ bool "Hide kernel processes"
54934+ help
54935+ If you say Y here, all kernel threads will be hidden to all
54936+ processes but those whose subject has the "view hidden processes"
54937+ flag.
54938+
54939+config GRKERNSEC_ACL_MAXTRIES
54940+ int "Maximum tries before password lockout"
54941+ default 3
54942+ help
54943+ This option enforces the maximum number of times a user can attempt
54944+ to authorize themselves with the grsecurity RBAC system before being
54945+ denied the ability to attempt authorization again for a specified time.
54946+ The lower the number, the harder it will be to brute-force a password.
54947+
54948+config GRKERNSEC_ACL_TIMEOUT
54949+ int "Time to wait after max password tries, in seconds"
54950+ default 30
54951+ help
54952+ This option specifies the time the user must wait after attempting to
54953+ authorize to the RBAC system with the maximum number of invalid
54954+ passwords. The higher the number, the harder it will be to brute-force
54955+ a password.
54956+
54957+endmenu
54958+menu "Filesystem Protections"
54959+depends on GRKERNSEC
54960+
54961+config GRKERNSEC_PROC
54962+ bool "Proc restrictions"
54963+ help
54964+ If you say Y here, the permissions of the /proc filesystem
54965+ will be altered to enhance system security and privacy. You MUST
54966+ choose either a user only restriction or a user and group restriction.
54967+ Depending upon the option you choose, you can either restrict users to
54968+ see only the processes they themselves run, or choose a group that can
54969+ view all processes and files normally restricted to root if you choose
54970+ the "restrict to user only" option. NOTE: If you're running identd as
54971+ a non-root user, you will have to run it as the group you specify here.
54972+
54973+config GRKERNSEC_PROC_USER
54974+ bool "Restrict /proc to user only"
54975+ depends on GRKERNSEC_PROC
54976+ help
54977+ If you say Y here, non-root users will only be able to view their own
54978+ processes, and restricts them from viewing network-related information,
54979+ and viewing kernel symbol and module information.
54980+
54981+config GRKERNSEC_PROC_USERGROUP
54982+ bool "Allow special group"
54983+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
54984+ help
54985+ If you say Y here, you will be able to select a group that will be
54986+ able to view all processes and network-related information. If you've
54987+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
54988+ remain hidden. This option is useful if you want to run identd as
54989+ a non-root user.
54990+
54991+config GRKERNSEC_PROC_GID
54992+ int "GID for special group"
54993+ depends on GRKERNSEC_PROC_USERGROUP
54994+ default 1001
54995+
54996+config GRKERNSEC_PROC_ADD
54997+ bool "Additional restrictions"
54998+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
54999+ help
55000+ If you say Y here, additional restrictions will be placed on
55001+ /proc that keep normal users from viewing device information and
55002+ slabinfo information that could be useful for exploits.
55003+
55004+config GRKERNSEC_LINK
55005+ bool "Linking restrictions"
55006+ help
55007+ If you say Y here, /tmp race exploits will be prevented, since users
55008+ will no longer be able to follow symlinks owned by other users in
55009+ world-writable +t directories (e.g. /tmp), unless the owner of the
55010+ symlink is the owner of the directory. users will also not be
55011+ able to hardlink to files they do not own. If the sysctl option is
55012+ enabled, a sysctl option with name "linking_restrictions" is created.
55013+
55014+config GRKERNSEC_FIFO
55015+ bool "FIFO restrictions"
55016+ help
55017+ If you say Y here, users will not be able to write to FIFOs they don't
55018+ own in world-writable +t directories (e.g. /tmp), unless the owner of
55019+ the FIFO is the same owner of the directory it's held in. If the sysctl
55020+ option is enabled, a sysctl option with name "fifo_restrictions" is
55021+ created.
55022+
55023+config GRKERNSEC_SYSFS_RESTRICT
55024+ bool "Sysfs/debugfs restriction"
55025+ depends on SYSFS
55026+ help
55027+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
55028+ any filesystem normally mounted under it (e.g. debugfs) will only
55029+ be accessible by root. These filesystems generally provide access
55030+ to hardware and debug information that isn't appropriate for unprivileged
55031+ users of the system. Sysfs and debugfs have also become a large source
55032+ of new vulnerabilities, ranging from infoleaks to local compromise.
55033+ There has been very little oversight with an eye toward security involved
55034+ in adding new exporters of information to these filesystems, so their
55035+ use is discouraged.
55036+ This option is equivalent to a chmod 0700 of the mount paths.
55037+
55038+config GRKERNSEC_ROFS
55039+ bool "Runtime read-only mount protection"
55040+ help
55041+ If you say Y here, a sysctl option with name "romount_protect" will
55042+ be created. By setting this option to 1 at runtime, filesystems
55043+ will be protected in the following ways:
55044+ * No new writable mounts will be allowed
55045+ * Existing read-only mounts won't be able to be remounted read/write
55046+ * Write operations will be denied on all block devices
55047+ This option acts independently of grsec_lock: once it is set to 1,
55048+ it cannot be turned off. Therefore, please be mindful of the resulting
55049+ behavior if this option is enabled in an init script on a read-only
55050+ filesystem. This feature is mainly intended for secure embedded systems.
55051+
55052+config GRKERNSEC_CHROOT
55053+ bool "Chroot jail restrictions"
55054+ help
55055+ If you say Y here, you will be able to choose several options that will
55056+ make breaking out of a chrooted jail much more difficult. If you
55057+ encounter no software incompatibilities with the following options, it
55058+ is recommended that you enable each one.
55059+
55060+config GRKERNSEC_CHROOT_MOUNT
55061+ bool "Deny mounts"
55062+ depends on GRKERNSEC_CHROOT
55063+ help
55064+ If you say Y here, processes inside a chroot will not be able to
55065+ mount or remount filesystems. If the sysctl option is enabled, a
55066+ sysctl option with name "chroot_deny_mount" is created.
55067+
55068+config GRKERNSEC_CHROOT_DOUBLE
55069+ bool "Deny double-chroots"
55070+ depends on GRKERNSEC_CHROOT
55071+ help
55072+ If you say Y here, processes inside a chroot will not be able to chroot
55073+ again outside the chroot. This is a widely used method of breaking
55074+ out of a chroot jail and should not be allowed. If the sysctl
55075+ option is enabled, a sysctl option with name
55076+ "chroot_deny_chroot" is created.
55077+
55078+config GRKERNSEC_CHROOT_PIVOT
55079+ bool "Deny pivot_root in chroot"
55080+ depends on GRKERNSEC_CHROOT
55081+ help
55082+ If you say Y here, processes inside a chroot will not be able to use
55083+ a function called pivot_root() that was introduced in Linux 2.3.41. It
55084+ works similar to chroot in that it changes the root filesystem. This
55085+ function could be misused in a chrooted process to attempt to break out
55086+ of the chroot, and therefore should not be allowed. If the sysctl
55087+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
55088+ created.
55089+
55090+config GRKERNSEC_CHROOT_CHDIR
55091+ bool "Enforce chdir(\"/\") on all chroots"
55092+ depends on GRKERNSEC_CHROOT
55093+ help
55094+ If you say Y here, the current working directory of all newly-chrooted
55095+ applications will be set to the the root directory of the chroot.
55096+ The man page on chroot(2) states:
55097+ Note that this call does not change the current working
55098+ directory, so that `.' can be outside the tree rooted at
55099+ `/'. In particular, the super-user can escape from a
55100+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
55101+
55102+ It is recommended that you say Y here, since it's not known to break
55103+ any software. If the sysctl option is enabled, a sysctl option with
55104+ name "chroot_enforce_chdir" is created.
55105+
55106+config GRKERNSEC_CHROOT_CHMOD
55107+ bool "Deny (f)chmod +s"
55108+ depends on GRKERNSEC_CHROOT
55109+ help
55110+ If you say Y here, processes inside a chroot will not be able to chmod
55111+ or fchmod files to make them have suid or sgid bits. This protects
55112+ against another published method of breaking a chroot. If the sysctl
55113+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
55114+ created.
55115+
55116+config GRKERNSEC_CHROOT_FCHDIR
55117+ bool "Deny fchdir out of chroot"
55118+ depends on GRKERNSEC_CHROOT
55119+ help
55120+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
55121+ to a file descriptor of the chrooting process that points to a directory
55122+ outside the filesystem will be stopped. If the sysctl option
55123+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
55124+
55125+config GRKERNSEC_CHROOT_MKNOD
55126+ bool "Deny mknod"
55127+ depends on GRKERNSEC_CHROOT
55128+ help
55129+ If you say Y here, processes inside a chroot will not be allowed to
55130+ mknod. The problem with using mknod inside a chroot is that it
55131+ would allow an attacker to create a device entry that is the same
55132+ as one on the physical root of your system, which could range from
55133+ anything from the console device to a device for your harddrive (which
55134+ they could then use to wipe the drive or steal data). It is recommended
55135+ that you say Y here, unless you run into software incompatibilities.
55136+ If the sysctl option is enabled, a sysctl option with name
55137+ "chroot_deny_mknod" is created.
55138+
55139+config GRKERNSEC_CHROOT_SHMAT
55140+ bool "Deny shmat() out of chroot"
55141+ depends on GRKERNSEC_CHROOT
55142+ help
55143+ If you say Y here, processes inside a chroot will not be able to attach
55144+ to shared memory segments that were created outside of the chroot jail.
55145+ It is recommended that you say Y here. If the sysctl option is enabled,
55146+ a sysctl option with name "chroot_deny_shmat" is created.
55147+
55148+config GRKERNSEC_CHROOT_UNIX
55149+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
55150+ depends on GRKERNSEC_CHROOT
55151+ help
55152+ If you say Y here, processes inside a chroot will not be able to
55153+ connect to abstract (meaning not belonging to a filesystem) Unix
55154+ domain sockets that were bound outside of a chroot. It is recommended
55155+ that you say Y here. If the sysctl option is enabled, a sysctl option
55156+ with name "chroot_deny_unix" is created.
55157+
55158+config GRKERNSEC_CHROOT_FINDTASK
55159+ bool "Protect outside processes"
55160+ depends on GRKERNSEC_CHROOT
55161+ help
55162+ If you say Y here, processes inside a chroot will not be able to
55163+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
55164+ getsid, or view any process outside of the chroot. If the sysctl
55165+ option is enabled, a sysctl option with name "chroot_findtask" is
55166+ created.
55167+
55168+config GRKERNSEC_CHROOT_NICE
55169+ bool "Restrict priority changes"
55170+ depends on GRKERNSEC_CHROOT
55171+ help
55172+ If you say Y here, processes inside a chroot will not be able to raise
55173+ the priority of processes in the chroot, or alter the priority of
55174+ processes outside the chroot. This provides more security than simply
55175+ removing CAP_SYS_NICE from the process' capability set. If the
55176+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
55177+ is created.
55178+
55179+config GRKERNSEC_CHROOT_SYSCTL
55180+ bool "Deny sysctl writes"
55181+ depends on GRKERNSEC_CHROOT
55182+ help
55183+ If you say Y here, an attacker in a chroot will not be able to
55184+ write to sysctl entries, either by sysctl(2) or through a /proc
55185+ interface. It is strongly recommended that you say Y here. If the
55186+ sysctl option is enabled, a sysctl option with name
55187+ "chroot_deny_sysctl" is created.
55188+
55189+config GRKERNSEC_CHROOT_CAPS
55190+ bool "Capability restrictions"
55191+ depends on GRKERNSEC_CHROOT
55192+ help
55193+ If you say Y here, the capabilities on all processes within a
55194+ chroot jail will be lowered to stop module insertion, raw i/o,
55195+ system and net admin tasks, rebooting the system, modifying immutable
55196+ files, modifying IPC owned by another, and changing the system time.
55197+ This is left an option because it can break some apps. Disable this
55198+ if your chrooted apps are having problems performing those kinds of
55199+ tasks. If the sysctl option is enabled, a sysctl option with
55200+ name "chroot_caps" is created.
55201+
55202+endmenu
55203+menu "Kernel Auditing"
55204+depends on GRKERNSEC
55205+
55206+config GRKERNSEC_AUDIT_GROUP
55207+ bool "Single group for auditing"
55208+ help
55209+ If you say Y here, the exec, chdir, and (un)mount logging features
55210+ will only operate on a group you specify. This option is recommended
55211+ if you only want to watch certain users instead of having a large
55212+ amount of logs from the entire system. If the sysctl option is enabled,
55213+ a sysctl option with name "audit_group" is created.
55214+
55215+config GRKERNSEC_AUDIT_GID
55216+ int "GID for auditing"
55217+ depends on GRKERNSEC_AUDIT_GROUP
55218+ default 1007
55219+
55220+config GRKERNSEC_EXECLOG
55221+ bool "Exec logging"
55222+ help
55223+ If you say Y here, all execve() calls will be logged (since the
55224+ other exec*() calls are frontends to execve(), all execution
55225+ will be logged). Useful for shell-servers that like to keep track
55226+ of their users. If the sysctl option is enabled, a sysctl option with
55227+ name "exec_logging" is created.
55228+ WARNING: This option when enabled will produce a LOT of logs, especially
55229+ on an active system.
55230+
55231+config GRKERNSEC_RESLOG
55232+ bool "Resource logging"
55233+ help
55234+ If you say Y here, all attempts to overstep resource limits will
55235+ be logged with the resource name, the requested size, and the current
55236+ limit. It is highly recommended that you say Y here. If the sysctl
55237+ option is enabled, a sysctl option with name "resource_logging" is
55238+ created. If the RBAC system is enabled, the sysctl value is ignored.
55239+
55240+config GRKERNSEC_CHROOT_EXECLOG
55241+ bool "Log execs within chroot"
55242+ help
55243+ If you say Y here, all executions inside a chroot jail will be logged
55244+ to syslog. This can cause a large amount of logs if certain
55245+ applications (eg. djb's daemontools) are installed on the system, and
55246+ is therefore left as an option. If the sysctl option is enabled, a
55247+ sysctl option with name "chroot_execlog" is created.
55248+
55249+config GRKERNSEC_AUDIT_PTRACE
55250+ bool "Ptrace logging"
55251+ help
55252+ If you say Y here, all attempts to attach to a process via ptrace
55253+ will be logged. If the sysctl option is enabled, a sysctl option
55254+ with name "audit_ptrace" is created.
55255+
55256+config GRKERNSEC_AUDIT_CHDIR
55257+ bool "Chdir logging"
55258+ help
55259+ If you say Y here, all chdir() calls will be logged. If the sysctl
55260+ option is enabled, a sysctl option with name "audit_chdir" is created.
55261+
55262+config GRKERNSEC_AUDIT_MOUNT
55263+ bool "(Un)Mount logging"
55264+ help
55265+ If you say Y here, all mounts and unmounts will be logged. If the
55266+ sysctl option is enabled, a sysctl option with name "audit_mount" is
55267+ created.
55268+
55269+config GRKERNSEC_SIGNAL
55270+ bool "Signal logging"
55271+ help
55272+ If you say Y here, certain important signals will be logged, such as
55273+ SIGSEGV, which will as a result inform you of when a error in a program
55274+ occurred, which in some cases could mean a possible exploit attempt.
55275+ If the sysctl option is enabled, a sysctl option with name
55276+ "signal_logging" is created.
55277+
55278+config GRKERNSEC_FORKFAIL
55279+ bool "Fork failure logging"
55280+ help
55281+ If you say Y here, all failed fork() attempts will be logged.
55282+ This could suggest a fork bomb, or someone attempting to overstep
55283+ their process limit. If the sysctl option is enabled, a sysctl option
55284+ with name "forkfail_logging" is created.
55285+
55286+config GRKERNSEC_TIME
55287+ bool "Time change logging"
55288+ help
55289+ If you say Y here, any changes of the system clock will be logged.
55290+ If the sysctl option is enabled, a sysctl option with name
55291+ "timechange_logging" is created.
55292+
55293+config GRKERNSEC_PROC_IPADDR
55294+ bool "/proc/<pid>/ipaddr support"
55295+ help
55296+ If you say Y here, a new entry will be added to each /proc/<pid>
55297+ directory that contains the IP address of the person using the task.
55298+ The IP is carried across local TCP and AF_UNIX stream sockets.
55299+ This information can be useful for IDS/IPSes to perform remote response
55300+ to a local attack. The entry is readable by only the owner of the
55301+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
55302+ the RBAC system), and thus does not create privacy concerns.
55303+
55304+config GRKERNSEC_RWXMAP_LOG
55305+ bool 'Denied RWX mmap/mprotect logging'
55306+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
55307+ help
55308+ If you say Y here, calls to mmap() and mprotect() with explicit
55309+ usage of PROT_WRITE and PROT_EXEC together will be logged when
55310+ denied by the PAX_MPROTECT feature. If the sysctl option is
55311+ enabled, a sysctl option with name "rwxmap_logging" is created.
55312+
55313+config GRKERNSEC_AUDIT_TEXTREL
55314+ bool 'ELF text relocations logging (READ HELP)'
55315+ depends on PAX_MPROTECT
55316+ help
55317+ If you say Y here, text relocations will be logged with the filename
55318+ of the offending library or binary. The purpose of the feature is
55319+ to help Linux distribution developers get rid of libraries and
55320+ binaries that need text relocations which hinder the future progress
55321+ of PaX. Only Linux distribution developers should say Y here, and
55322+ never on a production machine, as this option creates an information
55323+ leak that could aid an attacker in defeating the randomization of
55324+ a single memory region. If the sysctl option is enabled, a sysctl
55325+ option with name "audit_textrel" is created.
55326+
55327+endmenu
55328+
55329+menu "Executable Protections"
55330+depends on GRKERNSEC
55331+
55332+config GRKERNSEC_DMESG
55333+ bool "Dmesg(8) restriction"
55334+ help
55335+ If you say Y here, non-root users will not be able to use dmesg(8)
55336+ to view up to the last 4kb of messages in the kernel's log buffer.
55337+ The kernel's log buffer often contains kernel addresses and other
55338+ identifying information useful to an attacker in fingerprinting a
55339+ system for a targeted exploit.
55340+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
55341+ created.
55342+
55343+config GRKERNSEC_HARDEN_PTRACE
55344+ bool "Deter ptrace-based process snooping"
55345+ help
55346+ If you say Y here, TTY sniffers and other malicious monitoring
55347+ programs implemented through ptrace will be defeated. If you
55348+ have been using the RBAC system, this option has already been
55349+ enabled for several years for all users, with the ability to make
55350+ fine-grained exceptions.
55351+
55352+ This option only affects the ability of non-root users to ptrace
55353+ processes that are not a descendent of the ptracing process.
55354+ This means that strace ./binary and gdb ./binary will still work,
55355+ but attaching to arbitrary processes will not. If the sysctl
55356+ option is enabled, a sysctl option with name "harden_ptrace" is
55357+ created.
55358+
55359+config GRKERNSEC_TPE
55360+ bool "Trusted Path Execution (TPE)"
55361+ help
55362+ If you say Y here, you will be able to choose a gid to add to the
55363+ supplementary groups of users you want to mark as "untrusted."
55364+ These users will not be able to execute any files that are not in
55365+ root-owned directories writable only by root. If the sysctl option
55366+ is enabled, a sysctl option with name "tpe" is created.
55367+
55368+config GRKERNSEC_TPE_ALL
55369+ bool "Partially restrict all non-root users"
55370+ depends on GRKERNSEC_TPE
55371+ help
55372+ If you say Y here, all non-root users will be covered under
55373+ a weaker TPE restriction. This is separate from, and in addition to,
55374+ the main TPE options that you have selected elsewhere. Thus, if a
55375+ "trusted" GID is chosen, this restriction applies to even that GID.
55376+ Under this restriction, all non-root users will only be allowed to
55377+ execute files in directories they own that are not group or
55378+ world-writable, or in directories owned by root and writable only by
55379+ root. If the sysctl option is enabled, a sysctl option with name
55380+ "tpe_restrict_all" is created.
55381+
55382+config GRKERNSEC_TPE_INVERT
55383+ bool "Invert GID option"
55384+ depends on GRKERNSEC_TPE
55385+ help
55386+ If you say Y here, the group you specify in the TPE configuration will
55387+ decide what group TPE restrictions will be *disabled* for. This
55388+ option is useful if you want TPE restrictions to be applied to most
55389+ users on the system. If the sysctl option is enabled, a sysctl option
55390+ with name "tpe_invert" is created. Unlike other sysctl options, this
55391+ entry will default to on for backward-compatibility.
55392+
55393+config GRKERNSEC_TPE_GID
55394+ int "GID for untrusted users"
55395+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
55396+ default 1005
55397+ help
55398+ Setting this GID determines what group TPE restrictions will be
55399+ *enabled* for. If the sysctl option is enabled, a sysctl option
55400+ with name "tpe_gid" is created.
55401+
55402+config GRKERNSEC_TPE_GID
55403+ int "GID for trusted users"
55404+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
55405+ default 1005
55406+ help
55407+ Setting this GID determines what group TPE restrictions will be
55408+ *disabled* for. If the sysctl option is enabled, a sysctl option
55409+ with name "tpe_gid" is created.
55410+
55411+endmenu
55412+menu "Network Protections"
55413+depends on GRKERNSEC
55414+
55415+config GRKERNSEC_RANDNET
55416+ bool "Larger entropy pools"
55417+ help
55418+ If you say Y here, the entropy pools used for many features of Linux
55419+ and grsecurity will be doubled in size. Since several grsecurity
55420+ features use additional randomness, it is recommended that you say Y
55421+ here. Saying Y here has a similar effect as modifying
55422+ /proc/sys/kernel/random/poolsize.
55423+
55424+config GRKERNSEC_BLACKHOLE
55425+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
55426+ depends on NET
55427+ help
55428+ If you say Y here, neither TCP resets nor ICMP
55429+ destination-unreachable packets will be sent in response to packets
55430+ sent to ports for which no associated listening process exists.
55431+ This feature supports both IPV4 and IPV6 and exempts the
55432+ loopback interface from blackholing. Enabling this feature
55433+ makes a host more resilient to DoS attacks and reduces network
55434+ visibility against scanners.
55435+
55436+ The blackhole feature as-implemented is equivalent to the FreeBSD
55437+ blackhole feature, as it prevents RST responses to all packets, not
55438+ just SYNs. Under most application behavior this causes no
55439+ problems, but applications (like haproxy) may not close certain
55440+ connections in a way that cleanly terminates them on the remote
55441+ end, leaving the remote host in LAST_ACK state. Because of this
55442+ side-effect and to prevent intentional LAST_ACK DoSes, this
55443+ feature also adds automatic mitigation against such attacks.
55444+ The mitigation drastically reduces the amount of time a socket
55445+ can spend in LAST_ACK state. If you're using haproxy and not
55446+ all servers it connects to have this option enabled, consider
55447+ disabling this feature on the haproxy host.
55448+
55449+ If the sysctl option is enabled, two sysctl options with names
55450+ "ip_blackhole" and "lastack_retries" will be created.
55451+ While "ip_blackhole" takes the standard zero/non-zero on/off
55452+ toggle, "lastack_retries" uses the same kinds of values as
55453+ "tcp_retries1" and "tcp_retries2". The default value of 4
55454+ prevents a socket from lasting more than 45 seconds in LAST_ACK
55455+ state.
55456+
55457+config GRKERNSEC_SOCKET
55458+ bool "Socket restrictions"
55459+ depends on NET
55460+ help
55461+ If you say Y here, you will be able to choose from several options.
55462+ If you assign a GID on your system and add it to the supplementary
55463+ groups of users you want to restrict socket access to, this patch
55464+ will perform up to three things, based on the option(s) you choose.
55465+
55466+config GRKERNSEC_SOCKET_ALL
55467+ bool "Deny any sockets to group"
55468+ depends on GRKERNSEC_SOCKET
55469+ help
55470+ If you say Y here, you will be able to choose a GID of whose users will
55471+ be unable to connect to other hosts from your machine or run server
55472+ applications from your machine. If the sysctl option is enabled, a
55473+ sysctl option with name "socket_all" is created.
55474+
55475+config GRKERNSEC_SOCKET_ALL_GID
55476+ int "GID to deny all sockets for"
55477+ depends on GRKERNSEC_SOCKET_ALL
55478+ default 1004
55479+ help
55480+ Here you can choose the GID to disable socket access for. Remember to
55481+ add the users you want socket access disabled for to the GID
55482+ specified here. If the sysctl option is enabled, a sysctl option
55483+ with name "socket_all_gid" is created.
55484+
55485+config GRKERNSEC_SOCKET_CLIENT
55486+ bool "Deny client sockets to group"
55487+ depends on GRKERNSEC_SOCKET
55488+ help
55489+ If you say Y here, you will be able to choose a GID of whose users will
55490+ be unable to connect to other hosts from your machine, but will be
55491+ able to run servers. If this option is enabled, all users in the group
55492+ you specify will have to use passive mode when initiating ftp transfers
55493+ from the shell on your machine. If the sysctl option is enabled, a
55494+ sysctl option with name "socket_client" is created.
55495+
55496+config GRKERNSEC_SOCKET_CLIENT_GID
55497+ int "GID to deny client sockets for"
55498+ depends on GRKERNSEC_SOCKET_CLIENT
55499+ default 1003
55500+ help
55501+ Here you can choose the GID to disable client socket access for.
55502+ Remember to add the users you want client socket access disabled for to
55503+ the GID specified here. If the sysctl option is enabled, a sysctl
55504+ option with name "socket_client_gid" is created.
55505+
55506+config GRKERNSEC_SOCKET_SERVER
55507+ bool "Deny server sockets to group"
55508+ depends on GRKERNSEC_SOCKET
55509+ help
55510+ If you say Y here, you will be able to choose a GID of whose users will
55511+ be unable to run server applications from your machine. If the sysctl
55512+ option is enabled, a sysctl option with name "socket_server" is created.
55513+
55514+config GRKERNSEC_SOCKET_SERVER_GID
55515+ int "GID to deny server sockets for"
55516+ depends on GRKERNSEC_SOCKET_SERVER
55517+ default 1002
55518+ help
55519+ Here you can choose the GID to disable server socket access for.
55520+ Remember to add the users you want server socket access disabled for to
55521+ the GID specified here. If the sysctl option is enabled, a sysctl
55522+ option with name "socket_server_gid" is created.
55523+
55524+endmenu
55525+menu "Sysctl support"
55526+depends on GRKERNSEC && SYSCTL
55527+
55528+config GRKERNSEC_SYSCTL
55529+ bool "Sysctl support"
55530+ help
55531+ If you say Y here, you will be able to change the options that
55532+ grsecurity runs with at bootup, without having to recompile your
55533+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
55534+ to enable (1) or disable (0) various features. All the sysctl entries
55535+ are mutable until the "grsec_lock" entry is set to a non-zero value.
55536+ All features enabled in the kernel configuration are disabled at boot
55537+ if you do not say Y to the "Turn on features by default" option.
55538+ All options should be set at startup, and the grsec_lock entry should
55539+ be set to a non-zero value after all the options are set.
55540+ *THIS IS EXTREMELY IMPORTANT*
55541+
55542+config GRKERNSEC_SYSCTL_DISTRO
55543+ bool "Extra sysctl support for distro makers (READ HELP)"
55544+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
55545+ help
55546+ If you say Y here, additional sysctl options will be created
55547+ for features that affect processes running as root. Therefore,
55548+ it is critical when using this option that the grsec_lock entry be
55549+ enabled after boot. Only distros with prebuilt kernel packages
55550+ with this option enabled that can ensure grsec_lock is enabled
55551+ after boot should use this option.
55552+ *Failure to set grsec_lock after boot makes all grsec features
55553+ this option covers useless*
55554+
55555+ Currently this option creates the following sysctl entries:
55556+ "Disable Privileged I/O": "disable_priv_io"
55557+
55558+config GRKERNSEC_SYSCTL_ON
55559+ bool "Turn on features by default"
55560+ depends on GRKERNSEC_SYSCTL
55561+ help
55562+ If you say Y here, instead of having all features enabled in the
55563+ kernel configuration disabled at boot time, the features will be
55564+ enabled at boot time. It is recommended you say Y here unless
55565+ there is some reason you would want all sysctl-tunable features to
55566+ be disabled by default. As mentioned elsewhere, it is important
55567+ to enable the grsec_lock entry once you have finished modifying
55568+ the sysctl entries.
55569+
55570+endmenu
55571+menu "Logging Options"
55572+depends on GRKERNSEC
55573+
55574+config GRKERNSEC_FLOODTIME
55575+ int "Seconds in between log messages (minimum)"
55576+ default 10
55577+ help
55578+ This option allows you to enforce the number of seconds between
55579+ grsecurity log messages. The default should be suitable for most
55580+ people, however, if you choose to change it, choose a value small enough
55581+ to allow informative logs to be produced, but large enough to
55582+ prevent flooding.
55583+
55584+config GRKERNSEC_FLOODBURST
55585+ int "Number of messages in a burst (maximum)"
55586+ default 6
55587+ help
55588+ This option allows you to choose the maximum number of messages allowed
55589+ within the flood time interval you chose in a separate option. The
55590+ default should be suitable for most people, however if you find that
55591+ many of your logs are being interpreted as flooding, you may want to
55592+ raise this value.
55593+
55594+endmenu
55595+
55596+endmenu
55597diff --git a/grsecurity/Makefile b/grsecurity/Makefile
55598new file mode 100644
55599index 0000000..be9ae3a
55600--- /dev/null
55601+++ b/grsecurity/Makefile
55602@@ -0,0 +1,36 @@
55603+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
55604+# during 2001-2009 it has been completely redesigned by Brad Spengler
55605+# into an RBAC system
55606+#
55607+# All code in this directory and various hooks inserted throughout the kernel
55608+# are copyright Brad Spengler - Open Source Security, Inc., and released
55609+# under the GPL v2 or higher
55610+
55611+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
55612+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
55613+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
55614+
55615+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
55616+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
55617+ gracl_learn.o grsec_log.o
55618+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
55619+
55620+ifdef CONFIG_NET
55621+obj-y += grsec_sock.o
55622+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
55623+endif
55624+
55625+ifndef CONFIG_GRKERNSEC
55626+obj-y += grsec_disabled.o
55627+endif
55628+
55629+ifdef CONFIG_GRKERNSEC_HIDESYM
55630+extra-y := grsec_hidesym.o
55631+$(obj)/grsec_hidesym.o:
55632+ @-chmod -f 500 /boot
55633+ @-chmod -f 500 /lib/modules
55634+ @-chmod -f 500 /lib64/modules
55635+ @-chmod -f 500 /lib32/modules
55636+ @-chmod -f 700 .
55637+ @echo ' grsec: protected kernel image paths'
55638+endif
55639diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
55640new file mode 100644
55641index 0000000..6bd68d6
55642--- /dev/null
55643+++ b/grsecurity/gracl.c
55644@@ -0,0 +1,4141 @@
55645+#include <linux/kernel.h>
55646+#include <linux/module.h>
55647+#include <linux/sched.h>
55648+#include <linux/mm.h>
55649+#include <linux/file.h>
55650+#include <linux/fs.h>
55651+#include <linux/namei.h>
55652+#include <linux/mount.h>
55653+#include <linux/tty.h>
55654+#include <linux/proc_fs.h>
55655+#include <linux/smp_lock.h>
55656+#include <linux/slab.h>
55657+#include <linux/vmalloc.h>
55658+#include <linux/types.h>
55659+#include <linux/sysctl.h>
55660+#include <linux/netdevice.h>
55661+#include <linux/ptrace.h>
55662+#include <linux/gracl.h>
55663+#include <linux/gralloc.h>
55664+#include <linux/grsecurity.h>
55665+#include <linux/grinternal.h>
55666+#include <linux/pid_namespace.h>
55667+#include <linux/fdtable.h>
55668+#include <linux/percpu.h>
55669+
55670+#include <asm/uaccess.h>
55671+#include <asm/errno.h>
55672+#include <asm/mman.h>
55673+
55674+static struct acl_role_db acl_role_set;
55675+static struct name_db name_set;
55676+static struct inodev_db inodev_set;
55677+
55678+/* for keeping track of userspace pointers used for subjects, so we
55679+ can share references in the kernel as well
55680+*/
55681+
55682+static struct dentry *real_root;
55683+static struct vfsmount *real_root_mnt;
55684+
55685+static struct acl_subj_map_db subj_map_set;
55686+
55687+static struct acl_role_label *default_role;
55688+
55689+static struct acl_role_label *role_list;
55690+
55691+static u16 acl_sp_role_value;
55692+
55693+extern char *gr_shared_page[4];
55694+static DEFINE_MUTEX(gr_dev_mutex);
55695+DEFINE_RWLOCK(gr_inode_lock);
55696+
55697+struct gr_arg *gr_usermode;
55698+
55699+static unsigned int gr_status __read_only = GR_STATUS_INIT;
55700+
55701+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
55702+extern void gr_clear_learn_entries(void);
55703+
55704+#ifdef CONFIG_GRKERNSEC_RESLOG
55705+extern void gr_log_resource(const struct task_struct *task,
55706+ const int res, const unsigned long wanted, const int gt);
55707+#endif
55708+
55709+unsigned char *gr_system_salt;
55710+unsigned char *gr_system_sum;
55711+
55712+static struct sprole_pw **acl_special_roles = NULL;
55713+static __u16 num_sprole_pws = 0;
55714+
55715+static struct acl_role_label *kernel_role = NULL;
55716+
55717+static unsigned int gr_auth_attempts = 0;
55718+static unsigned long gr_auth_expires = 0UL;
55719+
55720+#ifdef CONFIG_NET
55721+extern struct vfsmount *sock_mnt;
55722+#endif
55723+extern struct vfsmount *pipe_mnt;
55724+extern struct vfsmount *shm_mnt;
55725+#ifdef CONFIG_HUGETLBFS
55726+extern struct vfsmount *hugetlbfs_vfsmount;
55727+#endif
55728+
55729+static struct acl_object_label *fakefs_obj_rw;
55730+static struct acl_object_label *fakefs_obj_rwx;
55731+
55732+extern int gr_init_uidset(void);
55733+extern void gr_free_uidset(void);
55734+extern void gr_remove_uid(uid_t uid);
55735+extern int gr_find_uid(uid_t uid);
55736+
55737+__inline__ int
55738+gr_acl_is_enabled(void)
55739+{
55740+ return (gr_status & GR_READY);
55741+}
55742+
55743+#ifdef CONFIG_BTRFS_FS
55744+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
55745+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
55746+#endif
55747+
55748+static inline dev_t __get_dev(const struct dentry *dentry)
55749+{
55750+#ifdef CONFIG_BTRFS_FS
55751+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
55752+ return get_btrfs_dev_from_inode(dentry->d_inode);
55753+ else
55754+#endif
55755+ return dentry->d_inode->i_sb->s_dev;
55756+}
55757+
55758+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
55759+{
55760+ return __get_dev(dentry);
55761+}
55762+
55763+static char gr_task_roletype_to_char(struct task_struct *task)
55764+{
55765+ switch (task->role->roletype &
55766+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
55767+ GR_ROLE_SPECIAL)) {
55768+ case GR_ROLE_DEFAULT:
55769+ return 'D';
55770+ case GR_ROLE_USER:
55771+ return 'U';
55772+ case GR_ROLE_GROUP:
55773+ return 'G';
55774+ case GR_ROLE_SPECIAL:
55775+ return 'S';
55776+ }
55777+
55778+ return 'X';
55779+}
55780+
55781+char gr_roletype_to_char(void)
55782+{
55783+ return gr_task_roletype_to_char(current);
55784+}
55785+
55786+__inline__ int
55787+gr_acl_tpe_check(void)
55788+{
55789+ if (unlikely(!(gr_status & GR_READY)))
55790+ return 0;
55791+ if (current->role->roletype & GR_ROLE_TPE)
55792+ return 1;
55793+ else
55794+ return 0;
55795+}
55796+
55797+int
55798+gr_handle_rawio(const struct inode *inode)
55799+{
55800+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55801+ if (inode && S_ISBLK(inode->i_mode) &&
55802+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
55803+ !capable(CAP_SYS_RAWIO))
55804+ return 1;
55805+#endif
55806+ return 0;
55807+}
55808+
55809+static int
55810+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
55811+{
55812+ if (likely(lena != lenb))
55813+ return 0;
55814+
55815+ return !memcmp(a, b, lena);
55816+}
55817+
55818+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
55819+{
55820+ *buflen -= namelen;
55821+ if (*buflen < 0)
55822+ return -ENAMETOOLONG;
55823+ *buffer -= namelen;
55824+ memcpy(*buffer, str, namelen);
55825+ return 0;
55826+}
55827+
55828+/* this must be called with vfsmount_lock and dcache_lock held */
55829+
55830+static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
55831+ struct dentry *root, struct vfsmount *rootmnt,
55832+ char *buffer, int buflen)
55833+{
55834+ char * end = buffer+buflen;
55835+ char * retval;
55836+ int namelen;
55837+
55838+ *--end = '\0';
55839+ buflen--;
55840+
55841+ if (buflen < 1)
55842+ goto Elong;
55843+ /* Get '/' right */
55844+ retval = end-1;
55845+ *retval = '/';
55846+
55847+ for (;;) {
55848+ struct dentry * parent;
55849+
55850+ if (dentry == root && vfsmnt == rootmnt)
55851+ break;
55852+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
55853+ /* Global root? */
55854+ if (vfsmnt->mnt_parent == vfsmnt)
55855+ goto global_root;
55856+ dentry = vfsmnt->mnt_mountpoint;
55857+ vfsmnt = vfsmnt->mnt_parent;
55858+ continue;
55859+ }
55860+ parent = dentry->d_parent;
55861+ prefetch(parent);
55862+ namelen = dentry->d_name.len;
55863+ buflen -= namelen + 1;
55864+ if (buflen < 0)
55865+ goto Elong;
55866+ end -= namelen;
55867+ memcpy(end, dentry->d_name.name, namelen);
55868+ *--end = '/';
55869+ retval = end;
55870+ dentry = parent;
55871+ }
55872+
55873+out:
55874+ return retval;
55875+
55876+global_root:
55877+ namelen = dentry->d_name.len;
55878+ buflen -= namelen;
55879+ if (buflen < 0)
55880+ goto Elong;
55881+ retval -= namelen-1; /* hit the slash */
55882+ memcpy(retval, dentry->d_name.name, namelen);
55883+ goto out;
55884+Elong:
55885+ retval = ERR_PTR(-ENAMETOOLONG);
55886+ goto out;
55887+}
55888+
55889+static char *
55890+gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
55891+ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
55892+{
55893+ char *retval;
55894+
55895+ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
55896+ if (unlikely(IS_ERR(retval)))
55897+ retval = strcpy(buf, "<path too long>");
55898+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
55899+ retval[1] = '\0';
55900+
55901+ return retval;
55902+}
55903+
55904+static char *
55905+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
55906+ char *buf, int buflen)
55907+{
55908+ char *res;
55909+
55910+ /* we can use real_root, real_root_mnt, because this is only called
55911+ by the RBAC system */
55912+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
55913+
55914+ return res;
55915+}
55916+
55917+static char *
55918+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
55919+ char *buf, int buflen)
55920+{
55921+ char *res;
55922+ struct dentry *root;
55923+ struct vfsmount *rootmnt;
55924+ struct task_struct *reaper = &init_task;
55925+
55926+ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
55927+ read_lock(&reaper->fs->lock);
55928+ root = dget(reaper->fs->root.dentry);
55929+ rootmnt = mntget(reaper->fs->root.mnt);
55930+ read_unlock(&reaper->fs->lock);
55931+
55932+ spin_lock(&dcache_lock);
55933+ spin_lock(&vfsmount_lock);
55934+ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
55935+ spin_unlock(&vfsmount_lock);
55936+ spin_unlock(&dcache_lock);
55937+
55938+ dput(root);
55939+ mntput(rootmnt);
55940+ return res;
55941+}
55942+
55943+static char *
55944+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
55945+{
55946+ char *ret;
55947+ spin_lock(&dcache_lock);
55948+ spin_lock(&vfsmount_lock);
55949+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
55950+ PAGE_SIZE);
55951+ spin_unlock(&vfsmount_lock);
55952+ spin_unlock(&dcache_lock);
55953+ return ret;
55954+}
55955+
55956+static char *
55957+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
55958+{
55959+ char *ret;
55960+ char *buf;
55961+ int buflen;
55962+
55963+ spin_lock(&dcache_lock);
55964+ spin_lock(&vfsmount_lock);
55965+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
55966+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
55967+ buflen = (int)(ret - buf);
55968+ if (buflen >= 5)
55969+ prepend(&ret, &buflen, "/proc", 5);
55970+ else
55971+ ret = strcpy(buf, "<path too long>");
55972+ spin_unlock(&vfsmount_lock);
55973+ spin_unlock(&dcache_lock);
55974+ return ret;
55975+}
55976+
55977+char *
55978+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
55979+{
55980+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
55981+ PAGE_SIZE);
55982+}
55983+
55984+char *
55985+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
55986+{
55987+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55988+ PAGE_SIZE);
55989+}
55990+
55991+char *
55992+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
55993+{
55994+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
55995+ PAGE_SIZE);
55996+}
55997+
55998+char *
55999+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
56000+{
56001+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
56002+ PAGE_SIZE);
56003+}
56004+
56005+char *
56006+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
56007+{
56008+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
56009+ PAGE_SIZE);
56010+}
56011+
56012+__inline__ __u32
56013+to_gr_audit(const __u32 reqmode)
56014+{
56015+ /* masks off auditable permission flags, then shifts them to create
56016+ auditing flags, and adds the special case of append auditing if
56017+ we're requesting write */
56018+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
56019+}
56020+
56021+struct acl_subject_label *
56022+lookup_subject_map(const struct acl_subject_label *userp)
56023+{
56024+ unsigned int index = shash(userp, subj_map_set.s_size);
56025+ struct subject_map *match;
56026+
56027+ match = subj_map_set.s_hash[index];
56028+
56029+ while (match && match->user != userp)
56030+ match = match->next;
56031+
56032+ if (match != NULL)
56033+ return match->kernel;
56034+ else
56035+ return NULL;
56036+}
56037+
56038+static void
56039+insert_subj_map_entry(struct subject_map *subjmap)
56040+{
56041+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
56042+ struct subject_map **curr;
56043+
56044+ subjmap->prev = NULL;
56045+
56046+ curr = &subj_map_set.s_hash[index];
56047+ if (*curr != NULL)
56048+ (*curr)->prev = subjmap;
56049+
56050+ subjmap->next = *curr;
56051+ *curr = subjmap;
56052+
56053+ return;
56054+}
56055+
56056+static struct acl_role_label *
56057+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
56058+ const gid_t gid)
56059+{
56060+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
56061+ struct acl_role_label *match;
56062+ struct role_allowed_ip *ipp;
56063+ unsigned int x;
56064+ u32 curr_ip = task->signal->curr_ip;
56065+
56066+ task->signal->saved_ip = curr_ip;
56067+
56068+ match = acl_role_set.r_hash[index];
56069+
56070+ while (match) {
56071+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
56072+ for (x = 0; x < match->domain_child_num; x++) {
56073+ if (match->domain_children[x] == uid)
56074+ goto found;
56075+ }
56076+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
56077+ break;
56078+ match = match->next;
56079+ }
56080+found:
56081+ if (match == NULL) {
56082+ try_group:
56083+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
56084+ match = acl_role_set.r_hash[index];
56085+
56086+ while (match) {
56087+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
56088+ for (x = 0; x < match->domain_child_num; x++) {
56089+ if (match->domain_children[x] == gid)
56090+ goto found2;
56091+ }
56092+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
56093+ break;
56094+ match = match->next;
56095+ }
56096+found2:
56097+ if (match == NULL)
56098+ match = default_role;
56099+ if (match->allowed_ips == NULL)
56100+ return match;
56101+ else {
56102+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
56103+ if (likely
56104+ ((ntohl(curr_ip) & ipp->netmask) ==
56105+ (ntohl(ipp->addr) & ipp->netmask)))
56106+ return match;
56107+ }
56108+ match = default_role;
56109+ }
56110+ } else if (match->allowed_ips == NULL) {
56111+ return match;
56112+ } else {
56113+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
56114+ if (likely
56115+ ((ntohl(curr_ip) & ipp->netmask) ==
56116+ (ntohl(ipp->addr) & ipp->netmask)))
56117+ return match;
56118+ }
56119+ goto try_group;
56120+ }
56121+
56122+ return match;
56123+}
56124+
56125+struct acl_subject_label *
56126+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
56127+ const struct acl_role_label *role)
56128+{
56129+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
56130+ struct acl_subject_label *match;
56131+
56132+ match = role->subj_hash[index];
56133+
56134+ while (match && (match->inode != ino || match->device != dev ||
56135+ (match->mode & GR_DELETED))) {
56136+ match = match->next;
56137+ }
56138+
56139+ if (match && !(match->mode & GR_DELETED))
56140+ return match;
56141+ else
56142+ return NULL;
56143+}
56144+
56145+struct acl_subject_label *
56146+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
56147+ const struct acl_role_label *role)
56148+{
56149+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
56150+ struct acl_subject_label *match;
56151+
56152+ match = role->subj_hash[index];
56153+
56154+ while (match && (match->inode != ino || match->device != dev ||
56155+ !(match->mode & GR_DELETED))) {
56156+ match = match->next;
56157+ }
56158+
56159+ if (match && (match->mode & GR_DELETED))
56160+ return match;
56161+ else
56162+ return NULL;
56163+}
56164+
56165+static struct acl_object_label *
56166+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
56167+ const struct acl_subject_label *subj)
56168+{
56169+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
56170+ struct acl_object_label *match;
56171+
56172+ match = subj->obj_hash[index];
56173+
56174+ while (match && (match->inode != ino || match->device != dev ||
56175+ (match->mode & GR_DELETED))) {
56176+ match = match->next;
56177+ }
56178+
56179+ if (match && !(match->mode & GR_DELETED))
56180+ return match;
56181+ else
56182+ return NULL;
56183+}
56184+
56185+static struct acl_object_label *
56186+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
56187+ const struct acl_subject_label *subj)
56188+{
56189+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
56190+ struct acl_object_label *match;
56191+
56192+ match = subj->obj_hash[index];
56193+
56194+ while (match && (match->inode != ino || match->device != dev ||
56195+ !(match->mode & GR_DELETED))) {
56196+ match = match->next;
56197+ }
56198+
56199+ if (match && (match->mode & GR_DELETED))
56200+ return match;
56201+
56202+ match = subj->obj_hash[index];
56203+
56204+ while (match && (match->inode != ino || match->device != dev ||
56205+ (match->mode & GR_DELETED))) {
56206+ match = match->next;
56207+ }
56208+
56209+ if (match && !(match->mode & GR_DELETED))
56210+ return match;
56211+ else
56212+ return NULL;
56213+}
56214+
56215+static struct name_entry *
56216+lookup_name_entry(const char *name)
56217+{
56218+ unsigned int len = strlen(name);
56219+ unsigned int key = full_name_hash(name, len);
56220+ unsigned int index = key % name_set.n_size;
56221+ struct name_entry *match;
56222+
56223+ match = name_set.n_hash[index];
56224+
56225+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
56226+ match = match->next;
56227+
56228+ return match;
56229+}
56230+
56231+static struct name_entry *
56232+lookup_name_entry_create(const char *name)
56233+{
56234+ unsigned int len = strlen(name);
56235+ unsigned int key = full_name_hash(name, len);
56236+ unsigned int index = key % name_set.n_size;
56237+ struct name_entry *match;
56238+
56239+ match = name_set.n_hash[index];
56240+
56241+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
56242+ !match->deleted))
56243+ match = match->next;
56244+
56245+ if (match && match->deleted)
56246+ return match;
56247+
56248+ match = name_set.n_hash[index];
56249+
56250+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
56251+ match->deleted))
56252+ match = match->next;
56253+
56254+ if (match && !match->deleted)
56255+ return match;
56256+ else
56257+ return NULL;
56258+}
56259+
56260+static struct inodev_entry *
56261+lookup_inodev_entry(const ino_t ino, const dev_t dev)
56262+{
56263+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
56264+ struct inodev_entry *match;
56265+
56266+ match = inodev_set.i_hash[index];
56267+
56268+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
56269+ match = match->next;
56270+
56271+ return match;
56272+}
56273+
56274+static void
56275+insert_inodev_entry(struct inodev_entry *entry)
56276+{
56277+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
56278+ inodev_set.i_size);
56279+ struct inodev_entry **curr;
56280+
56281+ entry->prev = NULL;
56282+
56283+ curr = &inodev_set.i_hash[index];
56284+ if (*curr != NULL)
56285+ (*curr)->prev = entry;
56286+
56287+ entry->next = *curr;
56288+ *curr = entry;
56289+
56290+ return;
56291+}
56292+
56293+static void
56294+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
56295+{
56296+ unsigned int index =
56297+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
56298+ struct acl_role_label **curr;
56299+ struct acl_role_label *tmp;
56300+
56301+ curr = &acl_role_set.r_hash[index];
56302+
56303+ /* if role was already inserted due to domains and already has
56304+ a role in the same bucket as it attached, then we need to
56305+ combine these two buckets
56306+ */
56307+ if (role->next) {
56308+ tmp = role->next;
56309+ while (tmp->next)
56310+ tmp = tmp->next;
56311+ tmp->next = *curr;
56312+ } else
56313+ role->next = *curr;
56314+ *curr = role;
56315+
56316+ return;
56317+}
56318+
56319+static void
56320+insert_acl_role_label(struct acl_role_label *role)
56321+{
56322+ int i;
56323+
56324+ if (role_list == NULL) {
56325+ role_list = role;
56326+ role->prev = NULL;
56327+ } else {
56328+ role->prev = role_list;
56329+ role_list = role;
56330+ }
56331+
56332+ /* used for hash chains */
56333+ role->next = NULL;
56334+
56335+ if (role->roletype & GR_ROLE_DOMAIN) {
56336+ for (i = 0; i < role->domain_child_num; i++)
56337+ __insert_acl_role_label(role, role->domain_children[i]);
56338+ } else
56339+ __insert_acl_role_label(role, role->uidgid);
56340+}
56341+
56342+static int
56343+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
56344+{
56345+ struct name_entry **curr, *nentry;
56346+ struct inodev_entry *ientry;
56347+ unsigned int len = strlen(name);
56348+ unsigned int key = full_name_hash(name, len);
56349+ unsigned int index = key % name_set.n_size;
56350+
56351+ curr = &name_set.n_hash[index];
56352+
56353+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
56354+ curr = &((*curr)->next);
56355+
56356+ if (*curr != NULL)
56357+ return 1;
56358+
56359+ nentry = acl_alloc(sizeof (struct name_entry));
56360+ if (nentry == NULL)
56361+ return 0;
56362+ ientry = acl_alloc(sizeof (struct inodev_entry));
56363+ if (ientry == NULL)
56364+ return 0;
56365+ ientry->nentry = nentry;
56366+
56367+ nentry->key = key;
56368+ nentry->name = name;
56369+ nentry->inode = inode;
56370+ nentry->device = device;
56371+ nentry->len = len;
56372+ nentry->deleted = deleted;
56373+
56374+ nentry->prev = NULL;
56375+ curr = &name_set.n_hash[index];
56376+ if (*curr != NULL)
56377+ (*curr)->prev = nentry;
56378+ nentry->next = *curr;
56379+ *curr = nentry;
56380+
56381+ /* insert us into the table searchable by inode/dev */
56382+ insert_inodev_entry(ientry);
56383+
56384+ return 1;
56385+}
56386+
56387+static void
56388+insert_acl_obj_label(struct acl_object_label *obj,
56389+ struct acl_subject_label *subj)
56390+{
56391+ unsigned int index =
56392+ fhash(obj->inode, obj->device, subj->obj_hash_size);
56393+ struct acl_object_label **curr;
56394+
56395+
56396+ obj->prev = NULL;
56397+
56398+ curr = &subj->obj_hash[index];
56399+ if (*curr != NULL)
56400+ (*curr)->prev = obj;
56401+
56402+ obj->next = *curr;
56403+ *curr = obj;
56404+
56405+ return;
56406+}
56407+
56408+static void
56409+insert_acl_subj_label(struct acl_subject_label *obj,
56410+ struct acl_role_label *role)
56411+{
56412+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
56413+ struct acl_subject_label **curr;
56414+
56415+ obj->prev = NULL;
56416+
56417+ curr = &role->subj_hash[index];
56418+ if (*curr != NULL)
56419+ (*curr)->prev = obj;
56420+
56421+ obj->next = *curr;
56422+ *curr = obj;
56423+
56424+ return;
56425+}
56426+
56427+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
56428+
56429+static void *
56430+create_table(__u32 * len, int elementsize)
56431+{
56432+ unsigned int table_sizes[] = {
56433+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
56434+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
56435+ 4194301, 8388593, 16777213, 33554393, 67108859
56436+ };
56437+ void *newtable = NULL;
56438+ unsigned int pwr = 0;
56439+
56440+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
56441+ table_sizes[pwr] <= *len)
56442+ pwr++;
56443+
56444+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
56445+ return newtable;
56446+
56447+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
56448+ newtable =
56449+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
56450+ else
56451+ newtable = vmalloc(table_sizes[pwr] * elementsize);
56452+
56453+ *len = table_sizes[pwr];
56454+
56455+ return newtable;
56456+}
56457+
56458+static int
56459+init_variables(const struct gr_arg *arg)
56460+{
56461+ struct task_struct *reaper = &init_task;
56462+ unsigned int stacksize;
56463+
56464+ subj_map_set.s_size = arg->role_db.num_subjects;
56465+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
56466+ name_set.n_size = arg->role_db.num_objects;
56467+ inodev_set.i_size = arg->role_db.num_objects;
56468+
56469+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
56470+ !name_set.n_size || !inodev_set.i_size)
56471+ return 1;
56472+
56473+ if (!gr_init_uidset())
56474+ return 1;
56475+
56476+ /* set up the stack that holds allocation info */
56477+
56478+ stacksize = arg->role_db.num_pointers + 5;
56479+
56480+ if (!acl_alloc_stack_init(stacksize))
56481+ return 1;
56482+
56483+ /* grab reference for the real root dentry and vfsmount */
56484+ read_lock(&reaper->fs->lock);
56485+ real_root = dget(reaper->fs->root.dentry);
56486+ real_root_mnt = mntget(reaper->fs->root.mnt);
56487+ read_unlock(&reaper->fs->lock);
56488+
56489+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56490+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root), real_root->d_inode->i_ino);
56491+#endif
56492+
56493+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
56494+ if (fakefs_obj_rw == NULL)
56495+ return 1;
56496+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
56497+
56498+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
56499+ if (fakefs_obj_rwx == NULL)
56500+ return 1;
56501+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
56502+
56503+ subj_map_set.s_hash =
56504+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
56505+ acl_role_set.r_hash =
56506+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
56507+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
56508+ inodev_set.i_hash =
56509+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
56510+
56511+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
56512+ !name_set.n_hash || !inodev_set.i_hash)
56513+ return 1;
56514+
56515+ memset(subj_map_set.s_hash, 0,
56516+ sizeof(struct subject_map *) * subj_map_set.s_size);
56517+ memset(acl_role_set.r_hash, 0,
56518+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
56519+ memset(name_set.n_hash, 0,
56520+ sizeof (struct name_entry *) * name_set.n_size);
56521+ memset(inodev_set.i_hash, 0,
56522+ sizeof (struct inodev_entry *) * inodev_set.i_size);
56523+
56524+ return 0;
56525+}
56526+
56527+/* free information not needed after startup
56528+ currently contains user->kernel pointer mappings for subjects
56529+*/
56530+
56531+static void
56532+free_init_variables(void)
56533+{
56534+ __u32 i;
56535+
56536+ if (subj_map_set.s_hash) {
56537+ for (i = 0; i < subj_map_set.s_size; i++) {
56538+ if (subj_map_set.s_hash[i]) {
56539+ kfree(subj_map_set.s_hash[i]);
56540+ subj_map_set.s_hash[i] = NULL;
56541+ }
56542+ }
56543+
56544+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
56545+ PAGE_SIZE)
56546+ kfree(subj_map_set.s_hash);
56547+ else
56548+ vfree(subj_map_set.s_hash);
56549+ }
56550+
56551+ return;
56552+}
56553+
56554+static void
56555+free_variables(void)
56556+{
56557+ struct acl_subject_label *s;
56558+ struct acl_role_label *r;
56559+ struct task_struct *task, *task2;
56560+ unsigned int x;
56561+
56562+ gr_clear_learn_entries();
56563+
56564+ read_lock(&tasklist_lock);
56565+ do_each_thread(task2, task) {
56566+ task->acl_sp_role = 0;
56567+ task->acl_role_id = 0;
56568+ task->acl = NULL;
56569+ task->role = NULL;
56570+ } while_each_thread(task2, task);
56571+ read_unlock(&tasklist_lock);
56572+
56573+ /* release the reference to the real root dentry and vfsmount */
56574+ if (real_root)
56575+ dput(real_root);
56576+ real_root = NULL;
56577+ if (real_root_mnt)
56578+ mntput(real_root_mnt);
56579+ real_root_mnt = NULL;
56580+
56581+ /* free all object hash tables */
56582+
56583+ FOR_EACH_ROLE_START(r)
56584+ if (r->subj_hash == NULL)
56585+ goto next_role;
56586+ FOR_EACH_SUBJECT_START(r, s, x)
56587+ if (s->obj_hash == NULL)
56588+ break;
56589+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
56590+ kfree(s->obj_hash);
56591+ else
56592+ vfree(s->obj_hash);
56593+ FOR_EACH_SUBJECT_END(s, x)
56594+ FOR_EACH_NESTED_SUBJECT_START(r, s)
56595+ if (s->obj_hash == NULL)
56596+ break;
56597+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
56598+ kfree(s->obj_hash);
56599+ else
56600+ vfree(s->obj_hash);
56601+ FOR_EACH_NESTED_SUBJECT_END(s)
56602+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
56603+ kfree(r->subj_hash);
56604+ else
56605+ vfree(r->subj_hash);
56606+ r->subj_hash = NULL;
56607+next_role:
56608+ FOR_EACH_ROLE_END(r)
56609+
56610+ acl_free_all();
56611+
56612+ if (acl_role_set.r_hash) {
56613+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
56614+ PAGE_SIZE)
56615+ kfree(acl_role_set.r_hash);
56616+ else
56617+ vfree(acl_role_set.r_hash);
56618+ }
56619+ if (name_set.n_hash) {
56620+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
56621+ PAGE_SIZE)
56622+ kfree(name_set.n_hash);
56623+ else
56624+ vfree(name_set.n_hash);
56625+ }
56626+
56627+ if (inodev_set.i_hash) {
56628+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
56629+ PAGE_SIZE)
56630+ kfree(inodev_set.i_hash);
56631+ else
56632+ vfree(inodev_set.i_hash);
56633+ }
56634+
56635+ gr_free_uidset();
56636+
56637+ memset(&name_set, 0, sizeof (struct name_db));
56638+ memset(&inodev_set, 0, sizeof (struct inodev_db));
56639+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
56640+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
56641+
56642+ default_role = NULL;
56643+ role_list = NULL;
56644+
56645+ return;
56646+}
56647+
56648+static __u32
56649+count_user_objs(struct acl_object_label *userp)
56650+{
56651+ struct acl_object_label o_tmp;
56652+ __u32 num = 0;
56653+
56654+ while (userp) {
56655+ if (copy_from_user(&o_tmp, userp,
56656+ sizeof (struct acl_object_label)))
56657+ break;
56658+
56659+ userp = o_tmp.prev;
56660+ num++;
56661+ }
56662+
56663+ return num;
56664+}
56665+
56666+static struct acl_subject_label *
56667+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
56668+
56669+static int
56670+copy_user_glob(struct acl_object_label *obj)
56671+{
56672+ struct acl_object_label *g_tmp, **guser;
56673+ unsigned int len;
56674+ char *tmp;
56675+
56676+ if (obj->globbed == NULL)
56677+ return 0;
56678+
56679+ guser = &obj->globbed;
56680+ while (*guser) {
56681+ g_tmp = (struct acl_object_label *)
56682+ acl_alloc(sizeof (struct acl_object_label));
56683+ if (g_tmp == NULL)
56684+ return -ENOMEM;
56685+
56686+ if (copy_from_user(g_tmp, *guser,
56687+ sizeof (struct acl_object_label)))
56688+ return -EFAULT;
56689+
56690+ len = strnlen_user(g_tmp->filename, PATH_MAX);
56691+
56692+ if (!len || len >= PATH_MAX)
56693+ return -EINVAL;
56694+
56695+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56696+ return -ENOMEM;
56697+
56698+ if (copy_from_user(tmp, g_tmp->filename, len))
56699+ return -EFAULT;
56700+ tmp[len-1] = '\0';
56701+ g_tmp->filename = tmp;
56702+
56703+ *guser = g_tmp;
56704+ guser = &(g_tmp->next);
56705+ }
56706+
56707+ return 0;
56708+}
56709+
56710+static int
56711+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
56712+ struct acl_role_label *role)
56713+{
56714+ struct acl_object_label *o_tmp;
56715+ unsigned int len;
56716+ int ret;
56717+ char *tmp;
56718+
56719+ while (userp) {
56720+ if ((o_tmp = (struct acl_object_label *)
56721+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
56722+ return -ENOMEM;
56723+
56724+ if (copy_from_user(o_tmp, userp,
56725+ sizeof (struct acl_object_label)))
56726+ return -EFAULT;
56727+
56728+ userp = o_tmp->prev;
56729+
56730+ len = strnlen_user(o_tmp->filename, PATH_MAX);
56731+
56732+ if (!len || len >= PATH_MAX)
56733+ return -EINVAL;
56734+
56735+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56736+ return -ENOMEM;
56737+
56738+ if (copy_from_user(tmp, o_tmp->filename, len))
56739+ return -EFAULT;
56740+ tmp[len-1] = '\0';
56741+ o_tmp->filename = tmp;
56742+
56743+ insert_acl_obj_label(o_tmp, subj);
56744+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
56745+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
56746+ return -ENOMEM;
56747+
56748+ ret = copy_user_glob(o_tmp);
56749+ if (ret)
56750+ return ret;
56751+
56752+ if (o_tmp->nested) {
56753+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
56754+ if (IS_ERR(o_tmp->nested))
56755+ return PTR_ERR(o_tmp->nested);
56756+
56757+ /* insert into nested subject list */
56758+ o_tmp->nested->next = role->hash->first;
56759+ role->hash->first = o_tmp->nested;
56760+ }
56761+ }
56762+
56763+ return 0;
56764+}
56765+
56766+static __u32
56767+count_user_subjs(struct acl_subject_label *userp)
56768+{
56769+ struct acl_subject_label s_tmp;
56770+ __u32 num = 0;
56771+
56772+ while (userp) {
56773+ if (copy_from_user(&s_tmp, userp,
56774+ sizeof (struct acl_subject_label)))
56775+ break;
56776+
56777+ userp = s_tmp.prev;
56778+ /* do not count nested subjects against this count, since
56779+ they are not included in the hash table, but are
56780+ attached to objects. We have already counted
56781+ the subjects in userspace for the allocation
56782+ stack
56783+ */
56784+ if (!(s_tmp.mode & GR_NESTED))
56785+ num++;
56786+ }
56787+
56788+ return num;
56789+}
56790+
56791+static int
56792+copy_user_allowedips(struct acl_role_label *rolep)
56793+{
56794+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
56795+
56796+ ruserip = rolep->allowed_ips;
56797+
56798+ while (ruserip) {
56799+ rlast = rtmp;
56800+
56801+ if ((rtmp = (struct role_allowed_ip *)
56802+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
56803+ return -ENOMEM;
56804+
56805+ if (copy_from_user(rtmp, ruserip,
56806+ sizeof (struct role_allowed_ip)))
56807+ return -EFAULT;
56808+
56809+ ruserip = rtmp->prev;
56810+
56811+ if (!rlast) {
56812+ rtmp->prev = NULL;
56813+ rolep->allowed_ips = rtmp;
56814+ } else {
56815+ rlast->next = rtmp;
56816+ rtmp->prev = rlast;
56817+ }
56818+
56819+ if (!ruserip)
56820+ rtmp->next = NULL;
56821+ }
56822+
56823+ return 0;
56824+}
56825+
56826+static int
56827+copy_user_transitions(struct acl_role_label *rolep)
56828+{
56829+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
56830+
56831+ unsigned int len;
56832+ char *tmp;
56833+
56834+ rusertp = rolep->transitions;
56835+
56836+ while (rusertp) {
56837+ rlast = rtmp;
56838+
56839+ if ((rtmp = (struct role_transition *)
56840+ acl_alloc(sizeof (struct role_transition))) == NULL)
56841+ return -ENOMEM;
56842+
56843+ if (copy_from_user(rtmp, rusertp,
56844+ sizeof (struct role_transition)))
56845+ return -EFAULT;
56846+
56847+ rusertp = rtmp->prev;
56848+
56849+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
56850+
56851+ if (!len || len >= GR_SPROLE_LEN)
56852+ return -EINVAL;
56853+
56854+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56855+ return -ENOMEM;
56856+
56857+ if (copy_from_user(tmp, rtmp->rolename, len))
56858+ return -EFAULT;
56859+ tmp[len-1] = '\0';
56860+ rtmp->rolename = tmp;
56861+
56862+ if (!rlast) {
56863+ rtmp->prev = NULL;
56864+ rolep->transitions = rtmp;
56865+ } else {
56866+ rlast->next = rtmp;
56867+ rtmp->prev = rlast;
56868+ }
56869+
56870+ if (!rusertp)
56871+ rtmp->next = NULL;
56872+ }
56873+
56874+ return 0;
56875+}
56876+
56877+static struct acl_subject_label *
56878+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
56879+{
56880+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
56881+ unsigned int len;
56882+ char *tmp;
56883+ __u32 num_objs;
56884+ struct acl_ip_label **i_tmp, *i_utmp2;
56885+ struct gr_hash_struct ghash;
56886+ struct subject_map *subjmap;
56887+ unsigned int i_num;
56888+ int err;
56889+
56890+ s_tmp = lookup_subject_map(userp);
56891+
56892+ /* we've already copied this subject into the kernel, just return
56893+ the reference to it, and don't copy it over again
56894+ */
56895+ if (s_tmp)
56896+ return(s_tmp);
56897+
56898+ if ((s_tmp = (struct acl_subject_label *)
56899+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
56900+ return ERR_PTR(-ENOMEM);
56901+
56902+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
56903+ if (subjmap == NULL)
56904+ return ERR_PTR(-ENOMEM);
56905+
56906+ subjmap->user = userp;
56907+ subjmap->kernel = s_tmp;
56908+ insert_subj_map_entry(subjmap);
56909+
56910+ if (copy_from_user(s_tmp, userp,
56911+ sizeof (struct acl_subject_label)))
56912+ return ERR_PTR(-EFAULT);
56913+
56914+ len = strnlen_user(s_tmp->filename, PATH_MAX);
56915+
56916+ if (!len || len >= PATH_MAX)
56917+ return ERR_PTR(-EINVAL);
56918+
56919+ if ((tmp = (char *) acl_alloc(len)) == NULL)
56920+ return ERR_PTR(-ENOMEM);
56921+
56922+ if (copy_from_user(tmp, s_tmp->filename, len))
56923+ return ERR_PTR(-EFAULT);
56924+ tmp[len-1] = '\0';
56925+ s_tmp->filename = tmp;
56926+
56927+ if (!strcmp(s_tmp->filename, "/"))
56928+ role->root_label = s_tmp;
56929+
56930+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
56931+ return ERR_PTR(-EFAULT);
56932+
56933+ /* copy user and group transition tables */
56934+
56935+ if (s_tmp->user_trans_num) {
56936+ uid_t *uidlist;
56937+
56938+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
56939+ if (uidlist == NULL)
56940+ return ERR_PTR(-ENOMEM);
56941+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
56942+ return ERR_PTR(-EFAULT);
56943+
56944+ s_tmp->user_transitions = uidlist;
56945+ }
56946+
56947+ if (s_tmp->group_trans_num) {
56948+ gid_t *gidlist;
56949+
56950+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
56951+ if (gidlist == NULL)
56952+ return ERR_PTR(-ENOMEM);
56953+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
56954+ return ERR_PTR(-EFAULT);
56955+
56956+ s_tmp->group_transitions = gidlist;
56957+ }
56958+
56959+ /* set up object hash table */
56960+ num_objs = count_user_objs(ghash.first);
56961+
56962+ s_tmp->obj_hash_size = num_objs;
56963+ s_tmp->obj_hash =
56964+ (struct acl_object_label **)
56965+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
56966+
56967+ if (!s_tmp->obj_hash)
56968+ return ERR_PTR(-ENOMEM);
56969+
56970+ memset(s_tmp->obj_hash, 0,
56971+ s_tmp->obj_hash_size *
56972+ sizeof (struct acl_object_label *));
56973+
56974+ /* add in objects */
56975+ err = copy_user_objs(ghash.first, s_tmp, role);
56976+
56977+ if (err)
56978+ return ERR_PTR(err);
56979+
56980+ /* set pointer for parent subject */
56981+ if (s_tmp->parent_subject) {
56982+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
56983+
56984+ if (IS_ERR(s_tmp2))
56985+ return s_tmp2;
56986+
56987+ s_tmp->parent_subject = s_tmp2;
56988+ }
56989+
56990+ /* add in ip acls */
56991+
56992+ if (!s_tmp->ip_num) {
56993+ s_tmp->ips = NULL;
56994+ goto insert;
56995+ }
56996+
56997+ i_tmp =
56998+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
56999+ sizeof (struct acl_ip_label *));
57000+
57001+ if (!i_tmp)
57002+ return ERR_PTR(-ENOMEM);
57003+
57004+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
57005+ *(i_tmp + i_num) =
57006+ (struct acl_ip_label *)
57007+ acl_alloc(sizeof (struct acl_ip_label));
57008+ if (!*(i_tmp + i_num))
57009+ return ERR_PTR(-ENOMEM);
57010+
57011+ if (copy_from_user
57012+ (&i_utmp2, s_tmp->ips + i_num,
57013+ sizeof (struct acl_ip_label *)))
57014+ return ERR_PTR(-EFAULT);
57015+
57016+ if (copy_from_user
57017+ (*(i_tmp + i_num), i_utmp2,
57018+ sizeof (struct acl_ip_label)))
57019+ return ERR_PTR(-EFAULT);
57020+
57021+ if ((*(i_tmp + i_num))->iface == NULL)
57022+ continue;
57023+
57024+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
57025+ if (!len || len >= IFNAMSIZ)
57026+ return ERR_PTR(-EINVAL);
57027+ tmp = acl_alloc(len);
57028+ if (tmp == NULL)
57029+ return ERR_PTR(-ENOMEM);
57030+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
57031+ return ERR_PTR(-EFAULT);
57032+ (*(i_tmp + i_num))->iface = tmp;
57033+ }
57034+
57035+ s_tmp->ips = i_tmp;
57036+
57037+insert:
57038+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
57039+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
57040+ return ERR_PTR(-ENOMEM);
57041+
57042+ return s_tmp;
57043+}
57044+
57045+static int
57046+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
57047+{
57048+ struct acl_subject_label s_pre;
57049+ struct acl_subject_label * ret;
57050+ int err;
57051+
57052+ while (userp) {
57053+ if (copy_from_user(&s_pre, userp,
57054+ sizeof (struct acl_subject_label)))
57055+ return -EFAULT;
57056+
57057+ /* do not add nested subjects here, add
57058+ while parsing objects
57059+ */
57060+
57061+ if (s_pre.mode & GR_NESTED) {
57062+ userp = s_pre.prev;
57063+ continue;
57064+ }
57065+
57066+ ret = do_copy_user_subj(userp, role);
57067+
57068+ err = PTR_ERR(ret);
57069+ if (IS_ERR(ret))
57070+ return err;
57071+
57072+ insert_acl_subj_label(ret, role);
57073+
57074+ userp = s_pre.prev;
57075+ }
57076+
57077+ return 0;
57078+}
57079+
57080+static int
57081+copy_user_acl(struct gr_arg *arg)
57082+{
57083+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
57084+ struct sprole_pw *sptmp;
57085+ struct gr_hash_struct *ghash;
57086+ uid_t *domainlist;
57087+ unsigned int r_num;
57088+ unsigned int len;
57089+ char *tmp;
57090+ int err = 0;
57091+ __u16 i;
57092+ __u32 num_subjs;
57093+
57094+ /* we need a default and kernel role */
57095+ if (arg->role_db.num_roles < 2)
57096+ return -EINVAL;
57097+
57098+ /* copy special role authentication info from userspace */
57099+
57100+ num_sprole_pws = arg->num_sprole_pws;
57101+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
57102+
57103+ if (!acl_special_roles) {
57104+ err = -ENOMEM;
57105+ goto cleanup;
57106+ }
57107+
57108+ for (i = 0; i < num_sprole_pws; i++) {
57109+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
57110+ if (!sptmp) {
57111+ err = -ENOMEM;
57112+ goto cleanup;
57113+ }
57114+ if (copy_from_user(sptmp, arg->sprole_pws + i,
57115+ sizeof (struct sprole_pw))) {
57116+ err = -EFAULT;
57117+ goto cleanup;
57118+ }
57119+
57120+ len =
57121+ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
57122+
57123+ if (!len || len >= GR_SPROLE_LEN) {
57124+ err = -EINVAL;
57125+ goto cleanup;
57126+ }
57127+
57128+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
57129+ err = -ENOMEM;
57130+ goto cleanup;
57131+ }
57132+
57133+ if (copy_from_user(tmp, sptmp->rolename, len)) {
57134+ err = -EFAULT;
57135+ goto cleanup;
57136+ }
57137+ tmp[len-1] = '\0';
57138+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57139+ printk(KERN_ALERT "Copying special role %s\n", tmp);
57140+#endif
57141+ sptmp->rolename = tmp;
57142+ acl_special_roles[i] = sptmp;
57143+ }
57144+
57145+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
57146+
57147+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
57148+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
57149+
57150+ if (!r_tmp) {
57151+ err = -ENOMEM;
57152+ goto cleanup;
57153+ }
57154+
57155+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
57156+ sizeof (struct acl_role_label *))) {
57157+ err = -EFAULT;
57158+ goto cleanup;
57159+ }
57160+
57161+ if (copy_from_user(r_tmp, r_utmp2,
57162+ sizeof (struct acl_role_label))) {
57163+ err = -EFAULT;
57164+ goto cleanup;
57165+ }
57166+
57167+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
57168+
57169+ if (!len || len >= PATH_MAX) {
57170+ err = -EINVAL;
57171+ goto cleanup;
57172+ }
57173+
57174+ if ((tmp = (char *) acl_alloc(len)) == NULL) {
57175+ err = -ENOMEM;
57176+ goto cleanup;
57177+ }
57178+ if (copy_from_user(tmp, r_tmp->rolename, len)) {
57179+ err = -EFAULT;
57180+ goto cleanup;
57181+ }
57182+ tmp[len-1] = '\0';
57183+ r_tmp->rolename = tmp;
57184+
57185+ if (!strcmp(r_tmp->rolename, "default")
57186+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
57187+ default_role = r_tmp;
57188+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
57189+ kernel_role = r_tmp;
57190+ }
57191+
57192+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
57193+ err = -ENOMEM;
57194+ goto cleanup;
57195+ }
57196+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
57197+ err = -EFAULT;
57198+ goto cleanup;
57199+ }
57200+
57201+ r_tmp->hash = ghash;
57202+
57203+ num_subjs = count_user_subjs(r_tmp->hash->first);
57204+
57205+ r_tmp->subj_hash_size = num_subjs;
57206+ r_tmp->subj_hash =
57207+ (struct acl_subject_label **)
57208+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
57209+
57210+ if (!r_tmp->subj_hash) {
57211+ err = -ENOMEM;
57212+ goto cleanup;
57213+ }
57214+
57215+ err = copy_user_allowedips(r_tmp);
57216+ if (err)
57217+ goto cleanup;
57218+
57219+ /* copy domain info */
57220+ if (r_tmp->domain_children != NULL) {
57221+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
57222+ if (domainlist == NULL) {
57223+ err = -ENOMEM;
57224+ goto cleanup;
57225+ }
57226+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
57227+ err = -EFAULT;
57228+ goto cleanup;
57229+ }
57230+ r_tmp->domain_children = domainlist;
57231+ }
57232+
57233+ err = copy_user_transitions(r_tmp);
57234+ if (err)
57235+ goto cleanup;
57236+
57237+ memset(r_tmp->subj_hash, 0,
57238+ r_tmp->subj_hash_size *
57239+ sizeof (struct acl_subject_label *));
57240+
57241+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
57242+
57243+ if (err)
57244+ goto cleanup;
57245+
57246+ /* set nested subject list to null */
57247+ r_tmp->hash->first = NULL;
57248+
57249+ insert_acl_role_label(r_tmp);
57250+ }
57251+
57252+ goto return_err;
57253+ cleanup:
57254+ free_variables();
57255+ return_err:
57256+ return err;
57257+
57258+}
57259+
57260+static int
57261+gracl_init(struct gr_arg *args)
57262+{
57263+ int error = 0;
57264+
57265+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
57266+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
57267+
57268+ if (init_variables(args)) {
57269+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
57270+ error = -ENOMEM;
57271+ free_variables();
57272+ goto out;
57273+ }
57274+
57275+ error = copy_user_acl(args);
57276+ free_init_variables();
57277+ if (error) {
57278+ free_variables();
57279+ goto out;
57280+ }
57281+
57282+ if ((error = gr_set_acls(0))) {
57283+ free_variables();
57284+ goto out;
57285+ }
57286+
57287+ pax_open_kernel();
57288+ gr_status |= GR_READY;
57289+ pax_close_kernel();
57290+
57291+ out:
57292+ return error;
57293+}
57294+
57295+/* derived from glibc fnmatch() 0: match, 1: no match*/
57296+
57297+static int
57298+glob_match(const char *p, const char *n)
57299+{
57300+ char c;
57301+
57302+ while ((c = *p++) != '\0') {
57303+ switch (c) {
57304+ case '?':
57305+ if (*n == '\0')
57306+ return 1;
57307+ else if (*n == '/')
57308+ return 1;
57309+ break;
57310+ case '\\':
57311+ if (*n != c)
57312+ return 1;
57313+ break;
57314+ case '*':
57315+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
57316+ if (*n == '/')
57317+ return 1;
57318+ else if (c == '?') {
57319+ if (*n == '\0')
57320+ return 1;
57321+ else
57322+ ++n;
57323+ }
57324+ }
57325+ if (c == '\0') {
57326+ return 0;
57327+ } else {
57328+ const char *endp;
57329+
57330+ if ((endp = strchr(n, '/')) == NULL)
57331+ endp = n + strlen(n);
57332+
57333+ if (c == '[') {
57334+ for (--p; n < endp; ++n)
57335+ if (!glob_match(p, n))
57336+ return 0;
57337+ } else if (c == '/') {
57338+ while (*n != '\0' && *n != '/')
57339+ ++n;
57340+ if (*n == '/' && !glob_match(p, n + 1))
57341+ return 0;
57342+ } else {
57343+ for (--p; n < endp; ++n)
57344+ if (*n == c && !glob_match(p, n))
57345+ return 0;
57346+ }
57347+
57348+ return 1;
57349+ }
57350+ case '[':
57351+ {
57352+ int not;
57353+ char cold;
57354+
57355+ if (*n == '\0' || *n == '/')
57356+ return 1;
57357+
57358+ not = (*p == '!' || *p == '^');
57359+ if (not)
57360+ ++p;
57361+
57362+ c = *p++;
57363+ for (;;) {
57364+ unsigned char fn = (unsigned char)*n;
57365+
57366+ if (c == '\0')
57367+ return 1;
57368+ else {
57369+ if (c == fn)
57370+ goto matched;
57371+ cold = c;
57372+ c = *p++;
57373+
57374+ if (c == '-' && *p != ']') {
57375+ unsigned char cend = *p++;
57376+
57377+ if (cend == '\0')
57378+ return 1;
57379+
57380+ if (cold <= fn && fn <= cend)
57381+ goto matched;
57382+
57383+ c = *p++;
57384+ }
57385+ }
57386+
57387+ if (c == ']')
57388+ break;
57389+ }
57390+ if (!not)
57391+ return 1;
57392+ break;
57393+ matched:
57394+ while (c != ']') {
57395+ if (c == '\0')
57396+ return 1;
57397+
57398+ c = *p++;
57399+ }
57400+ if (not)
57401+ return 1;
57402+ }
57403+ break;
57404+ default:
57405+ if (c != *n)
57406+ return 1;
57407+ }
57408+
57409+ ++n;
57410+ }
57411+
57412+ if (*n == '\0')
57413+ return 0;
57414+
57415+ if (*n == '/')
57416+ return 0;
57417+
57418+ return 1;
57419+}
57420+
57421+static struct acl_object_label *
57422+chk_glob_label(struct acl_object_label *globbed,
57423+ struct dentry *dentry, struct vfsmount *mnt, char **path)
57424+{
57425+ struct acl_object_label *tmp;
57426+
57427+ if (*path == NULL)
57428+ *path = gr_to_filename_nolock(dentry, mnt);
57429+
57430+ tmp = globbed;
57431+
57432+ while (tmp) {
57433+ if (!glob_match(tmp->filename, *path))
57434+ return tmp;
57435+ tmp = tmp->next;
57436+ }
57437+
57438+ return NULL;
57439+}
57440+
57441+static struct acl_object_label *
57442+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
57443+ const ino_t curr_ino, const dev_t curr_dev,
57444+ const struct acl_subject_label *subj, char **path, const int checkglob)
57445+{
57446+ struct acl_subject_label *tmpsubj;
57447+ struct acl_object_label *retval;
57448+ struct acl_object_label *retval2;
57449+
57450+ tmpsubj = (struct acl_subject_label *) subj;
57451+ read_lock(&gr_inode_lock);
57452+ do {
57453+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
57454+ if (retval) {
57455+ if (checkglob && retval->globbed) {
57456+ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
57457+ (struct vfsmount *)orig_mnt, path);
57458+ if (retval2)
57459+ retval = retval2;
57460+ }
57461+ break;
57462+ }
57463+ } while ((tmpsubj = tmpsubj->parent_subject));
57464+ read_unlock(&gr_inode_lock);
57465+
57466+ return retval;
57467+}
57468+
57469+static __inline__ struct acl_object_label *
57470+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
57471+ const struct dentry *curr_dentry,
57472+ const struct acl_subject_label *subj, char **path, const int checkglob)
57473+{
57474+ int newglob = checkglob;
57475+
57476+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
57477+ as we don't want a / * rule to match instead of the / object
57478+ don't do this for create lookups that call this function though, since they're looking up
57479+ on the parent and thus need globbing checks on all paths
57480+ */
57481+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
57482+ newglob = GR_NO_GLOB;
57483+
57484+ return __full_lookup(orig_dentry, orig_mnt,
57485+ curr_dentry->d_inode->i_ino,
57486+ __get_dev(curr_dentry), subj, path, newglob);
57487+}
57488+
57489+static struct acl_object_label *
57490+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57491+ const struct acl_subject_label *subj, char *path, const int checkglob)
57492+{
57493+ struct dentry *dentry = (struct dentry *) l_dentry;
57494+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
57495+ struct acl_object_label *retval;
57496+
57497+ spin_lock(&dcache_lock);
57498+ spin_lock(&vfsmount_lock);
57499+
57500+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
57501+#ifdef CONFIG_NET
57502+ mnt == sock_mnt ||
57503+#endif
57504+#ifdef CONFIG_HUGETLBFS
57505+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
57506+#endif
57507+ /* ignore Eric Biederman */
57508+ IS_PRIVATE(l_dentry->d_inode))) {
57509+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
57510+ goto out;
57511+ }
57512+
57513+ for (;;) {
57514+ if (dentry == real_root && mnt == real_root_mnt)
57515+ break;
57516+
57517+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
57518+ if (mnt->mnt_parent == mnt)
57519+ break;
57520+
57521+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57522+ if (retval != NULL)
57523+ goto out;
57524+
57525+ dentry = mnt->mnt_mountpoint;
57526+ mnt = mnt->mnt_parent;
57527+ continue;
57528+ }
57529+
57530+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57531+ if (retval != NULL)
57532+ goto out;
57533+
57534+ dentry = dentry->d_parent;
57535+ }
57536+
57537+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
57538+
57539+ if (retval == NULL)
57540+ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path, checkglob);
57541+out:
57542+ spin_unlock(&vfsmount_lock);
57543+ spin_unlock(&dcache_lock);
57544+
57545+ BUG_ON(retval == NULL);
57546+
57547+ return retval;
57548+}
57549+
57550+static __inline__ struct acl_object_label *
57551+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57552+ const struct acl_subject_label *subj)
57553+{
57554+ char *path = NULL;
57555+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
57556+}
57557+
57558+static __inline__ struct acl_object_label *
57559+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57560+ const struct acl_subject_label *subj)
57561+{
57562+ char *path = NULL;
57563+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
57564+}
57565+
57566+static __inline__ struct acl_object_label *
57567+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57568+ const struct acl_subject_label *subj, char *path)
57569+{
57570+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
57571+}
57572+
57573+static struct acl_subject_label *
57574+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
57575+ const struct acl_role_label *role)
57576+{
57577+ struct dentry *dentry = (struct dentry *) l_dentry;
57578+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
57579+ struct acl_subject_label *retval;
57580+
57581+ spin_lock(&dcache_lock);
57582+ spin_lock(&vfsmount_lock);
57583+
57584+ for (;;) {
57585+ if (dentry == real_root && mnt == real_root_mnt)
57586+ break;
57587+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
57588+ if (mnt->mnt_parent == mnt)
57589+ break;
57590+
57591+ read_lock(&gr_inode_lock);
57592+ retval =
57593+ lookup_acl_subj_label(dentry->d_inode->i_ino,
57594+ __get_dev(dentry), role);
57595+ read_unlock(&gr_inode_lock);
57596+ if (retval != NULL)
57597+ goto out;
57598+
57599+ dentry = mnt->mnt_mountpoint;
57600+ mnt = mnt->mnt_parent;
57601+ continue;
57602+ }
57603+
57604+ read_lock(&gr_inode_lock);
57605+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
57606+ __get_dev(dentry), role);
57607+ read_unlock(&gr_inode_lock);
57608+ if (retval != NULL)
57609+ goto out;
57610+
57611+ dentry = dentry->d_parent;
57612+ }
57613+
57614+ read_lock(&gr_inode_lock);
57615+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
57616+ __get_dev(dentry), role);
57617+ read_unlock(&gr_inode_lock);
57618+
57619+ if (unlikely(retval == NULL)) {
57620+ read_lock(&gr_inode_lock);
57621+ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
57622+ __get_dev(real_root), role);
57623+ read_unlock(&gr_inode_lock);
57624+ }
57625+out:
57626+ spin_unlock(&vfsmount_lock);
57627+ spin_unlock(&dcache_lock);
57628+
57629+ BUG_ON(retval == NULL);
57630+
57631+ return retval;
57632+}
57633+
57634+static void
57635+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
57636+{
57637+ struct task_struct *task = current;
57638+ const struct cred *cred = current_cred();
57639+
57640+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
57641+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57642+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57643+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
57644+
57645+ return;
57646+}
57647+
57648+static void
57649+gr_log_learn_sysctl(const char *path, const __u32 mode)
57650+{
57651+ struct task_struct *task = current;
57652+ const struct cred *cred = current_cred();
57653+
57654+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
57655+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57656+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57657+ 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
57658+
57659+ return;
57660+}
57661+
57662+static void
57663+gr_log_learn_id_change(const char type, const unsigned int real,
57664+ const unsigned int effective, const unsigned int fs)
57665+{
57666+ struct task_struct *task = current;
57667+ const struct cred *cred = current_cred();
57668+
57669+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
57670+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
57671+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
57672+ type, real, effective, fs, &task->signal->saved_ip);
57673+
57674+ return;
57675+}
57676+
57677+__u32
57678+gr_search_file(const struct dentry * dentry, const __u32 mode,
57679+ const struct vfsmount * mnt)
57680+{
57681+ __u32 retval = mode;
57682+ struct acl_subject_label *curracl;
57683+ struct acl_object_label *currobj;
57684+
57685+ if (unlikely(!(gr_status & GR_READY)))
57686+ return (mode & ~GR_AUDITS);
57687+
57688+ curracl = current->acl;
57689+
57690+ currobj = chk_obj_label(dentry, mnt, curracl);
57691+ retval = currobj->mode & mode;
57692+
57693+ /* if we're opening a specified transfer file for writing
57694+ (e.g. /dev/initctl), then transfer our role to init
57695+ */
57696+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
57697+ current->role->roletype & GR_ROLE_PERSIST)) {
57698+ struct task_struct *task = init_pid_ns.child_reaper;
57699+
57700+ if (task->role != current->role) {
57701+ task->acl_sp_role = 0;
57702+ task->acl_role_id = current->acl_role_id;
57703+ task->role = current->role;
57704+ rcu_read_lock();
57705+ read_lock(&grsec_exec_file_lock);
57706+ gr_apply_subject_to_task(task);
57707+ read_unlock(&grsec_exec_file_lock);
57708+ rcu_read_unlock();
57709+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
57710+ }
57711+ }
57712+
57713+ if (unlikely
57714+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
57715+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
57716+ __u32 new_mode = mode;
57717+
57718+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
57719+
57720+ retval = new_mode;
57721+
57722+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
57723+ new_mode |= GR_INHERIT;
57724+
57725+ if (!(mode & GR_NOLEARN))
57726+ gr_log_learn(dentry, mnt, new_mode);
57727+ }
57728+
57729+ return retval;
57730+}
57731+
57732+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
57733+ const struct dentry *parent,
57734+ const struct vfsmount *mnt)
57735+{
57736+ struct name_entry *match;
57737+ struct acl_object_label *matchpo;
57738+ struct acl_subject_label *curracl;
57739+ char *path;
57740+
57741+ if (unlikely(!(gr_status & GR_READY)))
57742+ return NULL;
57743+
57744+ preempt_disable();
57745+ path = gr_to_filename_rbac(new_dentry, mnt);
57746+ match = lookup_name_entry_create(path);
57747+
57748+ curracl = current->acl;
57749+
57750+ if (match) {
57751+ read_lock(&gr_inode_lock);
57752+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
57753+ read_unlock(&gr_inode_lock);
57754+
57755+ if (matchpo) {
57756+ preempt_enable();
57757+ return matchpo;
57758+ }
57759+ }
57760+
57761+ // lookup parent
57762+
57763+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
57764+
57765+ preempt_enable();
57766+ return matchpo;
57767+}
57768+
57769+__u32
57770+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
57771+ const struct vfsmount * mnt, const __u32 mode)
57772+{
57773+ struct acl_object_label *matchpo;
57774+ __u32 retval;
57775+
57776+ if (unlikely(!(gr_status & GR_READY)))
57777+ return (mode & ~GR_AUDITS);
57778+
57779+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
57780+
57781+ retval = matchpo->mode & mode;
57782+
57783+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
57784+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
57785+ __u32 new_mode = mode;
57786+
57787+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
57788+
57789+ gr_log_learn(new_dentry, mnt, new_mode);
57790+ return new_mode;
57791+ }
57792+
57793+ return retval;
57794+}
57795+
57796+__u32
57797+gr_check_link(const struct dentry * new_dentry,
57798+ const struct dentry * parent_dentry,
57799+ const struct vfsmount * parent_mnt,
57800+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
57801+{
57802+ struct acl_object_label *obj;
57803+ __u32 oldmode, newmode;
57804+ __u32 needmode;
57805+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
57806+ GR_DELETE | GR_INHERIT;
57807+
57808+ if (unlikely(!(gr_status & GR_READY)))
57809+ return (GR_CREATE | GR_LINK);
57810+
57811+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
57812+ oldmode = obj->mode;
57813+
57814+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
57815+ newmode = obj->mode;
57816+
57817+ needmode = newmode & checkmodes;
57818+
57819+ // old name for hardlink must have at least the permissions of the new name
57820+ if ((oldmode & needmode) != needmode)
57821+ goto bad;
57822+
57823+ // if old name had restrictions/auditing, make sure the new name does as well
57824+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
57825+
57826+ // don't allow hardlinking of suid/sgid files without permission
57827+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
57828+ needmode |= GR_SETID;
57829+
57830+ if ((newmode & needmode) != needmode)
57831+ goto bad;
57832+
57833+ // enforce minimum permissions
57834+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
57835+ return newmode;
57836+bad:
57837+ needmode = oldmode;
57838+ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
57839+ needmode |= GR_SETID;
57840+
57841+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
57842+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
57843+ return (GR_CREATE | GR_LINK);
57844+ } else if (newmode & GR_SUPPRESS)
57845+ return GR_SUPPRESS;
57846+ else
57847+ return 0;
57848+}
57849+
57850+int
57851+gr_check_hidden_task(const struct task_struct *task)
57852+{
57853+ if (unlikely(!(gr_status & GR_READY)))
57854+ return 0;
57855+
57856+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
57857+ return 1;
57858+
57859+ return 0;
57860+}
57861+
57862+int
57863+gr_check_protected_task(const struct task_struct *task)
57864+{
57865+ if (unlikely(!(gr_status & GR_READY) || !task))
57866+ return 0;
57867+
57868+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
57869+ task->acl != current->acl)
57870+ return 1;
57871+
57872+ return 0;
57873+}
57874+
57875+int
57876+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57877+{
57878+ struct task_struct *p;
57879+ int ret = 0;
57880+
57881+ if (unlikely(!(gr_status & GR_READY) || !pid))
57882+ return ret;
57883+
57884+ read_lock(&tasklist_lock);
57885+ do_each_pid_task(pid, type, p) {
57886+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
57887+ p->acl != current->acl) {
57888+ ret = 1;
57889+ goto out;
57890+ }
57891+ } while_each_pid_task(pid, type, p);
57892+out:
57893+ read_unlock(&tasklist_lock);
57894+
57895+ return ret;
57896+}
57897+
57898+void
57899+gr_copy_label(struct task_struct *tsk)
57900+{
57901+ tsk->signal->used_accept = 0;
57902+ tsk->acl_sp_role = 0;
57903+ tsk->acl_role_id = current->acl_role_id;
57904+ tsk->acl = current->acl;
57905+ tsk->role = current->role;
57906+ tsk->signal->curr_ip = current->signal->curr_ip;
57907+ tsk->signal->saved_ip = current->signal->saved_ip;
57908+ if (current->exec_file)
57909+ get_file(current->exec_file);
57910+ tsk->exec_file = current->exec_file;
57911+ tsk->is_writable = current->is_writable;
57912+ if (unlikely(current->signal->used_accept)) {
57913+ current->signal->curr_ip = 0;
57914+ current->signal->saved_ip = 0;
57915+ }
57916+
57917+ return;
57918+}
57919+
57920+static void
57921+gr_set_proc_res(struct task_struct *task)
57922+{
57923+ struct acl_subject_label *proc;
57924+ unsigned short i;
57925+
57926+ proc = task->acl;
57927+
57928+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
57929+ return;
57930+
57931+ for (i = 0; i < RLIM_NLIMITS; i++) {
57932+ if (!(proc->resmask & (1 << i)))
57933+ continue;
57934+
57935+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
57936+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
57937+ }
57938+
57939+ return;
57940+}
57941+
57942+extern int __gr_process_user_ban(struct user_struct *user);
57943+
57944+int
57945+gr_check_user_change(int real, int effective, int fs)
57946+{
57947+ unsigned int i;
57948+ __u16 num;
57949+ uid_t *uidlist;
57950+ int curuid;
57951+ int realok = 0;
57952+ int effectiveok = 0;
57953+ int fsok = 0;
57954+
57955+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
57956+ struct user_struct *user;
57957+
57958+ if (real == -1)
57959+ goto skipit;
57960+
57961+ user = find_user(real);
57962+ if (user == NULL)
57963+ goto skipit;
57964+
57965+ if (__gr_process_user_ban(user)) {
57966+ /* for find_user */
57967+ free_uid(user);
57968+ return 1;
57969+ }
57970+
57971+ /* for find_user */
57972+ free_uid(user);
57973+
57974+skipit:
57975+#endif
57976+
57977+ if (unlikely(!(gr_status & GR_READY)))
57978+ return 0;
57979+
57980+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57981+ gr_log_learn_id_change('u', real, effective, fs);
57982+
57983+ num = current->acl->user_trans_num;
57984+ uidlist = current->acl->user_transitions;
57985+
57986+ if (uidlist == NULL)
57987+ return 0;
57988+
57989+ if (real == -1)
57990+ realok = 1;
57991+ if (effective == -1)
57992+ effectiveok = 1;
57993+ if (fs == -1)
57994+ fsok = 1;
57995+
57996+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
57997+ for (i = 0; i < num; i++) {
57998+ curuid = (int)uidlist[i];
57999+ if (real == curuid)
58000+ realok = 1;
58001+ if (effective == curuid)
58002+ effectiveok = 1;
58003+ if (fs == curuid)
58004+ fsok = 1;
58005+ }
58006+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
58007+ for (i = 0; i < num; i++) {
58008+ curuid = (int)uidlist[i];
58009+ if (real == curuid)
58010+ break;
58011+ if (effective == curuid)
58012+ break;
58013+ if (fs == curuid)
58014+ break;
58015+ }
58016+ /* not in deny list */
58017+ if (i == num) {
58018+ realok = 1;
58019+ effectiveok = 1;
58020+ fsok = 1;
58021+ }
58022+ }
58023+
58024+ if (realok && effectiveok && fsok)
58025+ return 0;
58026+ else {
58027+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
58028+ return 1;
58029+ }
58030+}
58031+
58032+int
58033+gr_check_group_change(int real, int effective, int fs)
58034+{
58035+ unsigned int i;
58036+ __u16 num;
58037+ gid_t *gidlist;
58038+ int curgid;
58039+ int realok = 0;
58040+ int effectiveok = 0;
58041+ int fsok = 0;
58042+
58043+ if (unlikely(!(gr_status & GR_READY)))
58044+ return 0;
58045+
58046+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
58047+ gr_log_learn_id_change('g', real, effective, fs);
58048+
58049+ num = current->acl->group_trans_num;
58050+ gidlist = current->acl->group_transitions;
58051+
58052+ if (gidlist == NULL)
58053+ return 0;
58054+
58055+ if (real == -1)
58056+ realok = 1;
58057+ if (effective == -1)
58058+ effectiveok = 1;
58059+ if (fs == -1)
58060+ fsok = 1;
58061+
58062+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
58063+ for (i = 0; i < num; i++) {
58064+ curgid = (int)gidlist[i];
58065+ if (real == curgid)
58066+ realok = 1;
58067+ if (effective == curgid)
58068+ effectiveok = 1;
58069+ if (fs == curgid)
58070+ fsok = 1;
58071+ }
58072+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
58073+ for (i = 0; i < num; i++) {
58074+ curgid = (int)gidlist[i];
58075+ if (real == curgid)
58076+ break;
58077+ if (effective == curgid)
58078+ break;
58079+ if (fs == curgid)
58080+ break;
58081+ }
58082+ /* not in deny list */
58083+ if (i == num) {
58084+ realok = 1;
58085+ effectiveok = 1;
58086+ fsok = 1;
58087+ }
58088+ }
58089+
58090+ if (realok && effectiveok && fsok)
58091+ return 0;
58092+ else {
58093+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
58094+ return 1;
58095+ }
58096+}
58097+
58098+void
58099+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
58100+{
58101+ struct acl_role_label *role = task->role;
58102+ struct acl_subject_label *subj = NULL;
58103+ struct acl_object_label *obj;
58104+ struct file *filp;
58105+
58106+ if (unlikely(!(gr_status & GR_READY)))
58107+ return;
58108+
58109+ filp = task->exec_file;
58110+
58111+ /* kernel process, we'll give them the kernel role */
58112+ if (unlikely(!filp)) {
58113+ task->role = kernel_role;
58114+ task->acl = kernel_role->root_label;
58115+ return;
58116+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
58117+ role = lookup_acl_role_label(task, uid, gid);
58118+
58119+ /* perform subject lookup in possibly new role
58120+ we can use this result below in the case where role == task->role
58121+ */
58122+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
58123+
58124+ /* if we changed uid/gid, but result in the same role
58125+ and are using inheritance, don't lose the inherited subject
58126+ if current subject is other than what normal lookup
58127+ would result in, we arrived via inheritance, don't
58128+ lose subject
58129+ */
58130+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
58131+ (subj == task->acl)))
58132+ task->acl = subj;
58133+
58134+ task->role = role;
58135+
58136+ task->is_writable = 0;
58137+
58138+ /* ignore additional mmap checks for processes that are writable
58139+ by the default ACL */
58140+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58141+ if (unlikely(obj->mode & GR_WRITE))
58142+ task->is_writable = 1;
58143+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
58144+ if (unlikely(obj->mode & GR_WRITE))
58145+ task->is_writable = 1;
58146+
58147+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58148+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
58149+#endif
58150+
58151+ gr_set_proc_res(task);
58152+
58153+ return;
58154+}
58155+
58156+int
58157+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
58158+ const int unsafe_share)
58159+{
58160+ struct task_struct *task = current;
58161+ struct acl_subject_label *newacl;
58162+ struct acl_object_label *obj;
58163+ __u32 retmode;
58164+
58165+ if (unlikely(!(gr_status & GR_READY)))
58166+ return 0;
58167+
58168+ newacl = chk_subj_label(dentry, mnt, task->role);
58169+
58170+ task_lock(task);
58171+ if ((((task->ptrace & PT_PTRACED) || unsafe_share) &&
58172+ !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
58173+ !(task->role->roletype & GR_ROLE_GOD) &&
58174+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
58175+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN)))) {
58176+ task_unlock(task);
58177+ if (unsafe_share)
58178+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
58179+ else
58180+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
58181+ return -EACCES;
58182+ }
58183+ task_unlock(task);
58184+
58185+ obj = chk_obj_label(dentry, mnt, task->acl);
58186+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
58187+
58188+ if (!(task->acl->mode & GR_INHERITLEARN) &&
58189+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
58190+ if (obj->nested)
58191+ task->acl = obj->nested;
58192+ else
58193+ task->acl = newacl;
58194+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
58195+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
58196+
58197+ task->is_writable = 0;
58198+
58199+ /* ignore additional mmap checks for processes that are writable
58200+ by the default ACL */
58201+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
58202+ if (unlikely(obj->mode & GR_WRITE))
58203+ task->is_writable = 1;
58204+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
58205+ if (unlikely(obj->mode & GR_WRITE))
58206+ task->is_writable = 1;
58207+
58208+ gr_set_proc_res(task);
58209+
58210+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58211+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
58212+#endif
58213+ return 0;
58214+}
58215+
58216+/* always called with valid inodev ptr */
58217+static void
58218+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
58219+{
58220+ struct acl_object_label *matchpo;
58221+ struct acl_subject_label *matchps;
58222+ struct acl_subject_label *subj;
58223+ struct acl_role_label *role;
58224+ unsigned int x;
58225+
58226+ FOR_EACH_ROLE_START(role)
58227+ FOR_EACH_SUBJECT_START(role, subj, x)
58228+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
58229+ matchpo->mode |= GR_DELETED;
58230+ FOR_EACH_SUBJECT_END(subj,x)
58231+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
58232+ if (subj->inode == ino && subj->device == dev)
58233+ subj->mode |= GR_DELETED;
58234+ FOR_EACH_NESTED_SUBJECT_END(subj)
58235+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
58236+ matchps->mode |= GR_DELETED;
58237+ FOR_EACH_ROLE_END(role)
58238+
58239+ inodev->nentry->deleted = 1;
58240+
58241+ return;
58242+}
58243+
58244+void
58245+gr_handle_delete(const ino_t ino, const dev_t dev)
58246+{
58247+ struct inodev_entry *inodev;
58248+
58249+ if (unlikely(!(gr_status & GR_READY)))
58250+ return;
58251+
58252+ write_lock(&gr_inode_lock);
58253+ inodev = lookup_inodev_entry(ino, dev);
58254+ if (inodev != NULL)
58255+ do_handle_delete(inodev, ino, dev);
58256+ write_unlock(&gr_inode_lock);
58257+
58258+ return;
58259+}
58260+
58261+static void
58262+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
58263+ const ino_t newinode, const dev_t newdevice,
58264+ struct acl_subject_label *subj)
58265+{
58266+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
58267+ struct acl_object_label *match;
58268+
58269+ match = subj->obj_hash[index];
58270+
58271+ while (match && (match->inode != oldinode ||
58272+ match->device != olddevice ||
58273+ !(match->mode & GR_DELETED)))
58274+ match = match->next;
58275+
58276+ if (match && (match->inode == oldinode)
58277+ && (match->device == olddevice)
58278+ && (match->mode & GR_DELETED)) {
58279+ if (match->prev == NULL) {
58280+ subj->obj_hash[index] = match->next;
58281+ if (match->next != NULL)
58282+ match->next->prev = NULL;
58283+ } else {
58284+ match->prev->next = match->next;
58285+ if (match->next != NULL)
58286+ match->next->prev = match->prev;
58287+ }
58288+ match->prev = NULL;
58289+ match->next = NULL;
58290+ match->inode = newinode;
58291+ match->device = newdevice;
58292+ match->mode &= ~GR_DELETED;
58293+
58294+ insert_acl_obj_label(match, subj);
58295+ }
58296+
58297+ return;
58298+}
58299+
58300+static void
58301+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
58302+ const ino_t newinode, const dev_t newdevice,
58303+ struct acl_role_label *role)
58304+{
58305+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
58306+ struct acl_subject_label *match;
58307+
58308+ match = role->subj_hash[index];
58309+
58310+ while (match && (match->inode != oldinode ||
58311+ match->device != olddevice ||
58312+ !(match->mode & GR_DELETED)))
58313+ match = match->next;
58314+
58315+ if (match && (match->inode == oldinode)
58316+ && (match->device == olddevice)
58317+ && (match->mode & GR_DELETED)) {
58318+ if (match->prev == NULL) {
58319+ role->subj_hash[index] = match->next;
58320+ if (match->next != NULL)
58321+ match->next->prev = NULL;
58322+ } else {
58323+ match->prev->next = match->next;
58324+ if (match->next != NULL)
58325+ match->next->prev = match->prev;
58326+ }
58327+ match->prev = NULL;
58328+ match->next = NULL;
58329+ match->inode = newinode;
58330+ match->device = newdevice;
58331+ match->mode &= ~GR_DELETED;
58332+
58333+ insert_acl_subj_label(match, role);
58334+ }
58335+
58336+ return;
58337+}
58338+
58339+static void
58340+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
58341+ const ino_t newinode, const dev_t newdevice)
58342+{
58343+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
58344+ struct inodev_entry *match;
58345+
58346+ match = inodev_set.i_hash[index];
58347+
58348+ while (match && (match->nentry->inode != oldinode ||
58349+ match->nentry->device != olddevice || !match->nentry->deleted))
58350+ match = match->next;
58351+
58352+ if (match && (match->nentry->inode == oldinode)
58353+ && (match->nentry->device == olddevice) &&
58354+ match->nentry->deleted) {
58355+ if (match->prev == NULL) {
58356+ inodev_set.i_hash[index] = match->next;
58357+ if (match->next != NULL)
58358+ match->next->prev = NULL;
58359+ } else {
58360+ match->prev->next = match->next;
58361+ if (match->next != NULL)
58362+ match->next->prev = match->prev;
58363+ }
58364+ match->prev = NULL;
58365+ match->next = NULL;
58366+ match->nentry->inode = newinode;
58367+ match->nentry->device = newdevice;
58368+ match->nentry->deleted = 0;
58369+
58370+ insert_inodev_entry(match);
58371+ }
58372+
58373+ return;
58374+}
58375+
58376+static void
58377+__do_handle_create(const struct name_entry *matchn, ino_t inode, dev_t dev)
58378+{
58379+ struct acl_subject_label *subj;
58380+ struct acl_role_label *role;
58381+ unsigned int x;
58382+
58383+ FOR_EACH_ROLE_START(role)
58384+ update_acl_subj_label(matchn->inode, matchn->device,
58385+ inode, dev, role);
58386+
58387+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
58388+ if ((subj->inode == inode) && (subj->device == dev)) {
58389+ subj->inode = inode;
58390+ subj->device = dev;
58391+ }
58392+ FOR_EACH_NESTED_SUBJECT_END(subj)
58393+ FOR_EACH_SUBJECT_START(role, subj, x)
58394+ update_acl_obj_label(matchn->inode, matchn->device,
58395+ inode, dev, subj);
58396+ FOR_EACH_SUBJECT_END(subj,x)
58397+ FOR_EACH_ROLE_END(role)
58398+
58399+ update_inodev_entry(matchn->inode, matchn->device, inode, dev);
58400+
58401+ return;
58402+}
58403+
58404+static void
58405+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
58406+ const struct vfsmount *mnt)
58407+{
58408+ ino_t ino = dentry->d_inode->i_ino;
58409+ dev_t dev = __get_dev(dentry);
58410+
58411+ __do_handle_create(matchn, ino, dev);
58412+
58413+ return;
58414+}
58415+
58416+void
58417+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58418+{
58419+ struct name_entry *matchn;
58420+
58421+ if (unlikely(!(gr_status & GR_READY)))
58422+ return;
58423+
58424+ preempt_disable();
58425+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
58426+
58427+ if (unlikely((unsigned long)matchn)) {
58428+ write_lock(&gr_inode_lock);
58429+ do_handle_create(matchn, dentry, mnt);
58430+ write_unlock(&gr_inode_lock);
58431+ }
58432+ preempt_enable();
58433+
58434+ return;
58435+}
58436+
58437+void
58438+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
58439+{
58440+ struct name_entry *matchn;
58441+
58442+ if (unlikely(!(gr_status & GR_READY)))
58443+ return;
58444+
58445+ preempt_disable();
58446+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
58447+
58448+ if (unlikely((unsigned long)matchn)) {
58449+ write_lock(&gr_inode_lock);
58450+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
58451+ write_unlock(&gr_inode_lock);
58452+ }
58453+ preempt_enable();
58454+
58455+ return;
58456+}
58457+
58458+void
58459+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58460+ struct dentry *old_dentry,
58461+ struct dentry *new_dentry,
58462+ struct vfsmount *mnt, const __u8 replace)
58463+{
58464+ struct name_entry *matchn;
58465+ struct inodev_entry *inodev;
58466+ struct inode *inode = new_dentry->d_inode;
58467+ ino_t oldinode = old_dentry->d_inode->i_ino;
58468+ dev_t olddev = __get_dev(old_dentry);
58469+
58470+ /* vfs_rename swaps the name and parent link for old_dentry and
58471+ new_dentry
58472+ at this point, old_dentry has the new name, parent link, and inode
58473+ for the renamed file
58474+ if a file is being replaced by a rename, new_dentry has the inode
58475+ and name for the replaced file
58476+ */
58477+
58478+ if (unlikely(!(gr_status & GR_READY)))
58479+ return;
58480+
58481+ preempt_disable();
58482+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
58483+
58484+ /* we wouldn't have to check d_inode if it weren't for
58485+ NFS silly-renaming
58486+ */
58487+
58488+ write_lock(&gr_inode_lock);
58489+ if (unlikely(replace && inode)) {
58490+ ino_t newinode = inode->i_ino;
58491+ dev_t newdev = __get_dev(new_dentry);
58492+ inodev = lookup_inodev_entry(newinode, newdev);
58493+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
58494+ do_handle_delete(inodev, newinode, newdev);
58495+ }
58496+
58497+ inodev = lookup_inodev_entry(oldinode, olddev);
58498+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
58499+ do_handle_delete(inodev, oldinode, olddev);
58500+
58501+ if (unlikely((unsigned long)matchn))
58502+ do_handle_create(matchn, old_dentry, mnt);
58503+
58504+ write_unlock(&gr_inode_lock);
58505+ preempt_enable();
58506+
58507+ return;
58508+}
58509+
58510+static int
58511+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
58512+ unsigned char **sum)
58513+{
58514+ struct acl_role_label *r;
58515+ struct role_allowed_ip *ipp;
58516+ struct role_transition *trans;
58517+ unsigned int i;
58518+ int found = 0;
58519+ u32 curr_ip = current->signal->curr_ip;
58520+
58521+ current->signal->saved_ip = curr_ip;
58522+
58523+ /* check transition table */
58524+
58525+ for (trans = current->role->transitions; trans; trans = trans->next) {
58526+ if (!strcmp(rolename, trans->rolename)) {
58527+ found = 1;
58528+ break;
58529+ }
58530+ }
58531+
58532+ if (!found)
58533+ return 0;
58534+
58535+ /* handle special roles that do not require authentication
58536+ and check ip */
58537+
58538+ FOR_EACH_ROLE_START(r)
58539+ if (!strcmp(rolename, r->rolename) &&
58540+ (r->roletype & GR_ROLE_SPECIAL)) {
58541+ found = 0;
58542+ if (r->allowed_ips != NULL) {
58543+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
58544+ if ((ntohl(curr_ip) & ipp->netmask) ==
58545+ (ntohl(ipp->addr) & ipp->netmask))
58546+ found = 1;
58547+ }
58548+ } else
58549+ found = 2;
58550+ if (!found)
58551+ return 0;
58552+
58553+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
58554+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
58555+ *salt = NULL;
58556+ *sum = NULL;
58557+ return 1;
58558+ }
58559+ }
58560+ FOR_EACH_ROLE_END(r)
58561+
58562+ for (i = 0; i < num_sprole_pws; i++) {
58563+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
58564+ *salt = acl_special_roles[i]->salt;
58565+ *sum = acl_special_roles[i]->sum;
58566+ return 1;
58567+ }
58568+ }
58569+
58570+ return 0;
58571+}
58572+
58573+static void
58574+assign_special_role(char *rolename)
58575+{
58576+ struct acl_object_label *obj;
58577+ struct acl_role_label *r;
58578+ struct acl_role_label *assigned = NULL;
58579+ struct task_struct *tsk;
58580+ struct file *filp;
58581+
58582+ FOR_EACH_ROLE_START(r)
58583+ if (!strcmp(rolename, r->rolename) &&
58584+ (r->roletype & GR_ROLE_SPECIAL)) {
58585+ assigned = r;
58586+ break;
58587+ }
58588+ FOR_EACH_ROLE_END(r)
58589+
58590+ if (!assigned)
58591+ return;
58592+
58593+ read_lock(&tasklist_lock);
58594+ read_lock(&grsec_exec_file_lock);
58595+
58596+ tsk = current->real_parent;
58597+ if (tsk == NULL)
58598+ goto out_unlock;
58599+
58600+ filp = tsk->exec_file;
58601+ if (filp == NULL)
58602+ goto out_unlock;
58603+
58604+ tsk->is_writable = 0;
58605+
58606+ tsk->acl_sp_role = 1;
58607+ tsk->acl_role_id = ++acl_sp_role_value;
58608+ tsk->role = assigned;
58609+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
58610+
58611+ /* ignore additional mmap checks for processes that are writable
58612+ by the default ACL */
58613+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58614+ if (unlikely(obj->mode & GR_WRITE))
58615+ tsk->is_writable = 1;
58616+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
58617+ if (unlikely(obj->mode & GR_WRITE))
58618+ tsk->is_writable = 1;
58619+
58620+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58621+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
58622+#endif
58623+
58624+out_unlock:
58625+ read_unlock(&grsec_exec_file_lock);
58626+ read_unlock(&tasklist_lock);
58627+ return;
58628+}
58629+
58630+int gr_check_secure_terminal(struct task_struct *task)
58631+{
58632+ struct task_struct *p, *p2, *p3;
58633+ struct files_struct *files;
58634+ struct fdtable *fdt;
58635+ struct file *our_file = NULL, *file;
58636+ int i;
58637+
58638+ if (task->signal->tty == NULL)
58639+ return 1;
58640+
58641+ files = get_files_struct(task);
58642+ if (files != NULL) {
58643+ rcu_read_lock();
58644+ fdt = files_fdtable(files);
58645+ for (i=0; i < fdt->max_fds; i++) {
58646+ file = fcheck_files(files, i);
58647+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
58648+ get_file(file);
58649+ our_file = file;
58650+ }
58651+ }
58652+ rcu_read_unlock();
58653+ put_files_struct(files);
58654+ }
58655+
58656+ if (our_file == NULL)
58657+ return 1;
58658+
58659+ read_lock(&tasklist_lock);
58660+ do_each_thread(p2, p) {
58661+ files = get_files_struct(p);
58662+ if (files == NULL ||
58663+ (p->signal && p->signal->tty == task->signal->tty)) {
58664+ if (files != NULL)
58665+ put_files_struct(files);
58666+ continue;
58667+ }
58668+ rcu_read_lock();
58669+ fdt = files_fdtable(files);
58670+ for (i=0; i < fdt->max_fds; i++) {
58671+ file = fcheck_files(files, i);
58672+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
58673+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
58674+ p3 = task;
58675+ while (p3->pid > 0) {
58676+ if (p3 == p)
58677+ break;
58678+ p3 = p3->real_parent;
58679+ }
58680+ if (p3 == p)
58681+ break;
58682+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
58683+ gr_handle_alertkill(p);
58684+ rcu_read_unlock();
58685+ put_files_struct(files);
58686+ read_unlock(&tasklist_lock);
58687+ fput(our_file);
58688+ return 0;
58689+ }
58690+ }
58691+ rcu_read_unlock();
58692+ put_files_struct(files);
58693+ } while_each_thread(p2, p);
58694+ read_unlock(&tasklist_lock);
58695+
58696+ fput(our_file);
58697+ return 1;
58698+}
58699+
58700+ssize_t
58701+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
58702+{
58703+ struct gr_arg_wrapper uwrap;
58704+ unsigned char *sprole_salt = NULL;
58705+ unsigned char *sprole_sum = NULL;
58706+ int error = sizeof (struct gr_arg_wrapper);
58707+ int error2 = 0;
58708+
58709+ mutex_lock(&gr_dev_mutex);
58710+
58711+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
58712+ error = -EPERM;
58713+ goto out;
58714+ }
58715+
58716+ if (count != sizeof (struct gr_arg_wrapper)) {
58717+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
58718+ error = -EINVAL;
58719+ goto out;
58720+ }
58721+
58722+
58723+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
58724+ gr_auth_expires = 0;
58725+ gr_auth_attempts = 0;
58726+ }
58727+
58728+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
58729+ error = -EFAULT;
58730+ goto out;
58731+ }
58732+
58733+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
58734+ error = -EINVAL;
58735+ goto out;
58736+ }
58737+
58738+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
58739+ error = -EFAULT;
58740+ goto out;
58741+ }
58742+
58743+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
58744+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
58745+ time_after(gr_auth_expires, get_seconds())) {
58746+ error = -EBUSY;
58747+ goto out;
58748+ }
58749+
58750+ /* if non-root trying to do anything other than use a special role,
58751+ do not attempt authentication, do not count towards authentication
58752+ locking
58753+ */
58754+
58755+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
58756+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
58757+ current_uid()) {
58758+ error = -EPERM;
58759+ goto out;
58760+ }
58761+
58762+ /* ensure pw and special role name are null terminated */
58763+
58764+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
58765+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
58766+
58767+ /* Okay.
58768+ * We have our enough of the argument structure..(we have yet
58769+ * to copy_from_user the tables themselves) . Copy the tables
58770+ * only if we need them, i.e. for loading operations. */
58771+
58772+ switch (gr_usermode->mode) {
58773+ case GR_STATUS:
58774+ if (gr_status & GR_READY) {
58775+ error = 1;
58776+ if (!gr_check_secure_terminal(current))
58777+ error = 3;
58778+ } else
58779+ error = 2;
58780+ goto out;
58781+ case GR_SHUTDOWN:
58782+ if ((gr_status & GR_READY)
58783+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58784+ pax_open_kernel();
58785+ gr_status &= ~GR_READY;
58786+ pax_close_kernel();
58787+
58788+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
58789+ free_variables();
58790+ memset(gr_usermode, 0, sizeof (struct gr_arg));
58791+ memset(gr_system_salt, 0, GR_SALT_LEN);
58792+ memset(gr_system_sum, 0, GR_SHA_LEN);
58793+ } else if (gr_status & GR_READY) {
58794+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
58795+ error = -EPERM;
58796+ } else {
58797+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
58798+ error = -EAGAIN;
58799+ }
58800+ break;
58801+ case GR_ENABLE:
58802+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
58803+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
58804+ else {
58805+ if (gr_status & GR_READY)
58806+ error = -EAGAIN;
58807+ else
58808+ error = error2;
58809+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
58810+ }
58811+ break;
58812+ case GR_RELOAD:
58813+ if (!(gr_status & GR_READY)) {
58814+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
58815+ error = -EAGAIN;
58816+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58817+ lock_kernel();
58818+
58819+ pax_open_kernel();
58820+ gr_status &= ~GR_READY;
58821+ pax_close_kernel();
58822+
58823+ free_variables();
58824+ if (!(error2 = gracl_init(gr_usermode))) {
58825+ unlock_kernel();
58826+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
58827+ } else {
58828+ unlock_kernel();
58829+ error = error2;
58830+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
58831+ }
58832+ } else {
58833+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
58834+ error = -EPERM;
58835+ }
58836+ break;
58837+ case GR_SEGVMOD:
58838+ if (unlikely(!(gr_status & GR_READY))) {
58839+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
58840+ error = -EAGAIN;
58841+ break;
58842+ }
58843+
58844+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
58845+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
58846+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
58847+ struct acl_subject_label *segvacl;
58848+ segvacl =
58849+ lookup_acl_subj_label(gr_usermode->segv_inode,
58850+ gr_usermode->segv_device,
58851+ current->role);
58852+ if (segvacl) {
58853+ segvacl->crashes = 0;
58854+ segvacl->expires = 0;
58855+ }
58856+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
58857+ gr_remove_uid(gr_usermode->segv_uid);
58858+ }
58859+ } else {
58860+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
58861+ error = -EPERM;
58862+ }
58863+ break;
58864+ case GR_SPROLE:
58865+ case GR_SPROLEPAM:
58866+ if (unlikely(!(gr_status & GR_READY))) {
58867+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
58868+ error = -EAGAIN;
58869+ break;
58870+ }
58871+
58872+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
58873+ current->role->expires = 0;
58874+ current->role->auth_attempts = 0;
58875+ }
58876+
58877+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
58878+ time_after(current->role->expires, get_seconds())) {
58879+ error = -EBUSY;
58880+ goto out;
58881+ }
58882+
58883+ if (lookup_special_role_auth
58884+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
58885+ && ((!sprole_salt && !sprole_sum)
58886+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
58887+ char *p = "";
58888+ assign_special_role(gr_usermode->sp_role);
58889+ read_lock(&tasklist_lock);
58890+ if (current->real_parent)
58891+ p = current->real_parent->role->rolename;
58892+ read_unlock(&tasklist_lock);
58893+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
58894+ p, acl_sp_role_value);
58895+ } else {
58896+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
58897+ error = -EPERM;
58898+ if(!(current->role->auth_attempts++))
58899+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
58900+
58901+ goto out;
58902+ }
58903+ break;
58904+ case GR_UNSPROLE:
58905+ if (unlikely(!(gr_status & GR_READY))) {
58906+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
58907+ error = -EAGAIN;
58908+ break;
58909+ }
58910+
58911+ if (current->role->roletype & GR_ROLE_SPECIAL) {
58912+ char *p = "";
58913+ int i = 0;
58914+
58915+ read_lock(&tasklist_lock);
58916+ if (current->real_parent) {
58917+ p = current->real_parent->role->rolename;
58918+ i = current->real_parent->acl_role_id;
58919+ }
58920+ read_unlock(&tasklist_lock);
58921+
58922+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
58923+ gr_set_acls(1);
58924+ } else {
58925+ error = -EPERM;
58926+ goto out;
58927+ }
58928+ break;
58929+ default:
58930+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
58931+ error = -EINVAL;
58932+ break;
58933+ }
58934+
58935+ if (error != -EPERM)
58936+ goto out;
58937+
58938+ if(!(gr_auth_attempts++))
58939+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
58940+
58941+ out:
58942+ mutex_unlock(&gr_dev_mutex);
58943+ return error;
58944+}
58945+
58946+/* must be called with
58947+ rcu_read_lock();
58948+ read_lock(&tasklist_lock);
58949+ read_lock(&grsec_exec_file_lock);
58950+*/
58951+int gr_apply_subject_to_task(struct task_struct *task)
58952+{
58953+ struct acl_object_label *obj;
58954+ char *tmpname;
58955+ struct acl_subject_label *tmpsubj;
58956+ struct file *filp;
58957+ struct name_entry *nmatch;
58958+
58959+ filp = task->exec_file;
58960+ if (filp == NULL)
58961+ return 0;
58962+
58963+ /* the following is to apply the correct subject
58964+ on binaries running when the RBAC system
58965+ is enabled, when the binaries have been
58966+ replaced or deleted since their execution
58967+ -----
58968+ when the RBAC system starts, the inode/dev
58969+ from exec_file will be one the RBAC system
58970+ is unaware of. It only knows the inode/dev
58971+ of the present file on disk, or the absence
58972+ of it.
58973+ */
58974+ preempt_disable();
58975+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
58976+
58977+ nmatch = lookup_name_entry(tmpname);
58978+ preempt_enable();
58979+ tmpsubj = NULL;
58980+ if (nmatch) {
58981+ if (nmatch->deleted)
58982+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
58983+ else
58984+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
58985+ if (tmpsubj != NULL)
58986+ task->acl = tmpsubj;
58987+ }
58988+ if (tmpsubj == NULL)
58989+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
58990+ task->role);
58991+ if (task->acl) {
58992+ task->is_writable = 0;
58993+ /* ignore additional mmap checks for processes that are writable
58994+ by the default ACL */
58995+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58996+ if (unlikely(obj->mode & GR_WRITE))
58997+ task->is_writable = 1;
58998+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
58999+ if (unlikely(obj->mode & GR_WRITE))
59000+ task->is_writable = 1;
59001+
59002+ gr_set_proc_res(task);
59003+
59004+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59005+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
59006+#endif
59007+ } else {
59008+ return 1;
59009+ }
59010+
59011+ return 0;
59012+}
59013+
59014+int
59015+gr_set_acls(const int type)
59016+{
59017+ struct task_struct *task, *task2;
59018+ struct acl_role_label *role = current->role;
59019+ __u16 acl_role_id = current->acl_role_id;
59020+ const struct cred *cred;
59021+ int ret;
59022+
59023+ rcu_read_lock();
59024+ read_lock(&tasklist_lock);
59025+ read_lock(&grsec_exec_file_lock);
59026+ do_each_thread(task2, task) {
59027+ /* check to see if we're called from the exit handler,
59028+ if so, only replace ACLs that have inherited the admin
59029+ ACL */
59030+
59031+ if (type && (task->role != role ||
59032+ task->acl_role_id != acl_role_id))
59033+ continue;
59034+
59035+ task->acl_role_id = 0;
59036+ task->acl_sp_role = 0;
59037+
59038+ if (task->exec_file) {
59039+ cred = __task_cred(task);
59040+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
59041+
59042+ ret = gr_apply_subject_to_task(task);
59043+ if (ret) {
59044+ read_unlock(&grsec_exec_file_lock);
59045+ read_unlock(&tasklist_lock);
59046+ rcu_read_unlock();
59047+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
59048+ return ret;
59049+ }
59050+ } else {
59051+ // it's a kernel process
59052+ task->role = kernel_role;
59053+ task->acl = kernel_role->root_label;
59054+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
59055+ task->acl->mode &= ~GR_PROCFIND;
59056+#endif
59057+ }
59058+ } while_each_thread(task2, task);
59059+ read_unlock(&grsec_exec_file_lock);
59060+ read_unlock(&tasklist_lock);
59061+ rcu_read_unlock();
59062+
59063+ return 0;
59064+}
59065+
59066+void
59067+gr_learn_resource(const struct task_struct *task,
59068+ const int res, const unsigned long wanted, const int gt)
59069+{
59070+ struct acl_subject_label *acl;
59071+ const struct cred *cred;
59072+
59073+ if (unlikely((gr_status & GR_READY) &&
59074+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
59075+ goto skip_reslog;
59076+
59077+#ifdef CONFIG_GRKERNSEC_RESLOG
59078+ gr_log_resource(task, res, wanted, gt);
59079+#endif
59080+ skip_reslog:
59081+
59082+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
59083+ return;
59084+
59085+ acl = task->acl;
59086+
59087+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
59088+ !(acl->resmask & (1 << (unsigned short) res))))
59089+ return;
59090+
59091+ if (wanted >= acl->res[res].rlim_cur) {
59092+ unsigned long res_add;
59093+
59094+ res_add = wanted;
59095+ switch (res) {
59096+ case RLIMIT_CPU:
59097+ res_add += GR_RLIM_CPU_BUMP;
59098+ break;
59099+ case RLIMIT_FSIZE:
59100+ res_add += GR_RLIM_FSIZE_BUMP;
59101+ break;
59102+ case RLIMIT_DATA:
59103+ res_add += GR_RLIM_DATA_BUMP;
59104+ break;
59105+ case RLIMIT_STACK:
59106+ res_add += GR_RLIM_STACK_BUMP;
59107+ break;
59108+ case RLIMIT_CORE:
59109+ res_add += GR_RLIM_CORE_BUMP;
59110+ break;
59111+ case RLIMIT_RSS:
59112+ res_add += GR_RLIM_RSS_BUMP;
59113+ break;
59114+ case RLIMIT_NPROC:
59115+ res_add += GR_RLIM_NPROC_BUMP;
59116+ break;
59117+ case RLIMIT_NOFILE:
59118+ res_add += GR_RLIM_NOFILE_BUMP;
59119+ break;
59120+ case RLIMIT_MEMLOCK:
59121+ res_add += GR_RLIM_MEMLOCK_BUMP;
59122+ break;
59123+ case RLIMIT_AS:
59124+ res_add += GR_RLIM_AS_BUMP;
59125+ break;
59126+ case RLIMIT_LOCKS:
59127+ res_add += GR_RLIM_LOCKS_BUMP;
59128+ break;
59129+ case RLIMIT_SIGPENDING:
59130+ res_add += GR_RLIM_SIGPENDING_BUMP;
59131+ break;
59132+ case RLIMIT_MSGQUEUE:
59133+ res_add += GR_RLIM_MSGQUEUE_BUMP;
59134+ break;
59135+ case RLIMIT_NICE:
59136+ res_add += GR_RLIM_NICE_BUMP;
59137+ break;
59138+ case RLIMIT_RTPRIO:
59139+ res_add += GR_RLIM_RTPRIO_BUMP;
59140+ break;
59141+ case RLIMIT_RTTIME:
59142+ res_add += GR_RLIM_RTTIME_BUMP;
59143+ break;
59144+ }
59145+
59146+ acl->res[res].rlim_cur = res_add;
59147+
59148+ if (wanted > acl->res[res].rlim_max)
59149+ acl->res[res].rlim_max = res_add;
59150+
59151+ /* only log the subject filename, since resource logging is supported for
59152+ single-subject learning only */
59153+ rcu_read_lock();
59154+ cred = __task_cred(task);
59155+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
59156+ task->role->roletype, cred->uid, cred->gid, acl->filename,
59157+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
59158+ "", (unsigned long) res, &task->signal->saved_ip);
59159+ rcu_read_unlock();
59160+ }
59161+
59162+ return;
59163+}
59164+
59165+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
59166+void
59167+pax_set_initial_flags(struct linux_binprm *bprm)
59168+{
59169+ struct task_struct *task = current;
59170+ struct acl_subject_label *proc;
59171+ unsigned long flags;
59172+
59173+ if (unlikely(!(gr_status & GR_READY)))
59174+ return;
59175+
59176+ flags = pax_get_flags(task);
59177+
59178+ proc = task->acl;
59179+
59180+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
59181+ flags &= ~MF_PAX_PAGEEXEC;
59182+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
59183+ flags &= ~MF_PAX_SEGMEXEC;
59184+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
59185+ flags &= ~MF_PAX_RANDMMAP;
59186+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
59187+ flags &= ~MF_PAX_EMUTRAMP;
59188+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
59189+ flags &= ~MF_PAX_MPROTECT;
59190+
59191+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
59192+ flags |= MF_PAX_PAGEEXEC;
59193+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
59194+ flags |= MF_PAX_SEGMEXEC;
59195+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
59196+ flags |= MF_PAX_RANDMMAP;
59197+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
59198+ flags |= MF_PAX_EMUTRAMP;
59199+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
59200+ flags |= MF_PAX_MPROTECT;
59201+
59202+ pax_set_flags(task, flags);
59203+
59204+ return;
59205+}
59206+#endif
59207+
59208+#ifdef CONFIG_SYSCTL
59209+/* Eric Biederman likes breaking userland ABI and every inode-based security
59210+ system to save 35kb of memory */
59211+
59212+/* we modify the passed in filename, but adjust it back before returning */
59213+static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
59214+{
59215+ struct name_entry *nmatch;
59216+ char *p, *lastp = NULL;
59217+ struct acl_object_label *obj = NULL, *tmp;
59218+ struct acl_subject_label *tmpsubj;
59219+ char c = '\0';
59220+
59221+ read_lock(&gr_inode_lock);
59222+
59223+ p = name + len - 1;
59224+ do {
59225+ nmatch = lookup_name_entry(name);
59226+ if (lastp != NULL)
59227+ *lastp = c;
59228+
59229+ if (nmatch == NULL)
59230+ goto next_component;
59231+ tmpsubj = current->acl;
59232+ do {
59233+ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
59234+ if (obj != NULL) {
59235+ tmp = obj->globbed;
59236+ while (tmp) {
59237+ if (!glob_match(tmp->filename, name)) {
59238+ obj = tmp;
59239+ goto found_obj;
59240+ }
59241+ tmp = tmp->next;
59242+ }
59243+ goto found_obj;
59244+ }
59245+ } while ((tmpsubj = tmpsubj->parent_subject));
59246+next_component:
59247+ /* end case */
59248+ if (p == name)
59249+ break;
59250+
59251+ while (*p != '/')
59252+ p--;
59253+ if (p == name)
59254+ lastp = p + 1;
59255+ else {
59256+ lastp = p;
59257+ p--;
59258+ }
59259+ c = *lastp;
59260+ *lastp = '\0';
59261+ } while (1);
59262+found_obj:
59263+ read_unlock(&gr_inode_lock);
59264+ /* obj returned will always be non-null */
59265+ return obj;
59266+}
59267+
59268+/* returns 0 when allowing, non-zero on error
59269+ op of 0 is used for readdir, so we don't log the names of hidden files
59270+*/
59271+__u32
59272+gr_handle_sysctl(const struct ctl_table *table, const int op)
59273+{
59274+ ctl_table *tmp;
59275+ const char *proc_sys = "/proc/sys";
59276+ char *path;
59277+ struct acl_object_label *obj;
59278+ unsigned short len = 0, pos = 0, depth = 0, i;
59279+ __u32 err = 0;
59280+ __u32 mode = 0;
59281+
59282+ if (unlikely(!(gr_status & GR_READY)))
59283+ return 0;
59284+
59285+ /* for now, ignore operations on non-sysctl entries if it's not a
59286+ readdir*/
59287+ if (table->child != NULL && op != 0)
59288+ return 0;
59289+
59290+ mode |= GR_FIND;
59291+ /* it's only a read if it's an entry, read on dirs is for readdir */
59292+ if (op & MAY_READ)
59293+ mode |= GR_READ;
59294+ if (op & MAY_WRITE)
59295+ mode |= GR_WRITE;
59296+
59297+ preempt_disable();
59298+
59299+ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
59300+
59301+ /* it's only a read/write if it's an actual entry, not a dir
59302+ (which are opened for readdir)
59303+ */
59304+
59305+ /* convert the requested sysctl entry into a pathname */
59306+
59307+ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
59308+ len += strlen(tmp->procname);
59309+ len++;
59310+ depth++;
59311+ }
59312+
59313+ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
59314+ /* deny */
59315+ goto out;
59316+ }
59317+
59318+ memset(path, 0, PAGE_SIZE);
59319+
59320+ memcpy(path, proc_sys, strlen(proc_sys));
59321+
59322+ pos += strlen(proc_sys);
59323+
59324+ for (; depth > 0; depth--) {
59325+ path[pos] = '/';
59326+ pos++;
59327+ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
59328+ if (depth == i) {
59329+ memcpy(path + pos, tmp->procname,
59330+ strlen(tmp->procname));
59331+ pos += strlen(tmp->procname);
59332+ }
59333+ i++;
59334+ }
59335+ }
59336+
59337+ obj = gr_lookup_by_name(path, pos);
59338+ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
59339+
59340+ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
59341+ ((err & mode) != mode))) {
59342+ __u32 new_mode = mode;
59343+
59344+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
59345+
59346+ err = 0;
59347+ gr_log_learn_sysctl(path, new_mode);
59348+ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
59349+ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
59350+ err = -ENOENT;
59351+ } else if (!(err & GR_FIND)) {
59352+ err = -ENOENT;
59353+ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
59354+ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
59355+ path, (mode & GR_READ) ? " reading" : "",
59356+ (mode & GR_WRITE) ? " writing" : "");
59357+ err = -EACCES;
59358+ } else if ((err & mode) != mode) {
59359+ err = -EACCES;
59360+ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
59361+ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
59362+ path, (mode & GR_READ) ? " reading" : "",
59363+ (mode & GR_WRITE) ? " writing" : "");
59364+ err = 0;
59365+ } else
59366+ err = 0;
59367+
59368+ out:
59369+ preempt_enable();
59370+
59371+ return err;
59372+}
59373+#endif
59374+
59375+int
59376+gr_handle_proc_ptrace(struct task_struct *task)
59377+{
59378+ struct file *filp;
59379+ struct task_struct *tmp = task;
59380+ struct task_struct *curtemp = current;
59381+ __u32 retmode;
59382+
59383+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
59384+ if (unlikely(!(gr_status & GR_READY)))
59385+ return 0;
59386+#endif
59387+
59388+ read_lock(&tasklist_lock);
59389+ read_lock(&grsec_exec_file_lock);
59390+ filp = task->exec_file;
59391+
59392+ while (tmp->pid > 0) {
59393+ if (tmp == curtemp)
59394+ break;
59395+ tmp = tmp->real_parent;
59396+ }
59397+
59398+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
59399+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
59400+ read_unlock(&grsec_exec_file_lock);
59401+ read_unlock(&tasklist_lock);
59402+ return 1;
59403+ }
59404+
59405+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59406+ if (!(gr_status & GR_READY)) {
59407+ read_unlock(&grsec_exec_file_lock);
59408+ read_unlock(&tasklist_lock);
59409+ return 0;
59410+ }
59411+#endif
59412+
59413+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
59414+ read_unlock(&grsec_exec_file_lock);
59415+ read_unlock(&tasklist_lock);
59416+
59417+ if (retmode & GR_NOPTRACE)
59418+ return 1;
59419+
59420+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
59421+ && (current->acl != task->acl || (current->acl != current->role->root_label
59422+ && current->pid != task->pid)))
59423+ return 1;
59424+
59425+ return 0;
59426+}
59427+
59428+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
59429+{
59430+ if (unlikely(!(gr_status & GR_READY)))
59431+ return;
59432+
59433+ if (!(current->role->roletype & GR_ROLE_GOD))
59434+ return;
59435+
59436+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
59437+ p->role->rolename, gr_task_roletype_to_char(p),
59438+ p->acl->filename);
59439+}
59440+
59441+int
59442+gr_handle_ptrace(struct task_struct *task, const long request)
59443+{
59444+ struct task_struct *tmp = task;
59445+ struct task_struct *curtemp = current;
59446+ __u32 retmode;
59447+
59448+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
59449+ if (unlikely(!(gr_status & GR_READY)))
59450+ return 0;
59451+#endif
59452+
59453+ read_lock(&tasklist_lock);
59454+ while (tmp->pid > 0) {
59455+ if (tmp == curtemp)
59456+ break;
59457+ tmp = tmp->real_parent;
59458+ }
59459+
59460+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
59461+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
59462+ read_unlock(&tasklist_lock);
59463+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59464+ return 1;
59465+ }
59466+ read_unlock(&tasklist_lock);
59467+
59468+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59469+ if (!(gr_status & GR_READY))
59470+ return 0;
59471+#endif
59472+
59473+ read_lock(&grsec_exec_file_lock);
59474+ if (unlikely(!task->exec_file)) {
59475+ read_unlock(&grsec_exec_file_lock);
59476+ return 0;
59477+ }
59478+
59479+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
59480+ read_unlock(&grsec_exec_file_lock);
59481+
59482+ if (retmode & GR_NOPTRACE) {
59483+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59484+ return 1;
59485+ }
59486+
59487+ if (retmode & GR_PTRACERD) {
59488+ switch (request) {
59489+ case PTRACE_POKETEXT:
59490+ case PTRACE_POKEDATA:
59491+ case PTRACE_POKEUSR:
59492+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
59493+ case PTRACE_SETREGS:
59494+ case PTRACE_SETFPREGS:
59495+#endif
59496+#ifdef CONFIG_X86
59497+ case PTRACE_SETFPXREGS:
59498+#endif
59499+#ifdef CONFIG_ALTIVEC
59500+ case PTRACE_SETVRREGS:
59501+#endif
59502+ return 1;
59503+ default:
59504+ return 0;
59505+ }
59506+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
59507+ !(current->role->roletype & GR_ROLE_GOD) &&
59508+ (current->acl != task->acl)) {
59509+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
59510+ return 1;
59511+ }
59512+
59513+ return 0;
59514+}
59515+
59516+static int is_writable_mmap(const struct file *filp)
59517+{
59518+ struct task_struct *task = current;
59519+ struct acl_object_label *obj, *obj2;
59520+
59521+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
59522+ !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))) {
59523+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59524+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
59525+ task->role->root_label);
59526+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
59527+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
59528+ return 1;
59529+ }
59530+ }
59531+ return 0;
59532+}
59533+
59534+int
59535+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
59536+{
59537+ __u32 mode;
59538+
59539+ if (unlikely(!file || !(prot & PROT_EXEC)))
59540+ return 1;
59541+
59542+ if (is_writable_mmap(file))
59543+ return 0;
59544+
59545+ mode =
59546+ gr_search_file(file->f_path.dentry,
59547+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
59548+ file->f_path.mnt);
59549+
59550+ if (!gr_tpe_allow(file))
59551+ return 0;
59552+
59553+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
59554+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59555+ return 0;
59556+ } else if (unlikely(!(mode & GR_EXEC))) {
59557+ return 0;
59558+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
59559+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59560+ return 1;
59561+ }
59562+
59563+ return 1;
59564+}
59565+
59566+int
59567+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
59568+{
59569+ __u32 mode;
59570+
59571+ if (unlikely(!file || !(prot & PROT_EXEC)))
59572+ return 1;
59573+
59574+ if (is_writable_mmap(file))
59575+ return 0;
59576+
59577+ mode =
59578+ gr_search_file(file->f_path.dentry,
59579+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
59580+ file->f_path.mnt);
59581+
59582+ if (!gr_tpe_allow(file))
59583+ return 0;
59584+
59585+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
59586+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59587+ return 0;
59588+ } else if (unlikely(!(mode & GR_EXEC))) {
59589+ return 0;
59590+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
59591+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
59592+ return 1;
59593+ }
59594+
59595+ return 1;
59596+}
59597+
59598+void
59599+gr_acl_handle_psacct(struct task_struct *task, const long code)
59600+{
59601+ unsigned long runtime;
59602+ unsigned long cputime;
59603+ unsigned int wday, cday;
59604+ __u8 whr, chr;
59605+ __u8 wmin, cmin;
59606+ __u8 wsec, csec;
59607+ struct timespec timeval;
59608+
59609+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
59610+ !(task->acl->mode & GR_PROCACCT)))
59611+ return;
59612+
59613+ do_posix_clock_monotonic_gettime(&timeval);
59614+ runtime = timeval.tv_sec - task->start_time.tv_sec;
59615+ wday = runtime / (3600 * 24);
59616+ runtime -= wday * (3600 * 24);
59617+ whr = runtime / 3600;
59618+ runtime -= whr * 3600;
59619+ wmin = runtime / 60;
59620+ runtime -= wmin * 60;
59621+ wsec = runtime;
59622+
59623+ cputime = (task->utime + task->stime) / HZ;
59624+ cday = cputime / (3600 * 24);
59625+ cputime -= cday * (3600 * 24);
59626+ chr = cputime / 3600;
59627+ cputime -= chr * 3600;
59628+ cmin = cputime / 60;
59629+ cputime -= cmin * 60;
59630+ csec = cputime;
59631+
59632+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
59633+
59634+ return;
59635+}
59636+
59637+void gr_set_kernel_label(struct task_struct *task)
59638+{
59639+ if (gr_status & GR_READY) {
59640+ task->role = kernel_role;
59641+ task->acl = kernel_role->root_label;
59642+ }
59643+ return;
59644+}
59645+
59646+#ifdef CONFIG_TASKSTATS
59647+int gr_is_taskstats_denied(int pid)
59648+{
59649+ struct task_struct *task;
59650+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59651+ const struct cred *cred;
59652+#endif
59653+ int ret = 0;
59654+
59655+ /* restrict taskstats viewing to un-chrooted root users
59656+ who have the 'view' subject flag if the RBAC system is enabled
59657+ */
59658+
59659+ rcu_read_lock();
59660+ read_lock(&tasklist_lock);
59661+ task = find_task_by_vpid(pid);
59662+ if (task) {
59663+#ifdef CONFIG_GRKERNSEC_CHROOT
59664+ if (proc_is_chrooted(task))
59665+ ret = -EACCES;
59666+#endif
59667+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59668+ cred = __task_cred(task);
59669+#ifdef CONFIG_GRKERNSEC_PROC_USER
59670+ if (cred->uid != 0)
59671+ ret = -EACCES;
59672+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59673+ if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
59674+ ret = -EACCES;
59675+#endif
59676+#endif
59677+ if (gr_status & GR_READY) {
59678+ if (!(task->acl->mode & GR_VIEW))
59679+ ret = -EACCES;
59680+ }
59681+ } else
59682+ ret = -ENOENT;
59683+
59684+ read_unlock(&tasklist_lock);
59685+ rcu_read_unlock();
59686+
59687+ return ret;
59688+}
59689+#endif
59690+
59691+/* AUXV entries are filled via a descendant of search_binary_handler
59692+ after we've already applied the subject for the target
59693+*/
59694+int gr_acl_enable_at_secure(void)
59695+{
59696+ if (unlikely(!(gr_status & GR_READY)))
59697+ return 0;
59698+
59699+ if (current->acl->mode & GR_ATSECURE)
59700+ return 1;
59701+
59702+ return 0;
59703+}
59704+
59705+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
59706+{
59707+ struct task_struct *task = current;
59708+ struct dentry *dentry = file->f_path.dentry;
59709+ struct vfsmount *mnt = file->f_path.mnt;
59710+ struct acl_object_label *obj, *tmp;
59711+ struct acl_subject_label *subj;
59712+ unsigned int bufsize;
59713+ int is_not_root;
59714+ char *path;
59715+ dev_t dev = __get_dev(dentry);
59716+
59717+ if (unlikely(!(gr_status & GR_READY)))
59718+ return 1;
59719+
59720+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59721+ return 1;
59722+
59723+ /* ignore Eric Biederman */
59724+ if (IS_PRIVATE(dentry->d_inode))
59725+ return 1;
59726+
59727+ subj = task->acl;
59728+ do {
59729+ obj = lookup_acl_obj_label(ino, dev, subj);
59730+ if (obj != NULL)
59731+ return (obj->mode & GR_FIND) ? 1 : 0;
59732+ } while ((subj = subj->parent_subject));
59733+
59734+ /* this is purely an optimization since we're looking for an object
59735+ for the directory we're doing a readdir on
59736+ if it's possible for any globbed object to match the entry we're
59737+ filling into the directory, then the object we find here will be
59738+ an anchor point with attached globbed objects
59739+ */
59740+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
59741+ if (obj->globbed == NULL)
59742+ return (obj->mode & GR_FIND) ? 1 : 0;
59743+
59744+ is_not_root = ((obj->filename[0] == '/') &&
59745+ (obj->filename[1] == '\0')) ? 0 : 1;
59746+ bufsize = PAGE_SIZE - namelen - is_not_root;
59747+
59748+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
59749+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
59750+ return 1;
59751+
59752+ preempt_disable();
59753+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
59754+ bufsize);
59755+
59756+ bufsize = strlen(path);
59757+
59758+ /* if base is "/", don't append an additional slash */
59759+ if (is_not_root)
59760+ *(path + bufsize) = '/';
59761+ memcpy(path + bufsize + is_not_root, name, namelen);
59762+ *(path + bufsize + namelen + is_not_root) = '\0';
59763+
59764+ tmp = obj->globbed;
59765+ while (tmp) {
59766+ if (!glob_match(tmp->filename, path)) {
59767+ preempt_enable();
59768+ return (tmp->mode & GR_FIND) ? 1 : 0;
59769+ }
59770+ tmp = tmp->next;
59771+ }
59772+ preempt_enable();
59773+ return (obj->mode & GR_FIND) ? 1 : 0;
59774+}
59775+
59776+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
59777+EXPORT_SYMBOL(gr_acl_is_enabled);
59778+#endif
59779+EXPORT_SYMBOL(gr_learn_resource);
59780+EXPORT_SYMBOL(gr_set_kernel_label);
59781+#ifdef CONFIG_SECURITY
59782+EXPORT_SYMBOL(gr_check_user_change);
59783+EXPORT_SYMBOL(gr_check_group_change);
59784+#endif
59785+
59786diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
59787new file mode 100644
59788index 0000000..34fefda
59789--- /dev/null
59790+++ b/grsecurity/gracl_alloc.c
59791@@ -0,0 +1,105 @@
59792+#include <linux/kernel.h>
59793+#include <linux/mm.h>
59794+#include <linux/slab.h>
59795+#include <linux/vmalloc.h>
59796+#include <linux/gracl.h>
59797+#include <linux/grsecurity.h>
59798+
59799+static unsigned long alloc_stack_next = 1;
59800+static unsigned long alloc_stack_size = 1;
59801+static void **alloc_stack;
59802+
59803+static __inline__ int
59804+alloc_pop(void)
59805+{
59806+ if (alloc_stack_next == 1)
59807+ return 0;
59808+
59809+ kfree(alloc_stack[alloc_stack_next - 2]);
59810+
59811+ alloc_stack_next--;
59812+
59813+ return 1;
59814+}
59815+
59816+static __inline__ int
59817+alloc_push(void *buf)
59818+{
59819+ if (alloc_stack_next >= alloc_stack_size)
59820+ return 1;
59821+
59822+ alloc_stack[alloc_stack_next - 1] = buf;
59823+
59824+ alloc_stack_next++;
59825+
59826+ return 0;
59827+}
59828+
59829+void *
59830+acl_alloc(unsigned long len)
59831+{
59832+ void *ret = NULL;
59833+
59834+ if (!len || len > PAGE_SIZE)
59835+ goto out;
59836+
59837+ ret = kmalloc(len, GFP_KERNEL);
59838+
59839+ if (ret) {
59840+ if (alloc_push(ret)) {
59841+ kfree(ret);
59842+ ret = NULL;
59843+ }
59844+ }
59845+
59846+out:
59847+ return ret;
59848+}
59849+
59850+void *
59851+acl_alloc_num(unsigned long num, unsigned long len)
59852+{
59853+ if (!len || (num > (PAGE_SIZE / len)))
59854+ return NULL;
59855+
59856+ return acl_alloc(num * len);
59857+}
59858+
59859+void
59860+acl_free_all(void)
59861+{
59862+ if (gr_acl_is_enabled() || !alloc_stack)
59863+ return;
59864+
59865+ while (alloc_pop()) ;
59866+
59867+ if (alloc_stack) {
59868+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
59869+ kfree(alloc_stack);
59870+ else
59871+ vfree(alloc_stack);
59872+ }
59873+
59874+ alloc_stack = NULL;
59875+ alloc_stack_size = 1;
59876+ alloc_stack_next = 1;
59877+
59878+ return;
59879+}
59880+
59881+int
59882+acl_alloc_stack_init(unsigned long size)
59883+{
59884+ if ((size * sizeof (void *)) <= PAGE_SIZE)
59885+ alloc_stack =
59886+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
59887+ else
59888+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
59889+
59890+ alloc_stack_size = size;
59891+
59892+ if (!alloc_stack)
59893+ return 0;
59894+ else
59895+ return 1;
59896+}
59897diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
59898new file mode 100644
59899index 0000000..955ddfb
59900--- /dev/null
59901+++ b/grsecurity/gracl_cap.c
59902@@ -0,0 +1,101 @@
59903+#include <linux/kernel.h>
59904+#include <linux/module.h>
59905+#include <linux/sched.h>
59906+#include <linux/gracl.h>
59907+#include <linux/grsecurity.h>
59908+#include <linux/grinternal.h>
59909+
59910+extern const char *captab_log[];
59911+extern int captab_log_entries;
59912+
59913+int
59914+gr_acl_is_capable(const int cap)
59915+{
59916+ struct task_struct *task = current;
59917+ const struct cred *cred = current_cred();
59918+ struct acl_subject_label *curracl;
59919+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
59920+ kernel_cap_t cap_audit = __cap_empty_set;
59921+
59922+ if (!gr_acl_is_enabled())
59923+ return 1;
59924+
59925+ curracl = task->acl;
59926+
59927+ cap_drop = curracl->cap_lower;
59928+ cap_mask = curracl->cap_mask;
59929+ cap_audit = curracl->cap_invert_audit;
59930+
59931+ while ((curracl = curracl->parent_subject)) {
59932+ /* if the cap isn't specified in the current computed mask but is specified in the
59933+ current level subject, and is lowered in the current level subject, then add
59934+ it to the set of dropped capabilities
59935+ otherwise, add the current level subject's mask to the current computed mask
59936+ */
59937+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
59938+ cap_raise(cap_mask, cap);
59939+ if (cap_raised(curracl->cap_lower, cap))
59940+ cap_raise(cap_drop, cap);
59941+ if (cap_raised(curracl->cap_invert_audit, cap))
59942+ cap_raise(cap_audit, cap);
59943+ }
59944+ }
59945+
59946+ if (!cap_raised(cap_drop, cap)) {
59947+ if (cap_raised(cap_audit, cap))
59948+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
59949+ return 1;
59950+ }
59951+
59952+ curracl = task->acl;
59953+
59954+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
59955+ && cap_raised(cred->cap_effective, cap)) {
59956+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
59957+ task->role->roletype, cred->uid,
59958+ cred->gid, task->exec_file ?
59959+ gr_to_filename(task->exec_file->f_path.dentry,
59960+ task->exec_file->f_path.mnt) : curracl->filename,
59961+ curracl->filename, 0UL,
59962+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
59963+ return 1;
59964+ }
59965+
59966+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
59967+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
59968+ return 0;
59969+}
59970+
59971+int
59972+gr_acl_is_capable_nolog(const int cap)
59973+{
59974+ struct acl_subject_label *curracl;
59975+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
59976+
59977+ if (!gr_acl_is_enabled())
59978+ return 1;
59979+
59980+ curracl = current->acl;
59981+
59982+ cap_drop = curracl->cap_lower;
59983+ cap_mask = curracl->cap_mask;
59984+
59985+ while ((curracl = curracl->parent_subject)) {
59986+ /* if the cap isn't specified in the current computed mask but is specified in the
59987+ current level subject, and is lowered in the current level subject, then add
59988+ it to the set of dropped capabilities
59989+ otherwise, add the current level subject's mask to the current computed mask
59990+ */
59991+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
59992+ cap_raise(cap_mask, cap);
59993+ if (cap_raised(curracl->cap_lower, cap))
59994+ cap_raise(cap_drop, cap);
59995+ }
59996+ }
59997+
59998+ if (!cap_raised(cap_drop, cap))
59999+ return 1;
60000+
60001+ return 0;
60002+}
60003+
60004diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
60005new file mode 100644
60006index 0000000..d5f210c
60007--- /dev/null
60008+++ b/grsecurity/gracl_fs.c
60009@@ -0,0 +1,433 @@
60010+#include <linux/kernel.h>
60011+#include <linux/sched.h>
60012+#include <linux/types.h>
60013+#include <linux/fs.h>
60014+#include <linux/file.h>
60015+#include <linux/stat.h>
60016+#include <linux/grsecurity.h>
60017+#include <linux/grinternal.h>
60018+#include <linux/gracl.h>
60019+
60020+__u32
60021+gr_acl_handle_hidden_file(const struct dentry * dentry,
60022+ const struct vfsmount * mnt)
60023+{
60024+ __u32 mode;
60025+
60026+ if (unlikely(!dentry->d_inode))
60027+ return GR_FIND;
60028+
60029+ mode =
60030+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
60031+
60032+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
60033+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
60034+ return mode;
60035+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
60036+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
60037+ return 0;
60038+ } else if (unlikely(!(mode & GR_FIND)))
60039+ return 0;
60040+
60041+ return GR_FIND;
60042+}
60043+
60044+__u32
60045+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
60046+ int acc_mode)
60047+{
60048+ __u32 reqmode = GR_FIND;
60049+ __u32 mode;
60050+
60051+ if (unlikely(!dentry->d_inode))
60052+ return reqmode;
60053+
60054+ if (acc_mode & MAY_APPEND)
60055+ reqmode |= GR_APPEND;
60056+ else if (acc_mode & MAY_WRITE)
60057+ reqmode |= GR_WRITE;
60058+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
60059+ reqmode |= GR_READ;
60060+
60061+ mode =
60062+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
60063+ mnt);
60064+
60065+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
60066+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
60067+ reqmode & GR_READ ? " reading" : "",
60068+ reqmode & GR_WRITE ? " writing" : reqmode &
60069+ GR_APPEND ? " appending" : "");
60070+ return reqmode;
60071+ } else
60072+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
60073+ {
60074+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
60075+ reqmode & GR_READ ? " reading" : "",
60076+ reqmode & GR_WRITE ? " writing" : reqmode &
60077+ GR_APPEND ? " appending" : "");
60078+ return 0;
60079+ } else if (unlikely((mode & reqmode) != reqmode))
60080+ return 0;
60081+
60082+ return reqmode;
60083+}
60084+
60085+__u32
60086+gr_acl_handle_creat(const struct dentry * dentry,
60087+ const struct dentry * p_dentry,
60088+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60089+ const int imode)
60090+{
60091+ __u32 reqmode = GR_WRITE | GR_CREATE;
60092+ __u32 mode;
60093+
60094+ if (acc_mode & MAY_APPEND)
60095+ reqmode |= GR_APPEND;
60096+ // if a directory was required or the directory already exists, then
60097+ // don't count this open as a read
60098+ if ((acc_mode & MAY_READ) &&
60099+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
60100+ reqmode |= GR_READ;
60101+ if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
60102+ reqmode |= GR_SETID;
60103+
60104+ mode =
60105+ gr_check_create(dentry, p_dentry, p_mnt,
60106+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
60107+
60108+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
60109+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
60110+ reqmode & GR_READ ? " reading" : "",
60111+ reqmode & GR_WRITE ? " writing" : reqmode &
60112+ GR_APPEND ? " appending" : "");
60113+ return reqmode;
60114+ } else
60115+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
60116+ {
60117+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
60118+ reqmode & GR_READ ? " reading" : "",
60119+ reqmode & GR_WRITE ? " writing" : reqmode &
60120+ GR_APPEND ? " appending" : "");
60121+ return 0;
60122+ } else if (unlikely((mode & reqmode) != reqmode))
60123+ return 0;
60124+
60125+ return reqmode;
60126+}
60127+
60128+__u32
60129+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
60130+ const int fmode)
60131+{
60132+ __u32 mode, reqmode = GR_FIND;
60133+
60134+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
60135+ reqmode |= GR_EXEC;
60136+ if (fmode & S_IWOTH)
60137+ reqmode |= GR_WRITE;
60138+ if (fmode & S_IROTH)
60139+ reqmode |= GR_READ;
60140+
60141+ mode =
60142+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
60143+ mnt);
60144+
60145+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
60146+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
60147+ reqmode & GR_READ ? " reading" : "",
60148+ reqmode & GR_WRITE ? " writing" : "",
60149+ reqmode & GR_EXEC ? " executing" : "");
60150+ return reqmode;
60151+ } else
60152+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
60153+ {
60154+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
60155+ reqmode & GR_READ ? " reading" : "",
60156+ reqmode & GR_WRITE ? " writing" : "",
60157+ reqmode & GR_EXEC ? " executing" : "");
60158+ return 0;
60159+ } else if (unlikely((mode & reqmode) != reqmode))
60160+ return 0;
60161+
60162+ return reqmode;
60163+}
60164+
60165+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
60166+{
60167+ __u32 mode;
60168+
60169+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
60170+
60171+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
60172+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
60173+ return mode;
60174+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
60175+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
60176+ return 0;
60177+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
60178+ return 0;
60179+
60180+ return (reqmode);
60181+}
60182+
60183+__u32
60184+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
60185+{
60186+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
60187+}
60188+
60189+__u32
60190+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
60191+{
60192+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
60193+}
60194+
60195+__u32
60196+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
60197+{
60198+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
60199+}
60200+
60201+__u32
60202+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
60203+{
60204+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
60205+}
60206+
60207+__u32
60208+gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
60209+ mode_t mode)
60210+{
60211+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
60212+ return 1;
60213+
60214+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
60215+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
60216+ GR_FCHMOD_ACL_MSG);
60217+ } else {
60218+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
60219+ }
60220+}
60221+
60222+__u32
60223+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
60224+ mode_t mode)
60225+{
60226+ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
60227+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
60228+ GR_CHMOD_ACL_MSG);
60229+ } else {
60230+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
60231+ }
60232+}
60233+
60234+__u32
60235+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
60236+{
60237+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
60238+}
60239+
60240+__u32
60241+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
60242+{
60243+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
60244+}
60245+
60246+__u32
60247+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
60248+{
60249+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
60250+}
60251+
60252+__u32
60253+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
60254+{
60255+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
60256+ GR_UNIXCONNECT_ACL_MSG);
60257+}
60258+
60259+/* hardlinks require at minimum create and link permission,
60260+ any additional privilege required is based on the
60261+ privilege of the file being linked to
60262+*/
60263+__u32
60264+gr_acl_handle_link(const struct dentry * new_dentry,
60265+ const struct dentry * parent_dentry,
60266+ const struct vfsmount * parent_mnt,
60267+ const struct dentry * old_dentry,
60268+ const struct vfsmount * old_mnt, const char *to)
60269+{
60270+ __u32 mode;
60271+ __u32 needmode = GR_CREATE | GR_LINK;
60272+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
60273+
60274+ mode =
60275+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
60276+ old_mnt);
60277+
60278+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
60279+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
60280+ return mode;
60281+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
60282+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
60283+ return 0;
60284+ } else if (unlikely((mode & needmode) != needmode))
60285+ return 0;
60286+
60287+ return 1;
60288+}
60289+
60290+__u32
60291+gr_acl_handle_symlink(const struct dentry * new_dentry,
60292+ const struct dentry * parent_dentry,
60293+ const struct vfsmount * parent_mnt, const char *from)
60294+{
60295+ __u32 needmode = GR_WRITE | GR_CREATE;
60296+ __u32 mode;
60297+
60298+ mode =
60299+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
60300+ GR_CREATE | GR_AUDIT_CREATE |
60301+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
60302+
60303+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
60304+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
60305+ return mode;
60306+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
60307+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
60308+ return 0;
60309+ } else if (unlikely((mode & needmode) != needmode))
60310+ return 0;
60311+
60312+ return (GR_WRITE | GR_CREATE);
60313+}
60314+
60315+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)
60316+{
60317+ __u32 mode;
60318+
60319+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
60320+
60321+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
60322+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
60323+ return mode;
60324+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
60325+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
60326+ return 0;
60327+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
60328+ return 0;
60329+
60330+ return (reqmode);
60331+}
60332+
60333+__u32
60334+gr_acl_handle_mknod(const struct dentry * new_dentry,
60335+ const struct dentry * parent_dentry,
60336+ const struct vfsmount * parent_mnt,
60337+ const int mode)
60338+{
60339+ __u32 reqmode = GR_WRITE | GR_CREATE;
60340+ if (unlikely(mode & (S_ISUID | S_ISGID)))
60341+ reqmode |= GR_SETID;
60342+
60343+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
60344+ reqmode, GR_MKNOD_ACL_MSG);
60345+}
60346+
60347+__u32
60348+gr_acl_handle_mkdir(const struct dentry *new_dentry,
60349+ const struct dentry *parent_dentry,
60350+ const struct vfsmount *parent_mnt)
60351+{
60352+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
60353+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
60354+}
60355+
60356+#define RENAME_CHECK_SUCCESS(old, new) \
60357+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
60358+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
60359+
60360+int
60361+gr_acl_handle_rename(struct dentry *new_dentry,
60362+ struct dentry *parent_dentry,
60363+ const struct vfsmount *parent_mnt,
60364+ struct dentry *old_dentry,
60365+ struct inode *old_parent_inode,
60366+ struct vfsmount *old_mnt, const char *newname)
60367+{
60368+ __u32 comp1, comp2;
60369+ int error = 0;
60370+
60371+ if (unlikely(!gr_acl_is_enabled()))
60372+ return 0;
60373+
60374+ if (!new_dentry->d_inode) {
60375+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
60376+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
60377+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
60378+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
60379+ GR_DELETE | GR_AUDIT_DELETE |
60380+ GR_AUDIT_READ | GR_AUDIT_WRITE |
60381+ GR_SUPPRESS, old_mnt);
60382+ } else {
60383+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
60384+ GR_CREATE | GR_DELETE |
60385+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
60386+ GR_AUDIT_READ | GR_AUDIT_WRITE |
60387+ GR_SUPPRESS, parent_mnt);
60388+ comp2 =
60389+ gr_search_file(old_dentry,
60390+ GR_READ | GR_WRITE | GR_AUDIT_READ |
60391+ GR_DELETE | GR_AUDIT_DELETE |
60392+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
60393+ }
60394+
60395+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
60396+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
60397+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
60398+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
60399+ && !(comp2 & GR_SUPPRESS)) {
60400+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
60401+ error = -EACCES;
60402+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
60403+ error = -EACCES;
60404+
60405+ return error;
60406+}
60407+
60408+void
60409+gr_acl_handle_exit(void)
60410+{
60411+ u16 id;
60412+ char *rolename;
60413+ struct file *exec_file;
60414+
60415+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
60416+ !(current->role->roletype & GR_ROLE_PERSIST))) {
60417+ id = current->acl_role_id;
60418+ rolename = current->role->rolename;
60419+ gr_set_acls(1);
60420+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
60421+ }
60422+
60423+ write_lock(&grsec_exec_file_lock);
60424+ exec_file = current->exec_file;
60425+ current->exec_file = NULL;
60426+ write_unlock(&grsec_exec_file_lock);
60427+
60428+ if (exec_file)
60429+ fput(exec_file);
60430+}
60431+
60432+int
60433+gr_acl_handle_procpidmem(const struct task_struct *task)
60434+{
60435+ if (unlikely(!gr_acl_is_enabled()))
60436+ return 0;
60437+
60438+ if (task != current && task->acl->mode & GR_PROTPROCFD)
60439+ return -EACCES;
60440+
60441+ return 0;
60442+}
60443diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
60444new file mode 100644
60445index 0000000..cd07b96
60446--- /dev/null
60447+++ b/grsecurity/gracl_ip.c
60448@@ -0,0 +1,382 @@
60449+#include <linux/kernel.h>
60450+#include <asm/uaccess.h>
60451+#include <asm/errno.h>
60452+#include <net/sock.h>
60453+#include <linux/file.h>
60454+#include <linux/fs.h>
60455+#include <linux/net.h>
60456+#include <linux/in.h>
60457+#include <linux/skbuff.h>
60458+#include <linux/ip.h>
60459+#include <linux/udp.h>
60460+#include <linux/smp_lock.h>
60461+#include <linux/types.h>
60462+#include <linux/sched.h>
60463+#include <linux/netdevice.h>
60464+#include <linux/inetdevice.h>
60465+#include <linux/gracl.h>
60466+#include <linux/grsecurity.h>
60467+#include <linux/grinternal.h>
60468+
60469+#define GR_BIND 0x01
60470+#define GR_CONNECT 0x02
60471+#define GR_INVERT 0x04
60472+#define GR_BINDOVERRIDE 0x08
60473+#define GR_CONNECTOVERRIDE 0x10
60474+#define GR_SOCK_FAMILY 0x20
60475+
60476+static const char * gr_protocols[IPPROTO_MAX] = {
60477+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
60478+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
60479+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
60480+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
60481+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
60482+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
60483+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
60484+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
60485+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
60486+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
60487+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
60488+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
60489+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
60490+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
60491+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
60492+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
60493+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
60494+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
60495+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
60496+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
60497+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
60498+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
60499+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
60500+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
60501+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
60502+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
60503+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
60504+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
60505+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
60506+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
60507+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
60508+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
60509+ };
60510+
60511+static const char * gr_socktypes[SOCK_MAX] = {
60512+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
60513+ "unknown:7", "unknown:8", "unknown:9", "packet"
60514+ };
60515+
60516+static const char * gr_sockfamilies[AF_MAX+1] = {
60517+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
60518+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
60519+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
60520+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154"
60521+ };
60522+
60523+const char *
60524+gr_proto_to_name(unsigned char proto)
60525+{
60526+ return gr_protocols[proto];
60527+}
60528+
60529+const char *
60530+gr_socktype_to_name(unsigned char type)
60531+{
60532+ return gr_socktypes[type];
60533+}
60534+
60535+const char *
60536+gr_sockfamily_to_name(unsigned char family)
60537+{
60538+ return gr_sockfamilies[family];
60539+}
60540+
60541+int
60542+gr_search_socket(const int domain, const int type, const int protocol)
60543+{
60544+ struct acl_subject_label *curr;
60545+ const struct cred *cred = current_cred();
60546+
60547+ if (unlikely(!gr_acl_is_enabled()))
60548+ goto exit;
60549+
60550+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
60551+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
60552+ goto exit; // let the kernel handle it
60553+
60554+ curr = current->acl;
60555+
60556+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
60557+ /* the family is allowed, if this is PF_INET allow it only if
60558+ the extra sock type/protocol checks pass */
60559+ if (domain == PF_INET)
60560+ goto inet_check;
60561+ goto exit;
60562+ } else {
60563+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60564+ __u32 fakeip = 0;
60565+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60566+ current->role->roletype, cred->uid,
60567+ cred->gid, current->exec_file ?
60568+ gr_to_filename(current->exec_file->f_path.dentry,
60569+ current->exec_file->f_path.mnt) :
60570+ curr->filename, curr->filename,
60571+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
60572+ &current->signal->saved_ip);
60573+ goto exit;
60574+ }
60575+ goto exit_fail;
60576+ }
60577+
60578+inet_check:
60579+ /* the rest of this checking is for IPv4 only */
60580+ if (!curr->ips)
60581+ goto exit;
60582+
60583+ if ((curr->ip_type & (1 << type)) &&
60584+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
60585+ goto exit;
60586+
60587+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60588+ /* we don't place acls on raw sockets , and sometimes
60589+ dgram/ip sockets are opened for ioctl and not
60590+ bind/connect, so we'll fake a bind learn log */
60591+ if (type == SOCK_RAW || type == SOCK_PACKET) {
60592+ __u32 fakeip = 0;
60593+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60594+ current->role->roletype, cred->uid,
60595+ cred->gid, current->exec_file ?
60596+ gr_to_filename(current->exec_file->f_path.dentry,
60597+ current->exec_file->f_path.mnt) :
60598+ curr->filename, curr->filename,
60599+ &fakeip, 0, type,
60600+ protocol, GR_CONNECT, &current->signal->saved_ip);
60601+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
60602+ __u32 fakeip = 0;
60603+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60604+ current->role->roletype, cred->uid,
60605+ cred->gid, current->exec_file ?
60606+ gr_to_filename(current->exec_file->f_path.dentry,
60607+ current->exec_file->f_path.mnt) :
60608+ curr->filename, curr->filename,
60609+ &fakeip, 0, type,
60610+ protocol, GR_BIND, &current->signal->saved_ip);
60611+ }
60612+ /* we'll log when they use connect or bind */
60613+ goto exit;
60614+ }
60615+
60616+exit_fail:
60617+ if (domain == PF_INET)
60618+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
60619+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
60620+ else
60621+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
60622+ gr_socktype_to_name(type), protocol);
60623+
60624+ return 0;
60625+exit:
60626+ return 1;
60627+}
60628+
60629+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)
60630+{
60631+ if ((ip->mode & mode) &&
60632+ (ip_port >= ip->low) &&
60633+ (ip_port <= ip->high) &&
60634+ ((ntohl(ip_addr) & our_netmask) ==
60635+ (ntohl(our_addr) & our_netmask))
60636+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
60637+ && (ip->type & (1 << type))) {
60638+ if (ip->mode & GR_INVERT)
60639+ return 2; // specifically denied
60640+ else
60641+ return 1; // allowed
60642+ }
60643+
60644+ return 0; // not specifically allowed, may continue parsing
60645+}
60646+
60647+static int
60648+gr_search_connectbind(const int full_mode, struct sock *sk,
60649+ struct sockaddr_in *addr, const int type)
60650+{
60651+ char iface[IFNAMSIZ] = {0};
60652+ struct acl_subject_label *curr;
60653+ struct acl_ip_label *ip;
60654+ struct inet_sock *isk;
60655+ struct net_device *dev;
60656+ struct in_device *idev;
60657+ unsigned long i;
60658+ int ret;
60659+ int mode = full_mode & (GR_BIND | GR_CONNECT);
60660+ __u32 ip_addr = 0;
60661+ __u32 our_addr;
60662+ __u32 our_netmask;
60663+ char *p;
60664+ __u16 ip_port = 0;
60665+ const struct cred *cred = current_cred();
60666+
60667+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
60668+ return 0;
60669+
60670+ curr = current->acl;
60671+ isk = inet_sk(sk);
60672+
60673+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
60674+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
60675+ addr->sin_addr.s_addr = curr->inaddr_any_override;
60676+ if ((full_mode & GR_CONNECT) && isk->saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
60677+ struct sockaddr_in saddr;
60678+ int err;
60679+
60680+ saddr.sin_family = AF_INET;
60681+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
60682+ saddr.sin_port = isk->sport;
60683+
60684+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
60685+ if (err)
60686+ return err;
60687+
60688+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
60689+ if (err)
60690+ return err;
60691+ }
60692+
60693+ if (!curr->ips)
60694+ return 0;
60695+
60696+ ip_addr = addr->sin_addr.s_addr;
60697+ ip_port = ntohs(addr->sin_port);
60698+
60699+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
60700+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
60701+ current->role->roletype, cred->uid,
60702+ cred->gid, current->exec_file ?
60703+ gr_to_filename(current->exec_file->f_path.dentry,
60704+ current->exec_file->f_path.mnt) :
60705+ curr->filename, curr->filename,
60706+ &ip_addr, ip_port, type,
60707+ sk->sk_protocol, mode, &current->signal->saved_ip);
60708+ return 0;
60709+ }
60710+
60711+ for (i = 0; i < curr->ip_num; i++) {
60712+ ip = *(curr->ips + i);
60713+ if (ip->iface != NULL) {
60714+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
60715+ p = strchr(iface, ':');
60716+ if (p != NULL)
60717+ *p = '\0';
60718+ dev = dev_get_by_name(sock_net(sk), iface);
60719+ if (dev == NULL)
60720+ continue;
60721+ idev = in_dev_get(dev);
60722+ if (idev == NULL) {
60723+ dev_put(dev);
60724+ continue;
60725+ }
60726+ rcu_read_lock();
60727+ for_ifa(idev) {
60728+ if (!strcmp(ip->iface, ifa->ifa_label)) {
60729+ our_addr = ifa->ifa_address;
60730+ our_netmask = 0xffffffff;
60731+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
60732+ if (ret == 1) {
60733+ rcu_read_unlock();
60734+ in_dev_put(idev);
60735+ dev_put(dev);
60736+ return 0;
60737+ } else if (ret == 2) {
60738+ rcu_read_unlock();
60739+ in_dev_put(idev);
60740+ dev_put(dev);
60741+ goto denied;
60742+ }
60743+ }
60744+ } endfor_ifa(idev);
60745+ rcu_read_unlock();
60746+ in_dev_put(idev);
60747+ dev_put(dev);
60748+ } else {
60749+ our_addr = ip->addr;
60750+ our_netmask = ip->netmask;
60751+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
60752+ if (ret == 1)
60753+ return 0;
60754+ else if (ret == 2)
60755+ goto denied;
60756+ }
60757+ }
60758+
60759+denied:
60760+ if (mode == GR_BIND)
60761+ 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));
60762+ else if (mode == GR_CONNECT)
60763+ 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));
60764+
60765+ return -EACCES;
60766+}
60767+
60768+int
60769+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
60770+{
60771+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
60772+}
60773+
60774+int
60775+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
60776+{
60777+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
60778+}
60779+
60780+int gr_search_listen(struct socket *sock)
60781+{
60782+ struct sock *sk = sock->sk;
60783+ struct sockaddr_in addr;
60784+
60785+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
60786+ addr.sin_port = inet_sk(sk)->sport;
60787+
60788+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
60789+}
60790+
60791+int gr_search_accept(struct socket *sock)
60792+{
60793+ struct sock *sk = sock->sk;
60794+ struct sockaddr_in addr;
60795+
60796+ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
60797+ addr.sin_port = inet_sk(sk)->sport;
60798+
60799+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
60800+}
60801+
60802+int
60803+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
60804+{
60805+ if (addr)
60806+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
60807+ else {
60808+ struct sockaddr_in sin;
60809+ const struct inet_sock *inet = inet_sk(sk);
60810+
60811+ sin.sin_addr.s_addr = inet->daddr;
60812+ sin.sin_port = inet->dport;
60813+
60814+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
60815+ }
60816+}
60817+
60818+int
60819+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
60820+{
60821+ struct sockaddr_in sin;
60822+
60823+ if (unlikely(skb->len < sizeof (struct udphdr)))
60824+ return 0; // skip this packet
60825+
60826+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
60827+ sin.sin_port = udp_hdr(skb)->source;
60828+
60829+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
60830+}
60831diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
60832new file mode 100644
60833index 0000000..34bdd46
60834--- /dev/null
60835+++ b/grsecurity/gracl_learn.c
60836@@ -0,0 +1,208 @@
60837+#include <linux/kernel.h>
60838+#include <linux/mm.h>
60839+#include <linux/sched.h>
60840+#include <linux/poll.h>
60841+#include <linux/smp_lock.h>
60842+#include <linux/string.h>
60843+#include <linux/file.h>
60844+#include <linux/types.h>
60845+#include <linux/vmalloc.h>
60846+#include <linux/grinternal.h>
60847+
60848+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
60849+ size_t count, loff_t *ppos);
60850+extern int gr_acl_is_enabled(void);
60851+
60852+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
60853+static int gr_learn_attached;
60854+
60855+/* use a 512k buffer */
60856+#define LEARN_BUFFER_SIZE (512 * 1024)
60857+
60858+static DEFINE_SPINLOCK(gr_learn_lock);
60859+static DEFINE_MUTEX(gr_learn_user_mutex);
60860+
60861+/* we need to maintain two buffers, so that the kernel context of grlearn
60862+ uses a semaphore around the userspace copying, and the other kernel contexts
60863+ use a spinlock when copying into the buffer, since they cannot sleep
60864+*/
60865+static char *learn_buffer;
60866+static char *learn_buffer_user;
60867+static int learn_buffer_len;
60868+static int learn_buffer_user_len;
60869+
60870+static ssize_t
60871+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
60872+{
60873+ DECLARE_WAITQUEUE(wait, current);
60874+ ssize_t retval = 0;
60875+
60876+ add_wait_queue(&learn_wait, &wait);
60877+ set_current_state(TASK_INTERRUPTIBLE);
60878+ do {
60879+ mutex_lock(&gr_learn_user_mutex);
60880+ spin_lock(&gr_learn_lock);
60881+ if (learn_buffer_len)
60882+ break;
60883+ spin_unlock(&gr_learn_lock);
60884+ mutex_unlock(&gr_learn_user_mutex);
60885+ if (file->f_flags & O_NONBLOCK) {
60886+ retval = -EAGAIN;
60887+ goto out;
60888+ }
60889+ if (signal_pending(current)) {
60890+ retval = -ERESTARTSYS;
60891+ goto out;
60892+ }
60893+
60894+ schedule();
60895+ } while (1);
60896+
60897+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
60898+ learn_buffer_user_len = learn_buffer_len;
60899+ retval = learn_buffer_len;
60900+ learn_buffer_len = 0;
60901+
60902+ spin_unlock(&gr_learn_lock);
60903+
60904+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
60905+ retval = -EFAULT;
60906+
60907+ mutex_unlock(&gr_learn_user_mutex);
60908+out:
60909+ set_current_state(TASK_RUNNING);
60910+ remove_wait_queue(&learn_wait, &wait);
60911+ return retval;
60912+}
60913+
60914+static unsigned int
60915+poll_learn(struct file * file, poll_table * wait)
60916+{
60917+ poll_wait(file, &learn_wait, wait);
60918+
60919+ if (learn_buffer_len)
60920+ return (POLLIN | POLLRDNORM);
60921+
60922+ return 0;
60923+}
60924+
60925+void
60926+gr_clear_learn_entries(void)
60927+{
60928+ char *tmp;
60929+
60930+ mutex_lock(&gr_learn_user_mutex);
60931+ spin_lock(&gr_learn_lock);
60932+ tmp = learn_buffer;
60933+ learn_buffer = NULL;
60934+ spin_unlock(&gr_learn_lock);
60935+ if (tmp)
60936+ vfree(tmp);
60937+ if (learn_buffer_user != NULL) {
60938+ vfree(learn_buffer_user);
60939+ learn_buffer_user = NULL;
60940+ }
60941+ learn_buffer_len = 0;
60942+ mutex_unlock(&gr_learn_user_mutex);
60943+
60944+ return;
60945+}
60946+
60947+void
60948+gr_add_learn_entry(const char *fmt, ...)
60949+{
60950+ va_list args;
60951+ unsigned int len;
60952+
60953+ if (!gr_learn_attached)
60954+ return;
60955+
60956+ spin_lock(&gr_learn_lock);
60957+
60958+ /* leave a gap at the end so we know when it's "full" but don't have to
60959+ compute the exact length of the string we're trying to append
60960+ */
60961+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
60962+ spin_unlock(&gr_learn_lock);
60963+ wake_up_interruptible(&learn_wait);
60964+ return;
60965+ }
60966+ if (learn_buffer == NULL) {
60967+ spin_unlock(&gr_learn_lock);
60968+ return;
60969+ }
60970+
60971+ va_start(args, fmt);
60972+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
60973+ va_end(args);
60974+
60975+ learn_buffer_len += len + 1;
60976+
60977+ spin_unlock(&gr_learn_lock);
60978+ wake_up_interruptible(&learn_wait);
60979+
60980+ return;
60981+}
60982+
60983+static int
60984+open_learn(struct inode *inode, struct file *file)
60985+{
60986+ if (file->f_mode & FMODE_READ && gr_learn_attached)
60987+ return -EBUSY;
60988+ if (file->f_mode & FMODE_READ) {
60989+ int retval = 0;
60990+ mutex_lock(&gr_learn_user_mutex);
60991+ if (learn_buffer == NULL)
60992+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
60993+ if (learn_buffer_user == NULL)
60994+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
60995+ if (learn_buffer == NULL) {
60996+ retval = -ENOMEM;
60997+ goto out_error;
60998+ }
60999+ if (learn_buffer_user == NULL) {
61000+ retval = -ENOMEM;
61001+ goto out_error;
61002+ }
61003+ learn_buffer_len = 0;
61004+ learn_buffer_user_len = 0;
61005+ gr_learn_attached = 1;
61006+out_error:
61007+ mutex_unlock(&gr_learn_user_mutex);
61008+ return retval;
61009+ }
61010+ return 0;
61011+}
61012+
61013+static int
61014+close_learn(struct inode *inode, struct file *file)
61015+{
61016+ if (file->f_mode & FMODE_READ) {
61017+ char *tmp = NULL;
61018+ mutex_lock(&gr_learn_user_mutex);
61019+ spin_lock(&gr_learn_lock);
61020+ tmp = learn_buffer;
61021+ learn_buffer = NULL;
61022+ spin_unlock(&gr_learn_lock);
61023+ if (tmp)
61024+ vfree(tmp);
61025+ if (learn_buffer_user != NULL) {
61026+ vfree(learn_buffer_user);
61027+ learn_buffer_user = NULL;
61028+ }
61029+ learn_buffer_len = 0;
61030+ learn_buffer_user_len = 0;
61031+ gr_learn_attached = 0;
61032+ mutex_unlock(&gr_learn_user_mutex);
61033+ }
61034+
61035+ return 0;
61036+}
61037+
61038+const struct file_operations grsec_fops = {
61039+ .read = read_learn,
61040+ .write = write_grsec_handler,
61041+ .open = open_learn,
61042+ .release = close_learn,
61043+ .poll = poll_learn,
61044+};
61045diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
61046new file mode 100644
61047index 0000000..70b2179
61048--- /dev/null
61049+++ b/grsecurity/gracl_res.c
61050@@ -0,0 +1,67 @@
61051+#include <linux/kernel.h>
61052+#include <linux/sched.h>
61053+#include <linux/gracl.h>
61054+#include <linux/grinternal.h>
61055+
61056+static const char *restab_log[] = {
61057+ [RLIMIT_CPU] = "RLIMIT_CPU",
61058+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
61059+ [RLIMIT_DATA] = "RLIMIT_DATA",
61060+ [RLIMIT_STACK] = "RLIMIT_STACK",
61061+ [RLIMIT_CORE] = "RLIMIT_CORE",
61062+ [RLIMIT_RSS] = "RLIMIT_RSS",
61063+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
61064+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
61065+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
61066+ [RLIMIT_AS] = "RLIMIT_AS",
61067+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
61068+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
61069+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
61070+ [RLIMIT_NICE] = "RLIMIT_NICE",
61071+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
61072+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
61073+ [GR_CRASH_RES] = "RLIMIT_CRASH"
61074+};
61075+
61076+void
61077+gr_log_resource(const struct task_struct *task,
61078+ const int res, const unsigned long wanted, const int gt)
61079+{
61080+ const struct cred *cred;
61081+ unsigned long rlim;
61082+
61083+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
61084+ return;
61085+
61086+ // not yet supported resource
61087+ if (unlikely(!restab_log[res]))
61088+ return;
61089+
61090+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
61091+ rlim = task->signal->rlim[res].rlim_max;
61092+ else
61093+ rlim = task->signal->rlim[res].rlim_cur;
61094+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
61095+ return;
61096+
61097+ rcu_read_lock();
61098+ cred = __task_cred(task);
61099+
61100+ if (res == RLIMIT_NPROC &&
61101+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
61102+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
61103+ goto out_rcu_unlock;
61104+ else if (res == RLIMIT_MEMLOCK &&
61105+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
61106+ goto out_rcu_unlock;
61107+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
61108+ goto out_rcu_unlock;
61109+ rcu_read_unlock();
61110+
61111+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
61112+
61113+ return;
61114+out_rcu_unlock:
61115+ rcu_read_unlock();
61116+ return;
61117+}
61118diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
61119new file mode 100644
61120index 0000000..1d1b734
61121--- /dev/null
61122+++ b/grsecurity/gracl_segv.c
61123@@ -0,0 +1,284 @@
61124+#include <linux/kernel.h>
61125+#include <linux/mm.h>
61126+#include <asm/uaccess.h>
61127+#include <asm/errno.h>
61128+#include <asm/mman.h>
61129+#include <net/sock.h>
61130+#include <linux/file.h>
61131+#include <linux/fs.h>
61132+#include <linux/net.h>
61133+#include <linux/in.h>
61134+#include <linux/smp_lock.h>
61135+#include <linux/slab.h>
61136+#include <linux/types.h>
61137+#include <linux/sched.h>
61138+#include <linux/timer.h>
61139+#include <linux/gracl.h>
61140+#include <linux/grsecurity.h>
61141+#include <linux/grinternal.h>
61142+
61143+static struct crash_uid *uid_set;
61144+static unsigned short uid_used;
61145+static DEFINE_SPINLOCK(gr_uid_lock);
61146+extern rwlock_t gr_inode_lock;
61147+extern struct acl_subject_label *
61148+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
61149+ struct acl_role_label *role);
61150+extern int gr_fake_force_sig(int sig, struct task_struct *t);
61151+
61152+int
61153+gr_init_uidset(void)
61154+{
61155+ uid_set =
61156+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
61157+ uid_used = 0;
61158+
61159+ return uid_set ? 1 : 0;
61160+}
61161+
61162+void
61163+gr_free_uidset(void)
61164+{
61165+ if (uid_set)
61166+ kfree(uid_set);
61167+
61168+ return;
61169+}
61170+
61171+int
61172+gr_find_uid(const uid_t uid)
61173+{
61174+ struct crash_uid *tmp = uid_set;
61175+ uid_t buid;
61176+ int low = 0, high = uid_used - 1, mid;
61177+
61178+ while (high >= low) {
61179+ mid = (low + high) >> 1;
61180+ buid = tmp[mid].uid;
61181+ if (buid == uid)
61182+ return mid;
61183+ if (buid > uid)
61184+ high = mid - 1;
61185+ if (buid < uid)
61186+ low = mid + 1;
61187+ }
61188+
61189+ return -1;
61190+}
61191+
61192+static __inline__ void
61193+gr_insertsort(void)
61194+{
61195+ unsigned short i, j;
61196+ struct crash_uid index;
61197+
61198+ for (i = 1; i < uid_used; i++) {
61199+ index = uid_set[i];
61200+ j = i;
61201+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
61202+ uid_set[j] = uid_set[j - 1];
61203+ j--;
61204+ }
61205+ uid_set[j] = index;
61206+ }
61207+
61208+ return;
61209+}
61210+
61211+static __inline__ void
61212+gr_insert_uid(const uid_t uid, const unsigned long expires)
61213+{
61214+ int loc;
61215+
61216+ if (uid_used == GR_UIDTABLE_MAX)
61217+ return;
61218+
61219+ loc = gr_find_uid(uid);
61220+
61221+ if (loc >= 0) {
61222+ uid_set[loc].expires = expires;
61223+ return;
61224+ }
61225+
61226+ uid_set[uid_used].uid = uid;
61227+ uid_set[uid_used].expires = expires;
61228+ uid_used++;
61229+
61230+ gr_insertsort();
61231+
61232+ return;
61233+}
61234+
61235+void
61236+gr_remove_uid(const unsigned short loc)
61237+{
61238+ unsigned short i;
61239+
61240+ for (i = loc + 1; i < uid_used; i++)
61241+ uid_set[i - 1] = uid_set[i];
61242+
61243+ uid_used--;
61244+
61245+ return;
61246+}
61247+
61248+int
61249+gr_check_crash_uid(const uid_t uid)
61250+{
61251+ int loc;
61252+ int ret = 0;
61253+
61254+ if (unlikely(!gr_acl_is_enabled()))
61255+ return 0;
61256+
61257+ spin_lock(&gr_uid_lock);
61258+ loc = gr_find_uid(uid);
61259+
61260+ if (loc < 0)
61261+ goto out_unlock;
61262+
61263+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
61264+ gr_remove_uid(loc);
61265+ else
61266+ ret = 1;
61267+
61268+out_unlock:
61269+ spin_unlock(&gr_uid_lock);
61270+ return ret;
61271+}
61272+
61273+static __inline__ int
61274+proc_is_setxid(const struct cred *cred)
61275+{
61276+ if (cred->uid != cred->euid || cred->uid != cred->suid ||
61277+ cred->uid != cred->fsuid)
61278+ return 1;
61279+ if (cred->gid != cred->egid || cred->gid != cred->sgid ||
61280+ cred->gid != cred->fsgid)
61281+ return 1;
61282+
61283+ return 0;
61284+}
61285+
61286+void
61287+gr_handle_crash(struct task_struct *task, const int sig)
61288+{
61289+ struct acl_subject_label *curr;
61290+ struct task_struct *tsk, *tsk2;
61291+ const struct cred *cred;
61292+ const struct cred *cred2;
61293+
61294+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
61295+ return;
61296+
61297+ if (unlikely(!gr_acl_is_enabled()))
61298+ return;
61299+
61300+ curr = task->acl;
61301+
61302+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
61303+ return;
61304+
61305+ if (time_before_eq(curr->expires, get_seconds())) {
61306+ curr->expires = 0;
61307+ curr->crashes = 0;
61308+ }
61309+
61310+ curr->crashes++;
61311+
61312+ if (!curr->expires)
61313+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
61314+
61315+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
61316+ time_after(curr->expires, get_seconds())) {
61317+ rcu_read_lock();
61318+ cred = __task_cred(task);
61319+ if (cred->uid && proc_is_setxid(cred)) {
61320+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
61321+ spin_lock(&gr_uid_lock);
61322+ gr_insert_uid(cred->uid, curr->expires);
61323+ spin_unlock(&gr_uid_lock);
61324+ curr->expires = 0;
61325+ curr->crashes = 0;
61326+ read_lock(&tasklist_lock);
61327+ do_each_thread(tsk2, tsk) {
61328+ cred2 = __task_cred(tsk);
61329+ if (tsk != task && cred2->uid == cred->uid)
61330+ gr_fake_force_sig(SIGKILL, tsk);
61331+ } while_each_thread(tsk2, tsk);
61332+ read_unlock(&tasklist_lock);
61333+ } else {
61334+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
61335+ read_lock(&tasklist_lock);
61336+ read_lock(&grsec_exec_file_lock);
61337+ do_each_thread(tsk2, tsk) {
61338+ if (likely(tsk != task)) {
61339+ // if this thread has the same subject as the one that triggered
61340+ // RES_CRASH and it's the same binary, kill it
61341+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
61342+ gr_fake_force_sig(SIGKILL, tsk);
61343+ }
61344+ } while_each_thread(tsk2, tsk);
61345+ read_unlock(&grsec_exec_file_lock);
61346+ read_unlock(&tasklist_lock);
61347+ }
61348+ rcu_read_unlock();
61349+ }
61350+
61351+ return;
61352+}
61353+
61354+int
61355+gr_check_crash_exec(const struct file *filp)
61356+{
61357+ struct acl_subject_label *curr;
61358+
61359+ if (unlikely(!gr_acl_is_enabled()))
61360+ return 0;
61361+
61362+ read_lock(&gr_inode_lock);
61363+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
61364+ filp->f_path.dentry->d_inode->i_sb->s_dev,
61365+ current->role);
61366+ read_unlock(&gr_inode_lock);
61367+
61368+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
61369+ (!curr->crashes && !curr->expires))
61370+ return 0;
61371+
61372+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
61373+ time_after(curr->expires, get_seconds()))
61374+ return 1;
61375+ else if (time_before_eq(curr->expires, get_seconds())) {
61376+ curr->crashes = 0;
61377+ curr->expires = 0;
61378+ }
61379+
61380+ return 0;
61381+}
61382+
61383+void
61384+gr_handle_alertkill(struct task_struct *task)
61385+{
61386+ struct acl_subject_label *curracl;
61387+ __u32 curr_ip;
61388+ struct task_struct *p, *p2;
61389+
61390+ if (unlikely(!gr_acl_is_enabled()))
61391+ return;
61392+
61393+ curracl = task->acl;
61394+ curr_ip = task->signal->curr_ip;
61395+
61396+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
61397+ read_lock(&tasklist_lock);
61398+ do_each_thread(p2, p) {
61399+ if (p->signal->curr_ip == curr_ip)
61400+ gr_fake_force_sig(SIGKILL, p);
61401+ } while_each_thread(p2, p);
61402+ read_unlock(&tasklist_lock);
61403+ } else if (curracl->mode & GR_KILLPROC)
61404+ gr_fake_force_sig(SIGKILL, task);
61405+
61406+ return;
61407+}
61408diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
61409new file mode 100644
61410index 0000000..9d83a69
61411--- /dev/null
61412+++ b/grsecurity/gracl_shm.c
61413@@ -0,0 +1,40 @@
61414+#include <linux/kernel.h>
61415+#include <linux/mm.h>
61416+#include <linux/sched.h>
61417+#include <linux/file.h>
61418+#include <linux/ipc.h>
61419+#include <linux/gracl.h>
61420+#include <linux/grsecurity.h>
61421+#include <linux/grinternal.h>
61422+
61423+int
61424+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61425+ const time_t shm_createtime, const uid_t cuid, const int shmid)
61426+{
61427+ struct task_struct *task;
61428+
61429+ if (!gr_acl_is_enabled())
61430+ return 1;
61431+
61432+ rcu_read_lock();
61433+ read_lock(&tasklist_lock);
61434+
61435+ task = find_task_by_vpid(shm_cprid);
61436+
61437+ if (unlikely(!task))
61438+ task = find_task_by_vpid(shm_lapid);
61439+
61440+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
61441+ (task->pid == shm_lapid)) &&
61442+ (task->acl->mode & GR_PROTSHM) &&
61443+ (task->acl != current->acl))) {
61444+ read_unlock(&tasklist_lock);
61445+ rcu_read_unlock();
61446+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
61447+ return 0;
61448+ }
61449+ read_unlock(&tasklist_lock);
61450+ rcu_read_unlock();
61451+
61452+ return 1;
61453+}
61454diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
61455new file mode 100644
61456index 0000000..bc0be01
61457--- /dev/null
61458+++ b/grsecurity/grsec_chdir.c
61459@@ -0,0 +1,19 @@
61460+#include <linux/kernel.h>
61461+#include <linux/sched.h>
61462+#include <linux/fs.h>
61463+#include <linux/file.h>
61464+#include <linux/grsecurity.h>
61465+#include <linux/grinternal.h>
61466+
61467+void
61468+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
61469+{
61470+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61471+ if ((grsec_enable_chdir && grsec_enable_group &&
61472+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
61473+ !grsec_enable_group)) {
61474+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
61475+ }
61476+#endif
61477+ return;
61478+}
61479diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
61480new file mode 100644
61481index 0000000..197bdd5
61482--- /dev/null
61483+++ b/grsecurity/grsec_chroot.c
61484@@ -0,0 +1,386 @@
61485+#include <linux/kernel.h>
61486+#include <linux/module.h>
61487+#include <linux/sched.h>
61488+#include <linux/file.h>
61489+#include <linux/fs.h>
61490+#include <linux/mount.h>
61491+#include <linux/types.h>
61492+#include <linux/pid_namespace.h>
61493+#include <linux/grsecurity.h>
61494+#include <linux/grinternal.h>
61495+
61496+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
61497+{
61498+#ifdef CONFIG_GRKERNSEC
61499+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
61500+ path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
61501+ task->gr_is_chrooted = 1;
61502+ else
61503+ task->gr_is_chrooted = 0;
61504+
61505+ task->gr_chroot_dentry = path->dentry;
61506+#endif
61507+ return;
61508+}
61509+
61510+void gr_clear_chroot_entries(struct task_struct *task)
61511+{
61512+#ifdef CONFIG_GRKERNSEC
61513+ task->gr_is_chrooted = 0;
61514+ task->gr_chroot_dentry = NULL;
61515+#endif
61516+ return;
61517+}
61518+
61519+int
61520+gr_handle_chroot_unix(const pid_t pid)
61521+{
61522+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61523+ struct task_struct *p;
61524+
61525+ if (unlikely(!grsec_enable_chroot_unix))
61526+ return 1;
61527+
61528+ if (likely(!proc_is_chrooted(current)))
61529+ return 1;
61530+
61531+ rcu_read_lock();
61532+ read_lock(&tasklist_lock);
61533+
61534+ p = find_task_by_vpid_unrestricted(pid);
61535+ if (unlikely(p && !have_same_root(current, p))) {
61536+ read_unlock(&tasklist_lock);
61537+ rcu_read_unlock();
61538+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
61539+ return 0;
61540+ }
61541+ read_unlock(&tasklist_lock);
61542+ rcu_read_unlock();
61543+#endif
61544+ return 1;
61545+}
61546+
61547+int
61548+gr_handle_chroot_nice(void)
61549+{
61550+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61551+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
61552+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
61553+ return -EPERM;
61554+ }
61555+#endif
61556+ return 0;
61557+}
61558+
61559+int
61560+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
61561+{
61562+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61563+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
61564+ && proc_is_chrooted(current)) {
61565+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
61566+ return -EACCES;
61567+ }
61568+#endif
61569+ return 0;
61570+}
61571+
61572+int
61573+gr_handle_chroot_rawio(const struct inode *inode)
61574+{
61575+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61576+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
61577+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
61578+ return 1;
61579+#endif
61580+ return 0;
61581+}
61582+
61583+int
61584+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
61585+{
61586+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61587+ struct task_struct *p;
61588+ int ret = 0;
61589+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
61590+ return ret;
61591+
61592+ read_lock(&tasklist_lock);
61593+ do_each_pid_task(pid, type, p) {
61594+ if (!have_same_root(current, p)) {
61595+ ret = 1;
61596+ goto out;
61597+ }
61598+ } while_each_pid_task(pid, type, p);
61599+out:
61600+ read_unlock(&tasklist_lock);
61601+ return ret;
61602+#endif
61603+ return 0;
61604+}
61605+
61606+int
61607+gr_pid_is_chrooted(struct task_struct *p)
61608+{
61609+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61610+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
61611+ return 0;
61612+
61613+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
61614+ !have_same_root(current, p)) {
61615+ return 1;
61616+ }
61617+#endif
61618+ return 0;
61619+}
61620+
61621+EXPORT_SYMBOL(gr_pid_is_chrooted);
61622+
61623+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
61624+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
61625+{
61626+ struct dentry *dentry = (struct dentry *)u_dentry;
61627+ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
61628+ struct dentry *realroot;
61629+ struct vfsmount *realrootmnt;
61630+ struct dentry *currentroot;
61631+ struct vfsmount *currentmnt;
61632+ struct task_struct *reaper = &init_task;
61633+ int ret = 1;
61634+
61635+ read_lock(&reaper->fs->lock);
61636+ realrootmnt = mntget(reaper->fs->root.mnt);
61637+ realroot = dget(reaper->fs->root.dentry);
61638+ read_unlock(&reaper->fs->lock);
61639+
61640+ read_lock(&current->fs->lock);
61641+ currentmnt = mntget(current->fs->root.mnt);
61642+ currentroot = dget(current->fs->root.dentry);
61643+ read_unlock(&current->fs->lock);
61644+
61645+ spin_lock(&dcache_lock);
61646+ for (;;) {
61647+ if (unlikely((dentry == realroot && mnt == realrootmnt)
61648+ || (dentry == currentroot && mnt == currentmnt)))
61649+ break;
61650+ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
61651+ if (mnt->mnt_parent == mnt)
61652+ break;
61653+ dentry = mnt->mnt_mountpoint;
61654+ mnt = mnt->mnt_parent;
61655+ continue;
61656+ }
61657+ dentry = dentry->d_parent;
61658+ }
61659+ spin_unlock(&dcache_lock);
61660+
61661+ dput(currentroot);
61662+ mntput(currentmnt);
61663+
61664+ /* access is outside of chroot */
61665+ if (dentry == realroot && mnt == realrootmnt)
61666+ ret = 0;
61667+
61668+ dput(realroot);
61669+ mntput(realrootmnt);
61670+ return ret;
61671+}
61672+#endif
61673+
61674+int
61675+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
61676+{
61677+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61678+ if (!grsec_enable_chroot_fchdir)
61679+ return 1;
61680+
61681+ if (!proc_is_chrooted(current))
61682+ return 1;
61683+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
61684+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
61685+ return 0;
61686+ }
61687+#endif
61688+ return 1;
61689+}
61690+
61691+int
61692+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
61693+ const time_t shm_createtime)
61694+{
61695+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61696+ struct task_struct *p;
61697+ time_t starttime;
61698+
61699+ if (unlikely(!grsec_enable_chroot_shmat))
61700+ return 1;
61701+
61702+ if (likely(!proc_is_chrooted(current)))
61703+ return 1;
61704+
61705+ rcu_read_lock();
61706+ read_lock(&tasklist_lock);
61707+
61708+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
61709+ starttime = p->start_time.tv_sec;
61710+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
61711+ if (have_same_root(current, p)) {
61712+ goto allow;
61713+ } else {
61714+ read_unlock(&tasklist_lock);
61715+ rcu_read_unlock();
61716+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
61717+ return 0;
61718+ }
61719+ }
61720+ /* creator exited, pid reuse, fall through to next check */
61721+ }
61722+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
61723+ if (unlikely(!have_same_root(current, p))) {
61724+ read_unlock(&tasklist_lock);
61725+ rcu_read_unlock();
61726+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
61727+ return 0;
61728+ }
61729+ }
61730+
61731+allow:
61732+ read_unlock(&tasklist_lock);
61733+ rcu_read_unlock();
61734+#endif
61735+ return 1;
61736+}
61737+
61738+void
61739+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
61740+{
61741+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61742+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
61743+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
61744+#endif
61745+ return;
61746+}
61747+
61748+int
61749+gr_handle_chroot_mknod(const struct dentry *dentry,
61750+ const struct vfsmount *mnt, const int mode)
61751+{
61752+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61753+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
61754+ proc_is_chrooted(current)) {
61755+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
61756+ return -EPERM;
61757+ }
61758+#endif
61759+ return 0;
61760+}
61761+
61762+int
61763+gr_handle_chroot_mount(const struct dentry *dentry,
61764+ const struct vfsmount *mnt, const char *dev_name)
61765+{
61766+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61767+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
61768+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none" , dentry, mnt);
61769+ return -EPERM;
61770+ }
61771+#endif
61772+ return 0;
61773+}
61774+
61775+int
61776+gr_handle_chroot_pivot(void)
61777+{
61778+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61779+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
61780+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
61781+ return -EPERM;
61782+ }
61783+#endif
61784+ return 0;
61785+}
61786+
61787+int
61788+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
61789+{
61790+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61791+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
61792+ !gr_is_outside_chroot(dentry, mnt)) {
61793+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
61794+ return -EPERM;
61795+ }
61796+#endif
61797+ return 0;
61798+}
61799+
61800+extern const char *captab_log[];
61801+extern int captab_log_entries;
61802+
61803+int
61804+gr_chroot_is_capable(const int cap)
61805+{
61806+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61807+ if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
61808+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
61809+ if (cap_raised(chroot_caps, cap)) {
61810+ const struct cred *creds = current_cred();
61811+ if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
61812+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
61813+ }
61814+ return 0;
61815+ }
61816+ }
61817+#endif
61818+ return 1;
61819+}
61820+
61821+int
61822+gr_chroot_is_capable_nolog(const int cap)
61823+{
61824+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61825+ if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
61826+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
61827+ if (cap_raised(chroot_caps, cap)) {
61828+ return 0;
61829+ }
61830+ }
61831+#endif
61832+ return 1;
61833+}
61834+
61835+int
61836+gr_handle_chroot_sysctl(const int op)
61837+{
61838+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61839+ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
61840+ && (op & MAY_WRITE))
61841+ return -EACCES;
61842+#endif
61843+ return 0;
61844+}
61845+
61846+void
61847+gr_handle_chroot_chdir(struct path *path)
61848+{
61849+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61850+ if (grsec_enable_chroot_chdir)
61851+ set_fs_pwd(current->fs, path);
61852+#endif
61853+ return;
61854+}
61855+
61856+int
61857+gr_handle_chroot_chmod(const struct dentry *dentry,
61858+ const struct vfsmount *mnt, const int mode)
61859+{
61860+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61861+ /* allow chmod +s on directories, but not on files */
61862+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
61863+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
61864+ proc_is_chrooted(current)) {
61865+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
61866+ return -EPERM;
61867+ }
61868+#endif
61869+ return 0;
61870+}
61871diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
61872new file mode 100644
61873index 0000000..b81db5b
61874--- /dev/null
61875+++ b/grsecurity/grsec_disabled.c
61876@@ -0,0 +1,439 @@
61877+#include <linux/kernel.h>
61878+#include <linux/module.h>
61879+#include <linux/sched.h>
61880+#include <linux/file.h>
61881+#include <linux/fs.h>
61882+#include <linux/kdev_t.h>
61883+#include <linux/net.h>
61884+#include <linux/in.h>
61885+#include <linux/ip.h>
61886+#include <linux/skbuff.h>
61887+#include <linux/sysctl.h>
61888+
61889+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61890+void
61891+pax_set_initial_flags(struct linux_binprm *bprm)
61892+{
61893+ return;
61894+}
61895+#endif
61896+
61897+#ifdef CONFIG_SYSCTL
61898+__u32
61899+gr_handle_sysctl(const struct ctl_table * table, const int op)
61900+{
61901+ return 0;
61902+}
61903+#endif
61904+
61905+#ifdef CONFIG_TASKSTATS
61906+int gr_is_taskstats_denied(int pid)
61907+{
61908+ return 0;
61909+}
61910+#endif
61911+
61912+int
61913+gr_acl_is_enabled(void)
61914+{
61915+ return 0;
61916+}
61917+
61918+void
61919+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61920+{
61921+ return;
61922+}
61923+
61924+int
61925+gr_handle_rawio(const struct inode *inode)
61926+{
61927+ return 0;
61928+}
61929+
61930+void
61931+gr_acl_handle_psacct(struct task_struct *task, const long code)
61932+{
61933+ return;
61934+}
61935+
61936+int
61937+gr_handle_ptrace(struct task_struct *task, const long request)
61938+{
61939+ return 0;
61940+}
61941+
61942+int
61943+gr_handle_proc_ptrace(struct task_struct *task)
61944+{
61945+ return 0;
61946+}
61947+
61948+void
61949+gr_learn_resource(const struct task_struct *task,
61950+ const int res, const unsigned long wanted, const int gt)
61951+{
61952+ return;
61953+}
61954+
61955+int
61956+gr_set_acls(const int type)
61957+{
61958+ return 0;
61959+}
61960+
61961+int
61962+gr_check_hidden_task(const struct task_struct *tsk)
61963+{
61964+ return 0;
61965+}
61966+
61967+int
61968+gr_check_protected_task(const struct task_struct *task)
61969+{
61970+ return 0;
61971+}
61972+
61973+int
61974+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
61975+{
61976+ return 0;
61977+}
61978+
61979+void
61980+gr_copy_label(struct task_struct *tsk)
61981+{
61982+ return;
61983+}
61984+
61985+void
61986+gr_set_pax_flags(struct task_struct *task)
61987+{
61988+ return;
61989+}
61990+
61991+int
61992+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
61993+ const int unsafe_share)
61994+{
61995+ return 0;
61996+}
61997+
61998+void
61999+gr_handle_delete(const ino_t ino, const dev_t dev)
62000+{
62001+ return;
62002+}
62003+
62004+void
62005+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
62006+{
62007+ return;
62008+}
62009+
62010+void
62011+gr_handle_crash(struct task_struct *task, const int sig)
62012+{
62013+ return;
62014+}
62015+
62016+int
62017+gr_check_crash_exec(const struct file *filp)
62018+{
62019+ return 0;
62020+}
62021+
62022+int
62023+gr_check_crash_uid(const uid_t uid)
62024+{
62025+ return 0;
62026+}
62027+
62028+void
62029+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62030+ struct dentry *old_dentry,
62031+ struct dentry *new_dentry,
62032+ struct vfsmount *mnt, const __u8 replace)
62033+{
62034+ return;
62035+}
62036+
62037+int
62038+gr_search_socket(const int family, const int type, const int protocol)
62039+{
62040+ return 1;
62041+}
62042+
62043+int
62044+gr_search_connectbind(const int mode, const struct socket *sock,
62045+ const struct sockaddr_in *addr)
62046+{
62047+ return 0;
62048+}
62049+
62050+void
62051+gr_handle_alertkill(struct task_struct *task)
62052+{
62053+ return;
62054+}
62055+
62056+__u32
62057+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
62058+{
62059+ return 1;
62060+}
62061+
62062+__u32
62063+gr_acl_handle_hidden_file(const struct dentry * dentry,
62064+ const struct vfsmount * mnt)
62065+{
62066+ return 1;
62067+}
62068+
62069+__u32
62070+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62071+ int acc_mode)
62072+{
62073+ return 1;
62074+}
62075+
62076+__u32
62077+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62078+{
62079+ return 1;
62080+}
62081+
62082+__u32
62083+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
62084+{
62085+ return 1;
62086+}
62087+
62088+int
62089+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
62090+ unsigned int *vm_flags)
62091+{
62092+ return 1;
62093+}
62094+
62095+__u32
62096+gr_acl_handle_truncate(const struct dentry * dentry,
62097+ const struct vfsmount * mnt)
62098+{
62099+ return 1;
62100+}
62101+
62102+__u32
62103+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
62104+{
62105+ return 1;
62106+}
62107+
62108+__u32
62109+gr_acl_handle_access(const struct dentry * dentry,
62110+ const struct vfsmount * mnt, const int fmode)
62111+{
62112+ return 1;
62113+}
62114+
62115+__u32
62116+gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
62117+ mode_t mode)
62118+{
62119+ return 1;
62120+}
62121+
62122+__u32
62123+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
62124+ mode_t mode)
62125+{
62126+ return 1;
62127+}
62128+
62129+__u32
62130+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
62131+{
62132+ return 1;
62133+}
62134+
62135+__u32
62136+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
62137+{
62138+ return 1;
62139+}
62140+
62141+void
62142+grsecurity_init(void)
62143+{
62144+ return;
62145+}
62146+
62147+__u32
62148+gr_acl_handle_mknod(const struct dentry * new_dentry,
62149+ const struct dentry * parent_dentry,
62150+ const struct vfsmount * parent_mnt,
62151+ const int mode)
62152+{
62153+ return 1;
62154+}
62155+
62156+__u32
62157+gr_acl_handle_mkdir(const struct dentry * new_dentry,
62158+ const struct dentry * parent_dentry,
62159+ const struct vfsmount * parent_mnt)
62160+{
62161+ return 1;
62162+}
62163+
62164+__u32
62165+gr_acl_handle_symlink(const struct dentry * new_dentry,
62166+ const struct dentry * parent_dentry,
62167+ const struct vfsmount * parent_mnt, const char *from)
62168+{
62169+ return 1;
62170+}
62171+
62172+__u32
62173+gr_acl_handle_link(const struct dentry * new_dentry,
62174+ const struct dentry * parent_dentry,
62175+ const struct vfsmount * parent_mnt,
62176+ const struct dentry * old_dentry,
62177+ const struct vfsmount * old_mnt, const char *to)
62178+{
62179+ return 1;
62180+}
62181+
62182+int
62183+gr_acl_handle_rename(const struct dentry *new_dentry,
62184+ const struct dentry *parent_dentry,
62185+ const struct vfsmount *parent_mnt,
62186+ const struct dentry *old_dentry,
62187+ const struct inode *old_parent_inode,
62188+ const struct vfsmount *old_mnt, const char *newname)
62189+{
62190+ return 0;
62191+}
62192+
62193+int
62194+gr_acl_handle_filldir(const struct file *file, const char *name,
62195+ const int namelen, const ino_t ino)
62196+{
62197+ return 1;
62198+}
62199+
62200+int
62201+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62202+ const time_t shm_createtime, const uid_t cuid, const int shmid)
62203+{
62204+ return 1;
62205+}
62206+
62207+int
62208+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
62209+{
62210+ return 0;
62211+}
62212+
62213+int
62214+gr_search_accept(const struct socket *sock)
62215+{
62216+ return 0;
62217+}
62218+
62219+int
62220+gr_search_listen(const struct socket *sock)
62221+{
62222+ return 0;
62223+}
62224+
62225+int
62226+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
62227+{
62228+ return 0;
62229+}
62230+
62231+__u32
62232+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
62233+{
62234+ return 1;
62235+}
62236+
62237+__u32
62238+gr_acl_handle_creat(const struct dentry * dentry,
62239+ const struct dentry * p_dentry,
62240+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62241+ const int imode)
62242+{
62243+ return 1;
62244+}
62245+
62246+void
62247+gr_acl_handle_exit(void)
62248+{
62249+ return;
62250+}
62251+
62252+int
62253+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62254+{
62255+ return 1;
62256+}
62257+
62258+void
62259+gr_set_role_label(const uid_t uid, const gid_t gid)
62260+{
62261+ return;
62262+}
62263+
62264+int
62265+gr_acl_handle_procpidmem(const struct task_struct *task)
62266+{
62267+ return 0;
62268+}
62269+
62270+int
62271+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
62272+{
62273+ return 0;
62274+}
62275+
62276+int
62277+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
62278+{
62279+ return 0;
62280+}
62281+
62282+void
62283+gr_set_kernel_label(struct task_struct *task)
62284+{
62285+ return;
62286+}
62287+
62288+int
62289+gr_check_user_change(int real, int effective, int fs)
62290+{
62291+ return 0;
62292+}
62293+
62294+int
62295+gr_check_group_change(int real, int effective, int fs)
62296+{
62297+ return 0;
62298+}
62299+
62300+int gr_acl_enable_at_secure(void)
62301+{
62302+ return 0;
62303+}
62304+
62305+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62306+{
62307+ return dentry->d_inode->i_sb->s_dev;
62308+}
62309+
62310+EXPORT_SYMBOL(gr_learn_resource);
62311+EXPORT_SYMBOL(gr_set_kernel_label);
62312+#ifdef CONFIG_SECURITY
62313+EXPORT_SYMBOL(gr_check_user_change);
62314+EXPORT_SYMBOL(gr_check_group_change);
62315+#endif
62316diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
62317new file mode 100644
62318index 0000000..a96e155
62319--- /dev/null
62320+++ b/grsecurity/grsec_exec.c
62321@@ -0,0 +1,204 @@
62322+#include <linux/kernel.h>
62323+#include <linux/sched.h>
62324+#include <linux/file.h>
62325+#include <linux/binfmts.h>
62326+#include <linux/smp_lock.h>
62327+#include <linux/fs.h>
62328+#include <linux/types.h>
62329+#include <linux/grdefs.h>
62330+#include <linux/grinternal.h>
62331+#include <linux/capability.h>
62332+#include <linux/compat.h>
62333+#include <linux/module.h>
62334+
62335+#include <asm/uaccess.h>
62336+
62337+#ifdef CONFIG_GRKERNSEC_EXECLOG
62338+static char gr_exec_arg_buf[132];
62339+static DEFINE_MUTEX(gr_exec_arg_mutex);
62340+#endif
62341+
62342+void
62343+gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv)
62344+{
62345+#ifdef CONFIG_GRKERNSEC_EXECLOG
62346+ char *grarg = gr_exec_arg_buf;
62347+ unsigned int i, x, execlen = 0;
62348+ char c;
62349+
62350+ if (!((grsec_enable_execlog && grsec_enable_group &&
62351+ in_group_p(grsec_audit_gid))
62352+ || (grsec_enable_execlog && !grsec_enable_group)))
62353+ return;
62354+
62355+ mutex_lock(&gr_exec_arg_mutex);
62356+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
62357+
62358+ if (unlikely(argv == NULL))
62359+ goto log;
62360+
62361+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
62362+ const char __user *p;
62363+ unsigned int len;
62364+
62365+ if (copy_from_user(&p, argv + i, sizeof(p)))
62366+ goto log;
62367+ if (!p)
62368+ goto log;
62369+ len = strnlen_user(p, 128 - execlen);
62370+ if (len > 128 - execlen)
62371+ len = 128 - execlen;
62372+ else if (len > 0)
62373+ len--;
62374+ if (copy_from_user(grarg + execlen, p, len))
62375+ goto log;
62376+
62377+ /* rewrite unprintable characters */
62378+ for (x = 0; x < len; x++) {
62379+ c = *(grarg + execlen + x);
62380+ if (c < 32 || c > 126)
62381+ *(grarg + execlen + x) = ' ';
62382+ }
62383+
62384+ execlen += len;
62385+ *(grarg + execlen) = ' ';
62386+ *(grarg + execlen + 1) = '\0';
62387+ execlen++;
62388+ }
62389+
62390+ log:
62391+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
62392+ bprm->file->f_path.mnt, grarg);
62393+ mutex_unlock(&gr_exec_arg_mutex);
62394+#endif
62395+ return;
62396+}
62397+
62398+#ifdef CONFIG_COMPAT
62399+void
62400+gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv)
62401+{
62402+#ifdef CONFIG_GRKERNSEC_EXECLOG
62403+ char *grarg = gr_exec_arg_buf;
62404+ unsigned int i, x, execlen = 0;
62405+ char c;
62406+
62407+ if (!((grsec_enable_execlog && grsec_enable_group &&
62408+ in_group_p(grsec_audit_gid))
62409+ || (grsec_enable_execlog && !grsec_enable_group)))
62410+ return;
62411+
62412+ mutex_lock(&gr_exec_arg_mutex);
62413+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
62414+
62415+ if (unlikely(argv == NULL))
62416+ goto log;
62417+
62418+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
62419+ compat_uptr_t p;
62420+ unsigned int len;
62421+
62422+ if (get_user(p, argv + i))
62423+ goto log;
62424+ len = strnlen_user(compat_ptr(p), 128 - execlen);
62425+ if (len > 128 - execlen)
62426+ len = 128 - execlen;
62427+ else if (len > 0)
62428+ len--;
62429+ else
62430+ goto log;
62431+ if (copy_from_user(grarg + execlen, compat_ptr(p), len))
62432+ goto log;
62433+
62434+ /* rewrite unprintable characters */
62435+ for (x = 0; x < len; x++) {
62436+ c = *(grarg + execlen + x);
62437+ if (c < 32 || c > 126)
62438+ *(grarg + execlen + x) = ' ';
62439+ }
62440+
62441+ execlen += len;
62442+ *(grarg + execlen) = ' ';
62443+ *(grarg + execlen + 1) = '\0';
62444+ execlen++;
62445+ }
62446+
62447+ log:
62448+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
62449+ bprm->file->f_path.mnt, grarg);
62450+ mutex_unlock(&gr_exec_arg_mutex);
62451+#endif
62452+ return;
62453+}
62454+#endif
62455+
62456+#ifdef CONFIG_GRKERNSEC
62457+extern int gr_acl_is_capable(const int cap);
62458+extern int gr_acl_is_capable_nolog(const int cap);
62459+extern int gr_chroot_is_capable(const int cap);
62460+extern int gr_chroot_is_capable_nolog(const int cap);
62461+#endif
62462+
62463+const char *captab_log[] = {
62464+ "CAP_CHOWN",
62465+ "CAP_DAC_OVERRIDE",
62466+ "CAP_DAC_READ_SEARCH",
62467+ "CAP_FOWNER",
62468+ "CAP_FSETID",
62469+ "CAP_KILL",
62470+ "CAP_SETGID",
62471+ "CAP_SETUID",
62472+ "CAP_SETPCAP",
62473+ "CAP_LINUX_IMMUTABLE",
62474+ "CAP_NET_BIND_SERVICE",
62475+ "CAP_NET_BROADCAST",
62476+ "CAP_NET_ADMIN",
62477+ "CAP_NET_RAW",
62478+ "CAP_IPC_LOCK",
62479+ "CAP_IPC_OWNER",
62480+ "CAP_SYS_MODULE",
62481+ "CAP_SYS_RAWIO",
62482+ "CAP_SYS_CHROOT",
62483+ "CAP_SYS_PTRACE",
62484+ "CAP_SYS_PACCT",
62485+ "CAP_SYS_ADMIN",
62486+ "CAP_SYS_BOOT",
62487+ "CAP_SYS_NICE",
62488+ "CAP_SYS_RESOURCE",
62489+ "CAP_SYS_TIME",
62490+ "CAP_SYS_TTY_CONFIG",
62491+ "CAP_MKNOD",
62492+ "CAP_LEASE",
62493+ "CAP_AUDIT_WRITE",
62494+ "CAP_AUDIT_CONTROL",
62495+ "CAP_SETFCAP",
62496+ "CAP_MAC_OVERRIDE",
62497+ "CAP_MAC_ADMIN"
62498+};
62499+
62500+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
62501+
62502+int gr_is_capable(const int cap)
62503+{
62504+#ifdef CONFIG_GRKERNSEC
62505+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
62506+ return 1;
62507+ return 0;
62508+#else
62509+ return 1;
62510+#endif
62511+}
62512+
62513+int gr_is_capable_nolog(const int cap)
62514+{
62515+#ifdef CONFIG_GRKERNSEC
62516+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
62517+ return 1;
62518+ return 0;
62519+#else
62520+ return 1;
62521+#endif
62522+}
62523+
62524+EXPORT_SYMBOL(gr_is_capable);
62525+EXPORT_SYMBOL(gr_is_capable_nolog);
62526diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
62527new file mode 100644
62528index 0000000..d3ee748
62529--- /dev/null
62530+++ b/grsecurity/grsec_fifo.c
62531@@ -0,0 +1,24 @@
62532+#include <linux/kernel.h>
62533+#include <linux/sched.h>
62534+#include <linux/fs.h>
62535+#include <linux/file.h>
62536+#include <linux/grinternal.h>
62537+
62538+int
62539+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
62540+ const struct dentry *dir, const int flag, const int acc_mode)
62541+{
62542+#ifdef CONFIG_GRKERNSEC_FIFO
62543+ const struct cred *cred = current_cred();
62544+
62545+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
62546+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
62547+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
62548+ (cred->fsuid != dentry->d_inode->i_uid)) {
62549+ if (!inode_permission(dentry->d_inode, acc_mode))
62550+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
62551+ return -EACCES;
62552+ }
62553+#endif
62554+ return 0;
62555+}
62556diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
62557new file mode 100644
62558index 0000000..8ca18bf
62559--- /dev/null
62560+++ b/grsecurity/grsec_fork.c
62561@@ -0,0 +1,23 @@
62562+#include <linux/kernel.h>
62563+#include <linux/sched.h>
62564+#include <linux/grsecurity.h>
62565+#include <linux/grinternal.h>
62566+#include <linux/errno.h>
62567+
62568+void
62569+gr_log_forkfail(const int retval)
62570+{
62571+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62572+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
62573+ switch (retval) {
62574+ case -EAGAIN:
62575+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
62576+ break;
62577+ case -ENOMEM:
62578+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
62579+ break;
62580+ }
62581+ }
62582+#endif
62583+ return;
62584+}
62585diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
62586new file mode 100644
62587index 0000000..f813c26
62588--- /dev/null
62589+++ b/grsecurity/grsec_init.c
62590@@ -0,0 +1,270 @@
62591+#include <linux/kernel.h>
62592+#include <linux/sched.h>
62593+#include <linux/mm.h>
62594+#include <linux/smp_lock.h>
62595+#include <linux/gracl.h>
62596+#include <linux/slab.h>
62597+#include <linux/vmalloc.h>
62598+#include <linux/percpu.h>
62599+#include <linux/module.h>
62600+
62601+int grsec_enable_brute;
62602+int grsec_enable_link;
62603+int grsec_enable_dmesg;
62604+int grsec_enable_harden_ptrace;
62605+int grsec_enable_fifo;
62606+int grsec_enable_execlog;
62607+int grsec_enable_signal;
62608+int grsec_enable_forkfail;
62609+int grsec_enable_audit_ptrace;
62610+int grsec_enable_time;
62611+int grsec_enable_audit_textrel;
62612+int grsec_enable_group;
62613+int grsec_audit_gid;
62614+int grsec_enable_chdir;
62615+int grsec_enable_mount;
62616+int grsec_enable_rofs;
62617+int grsec_enable_chroot_findtask;
62618+int grsec_enable_chroot_mount;
62619+int grsec_enable_chroot_shmat;
62620+int grsec_enable_chroot_fchdir;
62621+int grsec_enable_chroot_double;
62622+int grsec_enable_chroot_pivot;
62623+int grsec_enable_chroot_chdir;
62624+int grsec_enable_chroot_chmod;
62625+int grsec_enable_chroot_mknod;
62626+int grsec_enable_chroot_nice;
62627+int grsec_enable_chroot_execlog;
62628+int grsec_enable_chroot_caps;
62629+int grsec_enable_chroot_sysctl;
62630+int grsec_enable_chroot_unix;
62631+int grsec_enable_tpe;
62632+int grsec_tpe_gid;
62633+int grsec_enable_blackhole;
62634+#ifdef CONFIG_IPV6_MODULE
62635+EXPORT_SYMBOL(grsec_enable_blackhole);
62636+#endif
62637+int grsec_lastack_retries;
62638+int grsec_enable_tpe_all;
62639+int grsec_enable_tpe_invert;
62640+int grsec_enable_socket_all;
62641+int grsec_socket_all_gid;
62642+int grsec_enable_socket_client;
62643+int grsec_socket_client_gid;
62644+int grsec_enable_socket_server;
62645+int grsec_socket_server_gid;
62646+int grsec_resource_logging;
62647+int grsec_disable_privio;
62648+int grsec_enable_log_rwxmaps;
62649+int grsec_lock;
62650+
62651+DEFINE_SPINLOCK(grsec_alert_lock);
62652+unsigned long grsec_alert_wtime = 0;
62653+unsigned long grsec_alert_fyet = 0;
62654+
62655+DEFINE_SPINLOCK(grsec_audit_lock);
62656+
62657+DEFINE_RWLOCK(grsec_exec_file_lock);
62658+
62659+char *gr_shared_page[4];
62660+
62661+char *gr_alert_log_fmt;
62662+char *gr_audit_log_fmt;
62663+char *gr_alert_log_buf;
62664+char *gr_audit_log_buf;
62665+
62666+extern struct gr_arg *gr_usermode;
62667+extern unsigned char *gr_system_salt;
62668+extern unsigned char *gr_system_sum;
62669+
62670+void __init
62671+grsecurity_init(void)
62672+{
62673+ int j;
62674+ /* create the per-cpu shared pages */
62675+
62676+#ifdef CONFIG_X86
62677+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
62678+#endif
62679+
62680+ for (j = 0; j < 4; j++) {
62681+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
62682+ if (gr_shared_page[j] == NULL) {
62683+ panic("Unable to allocate grsecurity shared page");
62684+ return;
62685+ }
62686+ }
62687+
62688+ /* allocate log buffers */
62689+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
62690+ if (!gr_alert_log_fmt) {
62691+ panic("Unable to allocate grsecurity alert log format buffer");
62692+ return;
62693+ }
62694+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
62695+ if (!gr_audit_log_fmt) {
62696+ panic("Unable to allocate grsecurity audit log format buffer");
62697+ return;
62698+ }
62699+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
62700+ if (!gr_alert_log_buf) {
62701+ panic("Unable to allocate grsecurity alert log buffer");
62702+ return;
62703+ }
62704+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
62705+ if (!gr_audit_log_buf) {
62706+ panic("Unable to allocate grsecurity audit log buffer");
62707+ return;
62708+ }
62709+
62710+ /* allocate memory for authentication structure */
62711+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
62712+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
62713+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
62714+
62715+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
62716+ panic("Unable to allocate grsecurity authentication structure");
62717+ return;
62718+ }
62719+
62720+
62721+#ifdef CONFIG_GRKERNSEC_IO
62722+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
62723+ grsec_disable_privio = 1;
62724+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
62725+ grsec_disable_privio = 1;
62726+#else
62727+ grsec_disable_privio = 0;
62728+#endif
62729+#endif
62730+
62731+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62732+ /* for backward compatibility, tpe_invert always defaults to on if
62733+ enabled in the kernel
62734+ */
62735+ grsec_enable_tpe_invert = 1;
62736+#endif
62737+
62738+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
62739+#ifndef CONFIG_GRKERNSEC_SYSCTL
62740+ grsec_lock = 1;
62741+#endif
62742+
62743+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62744+ grsec_enable_audit_textrel = 1;
62745+#endif
62746+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62747+ grsec_enable_log_rwxmaps = 1;
62748+#endif
62749+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62750+ grsec_enable_group = 1;
62751+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
62752+#endif
62753+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62754+ grsec_enable_chdir = 1;
62755+#endif
62756+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62757+ grsec_enable_harden_ptrace = 1;
62758+#endif
62759+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62760+ grsec_enable_mount = 1;
62761+#endif
62762+#ifdef CONFIG_GRKERNSEC_LINK
62763+ grsec_enable_link = 1;
62764+#endif
62765+#ifdef CONFIG_GRKERNSEC_BRUTE
62766+ grsec_enable_brute = 1;
62767+#endif
62768+#ifdef CONFIG_GRKERNSEC_DMESG
62769+ grsec_enable_dmesg = 1;
62770+#endif
62771+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62772+ grsec_enable_blackhole = 1;
62773+ grsec_lastack_retries = 4;
62774+#endif
62775+#ifdef CONFIG_GRKERNSEC_FIFO
62776+ grsec_enable_fifo = 1;
62777+#endif
62778+#ifdef CONFIG_GRKERNSEC_EXECLOG
62779+ grsec_enable_execlog = 1;
62780+#endif
62781+#ifdef CONFIG_GRKERNSEC_SIGNAL
62782+ grsec_enable_signal = 1;
62783+#endif
62784+#ifdef CONFIG_GRKERNSEC_FORKFAIL
62785+ grsec_enable_forkfail = 1;
62786+#endif
62787+#ifdef CONFIG_GRKERNSEC_TIME
62788+ grsec_enable_time = 1;
62789+#endif
62790+#ifdef CONFIG_GRKERNSEC_RESLOG
62791+ grsec_resource_logging = 1;
62792+#endif
62793+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62794+ grsec_enable_chroot_findtask = 1;
62795+#endif
62796+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62797+ grsec_enable_chroot_unix = 1;
62798+#endif
62799+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62800+ grsec_enable_chroot_mount = 1;
62801+#endif
62802+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62803+ grsec_enable_chroot_fchdir = 1;
62804+#endif
62805+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62806+ grsec_enable_chroot_shmat = 1;
62807+#endif
62808+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62809+ grsec_enable_audit_ptrace = 1;
62810+#endif
62811+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62812+ grsec_enable_chroot_double = 1;
62813+#endif
62814+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62815+ grsec_enable_chroot_pivot = 1;
62816+#endif
62817+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62818+ grsec_enable_chroot_chdir = 1;
62819+#endif
62820+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62821+ grsec_enable_chroot_chmod = 1;
62822+#endif
62823+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62824+ grsec_enable_chroot_mknod = 1;
62825+#endif
62826+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62827+ grsec_enable_chroot_nice = 1;
62828+#endif
62829+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62830+ grsec_enable_chroot_execlog = 1;
62831+#endif
62832+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62833+ grsec_enable_chroot_caps = 1;
62834+#endif
62835+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62836+ grsec_enable_chroot_sysctl = 1;
62837+#endif
62838+#ifdef CONFIG_GRKERNSEC_TPE
62839+ grsec_enable_tpe = 1;
62840+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
62841+#ifdef CONFIG_GRKERNSEC_TPE_ALL
62842+ grsec_enable_tpe_all = 1;
62843+#endif
62844+#endif
62845+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62846+ grsec_enable_socket_all = 1;
62847+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
62848+#endif
62849+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62850+ grsec_enable_socket_client = 1;
62851+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
62852+#endif
62853+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62854+ grsec_enable_socket_server = 1;
62855+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
62856+#endif
62857+#endif
62858+
62859+ return;
62860+}
62861diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
62862new file mode 100644
62863index 0000000..3efe141
62864--- /dev/null
62865+++ b/grsecurity/grsec_link.c
62866@@ -0,0 +1,43 @@
62867+#include <linux/kernel.h>
62868+#include <linux/sched.h>
62869+#include <linux/fs.h>
62870+#include <linux/file.h>
62871+#include <linux/grinternal.h>
62872+
62873+int
62874+gr_handle_follow_link(const struct inode *parent,
62875+ const struct inode *inode,
62876+ const struct dentry *dentry, const struct vfsmount *mnt)
62877+{
62878+#ifdef CONFIG_GRKERNSEC_LINK
62879+ const struct cred *cred = current_cred();
62880+
62881+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
62882+ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
62883+ (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
62884+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
62885+ return -EACCES;
62886+ }
62887+#endif
62888+ return 0;
62889+}
62890+
62891+int
62892+gr_handle_hardlink(const struct dentry *dentry,
62893+ const struct vfsmount *mnt,
62894+ struct inode *inode, const int mode, const char *to)
62895+{
62896+#ifdef CONFIG_GRKERNSEC_LINK
62897+ const struct cred *cred = current_cred();
62898+
62899+ if (grsec_enable_link && cred->fsuid != inode->i_uid &&
62900+ (!S_ISREG(mode) || (mode & S_ISUID) ||
62901+ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
62902+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
62903+ !capable(CAP_FOWNER) && cred->uid) {
62904+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
62905+ return -EPERM;
62906+ }
62907+#endif
62908+ return 0;
62909+}
62910diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
62911new file mode 100644
62912index 0000000..a45d2e9
62913--- /dev/null
62914+++ b/grsecurity/grsec_log.c
62915@@ -0,0 +1,322 @@
62916+#include <linux/kernel.h>
62917+#include <linux/sched.h>
62918+#include <linux/file.h>
62919+#include <linux/tty.h>
62920+#include <linux/fs.h>
62921+#include <linux/grinternal.h>
62922+
62923+#ifdef CONFIG_TREE_PREEMPT_RCU
62924+#define DISABLE_PREEMPT() preempt_disable()
62925+#define ENABLE_PREEMPT() preempt_enable()
62926+#else
62927+#define DISABLE_PREEMPT()
62928+#define ENABLE_PREEMPT()
62929+#endif
62930+
62931+#define BEGIN_LOCKS(x) \
62932+ DISABLE_PREEMPT(); \
62933+ rcu_read_lock(); \
62934+ read_lock(&tasklist_lock); \
62935+ read_lock(&grsec_exec_file_lock); \
62936+ if (x != GR_DO_AUDIT) \
62937+ spin_lock(&grsec_alert_lock); \
62938+ else \
62939+ spin_lock(&grsec_audit_lock)
62940+
62941+#define END_LOCKS(x) \
62942+ if (x != GR_DO_AUDIT) \
62943+ spin_unlock(&grsec_alert_lock); \
62944+ else \
62945+ spin_unlock(&grsec_audit_lock); \
62946+ read_unlock(&grsec_exec_file_lock); \
62947+ read_unlock(&tasklist_lock); \
62948+ rcu_read_unlock(); \
62949+ ENABLE_PREEMPT(); \
62950+ if (x == GR_DONT_AUDIT) \
62951+ gr_handle_alertkill(current)
62952+
62953+enum {
62954+ FLOODING,
62955+ NO_FLOODING
62956+};
62957+
62958+extern char *gr_alert_log_fmt;
62959+extern char *gr_audit_log_fmt;
62960+extern char *gr_alert_log_buf;
62961+extern char *gr_audit_log_buf;
62962+
62963+static int gr_log_start(int audit)
62964+{
62965+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
62966+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
62967+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
62968+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
62969+ unsigned long curr_secs = get_seconds();
62970+
62971+ if (audit == GR_DO_AUDIT)
62972+ goto set_fmt;
62973+
62974+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
62975+ grsec_alert_wtime = curr_secs;
62976+ grsec_alert_fyet = 0;
62977+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
62978+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
62979+ grsec_alert_fyet++;
62980+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
62981+ grsec_alert_wtime = curr_secs;
62982+ grsec_alert_fyet++;
62983+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
62984+ return FLOODING;
62985+ }
62986+ else return FLOODING;
62987+
62988+set_fmt:
62989+#endif
62990+ memset(buf, 0, PAGE_SIZE);
62991+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
62992+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
62993+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
62994+ } else if (current->signal->curr_ip) {
62995+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
62996+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
62997+ } else if (gr_acl_is_enabled()) {
62998+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
62999+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
63000+ } else {
63001+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
63002+ strcpy(buf, fmt);
63003+ }
63004+
63005+ return NO_FLOODING;
63006+}
63007+
63008+static void gr_log_middle(int audit, const char *msg, va_list ap)
63009+ __attribute__ ((format (printf, 2, 0)));
63010+
63011+static void gr_log_middle(int audit, const char *msg, va_list ap)
63012+{
63013+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63014+ unsigned int len = strlen(buf);
63015+
63016+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
63017+
63018+ return;
63019+}
63020+
63021+static void gr_log_middle_varargs(int audit, const char *msg, ...)
63022+ __attribute__ ((format (printf, 2, 3)));
63023+
63024+static void gr_log_middle_varargs(int audit, const char *msg, ...)
63025+{
63026+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63027+ unsigned int len = strlen(buf);
63028+ va_list ap;
63029+
63030+ va_start(ap, msg);
63031+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
63032+ va_end(ap);
63033+
63034+ return;
63035+}
63036+
63037+static void gr_log_end(int audit, int append_default)
63038+{
63039+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63040+
63041+ if (append_default) {
63042+ unsigned int len = strlen(buf);
63043+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
63044+ }
63045+
63046+ printk("%s\n", buf);
63047+
63048+ return;
63049+}
63050+
63051+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
63052+{
63053+ int logtype;
63054+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
63055+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
63056+ void *voidptr = NULL;
63057+ int num1 = 0, num2 = 0;
63058+ unsigned long ulong1 = 0, ulong2 = 0;
63059+ struct dentry *dentry = NULL;
63060+ struct vfsmount *mnt = NULL;
63061+ struct file *file = NULL;
63062+ struct task_struct *task = NULL;
63063+ const struct cred *cred, *pcred;
63064+ va_list ap;
63065+
63066+ BEGIN_LOCKS(audit);
63067+ logtype = gr_log_start(audit);
63068+ if (logtype == FLOODING) {
63069+ END_LOCKS(audit);
63070+ return;
63071+ }
63072+ va_start(ap, argtypes);
63073+ switch (argtypes) {
63074+ case GR_TTYSNIFF:
63075+ task = va_arg(ap, struct task_struct *);
63076+ 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);
63077+ break;
63078+ case GR_SYSCTL_HIDDEN:
63079+ str1 = va_arg(ap, char *);
63080+ gr_log_middle_varargs(audit, msg, result, str1);
63081+ break;
63082+ case GR_RBAC:
63083+ dentry = va_arg(ap, struct dentry *);
63084+ mnt = va_arg(ap, struct vfsmount *);
63085+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
63086+ break;
63087+ case GR_RBAC_STR:
63088+ dentry = va_arg(ap, struct dentry *);
63089+ mnt = va_arg(ap, struct vfsmount *);
63090+ str1 = va_arg(ap, char *);
63091+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
63092+ break;
63093+ case GR_STR_RBAC:
63094+ str1 = va_arg(ap, char *);
63095+ dentry = va_arg(ap, struct dentry *);
63096+ mnt = va_arg(ap, struct vfsmount *);
63097+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
63098+ break;
63099+ case GR_RBAC_MODE2:
63100+ dentry = va_arg(ap, struct dentry *);
63101+ mnt = va_arg(ap, struct vfsmount *);
63102+ str1 = va_arg(ap, char *);
63103+ str2 = va_arg(ap, char *);
63104+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
63105+ break;
63106+ case GR_RBAC_MODE3:
63107+ dentry = va_arg(ap, struct dentry *);
63108+ mnt = va_arg(ap, struct vfsmount *);
63109+ str1 = va_arg(ap, char *);
63110+ str2 = va_arg(ap, char *);
63111+ str3 = va_arg(ap, char *);
63112+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
63113+ break;
63114+ case GR_FILENAME:
63115+ dentry = va_arg(ap, struct dentry *);
63116+ mnt = va_arg(ap, struct vfsmount *);
63117+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
63118+ break;
63119+ case GR_STR_FILENAME:
63120+ str1 = va_arg(ap, char *);
63121+ dentry = va_arg(ap, struct dentry *);
63122+ mnt = va_arg(ap, struct vfsmount *);
63123+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
63124+ break;
63125+ case GR_FILENAME_STR:
63126+ dentry = va_arg(ap, struct dentry *);
63127+ mnt = va_arg(ap, struct vfsmount *);
63128+ str1 = va_arg(ap, char *);
63129+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
63130+ break;
63131+ case GR_FILENAME_TWO_INT:
63132+ dentry = va_arg(ap, struct dentry *);
63133+ mnt = va_arg(ap, struct vfsmount *);
63134+ num1 = va_arg(ap, int);
63135+ num2 = va_arg(ap, int);
63136+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
63137+ break;
63138+ case GR_FILENAME_TWO_INT_STR:
63139+ dentry = va_arg(ap, struct dentry *);
63140+ mnt = va_arg(ap, struct vfsmount *);
63141+ num1 = va_arg(ap, int);
63142+ num2 = va_arg(ap, int);
63143+ str1 = va_arg(ap, char *);
63144+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
63145+ break;
63146+ case GR_TEXTREL:
63147+ file = va_arg(ap, struct file *);
63148+ ulong1 = va_arg(ap, unsigned long);
63149+ ulong2 = va_arg(ap, unsigned long);
63150+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
63151+ break;
63152+ case GR_PTRACE:
63153+ task = va_arg(ap, struct task_struct *);
63154+ 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);
63155+ break;
63156+ case GR_RESOURCE:
63157+ task = va_arg(ap, struct task_struct *);
63158+ cred = __task_cred(task);
63159+ pcred = __task_cred(task->real_parent);
63160+ ulong1 = va_arg(ap, unsigned long);
63161+ str1 = va_arg(ap, char *);
63162+ ulong2 = va_arg(ap, unsigned long);
63163+ 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);
63164+ break;
63165+ case GR_CAP:
63166+ task = va_arg(ap, struct task_struct *);
63167+ cred = __task_cred(task);
63168+ pcred = __task_cred(task->real_parent);
63169+ str1 = va_arg(ap, char *);
63170+ 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);
63171+ break;
63172+ case GR_SIG:
63173+ str1 = va_arg(ap, char *);
63174+ voidptr = va_arg(ap, void *);
63175+ gr_log_middle_varargs(audit, msg, str1, voidptr);
63176+ break;
63177+ case GR_SIG2:
63178+ task = va_arg(ap, struct task_struct *);
63179+ cred = __task_cred(task);
63180+ pcred = __task_cred(task->real_parent);
63181+ num1 = va_arg(ap, int);
63182+ 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);
63183+ break;
63184+ case GR_CRASH1:
63185+ task = va_arg(ap, struct task_struct *);
63186+ cred = __task_cred(task);
63187+ pcred = __task_cred(task->real_parent);
63188+ ulong1 = va_arg(ap, unsigned long);
63189+ 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);
63190+ break;
63191+ case GR_CRASH2:
63192+ task = va_arg(ap, struct task_struct *);
63193+ cred = __task_cred(task);
63194+ pcred = __task_cred(task->real_parent);
63195+ ulong1 = va_arg(ap, unsigned long);
63196+ 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);
63197+ break;
63198+ case GR_RWXMAP:
63199+ file = va_arg(ap, struct file *);
63200+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
63201+ break;
63202+ case GR_PSACCT:
63203+ {
63204+ unsigned int wday, cday;
63205+ __u8 whr, chr;
63206+ __u8 wmin, cmin;
63207+ __u8 wsec, csec;
63208+ char cur_tty[64] = { 0 };
63209+ char parent_tty[64] = { 0 };
63210+
63211+ task = va_arg(ap, struct task_struct *);
63212+ wday = va_arg(ap, unsigned int);
63213+ cday = va_arg(ap, unsigned int);
63214+ whr = va_arg(ap, int);
63215+ chr = va_arg(ap, int);
63216+ wmin = va_arg(ap, int);
63217+ cmin = va_arg(ap, int);
63218+ wsec = va_arg(ap, int);
63219+ csec = va_arg(ap, int);
63220+ ulong1 = va_arg(ap, unsigned long);
63221+ cred = __task_cred(task);
63222+ pcred = __task_cred(task->real_parent);
63223+
63224+ 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);
63225+ }
63226+ break;
63227+ default:
63228+ gr_log_middle(audit, msg, ap);
63229+ }
63230+ va_end(ap);
63231+ // these don't need DEFAULTSECARGS printed on the end
63232+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
63233+ gr_log_end(audit, 0);
63234+ else
63235+ gr_log_end(audit, 1);
63236+ END_LOCKS(audit);
63237+}
63238diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
63239new file mode 100644
63240index 0000000..6c0416b
63241--- /dev/null
63242+++ b/grsecurity/grsec_mem.c
63243@@ -0,0 +1,33 @@
63244+#include <linux/kernel.h>
63245+#include <linux/sched.h>
63246+#include <linux/mm.h>
63247+#include <linux/mman.h>
63248+#include <linux/grinternal.h>
63249+
63250+void
63251+gr_handle_ioperm(void)
63252+{
63253+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
63254+ return;
63255+}
63256+
63257+void
63258+gr_handle_iopl(void)
63259+{
63260+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
63261+ return;
63262+}
63263+
63264+void
63265+gr_handle_mem_readwrite(u64 from, u64 to)
63266+{
63267+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
63268+ return;
63269+}
63270+
63271+void
63272+gr_handle_vm86(void)
63273+{
63274+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
63275+ return;
63276+}
63277diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
63278new file mode 100644
63279index 0000000..2131422
63280--- /dev/null
63281+++ b/grsecurity/grsec_mount.c
63282@@ -0,0 +1,62 @@
63283+#include <linux/kernel.h>
63284+#include <linux/sched.h>
63285+#include <linux/mount.h>
63286+#include <linux/grsecurity.h>
63287+#include <linux/grinternal.h>
63288+
63289+void
63290+gr_log_remount(const char *devname, const int retval)
63291+{
63292+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63293+ if (grsec_enable_mount && (retval >= 0))
63294+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
63295+#endif
63296+ return;
63297+}
63298+
63299+void
63300+gr_log_unmount(const char *devname, const int retval)
63301+{
63302+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63303+ if (grsec_enable_mount && (retval >= 0))
63304+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
63305+#endif
63306+ return;
63307+}
63308+
63309+void
63310+gr_log_mount(const char *from, const char *to, const int retval)
63311+{
63312+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63313+ if (grsec_enable_mount && (retval >= 0))
63314+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
63315+#endif
63316+ return;
63317+}
63318+
63319+int
63320+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
63321+{
63322+#ifdef CONFIG_GRKERNSEC_ROFS
63323+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
63324+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
63325+ return -EPERM;
63326+ } else
63327+ return 0;
63328+#endif
63329+ return 0;
63330+}
63331+
63332+int
63333+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
63334+{
63335+#ifdef CONFIG_GRKERNSEC_ROFS
63336+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
63337+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
63338+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
63339+ return -EPERM;
63340+ } else
63341+ return 0;
63342+#endif
63343+ return 0;
63344+}
63345diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
63346new file mode 100644
63347index 0000000..a3b12a0
63348--- /dev/null
63349+++ b/grsecurity/grsec_pax.c
63350@@ -0,0 +1,36 @@
63351+#include <linux/kernel.h>
63352+#include <linux/sched.h>
63353+#include <linux/mm.h>
63354+#include <linux/file.h>
63355+#include <linux/grinternal.h>
63356+#include <linux/grsecurity.h>
63357+
63358+void
63359+gr_log_textrel(struct vm_area_struct * vma)
63360+{
63361+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63362+ if (grsec_enable_audit_textrel)
63363+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
63364+#endif
63365+ return;
63366+}
63367+
63368+void
63369+gr_log_rwxmmap(struct file *file)
63370+{
63371+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63372+ if (grsec_enable_log_rwxmaps)
63373+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
63374+#endif
63375+ return;
63376+}
63377+
63378+void
63379+gr_log_rwxmprotect(struct file *file)
63380+{
63381+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63382+ if (grsec_enable_log_rwxmaps)
63383+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
63384+#endif
63385+ return;
63386+}
63387diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
63388new file mode 100644
63389index 0000000..472c1d6
63390--- /dev/null
63391+++ b/grsecurity/grsec_ptrace.c
63392@@ -0,0 +1,14 @@
63393+#include <linux/kernel.h>
63394+#include <linux/sched.h>
63395+#include <linux/grinternal.h>
63396+#include <linux/grsecurity.h>
63397+
63398+void
63399+gr_audit_ptrace(struct task_struct *task)
63400+{
63401+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63402+ if (grsec_enable_audit_ptrace)
63403+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
63404+#endif
63405+ return;
63406+}
63407diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
63408new file mode 100644
63409index 0000000..dc73fe9
63410--- /dev/null
63411+++ b/grsecurity/grsec_sig.c
63412@@ -0,0 +1,205 @@
63413+#include <linux/kernel.h>
63414+#include <linux/sched.h>
63415+#include <linux/delay.h>
63416+#include <linux/grsecurity.h>
63417+#include <linux/grinternal.h>
63418+#include <linux/hardirq.h>
63419+
63420+char *signames[] = {
63421+ [SIGSEGV] = "Segmentation fault",
63422+ [SIGILL] = "Illegal instruction",
63423+ [SIGABRT] = "Abort",
63424+ [SIGBUS] = "Invalid alignment/Bus error"
63425+};
63426+
63427+void
63428+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
63429+{
63430+#ifdef CONFIG_GRKERNSEC_SIGNAL
63431+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
63432+ (sig == SIGABRT) || (sig == SIGBUS))) {
63433+ if (t->pid == current->pid) {
63434+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
63435+ } else {
63436+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
63437+ }
63438+ }
63439+#endif
63440+ return;
63441+}
63442+
63443+int
63444+gr_handle_signal(const struct task_struct *p, const int sig)
63445+{
63446+#ifdef CONFIG_GRKERNSEC
63447+ if (current->pid > 1 && gr_check_protected_task(p)) {
63448+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
63449+ return -EPERM;
63450+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
63451+ return -EPERM;
63452+ }
63453+#endif
63454+ return 0;
63455+}
63456+
63457+#ifdef CONFIG_GRKERNSEC
63458+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
63459+
63460+int gr_fake_force_sig(int sig, struct task_struct *t)
63461+{
63462+ unsigned long int flags;
63463+ int ret, blocked, ignored;
63464+ struct k_sigaction *action;
63465+
63466+ spin_lock_irqsave(&t->sighand->siglock, flags);
63467+ action = &t->sighand->action[sig-1];
63468+ ignored = action->sa.sa_handler == SIG_IGN;
63469+ blocked = sigismember(&t->blocked, sig);
63470+ if (blocked || ignored) {
63471+ action->sa.sa_handler = SIG_DFL;
63472+ if (blocked) {
63473+ sigdelset(&t->blocked, sig);
63474+ recalc_sigpending_and_wake(t);
63475+ }
63476+ }
63477+ if (action->sa.sa_handler == SIG_DFL)
63478+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
63479+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
63480+
63481+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
63482+
63483+ return ret;
63484+}
63485+#endif
63486+
63487+#ifdef CONFIG_GRKERNSEC_BRUTE
63488+#define GR_USER_BAN_TIME (15 * 60)
63489+
63490+static int __get_dumpable(unsigned long mm_flags)
63491+{
63492+ int ret;
63493+
63494+ ret = mm_flags & MMF_DUMPABLE_MASK;
63495+ return (ret >= 2) ? 2 : ret;
63496+}
63497+#endif
63498+
63499+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
63500+{
63501+#ifdef CONFIG_GRKERNSEC_BRUTE
63502+ uid_t uid = 0;
63503+
63504+ if (!grsec_enable_brute)
63505+ return;
63506+
63507+ rcu_read_lock();
63508+ read_lock(&tasklist_lock);
63509+ read_lock(&grsec_exec_file_lock);
63510+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
63511+ p->real_parent->brute = 1;
63512+ else {
63513+ const struct cred *cred = __task_cred(p), *cred2;
63514+ struct task_struct *tsk, *tsk2;
63515+
63516+ if (!__get_dumpable(mm_flags) && cred->uid) {
63517+ struct user_struct *user;
63518+
63519+ uid = cred->uid;
63520+
63521+ /* this is put upon execution past expiration */
63522+ user = find_user(uid);
63523+ if (user == NULL)
63524+ goto unlock;
63525+ user->banned = 1;
63526+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
63527+ if (user->ban_expires == ~0UL)
63528+ user->ban_expires--;
63529+
63530+ do_each_thread(tsk2, tsk) {
63531+ cred2 = __task_cred(tsk);
63532+ if (tsk != p && cred2->uid == uid)
63533+ gr_fake_force_sig(SIGKILL, tsk);
63534+ } while_each_thread(tsk2, tsk);
63535+ }
63536+ }
63537+unlock:
63538+ read_unlock(&grsec_exec_file_lock);
63539+ read_unlock(&tasklist_lock);
63540+ rcu_read_unlock();
63541+
63542+ if (uid)
63543+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
63544+#endif
63545+ return;
63546+}
63547+
63548+void gr_handle_brute_check(void)
63549+{
63550+#ifdef CONFIG_GRKERNSEC_BRUTE
63551+ if (current->brute)
63552+ msleep(30 * 1000);
63553+#endif
63554+ return;
63555+}
63556+
63557+void gr_handle_kernel_exploit(void)
63558+{
63559+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
63560+ const struct cred *cred;
63561+ struct task_struct *tsk, *tsk2;
63562+ struct user_struct *user;
63563+ uid_t uid;
63564+
63565+ if (in_irq() || in_serving_softirq() || in_nmi())
63566+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
63567+
63568+ uid = current_uid();
63569+
63570+ if (uid == 0)
63571+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
63572+ else {
63573+ /* kill all the processes of this user, hold a reference
63574+ to their creds struct, and prevent them from creating
63575+ another process until system reset
63576+ */
63577+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
63578+ /* we intentionally leak this ref */
63579+ user = get_uid(current->cred->user);
63580+ if (user) {
63581+ user->banned = 1;
63582+ user->ban_expires = ~0UL;
63583+ }
63584+
63585+ read_lock(&tasklist_lock);
63586+ do_each_thread(tsk2, tsk) {
63587+ cred = __task_cred(tsk);
63588+ if (cred->uid == uid)
63589+ gr_fake_force_sig(SIGKILL, tsk);
63590+ } while_each_thread(tsk2, tsk);
63591+ read_unlock(&tasklist_lock);
63592+ }
63593+#endif
63594+}
63595+
63596+int __gr_process_user_ban(struct user_struct *user)
63597+{
63598+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63599+ if (unlikely(user->banned)) {
63600+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
63601+ user->banned = 0;
63602+ user->ban_expires = 0;
63603+ free_uid(user);
63604+ } else
63605+ return -EPERM;
63606+ }
63607+#endif
63608+ return 0;
63609+}
63610+
63611+int gr_process_user_ban(void)
63612+{
63613+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63614+ return __gr_process_user_ban(current->cred->user);
63615+#endif
63616+ return 0;
63617+}
63618diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
63619new file mode 100644
63620index 0000000..7512ea9
63621--- /dev/null
63622+++ b/grsecurity/grsec_sock.c
63623@@ -0,0 +1,275 @@
63624+#include <linux/kernel.h>
63625+#include <linux/module.h>
63626+#include <linux/sched.h>
63627+#include <linux/file.h>
63628+#include <linux/net.h>
63629+#include <linux/in.h>
63630+#include <linux/ip.h>
63631+#include <net/sock.h>
63632+#include <net/inet_sock.h>
63633+#include <linux/grsecurity.h>
63634+#include <linux/grinternal.h>
63635+#include <linux/gracl.h>
63636+
63637+kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
63638+EXPORT_SYMBOL(gr_cap_rtnetlink);
63639+
63640+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
63641+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
63642+
63643+EXPORT_SYMBOL(gr_search_udp_recvmsg);
63644+EXPORT_SYMBOL(gr_search_udp_sendmsg);
63645+
63646+#ifdef CONFIG_UNIX_MODULE
63647+EXPORT_SYMBOL(gr_acl_handle_unix);
63648+EXPORT_SYMBOL(gr_acl_handle_mknod);
63649+EXPORT_SYMBOL(gr_handle_chroot_unix);
63650+EXPORT_SYMBOL(gr_handle_create);
63651+#endif
63652+
63653+#ifdef CONFIG_GRKERNSEC
63654+#define gr_conn_table_size 32749
63655+struct conn_table_entry {
63656+ struct conn_table_entry *next;
63657+ struct signal_struct *sig;
63658+};
63659+
63660+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
63661+DEFINE_SPINLOCK(gr_conn_table_lock);
63662+
63663+extern const char * gr_socktype_to_name(unsigned char type);
63664+extern const char * gr_proto_to_name(unsigned char proto);
63665+extern const char * gr_sockfamily_to_name(unsigned char family);
63666+
63667+static __inline__ int
63668+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
63669+{
63670+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
63671+}
63672+
63673+static __inline__ int
63674+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
63675+ __u16 sport, __u16 dport)
63676+{
63677+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
63678+ sig->gr_sport == sport && sig->gr_dport == dport))
63679+ return 1;
63680+ else
63681+ return 0;
63682+}
63683+
63684+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
63685+{
63686+ struct conn_table_entry **match;
63687+ unsigned int index;
63688+
63689+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
63690+ sig->gr_sport, sig->gr_dport,
63691+ gr_conn_table_size);
63692+
63693+ newent->sig = sig;
63694+
63695+ match = &gr_conn_table[index];
63696+ newent->next = *match;
63697+ *match = newent;
63698+
63699+ return;
63700+}
63701+
63702+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
63703+{
63704+ struct conn_table_entry *match, *last = NULL;
63705+ unsigned int index;
63706+
63707+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
63708+ sig->gr_sport, sig->gr_dport,
63709+ gr_conn_table_size);
63710+
63711+ match = gr_conn_table[index];
63712+ while (match && !conn_match(match->sig,
63713+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
63714+ sig->gr_dport)) {
63715+ last = match;
63716+ match = match->next;
63717+ }
63718+
63719+ if (match) {
63720+ if (last)
63721+ last->next = match->next;
63722+ else
63723+ gr_conn_table[index] = NULL;
63724+ kfree(match);
63725+ }
63726+
63727+ return;
63728+}
63729+
63730+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
63731+ __u16 sport, __u16 dport)
63732+{
63733+ struct conn_table_entry *match;
63734+ unsigned int index;
63735+
63736+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
63737+
63738+ match = gr_conn_table[index];
63739+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
63740+ match = match->next;
63741+
63742+ if (match)
63743+ return match->sig;
63744+ else
63745+ return NULL;
63746+}
63747+
63748+#endif
63749+
63750+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
63751+{
63752+#ifdef CONFIG_GRKERNSEC
63753+ struct signal_struct *sig = task->signal;
63754+ struct conn_table_entry *newent;
63755+
63756+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
63757+ if (newent == NULL)
63758+ return;
63759+ /* no bh lock needed since we are called with bh disabled */
63760+ spin_lock(&gr_conn_table_lock);
63761+ gr_del_task_from_ip_table_nolock(sig);
63762+ sig->gr_saddr = inet->rcv_saddr;
63763+ sig->gr_daddr = inet->daddr;
63764+ sig->gr_sport = inet->sport;
63765+ sig->gr_dport = inet->dport;
63766+ gr_add_to_task_ip_table_nolock(sig, newent);
63767+ spin_unlock(&gr_conn_table_lock);
63768+#endif
63769+ return;
63770+}
63771+
63772+void gr_del_task_from_ip_table(struct task_struct *task)
63773+{
63774+#ifdef CONFIG_GRKERNSEC
63775+ spin_lock_bh(&gr_conn_table_lock);
63776+ gr_del_task_from_ip_table_nolock(task->signal);
63777+ spin_unlock_bh(&gr_conn_table_lock);
63778+#endif
63779+ return;
63780+}
63781+
63782+void
63783+gr_attach_curr_ip(const struct sock *sk)
63784+{
63785+#ifdef CONFIG_GRKERNSEC
63786+ struct signal_struct *p, *set;
63787+ const struct inet_sock *inet = inet_sk(sk);
63788+
63789+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
63790+ return;
63791+
63792+ set = current->signal;
63793+
63794+ spin_lock_bh(&gr_conn_table_lock);
63795+ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
63796+ inet->dport, inet->sport);
63797+ if (unlikely(p != NULL)) {
63798+ set->curr_ip = p->curr_ip;
63799+ set->used_accept = 1;
63800+ gr_del_task_from_ip_table_nolock(p);
63801+ spin_unlock_bh(&gr_conn_table_lock);
63802+ return;
63803+ }
63804+ spin_unlock_bh(&gr_conn_table_lock);
63805+
63806+ set->curr_ip = inet->daddr;
63807+ set->used_accept = 1;
63808+#endif
63809+ return;
63810+}
63811+
63812+int
63813+gr_handle_sock_all(const int family, const int type, const int protocol)
63814+{
63815+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63816+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
63817+ (family != AF_UNIX)) {
63818+ if (family == AF_INET)
63819+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
63820+ else
63821+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
63822+ return -EACCES;
63823+ }
63824+#endif
63825+ return 0;
63826+}
63827+
63828+int
63829+gr_handle_sock_server(const struct sockaddr *sck)
63830+{
63831+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63832+ if (grsec_enable_socket_server &&
63833+ in_group_p(grsec_socket_server_gid) &&
63834+ sck && (sck->sa_family != AF_UNIX) &&
63835+ (sck->sa_family != AF_LOCAL)) {
63836+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
63837+ return -EACCES;
63838+ }
63839+#endif
63840+ return 0;
63841+}
63842+
63843+int
63844+gr_handle_sock_server_other(const struct sock *sck)
63845+{
63846+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63847+ if (grsec_enable_socket_server &&
63848+ in_group_p(grsec_socket_server_gid) &&
63849+ sck && (sck->sk_family != AF_UNIX) &&
63850+ (sck->sk_family != AF_LOCAL)) {
63851+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
63852+ return -EACCES;
63853+ }
63854+#endif
63855+ return 0;
63856+}
63857+
63858+int
63859+gr_handle_sock_client(const struct sockaddr *sck)
63860+{
63861+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63862+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
63863+ sck && (sck->sa_family != AF_UNIX) &&
63864+ (sck->sa_family != AF_LOCAL)) {
63865+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
63866+ return -EACCES;
63867+ }
63868+#endif
63869+ return 0;
63870+}
63871+
63872+kernel_cap_t
63873+gr_cap_rtnetlink(struct sock *sock)
63874+{
63875+#ifdef CONFIG_GRKERNSEC
63876+ if (!gr_acl_is_enabled())
63877+ return current_cap();
63878+ else if (sock->sk_protocol == NETLINK_ISCSI &&
63879+ cap_raised(current_cap(), CAP_SYS_ADMIN) &&
63880+ gr_is_capable(CAP_SYS_ADMIN))
63881+ return current_cap();
63882+ else if (sock->sk_protocol == NETLINK_AUDIT &&
63883+ cap_raised(current_cap(), CAP_AUDIT_WRITE) &&
63884+ gr_is_capable(CAP_AUDIT_WRITE) &&
63885+ cap_raised(current_cap(), CAP_AUDIT_CONTROL) &&
63886+ gr_is_capable(CAP_AUDIT_CONTROL))
63887+ return current_cap();
63888+ else if (cap_raised(current_cap(), CAP_NET_ADMIN) &&
63889+ ((sock->sk_protocol == NETLINK_ROUTE) ?
63890+ gr_is_capable_nolog(CAP_NET_ADMIN) :
63891+ gr_is_capable(CAP_NET_ADMIN)))
63892+ return current_cap();
63893+ else
63894+ return __cap_empty_set;
63895+#else
63896+ return current_cap();
63897+#endif
63898+}
63899diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
63900new file mode 100644
63901index 0000000..2753505
63902--- /dev/null
63903+++ b/grsecurity/grsec_sysctl.c
63904@@ -0,0 +1,479 @@
63905+#include <linux/kernel.h>
63906+#include <linux/sched.h>
63907+#include <linux/sysctl.h>
63908+#include <linux/grsecurity.h>
63909+#include <linux/grinternal.h>
63910+
63911+int
63912+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
63913+{
63914+#ifdef CONFIG_GRKERNSEC_SYSCTL
63915+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
63916+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
63917+ return -EACCES;
63918+ }
63919+#endif
63920+ return 0;
63921+}
63922+
63923+#ifdef CONFIG_GRKERNSEC_ROFS
63924+static int __maybe_unused one = 1;
63925+#endif
63926+
63927+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
63928+ctl_table grsecurity_table[] = {
63929+#ifdef CONFIG_GRKERNSEC_SYSCTL
63930+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
63931+#ifdef CONFIG_GRKERNSEC_IO
63932+ {
63933+ .ctl_name = CTL_UNNUMBERED,
63934+ .procname = "disable_priv_io",
63935+ .data = &grsec_disable_privio,
63936+ .maxlen = sizeof(int),
63937+ .mode = 0600,
63938+ .proc_handler = &proc_dointvec,
63939+ },
63940+#endif
63941+#endif
63942+#ifdef CONFIG_GRKERNSEC_LINK
63943+ {
63944+ .ctl_name = CTL_UNNUMBERED,
63945+ .procname = "linking_restrictions",
63946+ .data = &grsec_enable_link,
63947+ .maxlen = sizeof(int),
63948+ .mode = 0600,
63949+ .proc_handler = &proc_dointvec,
63950+ },
63951+#endif
63952+#ifdef CONFIG_GRKERNSEC_BRUTE
63953+ {
63954+ .ctl_name = CTL_UNNUMBERED,
63955+ .procname = "deter_bruteforce",
63956+ .data = &grsec_enable_brute,
63957+ .maxlen = sizeof(int),
63958+ .mode = 0600,
63959+ .proc_handler = &proc_dointvec,
63960+ },
63961+#endif
63962+#ifdef CONFIG_GRKERNSEC_FIFO
63963+ {
63964+ .ctl_name = CTL_UNNUMBERED,
63965+ .procname = "fifo_restrictions",
63966+ .data = &grsec_enable_fifo,
63967+ .maxlen = sizeof(int),
63968+ .mode = 0600,
63969+ .proc_handler = &proc_dointvec,
63970+ },
63971+#endif
63972+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
63973+ {
63974+ .ctl_name = CTL_UNNUMBERED,
63975+ .procname = "ip_blackhole",
63976+ .data = &grsec_enable_blackhole,
63977+ .maxlen = sizeof(int),
63978+ .mode = 0600,
63979+ .proc_handler = &proc_dointvec,
63980+ },
63981+ {
63982+ .ctl_name = CTL_UNNUMBERED,
63983+ .procname = "lastack_retries",
63984+ .data = &grsec_lastack_retries,
63985+ .maxlen = sizeof(int),
63986+ .mode = 0600,
63987+ .proc_handler = &proc_dointvec,
63988+ },
63989+#endif
63990+#ifdef CONFIG_GRKERNSEC_EXECLOG
63991+ {
63992+ .ctl_name = CTL_UNNUMBERED,
63993+ .procname = "exec_logging",
63994+ .data = &grsec_enable_execlog,
63995+ .maxlen = sizeof(int),
63996+ .mode = 0600,
63997+ .proc_handler = &proc_dointvec,
63998+ },
63999+#endif
64000+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64001+ {
64002+ .ctl_name = CTL_UNNUMBERED,
64003+ .procname = "rwxmap_logging",
64004+ .data = &grsec_enable_log_rwxmaps,
64005+ .maxlen = sizeof(int),
64006+ .mode = 0600,
64007+ .proc_handler = &proc_dointvec,
64008+ },
64009+#endif
64010+#ifdef CONFIG_GRKERNSEC_SIGNAL
64011+ {
64012+ .ctl_name = CTL_UNNUMBERED,
64013+ .procname = "signal_logging",
64014+ .data = &grsec_enable_signal,
64015+ .maxlen = sizeof(int),
64016+ .mode = 0600,
64017+ .proc_handler = &proc_dointvec,
64018+ },
64019+#endif
64020+#ifdef CONFIG_GRKERNSEC_FORKFAIL
64021+ {
64022+ .ctl_name = CTL_UNNUMBERED,
64023+ .procname = "forkfail_logging",
64024+ .data = &grsec_enable_forkfail,
64025+ .maxlen = sizeof(int),
64026+ .mode = 0600,
64027+ .proc_handler = &proc_dointvec,
64028+ },
64029+#endif
64030+#ifdef CONFIG_GRKERNSEC_TIME
64031+ {
64032+ .ctl_name = CTL_UNNUMBERED,
64033+ .procname = "timechange_logging",
64034+ .data = &grsec_enable_time,
64035+ .maxlen = sizeof(int),
64036+ .mode = 0600,
64037+ .proc_handler = &proc_dointvec,
64038+ },
64039+#endif
64040+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64041+ {
64042+ .ctl_name = CTL_UNNUMBERED,
64043+ .procname = "chroot_deny_shmat",
64044+ .data = &grsec_enable_chroot_shmat,
64045+ .maxlen = sizeof(int),
64046+ .mode = 0600,
64047+ .proc_handler = &proc_dointvec,
64048+ },
64049+#endif
64050+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64051+ {
64052+ .ctl_name = CTL_UNNUMBERED,
64053+ .procname = "chroot_deny_unix",
64054+ .data = &grsec_enable_chroot_unix,
64055+ .maxlen = sizeof(int),
64056+ .mode = 0600,
64057+ .proc_handler = &proc_dointvec,
64058+ },
64059+#endif
64060+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64061+ {
64062+ .ctl_name = CTL_UNNUMBERED,
64063+ .procname = "chroot_deny_mount",
64064+ .data = &grsec_enable_chroot_mount,
64065+ .maxlen = sizeof(int),
64066+ .mode = 0600,
64067+ .proc_handler = &proc_dointvec,
64068+ },
64069+#endif
64070+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64071+ {
64072+ .ctl_name = CTL_UNNUMBERED,
64073+ .procname = "chroot_deny_fchdir",
64074+ .data = &grsec_enable_chroot_fchdir,
64075+ .maxlen = sizeof(int),
64076+ .mode = 0600,
64077+ .proc_handler = &proc_dointvec,
64078+ },
64079+#endif
64080+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64081+ {
64082+ .ctl_name = CTL_UNNUMBERED,
64083+ .procname = "chroot_deny_chroot",
64084+ .data = &grsec_enable_chroot_double,
64085+ .maxlen = sizeof(int),
64086+ .mode = 0600,
64087+ .proc_handler = &proc_dointvec,
64088+ },
64089+#endif
64090+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64091+ {
64092+ .ctl_name = CTL_UNNUMBERED,
64093+ .procname = "chroot_deny_pivot",
64094+ .data = &grsec_enable_chroot_pivot,
64095+ .maxlen = sizeof(int),
64096+ .mode = 0600,
64097+ .proc_handler = &proc_dointvec,
64098+ },
64099+#endif
64100+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64101+ {
64102+ .ctl_name = CTL_UNNUMBERED,
64103+ .procname = "chroot_enforce_chdir",
64104+ .data = &grsec_enable_chroot_chdir,
64105+ .maxlen = sizeof(int),
64106+ .mode = 0600,
64107+ .proc_handler = &proc_dointvec,
64108+ },
64109+#endif
64110+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64111+ {
64112+ .ctl_name = CTL_UNNUMBERED,
64113+ .procname = "chroot_deny_chmod",
64114+ .data = &grsec_enable_chroot_chmod,
64115+ .maxlen = sizeof(int),
64116+ .mode = 0600,
64117+ .proc_handler = &proc_dointvec,
64118+ },
64119+#endif
64120+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64121+ {
64122+ .ctl_name = CTL_UNNUMBERED,
64123+ .procname = "chroot_deny_mknod",
64124+ .data = &grsec_enable_chroot_mknod,
64125+ .maxlen = sizeof(int),
64126+ .mode = 0600,
64127+ .proc_handler = &proc_dointvec,
64128+ },
64129+#endif
64130+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64131+ {
64132+ .ctl_name = CTL_UNNUMBERED,
64133+ .procname = "chroot_restrict_nice",
64134+ .data = &grsec_enable_chroot_nice,
64135+ .maxlen = sizeof(int),
64136+ .mode = 0600,
64137+ .proc_handler = &proc_dointvec,
64138+ },
64139+#endif
64140+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64141+ {
64142+ .ctl_name = CTL_UNNUMBERED,
64143+ .procname = "chroot_execlog",
64144+ .data = &grsec_enable_chroot_execlog,
64145+ .maxlen = sizeof(int),
64146+ .mode = 0600,
64147+ .proc_handler = &proc_dointvec,
64148+ },
64149+#endif
64150+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64151+ {
64152+ .ctl_name = CTL_UNNUMBERED,
64153+ .procname = "chroot_caps",
64154+ .data = &grsec_enable_chroot_caps,
64155+ .maxlen = sizeof(int),
64156+ .mode = 0600,
64157+ .proc_handler = &proc_dointvec,
64158+ },
64159+#endif
64160+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64161+ {
64162+ .ctl_name = CTL_UNNUMBERED,
64163+ .procname = "chroot_deny_sysctl",
64164+ .data = &grsec_enable_chroot_sysctl,
64165+ .maxlen = sizeof(int),
64166+ .mode = 0600,
64167+ .proc_handler = &proc_dointvec,
64168+ },
64169+#endif
64170+#ifdef CONFIG_GRKERNSEC_TPE
64171+ {
64172+ .ctl_name = CTL_UNNUMBERED,
64173+ .procname = "tpe",
64174+ .data = &grsec_enable_tpe,
64175+ .maxlen = sizeof(int),
64176+ .mode = 0600,
64177+ .proc_handler = &proc_dointvec,
64178+ },
64179+ {
64180+ .ctl_name = CTL_UNNUMBERED,
64181+ .procname = "tpe_gid",
64182+ .data = &grsec_tpe_gid,
64183+ .maxlen = sizeof(int),
64184+ .mode = 0600,
64185+ .proc_handler = &proc_dointvec,
64186+ },
64187+#endif
64188+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64189+ {
64190+ .ctl_name = CTL_UNNUMBERED,
64191+ .procname = "tpe_invert",
64192+ .data = &grsec_enable_tpe_invert,
64193+ .maxlen = sizeof(int),
64194+ .mode = 0600,
64195+ .proc_handler = &proc_dointvec,
64196+ },
64197+#endif
64198+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64199+ {
64200+ .ctl_name = CTL_UNNUMBERED,
64201+ .procname = "tpe_restrict_all",
64202+ .data = &grsec_enable_tpe_all,
64203+ .maxlen = sizeof(int),
64204+ .mode = 0600,
64205+ .proc_handler = &proc_dointvec,
64206+ },
64207+#endif
64208+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64209+ {
64210+ .ctl_name = CTL_UNNUMBERED,
64211+ .procname = "socket_all",
64212+ .data = &grsec_enable_socket_all,
64213+ .maxlen = sizeof(int),
64214+ .mode = 0600,
64215+ .proc_handler = &proc_dointvec,
64216+ },
64217+ {
64218+ .ctl_name = CTL_UNNUMBERED,
64219+ .procname = "socket_all_gid",
64220+ .data = &grsec_socket_all_gid,
64221+ .maxlen = sizeof(int),
64222+ .mode = 0600,
64223+ .proc_handler = &proc_dointvec,
64224+ },
64225+#endif
64226+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64227+ {
64228+ .ctl_name = CTL_UNNUMBERED,
64229+ .procname = "socket_client",
64230+ .data = &grsec_enable_socket_client,
64231+ .maxlen = sizeof(int),
64232+ .mode = 0600,
64233+ .proc_handler = &proc_dointvec,
64234+ },
64235+ {
64236+ .ctl_name = CTL_UNNUMBERED,
64237+ .procname = "socket_client_gid",
64238+ .data = &grsec_socket_client_gid,
64239+ .maxlen = sizeof(int),
64240+ .mode = 0600,
64241+ .proc_handler = &proc_dointvec,
64242+ },
64243+#endif
64244+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64245+ {
64246+ .ctl_name = CTL_UNNUMBERED,
64247+ .procname = "socket_server",
64248+ .data = &grsec_enable_socket_server,
64249+ .maxlen = sizeof(int),
64250+ .mode = 0600,
64251+ .proc_handler = &proc_dointvec,
64252+ },
64253+ {
64254+ .ctl_name = CTL_UNNUMBERED,
64255+ .procname = "socket_server_gid",
64256+ .data = &grsec_socket_server_gid,
64257+ .maxlen = sizeof(int),
64258+ .mode = 0600,
64259+ .proc_handler = &proc_dointvec,
64260+ },
64261+#endif
64262+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
64263+ {
64264+ .ctl_name = CTL_UNNUMBERED,
64265+ .procname = "audit_group",
64266+ .data = &grsec_enable_group,
64267+ .maxlen = sizeof(int),
64268+ .mode = 0600,
64269+ .proc_handler = &proc_dointvec,
64270+ },
64271+ {
64272+ .ctl_name = CTL_UNNUMBERED,
64273+ .procname = "audit_gid",
64274+ .data = &grsec_audit_gid,
64275+ .maxlen = sizeof(int),
64276+ .mode = 0600,
64277+ .proc_handler = &proc_dointvec,
64278+ },
64279+#endif
64280+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64281+ {
64282+ .ctl_name = CTL_UNNUMBERED,
64283+ .procname = "audit_chdir",
64284+ .data = &grsec_enable_chdir,
64285+ .maxlen = sizeof(int),
64286+ .mode = 0600,
64287+ .proc_handler = &proc_dointvec,
64288+ },
64289+#endif
64290+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64291+ {
64292+ .ctl_name = CTL_UNNUMBERED,
64293+ .procname = "audit_mount",
64294+ .data = &grsec_enable_mount,
64295+ .maxlen = sizeof(int),
64296+ .mode = 0600,
64297+ .proc_handler = &proc_dointvec,
64298+ },
64299+#endif
64300+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64301+ {
64302+ .ctl_name = CTL_UNNUMBERED,
64303+ .procname = "audit_textrel",
64304+ .data = &grsec_enable_audit_textrel,
64305+ .maxlen = sizeof(int),
64306+ .mode = 0600,
64307+ .proc_handler = &proc_dointvec,
64308+ },
64309+#endif
64310+#ifdef CONFIG_GRKERNSEC_DMESG
64311+ {
64312+ .ctl_name = CTL_UNNUMBERED,
64313+ .procname = "dmesg",
64314+ .data = &grsec_enable_dmesg,
64315+ .maxlen = sizeof(int),
64316+ .mode = 0600,
64317+ .proc_handler = &proc_dointvec,
64318+ },
64319+#endif
64320+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64321+ {
64322+ .ctl_name = CTL_UNNUMBERED,
64323+ .procname = "chroot_findtask",
64324+ .data = &grsec_enable_chroot_findtask,
64325+ .maxlen = sizeof(int),
64326+ .mode = 0600,
64327+ .proc_handler = &proc_dointvec,
64328+ },
64329+#endif
64330+#ifdef CONFIG_GRKERNSEC_RESLOG
64331+ {
64332+ .ctl_name = CTL_UNNUMBERED,
64333+ .procname = "resource_logging",
64334+ .data = &grsec_resource_logging,
64335+ .maxlen = sizeof(int),
64336+ .mode = 0600,
64337+ .proc_handler = &proc_dointvec,
64338+ },
64339+#endif
64340+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64341+ {
64342+ .ctl_name = CTL_UNNUMBERED,
64343+ .procname = "audit_ptrace",
64344+ .data = &grsec_enable_audit_ptrace,
64345+ .maxlen = sizeof(int),
64346+ .mode = 0600,
64347+ .proc_handler = &proc_dointvec,
64348+ },
64349+#endif
64350+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
64351+ {
64352+ .ctl_name = CTL_UNNUMBERED,
64353+ .procname = "harden_ptrace",
64354+ .data = &grsec_enable_harden_ptrace,
64355+ .maxlen = sizeof(int),
64356+ .mode = 0600,
64357+ .proc_handler = &proc_dointvec,
64358+ },
64359+#endif
64360+ {
64361+ .ctl_name = CTL_UNNUMBERED,
64362+ .procname = "grsec_lock",
64363+ .data = &grsec_lock,
64364+ .maxlen = sizeof(int),
64365+ .mode = 0600,
64366+ .proc_handler = &proc_dointvec,
64367+ },
64368+#endif
64369+#ifdef CONFIG_GRKERNSEC_ROFS
64370+ {
64371+ .ctl_name = CTL_UNNUMBERED,
64372+ .procname = "romount_protect",
64373+ .data = &grsec_enable_rofs,
64374+ .maxlen = sizeof(int),
64375+ .mode = 0600,
64376+ .proc_handler = &proc_dointvec_minmax,
64377+ .extra1 = &one,
64378+ .extra2 = &one,
64379+ },
64380+#endif
64381+ { .ctl_name = 0 }
64382+};
64383+#endif
64384diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
64385new file mode 100644
64386index 0000000..0dc13c3
64387--- /dev/null
64388+++ b/grsecurity/grsec_time.c
64389@@ -0,0 +1,16 @@
64390+#include <linux/kernel.h>
64391+#include <linux/sched.h>
64392+#include <linux/grinternal.h>
64393+#include <linux/module.h>
64394+
64395+void
64396+gr_log_timechange(void)
64397+{
64398+#ifdef CONFIG_GRKERNSEC_TIME
64399+ if (grsec_enable_time)
64400+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
64401+#endif
64402+ return;
64403+}
64404+
64405+EXPORT_SYMBOL(gr_log_timechange);
64406diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
64407new file mode 100644
64408index 0000000..4a78774
64409--- /dev/null
64410+++ b/grsecurity/grsec_tpe.c
64411@@ -0,0 +1,39 @@
64412+#include <linux/kernel.h>
64413+#include <linux/sched.h>
64414+#include <linux/file.h>
64415+#include <linux/fs.h>
64416+#include <linux/grinternal.h>
64417+
64418+extern int gr_acl_tpe_check(void);
64419+
64420+int
64421+gr_tpe_allow(const struct file *file)
64422+{
64423+#ifdef CONFIG_GRKERNSEC
64424+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
64425+ const struct cred *cred = current_cred();
64426+
64427+ if (cred->uid && ((grsec_enable_tpe &&
64428+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
64429+ ((grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid)) ||
64430+ (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid)))
64431+#else
64432+ in_group_p(grsec_tpe_gid)
64433+#endif
64434+ ) || gr_acl_tpe_check()) &&
64435+ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
64436+ (inode->i_mode & S_IWOTH))))) {
64437+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
64438+ return 0;
64439+ }
64440+#ifdef CONFIG_GRKERNSEC_TPE_ALL
64441+ if (cred->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
64442+ ((inode->i_uid && (inode->i_uid != cred->uid)) ||
64443+ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
64444+ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
64445+ return 0;
64446+ }
64447+#endif
64448+#endif
64449+ return 1;
64450+}
64451diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
64452new file mode 100644
64453index 0000000..9f7b1ac
64454--- /dev/null
64455+++ b/grsecurity/grsum.c
64456@@ -0,0 +1,61 @@
64457+#include <linux/err.h>
64458+#include <linux/kernel.h>
64459+#include <linux/sched.h>
64460+#include <linux/mm.h>
64461+#include <linux/scatterlist.h>
64462+#include <linux/crypto.h>
64463+#include <linux/gracl.h>
64464+
64465+
64466+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
64467+#error "crypto and sha256 must be built into the kernel"
64468+#endif
64469+
64470+int
64471+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
64472+{
64473+ char *p;
64474+ struct crypto_hash *tfm;
64475+ struct hash_desc desc;
64476+ struct scatterlist sg;
64477+ unsigned char temp_sum[GR_SHA_LEN];
64478+ volatile int retval = 0;
64479+ volatile int dummy = 0;
64480+ unsigned int i;
64481+
64482+ sg_init_table(&sg, 1);
64483+
64484+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
64485+ if (IS_ERR(tfm)) {
64486+ /* should never happen, since sha256 should be built in */
64487+ return 1;
64488+ }
64489+
64490+ desc.tfm = tfm;
64491+ desc.flags = 0;
64492+
64493+ crypto_hash_init(&desc);
64494+
64495+ p = salt;
64496+ sg_set_buf(&sg, p, GR_SALT_LEN);
64497+ crypto_hash_update(&desc, &sg, sg.length);
64498+
64499+ p = entry->pw;
64500+ sg_set_buf(&sg, p, strlen(p));
64501+
64502+ crypto_hash_update(&desc, &sg, sg.length);
64503+
64504+ crypto_hash_final(&desc, temp_sum);
64505+
64506+ memset(entry->pw, 0, GR_PW_LEN);
64507+
64508+ for (i = 0; i < GR_SHA_LEN; i++)
64509+ if (sum[i] != temp_sum[i])
64510+ retval = 1;
64511+ else
64512+ dummy = 1; // waste a cycle
64513+
64514+ crypto_free_hash(tfm);
64515+
64516+ return retval;
64517+}
64518diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
64519index 3cd9ccd..fe16d47 100644
64520--- a/include/acpi/acpi_bus.h
64521+++ b/include/acpi/acpi_bus.h
64522@@ -107,7 +107,7 @@ struct acpi_device_ops {
64523 acpi_op_bind bind;
64524 acpi_op_unbind unbind;
64525 acpi_op_notify notify;
64526-};
64527+} __no_const;
64528
64529 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
64530
64531diff --git a/include/acpi/acpi_drivers.h b/include/acpi/acpi_drivers.h
64532index f4906f6..71feb73 100644
64533--- a/include/acpi/acpi_drivers.h
64534+++ b/include/acpi/acpi_drivers.h
64535@@ -119,8 +119,8 @@ int acpi_processor_set_thermal_limit(acpi_handle handle, int type);
64536 Dock Station
64537 -------------------------------------------------------------------------- */
64538 struct acpi_dock_ops {
64539- acpi_notify_handler handler;
64540- acpi_notify_handler uevent;
64541+ const acpi_notify_handler handler;
64542+ const acpi_notify_handler uevent;
64543 };
64544
64545 #if defined(CONFIG_ACPI_DOCK) || defined(CONFIG_ACPI_DOCK_MODULE)
64546@@ -128,7 +128,7 @@ extern int is_dock_device(acpi_handle handle);
64547 extern int register_dock_notifier(struct notifier_block *nb);
64548 extern void unregister_dock_notifier(struct notifier_block *nb);
64549 extern int register_hotplug_dock_device(acpi_handle handle,
64550- struct acpi_dock_ops *ops,
64551+ const struct acpi_dock_ops *ops,
64552 void *context);
64553 extern void unregister_hotplug_dock_device(acpi_handle handle);
64554 #else
64555@@ -144,7 +144,7 @@ static inline void unregister_dock_notifier(struct notifier_block *nb)
64556 {
64557 }
64558 static inline int register_hotplug_dock_device(acpi_handle handle,
64559- struct acpi_dock_ops *ops,
64560+ const struct acpi_dock_ops *ops,
64561 void *context)
64562 {
64563 return -ENODEV;
64564diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
64565index b7babf0..a9ac9fc 100644
64566--- a/include/asm-generic/atomic-long.h
64567+++ b/include/asm-generic/atomic-long.h
64568@@ -22,6 +22,12 @@
64569
64570 typedef atomic64_t atomic_long_t;
64571
64572+#ifdef CONFIG_PAX_REFCOUNT
64573+typedef atomic64_unchecked_t atomic_long_unchecked_t;
64574+#else
64575+typedef atomic64_t atomic_long_unchecked_t;
64576+#endif
64577+
64578 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
64579
64580 static inline long atomic_long_read(atomic_long_t *l)
64581@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
64582 return (long)atomic64_read(v);
64583 }
64584
64585+#ifdef CONFIG_PAX_REFCOUNT
64586+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
64587+{
64588+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64589+
64590+ return (long)atomic64_read_unchecked(v);
64591+}
64592+#endif
64593+
64594 static inline void atomic_long_set(atomic_long_t *l, long i)
64595 {
64596 atomic64_t *v = (atomic64_t *)l;
64597@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
64598 atomic64_set(v, i);
64599 }
64600
64601+#ifdef CONFIG_PAX_REFCOUNT
64602+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
64603+{
64604+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64605+
64606+ atomic64_set_unchecked(v, i);
64607+}
64608+#endif
64609+
64610 static inline void atomic_long_inc(atomic_long_t *l)
64611 {
64612 atomic64_t *v = (atomic64_t *)l;
64613@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
64614 atomic64_inc(v);
64615 }
64616
64617+#ifdef CONFIG_PAX_REFCOUNT
64618+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
64619+{
64620+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64621+
64622+ atomic64_inc_unchecked(v);
64623+}
64624+#endif
64625+
64626 static inline void atomic_long_dec(atomic_long_t *l)
64627 {
64628 atomic64_t *v = (atomic64_t *)l;
64629@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
64630 atomic64_dec(v);
64631 }
64632
64633+#ifdef CONFIG_PAX_REFCOUNT
64634+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
64635+{
64636+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64637+
64638+ atomic64_dec_unchecked(v);
64639+}
64640+#endif
64641+
64642 static inline void atomic_long_add(long i, atomic_long_t *l)
64643 {
64644 atomic64_t *v = (atomic64_t *)l;
64645@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
64646 atomic64_add(i, v);
64647 }
64648
64649+#ifdef CONFIG_PAX_REFCOUNT
64650+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
64651+{
64652+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64653+
64654+ atomic64_add_unchecked(i, v);
64655+}
64656+#endif
64657+
64658 static inline void atomic_long_sub(long i, atomic_long_t *l)
64659 {
64660 atomic64_t *v = (atomic64_t *)l;
64661@@ -115,6 +166,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
64662 return (long)atomic64_inc_return(v);
64663 }
64664
64665+#ifdef CONFIG_PAX_REFCOUNT
64666+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
64667+{
64668+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
64669+
64670+ return (long)atomic64_inc_return_unchecked(v);
64671+}
64672+#endif
64673+
64674 static inline long atomic_long_dec_return(atomic_long_t *l)
64675 {
64676 atomic64_t *v = (atomic64_t *)l;
64677@@ -140,6 +200,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
64678
64679 typedef atomic_t atomic_long_t;
64680
64681+#ifdef CONFIG_PAX_REFCOUNT
64682+typedef atomic_unchecked_t atomic_long_unchecked_t;
64683+#else
64684+typedef atomic_t atomic_long_unchecked_t;
64685+#endif
64686+
64687 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
64688 static inline long atomic_long_read(atomic_long_t *l)
64689 {
64690@@ -148,6 +214,15 @@ static inline long atomic_long_read(atomic_long_t *l)
64691 return (long)atomic_read(v);
64692 }
64693
64694+#ifdef CONFIG_PAX_REFCOUNT
64695+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
64696+{
64697+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64698+
64699+ return (long)atomic_read_unchecked(v);
64700+}
64701+#endif
64702+
64703 static inline void atomic_long_set(atomic_long_t *l, long i)
64704 {
64705 atomic_t *v = (atomic_t *)l;
64706@@ -155,6 +230,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
64707 atomic_set(v, i);
64708 }
64709
64710+#ifdef CONFIG_PAX_REFCOUNT
64711+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
64712+{
64713+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64714+
64715+ atomic_set_unchecked(v, i);
64716+}
64717+#endif
64718+
64719 static inline void atomic_long_inc(atomic_long_t *l)
64720 {
64721 atomic_t *v = (atomic_t *)l;
64722@@ -162,6 +246,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
64723 atomic_inc(v);
64724 }
64725
64726+#ifdef CONFIG_PAX_REFCOUNT
64727+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
64728+{
64729+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64730+
64731+ atomic_inc_unchecked(v);
64732+}
64733+#endif
64734+
64735 static inline void atomic_long_dec(atomic_long_t *l)
64736 {
64737 atomic_t *v = (atomic_t *)l;
64738@@ -169,6 +262,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
64739 atomic_dec(v);
64740 }
64741
64742+#ifdef CONFIG_PAX_REFCOUNT
64743+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
64744+{
64745+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64746+
64747+ atomic_dec_unchecked(v);
64748+}
64749+#endif
64750+
64751 static inline void atomic_long_add(long i, atomic_long_t *l)
64752 {
64753 atomic_t *v = (atomic_t *)l;
64754@@ -176,6 +278,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
64755 atomic_add(i, v);
64756 }
64757
64758+#ifdef CONFIG_PAX_REFCOUNT
64759+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
64760+{
64761+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64762+
64763+ atomic_add_unchecked(i, v);
64764+}
64765+#endif
64766+
64767 static inline void atomic_long_sub(long i, atomic_long_t *l)
64768 {
64769 atomic_t *v = (atomic_t *)l;
64770@@ -232,6 +343,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
64771 return (long)atomic_inc_return(v);
64772 }
64773
64774+#ifdef CONFIG_PAX_REFCOUNT
64775+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
64776+{
64777+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
64778+
64779+ return (long)atomic_inc_return_unchecked(v);
64780+}
64781+#endif
64782+
64783 static inline long atomic_long_dec_return(atomic_long_t *l)
64784 {
64785 atomic_t *v = (atomic_t *)l;
64786@@ -255,4 +375,47 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
64787
64788 #endif /* BITS_PER_LONG == 64 */
64789
64790+#ifdef CONFIG_PAX_REFCOUNT
64791+static inline void pax_refcount_needs_these_functions(void)
64792+{
64793+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
64794+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
64795+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
64796+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
64797+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
64798+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
64799+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
64800+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
64801+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
64802+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
64803+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
64804+
64805+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
64806+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
64807+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
64808+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
64809+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
64810+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
64811+}
64812+#else
64813+#define atomic_read_unchecked(v) atomic_read(v)
64814+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
64815+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
64816+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
64817+#define atomic_inc_unchecked(v) atomic_inc(v)
64818+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
64819+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
64820+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
64821+#define atomic_dec_unchecked(v) atomic_dec(v)
64822+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
64823+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
64824+
64825+#define atomic_long_read_unchecked(v) atomic_long_read(v)
64826+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
64827+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
64828+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
64829+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
64830+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
64831+#endif
64832+
64833 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
64834diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
64835index b18ce4f..2ee2843 100644
64836--- a/include/asm-generic/atomic64.h
64837+++ b/include/asm-generic/atomic64.h
64838@@ -16,6 +16,8 @@ typedef struct {
64839 long long counter;
64840 } atomic64_t;
64841
64842+typedef atomic64_t atomic64_unchecked_t;
64843+
64844 #define ATOMIC64_INIT(i) { (i) }
64845
64846 extern long long atomic64_read(const atomic64_t *v);
64847@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
64848 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
64849 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
64850
64851+#define atomic64_read_unchecked(v) atomic64_read(v)
64852+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
64853+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
64854+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
64855+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
64856+#define atomic64_inc_unchecked(v) atomic64_inc(v)
64857+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
64858+#define atomic64_dec_unchecked(v) atomic64_dec(v)
64859+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
64860+
64861 #endif /* _ASM_GENERIC_ATOMIC64_H */
64862diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
64863index d48ddf0..656a0ac 100644
64864--- a/include/asm-generic/bug.h
64865+++ b/include/asm-generic/bug.h
64866@@ -105,11 +105,11 @@ extern void warn_slowpath_null(const char *file, const int line);
64867
64868 #else /* !CONFIG_BUG */
64869 #ifndef HAVE_ARCH_BUG
64870-#define BUG() do {} while(0)
64871+#define BUG() do { for (;;) ; } while(0)
64872 #endif
64873
64874 #ifndef HAVE_ARCH_BUG_ON
64875-#define BUG_ON(condition) do { if (condition) ; } while(0)
64876+#define BUG_ON(condition) do { if (condition) for (;;) ; } while(0)
64877 #endif
64878
64879 #ifndef HAVE_ARCH_WARN_ON
64880diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
64881index 1bfcfe5..e04c5c9 100644
64882--- a/include/asm-generic/cache.h
64883+++ b/include/asm-generic/cache.h
64884@@ -6,7 +6,7 @@
64885 * cache lines need to provide their own cache.h.
64886 */
64887
64888-#define L1_CACHE_SHIFT 5
64889-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
64890+#define L1_CACHE_SHIFT 5UL
64891+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
64892
64893 #endif /* __ASM_GENERIC_CACHE_H */
64894diff --git a/include/asm-generic/dma-mapping-common.h b/include/asm-generic/dma-mapping-common.h
64895index 6920695..41038bc 100644
64896--- a/include/asm-generic/dma-mapping-common.h
64897+++ b/include/asm-generic/dma-mapping-common.h
64898@@ -11,7 +11,7 @@ static inline dma_addr_t dma_map_single_attrs(struct device *dev, void *ptr,
64899 enum dma_data_direction dir,
64900 struct dma_attrs *attrs)
64901 {
64902- struct dma_map_ops *ops = get_dma_ops(dev);
64903+ const struct dma_map_ops *ops = get_dma_ops(dev);
64904 dma_addr_t addr;
64905
64906 kmemcheck_mark_initialized(ptr, size);
64907@@ -30,7 +30,7 @@ static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t addr,
64908 enum dma_data_direction dir,
64909 struct dma_attrs *attrs)
64910 {
64911- struct dma_map_ops *ops = get_dma_ops(dev);
64912+ const struct dma_map_ops *ops = get_dma_ops(dev);
64913
64914 BUG_ON(!valid_dma_direction(dir));
64915 if (ops->unmap_page)
64916@@ -42,7 +42,7 @@ static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sg,
64917 int nents, enum dma_data_direction dir,
64918 struct dma_attrs *attrs)
64919 {
64920- struct dma_map_ops *ops = get_dma_ops(dev);
64921+ const struct dma_map_ops *ops = get_dma_ops(dev);
64922 int i, ents;
64923 struct scatterlist *s;
64924
64925@@ -59,7 +59,7 @@ static inline void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg
64926 int nents, enum dma_data_direction dir,
64927 struct dma_attrs *attrs)
64928 {
64929- struct dma_map_ops *ops = get_dma_ops(dev);
64930+ const struct dma_map_ops *ops = get_dma_ops(dev);
64931
64932 BUG_ON(!valid_dma_direction(dir));
64933 debug_dma_unmap_sg(dev, sg, nents, dir);
64934@@ -71,7 +71,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
64935 size_t offset, size_t size,
64936 enum dma_data_direction dir)
64937 {
64938- struct dma_map_ops *ops = get_dma_ops(dev);
64939+ const struct dma_map_ops *ops = get_dma_ops(dev);
64940 dma_addr_t addr;
64941
64942 kmemcheck_mark_initialized(page_address(page) + offset, size);
64943@@ -85,7 +85,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
64944 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
64945 size_t size, enum dma_data_direction dir)
64946 {
64947- struct dma_map_ops *ops = get_dma_ops(dev);
64948+ const struct dma_map_ops *ops = get_dma_ops(dev);
64949
64950 BUG_ON(!valid_dma_direction(dir));
64951 if (ops->unmap_page)
64952@@ -97,7 +97,7 @@ static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
64953 size_t size,
64954 enum dma_data_direction dir)
64955 {
64956- struct dma_map_ops *ops = get_dma_ops(dev);
64957+ const struct dma_map_ops *ops = get_dma_ops(dev);
64958
64959 BUG_ON(!valid_dma_direction(dir));
64960 if (ops->sync_single_for_cpu)
64961@@ -109,7 +109,7 @@ static inline void dma_sync_single_for_device(struct device *dev,
64962 dma_addr_t addr, size_t size,
64963 enum dma_data_direction dir)
64964 {
64965- struct dma_map_ops *ops = get_dma_ops(dev);
64966+ const struct dma_map_ops *ops = get_dma_ops(dev);
64967
64968 BUG_ON(!valid_dma_direction(dir));
64969 if (ops->sync_single_for_device)
64970@@ -123,7 +123,7 @@ static inline void dma_sync_single_range_for_cpu(struct device *dev,
64971 size_t size,
64972 enum dma_data_direction dir)
64973 {
64974- struct dma_map_ops *ops = get_dma_ops(dev);
64975+ const struct dma_map_ops *ops = get_dma_ops(dev);
64976
64977 BUG_ON(!valid_dma_direction(dir));
64978 if (ops->sync_single_range_for_cpu) {
64979@@ -140,7 +140,7 @@ static inline void dma_sync_single_range_for_device(struct device *dev,
64980 size_t size,
64981 enum dma_data_direction dir)
64982 {
64983- struct dma_map_ops *ops = get_dma_ops(dev);
64984+ const struct dma_map_ops *ops = get_dma_ops(dev);
64985
64986 BUG_ON(!valid_dma_direction(dir));
64987 if (ops->sync_single_range_for_device) {
64988@@ -155,7 +155,7 @@ static inline void
64989 dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
64990 int nelems, enum dma_data_direction dir)
64991 {
64992- struct dma_map_ops *ops = get_dma_ops(dev);
64993+ const struct dma_map_ops *ops = get_dma_ops(dev);
64994
64995 BUG_ON(!valid_dma_direction(dir));
64996 if (ops->sync_sg_for_cpu)
64997@@ -167,7 +167,7 @@ static inline void
64998 dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
64999 int nelems, enum dma_data_direction dir)
65000 {
65001- struct dma_map_ops *ops = get_dma_ops(dev);
65002+ const struct dma_map_ops *ops = get_dma_ops(dev);
65003
65004 BUG_ON(!valid_dma_direction(dir));
65005 if (ops->sync_sg_for_device)
65006diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
65007index 0d68a1e..b74a761 100644
65008--- a/include/asm-generic/emergency-restart.h
65009+++ b/include/asm-generic/emergency-restart.h
65010@@ -1,7 +1,7 @@
65011 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
65012 #define _ASM_GENERIC_EMERGENCY_RESTART_H
65013
65014-static inline void machine_emergency_restart(void)
65015+static inline __noreturn void machine_emergency_restart(void)
65016 {
65017 machine_restart(NULL);
65018 }
65019diff --git a/include/asm-generic/futex.h b/include/asm-generic/futex.h
65020index 3c2344f..4590a7d 100644
65021--- a/include/asm-generic/futex.h
65022+++ b/include/asm-generic/futex.h
65023@@ -6,7 +6,7 @@
65024 #include <asm/errno.h>
65025
65026 static inline int
65027-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
65028+futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
65029 {
65030 int op = (encoded_op >> 28) & 7;
65031 int cmp = (encoded_op >> 24) & 15;
65032@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
65033 }
65034
65035 static inline int
65036-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
65037+futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
65038 {
65039 return -ENOSYS;
65040 }
65041diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
65042index 1ca3efc..e3dc852 100644
65043--- a/include/asm-generic/int-l64.h
65044+++ b/include/asm-generic/int-l64.h
65045@@ -46,6 +46,8 @@ typedef unsigned int u32;
65046 typedef signed long s64;
65047 typedef unsigned long u64;
65048
65049+typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
65050+
65051 #define S8_C(x) x
65052 #define U8_C(x) x ## U
65053 #define S16_C(x) x
65054diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
65055index f394147..b6152b9 100644
65056--- a/include/asm-generic/int-ll64.h
65057+++ b/include/asm-generic/int-ll64.h
65058@@ -51,6 +51,8 @@ typedef unsigned int u32;
65059 typedef signed long long s64;
65060 typedef unsigned long long u64;
65061
65062+typedef unsigned long long intoverflow_t;
65063+
65064 #define S8_C(x) x
65065 #define U8_C(x) x ## U
65066 #define S16_C(x) x
65067diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
65068index e5f234a..cdb16b3 100644
65069--- a/include/asm-generic/kmap_types.h
65070+++ b/include/asm-generic/kmap_types.h
65071@@ -28,7 +28,8 @@ KMAP_D(15) KM_UML_USERCOPY,
65072 KMAP_D(16) KM_IRQ_PTE,
65073 KMAP_D(17) KM_NMI,
65074 KMAP_D(18) KM_NMI_PTE,
65075-KMAP_D(19) KM_TYPE_NR
65076+KMAP_D(19) KM_CLEARPAGE,
65077+KMAP_D(20) KM_TYPE_NR
65078 };
65079
65080 #undef KMAP_D
65081diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
65082index 725612b..9cc513a 100644
65083--- a/include/asm-generic/pgtable-nopmd.h
65084+++ b/include/asm-generic/pgtable-nopmd.h
65085@@ -1,14 +1,19 @@
65086 #ifndef _PGTABLE_NOPMD_H
65087 #define _PGTABLE_NOPMD_H
65088
65089-#ifndef __ASSEMBLY__
65090-
65091 #include <asm-generic/pgtable-nopud.h>
65092
65093-struct mm_struct;
65094-
65095 #define __PAGETABLE_PMD_FOLDED
65096
65097+#define PMD_SHIFT PUD_SHIFT
65098+#define PTRS_PER_PMD 1
65099+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
65100+#define PMD_MASK (~(PMD_SIZE-1))
65101+
65102+#ifndef __ASSEMBLY__
65103+
65104+struct mm_struct;
65105+
65106 /*
65107 * Having the pmd type consist of a pud gets the size right, and allows
65108 * us to conceptually access the pud entry that this pmd is folded into
65109@@ -16,11 +21,6 @@ struct mm_struct;
65110 */
65111 typedef struct { pud_t pud; } pmd_t;
65112
65113-#define PMD_SHIFT PUD_SHIFT
65114-#define PTRS_PER_PMD 1
65115-#define PMD_SIZE (1UL << PMD_SHIFT)
65116-#define PMD_MASK (~(PMD_SIZE-1))
65117-
65118 /*
65119 * The "pud_xxx()" functions here are trivial for a folded two-level
65120 * setup: the pmd is never bad, and a pmd always exists (as it's folded
65121diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
65122index 810431d..ccc3638 100644
65123--- a/include/asm-generic/pgtable-nopud.h
65124+++ b/include/asm-generic/pgtable-nopud.h
65125@@ -1,10 +1,15 @@
65126 #ifndef _PGTABLE_NOPUD_H
65127 #define _PGTABLE_NOPUD_H
65128
65129-#ifndef __ASSEMBLY__
65130-
65131 #define __PAGETABLE_PUD_FOLDED
65132
65133+#define PUD_SHIFT PGDIR_SHIFT
65134+#define PTRS_PER_PUD 1
65135+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
65136+#define PUD_MASK (~(PUD_SIZE-1))
65137+
65138+#ifndef __ASSEMBLY__
65139+
65140 /*
65141 * Having the pud type consist of a pgd gets the size right, and allows
65142 * us to conceptually access the pgd entry that this pud is folded into
65143@@ -12,11 +17,6 @@
65144 */
65145 typedef struct { pgd_t pgd; } pud_t;
65146
65147-#define PUD_SHIFT PGDIR_SHIFT
65148-#define PTRS_PER_PUD 1
65149-#define PUD_SIZE (1UL << PUD_SHIFT)
65150-#define PUD_MASK (~(PUD_SIZE-1))
65151-
65152 /*
65153 * The "pgd_xxx()" functions here are trivial for a folded two-level
65154 * setup: the pud is never bad, and a pud always exists (as it's folded
65155diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
65156index e2bd73e..fea8ed3 100644
65157--- a/include/asm-generic/pgtable.h
65158+++ b/include/asm-generic/pgtable.h
65159@@ -344,6 +344,14 @@ extern void untrack_pfn_vma(struct vm_area_struct *vma, unsigned long pfn,
65160 unsigned long size);
65161 #endif
65162
65163+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
65164+static inline unsigned long pax_open_kernel(void) { return 0; }
65165+#endif
65166+
65167+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
65168+static inline unsigned long pax_close_kernel(void) { return 0; }
65169+#endif
65170+
65171 #endif /* !__ASSEMBLY__ */
65172
65173 #endif /* _ASM_GENERIC_PGTABLE_H */
65174diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
65175index b6e818f..21aa58a 100644
65176--- a/include/asm-generic/vmlinux.lds.h
65177+++ b/include/asm-generic/vmlinux.lds.h
65178@@ -199,6 +199,7 @@
65179 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
65180 VMLINUX_SYMBOL(__start_rodata) = .; \
65181 *(.rodata) *(.rodata.*) \
65182+ *(.data.read_only) \
65183 *(__vermagic) /* Kernel version magic */ \
65184 *(__markers_strings) /* Markers: strings */ \
65185 *(__tracepoints_strings)/* Tracepoints: strings */ \
65186@@ -656,22 +657,24 @@
65187 * section in the linker script will go there too. @phdr should have
65188 * a leading colon.
65189 *
65190- * Note that this macros defines __per_cpu_load as an absolute symbol.
65191+ * Note that this macros defines per_cpu_load as an absolute symbol.
65192 * If there is no need to put the percpu section at a predetermined
65193 * address, use PERCPU().
65194 */
65195 #define PERCPU_VADDR(vaddr, phdr) \
65196- VMLINUX_SYMBOL(__per_cpu_load) = .; \
65197- .data.percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
65198+ per_cpu_load = .; \
65199+ .data.percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
65200 - LOAD_OFFSET) { \
65201+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
65202 VMLINUX_SYMBOL(__per_cpu_start) = .; \
65203 *(.data.percpu.first) \
65204- *(.data.percpu.page_aligned) \
65205 *(.data.percpu) \
65206+ . = ALIGN(PAGE_SIZE); \
65207+ *(.data.percpu.page_aligned) \
65208 *(.data.percpu.shared_aligned) \
65209 VMLINUX_SYMBOL(__per_cpu_end) = .; \
65210 } phdr \
65211- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data.percpu);
65212+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data.percpu);
65213
65214 /**
65215 * PERCPU - define output section for percpu area, simple version
65216diff --git a/include/drm/drmP.h b/include/drm/drmP.h
65217index 66713c6..98c0460 100644
65218--- a/include/drm/drmP.h
65219+++ b/include/drm/drmP.h
65220@@ -71,6 +71,7 @@
65221 #include <linux/workqueue.h>
65222 #include <linux/poll.h>
65223 #include <asm/pgalloc.h>
65224+#include <asm/local.h>
65225 #include "drm.h"
65226
65227 #include <linux/idr.h>
65228@@ -814,7 +815,7 @@ struct drm_driver {
65229 void (*vgaarb_irq)(struct drm_device *dev, bool state);
65230
65231 /* Driver private ops for this object */
65232- struct vm_operations_struct *gem_vm_ops;
65233+ const struct vm_operations_struct *gem_vm_ops;
65234
65235 int major;
65236 int minor;
65237@@ -917,7 +918,7 @@ struct drm_device {
65238
65239 /** \name Usage Counters */
65240 /*@{ */
65241- int open_count; /**< Outstanding files open */
65242+ local_t open_count; /**< Outstanding files open */
65243 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
65244 atomic_t vma_count; /**< Outstanding vma areas open */
65245 int buf_use; /**< Buffers in use -- cannot alloc */
65246@@ -928,7 +929,7 @@ struct drm_device {
65247 /*@{ */
65248 unsigned long counters;
65249 enum drm_stat_type types[15];
65250- atomic_t counts[15];
65251+ atomic_unchecked_t counts[15];
65252 /*@} */
65253
65254 struct list_head filelist;
65255@@ -1016,7 +1017,7 @@ struct drm_device {
65256 struct pci_controller *hose;
65257 #endif
65258 struct drm_sg_mem *sg; /**< Scatter gather memory */
65259- unsigned int num_crtcs; /**< Number of CRTCs on this device */
65260+ unsigned int num_crtcs; /**< Number of CRTCs on this device */
65261 void *dev_private; /**< device private data */
65262 void *mm_private;
65263 struct address_space *dev_mapping;
65264@@ -1042,11 +1043,11 @@ struct drm_device {
65265 spinlock_t object_name_lock;
65266 struct idr object_name_idr;
65267 atomic_t object_count;
65268- atomic_t object_memory;
65269+ atomic_unchecked_t object_memory;
65270 atomic_t pin_count;
65271- atomic_t pin_memory;
65272+ atomic_unchecked_t pin_memory;
65273 atomic_t gtt_count;
65274- atomic_t gtt_memory;
65275+ atomic_unchecked_t gtt_memory;
65276 uint32_t gtt_total;
65277 uint32_t invalidate_domains; /* domains pending invalidation */
65278 uint32_t flush_domains; /* domains pending flush */
65279diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
65280index b29e201..3413cc9 100644
65281--- a/include/drm/drm_crtc_helper.h
65282+++ b/include/drm/drm_crtc_helper.h
65283@@ -64,7 +64,7 @@ struct drm_crtc_helper_funcs {
65284
65285 /* reload the current crtc LUT */
65286 void (*load_lut)(struct drm_crtc *crtc);
65287-};
65288+} __no_const;
65289
65290 struct drm_encoder_helper_funcs {
65291 void (*dpms)(struct drm_encoder *encoder, int mode);
65292@@ -85,7 +85,7 @@ struct drm_encoder_helper_funcs {
65293 struct drm_connector *connector);
65294 /* disable encoder when not in use - more explicit than dpms off */
65295 void (*disable)(struct drm_encoder *encoder);
65296-};
65297+} __no_const;
65298
65299 struct drm_connector_helper_funcs {
65300 int (*get_modes)(struct drm_connector *connector);
65301diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
65302index b199170..6f9e64c 100644
65303--- a/include/drm/ttm/ttm_memory.h
65304+++ b/include/drm/ttm/ttm_memory.h
65305@@ -47,7 +47,7 @@
65306
65307 struct ttm_mem_shrink {
65308 int (*do_shrink) (struct ttm_mem_shrink *);
65309-};
65310+} __no_const;
65311
65312 /**
65313 * struct ttm_mem_global - Global memory accounting structure.
65314diff --git a/include/linux/a.out.h b/include/linux/a.out.h
65315index e86dfca..40cc55f 100644
65316--- a/include/linux/a.out.h
65317+++ b/include/linux/a.out.h
65318@@ -39,6 +39,14 @@ enum machine_type {
65319 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
65320 };
65321
65322+/* Constants for the N_FLAGS field */
65323+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65324+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
65325+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
65326+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
65327+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65328+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65329+
65330 #if !defined (N_MAGIC)
65331 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
65332 #endif
65333diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
65334index 817b237..62c10bc 100644
65335--- a/include/linux/atmdev.h
65336+++ b/include/linux/atmdev.h
65337@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
65338 #endif
65339
65340 struct k_atm_aal_stats {
65341-#define __HANDLE_ITEM(i) atomic_t i
65342+#define __HANDLE_ITEM(i) atomic_unchecked_t i
65343 __AAL_STAT_ITEMS
65344 #undef __HANDLE_ITEM
65345 };
65346diff --git a/include/linux/backlight.h b/include/linux/backlight.h
65347index 0f5f578..8c4f884 100644
65348--- a/include/linux/backlight.h
65349+++ b/include/linux/backlight.h
65350@@ -36,18 +36,18 @@ struct backlight_device;
65351 struct fb_info;
65352
65353 struct backlight_ops {
65354- unsigned int options;
65355+ const unsigned int options;
65356
65357 #define BL_CORE_SUSPENDRESUME (1 << 0)
65358
65359 /* Notify the backlight driver some property has changed */
65360- int (*update_status)(struct backlight_device *);
65361+ int (* const update_status)(struct backlight_device *);
65362 /* Return the current backlight brightness (accounting for power,
65363 fb_blank etc.) */
65364- int (*get_brightness)(struct backlight_device *);
65365+ int (* const get_brightness)(struct backlight_device *);
65366 /* Check if given framebuffer device is the one bound to this backlight;
65367 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
65368- int (*check_fb)(struct fb_info *);
65369+ int (* const check_fb)(struct fb_info *);
65370 };
65371
65372 /* This structure defines all the properties of a backlight */
65373@@ -86,7 +86,7 @@ struct backlight_device {
65374 registered this device has been unloaded, and if class_get_devdata()
65375 points to something in the body of that driver, it is also invalid. */
65376 struct mutex ops_lock;
65377- struct backlight_ops *ops;
65378+ const struct backlight_ops *ops;
65379
65380 /* The framebuffer notifier block */
65381 struct notifier_block fb_notif;
65382@@ -103,7 +103,7 @@ static inline void backlight_update_status(struct backlight_device *bd)
65383 }
65384
65385 extern struct backlight_device *backlight_device_register(const char *name,
65386- struct device *dev, void *devdata, struct backlight_ops *ops);
65387+ struct device *dev, void *devdata, const struct backlight_ops *ops);
65388 extern void backlight_device_unregister(struct backlight_device *bd);
65389 extern void backlight_force_update(struct backlight_device *bd,
65390 enum backlight_update_reason reason);
65391diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
65392index a3d802e..482f69c 100644
65393--- a/include/linux/binfmts.h
65394+++ b/include/linux/binfmts.h
65395@@ -83,6 +83,7 @@ struct linux_binfmt {
65396 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
65397 int (*load_shlib)(struct file *);
65398 int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
65399+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
65400 unsigned long min_coredump; /* minimal dump size */
65401 int hasvdso;
65402 };
65403diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
65404index a06bfab..4fa38bb 100644
65405--- a/include/linux/blkdev.h
65406+++ b/include/linux/blkdev.h
65407@@ -1278,7 +1278,7 @@ struct block_device_operations {
65408 int (*revalidate_disk) (struct gendisk *);
65409 int (*getgeo)(struct block_device *, struct hd_geometry *);
65410 struct module *owner;
65411-};
65412+} __do_const;
65413
65414 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
65415 unsigned long);
65416diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
65417index 3b73b99..629d21b 100644
65418--- a/include/linux/blktrace_api.h
65419+++ b/include/linux/blktrace_api.h
65420@@ -160,7 +160,7 @@ struct blk_trace {
65421 struct dentry *dir;
65422 struct dentry *dropped_file;
65423 struct dentry *msg_file;
65424- atomic_t dropped;
65425+ atomic_unchecked_t dropped;
65426 };
65427
65428 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
65429diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
65430index 83195fb..0b0f77d 100644
65431--- a/include/linux/byteorder/little_endian.h
65432+++ b/include/linux/byteorder/little_endian.h
65433@@ -42,51 +42,51 @@
65434
65435 static inline __le64 __cpu_to_le64p(const __u64 *p)
65436 {
65437- return (__force __le64)*p;
65438+ return (__force const __le64)*p;
65439 }
65440 static inline __u64 __le64_to_cpup(const __le64 *p)
65441 {
65442- return (__force __u64)*p;
65443+ return (__force const __u64)*p;
65444 }
65445 static inline __le32 __cpu_to_le32p(const __u32 *p)
65446 {
65447- return (__force __le32)*p;
65448+ return (__force const __le32)*p;
65449 }
65450 static inline __u32 __le32_to_cpup(const __le32 *p)
65451 {
65452- return (__force __u32)*p;
65453+ return (__force const __u32)*p;
65454 }
65455 static inline __le16 __cpu_to_le16p(const __u16 *p)
65456 {
65457- return (__force __le16)*p;
65458+ return (__force const __le16)*p;
65459 }
65460 static inline __u16 __le16_to_cpup(const __le16 *p)
65461 {
65462- return (__force __u16)*p;
65463+ return (__force const __u16)*p;
65464 }
65465 static inline __be64 __cpu_to_be64p(const __u64 *p)
65466 {
65467- return (__force __be64)__swab64p(p);
65468+ return (__force const __be64)__swab64p(p);
65469 }
65470 static inline __u64 __be64_to_cpup(const __be64 *p)
65471 {
65472- return __swab64p((__u64 *)p);
65473+ return __swab64p((const __u64 *)p);
65474 }
65475 static inline __be32 __cpu_to_be32p(const __u32 *p)
65476 {
65477- return (__force __be32)__swab32p(p);
65478+ return (__force const __be32)__swab32p(p);
65479 }
65480 static inline __u32 __be32_to_cpup(const __be32 *p)
65481 {
65482- return __swab32p((__u32 *)p);
65483+ return __swab32p((const __u32 *)p);
65484 }
65485 static inline __be16 __cpu_to_be16p(const __u16 *p)
65486 {
65487- return (__force __be16)__swab16p(p);
65488+ return (__force const __be16)__swab16p(p);
65489 }
65490 static inline __u16 __be16_to_cpup(const __be16 *p)
65491 {
65492- return __swab16p((__u16 *)p);
65493+ return __swab16p((const __u16 *)p);
65494 }
65495 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
65496 #define __le64_to_cpus(x) do { (void)(x); } while (0)
65497diff --git a/include/linux/cache.h b/include/linux/cache.h
65498index 97e2488..e7576b9 100644
65499--- a/include/linux/cache.h
65500+++ b/include/linux/cache.h
65501@@ -16,6 +16,10 @@
65502 #define __read_mostly
65503 #endif
65504
65505+#ifndef __read_only
65506+#define __read_only __read_mostly
65507+#endif
65508+
65509 #ifndef ____cacheline_aligned
65510 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
65511 #endif
65512diff --git a/include/linux/capability.h b/include/linux/capability.h
65513index c8f2a5f7..1618a5c 100644
65514--- a/include/linux/capability.h
65515+++ b/include/linux/capability.h
65516@@ -563,6 +563,7 @@ extern const kernel_cap_t __cap_init_eff_set;
65517 (security_real_capable_noaudit((t), (cap)) == 0)
65518
65519 extern int capable(int cap);
65520+int capable_nolog(int cap);
65521
65522 /* audit system wants to get cap info from files as well */
65523 struct dentry;
65524diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
65525index 450fa59..86019fb 100644
65526--- a/include/linux/compiler-gcc4.h
65527+++ b/include/linux/compiler-gcc4.h
65528@@ -36,4 +36,16 @@
65529 the kernel context */
65530 #define __cold __attribute__((__cold__))
65531
65532+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
65533+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
65534+#define __bos0(ptr) __bos((ptr), 0)
65535+#define __bos1(ptr) __bos((ptr), 1)
65536+
65537+#if __GNUC_MINOR__ >= 5
65538+#ifdef CONSTIFY_PLUGIN
65539+#define __no_const __attribute__((no_const))
65540+#define __do_const __attribute__((do_const))
65541+#endif
65542+#endif
65543+
65544 #endif
65545diff --git a/include/linux/compiler.h b/include/linux/compiler.h
65546index 04fb513..fd6477b 100644
65547--- a/include/linux/compiler.h
65548+++ b/include/linux/compiler.h
65549@@ -5,11 +5,14 @@
65550
65551 #ifdef __CHECKER__
65552 # define __user __attribute__((noderef, address_space(1)))
65553+# define __force_user __force __user
65554 # define __kernel /* default address space */
65555+# define __force_kernel __force __kernel
65556 # define __safe __attribute__((safe))
65557 # define __force __attribute__((force))
65558 # define __nocast __attribute__((nocast))
65559 # define __iomem __attribute__((noderef, address_space(2)))
65560+# define __force_iomem __force __iomem
65561 # define __acquires(x) __attribute__((context(x,0,1)))
65562 # define __releases(x) __attribute__((context(x,1,0)))
65563 # define __acquire(x) __context__(x,1)
65564@@ -17,13 +20,34 @@
65565 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
65566 extern void __chk_user_ptr(const volatile void __user *);
65567 extern void __chk_io_ptr(const volatile void __iomem *);
65568+#elif defined(CHECKER_PLUGIN)
65569+//# define __user
65570+//# define __force_user
65571+//# define __kernel
65572+//# define __force_kernel
65573+# define __safe
65574+# define __force
65575+# define __nocast
65576+# define __iomem
65577+# define __force_iomem
65578+# define __chk_user_ptr(x) (void)0
65579+# define __chk_io_ptr(x) (void)0
65580+# define __builtin_warning(x, y...) (1)
65581+# define __acquires(x)
65582+# define __releases(x)
65583+# define __acquire(x) (void)0
65584+# define __release(x) (void)0
65585+# define __cond_lock(x,c) (c)
65586 #else
65587 # define __user
65588+# define __force_user
65589 # define __kernel
65590+# define __force_kernel
65591 # define __safe
65592 # define __force
65593 # define __nocast
65594 # define __iomem
65595+# define __force_iomem
65596 # define __chk_user_ptr(x) (void)0
65597 # define __chk_io_ptr(x) (void)0
65598 # define __builtin_warning(x, y...) (1)
65599@@ -247,6 +271,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65600 # define __attribute_const__ /* unimplemented */
65601 #endif
65602
65603+#ifndef __no_const
65604+# define __no_const
65605+#endif
65606+
65607+#ifndef __do_const
65608+# define __do_const
65609+#endif
65610+
65611 /*
65612 * Tell gcc if a function is cold. The compiler will assume any path
65613 * directly leading to the call is unlikely.
65614@@ -256,6 +288,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65615 #define __cold
65616 #endif
65617
65618+#ifndef __alloc_size
65619+#define __alloc_size(...)
65620+#endif
65621+
65622+#ifndef __bos
65623+#define __bos(ptr, arg)
65624+#endif
65625+
65626+#ifndef __bos0
65627+#define __bos0(ptr)
65628+#endif
65629+
65630+#ifndef __bos1
65631+#define __bos1(ptr)
65632+#endif
65633+
65634 /* Simple shorthand for a section definition */
65635 #ifndef __section
65636 # define __section(S) __attribute__ ((__section__(#S)))
65637@@ -278,6 +326,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
65638 * use is to mediate communication between process-level code and irq/NMI
65639 * handlers, all running on the same CPU.
65640 */
65641-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
65642+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
65643+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
65644
65645 #endif /* __LINUX_COMPILER_H */
65646diff --git a/include/linux/crypto.h b/include/linux/crypto.h
65647index fd92988..a3164bd 100644
65648--- a/include/linux/crypto.h
65649+++ b/include/linux/crypto.h
65650@@ -394,7 +394,7 @@ struct cipher_tfm {
65651 const u8 *key, unsigned int keylen);
65652 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
65653 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
65654-};
65655+} __no_const;
65656
65657 struct hash_tfm {
65658 int (*init)(struct hash_desc *desc);
65659@@ -415,13 +415,13 @@ struct compress_tfm {
65660 int (*cot_decompress)(struct crypto_tfm *tfm,
65661 const u8 *src, unsigned int slen,
65662 u8 *dst, unsigned int *dlen);
65663-};
65664+} __no_const;
65665
65666 struct rng_tfm {
65667 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
65668 unsigned int dlen);
65669 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
65670-};
65671+} __no_const;
65672
65673 #define crt_ablkcipher crt_u.ablkcipher
65674 #define crt_aead crt_u.aead
65675diff --git a/include/linux/dcache.h b/include/linux/dcache.h
65676index 30b93b2..cd7a8db 100644
65677--- a/include/linux/dcache.h
65678+++ b/include/linux/dcache.h
65679@@ -119,6 +119,8 @@ struct dentry {
65680 unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
65681 };
65682
65683+#define DNAME_INLINE_LEN (sizeof(struct dentry)-offsetof(struct dentry,d_iname))
65684+
65685 /*
65686 * dentry->d_lock spinlock nesting subclasses:
65687 *
65688diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
65689index 3e9bd6a..f4e1aa0 100644
65690--- a/include/linux/decompress/mm.h
65691+++ b/include/linux/decompress/mm.h
65692@@ -78,7 +78,7 @@ static void free(void *where)
65693 * warnings when not needed (indeed large_malloc / large_free are not
65694 * needed by inflate */
65695
65696-#define malloc(a) kmalloc(a, GFP_KERNEL)
65697+#define malloc(a) kmalloc((a), GFP_KERNEL)
65698 #define free(a) kfree(a)
65699
65700 #define large_malloc(a) vmalloc(a)
65701diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
65702index 91b7618..92a93d32 100644
65703--- a/include/linux/dma-mapping.h
65704+++ b/include/linux/dma-mapping.h
65705@@ -16,51 +16,51 @@ enum dma_data_direction {
65706 };
65707
65708 struct dma_map_ops {
65709- void* (*alloc_coherent)(struct device *dev, size_t size,
65710+ void* (* const alloc_coherent)(struct device *dev, size_t size,
65711 dma_addr_t *dma_handle, gfp_t gfp);
65712- void (*free_coherent)(struct device *dev, size_t size,
65713+ void (* const free_coherent)(struct device *dev, size_t size,
65714 void *vaddr, dma_addr_t dma_handle);
65715- dma_addr_t (*map_page)(struct device *dev, struct page *page,
65716+ dma_addr_t (* const map_page)(struct device *dev, struct page *page,
65717 unsigned long offset, size_t size,
65718 enum dma_data_direction dir,
65719 struct dma_attrs *attrs);
65720- void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
65721+ void (* const unmap_page)(struct device *dev, dma_addr_t dma_handle,
65722 size_t size, enum dma_data_direction dir,
65723 struct dma_attrs *attrs);
65724- int (*map_sg)(struct device *dev, struct scatterlist *sg,
65725+ int (* const map_sg)(struct device *dev, struct scatterlist *sg,
65726 int nents, enum dma_data_direction dir,
65727 struct dma_attrs *attrs);
65728- void (*unmap_sg)(struct device *dev,
65729+ void (* const unmap_sg)(struct device *dev,
65730 struct scatterlist *sg, int nents,
65731 enum dma_data_direction dir,
65732 struct dma_attrs *attrs);
65733- void (*sync_single_for_cpu)(struct device *dev,
65734+ void (* const sync_single_for_cpu)(struct device *dev,
65735 dma_addr_t dma_handle, size_t size,
65736 enum dma_data_direction dir);
65737- void (*sync_single_for_device)(struct device *dev,
65738+ void (* const sync_single_for_device)(struct device *dev,
65739 dma_addr_t dma_handle, size_t size,
65740 enum dma_data_direction dir);
65741- void (*sync_single_range_for_cpu)(struct device *dev,
65742+ void (* const sync_single_range_for_cpu)(struct device *dev,
65743 dma_addr_t dma_handle,
65744 unsigned long offset,
65745 size_t size,
65746 enum dma_data_direction dir);
65747- void (*sync_single_range_for_device)(struct device *dev,
65748+ void (* const sync_single_range_for_device)(struct device *dev,
65749 dma_addr_t dma_handle,
65750 unsigned long offset,
65751 size_t size,
65752 enum dma_data_direction dir);
65753- void (*sync_sg_for_cpu)(struct device *dev,
65754+ void (* const sync_sg_for_cpu)(struct device *dev,
65755 struct scatterlist *sg, int nents,
65756 enum dma_data_direction dir);
65757- void (*sync_sg_for_device)(struct device *dev,
65758+ void (* const sync_sg_for_device)(struct device *dev,
65759 struct scatterlist *sg, int nents,
65760 enum dma_data_direction dir);
65761- int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
65762- int (*dma_supported)(struct device *dev, u64 mask);
65763+ int (* const mapping_error)(struct device *dev, dma_addr_t dma_addr);
65764+ int (* const dma_supported)(struct device *dev, u64 mask);
65765 int (*set_dma_mask)(struct device *dev, u64 mask);
65766 int is_phys;
65767-};
65768+} __do_const;
65769
65770 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
65771
65772diff --git a/include/linux/dst.h b/include/linux/dst.h
65773index e26fed8..b976d9f 100644
65774--- a/include/linux/dst.h
65775+++ b/include/linux/dst.h
65776@@ -380,7 +380,7 @@ struct dst_node
65777 struct thread_pool *pool;
65778
65779 /* Transaction IDs live here */
65780- atomic_long_t gen;
65781+ atomic_long_unchecked_t gen;
65782
65783 /*
65784 * How frequently and how many times transaction
65785diff --git a/include/linux/elf.h b/include/linux/elf.h
65786index 90a4ed0..d652617 100644
65787--- a/include/linux/elf.h
65788+++ b/include/linux/elf.h
65789@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
65790 #define PT_GNU_EH_FRAME 0x6474e550
65791
65792 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
65793+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
65794+
65795+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
65796+
65797+/* Constants for the e_flags field */
65798+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
65799+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
65800+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
65801+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
65802+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
65803+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
65804
65805 /* These constants define the different elf file types */
65806 #define ET_NONE 0
65807@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
65808 #define DT_DEBUG 21
65809 #define DT_TEXTREL 22
65810 #define DT_JMPREL 23
65811+#define DT_FLAGS 30
65812+ #define DF_TEXTREL 0x00000004
65813 #define DT_ENCODING 32
65814 #define OLD_DT_LOOS 0x60000000
65815 #define DT_LOOS 0x6000000d
65816@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
65817 #define PF_W 0x2
65818 #define PF_X 0x1
65819
65820+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
65821+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
65822+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
65823+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
65824+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
65825+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
65826+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
65827+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
65828+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
65829+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
65830+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
65831+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
65832+
65833 typedef struct elf32_phdr{
65834 Elf32_Word p_type;
65835 Elf32_Off p_offset;
65836@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
65837 #define EI_OSABI 7
65838 #define EI_PAD 8
65839
65840+#define EI_PAX 14
65841+
65842 #define ELFMAG0 0x7f /* EI_MAG */
65843 #define ELFMAG1 'E'
65844 #define ELFMAG2 'L'
65845@@ -386,6 +414,7 @@ extern Elf32_Dyn _DYNAMIC [];
65846 #define elf_phdr elf32_phdr
65847 #define elf_note elf32_note
65848 #define elf_addr_t Elf32_Off
65849+#define elf_dyn Elf32_Dyn
65850
65851 #else
65852
65853@@ -394,6 +423,7 @@ extern Elf64_Dyn _DYNAMIC [];
65854 #define elf_phdr elf64_phdr
65855 #define elf_note elf64_note
65856 #define elf_addr_t Elf64_Off
65857+#define elf_dyn Elf64_Dyn
65858
65859 #endif
65860
65861diff --git a/include/linux/fs.h b/include/linux/fs.h
65862index 1b9a47a..6fe2934 100644
65863--- a/include/linux/fs.h
65864+++ b/include/linux/fs.h
65865@@ -568,41 +568,41 @@ typedef int (*read_actor_t)(read_descriptor_t *, struct page *,
65866 unsigned long, unsigned long);
65867
65868 struct address_space_operations {
65869- int (*writepage)(struct page *page, struct writeback_control *wbc);
65870- int (*readpage)(struct file *, struct page *);
65871- void (*sync_page)(struct page *);
65872+ int (* const writepage)(struct page *page, struct writeback_control *wbc);
65873+ int (* const readpage)(struct file *, struct page *);
65874+ void (* const sync_page)(struct page *);
65875
65876 /* Write back some dirty pages from this mapping. */
65877- int (*writepages)(struct address_space *, struct writeback_control *);
65878+ int (* const writepages)(struct address_space *, struct writeback_control *);
65879
65880 /* Set a page dirty. Return true if this dirtied it */
65881- int (*set_page_dirty)(struct page *page);
65882+ int (* const set_page_dirty)(struct page *page);
65883
65884- int (*readpages)(struct file *filp, struct address_space *mapping,
65885+ int (* const readpages)(struct file *filp, struct address_space *mapping,
65886 struct list_head *pages, unsigned nr_pages);
65887
65888- int (*write_begin)(struct file *, struct address_space *mapping,
65889+ int (* const write_begin)(struct file *, struct address_space *mapping,
65890 loff_t pos, unsigned len, unsigned flags,
65891 struct page **pagep, void **fsdata);
65892- int (*write_end)(struct file *, struct address_space *mapping,
65893+ int (* const write_end)(struct file *, struct address_space *mapping,
65894 loff_t pos, unsigned len, unsigned copied,
65895 struct page *page, void *fsdata);
65896
65897 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
65898- sector_t (*bmap)(struct address_space *, sector_t);
65899- void (*invalidatepage) (struct page *, unsigned long);
65900- int (*releasepage) (struct page *, gfp_t);
65901- ssize_t (*direct_IO)(int, struct kiocb *, const struct iovec *iov,
65902+ sector_t (* const bmap)(struct address_space *, sector_t);
65903+ void (* const invalidatepage) (struct page *, unsigned long);
65904+ int (* const releasepage) (struct page *, gfp_t);
65905+ ssize_t (* const direct_IO)(int, struct kiocb *, const struct iovec *iov,
65906 loff_t offset, unsigned long nr_segs);
65907- int (*get_xip_mem)(struct address_space *, pgoff_t, int,
65908+ int (* const get_xip_mem)(struct address_space *, pgoff_t, int,
65909 void **, unsigned long *);
65910 /* migrate the contents of a page to the specified target */
65911- int (*migratepage) (struct address_space *,
65912+ int (* const migratepage) (struct address_space *,
65913 struct page *, struct page *);
65914- int (*launder_page) (struct page *);
65915- int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
65916+ int (* const launder_page) (struct page *);
65917+ int (* const is_partially_uptodate) (struct page *, read_descriptor_t *,
65918 unsigned long);
65919- int (*error_remove_page)(struct address_space *, struct page *);
65920+ int (* const error_remove_page)(struct address_space *, struct page *);
65921 };
65922
65923 /*
65924@@ -1031,19 +1031,19 @@ static inline int file_check_writeable(struct file *filp)
65925 typedef struct files_struct *fl_owner_t;
65926
65927 struct file_lock_operations {
65928- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
65929- void (*fl_release_private)(struct file_lock *);
65930+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
65931+ void (* const fl_release_private)(struct file_lock *);
65932 };
65933
65934 struct lock_manager_operations {
65935- int (*fl_compare_owner)(struct file_lock *, struct file_lock *);
65936- void (*fl_notify)(struct file_lock *); /* unblock callback */
65937- int (*fl_grant)(struct file_lock *, struct file_lock *, int);
65938- void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
65939- void (*fl_release_private)(struct file_lock *);
65940- void (*fl_break)(struct file_lock *);
65941- int (*fl_mylease)(struct file_lock *, struct file_lock *);
65942- int (*fl_change)(struct file_lock **, int);
65943+ int (* const fl_compare_owner)(struct file_lock *, struct file_lock *);
65944+ void (* const fl_notify)(struct file_lock *); /* unblock callback */
65945+ int (* const fl_grant)(struct file_lock *, struct file_lock *, int);
65946+ void (* const fl_copy_lock)(struct file_lock *, struct file_lock *);
65947+ void (* const fl_release_private)(struct file_lock *);
65948+ void (* const fl_break)(struct file_lock *);
65949+ int (* const fl_mylease)(struct file_lock *, struct file_lock *);
65950+ int (* const fl_change)(struct file_lock **, int);
65951 };
65952
65953 struct lock_manager {
65954@@ -1442,7 +1442,7 @@ struct fiemap_extent_info {
65955 unsigned int fi_flags; /* Flags as passed from user */
65956 unsigned int fi_extents_mapped; /* Number of mapped extents */
65957 unsigned int fi_extents_max; /* Size of fiemap_extent array */
65958- struct fiemap_extent *fi_extents_start; /* Start of fiemap_extent
65959+ struct fiemap_extent __user *fi_extents_start; /* Start of fiemap_extent
65960 * array */
65961 };
65962 int fiemap_fill_next_extent(struct fiemap_extent_info *info, u64 logical,
65963@@ -1512,7 +1512,8 @@ struct file_operations {
65964 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
65965 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
65966 int (*setlease)(struct file *, long, struct file_lock **);
65967-};
65968+} __do_const;
65969+typedef struct file_operations __no_const file_operations_no_const;
65970
65971 struct inode_operations {
65972 int (*create) (struct inode *,struct dentry *,int, struct nameidata *);
65973@@ -1559,30 +1560,30 @@ extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
65974 unsigned long, loff_t *);
65975
65976 struct super_operations {
65977- struct inode *(*alloc_inode)(struct super_block *sb);
65978- void (*destroy_inode)(struct inode *);
65979+ struct inode *(* const alloc_inode)(struct super_block *sb);
65980+ void (* const destroy_inode)(struct inode *);
65981
65982- void (*dirty_inode) (struct inode *);
65983- int (*write_inode) (struct inode *, int);
65984- void (*drop_inode) (struct inode *);
65985- void (*delete_inode) (struct inode *);
65986- void (*put_super) (struct super_block *);
65987- void (*write_super) (struct super_block *);
65988- int (*sync_fs)(struct super_block *sb, int wait);
65989- int (*freeze_fs) (struct super_block *);
65990- int (*unfreeze_fs) (struct super_block *);
65991- int (*statfs) (struct dentry *, struct kstatfs *);
65992- int (*remount_fs) (struct super_block *, int *, char *);
65993- void (*clear_inode) (struct inode *);
65994- void (*umount_begin) (struct super_block *);
65995+ void (* const dirty_inode) (struct inode *);
65996+ int (* const write_inode) (struct inode *, int);
65997+ void (* const drop_inode) (struct inode *);
65998+ void (* const delete_inode) (struct inode *);
65999+ void (* const put_super) (struct super_block *);
66000+ void (* const write_super) (struct super_block *);
66001+ int (* const sync_fs)(struct super_block *sb, int wait);
66002+ int (* const freeze_fs) (struct super_block *);
66003+ int (* const unfreeze_fs) (struct super_block *);
66004+ int (* const statfs) (struct dentry *, struct kstatfs *);
66005+ int (* const remount_fs) (struct super_block *, int *, char *);
66006+ void (* const clear_inode) (struct inode *);
66007+ void (* const umount_begin) (struct super_block *);
66008
66009- int (*show_options)(struct seq_file *, struct vfsmount *);
66010- int (*show_stats)(struct seq_file *, struct vfsmount *);
66011+ int (* const show_options)(struct seq_file *, struct vfsmount *);
66012+ int (* const show_stats)(struct seq_file *, struct vfsmount *);
66013 #ifdef CONFIG_QUOTA
66014- ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t);
66015- ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t);
66016+ ssize_t (* const quota_read)(struct super_block *, int, char *, size_t, loff_t);
66017+ ssize_t (* const quota_write)(struct super_block *, int, const char *, size_t, loff_t);
66018 #endif
66019- int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
66020+ int (* const bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
66021 };
66022
66023 /*
66024diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
66025index 78a05bf..2a7d3e1 100644
66026--- a/include/linux/fs_struct.h
66027+++ b/include/linux/fs_struct.h
66028@@ -4,7 +4,7 @@
66029 #include <linux/path.h>
66030
66031 struct fs_struct {
66032- int users;
66033+ atomic_t users;
66034 rwlock_t lock;
66035 int umask;
66036 int in_exec;
66037diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
66038index 7be0c6f..2f63a2b 100644
66039--- a/include/linux/fscache-cache.h
66040+++ b/include/linux/fscache-cache.h
66041@@ -116,7 +116,7 @@ struct fscache_operation {
66042 #endif
66043 };
66044
66045-extern atomic_t fscache_op_debug_id;
66046+extern atomic_unchecked_t fscache_op_debug_id;
66047 extern const struct slow_work_ops fscache_op_slow_work_ops;
66048
66049 extern void fscache_enqueue_operation(struct fscache_operation *);
66050@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
66051 fscache_operation_release_t release)
66052 {
66053 atomic_set(&op->usage, 1);
66054- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
66055+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
66056 op->release = release;
66057 INIT_LIST_HEAD(&op->pend_link);
66058 fscache_set_op_state(op, "Init");
66059diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
66060index 4d6f47b..00bcedb 100644
66061--- a/include/linux/fsnotify_backend.h
66062+++ b/include/linux/fsnotify_backend.h
66063@@ -86,6 +86,7 @@ struct fsnotify_ops {
66064 void (*freeing_mark)(struct fsnotify_mark_entry *entry, struct fsnotify_group *group);
66065 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
66066 };
66067+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
66068
66069 /*
66070 * A group is a "thing" that wants to receive notification about filesystem
66071diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
66072index 4ec5e67..42f1eb9 100644
66073--- a/include/linux/ftrace_event.h
66074+++ b/include/linux/ftrace_event.h
66075@@ -163,7 +163,7 @@ extern int trace_define_field(struct ftrace_event_call *call,
66076 int filter_type);
66077 extern int trace_define_common_fields(struct ftrace_event_call *call);
66078
66079-#define is_signed_type(type) (((type)(-1)) < 0)
66080+#define is_signed_type(type) (((type)(-1)) < (type)1)
66081
66082 int trace_set_clr_event(const char *system, const char *event, int set);
66083
66084diff --git a/include/linux/genhd.h b/include/linux/genhd.h
66085index 297df45..b6a74ff 100644
66086--- a/include/linux/genhd.h
66087+++ b/include/linux/genhd.h
66088@@ -161,7 +161,7 @@ struct gendisk {
66089
66090 struct timer_rand_state *random;
66091
66092- atomic_t sync_io; /* RAID */
66093+ atomic_unchecked_t sync_io; /* RAID */
66094 struct work_struct async_notify;
66095 #ifdef CONFIG_BLK_DEV_INTEGRITY
66096 struct blk_integrity *integrity;
66097diff --git a/include/linux/gracl.h b/include/linux/gracl.h
66098new file mode 100644
66099index 0000000..0dc3943
66100--- /dev/null
66101+++ b/include/linux/gracl.h
66102@@ -0,0 +1,317 @@
66103+#ifndef GR_ACL_H
66104+#define GR_ACL_H
66105+
66106+#include <linux/grdefs.h>
66107+#include <linux/resource.h>
66108+#include <linux/capability.h>
66109+#include <linux/dcache.h>
66110+#include <asm/resource.h>
66111+
66112+/* Major status information */
66113+
66114+#define GR_VERSION "grsecurity 2.2.2"
66115+#define GRSECURITY_VERSION 0x2202
66116+
66117+enum {
66118+ GR_SHUTDOWN = 0,
66119+ GR_ENABLE = 1,
66120+ GR_SPROLE = 2,
66121+ GR_RELOAD = 3,
66122+ GR_SEGVMOD = 4,
66123+ GR_STATUS = 5,
66124+ GR_UNSPROLE = 6,
66125+ GR_PASSSET = 7,
66126+ GR_SPROLEPAM = 8,
66127+};
66128+
66129+/* Password setup definitions
66130+ * kernel/grhash.c */
66131+enum {
66132+ GR_PW_LEN = 128,
66133+ GR_SALT_LEN = 16,
66134+ GR_SHA_LEN = 32,
66135+};
66136+
66137+enum {
66138+ GR_SPROLE_LEN = 64,
66139+};
66140+
66141+enum {
66142+ GR_NO_GLOB = 0,
66143+ GR_REG_GLOB,
66144+ GR_CREATE_GLOB
66145+};
66146+
66147+#define GR_NLIMITS 32
66148+
66149+/* Begin Data Structures */
66150+
66151+struct sprole_pw {
66152+ unsigned char *rolename;
66153+ unsigned char salt[GR_SALT_LEN];
66154+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
66155+};
66156+
66157+struct name_entry {
66158+ __u32 key;
66159+ ino_t inode;
66160+ dev_t device;
66161+ char *name;
66162+ __u16 len;
66163+ __u8 deleted;
66164+ struct name_entry *prev;
66165+ struct name_entry *next;
66166+};
66167+
66168+struct inodev_entry {
66169+ struct name_entry *nentry;
66170+ struct inodev_entry *prev;
66171+ struct inodev_entry *next;
66172+};
66173+
66174+struct acl_role_db {
66175+ struct acl_role_label **r_hash;
66176+ __u32 r_size;
66177+};
66178+
66179+struct inodev_db {
66180+ struct inodev_entry **i_hash;
66181+ __u32 i_size;
66182+};
66183+
66184+struct name_db {
66185+ struct name_entry **n_hash;
66186+ __u32 n_size;
66187+};
66188+
66189+struct crash_uid {
66190+ uid_t uid;
66191+ unsigned long expires;
66192+};
66193+
66194+struct gr_hash_struct {
66195+ void **table;
66196+ void **nametable;
66197+ void *first;
66198+ __u32 table_size;
66199+ __u32 used_size;
66200+ int type;
66201+};
66202+
66203+/* Userspace Grsecurity ACL data structures */
66204+
66205+struct acl_subject_label {
66206+ char *filename;
66207+ ino_t inode;
66208+ dev_t device;
66209+ __u32 mode;
66210+ kernel_cap_t cap_mask;
66211+ kernel_cap_t cap_lower;
66212+ kernel_cap_t cap_invert_audit;
66213+
66214+ struct rlimit res[GR_NLIMITS];
66215+ __u32 resmask;
66216+
66217+ __u8 user_trans_type;
66218+ __u8 group_trans_type;
66219+ uid_t *user_transitions;
66220+ gid_t *group_transitions;
66221+ __u16 user_trans_num;
66222+ __u16 group_trans_num;
66223+
66224+ __u32 sock_families[2];
66225+ __u32 ip_proto[8];
66226+ __u32 ip_type;
66227+ struct acl_ip_label **ips;
66228+ __u32 ip_num;
66229+ __u32 inaddr_any_override;
66230+
66231+ __u32 crashes;
66232+ unsigned long expires;
66233+
66234+ struct acl_subject_label *parent_subject;
66235+ struct gr_hash_struct *hash;
66236+ struct acl_subject_label *prev;
66237+ struct acl_subject_label *next;
66238+
66239+ struct acl_object_label **obj_hash;
66240+ __u32 obj_hash_size;
66241+ __u16 pax_flags;
66242+};
66243+
66244+struct role_allowed_ip {
66245+ __u32 addr;
66246+ __u32 netmask;
66247+
66248+ struct role_allowed_ip *prev;
66249+ struct role_allowed_ip *next;
66250+};
66251+
66252+struct role_transition {
66253+ char *rolename;
66254+
66255+ struct role_transition *prev;
66256+ struct role_transition *next;
66257+};
66258+
66259+struct acl_role_label {
66260+ char *rolename;
66261+ uid_t uidgid;
66262+ __u16 roletype;
66263+
66264+ __u16 auth_attempts;
66265+ unsigned long expires;
66266+
66267+ struct acl_subject_label *root_label;
66268+ struct gr_hash_struct *hash;
66269+
66270+ struct acl_role_label *prev;
66271+ struct acl_role_label *next;
66272+
66273+ struct role_transition *transitions;
66274+ struct role_allowed_ip *allowed_ips;
66275+ uid_t *domain_children;
66276+ __u16 domain_child_num;
66277+
66278+ struct acl_subject_label **subj_hash;
66279+ __u32 subj_hash_size;
66280+};
66281+
66282+struct user_acl_role_db {
66283+ struct acl_role_label **r_table;
66284+ __u32 num_pointers; /* Number of allocations to track */
66285+ __u32 num_roles; /* Number of roles */
66286+ __u32 num_domain_children; /* Number of domain children */
66287+ __u32 num_subjects; /* Number of subjects */
66288+ __u32 num_objects; /* Number of objects */
66289+};
66290+
66291+struct acl_object_label {
66292+ char *filename;
66293+ ino_t inode;
66294+ dev_t device;
66295+ __u32 mode;
66296+
66297+ struct acl_subject_label *nested;
66298+ struct acl_object_label *globbed;
66299+
66300+ /* next two structures not used */
66301+
66302+ struct acl_object_label *prev;
66303+ struct acl_object_label *next;
66304+};
66305+
66306+struct acl_ip_label {
66307+ char *iface;
66308+ __u32 addr;
66309+ __u32 netmask;
66310+ __u16 low, high;
66311+ __u8 mode;
66312+ __u32 type;
66313+ __u32 proto[8];
66314+
66315+ /* next two structures not used */
66316+
66317+ struct acl_ip_label *prev;
66318+ struct acl_ip_label *next;
66319+};
66320+
66321+struct gr_arg {
66322+ struct user_acl_role_db role_db;
66323+ unsigned char pw[GR_PW_LEN];
66324+ unsigned char salt[GR_SALT_LEN];
66325+ unsigned char sum[GR_SHA_LEN];
66326+ unsigned char sp_role[GR_SPROLE_LEN];
66327+ struct sprole_pw *sprole_pws;
66328+ dev_t segv_device;
66329+ ino_t segv_inode;
66330+ uid_t segv_uid;
66331+ __u16 num_sprole_pws;
66332+ __u16 mode;
66333+};
66334+
66335+struct gr_arg_wrapper {
66336+ struct gr_arg *arg;
66337+ __u32 version;
66338+ __u32 size;
66339+};
66340+
66341+struct subject_map {
66342+ struct acl_subject_label *user;
66343+ struct acl_subject_label *kernel;
66344+ struct subject_map *prev;
66345+ struct subject_map *next;
66346+};
66347+
66348+struct acl_subj_map_db {
66349+ struct subject_map **s_hash;
66350+ __u32 s_size;
66351+};
66352+
66353+/* End Data Structures Section */
66354+
66355+/* Hash functions generated by empirical testing by Brad Spengler
66356+ Makes good use of the low bits of the inode. Generally 0-1 times
66357+ in loop for successful match. 0-3 for unsuccessful match.
66358+ Shift/add algorithm with modulus of table size and an XOR*/
66359+
66360+static __inline__ unsigned int
66361+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
66362+{
66363+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
66364+}
66365+
66366+ static __inline__ unsigned int
66367+shash(const struct acl_subject_label *userp, const unsigned int sz)
66368+{
66369+ return ((const unsigned long)userp % sz);
66370+}
66371+
66372+static __inline__ unsigned int
66373+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
66374+{
66375+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
66376+}
66377+
66378+static __inline__ unsigned int
66379+nhash(const char *name, const __u16 len, const unsigned int sz)
66380+{
66381+ return full_name_hash((const unsigned char *)name, len) % sz;
66382+}
66383+
66384+#define FOR_EACH_ROLE_START(role) \
66385+ role = role_list; \
66386+ while (role) {
66387+
66388+#define FOR_EACH_ROLE_END(role) \
66389+ role = role->prev; \
66390+ }
66391+
66392+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
66393+ subj = NULL; \
66394+ iter = 0; \
66395+ while (iter < role->subj_hash_size) { \
66396+ if (subj == NULL) \
66397+ subj = role->subj_hash[iter]; \
66398+ if (subj == NULL) { \
66399+ iter++; \
66400+ continue; \
66401+ }
66402+
66403+#define FOR_EACH_SUBJECT_END(subj,iter) \
66404+ subj = subj->next; \
66405+ if (subj == NULL) \
66406+ iter++; \
66407+ }
66408+
66409+
66410+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
66411+ subj = role->hash->first; \
66412+ while (subj != NULL) {
66413+
66414+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
66415+ subj = subj->next; \
66416+ }
66417+
66418+#endif
66419+
66420diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
66421new file mode 100644
66422index 0000000..323ecf2
66423--- /dev/null
66424+++ b/include/linux/gralloc.h
66425@@ -0,0 +1,9 @@
66426+#ifndef __GRALLOC_H
66427+#define __GRALLOC_H
66428+
66429+void acl_free_all(void);
66430+int acl_alloc_stack_init(unsigned long size);
66431+void *acl_alloc(unsigned long len);
66432+void *acl_alloc_num(unsigned long num, unsigned long len);
66433+
66434+#endif
66435diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
66436new file mode 100644
66437index 0000000..70d6cd5
66438--- /dev/null
66439+++ b/include/linux/grdefs.h
66440@@ -0,0 +1,140 @@
66441+#ifndef GRDEFS_H
66442+#define GRDEFS_H
66443+
66444+/* Begin grsecurity status declarations */
66445+
66446+enum {
66447+ GR_READY = 0x01,
66448+ GR_STATUS_INIT = 0x00 // disabled state
66449+};
66450+
66451+/* Begin ACL declarations */
66452+
66453+/* Role flags */
66454+
66455+enum {
66456+ GR_ROLE_USER = 0x0001,
66457+ GR_ROLE_GROUP = 0x0002,
66458+ GR_ROLE_DEFAULT = 0x0004,
66459+ GR_ROLE_SPECIAL = 0x0008,
66460+ GR_ROLE_AUTH = 0x0010,
66461+ GR_ROLE_NOPW = 0x0020,
66462+ GR_ROLE_GOD = 0x0040,
66463+ GR_ROLE_LEARN = 0x0080,
66464+ GR_ROLE_TPE = 0x0100,
66465+ GR_ROLE_DOMAIN = 0x0200,
66466+ GR_ROLE_PAM = 0x0400,
66467+ GR_ROLE_PERSIST = 0x800
66468+};
66469+
66470+/* ACL Subject and Object mode flags */
66471+enum {
66472+ GR_DELETED = 0x80000000
66473+};
66474+
66475+/* ACL Object-only mode flags */
66476+enum {
66477+ GR_READ = 0x00000001,
66478+ GR_APPEND = 0x00000002,
66479+ GR_WRITE = 0x00000004,
66480+ GR_EXEC = 0x00000008,
66481+ GR_FIND = 0x00000010,
66482+ GR_INHERIT = 0x00000020,
66483+ GR_SETID = 0x00000040,
66484+ GR_CREATE = 0x00000080,
66485+ GR_DELETE = 0x00000100,
66486+ GR_LINK = 0x00000200,
66487+ GR_AUDIT_READ = 0x00000400,
66488+ GR_AUDIT_APPEND = 0x00000800,
66489+ GR_AUDIT_WRITE = 0x00001000,
66490+ GR_AUDIT_EXEC = 0x00002000,
66491+ GR_AUDIT_FIND = 0x00004000,
66492+ GR_AUDIT_INHERIT= 0x00008000,
66493+ GR_AUDIT_SETID = 0x00010000,
66494+ GR_AUDIT_CREATE = 0x00020000,
66495+ GR_AUDIT_DELETE = 0x00040000,
66496+ GR_AUDIT_LINK = 0x00080000,
66497+ GR_PTRACERD = 0x00100000,
66498+ GR_NOPTRACE = 0x00200000,
66499+ GR_SUPPRESS = 0x00400000,
66500+ GR_NOLEARN = 0x00800000,
66501+ GR_INIT_TRANSFER= 0x01000000
66502+};
66503+
66504+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
66505+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
66506+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
66507+
66508+/* ACL subject-only mode flags */
66509+enum {
66510+ GR_KILL = 0x00000001,
66511+ GR_VIEW = 0x00000002,
66512+ GR_PROTECTED = 0x00000004,
66513+ GR_LEARN = 0x00000008,
66514+ GR_OVERRIDE = 0x00000010,
66515+ /* just a placeholder, this mode is only used in userspace */
66516+ GR_DUMMY = 0x00000020,
66517+ GR_PROTSHM = 0x00000040,
66518+ GR_KILLPROC = 0x00000080,
66519+ GR_KILLIPPROC = 0x00000100,
66520+ /* just a placeholder, this mode is only used in userspace */
66521+ GR_NOTROJAN = 0x00000200,
66522+ GR_PROTPROCFD = 0x00000400,
66523+ GR_PROCACCT = 0x00000800,
66524+ GR_RELAXPTRACE = 0x00001000,
66525+ GR_NESTED = 0x00002000,
66526+ GR_INHERITLEARN = 0x00004000,
66527+ GR_PROCFIND = 0x00008000,
66528+ GR_POVERRIDE = 0x00010000,
66529+ GR_KERNELAUTH = 0x00020000,
66530+ GR_ATSECURE = 0x00040000,
66531+ GR_SHMEXEC = 0x00080000
66532+};
66533+
66534+enum {
66535+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
66536+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
66537+ GR_PAX_ENABLE_MPROTECT = 0x0004,
66538+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
66539+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
66540+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
66541+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
66542+ GR_PAX_DISABLE_MPROTECT = 0x0400,
66543+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
66544+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
66545+};
66546+
66547+enum {
66548+ GR_ID_USER = 0x01,
66549+ GR_ID_GROUP = 0x02,
66550+};
66551+
66552+enum {
66553+ GR_ID_ALLOW = 0x01,
66554+ GR_ID_DENY = 0x02,
66555+};
66556+
66557+#define GR_CRASH_RES 31
66558+#define GR_UIDTABLE_MAX 500
66559+
66560+/* begin resource learning section */
66561+enum {
66562+ GR_RLIM_CPU_BUMP = 60,
66563+ GR_RLIM_FSIZE_BUMP = 50000,
66564+ GR_RLIM_DATA_BUMP = 10000,
66565+ GR_RLIM_STACK_BUMP = 1000,
66566+ GR_RLIM_CORE_BUMP = 10000,
66567+ GR_RLIM_RSS_BUMP = 500000,
66568+ GR_RLIM_NPROC_BUMP = 1,
66569+ GR_RLIM_NOFILE_BUMP = 5,
66570+ GR_RLIM_MEMLOCK_BUMP = 50000,
66571+ GR_RLIM_AS_BUMP = 500000,
66572+ GR_RLIM_LOCKS_BUMP = 2,
66573+ GR_RLIM_SIGPENDING_BUMP = 5,
66574+ GR_RLIM_MSGQUEUE_BUMP = 10000,
66575+ GR_RLIM_NICE_BUMP = 1,
66576+ GR_RLIM_RTPRIO_BUMP = 1,
66577+ GR_RLIM_RTTIME_BUMP = 1000000
66578+};
66579+
66580+#endif
66581diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
66582new file mode 100644
66583index 0000000..e5817d7
66584--- /dev/null
66585+++ b/include/linux/grinternal.h
66586@@ -0,0 +1,218 @@
66587+#ifndef __GRINTERNAL_H
66588+#define __GRINTERNAL_H
66589+
66590+#ifdef CONFIG_GRKERNSEC
66591+
66592+#include <linux/fs.h>
66593+#include <linux/mnt_namespace.h>
66594+#include <linux/nsproxy.h>
66595+#include <linux/gracl.h>
66596+#include <linux/grdefs.h>
66597+#include <linux/grmsg.h>
66598+
66599+void gr_add_learn_entry(const char *fmt, ...)
66600+ __attribute__ ((format (printf, 1, 2)));
66601+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
66602+ const struct vfsmount *mnt);
66603+__u32 gr_check_create(const struct dentry *new_dentry,
66604+ const struct dentry *parent,
66605+ const struct vfsmount *mnt, const __u32 mode);
66606+int gr_check_protected_task(const struct task_struct *task);
66607+__u32 to_gr_audit(const __u32 reqmode);
66608+int gr_set_acls(const int type);
66609+int gr_apply_subject_to_task(struct task_struct *task);
66610+int gr_acl_is_enabled(void);
66611+char gr_roletype_to_char(void);
66612+
66613+void gr_handle_alertkill(struct task_struct *task);
66614+char *gr_to_filename(const struct dentry *dentry,
66615+ const struct vfsmount *mnt);
66616+char *gr_to_filename1(const struct dentry *dentry,
66617+ const struct vfsmount *mnt);
66618+char *gr_to_filename2(const struct dentry *dentry,
66619+ const struct vfsmount *mnt);
66620+char *gr_to_filename3(const struct dentry *dentry,
66621+ const struct vfsmount *mnt);
66622+
66623+extern int grsec_enable_harden_ptrace;
66624+extern int grsec_enable_link;
66625+extern int grsec_enable_fifo;
66626+extern int grsec_enable_shm;
66627+extern int grsec_enable_execlog;
66628+extern int grsec_enable_signal;
66629+extern int grsec_enable_audit_ptrace;
66630+extern int grsec_enable_forkfail;
66631+extern int grsec_enable_time;
66632+extern int grsec_enable_rofs;
66633+extern int grsec_enable_chroot_shmat;
66634+extern int grsec_enable_chroot_mount;
66635+extern int grsec_enable_chroot_double;
66636+extern int grsec_enable_chroot_pivot;
66637+extern int grsec_enable_chroot_chdir;
66638+extern int grsec_enable_chroot_chmod;
66639+extern int grsec_enable_chroot_mknod;
66640+extern int grsec_enable_chroot_fchdir;
66641+extern int grsec_enable_chroot_nice;
66642+extern int grsec_enable_chroot_execlog;
66643+extern int grsec_enable_chroot_caps;
66644+extern int grsec_enable_chroot_sysctl;
66645+extern int grsec_enable_chroot_unix;
66646+extern int grsec_enable_tpe;
66647+extern int grsec_tpe_gid;
66648+extern int grsec_enable_tpe_all;
66649+extern int grsec_enable_tpe_invert;
66650+extern int grsec_enable_socket_all;
66651+extern int grsec_socket_all_gid;
66652+extern int grsec_enable_socket_client;
66653+extern int grsec_socket_client_gid;
66654+extern int grsec_enable_socket_server;
66655+extern int grsec_socket_server_gid;
66656+extern int grsec_audit_gid;
66657+extern int grsec_enable_group;
66658+extern int grsec_enable_audit_textrel;
66659+extern int grsec_enable_log_rwxmaps;
66660+extern int grsec_enable_mount;
66661+extern int grsec_enable_chdir;
66662+extern int grsec_resource_logging;
66663+extern int grsec_enable_blackhole;
66664+extern int grsec_lastack_retries;
66665+extern int grsec_enable_brute;
66666+extern int grsec_lock;
66667+
66668+extern spinlock_t grsec_alert_lock;
66669+extern unsigned long grsec_alert_wtime;
66670+extern unsigned long grsec_alert_fyet;
66671+
66672+extern spinlock_t grsec_audit_lock;
66673+
66674+extern rwlock_t grsec_exec_file_lock;
66675+
66676+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
66677+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
66678+ (tsk)->exec_file->f_vfsmnt) : "/")
66679+
66680+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
66681+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
66682+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
66683+
66684+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
66685+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
66686+ (tsk)->exec_file->f_vfsmnt) : "/")
66687+
66688+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
66689+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
66690+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
66691+
66692+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
66693+
66694+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
66695+
66696+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
66697+ (task)->pid, (cred)->uid, \
66698+ (cred)->euid, (cred)->gid, (cred)->egid, \
66699+ gr_parent_task_fullpath(task), \
66700+ (task)->real_parent->comm, (task)->real_parent->pid, \
66701+ (pcred)->uid, (pcred)->euid, \
66702+ (pcred)->gid, (pcred)->egid
66703+
66704+#define GR_CHROOT_CAPS {{ \
66705+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
66706+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
66707+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
66708+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
66709+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
66710+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
66711+ CAP_TO_MASK(CAP_MAC_ADMIN) }}
66712+
66713+#define security_learn(normal_msg,args...) \
66714+({ \
66715+ read_lock(&grsec_exec_file_lock); \
66716+ gr_add_learn_entry(normal_msg "\n", ## args); \
66717+ read_unlock(&grsec_exec_file_lock); \
66718+})
66719+
66720+enum {
66721+ GR_DO_AUDIT,
66722+ GR_DONT_AUDIT,
66723+ GR_DONT_AUDIT_GOOD
66724+};
66725+
66726+enum {
66727+ GR_TTYSNIFF,
66728+ GR_RBAC,
66729+ GR_RBAC_STR,
66730+ GR_STR_RBAC,
66731+ GR_RBAC_MODE2,
66732+ GR_RBAC_MODE3,
66733+ GR_FILENAME,
66734+ GR_SYSCTL_HIDDEN,
66735+ GR_NOARGS,
66736+ GR_ONE_INT,
66737+ GR_ONE_INT_TWO_STR,
66738+ GR_ONE_STR,
66739+ GR_STR_INT,
66740+ GR_TWO_STR_INT,
66741+ GR_TWO_INT,
66742+ GR_TWO_U64,
66743+ GR_THREE_INT,
66744+ GR_FIVE_INT_TWO_STR,
66745+ GR_TWO_STR,
66746+ GR_THREE_STR,
66747+ GR_FOUR_STR,
66748+ GR_STR_FILENAME,
66749+ GR_FILENAME_STR,
66750+ GR_FILENAME_TWO_INT,
66751+ GR_FILENAME_TWO_INT_STR,
66752+ GR_TEXTREL,
66753+ GR_PTRACE,
66754+ GR_RESOURCE,
66755+ GR_CAP,
66756+ GR_SIG,
66757+ GR_SIG2,
66758+ GR_CRASH1,
66759+ GR_CRASH2,
66760+ GR_PSACCT,
66761+ GR_RWXMAP
66762+};
66763+
66764+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
66765+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
66766+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
66767+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
66768+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
66769+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
66770+#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)
66771+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
66772+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
66773+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
66774+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
66775+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
66776+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
66777+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
66778+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
66779+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
66780+#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)
66781+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
66782+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
66783+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
66784+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
66785+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
66786+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
66787+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
66788+#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)
66789+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
66790+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
66791+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
66792+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
66793+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
66794+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
66795+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
66796+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
66797+#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)
66798+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
66799+
66800+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
66801+
66802+#endif
66803+
66804+#endif
66805diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
66806new file mode 100644
66807index 0000000..9d5fd4a
66808--- /dev/null
66809+++ b/include/linux/grmsg.h
66810@@ -0,0 +1,108 @@
66811+#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"
66812+#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"
66813+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
66814+#define GR_STOPMOD_MSG "denied modification of module state by "
66815+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
66816+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
66817+#define GR_IOPERM_MSG "denied use of ioperm() by "
66818+#define GR_IOPL_MSG "denied use of iopl() by "
66819+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
66820+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
66821+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
66822+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
66823+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
66824+#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"
66825+#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"
66826+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
66827+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
66828+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
66829+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
66830+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
66831+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
66832+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
66833+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
66834+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
66835+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
66836+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
66837+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
66838+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
66839+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
66840+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
66841+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
66842+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
66843+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
66844+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
66845+#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
66846+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
66847+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
66848+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
66849+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
66850+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
66851+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
66852+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
66853+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
66854+#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
66855+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
66856+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
66857+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
66858+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
66859+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
66860+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
66861+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
66862+#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"
66863+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
66864+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
66865+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
66866+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
66867+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
66868+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
66869+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
66870+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
66871+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
66872+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
66873+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
66874+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
66875+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
66876+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
66877+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
66878+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
66879+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
66880+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
66881+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
66882+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
66883+#define GR_FAILFORK_MSG "failed fork with errno %s by "
66884+#define GR_NICE_CHROOT_MSG "denied priority change by "
66885+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
66886+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
66887+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
66888+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
66889+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
66890+#define GR_TIME_MSG "time set by "
66891+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
66892+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
66893+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
66894+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
66895+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
66896+#define GR_BIND_MSG "denied bind() by "
66897+#define GR_CONNECT_MSG "denied connect() by "
66898+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
66899+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
66900+#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"
66901+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
66902+#define GR_CAP_ACL_MSG "use of %s denied for "
66903+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
66904+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
66905+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
66906+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
66907+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
66908+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
66909+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
66910+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
66911+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
66912+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
66913+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
66914+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
66915+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
66916+#define GR_VM86_MSG "denied use of vm86 by "
66917+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
66918+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
66919diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
66920new file mode 100644
66921index 0000000..24676f4
66922--- /dev/null
66923+++ b/include/linux/grsecurity.h
66924@@ -0,0 +1,218 @@
66925+#ifndef GR_SECURITY_H
66926+#define GR_SECURITY_H
66927+#include <linux/fs.h>
66928+#include <linux/fs_struct.h>
66929+#include <linux/binfmts.h>
66930+#include <linux/gracl.h>
66931+#include <linux/compat.h>
66932+
66933+/* notify of brain-dead configs */
66934+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66935+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
66936+#endif
66937+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
66938+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
66939+#endif
66940+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
66941+#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
66942+#endif
66943+#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
66944+#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
66945+#endif
66946+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
66947+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
66948+#endif
66949+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
66950+#error "CONFIG_PAX enabled, but no PaX options are enabled."
66951+#endif
66952+
66953+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
66954+void gr_handle_brute_check(void);
66955+void gr_handle_kernel_exploit(void);
66956+int gr_process_user_ban(void);
66957+
66958+char gr_roletype_to_char(void);
66959+
66960+int gr_acl_enable_at_secure(void);
66961+
66962+int gr_check_user_change(int real, int effective, int fs);
66963+int gr_check_group_change(int real, int effective, int fs);
66964+
66965+void gr_del_task_from_ip_table(struct task_struct *p);
66966+
66967+int gr_pid_is_chrooted(struct task_struct *p);
66968+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
66969+int gr_handle_chroot_nice(void);
66970+int gr_handle_chroot_sysctl(const int op);
66971+int gr_handle_chroot_setpriority(struct task_struct *p,
66972+ const int niceval);
66973+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
66974+int gr_handle_chroot_chroot(const struct dentry *dentry,
66975+ const struct vfsmount *mnt);
66976+void gr_handle_chroot_chdir(struct path *path);
66977+int gr_handle_chroot_chmod(const struct dentry *dentry,
66978+ const struct vfsmount *mnt, const int mode);
66979+int gr_handle_chroot_mknod(const struct dentry *dentry,
66980+ const struct vfsmount *mnt, const int mode);
66981+int gr_handle_chroot_mount(const struct dentry *dentry,
66982+ const struct vfsmount *mnt,
66983+ const char *dev_name);
66984+int gr_handle_chroot_pivot(void);
66985+int gr_handle_chroot_unix(const pid_t pid);
66986+
66987+int gr_handle_rawio(const struct inode *inode);
66988+
66989+void gr_handle_ioperm(void);
66990+void gr_handle_iopl(void);
66991+
66992+int gr_tpe_allow(const struct file *file);
66993+
66994+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
66995+void gr_clear_chroot_entries(struct task_struct *task);
66996+
66997+void gr_log_forkfail(const int retval);
66998+void gr_log_timechange(void);
66999+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
67000+void gr_log_chdir(const struct dentry *dentry,
67001+ const struct vfsmount *mnt);
67002+void gr_log_chroot_exec(const struct dentry *dentry,
67003+ const struct vfsmount *mnt);
67004+void gr_handle_exec_args(struct linux_binprm *bprm, const char __user *const __user *argv);
67005+#ifdef CONFIG_COMPAT
67006+void gr_handle_exec_args_compat(struct linux_binprm *bprm, compat_uptr_t __user *argv);
67007+#endif
67008+void gr_log_remount(const char *devname, const int retval);
67009+void gr_log_unmount(const char *devname, const int retval);
67010+void gr_log_mount(const char *from, const char *to, const int retval);
67011+void gr_log_textrel(struct vm_area_struct *vma);
67012+void gr_log_rwxmmap(struct file *file);
67013+void gr_log_rwxmprotect(struct file *file);
67014+
67015+int gr_handle_follow_link(const struct inode *parent,
67016+ const struct inode *inode,
67017+ const struct dentry *dentry,
67018+ const struct vfsmount *mnt);
67019+int gr_handle_fifo(const struct dentry *dentry,
67020+ const struct vfsmount *mnt,
67021+ const struct dentry *dir, const int flag,
67022+ const int acc_mode);
67023+int gr_handle_hardlink(const struct dentry *dentry,
67024+ const struct vfsmount *mnt,
67025+ struct inode *inode,
67026+ const int mode, const char *to);
67027+
67028+int gr_is_capable(const int cap);
67029+int gr_is_capable_nolog(const int cap);
67030+void gr_learn_resource(const struct task_struct *task, const int limit,
67031+ const unsigned long wanted, const int gt);
67032+void gr_copy_label(struct task_struct *tsk);
67033+void gr_handle_crash(struct task_struct *task, const int sig);
67034+int gr_handle_signal(const struct task_struct *p, const int sig);
67035+int gr_check_crash_uid(const uid_t uid);
67036+int gr_check_protected_task(const struct task_struct *task);
67037+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
67038+int gr_acl_handle_mmap(const struct file *file,
67039+ const unsigned long prot);
67040+int gr_acl_handle_mprotect(const struct file *file,
67041+ const unsigned long prot);
67042+int gr_check_hidden_task(const struct task_struct *tsk);
67043+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
67044+ const struct vfsmount *mnt);
67045+__u32 gr_acl_handle_utime(const struct dentry *dentry,
67046+ const struct vfsmount *mnt);
67047+__u32 gr_acl_handle_access(const struct dentry *dentry,
67048+ const struct vfsmount *mnt, const int fmode);
67049+__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
67050+ const struct vfsmount *mnt, mode_t mode);
67051+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
67052+ const struct vfsmount *mnt, mode_t mode);
67053+__u32 gr_acl_handle_chown(const struct dentry *dentry,
67054+ const struct vfsmount *mnt);
67055+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
67056+ const struct vfsmount *mnt);
67057+int gr_handle_ptrace(struct task_struct *task, const long request);
67058+int gr_handle_proc_ptrace(struct task_struct *task);
67059+__u32 gr_acl_handle_execve(const struct dentry *dentry,
67060+ const struct vfsmount *mnt);
67061+int gr_check_crash_exec(const struct file *filp);
67062+int gr_acl_is_enabled(void);
67063+void gr_set_kernel_label(struct task_struct *task);
67064+void gr_set_role_label(struct task_struct *task, const uid_t uid,
67065+ const gid_t gid);
67066+int gr_set_proc_label(const struct dentry *dentry,
67067+ const struct vfsmount *mnt,
67068+ const int unsafe_share);
67069+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
67070+ const struct vfsmount *mnt);
67071+__u32 gr_acl_handle_open(const struct dentry *dentry,
67072+ const struct vfsmount *mnt, int acc_mode);
67073+__u32 gr_acl_handle_creat(const struct dentry *dentry,
67074+ const struct dentry *p_dentry,
67075+ const struct vfsmount *p_mnt,
67076+ int open_flags, int acc_mode, const int imode);
67077+void gr_handle_create(const struct dentry *dentry,
67078+ const struct vfsmount *mnt);
67079+void gr_handle_proc_create(const struct dentry *dentry,
67080+ const struct inode *inode);
67081+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
67082+ const struct dentry *parent_dentry,
67083+ const struct vfsmount *parent_mnt,
67084+ const int mode);
67085+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
67086+ const struct dentry *parent_dentry,
67087+ const struct vfsmount *parent_mnt);
67088+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
67089+ const struct vfsmount *mnt);
67090+void gr_handle_delete(const ino_t ino, const dev_t dev);
67091+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
67092+ const struct vfsmount *mnt);
67093+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
67094+ const struct dentry *parent_dentry,
67095+ const struct vfsmount *parent_mnt,
67096+ const char *from);
67097+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
67098+ const struct dentry *parent_dentry,
67099+ const struct vfsmount *parent_mnt,
67100+ const struct dentry *old_dentry,
67101+ const struct vfsmount *old_mnt, const char *to);
67102+int gr_acl_handle_rename(struct dentry *new_dentry,
67103+ struct dentry *parent_dentry,
67104+ const struct vfsmount *parent_mnt,
67105+ struct dentry *old_dentry,
67106+ struct inode *old_parent_inode,
67107+ struct vfsmount *old_mnt, const char *newname);
67108+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
67109+ struct dentry *old_dentry,
67110+ struct dentry *new_dentry,
67111+ struct vfsmount *mnt, const __u8 replace);
67112+__u32 gr_check_link(const struct dentry *new_dentry,
67113+ const struct dentry *parent_dentry,
67114+ const struct vfsmount *parent_mnt,
67115+ const struct dentry *old_dentry,
67116+ const struct vfsmount *old_mnt);
67117+int gr_acl_handle_filldir(const struct file *file, const char *name,
67118+ const unsigned int namelen, const ino_t ino);
67119+
67120+__u32 gr_acl_handle_unix(const struct dentry *dentry,
67121+ const struct vfsmount *mnt);
67122+void gr_acl_handle_exit(void);
67123+void gr_acl_handle_psacct(struct task_struct *task, const long code);
67124+int gr_acl_handle_procpidmem(const struct task_struct *task);
67125+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
67126+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
67127+void gr_audit_ptrace(struct task_struct *task);
67128+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
67129+
67130+#ifdef CONFIG_GRKERNSEC
67131+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
67132+void gr_handle_vm86(void);
67133+void gr_handle_mem_readwrite(u64 from, u64 to);
67134+
67135+extern int grsec_enable_dmesg;
67136+extern int grsec_disable_privio;
67137+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
67138+extern int grsec_enable_chroot_findtask;
67139+#endif
67140+#endif
67141+
67142+#endif
67143diff --git a/include/linux/hdpu_features.h b/include/linux/hdpu_features.h
67144index 6a87154..a3ce57b 100644
67145--- a/include/linux/hdpu_features.h
67146+++ b/include/linux/hdpu_features.h
67147@@ -3,7 +3,7 @@
67148 struct cpustate_t {
67149 spinlock_t lock;
67150 int excl;
67151- int open_count;
67152+ atomic_t open_count;
67153 unsigned char cached_val;
67154 int inited;
67155 unsigned long *set_addr;
67156diff --git a/include/linux/highmem.h b/include/linux/highmem.h
67157index 211ff44..00ab6d7 100644
67158--- a/include/linux/highmem.h
67159+++ b/include/linux/highmem.h
67160@@ -137,6 +137,18 @@ static inline void clear_highpage(struct page *page)
67161 kunmap_atomic(kaddr, KM_USER0);
67162 }
67163
67164+static inline void sanitize_highpage(struct page *page)
67165+{
67166+ void *kaddr;
67167+ unsigned long flags;
67168+
67169+ local_irq_save(flags);
67170+ kaddr = kmap_atomic(page, KM_CLEARPAGE);
67171+ clear_page(kaddr);
67172+ kunmap_atomic(kaddr, KM_CLEARPAGE);
67173+ local_irq_restore(flags);
67174+}
67175+
67176 static inline void zero_user_segments(struct page *page,
67177 unsigned start1, unsigned end1,
67178 unsigned start2, unsigned end2)
67179diff --git a/include/linux/i2c.h b/include/linux/i2c.h
67180index 7b40cda..24eb44e 100644
67181--- a/include/linux/i2c.h
67182+++ b/include/linux/i2c.h
67183@@ -325,6 +325,7 @@ struct i2c_algorithm {
67184 /* To determine what the adapter supports */
67185 u32 (*functionality) (struct i2c_adapter *);
67186 };
67187+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
67188
67189 /*
67190 * i2c_adapter is the structure used to identify a physical i2c bus along
67191diff --git a/include/linux/i2o.h b/include/linux/i2o.h
67192index 4c4e57d..f3c5303 100644
67193--- a/include/linux/i2o.h
67194+++ b/include/linux/i2o.h
67195@@ -564,7 +564,7 @@ struct i2o_controller {
67196 struct i2o_device *exec; /* Executive */
67197 #if BITS_PER_LONG == 64
67198 spinlock_t context_list_lock; /* lock for context_list */
67199- atomic_t context_list_counter; /* needed for unique contexts */
67200+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
67201 struct list_head context_list; /* list of context id's
67202 and pointers */
67203 #endif
67204diff --git a/include/linux/init_task.h b/include/linux/init_task.h
67205index 21a6f5d..dc42eab 100644
67206--- a/include/linux/init_task.h
67207+++ b/include/linux/init_task.h
67208@@ -83,6 +83,12 @@ extern struct group_info init_groups;
67209 #define INIT_IDS
67210 #endif
67211
67212+#ifdef CONFIG_X86
67213+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
67214+#else
67215+#define INIT_TASK_THREAD_INFO
67216+#endif
67217+
67218 #ifdef CONFIG_SECURITY_FILE_CAPABILITIES
67219 /*
67220 * Because of the reduced scope of CAP_SETPCAP when filesystem
67221@@ -156,6 +162,7 @@ extern struct cred init_cred;
67222 __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
67223 .comm = "swapper", \
67224 .thread = INIT_THREAD, \
67225+ INIT_TASK_THREAD_INFO \
67226 .fs = &init_fs, \
67227 .files = &init_files, \
67228 .signal = &init_signals, \
67229diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
67230index 4f0a72a..a849599 100644
67231--- a/include/linux/intel-iommu.h
67232+++ b/include/linux/intel-iommu.h
67233@@ -296,7 +296,7 @@ struct iommu_flush {
67234 u8 fm, u64 type);
67235 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
67236 unsigned int size_order, u64 type);
67237-};
67238+} __no_const;
67239
67240 enum {
67241 SR_DMAR_FECTL_REG,
67242diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
67243index c739150..be577b5 100644
67244--- a/include/linux/interrupt.h
67245+++ b/include/linux/interrupt.h
67246@@ -369,7 +369,7 @@ enum
67247 /* map softirq index to softirq name. update 'softirq_to_name' in
67248 * kernel/softirq.c when adding a new softirq.
67249 */
67250-extern char *softirq_to_name[NR_SOFTIRQS];
67251+extern const char * const softirq_to_name[NR_SOFTIRQS];
67252
67253 /* softirq mask and active fields moved to irq_cpustat_t in
67254 * asm/hardirq.h to get better cache usage. KAO
67255@@ -377,12 +377,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
67256
67257 struct softirq_action
67258 {
67259- void (*action)(struct softirq_action *);
67260+ void (*action)(void);
67261 };
67262
67263 asmlinkage void do_softirq(void);
67264 asmlinkage void __do_softirq(void);
67265-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
67266+extern void open_softirq(int nr, void (*action)(void));
67267 extern void softirq_init(void);
67268 #define __raise_softirq_irqoff(nr) do { or_softirq_pending(1UL << (nr)); } while (0)
67269 extern void raise_softirq_irqoff(unsigned int nr);
67270diff --git a/include/linux/irq.h b/include/linux/irq.h
67271index 9e5f45a..025865b 100644
67272--- a/include/linux/irq.h
67273+++ b/include/linux/irq.h
67274@@ -438,12 +438,12 @@ extern int set_irq_msi(unsigned int irq, struct msi_desc *entry);
67275 static inline bool alloc_desc_masks(struct irq_desc *desc, int node,
67276 bool boot)
67277 {
67278+#ifdef CONFIG_CPUMASK_OFFSTACK
67279 gfp_t gfp = GFP_ATOMIC;
67280
67281 if (boot)
67282 gfp = GFP_NOWAIT;
67283
67284-#ifdef CONFIG_CPUMASK_OFFSTACK
67285 if (!alloc_cpumask_var_node(&desc->affinity, gfp, node))
67286 return false;
67287
67288diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
67289index 7922742..27306a2 100644
67290--- a/include/linux/kallsyms.h
67291+++ b/include/linux/kallsyms.h
67292@@ -15,7 +15,8 @@
67293
67294 struct module;
67295
67296-#ifdef CONFIG_KALLSYMS
67297+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
67298+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67299 /* Lookup the address for a symbol. Returns 0 if not found. */
67300 unsigned long kallsyms_lookup_name(const char *name);
67301
67302@@ -92,6 +93,15 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
67303 /* Stupid that this does nothing, but I didn't create this mess. */
67304 #define __print_symbol(fmt, addr)
67305 #endif /*CONFIG_KALLSYMS*/
67306+#else /* when included by kallsyms.c, vsnprintf.c, or
67307+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
67308+extern void __print_symbol(const char *fmt, unsigned long address);
67309+extern int sprint_symbol(char *buffer, unsigned long address);
67310+const char *kallsyms_lookup(unsigned long addr,
67311+ unsigned long *symbolsize,
67312+ unsigned long *offset,
67313+ char **modname, char *namebuf);
67314+#endif
67315
67316 /* This macro allows us to keep printk typechecking */
67317 static void __check_printsym_format(const char *fmt, ...)
67318diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
67319index 6adcc29..13369e8 100644
67320--- a/include/linux/kgdb.h
67321+++ b/include/linux/kgdb.h
67322@@ -74,8 +74,8 @@ void kgdb_breakpoint(void);
67323
67324 extern int kgdb_connected;
67325
67326-extern atomic_t kgdb_setting_breakpoint;
67327-extern atomic_t kgdb_cpu_doing_single_step;
67328+extern atomic_unchecked_t kgdb_setting_breakpoint;
67329+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
67330
67331 extern struct task_struct *kgdb_usethread;
67332 extern struct task_struct *kgdb_contthread;
67333@@ -235,7 +235,7 @@ struct kgdb_arch {
67334 int (*remove_hw_breakpoint)(unsigned long, int, enum kgdb_bptype);
67335 void (*remove_all_hw_break)(void);
67336 void (*correct_hw_break)(void);
67337-};
67338+} __do_const;
67339
67340 /**
67341 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
67342@@ -257,14 +257,14 @@ struct kgdb_io {
67343 int (*init) (void);
67344 void (*pre_exception) (void);
67345 void (*post_exception) (void);
67346-};
67347+} __do_const;
67348
67349-extern struct kgdb_arch arch_kgdb_ops;
67350+extern const struct kgdb_arch arch_kgdb_ops;
67351
67352 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
67353
67354-extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
67355-extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
67356+extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
67357+extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
67358
67359 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
67360 extern int kgdb_mem2hex(char *mem, char *buf, int count);
67361diff --git a/include/linux/kmod.h b/include/linux/kmod.h
67362index 384ca8b..83dd97d 100644
67363--- a/include/linux/kmod.h
67364+++ b/include/linux/kmod.h
67365@@ -31,6 +31,8 @@
67366 * usually useless though. */
67367 extern int __request_module(bool wait, const char *name, ...) \
67368 __attribute__((format(printf, 2, 3)));
67369+extern int ___request_module(bool wait, char *param_name, const char *name, ...) \
67370+ __attribute__((format(printf, 3, 4)));
67371 #define request_module(mod...) __request_module(true, mod)
67372 #define request_module_nowait(mod...) __request_module(false, mod)
67373 #define try_then_request_module(x, mod...) \
67374diff --git a/include/linux/kobject.h b/include/linux/kobject.h
67375index 58ae8e0..3950d3c 100644
67376--- a/include/linux/kobject.h
67377+++ b/include/linux/kobject.h
67378@@ -106,7 +106,7 @@ extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);
67379
67380 struct kobj_type {
67381 void (*release)(struct kobject *kobj);
67382- struct sysfs_ops *sysfs_ops;
67383+ const struct sysfs_ops *sysfs_ops;
67384 struct attribute **default_attrs;
67385 };
67386
67387@@ -118,9 +118,9 @@ struct kobj_uevent_env {
67388 };
67389
67390 struct kset_uevent_ops {
67391- int (*filter)(struct kset *kset, struct kobject *kobj);
67392- const char *(*name)(struct kset *kset, struct kobject *kobj);
67393- int (*uevent)(struct kset *kset, struct kobject *kobj,
67394+ int (* const filter)(struct kset *kset, struct kobject *kobj);
67395+ const char *(* const name)(struct kset *kset, struct kobject *kobj);
67396+ int (* const uevent)(struct kset *kset, struct kobject *kobj,
67397 struct kobj_uevent_env *env);
67398 };
67399
67400@@ -132,7 +132,7 @@ struct kobj_attribute {
67401 const char *buf, size_t count);
67402 };
67403
67404-extern struct sysfs_ops kobj_sysfs_ops;
67405+extern const struct sysfs_ops kobj_sysfs_ops;
67406
67407 /**
67408 * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
67409@@ -155,14 +155,14 @@ struct kset {
67410 struct list_head list;
67411 spinlock_t list_lock;
67412 struct kobject kobj;
67413- struct kset_uevent_ops *uevent_ops;
67414+ const struct kset_uevent_ops *uevent_ops;
67415 };
67416
67417 extern void kset_init(struct kset *kset);
67418 extern int __must_check kset_register(struct kset *kset);
67419 extern void kset_unregister(struct kset *kset);
67420 extern struct kset * __must_check kset_create_and_add(const char *name,
67421- struct kset_uevent_ops *u,
67422+ const struct kset_uevent_ops *u,
67423 struct kobject *parent_kobj);
67424
67425 static inline struct kset *to_kset(struct kobject *kobj)
67426diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
67427index c728a50..752d821 100644
67428--- a/include/linux/kvm_host.h
67429+++ b/include/linux/kvm_host.h
67430@@ -210,7 +210,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
67431 void vcpu_load(struct kvm_vcpu *vcpu);
67432 void vcpu_put(struct kvm_vcpu *vcpu);
67433
67434-int kvm_init(void *opaque, unsigned int vcpu_size,
67435+int kvm_init(const void *opaque, unsigned int vcpu_size,
67436 struct module *module);
67437 void kvm_exit(void);
67438
67439@@ -316,7 +316,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
67440 struct kvm_guest_debug *dbg);
67441 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
67442
67443-int kvm_arch_init(void *opaque);
67444+int kvm_arch_init(const void *opaque);
67445 void kvm_arch_exit(void);
67446
67447 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
67448diff --git a/include/linux/libata.h b/include/linux/libata.h
67449index a069916..223edde 100644
67450--- a/include/linux/libata.h
67451+++ b/include/linux/libata.h
67452@@ -525,11 +525,11 @@ struct ata_ioports {
67453
67454 struct ata_host {
67455 spinlock_t lock;
67456- struct device *dev;
67457+ struct device *dev;
67458 void __iomem * const *iomap;
67459 unsigned int n_ports;
67460 void *private_data;
67461- struct ata_port_operations *ops;
67462+ const struct ata_port_operations *ops;
67463 unsigned long flags;
67464 #ifdef CONFIG_ATA_ACPI
67465 acpi_handle acpi_handle;
67466@@ -710,7 +710,7 @@ struct ata_link {
67467
67468 struct ata_port {
67469 struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
67470- struct ata_port_operations *ops;
67471+ const struct ata_port_operations *ops;
67472 spinlock_t *lock;
67473 /* Flags owned by the EH context. Only EH should touch these once the
67474 port is active */
67475@@ -884,7 +884,7 @@ struct ata_port_operations {
67476 * fields must be pointers.
67477 */
67478 const struct ata_port_operations *inherits;
67479-};
67480+} __do_const;
67481
67482 struct ata_port_info {
67483 unsigned long flags;
67484@@ -892,7 +892,7 @@ struct ata_port_info {
67485 unsigned long pio_mask;
67486 unsigned long mwdma_mask;
67487 unsigned long udma_mask;
67488- struct ata_port_operations *port_ops;
67489+ const struct ata_port_operations *port_ops;
67490 void *private_data;
67491 };
67492
67493@@ -916,7 +916,7 @@ extern const unsigned long sata_deb_timing_normal[];
67494 extern const unsigned long sata_deb_timing_hotplug[];
67495 extern const unsigned long sata_deb_timing_long[];
67496
67497-extern struct ata_port_operations ata_dummy_port_ops;
67498+extern const struct ata_port_operations ata_dummy_port_ops;
67499 extern const struct ata_port_info ata_dummy_port_info;
67500
67501 static inline const unsigned long *
67502@@ -962,7 +962,7 @@ extern int ata_host_activate(struct ata_host *host, int irq,
67503 struct scsi_host_template *sht);
67504 extern void ata_host_detach(struct ata_host *host);
67505 extern void ata_host_init(struct ata_host *, struct device *,
67506- unsigned long, struct ata_port_operations *);
67507+ unsigned long, const struct ata_port_operations *);
67508 extern int ata_scsi_detect(struct scsi_host_template *sht);
67509 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
67510 extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
67511diff --git a/include/linux/lockd/bind.h b/include/linux/lockd/bind.h
67512index fbc48f8..0886e57 100644
67513--- a/include/linux/lockd/bind.h
67514+++ b/include/linux/lockd/bind.h
67515@@ -23,13 +23,13 @@ struct svc_rqst;
67516 * This is the set of functions for lockd->nfsd communication
67517 */
67518 struct nlmsvc_binding {
67519- __be32 (*fopen)(struct svc_rqst *,
67520+ __be32 (* const fopen)(struct svc_rqst *,
67521 struct nfs_fh *,
67522 struct file **);
67523- void (*fclose)(struct file *);
67524+ void (* const fclose)(struct file *);
67525 };
67526
67527-extern struct nlmsvc_binding * nlmsvc_ops;
67528+extern const struct nlmsvc_binding * nlmsvc_ops;
67529
67530 /*
67531 * Similar to nfs_client_initdata, but without the NFS-specific
67532diff --git a/include/linux/mca.h b/include/linux/mca.h
67533index 3797270..7765ede 100644
67534--- a/include/linux/mca.h
67535+++ b/include/linux/mca.h
67536@@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
67537 int region);
67538 void * (*mca_transform_memory)(struct mca_device *,
67539 void *memory);
67540-};
67541+} __no_const;
67542
67543 struct mca_bus {
67544 u64 default_dma_mask;
67545diff --git a/include/linux/memory.h b/include/linux/memory.h
67546index 37fa19b..b597c85 100644
67547--- a/include/linux/memory.h
67548+++ b/include/linux/memory.h
67549@@ -108,7 +108,7 @@ struct memory_accessor {
67550 size_t count);
67551 ssize_t (*write)(struct memory_accessor *, const char *buf,
67552 off_t offset, size_t count);
67553-};
67554+} __no_const;
67555
67556 /*
67557 * Kernel text modification mutex, used for code patching. Users of this lock
67558diff --git a/include/linux/mm.h b/include/linux/mm.h
67559index 11e5be6..1ff2423 100644
67560--- a/include/linux/mm.h
67561+++ b/include/linux/mm.h
67562@@ -106,7 +106,14 @@ extern unsigned int kobjsize(const void *objp);
67563
67564 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
67565 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
67566+
67567+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
67568+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
67569+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
67570+#else
67571 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
67572+#endif
67573+
67574 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
67575 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
67576
67577@@ -841,12 +848,6 @@ int set_page_dirty(struct page *page);
67578 int set_page_dirty_lock(struct page *page);
67579 int clear_page_dirty_for_io(struct page *page);
67580
67581-/* Is the vma a continuation of the stack vma above it? */
67582-static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
67583-{
67584- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
67585-}
67586-
67587 extern unsigned long move_page_tables(struct vm_area_struct *vma,
67588 unsigned long old_addr, struct vm_area_struct *new_vma,
67589 unsigned long new_addr, unsigned long len);
67590@@ -890,6 +891,8 @@ struct shrinker {
67591 extern void register_shrinker(struct shrinker *);
67592 extern void unregister_shrinker(struct shrinker *);
67593
67594+pgprot_t vm_get_page_prot(unsigned long vm_flags);
67595+
67596 int vma_wants_writenotify(struct vm_area_struct *vma);
67597
67598 extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
67599@@ -1162,6 +1165,7 @@ out:
67600 }
67601
67602 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
67603+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
67604
67605 extern unsigned long do_brk(unsigned long, unsigned long);
67606
67607@@ -1218,6 +1222,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
67608 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
67609 struct vm_area_struct **pprev);
67610
67611+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
67612+extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
67613+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
67614+
67615 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
67616 NULL if none. Assume start_addr < end_addr. */
67617 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
67618@@ -1234,7 +1242,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
67619 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
67620 }
67621
67622-pgprot_t vm_get_page_prot(unsigned long vm_flags);
67623 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
67624 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
67625 unsigned long pfn, unsigned long size, pgprot_t);
67626@@ -1332,7 +1339,13 @@ extern void memory_failure(unsigned long pfn, int trapno);
67627 extern int __memory_failure(unsigned long pfn, int trapno, int ref);
67628 extern int sysctl_memory_failure_early_kill;
67629 extern int sysctl_memory_failure_recovery;
67630-extern atomic_long_t mce_bad_pages;
67631+extern atomic_long_unchecked_t mce_bad_pages;
67632+
67633+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67634+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
67635+#else
67636+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
67637+#endif
67638
67639 #endif /* __KERNEL__ */
67640 #endif /* _LINUX_MM_H */
67641diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
67642index 9d12ed5..6d9707a 100644
67643--- a/include/linux/mm_types.h
67644+++ b/include/linux/mm_types.h
67645@@ -186,6 +186,8 @@ struct vm_area_struct {
67646 #ifdef CONFIG_NUMA
67647 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
67648 #endif
67649+
67650+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
67651 };
67652
67653 struct core_thread {
67654@@ -287,6 +289,24 @@ struct mm_struct {
67655 #ifdef CONFIG_MMU_NOTIFIER
67656 struct mmu_notifier_mm *mmu_notifier_mm;
67657 #endif
67658+
67659+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
67660+ unsigned long pax_flags;
67661+#endif
67662+
67663+#ifdef CONFIG_PAX_DLRESOLVE
67664+ unsigned long call_dl_resolve;
67665+#endif
67666+
67667+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
67668+ unsigned long call_syscall;
67669+#endif
67670+
67671+#ifdef CONFIG_PAX_ASLR
67672+ unsigned long delta_mmap; /* randomized offset */
67673+ unsigned long delta_stack; /* randomized offset */
67674+#endif
67675+
67676 };
67677
67678 /* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
67679diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
67680index 4e02ee2..afb159e 100644
67681--- a/include/linux/mmu_notifier.h
67682+++ b/include/linux/mmu_notifier.h
67683@@ -235,12 +235,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
67684 */
67685 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
67686 ({ \
67687- pte_t __pte; \
67688+ pte_t ___pte; \
67689 struct vm_area_struct *___vma = __vma; \
67690 unsigned long ___address = __address; \
67691- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
67692+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
67693 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
67694- __pte; \
67695+ ___pte; \
67696 })
67697
67698 #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \
67699diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
67700index 6c31a2a..4b0e930 100644
67701--- a/include/linux/mmzone.h
67702+++ b/include/linux/mmzone.h
67703@@ -350,7 +350,7 @@ struct zone {
67704 unsigned long flags; /* zone flags, see below */
67705
67706 /* Zone statistics */
67707- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67708+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67709
67710 /*
67711 * prev_priority holds the scanning priority for this zone. It is
67712diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
67713index f58e9d8..3503935 100644
67714--- a/include/linux/mod_devicetable.h
67715+++ b/include/linux/mod_devicetable.h
67716@@ -12,7 +12,7 @@
67717 typedef unsigned long kernel_ulong_t;
67718 #endif
67719
67720-#define PCI_ANY_ID (~0)
67721+#define PCI_ANY_ID ((__u16)~0)
67722
67723 struct pci_device_id {
67724 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
67725@@ -131,7 +131,7 @@ struct usb_device_id {
67726 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
67727 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
67728
67729-#define HID_ANY_ID (~0)
67730+#define HID_ANY_ID (~0U)
67731
67732 struct hid_device_id {
67733 __u16 bus;
67734diff --git a/include/linux/module.h b/include/linux/module.h
67735index 482efc8..642032b 100644
67736--- a/include/linux/module.h
67737+++ b/include/linux/module.h
67738@@ -16,6 +16,7 @@
67739 #include <linux/kobject.h>
67740 #include <linux/moduleparam.h>
67741 #include <linux/tracepoint.h>
67742+#include <linux/fs.h>
67743
67744 #include <asm/local.h>
67745 #include <asm/module.h>
67746@@ -287,16 +288,16 @@ struct module
67747 int (*init)(void);
67748
67749 /* If this is non-NULL, vfree after init() returns */
67750- void *module_init;
67751+ void *module_init_rx, *module_init_rw;
67752
67753 /* Here is the actual code + data, vfree'd on unload. */
67754- void *module_core;
67755+ void *module_core_rx, *module_core_rw;
67756
67757 /* Here are the sizes of the init and core sections */
67758- unsigned int init_size, core_size;
67759+ unsigned int init_size_rw, core_size_rw;
67760
67761 /* The size of the executable code in each section. */
67762- unsigned int init_text_size, core_text_size;
67763+ unsigned int init_size_rx, core_size_rx;
67764
67765 /* Arch-specific module values */
67766 struct mod_arch_specific arch;
67767@@ -345,6 +346,10 @@ struct module
67768 #ifdef CONFIG_EVENT_TRACING
67769 struct ftrace_event_call *trace_events;
67770 unsigned int num_trace_events;
67771+ struct file_operations trace_id;
67772+ struct file_operations trace_enable;
67773+ struct file_operations trace_format;
67774+ struct file_operations trace_filter;
67775 #endif
67776 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
67777 unsigned long *ftrace_callsites;
67778@@ -393,16 +398,46 @@ struct module *__module_address(unsigned long addr);
67779 bool is_module_address(unsigned long addr);
67780 bool is_module_text_address(unsigned long addr);
67781
67782+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
67783+{
67784+
67785+#ifdef CONFIG_PAX_KERNEXEC
67786+ if (ktla_ktva(addr) >= (unsigned long)start &&
67787+ ktla_ktva(addr) < (unsigned long)start + size)
67788+ return 1;
67789+#endif
67790+
67791+ return ((void *)addr >= start && (void *)addr < start + size);
67792+}
67793+
67794+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
67795+{
67796+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
67797+}
67798+
67799+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
67800+{
67801+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
67802+}
67803+
67804+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
67805+{
67806+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
67807+}
67808+
67809+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
67810+{
67811+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
67812+}
67813+
67814 static inline int within_module_core(unsigned long addr, struct module *mod)
67815 {
67816- return (unsigned long)mod->module_core <= addr &&
67817- addr < (unsigned long)mod->module_core + mod->core_size;
67818+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
67819 }
67820
67821 static inline int within_module_init(unsigned long addr, struct module *mod)
67822 {
67823- return (unsigned long)mod->module_init <= addr &&
67824- addr < (unsigned long)mod->module_init + mod->init_size;
67825+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
67826 }
67827
67828 /* Search for module by name: must hold module_mutex. */
67829diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
67830index c1f40c2..682ca53 100644
67831--- a/include/linux/moduleloader.h
67832+++ b/include/linux/moduleloader.h
67833@@ -20,9 +20,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
67834 sections. Returns NULL on failure. */
67835 void *module_alloc(unsigned long size);
67836
67837+#ifdef CONFIG_PAX_KERNEXEC
67838+void *module_alloc_exec(unsigned long size);
67839+#else
67840+#define module_alloc_exec(x) module_alloc(x)
67841+#endif
67842+
67843 /* Free memory returned from module_alloc. */
67844 void module_free(struct module *mod, void *module_region);
67845
67846+#ifdef CONFIG_PAX_KERNEXEC
67847+void module_free_exec(struct module *mod, void *module_region);
67848+#else
67849+#define module_free_exec(x, y) module_free((x), (y))
67850+#endif
67851+
67852 /* Apply the given relocation to the (simplified) ELF. Return -error
67853 or 0. */
67854 int apply_relocate(Elf_Shdr *sechdrs,
67855diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
67856index 82a9124..8a5f622 100644
67857--- a/include/linux/moduleparam.h
67858+++ b/include/linux/moduleparam.h
67859@@ -132,7 +132,7 @@ struct kparam_array
67860
67861 /* Actually copy string: maxlen param is usually sizeof(string). */
67862 #define module_param_string(name, string, len, perm) \
67863- static const struct kparam_string __param_string_##name \
67864+ static const struct kparam_string __param_string_##name __used \
67865 = { len, string }; \
67866 __module_param_call(MODULE_PARAM_PREFIX, name, \
67867 param_set_copystring, param_get_string, \
67868@@ -211,7 +211,7 @@ extern int param_get_invbool(char *buffer, struct kernel_param *kp);
67869
67870 /* Comma-separated array: *nump is set to number they actually specified. */
67871 #define module_param_array_named(name, array, type, nump, perm) \
67872- static const struct kparam_array __param_arr_##name \
67873+ static const struct kparam_array __param_arr_##name __used \
67874 = { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
67875 sizeof(array[0]), array }; \
67876 __module_param_call(MODULE_PARAM_PREFIX, name, \
67877diff --git a/include/linux/mutex.h b/include/linux/mutex.h
67878index 878cab4..c92cb3e 100644
67879--- a/include/linux/mutex.h
67880+++ b/include/linux/mutex.h
67881@@ -51,7 +51,7 @@ struct mutex {
67882 spinlock_t wait_lock;
67883 struct list_head wait_list;
67884 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
67885- struct thread_info *owner;
67886+ struct task_struct *owner;
67887 #endif
67888 #ifdef CONFIG_DEBUG_MUTEXES
67889 const char *name;
67890diff --git a/include/linux/namei.h b/include/linux/namei.h
67891index ec0f607..d19e675 100644
67892--- a/include/linux/namei.h
67893+++ b/include/linux/namei.h
67894@@ -22,7 +22,7 @@ struct nameidata {
67895 unsigned int flags;
67896 int last_type;
67897 unsigned depth;
67898- char *saved_names[MAX_NESTED_LINKS + 1];
67899+ const char *saved_names[MAX_NESTED_LINKS + 1];
67900
67901 /* Intent data */
67902 union {
67903@@ -84,12 +84,12 @@ extern int follow_up(struct path *);
67904 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
67905 extern void unlock_rename(struct dentry *, struct dentry *);
67906
67907-static inline void nd_set_link(struct nameidata *nd, char *path)
67908+static inline void nd_set_link(struct nameidata *nd, const char *path)
67909 {
67910 nd->saved_names[nd->depth] = path;
67911 }
67912
67913-static inline char *nd_get_link(struct nameidata *nd)
67914+static inline const char *nd_get_link(const struct nameidata *nd)
67915 {
67916 return nd->saved_names[nd->depth];
67917 }
67918diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
67919index 9d7e8f7..04428c5 100644
67920--- a/include/linux/netdevice.h
67921+++ b/include/linux/netdevice.h
67922@@ -637,6 +637,7 @@ struct net_device_ops {
67923 u16 xid);
67924 #endif
67925 };
67926+typedef struct net_device_ops __no_const net_device_ops_no_const;
67927
67928 /*
67929 * The DEVICE structure.
67930diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
67931new file mode 100644
67932index 0000000..33f4af8
67933--- /dev/null
67934+++ b/include/linux/netfilter/xt_gradm.h
67935@@ -0,0 +1,9 @@
67936+#ifndef _LINUX_NETFILTER_XT_GRADM_H
67937+#define _LINUX_NETFILTER_XT_GRADM_H 1
67938+
67939+struct xt_gradm_mtinfo {
67940+ __u16 flags;
67941+ __u16 invflags;
67942+};
67943+
67944+#endif
67945diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
67946index b359c4a..c08b334 100644
67947--- a/include/linux/nodemask.h
67948+++ b/include/linux/nodemask.h
67949@@ -464,11 +464,11 @@ static inline int num_node_state(enum node_states state)
67950
67951 #define any_online_node(mask) \
67952 ({ \
67953- int node; \
67954- for_each_node_mask(node, (mask)) \
67955- if (node_online(node)) \
67956+ int __node; \
67957+ for_each_node_mask(__node, (mask)) \
67958+ if (node_online(__node)) \
67959 break; \
67960- node; \
67961+ __node; \
67962 })
67963
67964 #define num_online_nodes() num_node_state(N_ONLINE)
67965diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
67966index 5171639..7cf4235 100644
67967--- a/include/linux/oprofile.h
67968+++ b/include/linux/oprofile.h
67969@@ -129,9 +129,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
67970 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
67971 char const * name, ulong * val);
67972
67973-/** Create a file for read-only access to an atomic_t. */
67974+/** Create a file for read-only access to an atomic_unchecked_t. */
67975 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
67976- char const * name, atomic_t * val);
67977+ char const * name, atomic_unchecked_t * val);
67978
67979 /** create a directory */
67980 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
67981diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
67982index 3c62ed4..8924c7c 100644
67983--- a/include/linux/pagemap.h
67984+++ b/include/linux/pagemap.h
67985@@ -425,7 +425,9 @@ static inline int fault_in_pages_readable(const char __user *uaddr, int size)
67986 if (((unsigned long)uaddr & PAGE_MASK) !=
67987 ((unsigned long)end & PAGE_MASK))
67988 ret = __get_user(c, end);
67989+ (void)c;
67990 }
67991+ (void)c;
67992 return ret;
67993 }
67994
67995diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
67996index 81c9689..a567a55 100644
67997--- a/include/linux/perf_event.h
67998+++ b/include/linux/perf_event.h
67999@@ -476,7 +476,7 @@ struct hw_perf_event {
68000 struct hrtimer hrtimer;
68001 };
68002 };
68003- atomic64_t prev_count;
68004+ atomic64_unchecked_t prev_count;
68005 u64 sample_period;
68006 u64 last_period;
68007 atomic64_t period_left;
68008@@ -557,7 +557,7 @@ struct perf_event {
68009 const struct pmu *pmu;
68010
68011 enum perf_event_active_state state;
68012- atomic64_t count;
68013+ atomic64_unchecked_t count;
68014
68015 /*
68016 * These are the total time in nanoseconds that the event
68017@@ -595,8 +595,8 @@ struct perf_event {
68018 * These accumulate total time (in nanoseconds) that children
68019 * events have been enabled and running, respectively.
68020 */
68021- atomic64_t child_total_time_enabled;
68022- atomic64_t child_total_time_running;
68023+ atomic64_unchecked_t child_total_time_enabled;
68024+ atomic64_unchecked_t child_total_time_running;
68025
68026 /*
68027 * Protect attach/detach and child_list:
68028diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
68029index b43a9e0..b77d869 100644
68030--- a/include/linux/pipe_fs_i.h
68031+++ b/include/linux/pipe_fs_i.h
68032@@ -46,9 +46,9 @@ struct pipe_inode_info {
68033 wait_queue_head_t wait;
68034 unsigned int nrbufs, curbuf;
68035 struct page *tmp_page;
68036- unsigned int readers;
68037- unsigned int writers;
68038- unsigned int waiting_writers;
68039+ atomic_t readers;
68040+ atomic_t writers;
68041+ atomic_t waiting_writers;
68042 unsigned int r_counter;
68043 unsigned int w_counter;
68044 struct fasync_struct *fasync_readers;
68045diff --git a/include/linux/poison.h b/include/linux/poison.h
68046index 34066ff..e95d744 100644
68047--- a/include/linux/poison.h
68048+++ b/include/linux/poison.h
68049@@ -19,8 +19,8 @@
68050 * under normal circumstances, used to verify that nobody uses
68051 * non-initialized list entries.
68052 */
68053-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
68054-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
68055+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
68056+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
68057
68058 /********** include/linux/timer.h **********/
68059 /*
68060diff --git a/include/linux/posix-timers.h b/include/linux/posix-timers.h
68061index 4f71bf4..77ffa64 100644
68062--- a/include/linux/posix-timers.h
68063+++ b/include/linux/posix-timers.h
68064@@ -67,7 +67,7 @@ struct k_itimer {
68065 };
68066
68067 struct k_clock {
68068- int res; /* in nanoseconds */
68069+ const int res; /* in nanoseconds */
68070 int (*clock_getres) (const clockid_t which_clock, struct timespec *tp);
68071 int (*clock_set) (const clockid_t which_clock, struct timespec * tp);
68072 int (*clock_get) (const clockid_t which_clock, struct timespec * tp);
68073diff --git a/include/linux/preempt.h b/include/linux/preempt.h
68074index 72b1a10..13303a9 100644
68075--- a/include/linux/preempt.h
68076+++ b/include/linux/preempt.h
68077@@ -110,7 +110,7 @@ struct preempt_ops {
68078 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
68079 void (*sched_out)(struct preempt_notifier *notifier,
68080 struct task_struct *next);
68081-};
68082+} __no_const;
68083
68084 /**
68085 * preempt_notifier - key for installing preemption notifiers
68086diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
68087index 379eaed..1bf73e3 100644
68088--- a/include/linux/proc_fs.h
68089+++ b/include/linux/proc_fs.h
68090@@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
68091 return proc_create_data(name, mode, parent, proc_fops, NULL);
68092 }
68093
68094+static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
68095+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
68096+{
68097+#ifdef CONFIG_GRKERNSEC_PROC_USER
68098+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
68099+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68100+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
68101+#else
68102+ return proc_create_data(name, mode, parent, proc_fops, NULL);
68103+#endif
68104+}
68105+
68106+
68107 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
68108 mode_t mode, struct proc_dir_entry *base,
68109 read_proc_t *read_proc, void * data)
68110@@ -256,7 +269,7 @@ union proc_op {
68111 int (*proc_show)(struct seq_file *m,
68112 struct pid_namespace *ns, struct pid *pid,
68113 struct task_struct *task);
68114-};
68115+} __no_const;
68116
68117 struct ctl_table_header;
68118 struct ctl_table;
68119diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
68120index 7456d7d..6c1cfc9 100644
68121--- a/include/linux/ptrace.h
68122+++ b/include/linux/ptrace.h
68123@@ -96,10 +96,10 @@ extern void __ptrace_unlink(struct task_struct *child);
68124 extern void exit_ptrace(struct task_struct *tracer);
68125 #define PTRACE_MODE_READ 1
68126 #define PTRACE_MODE_ATTACH 2
68127-/* Returns 0 on success, -errno on denial. */
68128-extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
68129 /* Returns true on success, false on denial. */
68130 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
68131+/* Returns true on success, false on denial. */
68132+extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
68133
68134 static inline int ptrace_reparented(struct task_struct *child)
68135 {
68136diff --git a/include/linux/random.h b/include/linux/random.h
68137index 2948046..3262567 100644
68138--- a/include/linux/random.h
68139+++ b/include/linux/random.h
68140@@ -63,6 +63,11 @@ unsigned long randomize_range(unsigned long start, unsigned long end, unsigned l
68141 u32 random32(void);
68142 void srandom32(u32 seed);
68143
68144+static inline unsigned long pax_get_random_long(void)
68145+{
68146+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
68147+}
68148+
68149 #endif /* __KERNEL___ */
68150
68151 #endif /* _LINUX_RANDOM_H */
68152diff --git a/include/linux/reboot.h b/include/linux/reboot.h
68153index 988e55f..17cb4ef 100644
68154--- a/include/linux/reboot.h
68155+++ b/include/linux/reboot.h
68156@@ -47,9 +47,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
68157 * Architecture-specific implementations of sys_reboot commands.
68158 */
68159
68160-extern void machine_restart(char *cmd);
68161-extern void machine_halt(void);
68162-extern void machine_power_off(void);
68163+extern void machine_restart(char *cmd) __noreturn;
68164+extern void machine_halt(void) __noreturn;
68165+extern void machine_power_off(void) __noreturn;
68166
68167 extern void machine_shutdown(void);
68168 struct pt_regs;
68169@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
68170 */
68171
68172 extern void kernel_restart_prepare(char *cmd);
68173-extern void kernel_restart(char *cmd);
68174-extern void kernel_halt(void);
68175-extern void kernel_power_off(void);
68176+extern void kernel_restart(char *cmd) __noreturn;
68177+extern void kernel_halt(void) __noreturn;
68178+extern void kernel_power_off(void) __noreturn;
68179
68180 void ctrl_alt_del(void);
68181
68182@@ -75,7 +75,7 @@ extern int orderly_poweroff(bool force);
68183 * Emergency restart, callable from an interrupt handler.
68184 */
68185
68186-extern void emergency_restart(void);
68187+extern void emergency_restart(void) __noreturn;
68188 #include <asm/emergency-restart.h>
68189
68190 #endif
68191diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
68192index dd31e7b..5b03c5c 100644
68193--- a/include/linux/reiserfs_fs.h
68194+++ b/include/linux/reiserfs_fs.h
68195@@ -1326,7 +1326,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
68196 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
68197
68198 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
68199-#define get_generation(s) atomic_read (&fs_generation(s))
68200+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
68201 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
68202 #define __fs_changed(gen,s) (gen != get_generation (s))
68203 #define fs_changed(gen,s) ({cond_resched(); __fs_changed(gen, s);})
68204@@ -1534,24 +1534,24 @@ static inline struct super_block *sb_from_bi(struct buffer_info *bi)
68205 */
68206
68207 struct item_operations {
68208- int (*bytes_number) (struct item_head * ih, int block_size);
68209- void (*decrement_key) (struct cpu_key *);
68210- int (*is_left_mergeable) (struct reiserfs_key * ih,
68211+ int (* const bytes_number) (struct item_head * ih, int block_size);
68212+ void (* const decrement_key) (struct cpu_key *);
68213+ int (* const is_left_mergeable) (struct reiserfs_key * ih,
68214 unsigned long bsize);
68215- void (*print_item) (struct item_head *, char *item);
68216- void (*check_item) (struct item_head *, char *item);
68217+ void (* const print_item) (struct item_head *, char *item);
68218+ void (* const check_item) (struct item_head *, char *item);
68219
68220- int (*create_vi) (struct virtual_node * vn, struct virtual_item * vi,
68221+ int (* const create_vi) (struct virtual_node * vn, struct virtual_item * vi,
68222 int is_affected, int insert_size);
68223- int (*check_left) (struct virtual_item * vi, int free,
68224+ int (* const check_left) (struct virtual_item * vi, int free,
68225 int start_skip, int end_skip);
68226- int (*check_right) (struct virtual_item * vi, int free);
68227- int (*part_size) (struct virtual_item * vi, int from, int to);
68228- int (*unit_num) (struct virtual_item * vi);
68229- void (*print_vi) (struct virtual_item * vi);
68230+ int (* const check_right) (struct virtual_item * vi, int free);
68231+ int (* const part_size) (struct virtual_item * vi, int from, int to);
68232+ int (* const unit_num) (struct virtual_item * vi);
68233+ void (* const print_vi) (struct virtual_item * vi);
68234 };
68235
68236-extern struct item_operations *item_ops[TYPE_ANY + 1];
68237+extern const struct item_operations * const item_ops[TYPE_ANY + 1];
68238
68239 #define op_bytes_number(ih,bsize) item_ops[le_ih_k_type (ih)]->bytes_number (ih, bsize)
68240 #define op_is_left_mergeable(key,bsize) item_ops[le_key_k_type (le_key_version (key), key)]->is_left_mergeable (key, bsize)
68241diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
68242index dab68bb..0688727 100644
68243--- a/include/linux/reiserfs_fs_sb.h
68244+++ b/include/linux/reiserfs_fs_sb.h
68245@@ -377,7 +377,7 @@ struct reiserfs_sb_info {
68246 /* Comment? -Hans */
68247 wait_queue_head_t s_wait;
68248 /* To be obsoleted soon by per buffer seals.. -Hans */
68249- atomic_t s_generation_counter; // increased by one every time the
68250+ atomic_unchecked_t s_generation_counter; // increased by one every time the
68251 // tree gets re-balanced
68252 unsigned long s_properties; /* File system properties. Currently holds
68253 on-disk FS format */
68254diff --git a/include/linux/relay.h b/include/linux/relay.h
68255index 14a86bc..17d0700 100644
68256--- a/include/linux/relay.h
68257+++ b/include/linux/relay.h
68258@@ -159,7 +159,7 @@ struct rchan_callbacks
68259 * The callback should return 0 if successful, negative if not.
68260 */
68261 int (*remove_buf_file)(struct dentry *dentry);
68262-};
68263+} __no_const;
68264
68265 /*
68266 * CONFIG_RELAY kernel API, kernel/relay.c
68267diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
68268index 3392c59..a746428 100644
68269--- a/include/linux/rfkill.h
68270+++ b/include/linux/rfkill.h
68271@@ -144,6 +144,7 @@ struct rfkill_ops {
68272 void (*query)(struct rfkill *rfkill, void *data);
68273 int (*set_block)(void *data, bool blocked);
68274 };
68275+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
68276
68277 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
68278 /**
68279diff --git a/include/linux/sched.h b/include/linux/sched.h
68280index 71849bf..40217dc 100644
68281--- a/include/linux/sched.h
68282+++ b/include/linux/sched.h
68283@@ -101,6 +101,7 @@ struct bio;
68284 struct fs_struct;
68285 struct bts_context;
68286 struct perf_event_context;
68287+struct linux_binprm;
68288
68289 /*
68290 * List of flags we want to share for kernel threads,
68291@@ -350,7 +351,7 @@ extern signed long schedule_timeout_killable(signed long timeout);
68292 extern signed long schedule_timeout_uninterruptible(signed long timeout);
68293 asmlinkage void __schedule(void);
68294 asmlinkage void schedule(void);
68295-extern int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner);
68296+extern int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner);
68297
68298 struct nsproxy;
68299 struct user_namespace;
68300@@ -371,9 +372,12 @@ struct user_namespace;
68301 #define DEFAULT_MAX_MAP_COUNT (USHORT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
68302
68303 extern int sysctl_max_map_count;
68304+extern unsigned long sysctl_heap_stack_gap;
68305
68306 #include <linux/aio.h>
68307
68308+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
68309+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
68310 extern unsigned long
68311 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
68312 unsigned long, unsigned long);
68313@@ -666,6 +670,16 @@ struct signal_struct {
68314 struct tty_audit_buf *tty_audit_buf;
68315 #endif
68316
68317+#ifdef CONFIG_GRKERNSEC
68318+ u32 curr_ip;
68319+ u32 saved_ip;
68320+ u32 gr_saddr;
68321+ u32 gr_daddr;
68322+ u16 gr_sport;
68323+ u16 gr_dport;
68324+ u8 used_accept:1;
68325+#endif
68326+
68327 int oom_adj; /* OOM kill score adjustment (bit shift) */
68328 };
68329
68330@@ -723,6 +737,11 @@ struct user_struct {
68331 struct key *session_keyring; /* UID's default session keyring */
68332 #endif
68333
68334+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
68335+ unsigned int banned;
68336+ unsigned long ban_expires;
68337+#endif
68338+
68339 /* Hash table maintenance information */
68340 struct hlist_node uidhash_node;
68341 uid_t uid;
68342@@ -1328,8 +1347,8 @@ struct task_struct {
68343 struct list_head thread_group;
68344
68345 struct completion *vfork_done; /* for vfork() */
68346- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
68347- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
68348+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
68349+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
68350
68351 cputime_t utime, stime, utimescaled, stimescaled;
68352 cputime_t gtime;
68353@@ -1343,16 +1362,6 @@ struct task_struct {
68354 struct task_cputime cputime_expires;
68355 struct list_head cpu_timers[3];
68356
68357-/* process credentials */
68358- const struct cred *real_cred; /* objective and real subjective task
68359- * credentials (COW) */
68360- const struct cred *cred; /* effective (overridable) subjective task
68361- * credentials (COW) */
68362- struct mutex cred_guard_mutex; /* guard against foreign influences on
68363- * credential calculations
68364- * (notably. ptrace) */
68365- struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
68366-
68367 char comm[TASK_COMM_LEN]; /* executable name excluding path
68368 - access with [gs]et_task_comm (which lock
68369 it with task_lock())
68370@@ -1369,6 +1378,10 @@ struct task_struct {
68371 #endif
68372 /* CPU-specific state of this task */
68373 struct thread_struct thread;
68374+/* thread_info moved to task_struct */
68375+#ifdef CONFIG_X86
68376+ struct thread_info tinfo;
68377+#endif
68378 /* filesystem information */
68379 struct fs_struct *fs;
68380 /* open file information */
68381@@ -1436,6 +1449,15 @@ struct task_struct {
68382 int hardirq_context;
68383 int softirq_context;
68384 #endif
68385+
68386+/* process credentials */
68387+ const struct cred *real_cred; /* objective and real subjective task
68388+ * credentials (COW) */
68389+ struct mutex cred_guard_mutex; /* guard against foreign influences on
68390+ * credential calculations
68391+ * (notably. ptrace) */
68392+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
68393+
68394 #ifdef CONFIG_LOCKDEP
68395 # define MAX_LOCK_DEPTH 48UL
68396 u64 curr_chain_key;
68397@@ -1456,6 +1478,9 @@ struct task_struct {
68398
68399 struct backing_dev_info *backing_dev_info;
68400
68401+ const struct cred *cred; /* effective (overridable) subjective task
68402+ * credentials (COW) */
68403+
68404 struct io_context *io_context;
68405
68406 unsigned long ptrace_message;
68407@@ -1519,6 +1544,21 @@ struct task_struct {
68408 unsigned long default_timer_slack_ns;
68409
68410 struct list_head *scm_work_list;
68411+
68412+#ifdef CONFIG_GRKERNSEC
68413+ /* grsecurity */
68414+ struct dentry *gr_chroot_dentry;
68415+ struct acl_subject_label *acl;
68416+ struct acl_role_label *role;
68417+ struct file *exec_file;
68418+ u16 acl_role_id;
68419+ /* is this the task that authenticated to the special role */
68420+ u8 acl_sp_role;
68421+ u8 is_writable;
68422+ u8 brute;
68423+ u8 gr_is_chrooted;
68424+#endif
68425+
68426 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
68427 /* Index of current stored adress in ret_stack */
68428 int curr_ret_stack;
68429@@ -1542,6 +1582,57 @@ struct task_struct {
68430 #endif /* CONFIG_TRACING */
68431 };
68432
68433+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
68434+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
68435+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
68436+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
68437+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
68438+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
68439+
68440+#ifdef CONFIG_PAX_SOFTMODE
68441+extern int pax_softmode;
68442+#endif
68443+
68444+extern int pax_check_flags(unsigned long *);
68445+
68446+/* if tsk != current then task_lock must be held on it */
68447+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
68448+static inline unsigned long pax_get_flags(struct task_struct *tsk)
68449+{
68450+ if (likely(tsk->mm))
68451+ return tsk->mm->pax_flags;
68452+ else
68453+ return 0UL;
68454+}
68455+
68456+/* if tsk != current then task_lock must be held on it */
68457+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
68458+{
68459+ if (likely(tsk->mm)) {
68460+ tsk->mm->pax_flags = flags;
68461+ return 0;
68462+ }
68463+ return -EINVAL;
68464+}
68465+#endif
68466+
68467+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68468+extern void pax_set_initial_flags(struct linux_binprm *bprm);
68469+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
68470+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
68471+#endif
68472+
68473+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
68474+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
68475+extern void pax_report_refcount_overflow(struct pt_regs *regs);
68476+extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
68477+
68478+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
68479+extern void pax_track_stack(void);
68480+#else
68481+static inline void pax_track_stack(void) {}
68482+#endif
68483+
68484 /* Future-safe accessor for struct task_struct's cpus_allowed. */
68485 #define tsk_cpumask(tsk) (&(tsk)->cpus_allowed)
68486
68487@@ -1740,7 +1831,7 @@ extern void thread_group_times(struct task_struct *p, cputime_t *ut, cputime_t *
68488 #define PF_DUMPCORE 0x00000200 /* dumped core */
68489 #define PF_SIGNALED 0x00000400 /* killed by a signal */
68490 #define PF_MEMALLOC 0x00000800 /* Allocating memory */
68491-#define PF_FLUSHER 0x00001000 /* responsible for disk writeback */
68492+#define PF_NPROC_EXCEEDED 0x00001000 /* set_user noticed that RLIMIT_NPROC was exceeded */
68493 #define PF_USED_MATH 0x00002000 /* if unset the fpu must be initialized before use */
68494 #define PF_FREEZING 0x00004000 /* freeze in progress. do not account to load */
68495 #define PF_NOFREEZE 0x00008000 /* this thread should not be frozen */
68496@@ -1978,7 +2069,9 @@ void yield(void);
68497 extern struct exec_domain default_exec_domain;
68498
68499 union thread_union {
68500+#ifndef CONFIG_X86
68501 struct thread_info thread_info;
68502+#endif
68503 unsigned long stack[THREAD_SIZE/sizeof(long)];
68504 };
68505
68506@@ -2011,6 +2104,7 @@ extern struct pid_namespace init_pid_ns;
68507 */
68508
68509 extern struct task_struct *find_task_by_vpid(pid_t nr);
68510+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
68511 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
68512 struct pid_namespace *ns);
68513
68514@@ -2155,7 +2249,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
68515 extern void exit_itimers(struct signal_struct *);
68516 extern void flush_itimer_signals(void);
68517
68518-extern NORET_TYPE void do_group_exit(int);
68519+extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
68520
68521 extern void daemonize(const char *, ...);
68522 extern int allow_signal(int);
68523@@ -2284,13 +2378,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
68524
68525 #endif
68526
68527-static inline int object_is_on_stack(void *obj)
68528+static inline int object_starts_on_stack(void *obj)
68529 {
68530- void *stack = task_stack_page(current);
68531+ const void *stack = task_stack_page(current);
68532
68533 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
68534 }
68535
68536+#ifdef CONFIG_PAX_USERCOPY
68537+extern int object_is_on_stack(const void *obj, unsigned long len);
68538+#endif
68539+
68540 extern void thread_info_cache_init(void);
68541
68542 #ifdef CONFIG_DEBUG_STACK_USAGE
68543diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
68544index 1ee2c05..81b7ec4 100644
68545--- a/include/linux/screen_info.h
68546+++ b/include/linux/screen_info.h
68547@@ -42,7 +42,8 @@ struct screen_info {
68548 __u16 pages; /* 0x32 */
68549 __u16 vesa_attributes; /* 0x34 */
68550 __u32 capabilities; /* 0x36 */
68551- __u8 _reserved[6]; /* 0x3a */
68552+ __u16 vesapm_size; /* 0x3a */
68553+ __u8 _reserved[4]; /* 0x3c */
68554 } __attribute__((packed));
68555
68556 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68557diff --git a/include/linux/security.h b/include/linux/security.h
68558index d40d23f..d739b08 100644
68559--- a/include/linux/security.h
68560+++ b/include/linux/security.h
68561@@ -34,6 +34,7 @@
68562 #include <linux/key.h>
68563 #include <linux/xfrm.h>
68564 #include <linux/gfp.h>
68565+#include <linux/grsecurity.h>
68566 #include <net/flow.h>
68567
68568 /* Maximum number of letters for an LSM name string */
68569@@ -76,7 +77,7 @@ extern int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
68570 extern int cap_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp);
68571 extern int cap_task_setioprio(struct task_struct *p, int ioprio);
68572 extern int cap_task_setnice(struct task_struct *p, int nice);
68573-extern int cap_syslog(int type);
68574+extern int cap_syslog(int type, bool from_file);
68575 extern int cap_vm_enough_memory(struct mm_struct *mm, long pages);
68576
68577 struct msghdr;
68578@@ -1331,6 +1332,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
68579 * logging to the console.
68580 * See the syslog(2) manual page for an explanation of the @type values.
68581 * @type contains the type of action.
68582+ * @from_file indicates the context of action (if it came from /proc).
68583 * Return 0 if permission is granted.
68584 * @settime:
68585 * Check permission to change the system time.
68586@@ -1445,7 +1447,7 @@ struct security_operations {
68587 int (*sysctl) (struct ctl_table *table, int op);
68588 int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
68589 int (*quota_on) (struct dentry *dentry);
68590- int (*syslog) (int type);
68591+ int (*syslog) (int type, bool from_file);
68592 int (*settime) (struct timespec *ts, struct timezone *tz);
68593 int (*vm_enough_memory) (struct mm_struct *mm, long pages);
68594
68595@@ -1740,7 +1742,7 @@ int security_acct(struct file *file);
68596 int security_sysctl(struct ctl_table *table, int op);
68597 int security_quotactl(int cmds, int type, int id, struct super_block *sb);
68598 int security_quota_on(struct dentry *dentry);
68599-int security_syslog(int type);
68600+int security_syslog(int type, bool from_file);
68601 int security_settime(struct timespec *ts, struct timezone *tz);
68602 int security_vm_enough_memory(long pages);
68603 int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
68604@@ -1986,9 +1988,9 @@ static inline int security_quota_on(struct dentry *dentry)
68605 return 0;
68606 }
68607
68608-static inline int security_syslog(int type)
68609+static inline int security_syslog(int type, bool from_file)
68610 {
68611- return cap_syslog(type);
68612+ return cap_syslog(type, from_file);
68613 }
68614
68615 static inline int security_settime(struct timespec *ts, struct timezone *tz)
68616diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
68617index 8366d8f..2307490 100644
68618--- a/include/linux/seq_file.h
68619+++ b/include/linux/seq_file.h
68620@@ -32,6 +32,7 @@ struct seq_operations {
68621 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
68622 int (*show) (struct seq_file *m, void *v);
68623 };
68624+typedef struct seq_operations __no_const seq_operations_no_const;
68625
68626 #define SEQ_SKIP 1
68627
68628diff --git a/include/linux/shm.h b/include/linux/shm.h
68629index eca6235..c7417ed 100644
68630--- a/include/linux/shm.h
68631+++ b/include/linux/shm.h
68632@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the kernel */
68633 pid_t shm_cprid;
68634 pid_t shm_lprid;
68635 struct user_struct *mlock_user;
68636+#ifdef CONFIG_GRKERNSEC
68637+ time_t shm_createtime;
68638+ pid_t shm_lapid;
68639+#endif
68640 };
68641
68642 /* shm_mode upper byte flags */
68643diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
68644index bcdd660..6e12e11 100644
68645--- a/include/linux/skbuff.h
68646+++ b/include/linux/skbuff.h
68647@@ -14,6 +14,7 @@
68648 #ifndef _LINUX_SKBUFF_H
68649 #define _LINUX_SKBUFF_H
68650
68651+#include <linux/const.h>
68652 #include <linux/kernel.h>
68653 #include <linux/kmemcheck.h>
68654 #include <linux/compiler.h>
68655@@ -544,7 +545,7 @@ static inline union skb_shared_tx *skb_tx(struct sk_buff *skb)
68656 */
68657 static inline int skb_queue_empty(const struct sk_buff_head *list)
68658 {
68659- return list->next == (struct sk_buff *)list;
68660+ return list->next == (const struct sk_buff *)list;
68661 }
68662
68663 /**
68664@@ -557,7 +558,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
68665 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
68666 const struct sk_buff *skb)
68667 {
68668- return (skb->next == (struct sk_buff *) list);
68669+ return (skb->next == (const struct sk_buff *) list);
68670 }
68671
68672 /**
68673@@ -570,7 +571,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
68674 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
68675 const struct sk_buff *skb)
68676 {
68677- return (skb->prev == (struct sk_buff *) list);
68678+ return (skb->prev == (const struct sk_buff *) list);
68679 }
68680
68681 /**
68682@@ -1367,7 +1368,7 @@ static inline int skb_network_offset(const struct sk_buff *skb)
68683 * headroom, you should not reduce this.
68684 */
68685 #ifndef NET_SKB_PAD
68686-#define NET_SKB_PAD 32
68687+#define NET_SKB_PAD (_AC(32,UL))
68688 #endif
68689
68690 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
68691diff --git a/include/linux/slab.h b/include/linux/slab.h
68692index 2da8372..a3be824 100644
68693--- a/include/linux/slab.h
68694+++ b/include/linux/slab.h
68695@@ -11,12 +11,20 @@
68696
68697 #include <linux/gfp.h>
68698 #include <linux/types.h>
68699+#include <linux/err.h>
68700
68701 /*
68702 * Flags to pass to kmem_cache_create().
68703 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
68704 */
68705 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
68706+
68707+#ifdef CONFIG_PAX_USERCOPY
68708+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
68709+#else
68710+#define SLAB_USERCOPY 0x00000000UL
68711+#endif
68712+
68713 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
68714 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
68715 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
68716@@ -82,10 +90,13 @@
68717 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
68718 * Both make kfree a no-op.
68719 */
68720-#define ZERO_SIZE_PTR ((void *)16)
68721+#define ZERO_SIZE_PTR \
68722+({ \
68723+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
68724+ (void *)(-MAX_ERRNO-1L); \
68725+})
68726
68727-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
68728- (unsigned long)ZERO_SIZE_PTR)
68729+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
68730
68731 /*
68732 * struct kmem_cache related prototypes
68733@@ -138,6 +149,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
68734 void kfree(const void *);
68735 void kzfree(const void *);
68736 size_t ksize(const void *);
68737+void check_object_size(const void *ptr, unsigned long n, bool to);
68738
68739 /*
68740 * Allocator specific definitions. These are mainly used to establish optimized
68741@@ -328,4 +340,37 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
68742
68743 void __init kmem_cache_init_late(void);
68744
68745+#define kmalloc(x, y) \
68746+({ \
68747+ void *___retval; \
68748+ intoverflow_t ___x = (intoverflow_t)x; \
68749+ if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n"))\
68750+ ___retval = NULL; \
68751+ else \
68752+ ___retval = kmalloc((size_t)___x, (y)); \
68753+ ___retval; \
68754+})
68755+
68756+#define kmalloc_node(x, y, z) \
68757+({ \
68758+ void *___retval; \
68759+ intoverflow_t ___x = (intoverflow_t)x; \
68760+ if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
68761+ ___retval = NULL; \
68762+ else \
68763+ ___retval = kmalloc_node((size_t)___x, (y), (z));\
68764+ ___retval; \
68765+})
68766+
68767+#define kzalloc(x, y) \
68768+({ \
68769+ void *___retval; \
68770+ intoverflow_t ___x = (intoverflow_t)x; \
68771+ if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n"))\
68772+ ___retval = NULL; \
68773+ else \
68774+ ___retval = kzalloc((size_t)___x, (y)); \
68775+ ___retval; \
68776+})
68777+
68778 #endif /* _LINUX_SLAB_H */
68779diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
68780index 850d057..d9dfe3c 100644
68781--- a/include/linux/slab_def.h
68782+++ b/include/linux/slab_def.h
68783@@ -69,10 +69,10 @@ struct kmem_cache {
68784 unsigned long node_allocs;
68785 unsigned long node_frees;
68786 unsigned long node_overflow;
68787- atomic_t allochit;
68788- atomic_t allocmiss;
68789- atomic_t freehit;
68790- atomic_t freemiss;
68791+ atomic_unchecked_t allochit;
68792+ atomic_unchecked_t allocmiss;
68793+ atomic_unchecked_t freehit;
68794+ atomic_unchecked_t freemiss;
68795
68796 /*
68797 * If debugging is enabled, then the allocator can add additional
68798diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
68799index 5ad70a6..57f9f65 100644
68800--- a/include/linux/slub_def.h
68801+++ b/include/linux/slub_def.h
68802@@ -86,7 +86,7 @@ struct kmem_cache {
68803 struct kmem_cache_order_objects max;
68804 struct kmem_cache_order_objects min;
68805 gfp_t allocflags; /* gfp flags to use on each alloc */
68806- int refcount; /* Refcount for slab cache destroy */
68807+ atomic_t refcount; /* Refcount for slab cache destroy */
68808 void (*ctor)(void *);
68809 int inuse; /* Offset to metadata */
68810 int align; /* Alignment */
68811@@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
68812 #endif
68813
68814 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
68815-void *__kmalloc(size_t size, gfp_t flags);
68816+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
68817
68818 #ifdef CONFIG_KMEMTRACE
68819 extern void *kmem_cache_alloc_notrace(struct kmem_cache *s, gfp_t gfpflags);
68820diff --git a/include/linux/sonet.h b/include/linux/sonet.h
68821index 67ad11f..0bbd8af 100644
68822--- a/include/linux/sonet.h
68823+++ b/include/linux/sonet.h
68824@@ -61,7 +61,7 @@ struct sonet_stats {
68825 #include <asm/atomic.h>
68826
68827 struct k_sonet_stats {
68828-#define __HANDLE_ITEM(i) atomic_t i
68829+#define __HANDLE_ITEM(i) atomic_unchecked_t i
68830 __SONET_ITEMS
68831 #undef __HANDLE_ITEM
68832 };
68833diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
68834index 6f52b4d..5500323 100644
68835--- a/include/linux/sunrpc/cache.h
68836+++ b/include/linux/sunrpc/cache.h
68837@@ -125,7 +125,7 @@ struct cache_detail {
68838 */
68839 struct cache_req {
68840 struct cache_deferred_req *(*defer)(struct cache_req *req);
68841-};
68842+} __no_const;
68843 /* this must be embedded in a deferred_request that is being
68844 * delayed awaiting cache-fill
68845 */
68846diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
68847index 8ed9642..101ceab 100644
68848--- a/include/linux/sunrpc/clnt.h
68849+++ b/include/linux/sunrpc/clnt.h
68850@@ -167,9 +167,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
68851 {
68852 switch (sap->sa_family) {
68853 case AF_INET:
68854- return ntohs(((struct sockaddr_in *)sap)->sin_port);
68855+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
68856 case AF_INET6:
68857- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
68858+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
68859 }
68860 return 0;
68861 }
68862@@ -202,7 +202,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
68863 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
68864 const struct sockaddr *src)
68865 {
68866- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
68867+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
68868 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
68869
68870 dsin->sin_family = ssin->sin_family;
68871@@ -299,7 +299,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
68872 if (sa->sa_family != AF_INET6)
68873 return 0;
68874
68875- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
68876+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
68877 }
68878
68879 #endif /* __KERNEL__ */
68880diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
68881index c14fe86..393245e 100644
68882--- a/include/linux/sunrpc/svc_rdma.h
68883+++ b/include/linux/sunrpc/svc_rdma.h
68884@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
68885 extern unsigned int svcrdma_max_requests;
68886 extern unsigned int svcrdma_max_req_size;
68887
68888-extern atomic_t rdma_stat_recv;
68889-extern atomic_t rdma_stat_read;
68890-extern atomic_t rdma_stat_write;
68891-extern atomic_t rdma_stat_sq_starve;
68892-extern atomic_t rdma_stat_rq_starve;
68893-extern atomic_t rdma_stat_rq_poll;
68894-extern atomic_t rdma_stat_rq_prod;
68895-extern atomic_t rdma_stat_sq_poll;
68896-extern atomic_t rdma_stat_sq_prod;
68897+extern atomic_unchecked_t rdma_stat_recv;
68898+extern atomic_unchecked_t rdma_stat_read;
68899+extern atomic_unchecked_t rdma_stat_write;
68900+extern atomic_unchecked_t rdma_stat_sq_starve;
68901+extern atomic_unchecked_t rdma_stat_rq_starve;
68902+extern atomic_unchecked_t rdma_stat_rq_poll;
68903+extern atomic_unchecked_t rdma_stat_rq_prod;
68904+extern atomic_unchecked_t rdma_stat_sq_poll;
68905+extern atomic_unchecked_t rdma_stat_sq_prod;
68906
68907 #define RPCRDMA_VERSION 1
68908
68909diff --git a/include/linux/suspend.h b/include/linux/suspend.h
68910index 5e781d8..1e62818 100644
68911--- a/include/linux/suspend.h
68912+++ b/include/linux/suspend.h
68913@@ -104,15 +104,15 @@ typedef int __bitwise suspend_state_t;
68914 * which require special recovery actions in that situation.
68915 */
68916 struct platform_suspend_ops {
68917- int (*valid)(suspend_state_t state);
68918- int (*begin)(suspend_state_t state);
68919- int (*prepare)(void);
68920- int (*prepare_late)(void);
68921- int (*enter)(suspend_state_t state);
68922- void (*wake)(void);
68923- void (*finish)(void);
68924- void (*end)(void);
68925- void (*recover)(void);
68926+ int (* const valid)(suspend_state_t state);
68927+ int (* const begin)(suspend_state_t state);
68928+ int (* const prepare)(void);
68929+ int (* const prepare_late)(void);
68930+ int (* const enter)(suspend_state_t state);
68931+ void (* const wake)(void);
68932+ void (* const finish)(void);
68933+ void (* const end)(void);
68934+ void (* const recover)(void);
68935 };
68936
68937 #ifdef CONFIG_SUSPEND
68938@@ -120,7 +120,7 @@ struct platform_suspend_ops {
68939 * suspend_set_ops - set platform dependent suspend operations
68940 * @ops: The new suspend operations to set.
68941 */
68942-extern void suspend_set_ops(struct platform_suspend_ops *ops);
68943+extern void suspend_set_ops(const struct platform_suspend_ops *ops);
68944 extern int suspend_valid_only_mem(suspend_state_t state);
68945
68946 /**
68947@@ -145,7 +145,7 @@ extern int pm_suspend(suspend_state_t state);
68948 #else /* !CONFIG_SUSPEND */
68949 #define suspend_valid_only_mem NULL
68950
68951-static inline void suspend_set_ops(struct platform_suspend_ops *ops) {}
68952+static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
68953 static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
68954 #endif /* !CONFIG_SUSPEND */
68955
68956@@ -215,16 +215,16 @@ extern void mark_free_pages(struct zone *zone);
68957 * platforms which require special recovery actions in that situation.
68958 */
68959 struct platform_hibernation_ops {
68960- int (*begin)(void);
68961- void (*end)(void);
68962- int (*pre_snapshot)(void);
68963- void (*finish)(void);
68964- int (*prepare)(void);
68965- int (*enter)(void);
68966- void (*leave)(void);
68967- int (*pre_restore)(void);
68968- void (*restore_cleanup)(void);
68969- void (*recover)(void);
68970+ int (* const begin)(void);
68971+ void (* const end)(void);
68972+ int (* const pre_snapshot)(void);
68973+ void (* const finish)(void);
68974+ int (* const prepare)(void);
68975+ int (* const enter)(void);
68976+ void (* const leave)(void);
68977+ int (* const pre_restore)(void);
68978+ void (* const restore_cleanup)(void);
68979+ void (* const recover)(void);
68980 };
68981
68982 #ifdef CONFIG_HIBERNATION
68983@@ -243,7 +243,7 @@ extern void swsusp_set_page_free(struct page *);
68984 extern void swsusp_unset_page_free(struct page *);
68985 extern unsigned long get_safe_page(gfp_t gfp_mask);
68986
68987-extern void hibernation_set_ops(struct platform_hibernation_ops *ops);
68988+extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
68989 extern int hibernate(void);
68990 extern bool system_entering_hibernation(void);
68991 #else /* CONFIG_HIBERNATION */
68992@@ -251,7 +251,7 @@ static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
68993 static inline void swsusp_set_page_free(struct page *p) {}
68994 static inline void swsusp_unset_page_free(struct page *p) {}
68995
68996-static inline void hibernation_set_ops(struct platform_hibernation_ops *ops) {}
68997+static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
68998 static inline int hibernate(void) { return -ENOSYS; }
68999 static inline bool system_entering_hibernation(void) { return false; }
69000 #endif /* CONFIG_HIBERNATION */
69001diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
69002index 0eb6942..a805cb6 100644
69003--- a/include/linux/sysctl.h
69004+++ b/include/linux/sysctl.h
69005@@ -164,7 +164,11 @@ enum
69006 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
69007 };
69008
69009-
69010+#ifdef CONFIG_PAX_SOFTMODE
69011+enum {
69012+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
69013+};
69014+#endif
69015
69016 /* CTL_VM names: */
69017 enum
69018@@ -982,6 +986,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
69019
69020 extern int proc_dostring(struct ctl_table *, int,
69021 void __user *, size_t *, loff_t *);
69022+extern int proc_dostring_modpriv(struct ctl_table *, int,
69023+ void __user *, size_t *, loff_t *);
69024 extern int proc_dointvec(struct ctl_table *, int,
69025 void __user *, size_t *, loff_t *);
69026 extern int proc_dointvec_minmax(struct ctl_table *, int,
69027@@ -1003,6 +1009,7 @@ extern int do_sysctl (int __user *name, int nlen,
69028
69029 extern ctl_handler sysctl_data;
69030 extern ctl_handler sysctl_string;
69031+extern ctl_handler sysctl_string_modpriv;
69032 extern ctl_handler sysctl_intvec;
69033 extern ctl_handler sysctl_jiffies;
69034 extern ctl_handler sysctl_ms_jiffies;
69035diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
69036index 9d68fed..71f02cc 100644
69037--- a/include/linux/sysfs.h
69038+++ b/include/linux/sysfs.h
69039@@ -75,8 +75,8 @@ struct bin_attribute {
69040 };
69041
69042 struct sysfs_ops {
69043- ssize_t (*show)(struct kobject *, struct attribute *,char *);
69044- ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
69045+ ssize_t (* const show)(struct kobject *, struct attribute *,char *);
69046+ ssize_t (* const store)(struct kobject *,struct attribute *,const char *, size_t);
69047 };
69048
69049 struct sysfs_dirent;
69050diff --git a/include/linux/syslog.h b/include/linux/syslog.h
69051new file mode 100644
69052index 0000000..3891139
69053--- /dev/null
69054+++ b/include/linux/syslog.h
69055@@ -0,0 +1,52 @@
69056+/* Syslog internals
69057+ *
69058+ * Copyright 2010 Canonical, Ltd.
69059+ * Author: Kees Cook <kees.cook@canonical.com>
69060+ *
69061+ * This program is free software; you can redistribute it and/or modify
69062+ * it under the terms of the GNU General Public License as published by
69063+ * the Free Software Foundation; either version 2, or (at your option)
69064+ * any later version.
69065+ *
69066+ * This program is distributed in the hope that it will be useful,
69067+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
69068+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69069+ * GNU General Public License for more details.
69070+ *
69071+ * You should have received a copy of the GNU General Public License
69072+ * along with this program; see the file COPYING. If not, write to
69073+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
69074+ */
69075+
69076+#ifndef _LINUX_SYSLOG_H
69077+#define _LINUX_SYSLOG_H
69078+
69079+/* Close the log. Currently a NOP. */
69080+#define SYSLOG_ACTION_CLOSE 0
69081+/* Open the log. Currently a NOP. */
69082+#define SYSLOG_ACTION_OPEN 1
69083+/* Read from the log. */
69084+#define SYSLOG_ACTION_READ 2
69085+/* Read all messages remaining in the ring buffer. */
69086+#define SYSLOG_ACTION_READ_ALL 3
69087+/* Read and clear all messages remaining in the ring buffer */
69088+#define SYSLOG_ACTION_READ_CLEAR 4
69089+/* Clear ring buffer. */
69090+#define SYSLOG_ACTION_CLEAR 5
69091+/* Disable printk's to console */
69092+#define SYSLOG_ACTION_CONSOLE_OFF 6
69093+/* Enable printk's to console */
69094+#define SYSLOG_ACTION_CONSOLE_ON 7
69095+/* Set level of messages printed to console */
69096+#define SYSLOG_ACTION_CONSOLE_LEVEL 8
69097+/* Return number of unread characters in the log buffer */
69098+#define SYSLOG_ACTION_SIZE_UNREAD 9
69099+/* Return size of the log buffer */
69100+#define SYSLOG_ACTION_SIZE_BUFFER 10
69101+
69102+#define SYSLOG_FROM_CALL 0
69103+#define SYSLOG_FROM_FILE 1
69104+
69105+int do_syslog(int type, char __user *buf, int count, bool from_file);
69106+
69107+#endif /* _LINUX_SYSLOG_H */
69108diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
69109index a8cc4e1..98d3b85 100644
69110--- a/include/linux/thread_info.h
69111+++ b/include/linux/thread_info.h
69112@@ -23,7 +23,7 @@ struct restart_block {
69113 };
69114 /* For futex_wait and futex_wait_requeue_pi */
69115 struct {
69116- u32 *uaddr;
69117+ u32 __user *uaddr;
69118 u32 val;
69119 u32 flags;
69120 u32 bitset;
69121diff --git a/include/linux/tty.h b/include/linux/tty.h
69122index e9c57e9..ee6d489 100644
69123--- a/include/linux/tty.h
69124+++ b/include/linux/tty.h
69125@@ -493,7 +493,6 @@ extern void tty_ldisc_begin(void);
69126 /* This last one is just for the tty layer internals and shouldn't be used elsewhere */
69127 extern void tty_ldisc_enable(struct tty_struct *tty);
69128
69129-
69130 /* n_tty.c */
69131 extern struct tty_ldisc_ops tty_ldisc_N_TTY;
69132
69133diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
69134index 0c4ee9b..9f7c426 100644
69135--- a/include/linux/tty_ldisc.h
69136+++ b/include/linux/tty_ldisc.h
69137@@ -139,7 +139,7 @@ struct tty_ldisc_ops {
69138
69139 struct module *owner;
69140
69141- int refcount;
69142+ atomic_t refcount;
69143 };
69144
69145 struct tty_ldisc {
69146diff --git a/include/linux/types.h b/include/linux/types.h
69147index c42724f..d190eee 100644
69148--- a/include/linux/types.h
69149+++ b/include/linux/types.h
69150@@ -191,10 +191,26 @@ typedef struct {
69151 volatile int counter;
69152 } atomic_t;
69153
69154+#ifdef CONFIG_PAX_REFCOUNT
69155+typedef struct {
69156+ volatile int counter;
69157+} atomic_unchecked_t;
69158+#else
69159+typedef atomic_t atomic_unchecked_t;
69160+#endif
69161+
69162 #ifdef CONFIG_64BIT
69163 typedef struct {
69164 volatile long counter;
69165 } atomic64_t;
69166+
69167+#ifdef CONFIG_PAX_REFCOUNT
69168+typedef struct {
69169+ volatile long counter;
69170+} atomic64_unchecked_t;
69171+#else
69172+typedef atomic64_t atomic64_unchecked_t;
69173+#endif
69174 #endif
69175
69176 struct ustat {
69177diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
69178index 6b58367..53a3e8e 100644
69179--- a/include/linux/uaccess.h
69180+++ b/include/linux/uaccess.h
69181@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
69182 long ret; \
69183 mm_segment_t old_fs = get_fs(); \
69184 \
69185- set_fs(KERNEL_DS); \
69186 pagefault_disable(); \
69187- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
69188- pagefault_enable(); \
69189+ set_fs(KERNEL_DS); \
69190+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
69191 set_fs(old_fs); \
69192+ pagefault_enable(); \
69193 ret; \
69194 })
69195
69196@@ -93,7 +93,7 @@ static inline unsigned long __copy_from_user_nocache(void *to,
69197 * Safely read from address @src to the buffer at @dst. If a kernel fault
69198 * happens, handle that and return -EFAULT.
69199 */
69200-extern long probe_kernel_read(void *dst, void *src, size_t size);
69201+extern long probe_kernel_read(void *dst, const void *src, size_t size);
69202
69203 /*
69204 * probe_kernel_write(): safely attempt to write to a location
69205@@ -104,6 +104,6 @@ extern long probe_kernel_read(void *dst, void *src, size_t size);
69206 * Safely write to address @dst from the buffer at @src. If a kernel fault
69207 * happens, handle that and return -EFAULT.
69208 */
69209-extern long probe_kernel_write(void *dst, void *src, size_t size);
69210+extern long probe_kernel_write(void *dst, const void *src, size_t size);
69211
69212 #endif /* __LINUX_UACCESS_H__ */
69213diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
69214index 99c1b4d..bb94261 100644
69215--- a/include/linux/unaligned/access_ok.h
69216+++ b/include/linux/unaligned/access_ok.h
69217@@ -6,32 +6,32 @@
69218
69219 static inline u16 get_unaligned_le16(const void *p)
69220 {
69221- return le16_to_cpup((__le16 *)p);
69222+ return le16_to_cpup((const __le16 *)p);
69223 }
69224
69225 static inline u32 get_unaligned_le32(const void *p)
69226 {
69227- return le32_to_cpup((__le32 *)p);
69228+ return le32_to_cpup((const __le32 *)p);
69229 }
69230
69231 static inline u64 get_unaligned_le64(const void *p)
69232 {
69233- return le64_to_cpup((__le64 *)p);
69234+ return le64_to_cpup((const __le64 *)p);
69235 }
69236
69237 static inline u16 get_unaligned_be16(const void *p)
69238 {
69239- return be16_to_cpup((__be16 *)p);
69240+ return be16_to_cpup((const __be16 *)p);
69241 }
69242
69243 static inline u32 get_unaligned_be32(const void *p)
69244 {
69245- return be32_to_cpup((__be32 *)p);
69246+ return be32_to_cpup((const __be32 *)p);
69247 }
69248
69249 static inline u64 get_unaligned_be64(const void *p)
69250 {
69251- return be64_to_cpup((__be64 *)p);
69252+ return be64_to_cpup((const __be64 *)p);
69253 }
69254
69255 static inline void put_unaligned_le16(u16 val, void *p)
69256diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
69257index 79b9837..b5a56f9 100644
69258--- a/include/linux/vermagic.h
69259+++ b/include/linux/vermagic.h
69260@@ -26,9 +26,35 @@
69261 #define MODULE_ARCH_VERMAGIC ""
69262 #endif
69263
69264+#ifdef CONFIG_PAX_REFCOUNT
69265+#define MODULE_PAX_REFCOUNT "REFCOUNT "
69266+#else
69267+#define MODULE_PAX_REFCOUNT ""
69268+#endif
69269+
69270+#ifdef CONSTIFY_PLUGIN
69271+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
69272+#else
69273+#define MODULE_CONSTIFY_PLUGIN ""
69274+#endif
69275+
69276+#ifdef STACKLEAK_PLUGIN
69277+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
69278+#else
69279+#define MODULE_STACKLEAK_PLUGIN ""
69280+#endif
69281+
69282+#ifdef CONFIG_GRKERNSEC
69283+#define MODULE_GRSEC "GRSEC "
69284+#else
69285+#define MODULE_GRSEC ""
69286+#endif
69287+
69288 #define VERMAGIC_STRING \
69289 UTS_RELEASE " " \
69290 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
69291 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
69292- MODULE_ARCH_VERMAGIC
69293+ MODULE_ARCH_VERMAGIC \
69294+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
69295+ MODULE_GRSEC
69296
69297diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
69298index 819a634..462ac12 100644
69299--- a/include/linux/vmalloc.h
69300+++ b/include/linux/vmalloc.h
69301@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
69302 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
69303 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
69304 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
69305+
69306+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
69307+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
69308+#endif
69309+
69310 /* bits [20..32] reserved for arch specific ioremap internals */
69311
69312 /*
69313@@ -124,4 +129,81 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
69314
69315 void pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms);
69316
69317+#define vmalloc(x) \
69318+({ \
69319+ void *___retval; \
69320+ intoverflow_t ___x = (intoverflow_t)x; \
69321+ if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
69322+ ___retval = NULL; \
69323+ else \
69324+ ___retval = vmalloc((unsigned long)___x); \
69325+ ___retval; \
69326+})
69327+
69328+#define __vmalloc(x, y, z) \
69329+({ \
69330+ void *___retval; \
69331+ intoverflow_t ___x = (intoverflow_t)x; \
69332+ if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
69333+ ___retval = NULL; \
69334+ else \
69335+ ___retval = __vmalloc((unsigned long)___x, (y), (z));\
69336+ ___retval; \
69337+})
69338+
69339+#define vmalloc_user(x) \
69340+({ \
69341+ void *___retval; \
69342+ intoverflow_t ___x = (intoverflow_t)x; \
69343+ if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
69344+ ___retval = NULL; \
69345+ else \
69346+ ___retval = vmalloc_user((unsigned long)___x); \
69347+ ___retval; \
69348+})
69349+
69350+#define vmalloc_exec(x) \
69351+({ \
69352+ void *___retval; \
69353+ intoverflow_t ___x = (intoverflow_t)x; \
69354+ if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
69355+ ___retval = NULL; \
69356+ else \
69357+ ___retval = vmalloc_exec((unsigned long)___x); \
69358+ ___retval; \
69359+})
69360+
69361+#define vmalloc_node(x, y) \
69362+({ \
69363+ void *___retval; \
69364+ intoverflow_t ___x = (intoverflow_t)x; \
69365+ if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
69366+ ___retval = NULL; \
69367+ else \
69368+ ___retval = vmalloc_node((unsigned long)___x, (y));\
69369+ ___retval; \
69370+})
69371+
69372+#define vmalloc_32(x) \
69373+({ \
69374+ void *___retval; \
69375+ intoverflow_t ___x = (intoverflow_t)x; \
69376+ if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
69377+ ___retval = NULL; \
69378+ else \
69379+ ___retval = vmalloc_32((unsigned long)___x); \
69380+ ___retval; \
69381+})
69382+
69383+#define vmalloc_32_user(x) \
69384+({ \
69385+ void *___retval; \
69386+ intoverflow_t ___x = (intoverflow_t)x; \
69387+ if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
69388+ ___retval = NULL; \
69389+ else \
69390+ ___retval = vmalloc_32_user((unsigned long)___x);\
69391+ ___retval; \
69392+})
69393+
69394 #endif /* _LINUX_VMALLOC_H */
69395diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
69396index 13070d6..aa4159a 100644
69397--- a/include/linux/vmstat.h
69398+++ b/include/linux/vmstat.h
69399@@ -136,18 +136,18 @@ static inline void vm_events_fold_cpu(int cpu)
69400 /*
69401 * Zone based page accounting with per cpu differentials.
69402 */
69403-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69404+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
69405
69406 static inline void zone_page_state_add(long x, struct zone *zone,
69407 enum zone_stat_item item)
69408 {
69409- atomic_long_add(x, &zone->vm_stat[item]);
69410- atomic_long_add(x, &vm_stat[item]);
69411+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
69412+ atomic_long_add_unchecked(x, &vm_stat[item]);
69413 }
69414
69415 static inline unsigned long global_page_state(enum zone_stat_item item)
69416 {
69417- long x = atomic_long_read(&vm_stat[item]);
69418+ long x = atomic_long_read_unchecked(&vm_stat[item]);
69419 #ifdef CONFIG_SMP
69420 if (x < 0)
69421 x = 0;
69422@@ -158,7 +158,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
69423 static inline unsigned long zone_page_state(struct zone *zone,
69424 enum zone_stat_item item)
69425 {
69426- long x = atomic_long_read(&zone->vm_stat[item]);
69427+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
69428 #ifdef CONFIG_SMP
69429 if (x < 0)
69430 x = 0;
69431@@ -175,7 +175,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
69432 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
69433 enum zone_stat_item item)
69434 {
69435- long x = atomic_long_read(&zone->vm_stat[item]);
69436+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
69437
69438 #ifdef CONFIG_SMP
69439 int cpu;
69440@@ -264,8 +264,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
69441
69442 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
69443 {
69444- atomic_long_inc(&zone->vm_stat[item]);
69445- atomic_long_inc(&vm_stat[item]);
69446+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
69447+ atomic_long_inc_unchecked(&vm_stat[item]);
69448 }
69449
69450 static inline void __inc_zone_page_state(struct page *page,
69451@@ -276,8 +276,8 @@ static inline void __inc_zone_page_state(struct page *page,
69452
69453 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
69454 {
69455- atomic_long_dec(&zone->vm_stat[item]);
69456- atomic_long_dec(&vm_stat[item]);
69457+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
69458+ atomic_long_dec_unchecked(&vm_stat[item]);
69459 }
69460
69461 static inline void __dec_zone_page_state(struct page *page,
69462diff --git a/include/linux/xattr.h b/include/linux/xattr.h
69463index 5c84af8..1a3b6e2 100644
69464--- a/include/linux/xattr.h
69465+++ b/include/linux/xattr.h
69466@@ -33,6 +33,11 @@
69467 #define XATTR_USER_PREFIX "user."
69468 #define XATTR_USER_PREFIX_LEN (sizeof (XATTR_USER_PREFIX) - 1)
69469
69470+/* User namespace */
69471+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
69472+#define XATTR_PAX_FLAGS_SUFFIX "flags"
69473+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
69474+
69475 struct inode;
69476 struct dentry;
69477
69478diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
69479index eed5fcc..5080d24 100644
69480--- a/include/media/saa7146_vv.h
69481+++ b/include/media/saa7146_vv.h
69482@@ -167,7 +167,7 @@ struct saa7146_ext_vv
69483 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
69484
69485 /* the extension can override this */
69486- struct v4l2_ioctl_ops ops;
69487+ v4l2_ioctl_ops_no_const ops;
69488 /* pointer to the saa7146 core ops */
69489 const struct v4l2_ioctl_ops *core_ops;
69490
69491diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
69492index 73c9867..2da8837 100644
69493--- a/include/media/v4l2-dev.h
69494+++ b/include/media/v4l2-dev.h
69495@@ -34,7 +34,7 @@ struct v4l2_device;
69496 #define V4L2_FL_UNREGISTERED (0)
69497
69498 struct v4l2_file_operations {
69499- struct module *owner;
69500+ struct module * const owner;
69501 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
69502 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
69503 unsigned int (*poll) (struct file *, struct poll_table_struct *);
69504@@ -46,6 +46,7 @@ struct v4l2_file_operations {
69505 int (*open) (struct file *);
69506 int (*release) (struct file *);
69507 };
69508+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
69509
69510 /*
69511 * Newer version of video_device, handled by videodev2.c
69512diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
69513index 5d5d550..f559ef1 100644
69514--- a/include/media/v4l2-device.h
69515+++ b/include/media/v4l2-device.h
69516@@ -71,7 +71,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
69517 this function returns 0. If the name ends with a digit (e.g. cx18),
69518 then the name will be set to cx18-0 since cx180 looks really odd. */
69519 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
69520- atomic_t *instance);
69521+ atomic_unchecked_t *instance);
69522
69523 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
69524 Since the parent disappears this ensures that v4l2_dev doesn't have an
69525diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
69526index 7a4529d..7244290 100644
69527--- a/include/media/v4l2-ioctl.h
69528+++ b/include/media/v4l2-ioctl.h
69529@@ -243,6 +243,7 @@ struct v4l2_ioctl_ops {
69530 long (*vidioc_default) (struct file *file, void *fh,
69531 int cmd, void *arg);
69532 };
69533+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
69534
69535
69536 /* v4l debugging and diagnostics */
69537diff --git a/include/net/flow.h b/include/net/flow.h
69538index 809970b..c3df4f3 100644
69539--- a/include/net/flow.h
69540+++ b/include/net/flow.h
69541@@ -92,7 +92,7 @@ typedef int (*flow_resolve_t)(struct net *net, struct flowi *key, u16 family,
69542 extern void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family,
69543 u8 dir, flow_resolve_t resolver);
69544 extern void flow_cache_flush(void);
69545-extern atomic_t flow_cache_genid;
69546+extern atomic_unchecked_t flow_cache_genid;
69547
69548 static inline int flow_cache_uli_match(struct flowi *fl1, struct flowi *fl2)
69549 {
69550diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
69551index 15e1f8fe..668837c 100644
69552--- a/include/net/inetpeer.h
69553+++ b/include/net/inetpeer.h
69554@@ -24,7 +24,7 @@ struct inet_peer
69555 __u32 dtime; /* the time of last use of not
69556 * referenced entries */
69557 atomic_t refcnt;
69558- atomic_t rid; /* Frag reception counter */
69559+ atomic_unchecked_t rid; /* Frag reception counter */
69560 __u32 tcp_ts;
69561 unsigned long tcp_ts_stamp;
69562 };
69563diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
69564index 98978e7..2243a3d 100644
69565--- a/include/net/ip_vs.h
69566+++ b/include/net/ip_vs.h
69567@@ -365,7 +365,7 @@ struct ip_vs_conn {
69568 struct ip_vs_conn *control; /* Master control connection */
69569 atomic_t n_control; /* Number of controlled ones */
69570 struct ip_vs_dest *dest; /* real server */
69571- atomic_t in_pkts; /* incoming packet counter */
69572+ atomic_unchecked_t in_pkts; /* incoming packet counter */
69573
69574 /* packet transmitter for different forwarding methods. If it
69575 mangles the packet, it must return NF_DROP or better NF_STOLEN,
69576@@ -466,7 +466,7 @@ struct ip_vs_dest {
69577 union nf_inet_addr addr; /* IP address of the server */
69578 __be16 port; /* port number of the server */
69579 volatile unsigned flags; /* dest status flags */
69580- atomic_t conn_flags; /* flags to copy to conn */
69581+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
69582 atomic_t weight; /* server weight */
69583
69584 atomic_t refcnt; /* reference counter */
69585diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
69586index 69b610a..fe3962c 100644
69587--- a/include/net/irda/ircomm_core.h
69588+++ b/include/net/irda/ircomm_core.h
69589@@ -51,7 +51,7 @@ typedef struct {
69590 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
69591 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
69592 struct ircomm_info *);
69593-} call_t;
69594+} __no_const call_t;
69595
69596 struct ircomm_cb {
69597 irda_queue_t queue;
69598diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
69599index eea2e61..08c692d 100644
69600--- a/include/net/irda/ircomm_tty.h
69601+++ b/include/net/irda/ircomm_tty.h
69602@@ -35,6 +35,7 @@
69603 #include <linux/termios.h>
69604 #include <linux/timer.h>
69605 #include <linux/tty.h> /* struct tty_struct */
69606+#include <asm/local.h>
69607
69608 #include <net/irda/irias_object.h>
69609 #include <net/irda/ircomm_core.h>
69610@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
69611 unsigned short close_delay;
69612 unsigned short closing_wait; /* time to wait before closing */
69613
69614- int open_count;
69615- int blocked_open; /* # of blocked opens */
69616+ local_t open_count;
69617+ local_t blocked_open; /* # of blocked opens */
69618
69619 /* Protect concurent access to :
69620 * o self->open_count
69621diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
69622index f82a1e8..82d81e8 100644
69623--- a/include/net/iucv/af_iucv.h
69624+++ b/include/net/iucv/af_iucv.h
69625@@ -87,7 +87,7 @@ struct iucv_sock {
69626 struct iucv_sock_list {
69627 struct hlist_head head;
69628 rwlock_t lock;
69629- atomic_t autobind_name;
69630+ atomic_unchecked_t autobind_name;
69631 };
69632
69633 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
69634diff --git a/include/net/lapb.h b/include/net/lapb.h
69635index 96cb5dd..25e8d4f 100644
69636--- a/include/net/lapb.h
69637+++ b/include/net/lapb.h
69638@@ -95,7 +95,7 @@ struct lapb_cb {
69639 struct sk_buff_head write_queue;
69640 struct sk_buff_head ack_queue;
69641 unsigned char window;
69642- struct lapb_register_struct callbacks;
69643+ struct lapb_register_struct *callbacks;
69644
69645 /* FRMR control information */
69646 struct lapb_frame frmr_data;
69647diff --git a/include/net/neighbour.h b/include/net/neighbour.h
69648index 3817fda..cdb2343 100644
69649--- a/include/net/neighbour.h
69650+++ b/include/net/neighbour.h
69651@@ -131,7 +131,7 @@ struct neigh_ops
69652 int (*connected_output)(struct sk_buff*);
69653 int (*hh_output)(struct sk_buff*);
69654 int (*queue_xmit)(struct sk_buff*);
69655-};
69656+} __do_const;
69657
69658 struct pneigh_entry
69659 {
69660diff --git a/include/net/netlink.h b/include/net/netlink.h
69661index c344646..4778c71 100644
69662--- a/include/net/netlink.h
69663+++ b/include/net/netlink.h
69664@@ -335,7 +335,7 @@ static inline int nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
69665 {
69666 return (remaining >= (int) sizeof(struct nlmsghdr) &&
69667 nlh->nlmsg_len >= sizeof(struct nlmsghdr) &&
69668- nlh->nlmsg_len <= remaining);
69669+ nlh->nlmsg_len <= (unsigned int)remaining);
69670 }
69671
69672 /**
69673@@ -558,7 +558,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
69674 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
69675 {
69676 if (mark)
69677- skb_trim(skb, (unsigned char *) mark - skb->data);
69678+ skb_trim(skb, (const unsigned char *) mark - skb->data);
69679 }
69680
69681 /**
69682diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
69683index 9a4b8b7..e49e077 100644
69684--- a/include/net/netns/ipv4.h
69685+++ b/include/net/netns/ipv4.h
69686@@ -54,7 +54,7 @@ struct netns_ipv4 {
69687 int current_rt_cache_rebuild_count;
69688
69689 struct timer_list rt_secret_timer;
69690- atomic_t rt_genid;
69691+ atomic_unchecked_t rt_genid;
69692
69693 #ifdef CONFIG_IP_MROUTE
69694 struct sock *mroute_sk;
69695diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
69696index 8a6d529..171f401 100644
69697--- a/include/net/sctp/sctp.h
69698+++ b/include/net/sctp/sctp.h
69699@@ -305,8 +305,8 @@ extern int sctp_debug_flag;
69700
69701 #else /* SCTP_DEBUG */
69702
69703-#define SCTP_DEBUG_PRINTK(whatever...)
69704-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
69705+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
69706+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
69707 #define SCTP_ENABLE_DEBUG
69708 #define SCTP_DISABLE_DEBUG
69709 #define SCTP_ASSERT(expr, str, func)
69710diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
69711index d97f689..f3b90ab 100644
69712--- a/include/net/secure_seq.h
69713+++ b/include/net/secure_seq.h
69714@@ -7,14 +7,14 @@ extern __u32 secure_ip_id(__be32 daddr);
69715 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
69716 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
69717 extern u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
69718- __be16 dport);
69719+ __be16 dport);
69720 extern __u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
69721 __be16 sport, __be16 dport);
69722 extern __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
69723- __be16 sport, __be16 dport);
69724+ __be16 sport, __be16 dport);
69725 extern u64 secure_dccp_sequence_number(__be32 saddr, __be32 daddr,
69726- __be16 sport, __be16 dport);
69727+ __be16 sport, __be16 dport);
69728 extern u64 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
69729- __be16 sport, __be16 dport);
69730+ __be16 sport, __be16 dport);
69731
69732 #endif /* _NET_SECURE_SEQ */
69733diff --git a/include/net/sock.h b/include/net/sock.h
69734index 9f96394..76fc9c7 100644
69735--- a/include/net/sock.h
69736+++ b/include/net/sock.h
69737@@ -272,7 +272,7 @@ struct sock {
69738 rwlock_t sk_callback_lock;
69739 int sk_err,
69740 sk_err_soft;
69741- atomic_t sk_drops;
69742+ atomic_unchecked_t sk_drops;
69743 unsigned short sk_ack_backlog;
69744 unsigned short sk_max_ack_backlog;
69745 __u32 sk_priority;
69746@@ -737,7 +737,7 @@ static inline void sk_refcnt_debug_release(const struct sock *sk)
69747 extern void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc);
69748 extern int sock_prot_inuse_get(struct net *net, struct proto *proto);
69749 #else
69750-static void inline sock_prot_inuse_add(struct net *net, struct proto *prot,
69751+static inline void sock_prot_inuse_add(struct net *net, struct proto *prot,
69752 int inc)
69753 {
69754 }
69755diff --git a/include/net/tcp.h b/include/net/tcp.h
69756index 6cfe18b..dd21acb 100644
69757--- a/include/net/tcp.h
69758+++ b/include/net/tcp.h
69759@@ -1444,8 +1444,8 @@ enum tcp_seq_states {
69760 struct tcp_seq_afinfo {
69761 char *name;
69762 sa_family_t family;
69763- struct file_operations seq_fops;
69764- struct seq_operations seq_ops;
69765+ file_operations_no_const seq_fops;
69766+ seq_operations_no_const seq_ops;
69767 };
69768
69769 struct tcp_iter_state {
69770diff --git a/include/net/udp.h b/include/net/udp.h
69771index f98abd2..b4b042f 100644
69772--- a/include/net/udp.h
69773+++ b/include/net/udp.h
69774@@ -187,8 +187,8 @@ struct udp_seq_afinfo {
69775 char *name;
69776 sa_family_t family;
69777 struct udp_table *udp_table;
69778- struct file_operations seq_fops;
69779- struct seq_operations seq_ops;
69780+ file_operations_no_const seq_fops;
69781+ seq_operations_no_const seq_ops;
69782 };
69783
69784 struct udp_iter_state {
69785diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
69786index cbb822e..e9c1cbe 100644
69787--- a/include/rdma/iw_cm.h
69788+++ b/include/rdma/iw_cm.h
69789@@ -129,7 +129,7 @@ struct iw_cm_verbs {
69790 int backlog);
69791
69792 int (*destroy_listen)(struct iw_cm_id *cm_id);
69793-};
69794+} __no_const;
69795
69796 /**
69797 * iw_create_cm_id - Create an IW CM identifier.
69798diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
69799index 09a124b..caa8ca8 100644
69800--- a/include/scsi/libfc.h
69801+++ b/include/scsi/libfc.h
69802@@ -675,6 +675,7 @@ struct libfc_function_template {
69803 */
69804 void (*disc_stop_final) (struct fc_lport *);
69805 };
69806+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
69807
69808 /* information used by the discovery layer */
69809 struct fc_disc {
69810@@ -707,7 +708,7 @@ struct fc_lport {
69811 struct fc_disc disc;
69812
69813 /* Operational Information */
69814- struct libfc_function_template tt;
69815+ libfc_function_template_no_const tt;
69816 u8 link_up;
69817 u8 qfull;
69818 enum fc_lport_state state;
69819diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
69820index de8e180..f15e0d7 100644
69821--- a/include/scsi/scsi_device.h
69822+++ b/include/scsi/scsi_device.h
69823@@ -156,9 +156,9 @@ struct scsi_device {
69824 unsigned int max_device_blocked; /* what device_blocked counts down from */
69825 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
69826
69827- atomic_t iorequest_cnt;
69828- atomic_t iodone_cnt;
69829- atomic_t ioerr_cnt;
69830+ atomic_unchecked_t iorequest_cnt;
69831+ atomic_unchecked_t iodone_cnt;
69832+ atomic_unchecked_t ioerr_cnt;
69833
69834 struct device sdev_gendev,
69835 sdev_dev;
69836diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
69837index fc50bd6..81ba9cb 100644
69838--- a/include/scsi/scsi_transport_fc.h
69839+++ b/include/scsi/scsi_transport_fc.h
69840@@ -708,7 +708,7 @@ struct fc_function_template {
69841 unsigned long show_host_system_hostname:1;
69842
69843 unsigned long disable_target_scan:1;
69844-};
69845+} __do_const;
69846
69847
69848 /**
69849diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
69850index 3dae3f7..8440d6f 100644
69851--- a/include/sound/ac97_codec.h
69852+++ b/include/sound/ac97_codec.h
69853@@ -419,15 +419,15 @@
69854 struct snd_ac97;
69855
69856 struct snd_ac97_build_ops {
69857- int (*build_3d) (struct snd_ac97 *ac97);
69858- int (*build_specific) (struct snd_ac97 *ac97);
69859- int (*build_spdif) (struct snd_ac97 *ac97);
69860- int (*build_post_spdif) (struct snd_ac97 *ac97);
69861+ int (* const build_3d) (struct snd_ac97 *ac97);
69862+ int (* const build_specific) (struct snd_ac97 *ac97);
69863+ int (* const build_spdif) (struct snd_ac97 *ac97);
69864+ int (* const build_post_spdif) (struct snd_ac97 *ac97);
69865 #ifdef CONFIG_PM
69866- void (*suspend) (struct snd_ac97 *ac97);
69867- void (*resume) (struct snd_ac97 *ac97);
69868+ void (* const suspend) (struct snd_ac97 *ac97);
69869+ void (* const resume) (struct snd_ac97 *ac97);
69870 #endif
69871- void (*update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
69872+ void (* const update_jacks) (struct snd_ac97 *ac97); /* for jack-sharing */
69873 };
69874
69875 struct snd_ac97_bus_ops {
69876@@ -477,7 +477,7 @@ struct snd_ac97_template {
69877
69878 struct snd_ac97 {
69879 /* -- lowlevel (hardware) driver specific -- */
69880- struct snd_ac97_build_ops * build_ops;
69881+ const struct snd_ac97_build_ops * build_ops;
69882 void *private_data;
69883 void (*private_free) (struct snd_ac97 *ac97);
69884 /* --- */
69885diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
69886index 891cf1a..a94ba2b 100644
69887--- a/include/sound/ak4xxx-adda.h
69888+++ b/include/sound/ak4xxx-adda.h
69889@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
69890 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
69891 unsigned char val);
69892 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
69893-};
69894+} __no_const;
69895
69896 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
69897
69898diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
69899index 8c05e47..2b5df97 100644
69900--- a/include/sound/hwdep.h
69901+++ b/include/sound/hwdep.h
69902@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
69903 struct snd_hwdep_dsp_status *status);
69904 int (*dsp_load)(struct snd_hwdep *hw,
69905 struct snd_hwdep_dsp_image *image);
69906-};
69907+} __no_const;
69908
69909 struct snd_hwdep {
69910 struct snd_card *card;
69911diff --git a/include/sound/info.h b/include/sound/info.h
69912index 112e894..6fda5b5 100644
69913--- a/include/sound/info.h
69914+++ b/include/sound/info.h
69915@@ -44,7 +44,7 @@ struct snd_info_entry_text {
69916 struct snd_info_buffer *buffer);
69917 void (*write)(struct snd_info_entry *entry,
69918 struct snd_info_buffer *buffer);
69919-};
69920+} __no_const;
69921
69922 struct snd_info_entry_ops {
69923 int (*open)(struct snd_info_entry *entry,
69924diff --git a/include/sound/pcm.h b/include/sound/pcm.h
69925index de6d981..590a550 100644
69926--- a/include/sound/pcm.h
69927+++ b/include/sound/pcm.h
69928@@ -80,6 +80,7 @@ struct snd_pcm_ops {
69929 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
69930 int (*ack)(struct snd_pcm_substream *substream);
69931 };
69932+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
69933
69934 /*
69935 *
69936diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
69937index 736eac7..fe8a80f 100644
69938--- a/include/sound/sb16_csp.h
69939+++ b/include/sound/sb16_csp.h
69940@@ -139,7 +139,7 @@ struct snd_sb_csp_ops {
69941 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
69942 int (*csp_stop) (struct snd_sb_csp * p);
69943 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
69944-};
69945+} __no_const;
69946
69947 /*
69948 * CSP private data
69949diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
69950index 444cd6b..3327cc5 100644
69951--- a/include/sound/ymfpci.h
69952+++ b/include/sound/ymfpci.h
69953@@ -358,7 +358,7 @@ struct snd_ymfpci {
69954 spinlock_t reg_lock;
69955 spinlock_t voice_lock;
69956 wait_queue_head_t interrupt_sleep;
69957- atomic_t interrupt_sleep_count;
69958+ atomic_unchecked_t interrupt_sleep_count;
69959 struct snd_info_entry *proc_entry;
69960 const struct firmware *dsp_microcode;
69961 const struct firmware *controller_microcode;
69962diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
69963index b89f9db..f097b38 100644
69964--- a/include/trace/events/irq.h
69965+++ b/include/trace/events/irq.h
69966@@ -34,7 +34,7 @@
69967 */
69968 TRACE_EVENT(irq_handler_entry,
69969
69970- TP_PROTO(int irq, struct irqaction *action),
69971+ TP_PROTO(int irq, const struct irqaction *action),
69972
69973 TP_ARGS(irq, action),
69974
69975@@ -64,7 +64,7 @@ TRACE_EVENT(irq_handler_entry,
69976 */
69977 TRACE_EVENT(irq_handler_exit,
69978
69979- TP_PROTO(int irq, struct irqaction *action, int ret),
69980+ TP_PROTO(int irq, const struct irqaction *action, int ret),
69981
69982 TP_ARGS(irq, action, ret),
69983
69984@@ -95,7 +95,7 @@ TRACE_EVENT(irq_handler_exit,
69985 */
69986 TRACE_EVENT(softirq_entry,
69987
69988- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
69989+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
69990
69991 TP_ARGS(h, vec),
69992
69993@@ -124,7 +124,7 @@ TRACE_EVENT(softirq_entry,
69994 */
69995 TRACE_EVENT(softirq_exit,
69996
69997- TP_PROTO(struct softirq_action *h, struct softirq_action *vec),
69998+ TP_PROTO(const struct softirq_action *h, const struct softirq_action *vec),
69999
70000 TP_ARGS(h, vec),
70001
70002diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
70003index 0993a22..32ba2fe 100644
70004--- a/include/video/uvesafb.h
70005+++ b/include/video/uvesafb.h
70006@@ -177,6 +177,7 @@ struct uvesafb_par {
70007 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
70008 u8 pmi_setpal; /* PMI for palette changes */
70009 u16 *pmi_base; /* protected mode interface location */
70010+ u8 *pmi_code; /* protected mode code location */
70011 void *pmi_start;
70012 void *pmi_pal;
70013 u8 *vbe_state_orig; /*
70014diff --git a/init/Kconfig b/init/Kconfig
70015index d72691b..3996e54 100644
70016--- a/init/Kconfig
70017+++ b/init/Kconfig
70018@@ -1004,7 +1004,7 @@ config SLUB_DEBUG
70019
70020 config COMPAT_BRK
70021 bool "Disable heap randomization"
70022- default y
70023+ default n
70024 help
70025 Randomizing heap placement makes heap exploits harder, but it
70026 also breaks ancient binaries (including anything libc5 based).
70027diff --git a/init/do_mounts.c b/init/do_mounts.c
70028index bb008d0..4fa3933 100644
70029--- a/init/do_mounts.c
70030+++ b/init/do_mounts.c
70031@@ -216,11 +216,11 @@ static void __init get_fs_names(char *page)
70032
70033 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
70034 {
70035- int err = sys_mount(name, "/root", fs, flags, data);
70036+ int err = sys_mount((__force char __user *)name, (__force char __user *)"/root", (__force char __user *)fs, flags, (__force void __user *)data);
70037 if (err)
70038 return err;
70039
70040- sys_chdir("/root");
70041+ sys_chdir((__force const char __user *)"/root");
70042 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
70043 printk("VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
70044 current->fs->pwd.mnt->mnt_sb->s_type->name,
70045@@ -311,18 +311,18 @@ void __init change_floppy(char *fmt, ...)
70046 va_start(args, fmt);
70047 vsprintf(buf, fmt, args);
70048 va_end(args);
70049- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
70050+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
70051 if (fd >= 0) {
70052 sys_ioctl(fd, FDEJECT, 0);
70053 sys_close(fd);
70054 }
70055 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
70056- fd = sys_open("/dev/console", O_RDWR, 0);
70057+ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
70058 if (fd >= 0) {
70059 sys_ioctl(fd, TCGETS, (long)&termios);
70060 termios.c_lflag &= ~ICANON;
70061 sys_ioctl(fd, TCSETSF, (long)&termios);
70062- sys_read(fd, &c, 1);
70063+ sys_read(fd, (char __user *)&c, 1);
70064 termios.c_lflag |= ICANON;
70065 sys_ioctl(fd, TCSETSF, (long)&termios);
70066 sys_close(fd);
70067@@ -416,6 +416,6 @@ void __init prepare_namespace(void)
70068 mount_root();
70069 out:
70070 devtmpfs_mount("dev");
70071- sys_mount(".", "/", NULL, MS_MOVE, NULL);
70072- sys_chroot(".");
70073+ sys_mount((__force char __user *)".", (__force char __user *)"/", NULL, MS_MOVE, NULL);
70074+ sys_chroot((__force char __user *)".");
70075 }
70076diff --git a/init/do_mounts.h b/init/do_mounts.h
70077index f5b978a..69dbfe8 100644
70078--- a/init/do_mounts.h
70079+++ b/init/do_mounts.h
70080@@ -15,15 +15,15 @@ extern int root_mountflags;
70081
70082 static inline int create_dev(char *name, dev_t dev)
70083 {
70084- sys_unlink(name);
70085- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
70086+ sys_unlink((char __force_user *)name);
70087+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
70088 }
70089
70090 #if BITS_PER_LONG == 32
70091 static inline u32 bstat(char *name)
70092 {
70093 struct stat64 stat;
70094- if (sys_stat64(name, &stat) != 0)
70095+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
70096 return 0;
70097 if (!S_ISBLK(stat.st_mode))
70098 return 0;
70099@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
70100 static inline u32 bstat(char *name)
70101 {
70102 struct stat stat;
70103- if (sys_newstat(name, &stat) != 0)
70104+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
70105 return 0;
70106 if (!S_ISBLK(stat.st_mode))
70107 return 0;
70108diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
70109index 614241b..4da046b 100644
70110--- a/init/do_mounts_initrd.c
70111+++ b/init/do_mounts_initrd.c
70112@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shell)
70113 sys_close(old_fd);sys_close(root_fd);
70114 sys_close(0);sys_close(1);sys_close(2);
70115 sys_setsid();
70116- (void) sys_open("/dev/console",O_RDWR,0);
70117+ (void) sys_open((__force const char __user *)"/dev/console",O_RDWR,0);
70118 (void) sys_dup(0);
70119 (void) sys_dup(0);
70120 return kernel_execve(shell, argv, envp_init);
70121@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
70122 create_dev("/dev/root.old", Root_RAM0);
70123 /* mount initrd on rootfs' /root */
70124 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
70125- sys_mkdir("/old", 0700);
70126- root_fd = sys_open("/", 0, 0);
70127- old_fd = sys_open("/old", 0, 0);
70128+ sys_mkdir((const char __force_user *)"/old", 0700);
70129+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
70130+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
70131 /* move initrd over / and chdir/chroot in initrd root */
70132- sys_chdir("/root");
70133- sys_mount(".", "/", NULL, MS_MOVE, NULL);
70134- sys_chroot(".");
70135+ sys_chdir((const char __force_user *)"/root");
70136+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
70137+ sys_chroot((const char __force_user *)".");
70138
70139 /*
70140 * In case that a resume from disk is carried out by linuxrc or one of
70141@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
70142
70143 /* move initrd to rootfs' /old */
70144 sys_fchdir(old_fd);
70145- sys_mount("/", ".", NULL, MS_MOVE, NULL);
70146+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
70147 /* switch root and cwd back to / of rootfs */
70148 sys_fchdir(root_fd);
70149- sys_chroot(".");
70150+ sys_chroot((const char __force_user *)".");
70151 sys_close(old_fd);
70152 sys_close(root_fd);
70153
70154 if (new_decode_dev(real_root_dev) == Root_RAM0) {
70155- sys_chdir("/old");
70156+ sys_chdir((const char __force_user *)"/old");
70157 return;
70158 }
70159
70160@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
70161 mount_root();
70162
70163 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
70164- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
70165+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
70166 if (!error)
70167 printk("okay\n");
70168 else {
70169- int fd = sys_open("/dev/root.old", O_RDWR, 0);
70170+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
70171 if (error == -ENOENT)
70172 printk("/initrd does not exist. Ignored.\n");
70173 else
70174 printk("failed\n");
70175 printk(KERN_NOTICE "Unmounting old root\n");
70176- sys_umount("/old", MNT_DETACH);
70177+ sys_umount((char __force_user *)"/old", MNT_DETACH);
70178 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
70179 if (fd < 0) {
70180 error = fd;
70181@@ -119,11 +119,11 @@ int __init initrd_load(void)
70182 * mounted in the normal path.
70183 */
70184 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
70185- sys_unlink("/initrd.image");
70186+ sys_unlink((const char __force_user *)"/initrd.image");
70187 handle_initrd();
70188 return 1;
70189 }
70190 }
70191- sys_unlink("/initrd.image");
70192+ sys_unlink((const char __force_user *)"/initrd.image");
70193 return 0;
70194 }
70195diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
70196index 69aebbf..c0bf6a7 100644
70197--- a/init/do_mounts_md.c
70198+++ b/init/do_mounts_md.c
70199@@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
70200 partitioned ? "_d" : "", minor,
70201 md_setup_args[ent].device_names);
70202
70203- fd = sys_open(name, 0, 0);
70204+ fd = sys_open((char __force_user *)name, 0, 0);
70205 if (fd < 0) {
70206 printk(KERN_ERR "md: open failed - cannot start "
70207 "array %s\n", name);
70208@@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
70209 * array without it
70210 */
70211 sys_close(fd);
70212- fd = sys_open(name, 0, 0);
70213+ fd = sys_open((char __force_user *)name, 0, 0);
70214 sys_ioctl(fd, BLKRRPART, 0);
70215 }
70216 sys_close(fd);
70217@@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
70218
70219 wait_for_device_probe();
70220
70221- fd = sys_open("/dev/md0", 0, 0);
70222+ fd = sys_open((__force char __user *)"/dev/md0", 0, 0);
70223 if (fd >= 0) {
70224 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
70225 sys_close(fd);
70226diff --git a/init/initramfs.c b/init/initramfs.c
70227index 1fd59b8..a01b079 100644
70228--- a/init/initramfs.c
70229+++ b/init/initramfs.c
70230@@ -74,7 +74,7 @@ static void __init free_hash(void)
70231 }
70232 }
70233
70234-static long __init do_utime(char __user *filename, time_t mtime)
70235+static long __init do_utime(__force char __user *filename, time_t mtime)
70236 {
70237 struct timespec t[2];
70238
70239@@ -109,7 +109,7 @@ static void __init dir_utime(void)
70240 struct dir_entry *de, *tmp;
70241 list_for_each_entry_safe(de, tmp, &dir_list, list) {
70242 list_del(&de->list);
70243- do_utime(de->name, de->mtime);
70244+ do_utime((char __force_user *)de->name, de->mtime);
70245 kfree(de->name);
70246 kfree(de);
70247 }
70248@@ -271,7 +271,7 @@ static int __init maybe_link(void)
70249 if (nlink >= 2) {
70250 char *old = find_link(major, minor, ino, mode, collected);
70251 if (old)
70252- return (sys_link(old, collected) < 0) ? -1 : 1;
70253+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
70254 }
70255 return 0;
70256 }
70257@@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
70258 {
70259 struct stat st;
70260
70261- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
70262+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
70263 if (S_ISDIR(st.st_mode))
70264- sys_rmdir(path);
70265+ sys_rmdir((char __force_user *)path);
70266 else
70267- sys_unlink(path);
70268+ sys_unlink((char __force_user *)path);
70269 }
70270 }
70271
70272@@ -305,7 +305,7 @@ static int __init do_name(void)
70273 int openflags = O_WRONLY|O_CREAT;
70274 if (ml != 1)
70275 openflags |= O_TRUNC;
70276- wfd = sys_open(collected, openflags, mode);
70277+ wfd = sys_open((char __force_user *)collected, openflags, mode);
70278
70279 if (wfd >= 0) {
70280 sys_fchown(wfd, uid, gid);
70281@@ -317,17 +317,17 @@ static int __init do_name(void)
70282 }
70283 }
70284 } else if (S_ISDIR(mode)) {
70285- sys_mkdir(collected, mode);
70286- sys_chown(collected, uid, gid);
70287- sys_chmod(collected, mode);
70288+ sys_mkdir((char __force_user *)collected, mode);
70289+ sys_chown((char __force_user *)collected, uid, gid);
70290+ sys_chmod((char __force_user *)collected, mode);
70291 dir_add(collected, mtime);
70292 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
70293 S_ISFIFO(mode) || S_ISSOCK(mode)) {
70294 if (maybe_link() == 0) {
70295- sys_mknod(collected, mode, rdev);
70296- sys_chown(collected, uid, gid);
70297- sys_chmod(collected, mode);
70298- do_utime(collected, mtime);
70299+ sys_mknod((char __force_user *)collected, mode, rdev);
70300+ sys_chown((char __force_user *)collected, uid, gid);
70301+ sys_chmod((char __force_user *)collected, mode);
70302+ do_utime((char __force_user *)collected, mtime);
70303 }
70304 }
70305 return 0;
70306@@ -336,15 +336,15 @@ static int __init do_name(void)
70307 static int __init do_copy(void)
70308 {
70309 if (count >= body_len) {
70310- sys_write(wfd, victim, body_len);
70311+ sys_write(wfd, (char __force_user *)victim, body_len);
70312 sys_close(wfd);
70313- do_utime(vcollected, mtime);
70314+ do_utime((char __force_user *)vcollected, mtime);
70315 kfree(vcollected);
70316 eat(body_len);
70317 state = SkipIt;
70318 return 0;
70319 } else {
70320- sys_write(wfd, victim, count);
70321+ sys_write(wfd, (char __force_user *)victim, count);
70322 body_len -= count;
70323 eat(count);
70324 return 1;
70325@@ -355,9 +355,9 @@ static int __init do_symlink(void)
70326 {
70327 collected[N_ALIGN(name_len) + body_len] = '\0';
70328 clean_path(collected, 0);
70329- sys_symlink(collected + N_ALIGN(name_len), collected);
70330- sys_lchown(collected, uid, gid);
70331- do_utime(collected, mtime);
70332+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
70333+ sys_lchown((char __force_user *)collected, uid, gid);
70334+ do_utime((char __force_user *)collected, mtime);
70335 state = SkipIt;
70336 next_state = Reset;
70337 return 0;
70338diff --git a/init/main.c b/init/main.c
70339index 1eb4bd5..da8c6f5 100644
70340--- a/init/main.c
70341+++ b/init/main.c
70342@@ -97,6 +97,7 @@ static inline void mark_rodata_ro(void) { }
70343 #ifdef CONFIG_TC
70344 extern void tc_init(void);
70345 #endif
70346+extern void grsecurity_init(void);
70347
70348 enum system_states system_state __read_mostly;
70349 EXPORT_SYMBOL(system_state);
70350@@ -183,6 +184,49 @@ static int __init set_reset_devices(char *str)
70351
70352 __setup("reset_devices", set_reset_devices);
70353
70354+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
70355+extern char pax_enter_kernel_user[];
70356+extern char pax_exit_kernel_user[];
70357+extern pgdval_t clone_pgd_mask;
70358+#endif
70359+
70360+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
70361+static int __init setup_pax_nouderef(char *str)
70362+{
70363+#ifdef CONFIG_X86_32
70364+ unsigned int cpu;
70365+ struct desc_struct *gdt;
70366+
70367+ for (cpu = 0; cpu < NR_CPUS; cpu++) {
70368+ gdt = get_cpu_gdt_table(cpu);
70369+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
70370+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
70371+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
70372+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
70373+ }
70374+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
70375+#else
70376+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
70377+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
70378+ clone_pgd_mask = ~(pgdval_t)0UL;
70379+#endif
70380+
70381+ return 0;
70382+}
70383+early_param("pax_nouderef", setup_pax_nouderef);
70384+#endif
70385+
70386+#ifdef CONFIG_PAX_SOFTMODE
70387+int pax_softmode;
70388+
70389+static int __init setup_pax_softmode(char *str)
70390+{
70391+ get_option(&str, &pax_softmode);
70392+ return 1;
70393+}
70394+__setup("pax_softmode=", setup_pax_softmode);
70395+#endif
70396+
70397 static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
70398 char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
70399 static const char *panic_later, *panic_param;
70400@@ -705,52 +749,53 @@ int initcall_debug;
70401 core_param(initcall_debug, initcall_debug, bool, 0644);
70402
70403 static char msgbuf[64];
70404-static struct boot_trace_call call;
70405-static struct boot_trace_ret ret;
70406+static struct boot_trace_call trace_call;
70407+static struct boot_trace_ret trace_ret;
70408
70409 int do_one_initcall(initcall_t fn)
70410 {
70411 int count = preempt_count();
70412 ktime_t calltime, delta, rettime;
70413+ const char *msg1 = "", *msg2 = "";
70414
70415 if (initcall_debug) {
70416- call.caller = task_pid_nr(current);
70417- printk("calling %pF @ %i\n", fn, call.caller);
70418+ trace_call.caller = task_pid_nr(current);
70419+ printk("calling %pF @ %i\n", fn, trace_call.caller);
70420 calltime = ktime_get();
70421- trace_boot_call(&call, fn);
70422+ trace_boot_call(&trace_call, fn);
70423 enable_boot_trace();
70424 }
70425
70426- ret.result = fn();
70427+ trace_ret.result = fn();
70428
70429 if (initcall_debug) {
70430 disable_boot_trace();
70431 rettime = ktime_get();
70432 delta = ktime_sub(rettime, calltime);
70433- ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
70434- trace_boot_ret(&ret, fn);
70435+ trace_ret.duration = (unsigned long long) ktime_to_ns(delta) >> 10;
70436+ trace_boot_ret(&trace_ret, fn);
70437 printk("initcall %pF returned %d after %Ld usecs\n", fn,
70438- ret.result, ret.duration);
70439+ trace_ret.result, trace_ret.duration);
70440 }
70441
70442 msgbuf[0] = 0;
70443
70444- if (ret.result && ret.result != -ENODEV && initcall_debug)
70445- sprintf(msgbuf, "error code %d ", ret.result);
70446+ if (trace_ret.result && trace_ret.result != -ENODEV && initcall_debug)
70447+ sprintf(msgbuf, "error code %d ", trace_ret.result);
70448
70449 if (preempt_count() != count) {
70450- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
70451+ msg1 = " preemption imbalance";
70452 preempt_count() = count;
70453 }
70454 if (irqs_disabled()) {
70455- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
70456+ msg2 = " disabled interrupts";
70457 local_irq_enable();
70458 }
70459- if (msgbuf[0]) {
70460- printk("initcall %pF returned with %s\n", fn, msgbuf);
70461+ if (msgbuf[0] || *msg1 || *msg2) {
70462+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
70463 }
70464
70465- return ret.result;
70466+ return trace_ret.result;
70467 }
70468
70469
70470@@ -893,11 +938,13 @@ static int __init kernel_init(void * unused)
70471 if (!ramdisk_execute_command)
70472 ramdisk_execute_command = "/init";
70473
70474- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
70475+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
70476 ramdisk_execute_command = NULL;
70477 prepare_namespace();
70478 }
70479
70480+ grsecurity_init();
70481+
70482 /*
70483 * Ok, we have completed the initial bootup, and
70484 * we're essentially up and running. Get rid of the
70485diff --git a/init/noinitramfs.c b/init/noinitramfs.c
70486index f4c1a3a..96c19bd 100644
70487--- a/init/noinitramfs.c
70488+++ b/init/noinitramfs.c
70489@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
70490 {
70491 int err;
70492
70493- err = sys_mkdir("/dev", 0755);
70494+ err = sys_mkdir((const char __user *)"/dev", 0755);
70495 if (err < 0)
70496 goto out;
70497
70498@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
70499 if (err < 0)
70500 goto out;
70501
70502- err = sys_mkdir("/root", 0700);
70503+ err = sys_mkdir((const char __user *)"/root", 0700);
70504 if (err < 0)
70505 goto out;
70506
70507diff --git a/ipc/mqueue.c b/ipc/mqueue.c
70508index d01bc14..8df81db 100644
70509--- a/ipc/mqueue.c
70510+++ b/ipc/mqueue.c
70511@@ -150,6 +150,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
70512 mq_bytes = (mq_msg_tblsz +
70513 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
70514
70515+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
70516 spin_lock(&mq_lock);
70517 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
70518 u->mq_bytes + mq_bytes >
70519diff --git a/ipc/msg.c b/ipc/msg.c
70520index 779f762..4af9e36 100644
70521--- a/ipc/msg.c
70522+++ b/ipc/msg.c
70523@@ -310,18 +310,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
70524 return security_msg_queue_associate(msq, msgflg);
70525 }
70526
70527+static struct ipc_ops msg_ops = {
70528+ .getnew = newque,
70529+ .associate = msg_security,
70530+ .more_checks = NULL
70531+};
70532+
70533 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
70534 {
70535 struct ipc_namespace *ns;
70536- struct ipc_ops msg_ops;
70537 struct ipc_params msg_params;
70538
70539 ns = current->nsproxy->ipc_ns;
70540
70541- msg_ops.getnew = newque;
70542- msg_ops.associate = msg_security;
70543- msg_ops.more_checks = NULL;
70544-
70545 msg_params.key = key;
70546 msg_params.flg = msgflg;
70547
70548diff --git a/ipc/sem.c b/ipc/sem.c
70549index b781007..f738b04 100644
70550--- a/ipc/sem.c
70551+++ b/ipc/sem.c
70552@@ -309,10 +309,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
70553 return 0;
70554 }
70555
70556+static struct ipc_ops sem_ops = {
70557+ .getnew = newary,
70558+ .associate = sem_security,
70559+ .more_checks = sem_more_checks
70560+};
70561+
70562 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
70563 {
70564 struct ipc_namespace *ns;
70565- struct ipc_ops sem_ops;
70566 struct ipc_params sem_params;
70567
70568 ns = current->nsproxy->ipc_ns;
70569@@ -320,10 +325,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
70570 if (nsems < 0 || nsems > ns->sc_semmsl)
70571 return -EINVAL;
70572
70573- sem_ops.getnew = newary;
70574- sem_ops.associate = sem_security;
70575- sem_ops.more_checks = sem_more_checks;
70576-
70577 sem_params.key = key;
70578 sem_params.flg = semflg;
70579 sem_params.u.nsems = nsems;
70580@@ -671,6 +672,8 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
70581 ushort* sem_io = fast_sem_io;
70582 int nsems;
70583
70584+ pax_track_stack();
70585+
70586 sma = sem_lock_check(ns, semid);
70587 if (IS_ERR(sma))
70588 return PTR_ERR(sma);
70589@@ -1071,6 +1074,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
70590 unsigned long jiffies_left = 0;
70591 struct ipc_namespace *ns;
70592
70593+ pax_track_stack();
70594+
70595 ns = current->nsproxy->ipc_ns;
70596
70597 if (nsops < 1 || semid < 0)
70598diff --git a/ipc/shm.c b/ipc/shm.c
70599index d30732c..7379456 100644
70600--- a/ipc/shm.c
70601+++ b/ipc/shm.c
70602@@ -70,6 +70,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
70603 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
70604 #endif
70605
70606+#ifdef CONFIG_GRKERNSEC
70607+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70608+ const time_t shm_createtime, const uid_t cuid,
70609+ const int shmid);
70610+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
70611+ const time_t shm_createtime);
70612+#endif
70613+
70614 void shm_init_ns(struct ipc_namespace *ns)
70615 {
70616 ns->shm_ctlmax = SHMMAX;
70617@@ -396,6 +404,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
70618 shp->shm_lprid = 0;
70619 shp->shm_atim = shp->shm_dtim = 0;
70620 shp->shm_ctim = get_seconds();
70621+#ifdef CONFIG_GRKERNSEC
70622+ {
70623+ struct timespec timeval;
70624+ do_posix_clock_monotonic_gettime(&timeval);
70625+
70626+ shp->shm_createtime = timeval.tv_sec;
70627+ }
70628+#endif
70629 shp->shm_segsz = size;
70630 shp->shm_nattch = 0;
70631 shp->shm_file = file;
70632@@ -446,18 +462,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
70633 return 0;
70634 }
70635
70636+static struct ipc_ops shm_ops = {
70637+ .getnew = newseg,
70638+ .associate = shm_security,
70639+ .more_checks = shm_more_checks
70640+};
70641+
70642 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
70643 {
70644 struct ipc_namespace *ns;
70645- struct ipc_ops shm_ops;
70646 struct ipc_params shm_params;
70647
70648 ns = current->nsproxy->ipc_ns;
70649
70650- shm_ops.getnew = newseg;
70651- shm_ops.associate = shm_security;
70652- shm_ops.more_checks = shm_more_checks;
70653-
70654 shm_params.key = key;
70655 shm_params.flg = shmflg;
70656 shm_params.u.size = size;
70657@@ -880,9 +897,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
70658 if (err)
70659 goto out_unlock;
70660
70661+#ifdef CONFIG_GRKERNSEC
70662+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
70663+ shp->shm_perm.cuid, shmid) ||
70664+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
70665+ err = -EACCES;
70666+ goto out_unlock;
70667+ }
70668+#endif
70669+
70670 path.dentry = dget(shp->shm_file->f_path.dentry);
70671 path.mnt = shp->shm_file->f_path.mnt;
70672 shp->shm_nattch++;
70673+#ifdef CONFIG_GRKERNSEC
70674+ shp->shm_lapid = current->pid;
70675+#endif
70676 size = i_size_read(path.dentry->d_inode);
70677 shm_unlock(shp);
70678
70679diff --git a/kernel/acct.c b/kernel/acct.c
70680index a6605ca..ca91111 100644
70681--- a/kernel/acct.c
70682+++ b/kernel/acct.c
70683@@ -579,7 +579,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
70684 */
70685 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
70686 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
70687- file->f_op->write(file, (char *)&ac,
70688+ file->f_op->write(file, (char __force_user *)&ac,
70689 sizeof(acct_t), &file->f_pos);
70690 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
70691 set_fs(fs);
70692diff --git a/kernel/audit.c b/kernel/audit.c
70693index 5feed23..513b02c 100644
70694--- a/kernel/audit.c
70695+++ b/kernel/audit.c
70696@@ -110,7 +110,7 @@ u32 audit_sig_sid = 0;
70697 3) suppressed due to audit_rate_limit
70698 4) suppressed due to audit_backlog_limit
70699 */
70700-static atomic_t audit_lost = ATOMIC_INIT(0);
70701+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
70702
70703 /* The netlink socket. */
70704 static struct sock *audit_sock;
70705@@ -232,7 +232,7 @@ void audit_log_lost(const char *message)
70706 unsigned long now;
70707 int print;
70708
70709- atomic_inc(&audit_lost);
70710+ atomic_inc_unchecked(&audit_lost);
70711
70712 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
70713
70714@@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
70715 printk(KERN_WARNING
70716 "audit: audit_lost=%d audit_rate_limit=%d "
70717 "audit_backlog_limit=%d\n",
70718- atomic_read(&audit_lost),
70719+ atomic_read_unchecked(&audit_lost),
70720 audit_rate_limit,
70721 audit_backlog_limit);
70722 audit_panic(message);
70723@@ -691,7 +691,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
70724 status_set.pid = audit_pid;
70725 status_set.rate_limit = audit_rate_limit;
70726 status_set.backlog_limit = audit_backlog_limit;
70727- status_set.lost = atomic_read(&audit_lost);
70728+ status_set.lost = atomic_read_unchecked(&audit_lost);
70729 status_set.backlog = skb_queue_len(&audit_skb_queue);
70730 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
70731 &status_set, sizeof(status_set));
70732@@ -891,8 +891,10 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
70733 spin_unlock_irq(&tsk->sighand->siglock);
70734 }
70735 read_unlock(&tasklist_lock);
70736- audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_TTY_GET, 0, 0,
70737- &s, sizeof(s));
70738+
70739+ if (!err)
70740+ audit_send_reply(NETLINK_CB(skb).pid, seq,
70741+ AUDIT_TTY_GET, 0, 0, &s, sizeof(s));
70742 break;
70743 }
70744 case AUDIT_TTY_SET: {
70745diff --git a/kernel/auditsc.c b/kernel/auditsc.c
70746index 267e484..f8e295a 100644
70747--- a/kernel/auditsc.c
70748+++ b/kernel/auditsc.c
70749@@ -2113,7 +2113,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
70750 }
70751
70752 /* global counter which is incremented every time something logs in */
70753-static atomic_t session_id = ATOMIC_INIT(0);
70754+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
70755
70756 /**
70757 * audit_set_loginuid - set a task's audit_context loginuid
70758@@ -2126,7 +2126,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
70759 */
70760 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
70761 {
70762- unsigned int sessionid = atomic_inc_return(&session_id);
70763+ unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
70764 struct audit_context *context = task->audit_context;
70765
70766 if (context && context->in_syscall) {
70767diff --git a/kernel/capability.c b/kernel/capability.c
70768index 8a944f5..db5001e 100644
70769--- a/kernel/capability.c
70770+++ b/kernel/capability.c
70771@@ -305,10 +305,26 @@ int capable(int cap)
70772 BUG();
70773 }
70774
70775- if (security_capable(cap) == 0) {
70776+ if (security_capable(cap) == 0 && gr_is_capable(cap)) {
70777 current->flags |= PF_SUPERPRIV;
70778 return 1;
70779 }
70780 return 0;
70781 }
70782+
70783+int capable_nolog(int cap)
70784+{
70785+ if (unlikely(!cap_valid(cap))) {
70786+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
70787+ BUG();
70788+ }
70789+
70790+ if (security_capable(cap) == 0 && gr_is_capable_nolog(cap)) {
70791+ current->flags |= PF_SUPERPRIV;
70792+ return 1;
70793+ }
70794+ return 0;
70795+}
70796+
70797 EXPORT_SYMBOL(capable);
70798+EXPORT_SYMBOL(capable_nolog);
70799diff --git a/kernel/cgroup.c b/kernel/cgroup.c
70800index 1fbcc74..7000012 100644
70801--- a/kernel/cgroup.c
70802+++ b/kernel/cgroup.c
70803@@ -536,6 +536,8 @@ static struct css_set *find_css_set(
70804 struct hlist_head *hhead;
70805 struct cg_cgroup_link *link;
70806
70807+ pax_track_stack();
70808+
70809 /* First see if we already have a cgroup group that matches
70810 * the desired set */
70811 read_lock(&css_set_lock);
70812diff --git a/kernel/compat.c b/kernel/compat.c
70813index 8bc5578..186e44a 100644
70814--- a/kernel/compat.c
70815+++ b/kernel/compat.c
70816@@ -108,7 +108,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
70817 mm_segment_t oldfs;
70818 long ret;
70819
70820- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
70821+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
70822 oldfs = get_fs();
70823 set_fs(KERNEL_DS);
70824 ret = hrtimer_nanosleep_restart(restart);
70825@@ -140,7 +140,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
70826 oldfs = get_fs();
70827 set_fs(KERNEL_DS);
70828 ret = hrtimer_nanosleep(&tu,
70829- rmtp ? (struct timespec __user *)&rmt : NULL,
70830+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
70831 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
70832 set_fs(oldfs);
70833
70834@@ -247,7 +247,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
70835 mm_segment_t old_fs = get_fs();
70836
70837 set_fs(KERNEL_DS);
70838- ret = sys_sigpending((old_sigset_t __user *) &s);
70839+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
70840 set_fs(old_fs);
70841 if (ret == 0)
70842 ret = put_user(s, set);
70843@@ -266,8 +266,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
70844 old_fs = get_fs();
70845 set_fs(KERNEL_DS);
70846 ret = sys_sigprocmask(how,
70847- set ? (old_sigset_t __user *) &s : NULL,
70848- oset ? (old_sigset_t __user *) &s : NULL);
70849+ set ? (old_sigset_t __force_user *) &s : NULL,
70850+ oset ? (old_sigset_t __force_user *) &s : NULL);
70851 set_fs(old_fs);
70852 if (ret == 0)
70853 if (oset)
70854@@ -310,7 +310,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
70855 mm_segment_t old_fs = get_fs();
70856
70857 set_fs(KERNEL_DS);
70858- ret = sys_old_getrlimit(resource, &r);
70859+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
70860 set_fs(old_fs);
70861
70862 if (!ret) {
70863@@ -385,7 +385,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
70864 mm_segment_t old_fs = get_fs();
70865
70866 set_fs(KERNEL_DS);
70867- ret = sys_getrusage(who, (struct rusage __user *) &r);
70868+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
70869 set_fs(old_fs);
70870
70871 if (ret)
70872@@ -412,8 +412,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
70873 set_fs (KERNEL_DS);
70874 ret = sys_wait4(pid,
70875 (stat_addr ?
70876- (unsigned int __user *) &status : NULL),
70877- options, (struct rusage __user *) &r);
70878+ (unsigned int __force_user *) &status : NULL),
70879+ options, (struct rusage __force_user *) &r);
70880 set_fs (old_fs);
70881
70882 if (ret > 0) {
70883@@ -438,8 +438,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
70884 memset(&info, 0, sizeof(info));
70885
70886 set_fs(KERNEL_DS);
70887- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
70888- uru ? (struct rusage __user *)&ru : NULL);
70889+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
70890+ uru ? (struct rusage __force_user *)&ru : NULL);
70891 set_fs(old_fs);
70892
70893 if ((ret < 0) || (info.si_signo == 0))
70894@@ -569,8 +569,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
70895 oldfs = get_fs();
70896 set_fs(KERNEL_DS);
70897 err = sys_timer_settime(timer_id, flags,
70898- (struct itimerspec __user *) &newts,
70899- (struct itimerspec __user *) &oldts);
70900+ (struct itimerspec __force_user *) &newts,
70901+ (struct itimerspec __force_user *) &oldts);
70902 set_fs(oldfs);
70903 if (!err && old && put_compat_itimerspec(old, &oldts))
70904 return -EFAULT;
70905@@ -587,7 +587,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
70906 oldfs = get_fs();
70907 set_fs(KERNEL_DS);
70908 err = sys_timer_gettime(timer_id,
70909- (struct itimerspec __user *) &ts);
70910+ (struct itimerspec __force_user *) &ts);
70911 set_fs(oldfs);
70912 if (!err && put_compat_itimerspec(setting, &ts))
70913 return -EFAULT;
70914@@ -606,7 +606,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
70915 oldfs = get_fs();
70916 set_fs(KERNEL_DS);
70917 err = sys_clock_settime(which_clock,
70918- (struct timespec __user *) &ts);
70919+ (struct timespec __force_user *) &ts);
70920 set_fs(oldfs);
70921 return err;
70922 }
70923@@ -621,7 +621,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
70924 oldfs = get_fs();
70925 set_fs(KERNEL_DS);
70926 err = sys_clock_gettime(which_clock,
70927- (struct timespec __user *) &ts);
70928+ (struct timespec __force_user *) &ts);
70929 set_fs(oldfs);
70930 if (!err && put_compat_timespec(&ts, tp))
70931 return -EFAULT;
70932@@ -638,7 +638,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
70933 oldfs = get_fs();
70934 set_fs(KERNEL_DS);
70935 err = sys_clock_getres(which_clock,
70936- (struct timespec __user *) &ts);
70937+ (struct timespec __force_user *) &ts);
70938 set_fs(oldfs);
70939 if (!err && tp && put_compat_timespec(&ts, tp))
70940 return -EFAULT;
70941@@ -650,9 +650,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
70942 long err;
70943 mm_segment_t oldfs;
70944 struct timespec tu;
70945- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
70946+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
70947
70948- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
70949+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
70950 oldfs = get_fs();
70951 set_fs(KERNEL_DS);
70952 err = clock_nanosleep_restart(restart);
70953@@ -684,8 +684,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
70954 oldfs = get_fs();
70955 set_fs(KERNEL_DS);
70956 err = sys_clock_nanosleep(which_clock, flags,
70957- (struct timespec __user *) &in,
70958- (struct timespec __user *) &out);
70959+ (struct timespec __force_user *) &in,
70960+ (struct timespec __force_user *) &out);
70961 set_fs(oldfs);
70962
70963 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
70964diff --git a/kernel/configs.c b/kernel/configs.c
70965index abaee68..047facd 100644
70966--- a/kernel/configs.c
70967+++ b/kernel/configs.c
70968@@ -73,8 +73,19 @@ static int __init ikconfig_init(void)
70969 struct proc_dir_entry *entry;
70970
70971 /* create the current config file */
70972+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
70973+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
70974+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
70975+ &ikconfig_file_ops);
70976+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70977+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
70978+ &ikconfig_file_ops);
70979+#endif
70980+#else
70981 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
70982 &ikconfig_file_ops);
70983+#endif
70984+
70985 if (!entry)
70986 return -ENOMEM;
70987
70988diff --git a/kernel/cpu.c b/kernel/cpu.c
70989index 7e8b6ac..8921388 100644
70990--- a/kernel/cpu.c
70991+++ b/kernel/cpu.c
70992@@ -19,7 +19,7 @@
70993 /* Serializes the updates to cpu_online_mask, cpu_present_mask */
70994 static DEFINE_MUTEX(cpu_add_remove_lock);
70995
70996-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
70997+static RAW_NOTIFIER_HEAD(cpu_chain);
70998
70999 /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
71000 * Should always be manipulated under cpu_add_remove_lock
71001diff --git a/kernel/cred.c b/kernel/cred.c
71002index 0b5b5fc..419b86a 100644
71003--- a/kernel/cred.c
71004+++ b/kernel/cred.c
71005@@ -160,6 +160,8 @@ static void put_cred_rcu(struct rcu_head *rcu)
71006 */
71007 void __put_cred(struct cred *cred)
71008 {
71009+ pax_track_stack();
71010+
71011 kdebug("__put_cred(%p{%d,%d})", cred,
71012 atomic_read(&cred->usage),
71013 read_cred_subscribers(cred));
71014@@ -184,6 +186,8 @@ void exit_creds(struct task_struct *tsk)
71015 {
71016 struct cred *cred;
71017
71018+ pax_track_stack();
71019+
71020 kdebug("exit_creds(%u,%p,%p,{%d,%d})", tsk->pid, tsk->real_cred, tsk->cred,
71021 atomic_read(&tsk->cred->usage),
71022 read_cred_subscribers(tsk->cred));
71023@@ -222,6 +226,8 @@ const struct cred *get_task_cred(struct task_struct *task)
71024 {
71025 const struct cred *cred;
71026
71027+ pax_track_stack();
71028+
71029 rcu_read_lock();
71030
71031 do {
71032@@ -241,6 +247,8 @@ struct cred *cred_alloc_blank(void)
71033 {
71034 struct cred *new;
71035
71036+ pax_track_stack();
71037+
71038 new = kmem_cache_zalloc(cred_jar, GFP_KERNEL);
71039 if (!new)
71040 return NULL;
71041@@ -289,6 +297,8 @@ struct cred *prepare_creds(void)
71042 const struct cred *old;
71043 struct cred *new;
71044
71045+ pax_track_stack();
71046+
71047 validate_process_creds();
71048
71049 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
71050@@ -335,6 +345,8 @@ struct cred *prepare_exec_creds(void)
71051 struct thread_group_cred *tgcred = NULL;
71052 struct cred *new;
71053
71054+ pax_track_stack();
71055+
71056 #ifdef CONFIG_KEYS
71057 tgcred = kmalloc(sizeof(*tgcred), GFP_KERNEL);
71058 if (!tgcred)
71059@@ -441,6 +453,8 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
71060 struct cred *new;
71061 int ret;
71062
71063+ pax_track_stack();
71064+
71065 mutex_init(&p->cred_guard_mutex);
71066
71067 if (
71068@@ -528,6 +542,8 @@ int commit_creds(struct cred *new)
71069 struct task_struct *task = current;
71070 const struct cred *old = task->real_cred;
71071
71072+ pax_track_stack();
71073+
71074 kdebug("commit_creds(%p{%d,%d})", new,
71075 atomic_read(&new->usage),
71076 read_cred_subscribers(new));
71077@@ -544,6 +560,8 @@ int commit_creds(struct cred *new)
71078
71079 get_cred(new); /* we will require a ref for the subj creds too */
71080
71081+ gr_set_role_label(task, new->uid, new->gid);
71082+
71083 /* dumpability changes */
71084 if (old->euid != new->euid ||
71085 old->egid != new->egid ||
71086@@ -563,10 +581,8 @@ int commit_creds(struct cred *new)
71087 key_fsgid_changed(task);
71088
71089 /* do it
71090- * - What if a process setreuid()'s and this brings the
71091- * new uid over his NPROC rlimit? We can check this now
71092- * cheaply with the new uid cache, so if it matters
71093- * we should be checking for it. -DaveM
71094+ * RLIMIT_NPROC limits on user->processes have already been checked
71095+ * in set_user().
71096 */
71097 alter_cred_subscribers(new, 2);
71098 if (new->user != old->user)
71099@@ -606,6 +622,8 @@ EXPORT_SYMBOL(commit_creds);
71100 */
71101 void abort_creds(struct cred *new)
71102 {
71103+ pax_track_stack();
71104+
71105 kdebug("abort_creds(%p{%d,%d})", new,
71106 atomic_read(&new->usage),
71107 read_cred_subscribers(new));
71108@@ -629,6 +647,8 @@ const struct cred *override_creds(const struct cred *new)
71109 {
71110 const struct cred *old = current->cred;
71111
71112+ pax_track_stack();
71113+
71114 kdebug("override_creds(%p{%d,%d})", new,
71115 atomic_read(&new->usage),
71116 read_cred_subscribers(new));
71117@@ -658,6 +678,8 @@ void revert_creds(const struct cred *old)
71118 {
71119 const struct cred *override = current->cred;
71120
71121+ pax_track_stack();
71122+
71123 kdebug("revert_creds(%p{%d,%d})", old,
71124 atomic_read(&old->usage),
71125 read_cred_subscribers(old));
71126@@ -704,6 +726,8 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
71127 const struct cred *old;
71128 struct cred *new;
71129
71130+ pax_track_stack();
71131+
71132 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
71133 if (!new)
71134 return NULL;
71135@@ -758,6 +782,8 @@ EXPORT_SYMBOL(prepare_kernel_cred);
71136 */
71137 int set_security_override(struct cred *new, u32 secid)
71138 {
71139+ pax_track_stack();
71140+
71141 return security_kernel_act_as(new, secid);
71142 }
71143 EXPORT_SYMBOL(set_security_override);
71144@@ -777,6 +803,8 @@ int set_security_override_from_ctx(struct cred *new, const char *secctx)
71145 u32 secid;
71146 int ret;
71147
71148+ pax_track_stack();
71149+
71150 ret = security_secctx_to_secid(secctx, strlen(secctx), &secid);
71151 if (ret < 0)
71152 return ret;
71153diff --git a/kernel/exit.c b/kernel/exit.c
71154index 0f8fae3..9344a56 100644
71155--- a/kernel/exit.c
71156+++ b/kernel/exit.c
71157@@ -55,6 +55,10 @@
71158 #include <asm/pgtable.h>
71159 #include <asm/mmu_context.h>
71160
71161+#ifdef CONFIG_GRKERNSEC
71162+extern rwlock_t grsec_exec_file_lock;
71163+#endif
71164+
71165 static void exit_mm(struct task_struct * tsk);
71166
71167 static void __unhash_process(struct task_struct *p)
71168@@ -174,6 +178,10 @@ void release_task(struct task_struct * p)
71169 struct task_struct *leader;
71170 int zap_leader;
71171 repeat:
71172+#ifdef CONFIG_NET
71173+ gr_del_task_from_ip_table(p);
71174+#endif
71175+
71176 tracehook_prepare_release_task(p);
71177 /* don't need to get the RCU readlock here - the process is dead and
71178 * can't be modifying its own credentials */
71179@@ -397,7 +405,7 @@ int allow_signal(int sig)
71180 * know it'll be handled, so that they don't get converted to
71181 * SIGKILL or just silently dropped.
71182 */
71183- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
71184+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
71185 recalc_sigpending();
71186 spin_unlock_irq(&current->sighand->siglock);
71187 return 0;
71188@@ -433,6 +441,17 @@ void daemonize(const char *name, ...)
71189 vsnprintf(current->comm, sizeof(current->comm), name, args);
71190 va_end(args);
71191
71192+#ifdef CONFIG_GRKERNSEC
71193+ write_lock(&grsec_exec_file_lock);
71194+ if (current->exec_file) {
71195+ fput(current->exec_file);
71196+ current->exec_file = NULL;
71197+ }
71198+ write_unlock(&grsec_exec_file_lock);
71199+#endif
71200+
71201+ gr_set_kernel_label(current);
71202+
71203 /*
71204 * If we were started as result of loading a module, close all of the
71205 * user space pages. We don't need them, and if we didn't close them
71206@@ -897,17 +916,17 @@ NORET_TYPE void do_exit(long code)
71207 struct task_struct *tsk = current;
71208 int group_dead;
71209
71210- profile_task_exit(tsk);
71211-
71212- WARN_ON(atomic_read(&tsk->fs_excl));
71213-
71214+ /*
71215+ * Check this first since set_fs() below depends on
71216+ * current_thread_info(), which we better not access when we're in
71217+ * interrupt context. Other than that, we want to do the set_fs()
71218+ * as early as possible.
71219+ */
71220 if (unlikely(in_interrupt()))
71221 panic("Aiee, killing interrupt handler!");
71222- if (unlikely(!tsk->pid))
71223- panic("Attempted to kill the idle task!");
71224
71225 /*
71226- * If do_exit is called because this processes oopsed, it's possible
71227+ * If do_exit is called because this processes Oops'ed, it's possible
71228 * that get_fs() was left as KERNEL_DS, so reset it to USER_DS before
71229 * continuing. Amongst other possible reasons, this is to prevent
71230 * mm_release()->clear_child_tid() from writing to a user-controlled
71231@@ -915,6 +934,13 @@ NORET_TYPE void do_exit(long code)
71232 */
71233 set_fs(USER_DS);
71234
71235+ profile_task_exit(tsk);
71236+
71237+ WARN_ON(atomic_read(&tsk->fs_excl));
71238+
71239+ if (unlikely(!tsk->pid))
71240+ panic("Attempted to kill the idle task!");
71241+
71242 tracehook_report_exit(&code);
71243
71244 validate_creds_for_do_exit(tsk);
71245@@ -973,6 +999,9 @@ NORET_TYPE void do_exit(long code)
71246 tsk->exit_code = code;
71247 taskstats_exit(tsk, group_dead);
71248
71249+ gr_acl_handle_psacct(tsk, code);
71250+ gr_acl_handle_exit();
71251+
71252 exit_mm(tsk);
71253
71254 if (group_dead)
71255@@ -1188,7 +1217,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
71256
71257 if (unlikely(wo->wo_flags & WNOWAIT)) {
71258 int exit_code = p->exit_code;
71259- int why, status;
71260+ int why;
71261
71262 get_task_struct(p);
71263 read_unlock(&tasklist_lock);
71264diff --git a/kernel/fork.c b/kernel/fork.c
71265index 4bde56f..29a9bab 100644
71266--- a/kernel/fork.c
71267+++ b/kernel/fork.c
71268@@ -253,7 +253,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
71269 *stackend = STACK_END_MAGIC; /* for overflow detection */
71270
71271 #ifdef CONFIG_CC_STACKPROTECTOR
71272- tsk->stack_canary = get_random_int();
71273+ tsk->stack_canary = pax_get_random_long();
71274 #endif
71275
71276 /* One for us, one for whoever does the "release_task()" (usually parent) */
71277@@ -293,8 +293,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
71278 mm->locked_vm = 0;
71279 mm->mmap = NULL;
71280 mm->mmap_cache = NULL;
71281- mm->free_area_cache = oldmm->mmap_base;
71282- mm->cached_hole_size = ~0UL;
71283+ mm->free_area_cache = oldmm->free_area_cache;
71284+ mm->cached_hole_size = oldmm->cached_hole_size;
71285 mm->map_count = 0;
71286 cpumask_clear(mm_cpumask(mm));
71287 mm->mm_rb = RB_ROOT;
71288@@ -335,6 +335,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
71289 tmp->vm_flags &= ~VM_LOCKED;
71290 tmp->vm_mm = mm;
71291 tmp->vm_next = tmp->vm_prev = NULL;
71292+ tmp->vm_mirror = NULL;
71293 anon_vma_link(tmp);
71294 file = tmp->vm_file;
71295 if (file) {
71296@@ -384,6 +385,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
71297 if (retval)
71298 goto out;
71299 }
71300+
71301+#ifdef CONFIG_PAX_SEGMEXEC
71302+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
71303+ struct vm_area_struct *mpnt_m;
71304+
71305+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
71306+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
71307+
71308+ if (!mpnt->vm_mirror)
71309+ continue;
71310+
71311+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
71312+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
71313+ mpnt->vm_mirror = mpnt_m;
71314+ } else {
71315+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
71316+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
71317+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
71318+ mpnt->vm_mirror->vm_mirror = mpnt;
71319+ }
71320+ }
71321+ BUG_ON(mpnt_m);
71322+ }
71323+#endif
71324+
71325 /* a new mm has just been created */
71326 arch_dup_mmap(oldmm, mm);
71327 retval = 0;
71328@@ -734,13 +760,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
71329 write_unlock(&fs->lock);
71330 return -EAGAIN;
71331 }
71332- fs->users++;
71333+ atomic_inc(&fs->users);
71334 write_unlock(&fs->lock);
71335 return 0;
71336 }
71337 tsk->fs = copy_fs_struct(fs);
71338 if (!tsk->fs)
71339 return -ENOMEM;
71340+ gr_set_chroot_entries(tsk, &tsk->fs->root);
71341 return 0;
71342 }
71343
71344@@ -1033,12 +1060,16 @@ static struct task_struct *copy_process(unsigned long clone_flags,
71345 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
71346 #endif
71347 retval = -EAGAIN;
71348+
71349+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
71350+
71351 if (atomic_read(&p->real_cred->user->processes) >=
71352 p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
71353- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
71354- p->real_cred->user != INIT_USER)
71355+ if (p->real_cred->user != INIT_USER &&
71356+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
71357 goto bad_fork_free;
71358 }
71359+ current->flags &= ~PF_NPROC_EXCEEDED;
71360
71361 retval = copy_creds(p, clone_flags);
71362 if (retval < 0)
71363@@ -1183,6 +1214,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
71364 goto bad_fork_free_pid;
71365 }
71366
71367+ gr_copy_label(p);
71368+
71369 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
71370 /*
71371 * Clear TID on mm_release()?
71372@@ -1333,6 +1366,8 @@ bad_fork_cleanup_count:
71373 bad_fork_free:
71374 free_task(p);
71375 fork_out:
71376+ gr_log_forkfail(retval);
71377+
71378 return ERR_PTR(retval);
71379 }
71380
71381@@ -1426,6 +1461,8 @@ long do_fork(unsigned long clone_flags,
71382 if (clone_flags & CLONE_PARENT_SETTID)
71383 put_user(nr, parent_tidptr);
71384
71385+ gr_handle_brute_check();
71386+
71387 if (clone_flags & CLONE_VFORK) {
71388 p->vfork_done = &vfork;
71389 init_completion(&vfork);
71390@@ -1558,7 +1595,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
71391 return 0;
71392
71393 /* don't need lock here; in the worst case we'll do useless copy */
71394- if (fs->users == 1)
71395+ if (atomic_read(&fs->users) == 1)
71396 return 0;
71397
71398 *new_fsp = copy_fs_struct(fs);
71399@@ -1681,7 +1718,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
71400 fs = current->fs;
71401 write_lock(&fs->lock);
71402 current->fs = new_fs;
71403- if (--fs->users)
71404+ gr_set_chroot_entries(current, &current->fs->root);
71405+ if (atomic_dec_return(&fs->users))
71406 new_fs = NULL;
71407 else
71408 new_fs = fs;
71409diff --git a/kernel/futex.c b/kernel/futex.c
71410index fb98c9f..333faec 100644
71411--- a/kernel/futex.c
71412+++ b/kernel/futex.c
71413@@ -54,6 +54,7 @@
71414 #include <linux/mount.h>
71415 #include <linux/pagemap.h>
71416 #include <linux/syscalls.h>
71417+#include <linux/ptrace.h>
71418 #include <linux/signal.h>
71419 #include <linux/module.h>
71420 #include <linux/magic.h>
71421@@ -223,6 +224,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
71422 struct page *page;
71423 int err, ro = 0;
71424
71425+#ifdef CONFIG_PAX_SEGMEXEC
71426+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
71427+ return -EFAULT;
71428+#endif
71429+
71430 /*
71431 * The futex address must be "naturally" aligned.
71432 */
71433@@ -1819,6 +1825,8 @@ static int futex_wait(u32 __user *uaddr, int fshared,
71434 struct futex_q q;
71435 int ret;
71436
71437+ pax_track_stack();
71438+
71439 if (!bitset)
71440 return -EINVAL;
71441
71442@@ -1871,7 +1879,7 @@ retry:
71443
71444 restart = &current_thread_info()->restart_block;
71445 restart->fn = futex_wait_restart;
71446- restart->futex.uaddr = (u32 *)uaddr;
71447+ restart->futex.uaddr = uaddr;
71448 restart->futex.val = val;
71449 restart->futex.time = abs_time->tv64;
71450 restart->futex.bitset = bitset;
71451@@ -2233,6 +2241,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, int fshared,
71452 struct futex_q q;
71453 int res, ret;
71454
71455+ pax_track_stack();
71456+
71457 if (!bitset)
71458 return -EINVAL;
71459
71460@@ -2423,6 +2433,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
71461 if (!p)
71462 goto err_unlock;
71463 ret = -EPERM;
71464+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71465+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
71466+ goto err_unlock;
71467+#endif
71468 pcred = __task_cred(p);
71469 if (cred->euid != pcred->euid &&
71470 cred->euid != pcred->uid &&
71471@@ -2489,7 +2503,7 @@ retry:
71472 */
71473 static inline int fetch_robust_entry(struct robust_list __user **entry,
71474 struct robust_list __user * __user *head,
71475- int *pi)
71476+ unsigned int *pi)
71477 {
71478 unsigned long uentry;
71479
71480@@ -2670,6 +2684,7 @@ static int __init futex_init(void)
71481 {
71482 u32 curval;
71483 int i;
71484+ mm_segment_t oldfs;
71485
71486 /*
71487 * This will fail and we want it. Some arch implementations do
71488@@ -2681,7 +2696,10 @@ static int __init futex_init(void)
71489 * implementation, the non functional ones will return
71490 * -ENOSYS.
71491 */
71492+ oldfs = get_fs();
71493+ set_fs(USER_DS);
71494 curval = cmpxchg_futex_value_locked(NULL, 0, 0);
71495+ set_fs(oldfs);
71496 if (curval == -EFAULT)
71497 futex_cmpxchg_enabled = 1;
71498
71499diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
71500index 2357165..eb25501 100644
71501--- a/kernel/futex_compat.c
71502+++ b/kernel/futex_compat.c
71503@@ -10,6 +10,7 @@
71504 #include <linux/compat.h>
71505 #include <linux/nsproxy.h>
71506 #include <linux/futex.h>
71507+#include <linux/ptrace.h>
71508
71509 #include <asm/uaccess.h>
71510
71511@@ -135,7 +136,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
71512 {
71513 struct compat_robust_list_head __user *head;
71514 unsigned long ret;
71515- const struct cred *cred = current_cred(), *pcred;
71516+ const struct cred *cred = current_cred();
71517+ const struct cred *pcred;
71518
71519 if (!futex_cmpxchg_enabled)
71520 return -ENOSYS;
71521@@ -151,6 +153,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
71522 if (!p)
71523 goto err_unlock;
71524 ret = -EPERM;
71525+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71526+ if (!ptrace_may_access(p, PTRACE_MODE_READ))
71527+ goto err_unlock;
71528+#endif
71529 pcred = __task_cred(p);
71530 if (cred->euid != pcred->euid &&
71531 cred->euid != pcred->uid &&
71532diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
71533index 9b22d03..6295b62 100644
71534--- a/kernel/gcov/base.c
71535+++ b/kernel/gcov/base.c
71536@@ -102,11 +102,6 @@ void gcov_enable_events(void)
71537 }
71538
71539 #ifdef CONFIG_MODULES
71540-static inline int within(void *addr, void *start, unsigned long size)
71541-{
71542- return ((addr >= start) && (addr < start + size));
71543-}
71544-
71545 /* Update list and generate events when modules are unloaded. */
71546 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
71547 void *data)
71548@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
71549 prev = NULL;
71550 /* Remove entries located in module from linked list. */
71551 for (info = gcov_info_head; info; info = info->next) {
71552- if (within(info, mod->module_core, mod->core_size)) {
71553+ if (within_module_core_rw((unsigned long)info, mod)) {
71554 if (prev)
71555 prev->next = info->next;
71556 else
71557diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
71558index a6e9d00..a0da4f9 100644
71559--- a/kernel/hrtimer.c
71560+++ b/kernel/hrtimer.c
71561@@ -1391,7 +1391,7 @@ void hrtimer_peek_ahead_timers(void)
71562 local_irq_restore(flags);
71563 }
71564
71565-static void run_hrtimer_softirq(struct softirq_action *h)
71566+static void run_hrtimer_softirq(void)
71567 {
71568 hrtimer_peek_ahead_timers();
71569 }
71570diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
71571index 8b6b8b6..6bc87df 100644
71572--- a/kernel/kallsyms.c
71573+++ b/kernel/kallsyms.c
71574@@ -11,6 +11,9 @@
71575 * Changed the compression method from stem compression to "table lookup"
71576 * compression (see scripts/kallsyms.c for a more complete description)
71577 */
71578+#ifdef CONFIG_GRKERNSEC_HIDESYM
71579+#define __INCLUDED_BY_HIDESYM 1
71580+#endif
71581 #include <linux/kallsyms.h>
71582 #include <linux/module.h>
71583 #include <linux/init.h>
71584@@ -51,12 +54,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
71585
71586 static inline int is_kernel_inittext(unsigned long addr)
71587 {
71588+ if (system_state != SYSTEM_BOOTING)
71589+ return 0;
71590+
71591 if (addr >= (unsigned long)_sinittext
71592 && addr <= (unsigned long)_einittext)
71593 return 1;
71594 return 0;
71595 }
71596
71597+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71598+#ifdef CONFIG_MODULES
71599+static inline int is_module_text(unsigned long addr)
71600+{
71601+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
71602+ return 1;
71603+
71604+ addr = ktla_ktva(addr);
71605+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
71606+}
71607+#else
71608+static inline int is_module_text(unsigned long addr)
71609+{
71610+ return 0;
71611+}
71612+#endif
71613+#endif
71614+
71615 static inline int is_kernel_text(unsigned long addr)
71616 {
71617 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
71618@@ -67,13 +91,28 @@ static inline int is_kernel_text(unsigned long addr)
71619
71620 static inline int is_kernel(unsigned long addr)
71621 {
71622+
71623+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71624+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
71625+ return 1;
71626+
71627+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
71628+#else
71629 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
71630+#endif
71631+
71632 return 1;
71633 return in_gate_area_no_task(addr);
71634 }
71635
71636 static int is_ksym_addr(unsigned long addr)
71637 {
71638+
71639+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71640+ if (is_module_text(addr))
71641+ return 0;
71642+#endif
71643+
71644 if (all_var)
71645 return is_kernel(addr);
71646
71647@@ -413,7 +452,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
71648
71649 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
71650 {
71651- iter->name[0] = '\0';
71652 iter->nameoff = get_symbol_offset(new_pos);
71653 iter->pos = new_pos;
71654 }
71655@@ -461,6 +499,11 @@ static int s_show(struct seq_file *m, void *p)
71656 {
71657 struct kallsym_iter *iter = m->private;
71658
71659+#ifdef CONFIG_GRKERNSEC_HIDESYM
71660+ if (current_uid())
71661+ return 0;
71662+#endif
71663+
71664 /* Some debugging symbols have no name. Ignore them. */
71665 if (!iter->name[0])
71666 return 0;
71667@@ -501,7 +544,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
71668 struct kallsym_iter *iter;
71669 int ret;
71670
71671- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
71672+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
71673 if (!iter)
71674 return -ENOMEM;
71675 reset_iter(iter, 0);
71676diff --git a/kernel/kexec.c b/kernel/kexec.c
71677index f336e21..9c1c20b 100644
71678--- a/kernel/kexec.c
71679+++ b/kernel/kexec.c
71680@@ -1028,7 +1028,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
71681 unsigned long flags)
71682 {
71683 struct compat_kexec_segment in;
71684- struct kexec_segment out, __user *ksegments;
71685+ struct kexec_segment out;
71686+ struct kexec_segment __user *ksegments;
71687 unsigned long i, result;
71688
71689 /* Don't allow clients that don't understand the native
71690diff --git a/kernel/kgdb.c b/kernel/kgdb.c
71691index 53dae4b..9ba3743 100644
71692--- a/kernel/kgdb.c
71693+++ b/kernel/kgdb.c
71694@@ -86,7 +86,7 @@ static int kgdb_io_module_registered;
71695 /* Guard for recursive entry */
71696 static int exception_level;
71697
71698-static struct kgdb_io *kgdb_io_ops;
71699+static const struct kgdb_io *kgdb_io_ops;
71700 static DEFINE_SPINLOCK(kgdb_registration_lock);
71701
71702 /* kgdb console driver is loaded */
71703@@ -123,7 +123,7 @@ atomic_t kgdb_active = ATOMIC_INIT(-1);
71704 */
71705 static atomic_t passive_cpu_wait[NR_CPUS];
71706 static atomic_t cpu_in_kgdb[NR_CPUS];
71707-atomic_t kgdb_setting_breakpoint;
71708+atomic_unchecked_t kgdb_setting_breakpoint;
71709
71710 struct task_struct *kgdb_usethread;
71711 struct task_struct *kgdb_contthread;
71712@@ -140,7 +140,7 @@ static unsigned long gdb_regs[(NUMREGBYTES +
71713 sizeof(unsigned long)];
71714
71715 /* to keep track of the CPU which is doing the single stepping*/
71716-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
71717+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
71718
71719 /*
71720 * If you are debugging a problem where roundup (the collection of
71721@@ -815,7 +815,7 @@ static int kgdb_io_ready(int print_wait)
71722 return 0;
71723 if (kgdb_connected)
71724 return 1;
71725- if (atomic_read(&kgdb_setting_breakpoint))
71726+ if (atomic_read_unchecked(&kgdb_setting_breakpoint))
71727 return 1;
71728 if (print_wait)
71729 printk(KERN_CRIT "KGDB: Waiting for remote debugger\n");
71730@@ -1426,8 +1426,8 @@ acquirelock:
71731 * instance of the exception handler wanted to come into the
71732 * debugger on a different CPU via a single step
71733 */
71734- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
71735- atomic_read(&kgdb_cpu_doing_single_step) != cpu) {
71736+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
71737+ atomic_read_unchecked(&kgdb_cpu_doing_single_step) != cpu) {
71738
71739 atomic_set(&kgdb_active, -1);
71740 touch_softlockup_watchdog();
71741@@ -1634,7 +1634,7 @@ static void kgdb_initial_breakpoint(void)
71742 *
71743 * Register it with the KGDB core.
71744 */
71745-int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
71746+int kgdb_register_io_module(const struct kgdb_io *new_kgdb_io_ops)
71747 {
71748 int err;
71749
71750@@ -1679,7 +1679,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_module);
71751 *
71752 * Unregister it with the KGDB core.
71753 */
71754-void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
71755+void kgdb_unregister_io_module(const struct kgdb_io *old_kgdb_io_ops)
71756 {
71757 BUG_ON(kgdb_connected);
71758
71759@@ -1712,11 +1712,11 @@ EXPORT_SYMBOL_GPL(kgdb_unregister_io_module);
71760 */
71761 void kgdb_breakpoint(void)
71762 {
71763- atomic_set(&kgdb_setting_breakpoint, 1);
71764+ atomic_set_unchecked(&kgdb_setting_breakpoint, 1);
71765 wmb(); /* Sync point before breakpoint */
71766 arch_kgdb_breakpoint();
71767 wmb(); /* Sync point after breakpoint */
71768- atomic_set(&kgdb_setting_breakpoint, 0);
71769+ atomic_set_unchecked(&kgdb_setting_breakpoint, 0);
71770 }
71771 EXPORT_SYMBOL_GPL(kgdb_breakpoint);
71772
71773diff --git a/kernel/kmod.c b/kernel/kmod.c
71774index d206078..e27ba6a 100644
71775--- a/kernel/kmod.c
71776+++ b/kernel/kmod.c
71777@@ -65,13 +65,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
71778 * If module auto-loading support is disabled then this function
71779 * becomes a no-operation.
71780 */
71781-int __request_module(bool wait, const char *fmt, ...)
71782+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
71783 {
71784- va_list args;
71785 char module_name[MODULE_NAME_LEN];
71786 unsigned int max_modprobes;
71787 int ret;
71788- char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
71789+ char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
71790 static char *envp[] = { "HOME=/",
71791 "TERM=linux",
71792 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
71793@@ -84,12 +83,24 @@ int __request_module(bool wait, const char *fmt, ...)
71794 if (ret)
71795 return ret;
71796
71797- va_start(args, fmt);
71798- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
71799- va_end(args);
71800+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
71801 if (ret >= MODULE_NAME_LEN)
71802 return -ENAMETOOLONG;
71803
71804+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71805+ if (!current_uid()) {
71806+ /* hack to workaround consolekit/udisks stupidity */
71807+ read_lock(&tasklist_lock);
71808+ if (!strcmp(current->comm, "mount") &&
71809+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
71810+ read_unlock(&tasklist_lock);
71811+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
71812+ return -EPERM;
71813+ }
71814+ read_unlock(&tasklist_lock);
71815+ }
71816+#endif
71817+
71818 /* If modprobe needs a service that is in a module, we get a recursive
71819 * loop. Limit the number of running kmod threads to max_threads/2 or
71820 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
71821@@ -123,6 +134,48 @@ int __request_module(bool wait, const char *fmt, ...)
71822 atomic_dec(&kmod_concurrent);
71823 return ret;
71824 }
71825+
71826+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
71827+{
71828+ va_list args;
71829+ int ret;
71830+
71831+ va_start(args, fmt);
71832+ ret = ____request_module(wait, module_param, fmt, args);
71833+ va_end(args);
71834+
71835+ return ret;
71836+}
71837+
71838+int __request_module(bool wait, const char *fmt, ...)
71839+{
71840+ va_list args;
71841+ int ret;
71842+
71843+#ifdef CONFIG_GRKERNSEC_MODHARDEN
71844+ if (current_uid()) {
71845+ char module_param[MODULE_NAME_LEN];
71846+
71847+ memset(module_param, 0, sizeof(module_param));
71848+
71849+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
71850+
71851+ va_start(args, fmt);
71852+ ret = ____request_module(wait, module_param, fmt, args);
71853+ va_end(args);
71854+
71855+ return ret;
71856+ }
71857+#endif
71858+
71859+ va_start(args, fmt);
71860+ ret = ____request_module(wait, NULL, fmt, args);
71861+ va_end(args);
71862+
71863+ return ret;
71864+}
71865+
71866+
71867 EXPORT_SYMBOL(__request_module);
71868 #endif /* CONFIG_MODULES */
71869
71870@@ -228,7 +281,7 @@ static int wait_for_helper(void *data)
71871 *
71872 * Thus the __user pointer cast is valid here.
71873 */
71874- sys_wait4(pid, (int __user *)&ret, 0, NULL);
71875+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
71876
71877 /*
71878 * If ret is 0, either ____call_usermodehelper failed and the
71879diff --git a/kernel/kprobes.c b/kernel/kprobes.c
71880index 5240d75..5a6fb33 100644
71881--- a/kernel/kprobes.c
71882+++ b/kernel/kprobes.c
71883@@ -183,7 +183,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(void)
71884 * kernel image and loaded module images reside. This is required
71885 * so x86_64 can correctly handle the %rip-relative fixups.
71886 */
71887- kip->insns = module_alloc(PAGE_SIZE);
71888+ kip->insns = module_alloc_exec(PAGE_SIZE);
71889 if (!kip->insns) {
71890 kfree(kip);
71891 return NULL;
71892@@ -220,7 +220,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
71893 */
71894 if (!list_is_singular(&kprobe_insn_pages)) {
71895 list_del(&kip->list);
71896- module_free(NULL, kip->insns);
71897+ module_free_exec(NULL, kip->insns);
71898 kfree(kip);
71899 }
71900 return 1;
71901@@ -1189,7 +1189,7 @@ static int __init init_kprobes(void)
71902 {
71903 int i, err = 0;
71904 unsigned long offset = 0, size = 0;
71905- char *modname, namebuf[128];
71906+ char *modname, namebuf[KSYM_NAME_LEN];
71907 const char *symbol_name;
71908 void *addr;
71909 struct kprobe_blackpoint *kb;
71910@@ -1304,7 +1304,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
71911 const char *sym = NULL;
71912 unsigned int i = *(loff_t *) v;
71913 unsigned long offset = 0;
71914- char *modname, namebuf[128];
71915+ char *modname, namebuf[KSYM_NAME_LEN];
71916
71917 head = &kprobe_table[i];
71918 preempt_disable();
71919diff --git a/kernel/lockdep.c b/kernel/lockdep.c
71920index d86fe89..d12fc66 100644
71921--- a/kernel/lockdep.c
71922+++ b/kernel/lockdep.c
71923@@ -421,20 +421,20 @@ static struct stack_trace lockdep_init_trace = {
71924 /*
71925 * Various lockdep statistics:
71926 */
71927-atomic_t chain_lookup_hits;
71928-atomic_t chain_lookup_misses;
71929-atomic_t hardirqs_on_events;
71930-atomic_t hardirqs_off_events;
71931-atomic_t redundant_hardirqs_on;
71932-atomic_t redundant_hardirqs_off;
71933-atomic_t softirqs_on_events;
71934-atomic_t softirqs_off_events;
71935-atomic_t redundant_softirqs_on;
71936-atomic_t redundant_softirqs_off;
71937-atomic_t nr_unused_locks;
71938-atomic_t nr_cyclic_checks;
71939-atomic_t nr_find_usage_forwards_checks;
71940-atomic_t nr_find_usage_backwards_checks;
71941+atomic_unchecked_t chain_lookup_hits;
71942+atomic_unchecked_t chain_lookup_misses;
71943+atomic_unchecked_t hardirqs_on_events;
71944+atomic_unchecked_t hardirqs_off_events;
71945+atomic_unchecked_t redundant_hardirqs_on;
71946+atomic_unchecked_t redundant_hardirqs_off;
71947+atomic_unchecked_t softirqs_on_events;
71948+atomic_unchecked_t softirqs_off_events;
71949+atomic_unchecked_t redundant_softirqs_on;
71950+atomic_unchecked_t redundant_softirqs_off;
71951+atomic_unchecked_t nr_unused_locks;
71952+atomic_unchecked_t nr_cyclic_checks;
71953+atomic_unchecked_t nr_find_usage_forwards_checks;
71954+atomic_unchecked_t nr_find_usage_backwards_checks;
71955 #endif
71956
71957 /*
71958@@ -577,6 +577,10 @@ static int static_obj(void *obj)
71959 int i;
71960 #endif
71961
71962+#ifdef CONFIG_PAX_KERNEXEC
71963+ start = ktla_ktva(start);
71964+#endif
71965+
71966 /*
71967 * static variable?
71968 */
71969@@ -592,8 +596,7 @@ static int static_obj(void *obj)
71970 */
71971 for_each_possible_cpu(i) {
71972 start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
71973- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
71974- + per_cpu_offset(i);
71975+ end = start + PERCPU_ENOUGH_ROOM;
71976
71977 if ((addr >= start) && (addr < end))
71978 return 1;
71979@@ -710,6 +713,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
71980 if (!static_obj(lock->key)) {
71981 debug_locks_off();
71982 printk("INFO: trying to register non-static key.\n");
71983+ printk("lock:%pS key:%pS.\n", lock, lock->key);
71984 printk("the code is fine but needs lockdep annotation.\n");
71985 printk("turning off the locking correctness validator.\n");
71986 dump_stack();
71987@@ -2751,7 +2755,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
71988 if (!class)
71989 return 0;
71990 }
71991- debug_atomic_inc((atomic_t *)&class->ops);
71992+ debug_atomic_inc((atomic_unchecked_t *)&class->ops);
71993 if (very_verbose(class)) {
71994 printk("\nacquire class [%p] %s", class->key, class->name);
71995 if (class->name_version > 1)
71996diff --git a/kernel/lockdep_internals.h b/kernel/lockdep_internals.h
71997index a2ee95a..092f0f2 100644
71998--- a/kernel/lockdep_internals.h
71999+++ b/kernel/lockdep_internals.h
72000@@ -113,26 +113,26 @@ lockdep_count_backward_deps(struct lock_class *class)
72001 /*
72002 * Various lockdep statistics:
72003 */
72004-extern atomic_t chain_lookup_hits;
72005-extern atomic_t chain_lookup_misses;
72006-extern atomic_t hardirqs_on_events;
72007-extern atomic_t hardirqs_off_events;
72008-extern atomic_t redundant_hardirqs_on;
72009-extern atomic_t redundant_hardirqs_off;
72010-extern atomic_t softirqs_on_events;
72011-extern atomic_t softirqs_off_events;
72012-extern atomic_t redundant_softirqs_on;
72013-extern atomic_t redundant_softirqs_off;
72014-extern atomic_t nr_unused_locks;
72015-extern atomic_t nr_cyclic_checks;
72016-extern atomic_t nr_cyclic_check_recursions;
72017-extern atomic_t nr_find_usage_forwards_checks;
72018-extern atomic_t nr_find_usage_forwards_recursions;
72019-extern atomic_t nr_find_usage_backwards_checks;
72020-extern atomic_t nr_find_usage_backwards_recursions;
72021-# define debug_atomic_inc(ptr) atomic_inc(ptr)
72022-# define debug_atomic_dec(ptr) atomic_dec(ptr)
72023-# define debug_atomic_read(ptr) atomic_read(ptr)
72024+extern atomic_unchecked_t chain_lookup_hits;
72025+extern atomic_unchecked_t chain_lookup_misses;
72026+extern atomic_unchecked_t hardirqs_on_events;
72027+extern atomic_unchecked_t hardirqs_off_events;
72028+extern atomic_unchecked_t redundant_hardirqs_on;
72029+extern atomic_unchecked_t redundant_hardirqs_off;
72030+extern atomic_unchecked_t softirqs_on_events;
72031+extern atomic_unchecked_t softirqs_off_events;
72032+extern atomic_unchecked_t redundant_softirqs_on;
72033+extern atomic_unchecked_t redundant_softirqs_off;
72034+extern atomic_unchecked_t nr_unused_locks;
72035+extern atomic_unchecked_t nr_cyclic_checks;
72036+extern atomic_unchecked_t nr_cyclic_check_recursions;
72037+extern atomic_unchecked_t nr_find_usage_forwards_checks;
72038+extern atomic_unchecked_t nr_find_usage_forwards_recursions;
72039+extern atomic_unchecked_t nr_find_usage_backwards_checks;
72040+extern atomic_unchecked_t nr_find_usage_backwards_recursions;
72041+# define debug_atomic_inc(ptr) atomic_inc_unchecked(ptr)
72042+# define debug_atomic_dec(ptr) atomic_dec_unchecked(ptr)
72043+# define debug_atomic_read(ptr) atomic_read_unchecked(ptr)
72044 #else
72045 # define debug_atomic_inc(ptr) do { } while (0)
72046 # define debug_atomic_dec(ptr) do { } while (0)
72047diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
72048index d4aba4f..02a353f 100644
72049--- a/kernel/lockdep_proc.c
72050+++ b/kernel/lockdep_proc.c
72051@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
72052
72053 static void print_name(struct seq_file *m, struct lock_class *class)
72054 {
72055- char str[128];
72056+ char str[KSYM_NAME_LEN];
72057 const char *name = class->name;
72058
72059 if (!name) {
72060diff --git a/kernel/module.c b/kernel/module.c
72061index 4b270e6..2226274 100644
72062--- a/kernel/module.c
72063+++ b/kernel/module.c
72064@@ -55,6 +55,7 @@
72065 #include <linux/async.h>
72066 #include <linux/percpu.h>
72067 #include <linux/kmemleak.h>
72068+#include <linux/grsecurity.h>
72069
72070 #define CREATE_TRACE_POINTS
72071 #include <trace/events/module.h>
72072@@ -89,7 +90,8 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq);
72073 static BLOCKING_NOTIFIER_HEAD(module_notify_list);
72074
72075 /* Bounds of module allocation, for speeding __module_address */
72076-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
72077+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
72078+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
72079
72080 int register_module_notifier(struct notifier_block * nb)
72081 {
72082@@ -245,7 +247,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
72083 return true;
72084
72085 list_for_each_entry_rcu(mod, &modules, list) {
72086- struct symsearch arr[] = {
72087+ struct symsearch modarr[] = {
72088 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
72089 NOT_GPL_ONLY, false },
72090 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
72091@@ -267,7 +269,7 @@ bool each_symbol(bool (*fn)(const struct symsearch *arr, struct module *owner,
72092 #endif
72093 };
72094
72095- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
72096+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
72097 return true;
72098 }
72099 return false;
72100@@ -442,7 +444,7 @@ static void *percpu_modalloc(unsigned long size, unsigned long align,
72101 void *ptr;
72102 int cpu;
72103
72104- if (align > PAGE_SIZE) {
72105+ if (align-1 >= PAGE_SIZE) {
72106 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
72107 name, align, PAGE_SIZE);
72108 align = PAGE_SIZE;
72109@@ -1158,7 +1160,7 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
72110 * /sys/module/foo/sections stuff
72111 * J. Corbet <corbet@lwn.net>
72112 */
72113-#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
72114+#if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
72115
72116 static inline bool sect_empty(const Elf_Shdr *sect)
72117 {
72118@@ -1545,7 +1547,8 @@ static void free_module(struct module *mod)
72119 destroy_params(mod->kp, mod->num_kp);
72120
72121 /* This may be NULL, but that's OK */
72122- module_free(mod, mod->module_init);
72123+ module_free(mod, mod->module_init_rw);
72124+ module_free_exec(mod, mod->module_init_rx);
72125 kfree(mod->args);
72126 if (mod->percpu)
72127 percpu_modfree(mod->percpu);
72128@@ -1554,10 +1557,12 @@ static void free_module(struct module *mod)
72129 percpu_modfree(mod->refptr);
72130 #endif
72131 /* Free lock-classes: */
72132- lockdep_free_key_range(mod->module_core, mod->core_size);
72133+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
72134+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
72135
72136 /* Finally, free the core (containing the module structure) */
72137- module_free(mod, mod->module_core);
72138+ module_free_exec(mod, mod->module_core_rx);
72139+ module_free(mod, mod->module_core_rw);
72140
72141 #ifdef CONFIG_MPU
72142 update_protections(current->mm);
72143@@ -1628,8 +1633,32 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
72144 unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
72145 int ret = 0;
72146 const struct kernel_symbol *ksym;
72147+#ifdef CONFIG_GRKERNSEC_MODHARDEN
72148+ int is_fs_load = 0;
72149+ int register_filesystem_found = 0;
72150+ char *p;
72151+
72152+ p = strstr(mod->args, "grsec_modharden_fs");
72153+
72154+ if (p) {
72155+ char *endptr = p + strlen("grsec_modharden_fs");
72156+ /* copy \0 as well */
72157+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
72158+ is_fs_load = 1;
72159+ }
72160+#endif
72161+
72162
72163 for (i = 1; i < n; i++) {
72164+#ifdef CONFIG_GRKERNSEC_MODHARDEN
72165+ const char *name = strtab + sym[i].st_name;
72166+
72167+ /* it's a real shame this will never get ripped and copied
72168+ upstream! ;(
72169+ */
72170+ if (is_fs_load && !strcmp(name, "register_filesystem"))
72171+ register_filesystem_found = 1;
72172+#endif
72173 switch (sym[i].st_shndx) {
72174 case SHN_COMMON:
72175 /* We compiled with -fno-common. These are not
72176@@ -1651,7 +1680,9 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
72177 strtab + sym[i].st_name, mod);
72178 /* Ok if resolved. */
72179 if (ksym) {
72180+ pax_open_kernel();
72181 sym[i].st_value = ksym->value;
72182+ pax_close_kernel();
72183 break;
72184 }
72185
72186@@ -1670,11 +1701,20 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
72187 secbase = (unsigned long)mod->percpu;
72188 else
72189 secbase = sechdrs[sym[i].st_shndx].sh_addr;
72190+ pax_open_kernel();
72191 sym[i].st_value += secbase;
72192+ pax_close_kernel();
72193 break;
72194 }
72195 }
72196
72197+#ifdef CONFIG_GRKERNSEC_MODHARDEN
72198+ if (is_fs_load && !register_filesystem_found) {
72199+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
72200+ ret = -EPERM;
72201+ }
72202+#endif
72203+
72204 return ret;
72205 }
72206
72207@@ -1731,11 +1771,12 @@ static void layout_sections(struct module *mod,
72208 || s->sh_entsize != ~0UL
72209 || strstarts(secstrings + s->sh_name, ".init"))
72210 continue;
72211- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
72212+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
72213+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
72214+ else
72215+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
72216 DEBUGP("\t%s\n", secstrings + s->sh_name);
72217 }
72218- if (m == 0)
72219- mod->core_text_size = mod->core_size;
72220 }
72221
72222 DEBUGP("Init section allocation order:\n");
72223@@ -1748,12 +1789,13 @@ static void layout_sections(struct module *mod,
72224 || s->sh_entsize != ~0UL
72225 || !strstarts(secstrings + s->sh_name, ".init"))
72226 continue;
72227- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
72228- | INIT_OFFSET_MASK);
72229+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
72230+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
72231+ else
72232+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
72233+ s->sh_entsize |= INIT_OFFSET_MASK;
72234 DEBUGP("\t%s\n", secstrings + s->sh_name);
72235 }
72236- if (m == 0)
72237- mod->init_text_size = mod->init_size;
72238 }
72239 }
72240
72241@@ -1857,9 +1899,8 @@ static int is_exported(const char *name, unsigned long value,
72242
72243 /* As per nm */
72244 static char elf_type(const Elf_Sym *sym,
72245- Elf_Shdr *sechdrs,
72246- const char *secstrings,
72247- struct module *mod)
72248+ const Elf_Shdr *sechdrs,
72249+ const char *secstrings)
72250 {
72251 if (ELF_ST_BIND(sym->st_info) == STB_WEAK) {
72252 if (ELF_ST_TYPE(sym->st_info) == STT_OBJECT)
72253@@ -1934,7 +1975,7 @@ static unsigned long layout_symtab(struct module *mod,
72254
72255 /* Put symbol section at end of init part of module. */
72256 symsect->sh_flags |= SHF_ALLOC;
72257- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
72258+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
72259 symindex) | INIT_OFFSET_MASK;
72260 DEBUGP("\t%s\n", secstrings + symsect->sh_name);
72261
72262@@ -1951,19 +1992,19 @@ static unsigned long layout_symtab(struct module *mod,
72263 }
72264
72265 /* Append room for core symbols at end of core part. */
72266- symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
72267- mod->core_size = symoffs + ndst * sizeof(Elf_Sym);
72268+ symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
72269+ mod->core_size_rx = symoffs + ndst * sizeof(Elf_Sym);
72270
72271 /* Put string table section at end of init part of module. */
72272 strsect->sh_flags |= SHF_ALLOC;
72273- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
72274+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
72275 strindex) | INIT_OFFSET_MASK;
72276 DEBUGP("\t%s\n", secstrings + strsect->sh_name);
72277
72278 /* Append room for core symbols' strings at end of core part. */
72279- *pstroffs = mod->core_size;
72280+ *pstroffs = mod->core_size_rx;
72281 __set_bit(0, strmap);
72282- mod->core_size += bitmap_weight(strmap, strsect->sh_size);
72283+ mod->core_size_rx += bitmap_weight(strmap, strsect->sh_size);
72284
72285 return symoffs;
72286 }
72287@@ -1987,12 +2028,14 @@ static void add_kallsyms(struct module *mod,
72288 mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
72289 mod->strtab = (void *)sechdrs[strindex].sh_addr;
72290
72291+ pax_open_kernel();
72292+
72293 /* Set types up while we still have access to sections. */
72294 for (i = 0; i < mod->num_symtab; i++)
72295 mod->symtab[i].st_info
72296- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
72297+ = elf_type(&mod->symtab[i], sechdrs, secstrings);
72298
72299- mod->core_symtab = dst = mod->module_core + symoffs;
72300+ mod->core_symtab = dst = mod->module_core_rx + symoffs;
72301 src = mod->symtab;
72302 *dst = *src;
72303 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
72304@@ -2004,10 +2047,12 @@ static void add_kallsyms(struct module *mod,
72305 }
72306 mod->core_num_syms = ndst;
72307
72308- mod->core_strtab = s = mod->module_core + stroffs;
72309+ mod->core_strtab = s = mod->module_core_rx + stroffs;
72310 for (*s = 0, i = 1; i < sechdrs[strindex].sh_size; ++i)
72311 if (test_bit(i, strmap))
72312 *++s = mod->strtab[i];
72313+
72314+ pax_close_kernel();
72315 }
72316 #else
72317 static inline unsigned long layout_symtab(struct module *mod,
72318@@ -2044,16 +2089,30 @@ static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
72319 #endif
72320 }
72321
72322-static void *module_alloc_update_bounds(unsigned long size)
72323+static void *module_alloc_update_bounds_rw(unsigned long size)
72324 {
72325 void *ret = module_alloc(size);
72326
72327 if (ret) {
72328 /* Update module bounds. */
72329- if ((unsigned long)ret < module_addr_min)
72330- module_addr_min = (unsigned long)ret;
72331- if ((unsigned long)ret + size > module_addr_max)
72332- module_addr_max = (unsigned long)ret + size;
72333+ if ((unsigned long)ret < module_addr_min_rw)
72334+ module_addr_min_rw = (unsigned long)ret;
72335+ if ((unsigned long)ret + size > module_addr_max_rw)
72336+ module_addr_max_rw = (unsigned long)ret + size;
72337+ }
72338+ return ret;
72339+}
72340+
72341+static void *module_alloc_update_bounds_rx(unsigned long size)
72342+{
72343+ void *ret = module_alloc_exec(size);
72344+
72345+ if (ret) {
72346+ /* Update module bounds. */
72347+ if ((unsigned long)ret < module_addr_min_rx)
72348+ module_addr_min_rx = (unsigned long)ret;
72349+ if ((unsigned long)ret + size > module_addr_max_rx)
72350+ module_addr_max_rx = (unsigned long)ret + size;
72351 }
72352 return ret;
72353 }
72354@@ -2065,8 +2124,8 @@ static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
72355 unsigned int i;
72356
72357 /* only scan the sections containing data */
72358- kmemleak_scan_area(mod->module_core, (unsigned long)mod -
72359- (unsigned long)mod->module_core,
72360+ kmemleak_scan_area(mod->module_core_rw, (unsigned long)mod -
72361+ (unsigned long)mod->module_core_rw,
72362 sizeof(struct module), GFP_KERNEL);
72363
72364 for (i = 1; i < hdr->e_shnum; i++) {
72365@@ -2076,8 +2135,8 @@ static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
72366 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0)
72367 continue;
72368
72369- kmemleak_scan_area(mod->module_core, sechdrs[i].sh_addr -
72370- (unsigned long)mod->module_core,
72371+ kmemleak_scan_area(mod->module_core_rw, sechdrs[i].sh_addr -
72372+ (unsigned long)mod->module_core_rw,
72373 sechdrs[i].sh_size, GFP_KERNEL);
72374 }
72375 }
72376@@ -2097,7 +2156,7 @@ static noinline struct module *load_module(void __user *umod,
72377 Elf_Ehdr *hdr;
72378 Elf_Shdr *sechdrs;
72379 char *secstrings, *args, *modmagic, *strtab = NULL;
72380- char *staging;
72381+ char *staging, *license;
72382 unsigned int i;
72383 unsigned int symindex = 0;
72384 unsigned int strindex = 0;
72385@@ -2195,6 +2254,14 @@ static noinline struct module *load_module(void __user *umod,
72386 goto free_hdr;
72387 }
72388
72389+ license = get_modinfo(sechdrs, infoindex, "license");
72390+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
72391+ if (!license || !license_is_gpl_compatible(license)) {
72392+ err -ENOEXEC;
72393+ goto free_hdr;
72394+ }
72395+#endif
72396+
72397 modmagic = get_modinfo(sechdrs, infoindex, "vermagic");
72398 /* This is allowed: modprobe --force will invalidate it. */
72399 if (!modmagic) {
72400@@ -2263,7 +2330,7 @@ static noinline struct module *load_module(void __user *umod,
72401 secstrings, &stroffs, strmap);
72402
72403 /* Do the allocs. */
72404- ptr = module_alloc_update_bounds(mod->core_size);
72405+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
72406 /*
72407 * The pointer to this block is stored in the module structure
72408 * which is inside the block. Just mark it as not being a
72409@@ -2274,23 +2341,47 @@ static noinline struct module *load_module(void __user *umod,
72410 err = -ENOMEM;
72411 goto free_percpu;
72412 }
72413- memset(ptr, 0, mod->core_size);
72414- mod->module_core = ptr;
72415+ memset(ptr, 0, mod->core_size_rw);
72416+ mod->module_core_rw = ptr;
72417
72418- ptr = module_alloc_update_bounds(mod->init_size);
72419+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
72420 /*
72421 * The pointer to this block is stored in the module structure
72422 * which is inside the block. This block doesn't need to be
72423 * scanned as it contains data and code that will be freed
72424 * after the module is initialized.
72425 */
72426- kmemleak_ignore(ptr);
72427- if (!ptr && mod->init_size) {
72428+ kmemleak_not_leak(ptr);
72429+ if (!ptr && mod->init_size_rw) {
72430 err = -ENOMEM;
72431- goto free_core;
72432+ goto free_core_rw;
72433 }
72434- memset(ptr, 0, mod->init_size);
72435- mod->module_init = ptr;
72436+ memset(ptr, 0, mod->init_size_rw);
72437+ mod->module_init_rw = ptr;
72438+
72439+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
72440+ kmemleak_not_leak(ptr);
72441+ if (!ptr) {
72442+ err = -ENOMEM;
72443+ goto free_init_rw;
72444+ }
72445+
72446+ pax_open_kernel();
72447+ memset(ptr, 0, mod->core_size_rx);
72448+ pax_close_kernel();
72449+ mod->module_core_rx = ptr;
72450+
72451+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
72452+ kmemleak_not_leak(ptr);
72453+ if (!ptr && mod->init_size_rx) {
72454+ err = -ENOMEM;
72455+ goto free_core_rx;
72456+ }
72457+
72458+ pax_open_kernel();
72459+ memset(ptr, 0, mod->init_size_rx);
72460+ pax_close_kernel();
72461+ mod->module_init_rx = ptr;
72462
72463 /* Transfer each section which specifies SHF_ALLOC */
72464 DEBUGP("final section addresses:\n");
72465@@ -2300,17 +2391,45 @@ static noinline struct module *load_module(void __user *umod,
72466 if (!(sechdrs[i].sh_flags & SHF_ALLOC))
72467 continue;
72468
72469- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
72470- dest = mod->module_init
72471- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72472- else
72473- dest = mod->module_core + sechdrs[i].sh_entsize;
72474+ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
72475+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
72476+ dest = mod->module_init_rw
72477+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72478+ else
72479+ dest = mod->module_init_rx
72480+ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
72481+ } else {
72482+ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
72483+ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
72484+ else
72485+ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
72486+ }
72487
72488- if (sechdrs[i].sh_type != SHT_NOBITS)
72489- memcpy(dest, (void *)sechdrs[i].sh_addr,
72490- sechdrs[i].sh_size);
72491+ if (sechdrs[i].sh_type != SHT_NOBITS) {
72492+
72493+#ifdef CONFIG_PAX_KERNEXEC
72494+#ifdef CONFIG_X86_64
72495+ if ((sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_EXECINSTR))
72496+ set_memory_x((unsigned long)dest, (sechdrs[i].sh_size + PAGE_SIZE) >> PAGE_SHIFT);
72497+#endif
72498+ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
72499+ pax_open_kernel();
72500+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
72501+ pax_close_kernel();
72502+ } else
72503+#endif
72504+
72505+ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
72506+ }
72507 /* Update sh_addr to point to copy in image. */
72508- sechdrs[i].sh_addr = (unsigned long)dest;
72509+
72510+#ifdef CONFIG_PAX_KERNEXEC
72511+ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
72512+ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
72513+ else
72514+#endif
72515+
72516+ sechdrs[i].sh_addr = (unsigned long)dest;
72517 DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
72518 }
72519 /* Module has been moved. */
72520@@ -2322,7 +2441,7 @@ static noinline struct module *load_module(void __user *umod,
72521 mod->name);
72522 if (!mod->refptr) {
72523 err = -ENOMEM;
72524- goto free_init;
72525+ goto free_init_rx;
72526 }
72527 #endif
72528 /* Now we've moved module, initialize linked lists, etc. */
72529@@ -2334,7 +2453,7 @@ static noinline struct module *load_module(void __user *umod,
72530 goto free_unload;
72531
72532 /* Set up license info based on the info section */
72533- set_license(mod, get_modinfo(sechdrs, infoindex, "license"));
72534+ set_license(mod, license);
72535
72536 /*
72537 * ndiswrapper is under GPL by itself, but loads proprietary modules.
72538@@ -2351,6 +2470,31 @@ static noinline struct module *load_module(void __user *umod,
72539 /* Set up MODINFO_ATTR fields */
72540 setup_modinfo(mod, sechdrs, infoindex);
72541
72542+ mod->args = args;
72543+
72544+#ifdef CONFIG_GRKERNSEC_MODHARDEN
72545+ {
72546+ char *p, *p2;
72547+
72548+ if (strstr(mod->args, "grsec_modharden_netdev")) {
72549+ 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);
72550+ err = -EPERM;
72551+ goto cleanup;
72552+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
72553+ p += strlen("grsec_modharden_normal");
72554+ p2 = strstr(p, "_");
72555+ if (p2) {
72556+ *p2 = '\0';
72557+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
72558+ *p2 = '_';
72559+ }
72560+ err = -EPERM;
72561+ goto cleanup;
72562+ }
72563+ }
72564+#endif
72565+
72566+
72567 /* Fix up syms, so that st_value is a pointer to location. */
72568 err = simplify_symbols(sechdrs, symindex, strtab, versindex, pcpuindex,
72569 mod);
72570@@ -2431,8 +2575,8 @@ static noinline struct module *load_module(void __user *umod,
72571
72572 /* Now do relocations. */
72573 for (i = 1; i < hdr->e_shnum; i++) {
72574- const char *strtab = (char *)sechdrs[strindex].sh_addr;
72575 unsigned int info = sechdrs[i].sh_info;
72576+ strtab = (char *)sechdrs[strindex].sh_addr;
72577
72578 /* Not a valid relocation section? */
72579 if (info >= hdr->e_shnum)
72580@@ -2493,16 +2637,15 @@ static noinline struct module *load_module(void __user *umod,
72581 * Do it before processing of module parameters, so the module
72582 * can provide parameter accessor functions of its own.
72583 */
72584- if (mod->module_init)
72585- flush_icache_range((unsigned long)mod->module_init,
72586- (unsigned long)mod->module_init
72587- + mod->init_size);
72588- flush_icache_range((unsigned long)mod->module_core,
72589- (unsigned long)mod->module_core + mod->core_size);
72590+ if (mod->module_init_rx)
72591+ flush_icache_range((unsigned long)mod->module_init_rx,
72592+ (unsigned long)mod->module_init_rx
72593+ + mod->init_size_rx);
72594+ flush_icache_range((unsigned long)mod->module_core_rx,
72595+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
72596
72597 set_fs(old_fs);
72598
72599- mod->args = args;
72600 if (section_addr(hdr, sechdrs, secstrings, "__obsparm"))
72601 printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
72602 mod->name);
72603@@ -2546,12 +2689,16 @@ static noinline struct module *load_module(void __user *umod,
72604 free_unload:
72605 module_unload_free(mod);
72606 #if defined(CONFIG_MODULE_UNLOAD) && defined(CONFIG_SMP)
72607+ free_init_rx:
72608 percpu_modfree(mod->refptr);
72609- free_init:
72610 #endif
72611- module_free(mod, mod->module_init);
72612- free_core:
72613- module_free(mod, mod->module_core);
72614+ module_free_exec(mod, mod->module_init_rx);
72615+ free_core_rx:
72616+ module_free_exec(mod, mod->module_core_rx);
72617+ free_init_rw:
72618+ module_free(mod, mod->module_init_rw);
72619+ free_core_rw:
72620+ module_free(mod, mod->module_core_rw);
72621 /* mod will be freed with core. Don't access it beyond this line! */
72622 free_percpu:
72623 if (percpu)
72624@@ -2653,10 +2800,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
72625 mod->symtab = mod->core_symtab;
72626 mod->strtab = mod->core_strtab;
72627 #endif
72628- module_free(mod, mod->module_init);
72629- mod->module_init = NULL;
72630- mod->init_size = 0;
72631- mod->init_text_size = 0;
72632+ module_free(mod, mod->module_init_rw);
72633+ module_free_exec(mod, mod->module_init_rx);
72634+ mod->module_init_rw = NULL;
72635+ mod->module_init_rx = NULL;
72636+ mod->init_size_rw = 0;
72637+ mod->init_size_rx = 0;
72638 mutex_unlock(&module_mutex);
72639
72640 return 0;
72641@@ -2687,10 +2836,16 @@ static const char *get_ksymbol(struct module *mod,
72642 unsigned long nextval;
72643
72644 /* At worse, next value is at end of module */
72645- if (within_module_init(addr, mod))
72646- nextval = (unsigned long)mod->module_init+mod->init_text_size;
72647+ if (within_module_init_rx(addr, mod))
72648+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
72649+ else if (within_module_init_rw(addr, mod))
72650+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
72651+ else if (within_module_core_rx(addr, mod))
72652+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
72653+ else if (within_module_core_rw(addr, mod))
72654+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
72655 else
72656- nextval = (unsigned long)mod->module_core+mod->core_text_size;
72657+ return NULL;
72658
72659 /* Scan for closest preceeding symbol, and next symbol. (ELF
72660 starts real symbols at 1). */
72661@@ -2936,7 +3091,7 @@ static int m_show(struct seq_file *m, void *p)
72662 char buf[8];
72663
72664 seq_printf(m, "%s %u",
72665- mod->name, mod->init_size + mod->core_size);
72666+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
72667 print_unload_info(m, mod);
72668
72669 /* Informative for users. */
72670@@ -2945,7 +3100,7 @@ static int m_show(struct seq_file *m, void *p)
72671 mod->state == MODULE_STATE_COMING ? "Loading":
72672 "Live");
72673 /* Used by oprofile and other similar tools. */
72674- seq_printf(m, " 0x%p", mod->module_core);
72675+ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
72676
72677 /* Taints info */
72678 if (mod->taints)
72679@@ -2981,7 +3136,17 @@ static const struct file_operations proc_modules_operations = {
72680
72681 static int __init proc_modules_init(void)
72682 {
72683+#ifndef CONFIG_GRKERNSEC_HIDESYM
72684+#ifdef CONFIG_GRKERNSEC_PROC_USER
72685+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
72686+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72687+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
72688+#else
72689 proc_create("modules", 0, NULL, &proc_modules_operations);
72690+#endif
72691+#else
72692+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
72693+#endif
72694 return 0;
72695 }
72696 module_init(proc_modules_init);
72697@@ -3040,12 +3205,12 @@ struct module *__module_address(unsigned long addr)
72698 {
72699 struct module *mod;
72700
72701- if (addr < module_addr_min || addr > module_addr_max)
72702+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
72703+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
72704 return NULL;
72705
72706 list_for_each_entry_rcu(mod, &modules, list)
72707- if (within_module_core(addr, mod)
72708- || within_module_init(addr, mod))
72709+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
72710 return mod;
72711 return NULL;
72712 }
72713@@ -3079,11 +3244,20 @@ bool is_module_text_address(unsigned long addr)
72714 */
72715 struct module *__module_text_address(unsigned long addr)
72716 {
72717- struct module *mod = __module_address(addr);
72718+ struct module *mod;
72719+
72720+#ifdef CONFIG_X86_32
72721+ addr = ktla_ktva(addr);
72722+#endif
72723+
72724+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
72725+ return NULL;
72726+
72727+ mod = __module_address(addr);
72728+
72729 if (mod) {
72730 /* Make sure it's within the text section. */
72731- if (!within(addr, mod->module_init, mod->init_text_size)
72732- && !within(addr, mod->module_core, mod->core_text_size))
72733+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
72734 mod = NULL;
72735 }
72736 return mod;
72737diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
72738index ec815a9..fe46e99 100644
72739--- a/kernel/mutex-debug.c
72740+++ b/kernel/mutex-debug.c
72741@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
72742 }
72743
72744 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72745- struct thread_info *ti)
72746+ struct task_struct *task)
72747 {
72748 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
72749
72750 /* Mark the current thread as blocked on the lock: */
72751- ti->task->blocked_on = waiter;
72752+ task->blocked_on = waiter;
72753 }
72754
72755 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72756- struct thread_info *ti)
72757+ struct task_struct *task)
72758 {
72759 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
72760- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
72761- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
72762- ti->task->blocked_on = NULL;
72763+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
72764+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
72765+ task->blocked_on = NULL;
72766
72767 list_del_init(&waiter->list);
72768 waiter->task = NULL;
72769@@ -75,7 +75,7 @@ void debug_mutex_unlock(struct mutex *lock)
72770 return;
72771
72772 DEBUG_LOCKS_WARN_ON(lock->magic != lock);
72773- DEBUG_LOCKS_WARN_ON(lock->owner != current_thread_info());
72774+ DEBUG_LOCKS_WARN_ON(lock->owner != current);
72775 DEBUG_LOCKS_WARN_ON(!lock->wait_list.prev && !lock->wait_list.next);
72776 mutex_clear_owner(lock);
72777 }
72778diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
72779index 6b2d735..372d3c4 100644
72780--- a/kernel/mutex-debug.h
72781+++ b/kernel/mutex-debug.h
72782@@ -20,16 +20,16 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
72783 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
72784 extern void debug_mutex_add_waiter(struct mutex *lock,
72785 struct mutex_waiter *waiter,
72786- struct thread_info *ti);
72787+ struct task_struct *task);
72788 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
72789- struct thread_info *ti);
72790+ struct task_struct *task);
72791 extern void debug_mutex_unlock(struct mutex *lock);
72792 extern void debug_mutex_init(struct mutex *lock, const char *name,
72793 struct lock_class_key *key);
72794
72795 static inline void mutex_set_owner(struct mutex *lock)
72796 {
72797- lock->owner = current_thread_info();
72798+ lock->owner = current;
72799 }
72800
72801 static inline void mutex_clear_owner(struct mutex *lock)
72802diff --git a/kernel/mutex.c b/kernel/mutex.c
72803index f85644c..5ee9f77 100644
72804--- a/kernel/mutex.c
72805+++ b/kernel/mutex.c
72806@@ -169,7 +169,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72807 */
72808
72809 for (;;) {
72810- struct thread_info *owner;
72811+ struct task_struct *owner;
72812
72813 /*
72814 * If we own the BKL, then don't spin. The owner of
72815@@ -214,7 +214,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72816 spin_lock_mutex(&lock->wait_lock, flags);
72817
72818 debug_mutex_lock_common(lock, &waiter);
72819- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
72820+ debug_mutex_add_waiter(lock, &waiter, task);
72821
72822 /* add waiting tasks to the end of the waitqueue (FIFO): */
72823 list_add_tail(&waiter.list, &lock->wait_list);
72824@@ -243,8 +243,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72825 * TASK_UNINTERRUPTIBLE case.)
72826 */
72827 if (unlikely(signal_pending_state(state, task))) {
72828- mutex_remove_waiter(lock, &waiter,
72829- task_thread_info(task));
72830+ mutex_remove_waiter(lock, &waiter, task);
72831 mutex_release(&lock->dep_map, 1, ip);
72832 spin_unlock_mutex(&lock->wait_lock, flags);
72833
72834@@ -265,7 +264,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
72835 done:
72836 lock_acquired(&lock->dep_map, ip);
72837 /* got the lock - rejoice! */
72838- mutex_remove_waiter(lock, &waiter, current_thread_info());
72839+ mutex_remove_waiter(lock, &waiter, task);
72840 mutex_set_owner(lock);
72841
72842 /* set it to 0 if there are no waiters left: */
72843diff --git a/kernel/mutex.h b/kernel/mutex.h
72844index 67578ca..4115fbf 100644
72845--- a/kernel/mutex.h
72846+++ b/kernel/mutex.h
72847@@ -19,7 +19,7 @@
72848 #ifdef CONFIG_SMP
72849 static inline void mutex_set_owner(struct mutex *lock)
72850 {
72851- lock->owner = current_thread_info();
72852+ lock->owner = current;
72853 }
72854
72855 static inline void mutex_clear_owner(struct mutex *lock)
72856diff --git a/kernel/panic.c b/kernel/panic.c
72857index 96b45d0..45c447a 100644
72858--- a/kernel/panic.c
72859+++ b/kernel/panic.c
72860@@ -352,7 +352,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller, struc
72861 const char *board;
72862
72863 printk(KERN_WARNING "------------[ cut here ]------------\n");
72864- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
72865+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
72866 board = dmi_get_system_info(DMI_PRODUCT_NAME);
72867 if (board)
72868 printk(KERN_WARNING "Hardware name: %s\n", board);
72869@@ -392,7 +392,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
72870 */
72871 void __stack_chk_fail(void)
72872 {
72873- panic("stack-protector: Kernel stack is corrupted in: %p\n",
72874+ dump_stack();
72875+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
72876 __builtin_return_address(0));
72877 }
72878 EXPORT_SYMBOL(__stack_chk_fail);
72879diff --git a/kernel/params.c b/kernel/params.c
72880index d656c27..21e452c 100644
72881--- a/kernel/params.c
72882+++ b/kernel/params.c
72883@@ -725,7 +725,7 @@ static ssize_t module_attr_store(struct kobject *kobj,
72884 return ret;
72885 }
72886
72887-static struct sysfs_ops module_sysfs_ops = {
72888+static const struct sysfs_ops module_sysfs_ops = {
72889 .show = module_attr_show,
72890 .store = module_attr_store,
72891 };
72892@@ -739,7 +739,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
72893 return 0;
72894 }
72895
72896-static struct kset_uevent_ops module_uevent_ops = {
72897+static const struct kset_uevent_ops module_uevent_ops = {
72898 .filter = uevent_filter,
72899 };
72900
72901diff --git a/kernel/perf_event.c b/kernel/perf_event.c
72902index 37ebc14..9c121d9 100644
72903--- a/kernel/perf_event.c
72904+++ b/kernel/perf_event.c
72905@@ -77,7 +77,7 @@ int sysctl_perf_event_mlock __read_mostly = 516; /* 'free' kb per user */
72906 */
72907 int sysctl_perf_event_sample_rate __read_mostly = 100000;
72908
72909-static atomic64_t perf_event_id;
72910+static atomic64_unchecked_t perf_event_id;
72911
72912 /*
72913 * Lock for (sysadmin-configurable) event reservations:
72914@@ -1094,9 +1094,9 @@ static void __perf_event_sync_stat(struct perf_event *event,
72915 * In order to keep per-task stats reliable we need to flip the event
72916 * values when we flip the contexts.
72917 */
72918- value = atomic64_read(&next_event->count);
72919- value = atomic64_xchg(&event->count, value);
72920- atomic64_set(&next_event->count, value);
72921+ value = atomic64_read_unchecked(&next_event->count);
72922+ value = atomic64_xchg_unchecked(&event->count, value);
72923+ atomic64_set_unchecked(&next_event->count, value);
72924
72925 swap(event->total_time_enabled, next_event->total_time_enabled);
72926 swap(event->total_time_running, next_event->total_time_running);
72927@@ -1552,7 +1552,7 @@ static u64 perf_event_read(struct perf_event *event)
72928 update_event_times(event);
72929 }
72930
72931- return atomic64_read(&event->count);
72932+ return atomic64_read_unchecked(&event->count);
72933 }
72934
72935 /*
72936@@ -1790,11 +1790,11 @@ static int perf_event_read_group(struct perf_event *event,
72937 values[n++] = 1 + leader->nr_siblings;
72938 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
72939 values[n++] = leader->total_time_enabled +
72940- atomic64_read(&leader->child_total_time_enabled);
72941+ atomic64_read_unchecked(&leader->child_total_time_enabled);
72942 }
72943 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
72944 values[n++] = leader->total_time_running +
72945- atomic64_read(&leader->child_total_time_running);
72946+ atomic64_read_unchecked(&leader->child_total_time_running);
72947 }
72948
72949 size = n * sizeof(u64);
72950@@ -1829,11 +1829,11 @@ static int perf_event_read_one(struct perf_event *event,
72951 values[n++] = perf_event_read_value(event);
72952 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
72953 values[n++] = event->total_time_enabled +
72954- atomic64_read(&event->child_total_time_enabled);
72955+ atomic64_read_unchecked(&event->child_total_time_enabled);
72956 }
72957 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
72958 values[n++] = event->total_time_running +
72959- atomic64_read(&event->child_total_time_running);
72960+ atomic64_read_unchecked(&event->child_total_time_running);
72961 }
72962 if (read_format & PERF_FORMAT_ID)
72963 values[n++] = primary_event_id(event);
72964@@ -1903,7 +1903,7 @@ static unsigned int perf_poll(struct file *file, poll_table *wait)
72965 static void perf_event_reset(struct perf_event *event)
72966 {
72967 (void)perf_event_read(event);
72968- atomic64_set(&event->count, 0);
72969+ atomic64_set_unchecked(&event->count, 0);
72970 perf_event_update_userpage(event);
72971 }
72972
72973@@ -2079,15 +2079,15 @@ void perf_event_update_userpage(struct perf_event *event)
72974 ++userpg->lock;
72975 barrier();
72976 userpg->index = perf_event_index(event);
72977- userpg->offset = atomic64_read(&event->count);
72978+ userpg->offset = atomic64_read_unchecked(&event->count);
72979 if (event->state == PERF_EVENT_STATE_ACTIVE)
72980- userpg->offset -= atomic64_read(&event->hw.prev_count);
72981+ userpg->offset -= atomic64_read_unchecked(&event->hw.prev_count);
72982
72983 userpg->time_enabled = event->total_time_enabled +
72984- atomic64_read(&event->child_total_time_enabled);
72985+ atomic64_read_unchecked(&event->child_total_time_enabled);
72986
72987 userpg->time_running = event->total_time_running +
72988- atomic64_read(&event->child_total_time_running);
72989+ atomic64_read_unchecked(&event->child_total_time_running);
72990
72991 barrier();
72992 ++userpg->lock;
72993@@ -2903,14 +2903,14 @@ static void perf_output_read_one(struct perf_output_handle *handle,
72994 u64 values[4];
72995 int n = 0;
72996
72997- values[n++] = atomic64_read(&event->count);
72998+ values[n++] = atomic64_read_unchecked(&event->count);
72999 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
73000 values[n++] = event->total_time_enabled +
73001- atomic64_read(&event->child_total_time_enabled);
73002+ atomic64_read_unchecked(&event->child_total_time_enabled);
73003 }
73004 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
73005 values[n++] = event->total_time_running +
73006- atomic64_read(&event->child_total_time_running);
73007+ atomic64_read_unchecked(&event->child_total_time_running);
73008 }
73009 if (read_format & PERF_FORMAT_ID)
73010 values[n++] = primary_event_id(event);
73011@@ -2940,7 +2940,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
73012 if (leader != event)
73013 leader->pmu->read(leader);
73014
73015- values[n++] = atomic64_read(&leader->count);
73016+ values[n++] = atomic64_read_unchecked(&leader->count);
73017 if (read_format & PERF_FORMAT_ID)
73018 values[n++] = primary_event_id(leader);
73019
73020@@ -2952,7 +2952,7 @@ static void perf_output_read_group(struct perf_output_handle *handle,
73021 if (sub != event)
73022 sub->pmu->read(sub);
73023
73024- values[n++] = atomic64_read(&sub->count);
73025+ values[n++] = atomic64_read_unchecked(&sub->count);
73026 if (read_format & PERF_FORMAT_ID)
73027 values[n++] = primary_event_id(sub);
73028
73029@@ -3525,12 +3525,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
73030 * need to add enough zero bytes after the string to handle
73031 * the 64bit alignment we do later.
73032 */
73033- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
73034+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
73035 if (!buf) {
73036 name = strncpy(tmp, "//enomem", sizeof(tmp));
73037 goto got_name;
73038 }
73039- name = d_path(&file->f_path, buf, PATH_MAX);
73040+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
73041 if (IS_ERR(name)) {
73042 name = strncpy(tmp, "//toolong", sizeof(tmp));
73043 goto got_name;
73044@@ -3783,7 +3783,7 @@ static void perf_swevent_add(struct perf_event *event, u64 nr,
73045 {
73046 struct hw_perf_event *hwc = &event->hw;
73047
73048- atomic64_add(nr, &event->count);
73049+ atomic64_add_unchecked(nr, &event->count);
73050
73051 if (!hwc->sample_period)
73052 return;
73053@@ -4040,9 +4040,9 @@ static void cpu_clock_perf_event_update(struct perf_event *event)
73054 u64 now;
73055
73056 now = cpu_clock(cpu);
73057- prev = atomic64_read(&event->hw.prev_count);
73058- atomic64_set(&event->hw.prev_count, now);
73059- atomic64_add(now - prev, &event->count);
73060+ prev = atomic64_read_unchecked(&event->hw.prev_count);
73061+ atomic64_set_unchecked(&event->hw.prev_count, now);
73062+ atomic64_add_unchecked(now - prev, &event->count);
73063 }
73064
73065 static int cpu_clock_perf_event_enable(struct perf_event *event)
73066@@ -4050,7 +4050,7 @@ static int cpu_clock_perf_event_enable(struct perf_event *event)
73067 struct hw_perf_event *hwc = &event->hw;
73068 int cpu = raw_smp_processor_id();
73069
73070- atomic64_set(&hwc->prev_count, cpu_clock(cpu));
73071+ atomic64_set_unchecked(&hwc->prev_count, cpu_clock(cpu));
73072 perf_swevent_start_hrtimer(event);
73073
73074 return 0;
73075@@ -4082,9 +4082,9 @@ static void task_clock_perf_event_update(struct perf_event *event, u64 now)
73076 u64 prev;
73077 s64 delta;
73078
73079- prev = atomic64_xchg(&event->hw.prev_count, now);
73080+ prev = atomic64_xchg_unchecked(&event->hw.prev_count, now);
73081 delta = now - prev;
73082- atomic64_add(delta, &event->count);
73083+ atomic64_add_unchecked(delta, &event->count);
73084 }
73085
73086 static int task_clock_perf_event_enable(struct perf_event *event)
73087@@ -4094,7 +4094,7 @@ static int task_clock_perf_event_enable(struct perf_event *event)
73088
73089 now = event->ctx->time;
73090
73091- atomic64_set(&hwc->prev_count, now);
73092+ atomic64_set_unchecked(&hwc->prev_count, now);
73093
73094 perf_swevent_start_hrtimer(event);
73095
73096@@ -4289,7 +4289,7 @@ perf_event_alloc(struct perf_event_attr *attr,
73097 event->parent = parent_event;
73098
73099 event->ns = get_pid_ns(current->nsproxy->pid_ns);
73100- event->id = atomic64_inc_return(&perf_event_id);
73101+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
73102
73103 event->state = PERF_EVENT_STATE_INACTIVE;
73104
73105@@ -4720,15 +4720,15 @@ static void sync_child_event(struct perf_event *child_event,
73106 if (child_event->attr.inherit_stat)
73107 perf_event_read_event(child_event, child);
73108
73109- child_val = atomic64_read(&child_event->count);
73110+ child_val = atomic64_read_unchecked(&child_event->count);
73111
73112 /*
73113 * Add back the child's count to the parent's count:
73114 */
73115- atomic64_add(child_val, &parent_event->count);
73116- atomic64_add(child_event->total_time_enabled,
73117+ atomic64_add_unchecked(child_val, &parent_event->count);
73118+ atomic64_add_unchecked(child_event->total_time_enabled,
73119 &parent_event->child_total_time_enabled);
73120- atomic64_add(child_event->total_time_running,
73121+ atomic64_add_unchecked(child_event->total_time_running,
73122 &parent_event->child_total_time_running);
73123
73124 /*
73125diff --git a/kernel/pid.c b/kernel/pid.c
73126index fce7198..4f23a7e 100644
73127--- a/kernel/pid.c
73128+++ b/kernel/pid.c
73129@@ -33,6 +33,7 @@
73130 #include <linux/rculist.h>
73131 #include <linux/bootmem.h>
73132 #include <linux/hash.h>
73133+#include <linux/security.h>
73134 #include <linux/pid_namespace.h>
73135 #include <linux/init_task.h>
73136 #include <linux/syscalls.h>
73137@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
73138
73139 int pid_max = PID_MAX_DEFAULT;
73140
73141-#define RESERVED_PIDS 300
73142+#define RESERVED_PIDS 500
73143
73144 int pid_max_min = RESERVED_PIDS + 1;
73145 int pid_max_max = PID_MAX_LIMIT;
73146@@ -383,7 +384,14 @@ EXPORT_SYMBOL(pid_task);
73147 */
73148 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
73149 {
73150- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
73151+ struct task_struct *task;
73152+
73153+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
73154+
73155+ if (gr_pid_is_chrooted(task))
73156+ return NULL;
73157+
73158+ return task;
73159 }
73160
73161 struct task_struct *find_task_by_vpid(pid_t vnr)
73162@@ -391,6 +399,11 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
73163 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
73164 }
73165
73166+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
73167+{
73168+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
73169+}
73170+
73171 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
73172 {
73173 struct pid *pid;
73174diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
73175index 5c9dc22..d271117 100644
73176--- a/kernel/posix-cpu-timers.c
73177+++ b/kernel/posix-cpu-timers.c
73178@@ -6,6 +6,7 @@
73179 #include <linux/posix-timers.h>
73180 #include <linux/errno.h>
73181 #include <linux/math64.h>
73182+#include <linux/security.h>
73183 #include <asm/uaccess.h>
73184 #include <linux/kernel_stat.h>
73185 #include <trace/events/timer.h>
73186@@ -1697,7 +1698,7 @@ static long thread_cpu_nsleep_restart(struct restart_block *restart_block)
73187
73188 static __init int init_posix_cpu_timers(void)
73189 {
73190- struct k_clock process = {
73191+ static struct k_clock process = {
73192 .clock_getres = process_cpu_clock_getres,
73193 .clock_get = process_cpu_clock_get,
73194 .clock_set = do_posix_clock_nosettime,
73195@@ -1705,7 +1706,7 @@ static __init int init_posix_cpu_timers(void)
73196 .nsleep = process_cpu_nsleep,
73197 .nsleep_restart = process_cpu_nsleep_restart,
73198 };
73199- struct k_clock thread = {
73200+ static struct k_clock thread = {
73201 .clock_getres = thread_cpu_clock_getres,
73202 .clock_get = thread_cpu_clock_get,
73203 .clock_set = do_posix_clock_nosettime,
73204diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
73205index 5e76d22..cf1baeb 100644
73206--- a/kernel/posix-timers.c
73207+++ b/kernel/posix-timers.c
73208@@ -42,6 +42,7 @@
73209 #include <linux/compiler.h>
73210 #include <linux/idr.h>
73211 #include <linux/posix-timers.h>
73212+#include <linux/grsecurity.h>
73213 #include <linux/syscalls.h>
73214 #include <linux/wait.h>
73215 #include <linux/workqueue.h>
73216@@ -131,7 +132,7 @@ static DEFINE_SPINLOCK(idr_lock);
73217 * which we beg off on and pass to do_sys_settimeofday().
73218 */
73219
73220-static struct k_clock posix_clocks[MAX_CLOCKS];
73221+static struct k_clock *posix_clocks[MAX_CLOCKS];
73222
73223 /*
73224 * These ones are defined below.
73225@@ -157,8 +158,8 @@ static inline void unlock_timer(struct k_itimer *timr, unsigned long flags)
73226 */
73227 #define CLOCK_DISPATCH(clock, call, arglist) \
73228 ((clock) < 0 ? posix_cpu_##call arglist : \
73229- (posix_clocks[clock].call != NULL \
73230- ? (*posix_clocks[clock].call) arglist : common_##call arglist))
73231+ (posix_clocks[clock]->call != NULL \
73232+ ? (*posix_clocks[clock]->call) arglist : common_##call arglist))
73233
73234 /*
73235 * Default clock hook functions when the struct k_clock passed
73236@@ -172,7 +173,7 @@ static inline int common_clock_getres(const clockid_t which_clock,
73237 struct timespec *tp)
73238 {
73239 tp->tv_sec = 0;
73240- tp->tv_nsec = posix_clocks[which_clock].res;
73241+ tp->tv_nsec = posix_clocks[which_clock]->res;
73242 return 0;
73243 }
73244
73245@@ -217,9 +218,11 @@ static inline int invalid_clockid(const clockid_t which_clock)
73246 return 0;
73247 if ((unsigned) which_clock >= MAX_CLOCKS)
73248 return 1;
73249- if (posix_clocks[which_clock].clock_getres != NULL)
73250+ if (posix_clocks[which_clock] == NULL)
73251 return 0;
73252- if (posix_clocks[which_clock].res != 0)
73253+ if (posix_clocks[which_clock]->clock_getres != NULL)
73254+ return 0;
73255+ if (posix_clocks[which_clock]->res != 0)
73256 return 0;
73257 return 1;
73258 }
73259@@ -266,29 +269,29 @@ int posix_get_coarse_res(const clockid_t which_clock, struct timespec *tp)
73260 */
73261 static __init int init_posix_timers(void)
73262 {
73263- struct k_clock clock_realtime = {
73264+ static struct k_clock clock_realtime = {
73265 .clock_getres = hrtimer_get_res,
73266 };
73267- struct k_clock clock_monotonic = {
73268+ static struct k_clock clock_monotonic = {
73269 .clock_getres = hrtimer_get_res,
73270 .clock_get = posix_ktime_get_ts,
73271 .clock_set = do_posix_clock_nosettime,
73272 };
73273- struct k_clock clock_monotonic_raw = {
73274+ static struct k_clock clock_monotonic_raw = {
73275 .clock_getres = hrtimer_get_res,
73276 .clock_get = posix_get_monotonic_raw,
73277 .clock_set = do_posix_clock_nosettime,
73278 .timer_create = no_timer_create,
73279 .nsleep = no_nsleep,
73280 };
73281- struct k_clock clock_realtime_coarse = {
73282+ static struct k_clock clock_realtime_coarse = {
73283 .clock_getres = posix_get_coarse_res,
73284 .clock_get = posix_get_realtime_coarse,
73285 .clock_set = do_posix_clock_nosettime,
73286 .timer_create = no_timer_create,
73287 .nsleep = no_nsleep,
73288 };
73289- struct k_clock clock_monotonic_coarse = {
73290+ static struct k_clock clock_monotonic_coarse = {
73291 .clock_getres = posix_get_coarse_res,
73292 .clock_get = posix_get_monotonic_coarse,
73293 .clock_set = do_posix_clock_nosettime,
73294@@ -296,6 +299,8 @@ static __init int init_posix_timers(void)
73295 .nsleep = no_nsleep,
73296 };
73297
73298+ pax_track_stack();
73299+
73300 register_posix_clock(CLOCK_REALTIME, &clock_realtime);
73301 register_posix_clock(CLOCK_MONOTONIC, &clock_monotonic);
73302 register_posix_clock(CLOCK_MONOTONIC_RAW, &clock_monotonic_raw);
73303@@ -484,7 +489,7 @@ void register_posix_clock(const clockid_t clock_id, struct k_clock *new_clock)
73304 return;
73305 }
73306
73307- posix_clocks[clock_id] = *new_clock;
73308+ posix_clocks[clock_id] = new_clock;
73309 }
73310 EXPORT_SYMBOL_GPL(register_posix_clock);
73311
73312@@ -948,6 +953,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
73313 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
73314 return -EFAULT;
73315
73316+ /* only the CLOCK_REALTIME clock can be set, all other clocks
73317+ have their clock_set fptr set to a nosettime dummy function
73318+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
73319+ call common_clock_set, which calls do_sys_settimeofday, which
73320+ we hook
73321+ */
73322+
73323 return CLOCK_DISPATCH(which_clock, clock_set, (which_clock, &new_tp));
73324 }
73325
73326diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
73327index 04a9e90..bc355aa 100644
73328--- a/kernel/power/hibernate.c
73329+++ b/kernel/power/hibernate.c
73330@@ -48,14 +48,14 @@ enum {
73331
73332 static int hibernation_mode = HIBERNATION_SHUTDOWN;
73333
73334-static struct platform_hibernation_ops *hibernation_ops;
73335+static const struct platform_hibernation_ops *hibernation_ops;
73336
73337 /**
73338 * hibernation_set_ops - set the global hibernate operations
73339 * @ops: the hibernation operations to use in subsequent hibernation transitions
73340 */
73341
73342-void hibernation_set_ops(struct platform_hibernation_ops *ops)
73343+void hibernation_set_ops(const struct platform_hibernation_ops *ops)
73344 {
73345 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
73346 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
73347diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
73348index e8b3370..484c2e4 100644
73349--- a/kernel/power/poweroff.c
73350+++ b/kernel/power/poweroff.c
73351@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
73352 .enable_mask = SYSRQ_ENABLE_BOOT,
73353 };
73354
73355-static int pm_sysrq_init(void)
73356+static int __init pm_sysrq_init(void)
73357 {
73358 register_sysrq_key('o', &sysrq_poweroff_op);
73359 return 0;
73360diff --git a/kernel/power/process.c b/kernel/power/process.c
73361index e7cd671..56d5f459 100644
73362--- a/kernel/power/process.c
73363+++ b/kernel/power/process.c
73364@@ -37,12 +37,15 @@ static int try_to_freeze_tasks(bool sig_only)
73365 struct timeval start, end;
73366 u64 elapsed_csecs64;
73367 unsigned int elapsed_csecs;
73368+ bool timedout = false;
73369
73370 do_gettimeofday(&start);
73371
73372 end_time = jiffies + TIMEOUT;
73373 do {
73374 todo = 0;
73375+ if (time_after(jiffies, end_time))
73376+ timedout = true;
73377 read_lock(&tasklist_lock);
73378 do_each_thread(g, p) {
73379 if (frozen(p) || !freezeable(p))
73380@@ -57,15 +60,17 @@ static int try_to_freeze_tasks(bool sig_only)
73381 * It is "frozen enough". If the task does wake
73382 * up, it will immediately call try_to_freeze.
73383 */
73384- if (!task_is_stopped_or_traced(p) &&
73385- !freezer_should_skip(p))
73386+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
73387 todo++;
73388+ if (timedout) {
73389+ printk(KERN_ERR "Task refusing to freeze:\n");
73390+ sched_show_task(p);
73391+ }
73392+ }
73393 } while_each_thread(g, p);
73394 read_unlock(&tasklist_lock);
73395 yield(); /* Yield is okay here */
73396- if (time_after(jiffies, end_time))
73397- break;
73398- } while (todo);
73399+ } while (todo && !timedout);
73400
73401 do_gettimeofday(&end);
73402 elapsed_csecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
73403diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
73404index 40dd021..fb30ceb 100644
73405--- a/kernel/power/suspend.c
73406+++ b/kernel/power/suspend.c
73407@@ -23,13 +23,13 @@ const char *const pm_states[PM_SUSPEND_MAX] = {
73408 [PM_SUSPEND_MEM] = "mem",
73409 };
73410
73411-static struct platform_suspend_ops *suspend_ops;
73412+static const struct platform_suspend_ops *suspend_ops;
73413
73414 /**
73415 * suspend_set_ops - Set the global suspend method table.
73416 * @ops: Pointer to ops structure.
73417 */
73418-void suspend_set_ops(struct platform_suspend_ops *ops)
73419+void suspend_set_ops(const struct platform_suspend_ops *ops)
73420 {
73421 mutex_lock(&pm_mutex);
73422 suspend_ops = ops;
73423diff --git a/kernel/printk.c b/kernel/printk.c
73424index 4cade47..4d17900 100644
73425--- a/kernel/printk.c
73426+++ b/kernel/printk.c
73427@@ -33,6 +33,7 @@
73428 #include <linux/bootmem.h>
73429 #include <linux/syscalls.h>
73430 #include <linux/kexec.h>
73431+#include <linux/syslog.h>
73432
73433 #include <asm/uaccess.h>
73434
73435@@ -256,38 +257,30 @@ static inline void boot_delay_msec(void)
73436 }
73437 #endif
73438
73439-/*
73440- * Commands to do_syslog:
73441- *
73442- * 0 -- Close the log. Currently a NOP.
73443- * 1 -- Open the log. Currently a NOP.
73444- * 2 -- Read from the log.
73445- * 3 -- Read all messages remaining in the ring buffer.
73446- * 4 -- Read and clear all messages remaining in the ring buffer
73447- * 5 -- Clear ring buffer.
73448- * 6 -- Disable printk's to console
73449- * 7 -- Enable printk's to console
73450- * 8 -- Set level of messages printed to console
73451- * 9 -- Return number of unread characters in the log buffer
73452- * 10 -- Return size of the log buffer
73453- */
73454-int do_syslog(int type, char __user *buf, int len)
73455+int do_syslog(int type, char __user *buf, int len, bool from_file)
73456 {
73457 unsigned i, j, limit, count;
73458 int do_clear = 0;
73459 char c;
73460 int error = 0;
73461
73462- error = security_syslog(type);
73463+#ifdef CONFIG_GRKERNSEC_DMESG
73464+ if (grsec_enable_dmesg &&
73465+ (!from_file || (from_file && type == SYSLOG_ACTION_OPEN)) &&
73466+ !capable(CAP_SYS_ADMIN))
73467+ return -EPERM;
73468+#endif
73469+
73470+ error = security_syslog(type, from_file);
73471 if (error)
73472 return error;
73473
73474 switch (type) {
73475- case 0: /* Close log */
73476+ case SYSLOG_ACTION_CLOSE: /* Close log */
73477 break;
73478- case 1: /* Open log */
73479+ case SYSLOG_ACTION_OPEN: /* Open log */
73480 break;
73481- case 2: /* Read from log */
73482+ case SYSLOG_ACTION_READ: /* Read from log */
73483 error = -EINVAL;
73484 if (!buf || len < 0)
73485 goto out;
73486@@ -318,10 +311,12 @@ int do_syslog(int type, char __user *buf, int len)
73487 if (!error)
73488 error = i;
73489 break;
73490- case 4: /* Read/clear last kernel messages */
73491+ /* Read/clear last kernel messages */
73492+ case SYSLOG_ACTION_READ_CLEAR:
73493 do_clear = 1;
73494 /* FALL THRU */
73495- case 3: /* Read last kernel messages */
73496+ /* Read last kernel messages */
73497+ case SYSLOG_ACTION_READ_ALL:
73498 error = -EINVAL;
73499 if (!buf || len < 0)
73500 goto out;
73501@@ -374,21 +369,25 @@ int do_syslog(int type, char __user *buf, int len)
73502 }
73503 }
73504 break;
73505- case 5: /* Clear ring buffer */
73506+ /* Clear ring buffer */
73507+ case SYSLOG_ACTION_CLEAR:
73508 logged_chars = 0;
73509 break;
73510- case 6: /* Disable logging to console */
73511+ /* Disable logging to console */
73512+ case SYSLOG_ACTION_CONSOLE_OFF:
73513 if (saved_console_loglevel == -1)
73514 saved_console_loglevel = console_loglevel;
73515 console_loglevel = minimum_console_loglevel;
73516 break;
73517- case 7: /* Enable logging to console */
73518+ /* Enable logging to console */
73519+ case SYSLOG_ACTION_CONSOLE_ON:
73520 if (saved_console_loglevel != -1) {
73521 console_loglevel = saved_console_loglevel;
73522 saved_console_loglevel = -1;
73523 }
73524 break;
73525- case 8: /* Set level of messages printed to console */
73526+ /* Set level of messages printed to console */
73527+ case SYSLOG_ACTION_CONSOLE_LEVEL:
73528 error = -EINVAL;
73529 if (len < 1 || len > 8)
73530 goto out;
73531@@ -399,10 +398,12 @@ int do_syslog(int type, char __user *buf, int len)
73532 saved_console_loglevel = -1;
73533 error = 0;
73534 break;
73535- case 9: /* Number of chars in the log buffer */
73536+ /* Number of chars in the log buffer */
73537+ case SYSLOG_ACTION_SIZE_UNREAD:
73538 error = log_end - log_start;
73539 break;
73540- case 10: /* Size of the log buffer */
73541+ /* Size of the log buffer */
73542+ case SYSLOG_ACTION_SIZE_BUFFER:
73543 error = log_buf_len;
73544 break;
73545 default:
73546@@ -415,7 +416,7 @@ out:
73547
73548 SYSCALL_DEFINE3(syslog, int, type, char __user *, buf, int, len)
73549 {
73550- return do_syslog(type, buf, len);
73551+ return do_syslog(type, buf, len, SYSLOG_FROM_CALL);
73552 }
73553
73554 /*
73555diff --git a/kernel/profile.c b/kernel/profile.c
73556index dfadc5b..7f59404 100644
73557--- a/kernel/profile.c
73558+++ b/kernel/profile.c
73559@@ -39,7 +39,7 @@ struct profile_hit {
73560 /* Oprofile timer tick hook */
73561 static int (*timer_hook)(struct pt_regs *) __read_mostly;
73562
73563-static atomic_t *prof_buffer;
73564+static atomic_unchecked_t *prof_buffer;
73565 static unsigned long prof_len, prof_shift;
73566
73567 int prof_on __read_mostly;
73568@@ -283,7 +283,7 @@ static void profile_flip_buffers(void)
73569 hits[i].pc = 0;
73570 continue;
73571 }
73572- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
73573+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
73574 hits[i].hits = hits[i].pc = 0;
73575 }
73576 }
73577@@ -346,9 +346,9 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits)
73578 * Add the current hit(s) and flush the write-queue out
73579 * to the global buffer:
73580 */
73581- atomic_add(nr_hits, &prof_buffer[pc]);
73582+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
73583 for (i = 0; i < NR_PROFILE_HIT; ++i) {
73584- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
73585+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
73586 hits[i].pc = hits[i].hits = 0;
73587 }
73588 out:
73589@@ -426,7 +426,7 @@ void profile_hits(int type, void *__pc, unsigned int nr_hits)
73590 if (prof_on != type || !prof_buffer)
73591 return;
73592 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
73593- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
73594+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
73595 }
73596 #endif /* !CONFIG_SMP */
73597 EXPORT_SYMBOL_GPL(profile_hits);
73598@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
73599 return -EFAULT;
73600 buf++; p++; count--; read++;
73601 }
73602- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
73603+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
73604 if (copy_to_user(buf, (void *)pnt, count))
73605 return -EFAULT;
73606 read += count;
73607@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
73608 }
73609 #endif
73610 profile_discard_flip_buffers();
73611- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
73612+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
73613 return count;
73614 }
73615
73616diff --git a/kernel/ptrace.c b/kernel/ptrace.c
73617index 05625f6..733bf70 100644
73618--- a/kernel/ptrace.c
73619+++ b/kernel/ptrace.c
73620@@ -117,7 +117,8 @@ int ptrace_check_attach(struct task_struct *child, int kill)
73621 return ret;
73622 }
73623
73624-int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73625+static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
73626+ unsigned int log)
73627 {
73628 const struct cred *cred = current_cred(), *tcred;
73629
73630@@ -141,7 +142,9 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73631 cred->gid != tcred->egid ||
73632 cred->gid != tcred->sgid ||
73633 cred->gid != tcred->gid) &&
73634- !capable(CAP_SYS_PTRACE)) {
73635+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
73636+ (log && !capable(CAP_SYS_PTRACE)))
73637+ ) {
73638 rcu_read_unlock();
73639 return -EPERM;
73640 }
73641@@ -149,7 +152,9 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
73642 smp_rmb();
73643 if (task->mm)
73644 dumpable = get_dumpable(task->mm);
73645- if (!dumpable && !capable(CAP_SYS_PTRACE))
73646+ if (!dumpable &&
73647+ ((!log && !capable_nolog(CAP_SYS_PTRACE)) ||
73648+ (log && !capable(CAP_SYS_PTRACE))))
73649 return -EPERM;
73650
73651 return security_ptrace_access_check(task, mode);
73652@@ -159,7 +164,16 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
73653 {
73654 int err;
73655 task_lock(task);
73656- err = __ptrace_may_access(task, mode);
73657+ err = __ptrace_may_access(task, mode, 0);
73658+ task_unlock(task);
73659+ return !err;
73660+}
73661+
73662+bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
73663+{
73664+ int err;
73665+ task_lock(task);
73666+ err = __ptrace_may_access(task, mode, 1);
73667 task_unlock(task);
73668 return !err;
73669 }
73670@@ -186,7 +200,7 @@ int ptrace_attach(struct task_struct *task)
73671 goto out;
73672
73673 task_lock(task);
73674- retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
73675+ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
73676 task_unlock(task);
73677 if (retval)
73678 goto unlock_creds;
73679@@ -199,7 +213,7 @@ int ptrace_attach(struct task_struct *task)
73680 goto unlock_tasklist;
73681
73682 task->ptrace = PT_PTRACED;
73683- if (capable(CAP_SYS_PTRACE))
73684+ if (capable_nolog(CAP_SYS_PTRACE))
73685 task->ptrace |= PT_PTRACE_CAP;
73686
73687 __ptrace_link(task, current);
73688@@ -351,6 +365,8 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
73689 {
73690 int copied = 0;
73691
73692+ pax_track_stack();
73693+
73694 while (len > 0) {
73695 char buf[128];
73696 int this_len, retval;
73697@@ -376,6 +392,8 @@ int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long ds
73698 {
73699 int copied = 0;
73700
73701+ pax_track_stack();
73702+
73703 while (len > 0) {
73704 char buf[128];
73705 int this_len, retval;
73706@@ -517,6 +535,8 @@ int ptrace_request(struct task_struct *child, long request,
73707 int ret = -EIO;
73708 siginfo_t siginfo;
73709
73710+ pax_track_stack();
73711+
73712 switch (request) {
73713 case PTRACE_PEEKTEXT:
73714 case PTRACE_PEEKDATA:
73715@@ -532,18 +552,18 @@ int ptrace_request(struct task_struct *child, long request,
73716 ret = ptrace_setoptions(child, data);
73717 break;
73718 case PTRACE_GETEVENTMSG:
73719- ret = put_user(child->ptrace_message, (unsigned long __user *) data);
73720+ ret = put_user(child->ptrace_message, (__force unsigned long __user *) data);
73721 break;
73722
73723 case PTRACE_GETSIGINFO:
73724 ret = ptrace_getsiginfo(child, &siginfo);
73725 if (!ret)
73726- ret = copy_siginfo_to_user((siginfo_t __user *) data,
73727+ ret = copy_siginfo_to_user((__force siginfo_t __user *) data,
73728 &siginfo);
73729 break;
73730
73731 case PTRACE_SETSIGINFO:
73732- if (copy_from_user(&siginfo, (siginfo_t __user *) data,
73733+ if (copy_from_user(&siginfo, (__force siginfo_t __user *) data,
73734 sizeof siginfo))
73735 ret = -EFAULT;
73736 else
73737@@ -621,14 +641,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
73738 goto out;
73739 }
73740
73741+ if (gr_handle_ptrace(child, request)) {
73742+ ret = -EPERM;
73743+ goto out_put_task_struct;
73744+ }
73745+
73746 if (request == PTRACE_ATTACH) {
73747 ret = ptrace_attach(child);
73748 /*
73749 * Some architectures need to do book-keeping after
73750 * a ptrace attach.
73751 */
73752- if (!ret)
73753+ if (!ret) {
73754 arch_ptrace_attach(child);
73755+ gr_audit_ptrace(child);
73756+ }
73757 goto out_put_task_struct;
73758 }
73759
73760@@ -653,7 +680,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
73761 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
73762 if (copied != sizeof(tmp))
73763 return -EIO;
73764- return put_user(tmp, (unsigned long __user *)data);
73765+ return put_user(tmp, (__force unsigned long __user *)data);
73766 }
73767
73768 int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data)
73769@@ -675,6 +702,8 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
73770 siginfo_t siginfo;
73771 int ret;
73772
73773+ pax_track_stack();
73774+
73775 switch (request) {
73776 case PTRACE_PEEKTEXT:
73777 case PTRACE_PEEKDATA:
73778@@ -740,14 +769,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
73779 goto out;
73780 }
73781
73782+ if (gr_handle_ptrace(child, request)) {
73783+ ret = -EPERM;
73784+ goto out_put_task_struct;
73785+ }
73786+
73787 if (request == PTRACE_ATTACH) {
73788 ret = ptrace_attach(child);
73789 /*
73790 * Some architectures need to do book-keeping after
73791 * a ptrace attach.
73792 */
73793- if (!ret)
73794+ if (!ret) {
73795 arch_ptrace_attach(child);
73796+ gr_audit_ptrace(child);
73797+ }
73798 goto out_put_task_struct;
73799 }
73800
73801diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
73802index 697c0a0..2402696 100644
73803--- a/kernel/rcutorture.c
73804+++ b/kernel/rcutorture.c
73805@@ -118,12 +118,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
73806 { 0 };
73807 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
73808 { 0 };
73809-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
73810-static atomic_t n_rcu_torture_alloc;
73811-static atomic_t n_rcu_torture_alloc_fail;
73812-static atomic_t n_rcu_torture_free;
73813-static atomic_t n_rcu_torture_mberror;
73814-static atomic_t n_rcu_torture_error;
73815+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
73816+static atomic_unchecked_t n_rcu_torture_alloc;
73817+static atomic_unchecked_t n_rcu_torture_alloc_fail;
73818+static atomic_unchecked_t n_rcu_torture_free;
73819+static atomic_unchecked_t n_rcu_torture_mberror;
73820+static atomic_unchecked_t n_rcu_torture_error;
73821 static long n_rcu_torture_timers;
73822 static struct list_head rcu_torture_removed;
73823 static cpumask_var_t shuffle_tmp_mask;
73824@@ -187,11 +187,11 @@ rcu_torture_alloc(void)
73825
73826 spin_lock_bh(&rcu_torture_lock);
73827 if (list_empty(&rcu_torture_freelist)) {
73828- atomic_inc(&n_rcu_torture_alloc_fail);
73829+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
73830 spin_unlock_bh(&rcu_torture_lock);
73831 return NULL;
73832 }
73833- atomic_inc(&n_rcu_torture_alloc);
73834+ atomic_inc_unchecked(&n_rcu_torture_alloc);
73835 p = rcu_torture_freelist.next;
73836 list_del_init(p);
73837 spin_unlock_bh(&rcu_torture_lock);
73838@@ -204,7 +204,7 @@ rcu_torture_alloc(void)
73839 static void
73840 rcu_torture_free(struct rcu_torture *p)
73841 {
73842- atomic_inc(&n_rcu_torture_free);
73843+ atomic_inc_unchecked(&n_rcu_torture_free);
73844 spin_lock_bh(&rcu_torture_lock);
73845 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
73846 spin_unlock_bh(&rcu_torture_lock);
73847@@ -319,7 +319,7 @@ rcu_torture_cb(struct rcu_head *p)
73848 i = rp->rtort_pipe_count;
73849 if (i > RCU_TORTURE_PIPE_LEN)
73850 i = RCU_TORTURE_PIPE_LEN;
73851- atomic_inc(&rcu_torture_wcount[i]);
73852+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
73853 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
73854 rp->rtort_mbtest = 0;
73855 rcu_torture_free(rp);
73856@@ -359,7 +359,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
73857 i = rp->rtort_pipe_count;
73858 if (i > RCU_TORTURE_PIPE_LEN)
73859 i = RCU_TORTURE_PIPE_LEN;
73860- atomic_inc(&rcu_torture_wcount[i]);
73861+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
73862 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
73863 rp->rtort_mbtest = 0;
73864 list_del(&rp->rtort_free);
73865@@ -653,7 +653,7 @@ rcu_torture_writer(void *arg)
73866 i = old_rp->rtort_pipe_count;
73867 if (i > RCU_TORTURE_PIPE_LEN)
73868 i = RCU_TORTURE_PIPE_LEN;
73869- atomic_inc(&rcu_torture_wcount[i]);
73870+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
73871 old_rp->rtort_pipe_count++;
73872 cur_ops->deferred_free(old_rp);
73873 }
73874@@ -718,7 +718,7 @@ static void rcu_torture_timer(unsigned long unused)
73875 return;
73876 }
73877 if (p->rtort_mbtest == 0)
73878- atomic_inc(&n_rcu_torture_mberror);
73879+ atomic_inc_unchecked(&n_rcu_torture_mberror);
73880 spin_lock(&rand_lock);
73881 cur_ops->read_delay(&rand);
73882 n_rcu_torture_timers++;
73883@@ -776,7 +776,7 @@ rcu_torture_reader(void *arg)
73884 continue;
73885 }
73886 if (p->rtort_mbtest == 0)
73887- atomic_inc(&n_rcu_torture_mberror);
73888+ atomic_inc_unchecked(&n_rcu_torture_mberror);
73889 cur_ops->read_delay(&rand);
73890 preempt_disable();
73891 pipe_count = p->rtort_pipe_count;
73892@@ -834,17 +834,17 @@ rcu_torture_printk(char *page)
73893 rcu_torture_current,
73894 rcu_torture_current_version,
73895 list_empty(&rcu_torture_freelist),
73896- atomic_read(&n_rcu_torture_alloc),
73897- atomic_read(&n_rcu_torture_alloc_fail),
73898- atomic_read(&n_rcu_torture_free),
73899- atomic_read(&n_rcu_torture_mberror),
73900+ atomic_read_unchecked(&n_rcu_torture_alloc),
73901+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
73902+ atomic_read_unchecked(&n_rcu_torture_free),
73903+ atomic_read_unchecked(&n_rcu_torture_mberror),
73904 n_rcu_torture_timers);
73905- if (atomic_read(&n_rcu_torture_mberror) != 0)
73906+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0)
73907 cnt += sprintf(&page[cnt], " !!!");
73908 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
73909 if (i > 1) {
73910 cnt += sprintf(&page[cnt], "!!! ");
73911- atomic_inc(&n_rcu_torture_error);
73912+ atomic_inc_unchecked(&n_rcu_torture_error);
73913 WARN_ON_ONCE(1);
73914 }
73915 cnt += sprintf(&page[cnt], "Reader Pipe: ");
73916@@ -858,7 +858,7 @@ rcu_torture_printk(char *page)
73917 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
73918 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
73919 cnt += sprintf(&page[cnt], " %d",
73920- atomic_read(&rcu_torture_wcount[i]));
73921+ atomic_read_unchecked(&rcu_torture_wcount[i]));
73922 }
73923 cnt += sprintf(&page[cnt], "\n");
73924 if (cur_ops->stats)
73925@@ -1084,7 +1084,7 @@ rcu_torture_cleanup(void)
73926
73927 if (cur_ops->cleanup)
73928 cur_ops->cleanup();
73929- if (atomic_read(&n_rcu_torture_error))
73930+ if (atomic_read_unchecked(&n_rcu_torture_error))
73931 rcu_torture_print_module_parms("End of test: FAILURE");
73932 else
73933 rcu_torture_print_module_parms("End of test: SUCCESS");
73934@@ -1138,13 +1138,13 @@ rcu_torture_init(void)
73935
73936 rcu_torture_current = NULL;
73937 rcu_torture_current_version = 0;
73938- atomic_set(&n_rcu_torture_alloc, 0);
73939- atomic_set(&n_rcu_torture_alloc_fail, 0);
73940- atomic_set(&n_rcu_torture_free, 0);
73941- atomic_set(&n_rcu_torture_mberror, 0);
73942- atomic_set(&n_rcu_torture_error, 0);
73943+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
73944+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
73945+ atomic_set_unchecked(&n_rcu_torture_free, 0);
73946+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
73947+ atomic_set_unchecked(&n_rcu_torture_error, 0);
73948 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
73949- atomic_set(&rcu_torture_wcount[i], 0);
73950+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
73951 for_each_possible_cpu(cpu) {
73952 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
73953 per_cpu(rcu_torture_count, cpu)[i] = 0;
73954diff --git a/kernel/rcutree.c b/kernel/rcutree.c
73955index 683c4f3..97f54c6 100644
73956--- a/kernel/rcutree.c
73957+++ b/kernel/rcutree.c
73958@@ -1303,7 +1303,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
73959 /*
73960 * Do softirq processing for the current CPU.
73961 */
73962-static void rcu_process_callbacks(struct softirq_action *unused)
73963+static void rcu_process_callbacks(void)
73964 {
73965 /*
73966 * Memory references from any prior RCU read-side critical sections
73967diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
73968index c03edf7..ac1b341 100644
73969--- a/kernel/rcutree_plugin.h
73970+++ b/kernel/rcutree_plugin.h
73971@@ -145,7 +145,7 @@ static void rcu_preempt_note_context_switch(int cpu)
73972 */
73973 void __rcu_read_lock(void)
73974 {
73975- ACCESS_ONCE(current->rcu_read_lock_nesting)++;
73976+ ACCESS_ONCE_RW(current->rcu_read_lock_nesting)++;
73977 barrier(); /* needed if we ever invoke rcu_read_lock in rcutree.c */
73978 }
73979 EXPORT_SYMBOL_GPL(__rcu_read_lock);
73980@@ -251,7 +251,7 @@ void __rcu_read_unlock(void)
73981 struct task_struct *t = current;
73982
73983 barrier(); /* needed if we ever invoke rcu_read_unlock in rcutree.c */
73984- if (--ACCESS_ONCE(t->rcu_read_lock_nesting) == 0 &&
73985+ if (--ACCESS_ONCE_RW(t->rcu_read_lock_nesting) == 0 &&
73986 unlikely(ACCESS_ONCE(t->rcu_read_unlock_special)))
73987 rcu_read_unlock_special(t);
73988 }
73989diff --git a/kernel/relay.c b/kernel/relay.c
73990index 760c262..a9fd241 100644
73991--- a/kernel/relay.c
73992+++ b/kernel/relay.c
73993@@ -1222,7 +1222,7 @@ static int subbuf_splice_actor(struct file *in,
73994 unsigned int flags,
73995 int *nonpad_ret)
73996 {
73997- unsigned int pidx, poff, total_len, subbuf_pages, nr_pages, ret;
73998+ unsigned int pidx, poff, total_len, subbuf_pages, nr_pages;
73999 struct rchan_buf *rbuf = in->private_data;
74000 unsigned int subbuf_size = rbuf->chan->subbuf_size;
74001 uint64_t pos = (uint64_t) *ppos;
74002@@ -1241,6 +1241,9 @@ static int subbuf_splice_actor(struct file *in,
74003 .ops = &relay_pipe_buf_ops,
74004 .spd_release = relay_page_release,
74005 };
74006+ ssize_t ret;
74007+
74008+ pax_track_stack();
74009
74010 if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
74011 return 0;
74012diff --git a/kernel/resource.c b/kernel/resource.c
74013index fb11a58..4e61ae1 100644
74014--- a/kernel/resource.c
74015+++ b/kernel/resource.c
74016@@ -132,8 +132,18 @@ static const struct file_operations proc_iomem_operations = {
74017
74018 static int __init ioresources_init(void)
74019 {
74020+#ifdef CONFIG_GRKERNSEC_PROC_ADD
74021+#ifdef CONFIG_GRKERNSEC_PROC_USER
74022+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
74023+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
74024+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74025+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
74026+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
74027+#endif
74028+#else
74029 proc_create("ioports", 0, NULL, &proc_ioports_operations);
74030 proc_create("iomem", 0, NULL, &proc_iomem_operations);
74031+#endif
74032 return 0;
74033 }
74034 __initcall(ioresources_init);
74035diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
74036index a56f629..1fc4989 100644
74037--- a/kernel/rtmutex-tester.c
74038+++ b/kernel/rtmutex-tester.c
74039@@ -21,7 +21,7 @@
74040 #define MAX_RT_TEST_MUTEXES 8
74041
74042 static spinlock_t rttest_lock;
74043-static atomic_t rttest_event;
74044+static atomic_unchecked_t rttest_event;
74045
74046 struct test_thread_data {
74047 int opcode;
74048@@ -64,7 +64,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
74049
74050 case RTTEST_LOCKCONT:
74051 td->mutexes[td->opdata] = 1;
74052- td->event = atomic_add_return(1, &rttest_event);
74053+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74054 return 0;
74055
74056 case RTTEST_RESET:
74057@@ -82,7 +82,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
74058 return 0;
74059
74060 case RTTEST_RESETEVENT:
74061- atomic_set(&rttest_event, 0);
74062+ atomic_set_unchecked(&rttest_event, 0);
74063 return 0;
74064
74065 default:
74066@@ -99,9 +99,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
74067 return ret;
74068
74069 td->mutexes[id] = 1;
74070- td->event = atomic_add_return(1, &rttest_event);
74071+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74072 rt_mutex_lock(&mutexes[id]);
74073- td->event = atomic_add_return(1, &rttest_event);
74074+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74075 td->mutexes[id] = 4;
74076 return 0;
74077
74078@@ -112,9 +112,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
74079 return ret;
74080
74081 td->mutexes[id] = 1;
74082- td->event = atomic_add_return(1, &rttest_event);
74083+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74084 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
74085- td->event = atomic_add_return(1, &rttest_event);
74086+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74087 td->mutexes[id] = ret ? 0 : 4;
74088 return ret ? -EINTR : 0;
74089
74090@@ -123,9 +123,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
74091 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
74092 return ret;
74093
74094- td->event = atomic_add_return(1, &rttest_event);
74095+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74096 rt_mutex_unlock(&mutexes[id]);
74097- td->event = atomic_add_return(1, &rttest_event);
74098+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74099 td->mutexes[id] = 0;
74100 return 0;
74101
74102@@ -187,7 +187,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
74103 break;
74104
74105 td->mutexes[dat] = 2;
74106- td->event = atomic_add_return(1, &rttest_event);
74107+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74108 break;
74109
74110 case RTTEST_LOCKBKL:
74111@@ -208,7 +208,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
74112 return;
74113
74114 td->mutexes[dat] = 3;
74115- td->event = atomic_add_return(1, &rttest_event);
74116+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74117 break;
74118
74119 case RTTEST_LOCKNOWAIT:
74120@@ -220,7 +220,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
74121 return;
74122
74123 td->mutexes[dat] = 1;
74124- td->event = atomic_add_return(1, &rttest_event);
74125+ td->event = atomic_add_return_unchecked(1, &rttest_event);
74126 return;
74127
74128 case RTTEST_LOCKBKL:
74129diff --git a/kernel/rtmutex.c b/kernel/rtmutex.c
74130index 29bd4ba..8c5de90 100644
74131--- a/kernel/rtmutex.c
74132+++ b/kernel/rtmutex.c
74133@@ -511,7 +511,7 @@ static void wakeup_next_waiter(struct rt_mutex *lock)
74134 */
74135 spin_lock_irqsave(&pendowner->pi_lock, flags);
74136
74137- WARN_ON(!pendowner->pi_blocked_on);
74138+ BUG_ON(!pendowner->pi_blocked_on);
74139 WARN_ON(pendowner->pi_blocked_on != waiter);
74140 WARN_ON(pendowner->pi_blocked_on->lock != lock);
74141
74142diff --git a/kernel/sched.c b/kernel/sched.c
74143index 0591df8..6e343c3 100644
74144--- a/kernel/sched.c
74145+++ b/kernel/sched.c
74146@@ -2764,9 +2764,10 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
74147 {
74148 unsigned long flags;
74149 struct rq *rq;
74150- int cpu = get_cpu();
74151
74152 #ifdef CONFIG_SMP
74153+ int cpu = get_cpu();
74154+
74155 rq = task_rq_lock(p, &flags);
74156 p->state = TASK_WAKING;
74157
74158@@ -5043,7 +5044,7 @@ out:
74159 * In CONFIG_NO_HZ case, the idle load balance owner will do the
74160 * rebalancing for all the cpus for whom scheduler ticks are stopped.
74161 */
74162-static void run_rebalance_domains(struct softirq_action *h)
74163+static void run_rebalance_domains(void)
74164 {
74165 int this_cpu = smp_processor_id();
74166 struct rq *this_rq = cpu_rq(this_cpu);
74167@@ -5700,6 +5701,8 @@ asmlinkage void __sched schedule(void)
74168 struct rq *rq;
74169 int cpu;
74170
74171+ pax_track_stack();
74172+
74173 need_resched:
74174 preempt_disable();
74175 cpu = smp_processor_id();
74176@@ -5770,7 +5773,7 @@ EXPORT_SYMBOL(schedule);
74177 * Look out! "owner" is an entirely speculative pointer
74178 * access and not reliable.
74179 */
74180-int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
74181+int mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner)
74182 {
74183 unsigned int cpu;
74184 struct rq *rq;
74185@@ -5784,10 +5787,10 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
74186 * DEBUG_PAGEALLOC could have unmapped it if
74187 * the mutex owner just released it and exited.
74188 */
74189- if (probe_kernel_address(&owner->cpu, cpu))
74190+ if (probe_kernel_address(&task_thread_info(owner)->cpu, cpu))
74191 return 0;
74192 #else
74193- cpu = owner->cpu;
74194+ cpu = task_thread_info(owner)->cpu;
74195 #endif
74196
74197 /*
74198@@ -5816,7 +5819,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner)
74199 /*
74200 * Is that owner really running on that cpu?
74201 */
74202- if (task_thread_info(rq->curr) != owner || need_resched())
74203+ if (rq->curr != owner || need_resched())
74204 return 0;
74205
74206 cpu_relax();
74207@@ -6359,6 +6362,8 @@ int can_nice(const struct task_struct *p, const int nice)
74208 /* convert nice value [19,-20] to rlimit style value [1,40] */
74209 int nice_rlim = 20 - nice;
74210
74211+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
74212+
74213 return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur ||
74214 capable(CAP_SYS_NICE));
74215 }
74216@@ -6392,7 +6397,8 @@ SYSCALL_DEFINE1(nice, int, increment)
74217 if (nice > 19)
74218 nice = 19;
74219
74220- if (increment < 0 && !can_nice(current, nice))
74221+ if (increment < 0 && (!can_nice(current, nice) ||
74222+ gr_handle_chroot_nice()))
74223 return -EPERM;
74224
74225 retval = security_task_setnice(current, nice);
74226@@ -8774,7 +8780,7 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd)
74227 long power;
74228 int weight;
74229
74230- WARN_ON(!sd || !sd->groups);
74231+ BUG_ON(!sd || !sd->groups);
74232
74233 if (cpu != group_first_cpu(sd->groups))
74234 return;
74235diff --git a/kernel/signal.c b/kernel/signal.c
74236index 2494827..cda80a0 100644
74237--- a/kernel/signal.c
74238+++ b/kernel/signal.c
74239@@ -41,12 +41,12 @@
74240
74241 static struct kmem_cache *sigqueue_cachep;
74242
74243-static void __user *sig_handler(struct task_struct *t, int sig)
74244+static __sighandler_t sig_handler(struct task_struct *t, int sig)
74245 {
74246 return t->sighand->action[sig - 1].sa.sa_handler;
74247 }
74248
74249-static int sig_handler_ignored(void __user *handler, int sig)
74250+static int sig_handler_ignored(__sighandler_t handler, int sig)
74251 {
74252 /* Is it explicitly or implicitly ignored? */
74253 return handler == SIG_IGN ||
74254@@ -56,7 +56,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
74255 static int sig_task_ignored(struct task_struct *t, int sig,
74256 int from_ancestor_ns)
74257 {
74258- void __user *handler;
74259+ __sighandler_t handler;
74260
74261 handler = sig_handler(t, sig);
74262
74263@@ -207,6 +207,9 @@ static struct sigqueue *__sigqueue_alloc(struct task_struct *t, gfp_t flags,
74264 */
74265 user = get_uid(__task_cred(t)->user);
74266 atomic_inc(&user->sigpending);
74267+
74268+ if (!override_rlimit)
74269+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
74270 if (override_rlimit ||
74271 atomic_read(&user->sigpending) <=
74272 t->signal->rlim[RLIMIT_SIGPENDING].rlim_cur)
74273@@ -327,7 +330,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
74274
74275 int unhandled_signal(struct task_struct *tsk, int sig)
74276 {
74277- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
74278+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
74279 if (is_global_init(tsk))
74280 return 1;
74281 if (handler != SIG_IGN && handler != SIG_DFL)
74282@@ -627,6 +630,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
74283 }
74284 }
74285
74286+ /* allow glibc communication via tgkill to other threads in our
74287+ thread group */
74288+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
74289+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
74290+ && gr_handle_signal(t, sig))
74291+ return -EPERM;
74292+
74293 return security_task_kill(t, info, sig, 0);
74294 }
74295
74296@@ -968,7 +978,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
74297 return send_signal(sig, info, p, 1);
74298 }
74299
74300-static int
74301+int
74302 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
74303 {
74304 return send_signal(sig, info, t, 0);
74305@@ -1005,6 +1015,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
74306 unsigned long int flags;
74307 int ret, blocked, ignored;
74308 struct k_sigaction *action;
74309+ int is_unhandled = 0;
74310
74311 spin_lock_irqsave(&t->sighand->siglock, flags);
74312 action = &t->sighand->action[sig-1];
74313@@ -1019,9 +1030,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
74314 }
74315 if (action->sa.sa_handler == SIG_DFL)
74316 t->signal->flags &= ~SIGNAL_UNKILLABLE;
74317+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
74318+ is_unhandled = 1;
74319 ret = specific_send_sig_info(sig, info, t);
74320 spin_unlock_irqrestore(&t->sighand->siglock, flags);
74321
74322+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
74323+ normal operation */
74324+ if (is_unhandled) {
74325+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
74326+ gr_handle_crash(t, sig);
74327+ }
74328+
74329 return ret;
74330 }
74331
74332@@ -1081,8 +1101,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
74333 {
74334 int ret = check_kill_permission(sig, info, p);
74335
74336- if (!ret && sig)
74337+ if (!ret && sig) {
74338 ret = do_send_sig_info(sig, info, p, true);
74339+ if (!ret)
74340+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
74341+ }
74342
74343 return ret;
74344 }
74345@@ -1644,6 +1667,8 @@ void ptrace_notify(int exit_code)
74346 {
74347 siginfo_t info;
74348
74349+ pax_track_stack();
74350+
74351 BUG_ON((exit_code & (0x7f | ~0xffff)) != SIGTRAP);
74352
74353 memset(&info, 0, sizeof info);
74354@@ -2275,7 +2300,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
74355 int error = -ESRCH;
74356
74357 rcu_read_lock();
74358- p = find_task_by_vpid(pid);
74359+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74360+ /* allow glibc communication via tgkill to other threads in our
74361+ thread group */
74362+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
74363+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
74364+ p = find_task_by_vpid_unrestricted(pid);
74365+ else
74366+#endif
74367+ p = find_task_by_vpid(pid);
74368 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
74369 error = check_kill_permission(sig, info, p);
74370 /*
74371diff --git a/kernel/smp.c b/kernel/smp.c
74372index aa9cff3..631a0de 100644
74373--- a/kernel/smp.c
74374+++ b/kernel/smp.c
74375@@ -522,22 +522,22 @@ int smp_call_function(void (*func)(void *), void *info, int wait)
74376 }
74377 EXPORT_SYMBOL(smp_call_function);
74378
74379-void ipi_call_lock(void)
74380+void ipi_call_lock(void) __acquires(call_function.lock)
74381 {
74382 spin_lock(&call_function.lock);
74383 }
74384
74385-void ipi_call_unlock(void)
74386+void ipi_call_unlock(void) __releases(call_function.lock)
74387 {
74388 spin_unlock(&call_function.lock);
74389 }
74390
74391-void ipi_call_lock_irq(void)
74392+void ipi_call_lock_irq(void) __acquires(call_function.lock)
74393 {
74394 spin_lock_irq(&call_function.lock);
74395 }
74396
74397-void ipi_call_unlock_irq(void)
74398+void ipi_call_unlock_irq(void) __releases(call_function.lock)
74399 {
74400 spin_unlock_irq(&call_function.lock);
74401 }
74402diff --git a/kernel/softirq.c b/kernel/softirq.c
74403index 04a0252..580c512 100644
74404--- a/kernel/softirq.c
74405+++ b/kernel/softirq.c
74406@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
74407
74408 static DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
74409
74410-char *softirq_to_name[NR_SOFTIRQS] = {
74411+const char * const softirq_to_name[NR_SOFTIRQS] = {
74412 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
74413 "TASKLET", "SCHED", "HRTIMER", "RCU"
74414 };
74415@@ -206,7 +206,7 @@ EXPORT_SYMBOL(local_bh_enable_ip);
74416
74417 asmlinkage void __do_softirq(void)
74418 {
74419- struct softirq_action *h;
74420+ const struct softirq_action *h;
74421 __u32 pending;
74422 int max_restart = MAX_SOFTIRQ_RESTART;
74423 int cpu;
74424@@ -233,7 +233,7 @@ restart:
74425 kstat_incr_softirqs_this_cpu(h - softirq_vec);
74426
74427 trace_softirq_entry(h, softirq_vec);
74428- h->action(h);
74429+ h->action();
74430 trace_softirq_exit(h, softirq_vec);
74431 if (unlikely(prev_count != preempt_count())) {
74432 printk(KERN_ERR "huh, entered softirq %td %s %p"
74433@@ -363,9 +363,11 @@ void raise_softirq(unsigned int nr)
74434 local_irq_restore(flags);
74435 }
74436
74437-void open_softirq(int nr, void (*action)(struct softirq_action *))
74438+void open_softirq(int nr, void (*action)(void))
74439 {
74440- softirq_vec[nr].action = action;
74441+ pax_open_kernel();
74442+ *(void **)&softirq_vec[nr].action = action;
74443+ pax_close_kernel();
74444 }
74445
74446 /*
74447@@ -419,7 +421,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
74448
74449 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
74450
74451-static void tasklet_action(struct softirq_action *a)
74452+static void tasklet_action(void)
74453 {
74454 struct tasklet_struct *list;
74455
74456@@ -454,7 +456,7 @@ static void tasklet_action(struct softirq_action *a)
74457 }
74458 }
74459
74460-static void tasklet_hi_action(struct softirq_action *a)
74461+static void tasklet_hi_action(void)
74462 {
74463 struct tasklet_struct *list;
74464
74465diff --git a/kernel/sys.c b/kernel/sys.c
74466index e9512b1..3c265de 100644
74467--- a/kernel/sys.c
74468+++ b/kernel/sys.c
74469@@ -133,6 +133,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
74470 error = -EACCES;
74471 goto out;
74472 }
74473+
74474+ if (gr_handle_chroot_setpriority(p, niceval)) {
74475+ error = -EACCES;
74476+ goto out;
74477+ }
74478+
74479 no_nice = security_task_setnice(p, niceval);
74480 if (no_nice) {
74481 error = no_nice;
74482@@ -190,10 +196,10 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)
74483 !(user = find_user(who)))
74484 goto out_unlock; /* No processes for this user */
74485
74486- do_each_thread(g, p)
74487+ do_each_thread(g, p) {
74488 if (__task_cred(p)->uid == who)
74489 error = set_one_prio(p, niceval, error);
74490- while_each_thread(g, p);
74491+ } while_each_thread(g, p);
74492 if (who != cred->uid)
74493 free_uid(user); /* For find_user() */
74494 break;
74495@@ -253,13 +259,13 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)
74496 !(user = find_user(who)))
74497 goto out_unlock; /* No processes for this user */
74498
74499- do_each_thread(g, p)
74500+ do_each_thread(g, p) {
74501 if (__task_cred(p)->uid == who) {
74502 niceval = 20 - task_nice(p);
74503 if (niceval > retval)
74504 retval = niceval;
74505 }
74506- while_each_thread(g, p);
74507+ } while_each_thread(g, p);
74508 if (who != cred->uid)
74509 free_uid(user); /* for find_user() */
74510 break;
74511@@ -509,6 +515,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
74512 goto error;
74513 }
74514
74515+ if (gr_check_group_change(new->gid, new->egid, -1))
74516+ goto error;
74517+
74518 if (rgid != (gid_t) -1 ||
74519 (egid != (gid_t) -1 && egid != old->gid))
74520 new->sgid = new->egid;
74521@@ -542,6 +551,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
74522 goto error;
74523
74524 retval = -EPERM;
74525+
74526+ if (gr_check_group_change(gid, gid, gid))
74527+ goto error;
74528+
74529 if (capable(CAP_SETGID))
74530 new->gid = new->egid = new->sgid = new->fsgid = gid;
74531 else if (gid == old->gid || gid == old->sgid)
74532@@ -567,12 +580,19 @@ static int set_user(struct cred *new)
74533 if (!new_user)
74534 return -EAGAIN;
74535
74536+ /*
74537+ * We don't fail in case of NPROC limit excess here because too many
74538+ * poorly written programs don't check set*uid() return code, assuming
74539+ * it never fails if called by root. We may still enforce NPROC limit
74540+ * for programs doing set*uid()+execve() by harmlessly deferring the
74541+ * failure to the execve() stage.
74542+ */
74543 if (atomic_read(&new_user->processes) >=
74544 current->signal->rlim[RLIMIT_NPROC].rlim_cur &&
74545- new_user != INIT_USER) {
74546- free_uid(new_user);
74547- return -EAGAIN;
74548- }
74549+ new_user != INIT_USER)
74550+ current->flags |= PF_NPROC_EXCEEDED;
74551+ else
74552+ current->flags &= ~PF_NPROC_EXCEEDED;
74553
74554 free_uid(new->user);
74555 new->user = new_user;
74556@@ -627,6 +647,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
74557 goto error;
74558 }
74559
74560+ if (gr_check_user_change(new->uid, new->euid, -1))
74561+ goto error;
74562+
74563 if (new->uid != old->uid) {
74564 retval = set_user(new);
74565 if (retval < 0)
74566@@ -675,6 +698,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
74567 goto error;
74568
74569 retval = -EPERM;
74570+
74571+ if (gr_check_crash_uid(uid))
74572+ goto error;
74573+ if (gr_check_user_change(uid, uid, uid))
74574+ goto error;
74575+
74576 if (capable(CAP_SETUID)) {
74577 new->suid = new->uid = uid;
74578 if (uid != old->uid) {
74579@@ -732,6 +761,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
74580 goto error;
74581 }
74582
74583+ if (gr_check_user_change(ruid, euid, -1))
74584+ goto error;
74585+
74586 if (ruid != (uid_t) -1) {
74587 new->uid = ruid;
74588 if (ruid != old->uid) {
74589@@ -800,6 +832,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
74590 goto error;
74591 }
74592
74593+ if (gr_check_group_change(rgid, egid, -1))
74594+ goto error;
74595+
74596 if (rgid != (gid_t) -1)
74597 new->gid = rgid;
74598 if (egid != (gid_t) -1)
74599@@ -849,6 +884,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
74600 if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS) < 0)
74601 goto error;
74602
74603+ if (gr_check_user_change(-1, -1, uid))
74604+ goto error;
74605+
74606 if (uid == old->uid || uid == old->euid ||
74607 uid == old->suid || uid == old->fsuid ||
74608 capable(CAP_SETUID)) {
74609@@ -889,6 +927,9 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
74610 if (gid == old->gid || gid == old->egid ||
74611 gid == old->sgid || gid == old->fsgid ||
74612 capable(CAP_SETGID)) {
74613+ if (gr_check_group_change(-1, -1, gid))
74614+ goto error;
74615+
74616 if (gid != old_fsgid) {
74617 new->fsgid = gid;
74618 goto change_okay;
74619@@ -1454,7 +1495,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
74620 error = get_dumpable(me->mm);
74621 break;
74622 case PR_SET_DUMPABLE:
74623- if (arg2 < 0 || arg2 > 1) {
74624+ if (arg2 > 1) {
74625 error = -EINVAL;
74626 break;
74627 }
74628diff --git a/kernel/sysctl.c b/kernel/sysctl.c
74629index b8bd058..ab6a76be 100644
74630--- a/kernel/sysctl.c
74631+++ b/kernel/sysctl.c
74632@@ -63,6 +63,13 @@
74633 static int deprecated_sysctl_warning(struct __sysctl_args *args);
74634
74635 #if defined(CONFIG_SYSCTL)
74636+#include <linux/grsecurity.h>
74637+#include <linux/grinternal.h>
74638+
74639+extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
74640+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
74641+ const int op);
74642+extern int gr_handle_chroot_sysctl(const int op);
74643
74644 /* External variables not in a header file. */
74645 extern int C_A_D;
74646@@ -168,6 +175,7 @@ static int proc_do_cad_pid(struct ctl_table *table, int write,
74647 static int proc_taint(struct ctl_table *table, int write,
74648 void __user *buffer, size_t *lenp, loff_t *ppos);
74649 #endif
74650+extern ctl_table grsecurity_table[];
74651
74652 static struct ctl_table root_table[];
74653 static struct ctl_table_root sysctl_table_root;
74654@@ -200,6 +208,21 @@ extern struct ctl_table epoll_table[];
74655 int sysctl_legacy_va_layout;
74656 #endif
74657
74658+#ifdef CONFIG_PAX_SOFTMODE
74659+static ctl_table pax_table[] = {
74660+ {
74661+ .ctl_name = CTL_UNNUMBERED,
74662+ .procname = "softmode",
74663+ .data = &pax_softmode,
74664+ .maxlen = sizeof(unsigned int),
74665+ .mode = 0600,
74666+ .proc_handler = &proc_dointvec,
74667+ },
74668+
74669+ { .ctl_name = 0 }
74670+};
74671+#endif
74672+
74673 extern int prove_locking;
74674 extern int lock_stat;
74675
74676@@ -251,6 +274,24 @@ static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
74677 #endif
74678
74679 static struct ctl_table kern_table[] = {
74680+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
74681+ {
74682+ .ctl_name = CTL_UNNUMBERED,
74683+ .procname = "grsecurity",
74684+ .mode = 0500,
74685+ .child = grsecurity_table,
74686+ },
74687+#endif
74688+
74689+#ifdef CONFIG_PAX_SOFTMODE
74690+ {
74691+ .ctl_name = CTL_UNNUMBERED,
74692+ .procname = "pax",
74693+ .mode = 0500,
74694+ .child = pax_table,
74695+ },
74696+#endif
74697+
74698 {
74699 .ctl_name = CTL_UNNUMBERED,
74700 .procname = "sched_child_runs_first",
74701@@ -567,8 +608,8 @@ static struct ctl_table kern_table[] = {
74702 .data = &modprobe_path,
74703 .maxlen = KMOD_PATH_LEN,
74704 .mode = 0644,
74705- .proc_handler = &proc_dostring,
74706- .strategy = &sysctl_string,
74707+ .proc_handler = &proc_dostring_modpriv,
74708+ .strategy = &sysctl_string_modpriv,
74709 },
74710 {
74711 .ctl_name = CTL_UNNUMBERED,
74712@@ -1247,6 +1288,13 @@ static struct ctl_table vm_table[] = {
74713 .mode = 0644,
74714 .proc_handler = &proc_dointvec
74715 },
74716+ {
74717+ .procname = "heap_stack_gap",
74718+ .data = &sysctl_heap_stack_gap,
74719+ .maxlen = sizeof(sysctl_heap_stack_gap),
74720+ .mode = 0644,
74721+ .proc_handler = proc_doulongvec_minmax,
74722+ },
74723 #else
74724 {
74725 .ctl_name = CTL_UNNUMBERED,
74726@@ -1803,6 +1851,8 @@ static int do_sysctl_strategy(struct ctl_table_root *root,
74727 return 0;
74728 }
74729
74730+static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
74731+
74732 static int parse_table(int __user *name, int nlen,
74733 void __user *oldval, size_t __user *oldlenp,
74734 void __user *newval, size_t newlen,
74735@@ -1821,7 +1871,7 @@ repeat:
74736 if (n == table->ctl_name) {
74737 int error;
74738 if (table->child) {
74739- if (sysctl_perm(root, table, MAY_EXEC))
74740+ if (sysctl_perm_nochk(root, table, MAY_EXEC))
74741 return -EPERM;
74742 name++;
74743 nlen--;
74744@@ -1906,6 +1956,33 @@ int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
74745 int error;
74746 int mode;
74747
74748+ if (table->parent != NULL && table->parent->procname != NULL &&
74749+ table->procname != NULL &&
74750+ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
74751+ return -EACCES;
74752+ if (gr_handle_chroot_sysctl(op))
74753+ return -EACCES;
74754+ error = gr_handle_sysctl(table, op);
74755+ if (error)
74756+ return error;
74757+
74758+ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
74759+ if (error)
74760+ return error;
74761+
74762+ if (root->permissions)
74763+ mode = root->permissions(root, current->nsproxy, table);
74764+ else
74765+ mode = table->mode;
74766+
74767+ return test_perm(mode, op);
74768+}
74769+
74770+int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
74771+{
74772+ int error;
74773+ int mode;
74774+
74775 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
74776 if (error)
74777 return error;
74778@@ -2335,6 +2412,16 @@ int proc_dostring(struct ctl_table *table, int write,
74779 buffer, lenp, ppos);
74780 }
74781
74782+int proc_dostring_modpriv(struct ctl_table *table, int write,
74783+ void __user *buffer, size_t *lenp, loff_t *ppos)
74784+{
74785+ if (write && !capable(CAP_SYS_MODULE))
74786+ return -EPERM;
74787+
74788+ return _proc_do_string(table->data, table->maxlen, write,
74789+ buffer, lenp, ppos);
74790+}
74791+
74792
74793 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
74794 int *valp,
74795@@ -2609,7 +2696,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
74796 vleft = table->maxlen / sizeof(unsigned long);
74797 left = *lenp;
74798
74799- for (; left && vleft--; i++, min++, max++, first=0) {
74800+ for (; left && vleft--; i++, first=0) {
74801 if (write) {
74802 while (left) {
74803 char c;
74804@@ -2910,6 +2997,12 @@ int proc_dostring(struct ctl_table *table, int write,
74805 return -ENOSYS;
74806 }
74807
74808+int proc_dostring_modpriv(struct ctl_table *table, int write,
74809+ void __user *buffer, size_t *lenp, loff_t *ppos)
74810+{
74811+ return -ENOSYS;
74812+}
74813+
74814 int proc_dointvec(struct ctl_table *table, int write,
74815 void __user *buffer, size_t *lenp, loff_t *ppos)
74816 {
74817@@ -3038,6 +3131,16 @@ int sysctl_string(struct ctl_table *table,
74818 return 1;
74819 }
74820
74821+int sysctl_string_modpriv(struct ctl_table *table,
74822+ void __user *oldval, size_t __user *oldlenp,
74823+ void __user *newval, size_t newlen)
74824+{
74825+ if (newval && newlen && !capable(CAP_SYS_MODULE))
74826+ return -EPERM;
74827+
74828+ return sysctl_string(table, oldval, oldlenp, newval, newlen);
74829+}
74830+
74831 /*
74832 * This function makes sure that all of the integers in the vector
74833 * are between the minimum and maximum values given in the arrays
74834@@ -3182,6 +3285,13 @@ int sysctl_string(struct ctl_table *table,
74835 return -ENOSYS;
74836 }
74837
74838+int sysctl_string_modpriv(struct ctl_table *table,
74839+ void __user *oldval, size_t __user *oldlenp,
74840+ void __user *newval, size_t newlen)
74841+{
74842+ return -ENOSYS;
74843+}
74844+
74845 int sysctl_intvec(struct ctl_table *table,
74846 void __user *oldval, size_t __user *oldlenp,
74847 void __user *newval, size_t newlen)
74848@@ -3246,6 +3356,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
74849 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
74850 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
74851 EXPORT_SYMBOL(proc_dostring);
74852+EXPORT_SYMBOL(proc_dostring_modpriv);
74853 EXPORT_SYMBOL(proc_doulongvec_minmax);
74854 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
74855 EXPORT_SYMBOL(register_sysctl_table);
74856@@ -3254,5 +3365,6 @@ EXPORT_SYMBOL(sysctl_intvec);
74857 EXPORT_SYMBOL(sysctl_jiffies);
74858 EXPORT_SYMBOL(sysctl_ms_jiffies);
74859 EXPORT_SYMBOL(sysctl_string);
74860+EXPORT_SYMBOL(sysctl_string_modpriv);
74861 EXPORT_SYMBOL(sysctl_data);
74862 EXPORT_SYMBOL(unregister_sysctl_table);
74863diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
74864index 469193c..ea3ecb2 100644
74865--- a/kernel/sysctl_check.c
74866+++ b/kernel/sysctl_check.c
74867@@ -1489,10 +1489,12 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
74868 } else {
74869 if ((table->strategy == sysctl_data) ||
74870 (table->strategy == sysctl_string) ||
74871+ (table->strategy == sysctl_string_modpriv) ||
74872 (table->strategy == sysctl_intvec) ||
74873 (table->strategy == sysctl_jiffies) ||
74874 (table->strategy == sysctl_ms_jiffies) ||
74875 (table->proc_handler == proc_dostring) ||
74876+ (table->proc_handler == proc_dostring_modpriv) ||
74877 (table->proc_handler == proc_dointvec) ||
74878 (table->proc_handler == proc_dointvec_minmax) ||
74879 (table->proc_handler == proc_dointvec_jiffies) ||
74880diff --git a/kernel/taskstats.c b/kernel/taskstats.c
74881index a4ef542..798bcd7 100644
74882--- a/kernel/taskstats.c
74883+++ b/kernel/taskstats.c
74884@@ -26,9 +26,12 @@
74885 #include <linux/cgroup.h>
74886 #include <linux/fs.h>
74887 #include <linux/file.h>
74888+#include <linux/grsecurity.h>
74889 #include <net/genetlink.h>
74890 #include <asm/atomic.h>
74891
74892+extern int gr_is_taskstats_denied(int pid);
74893+
74894 /*
74895 * Maximum length of a cpumask that can be specified in
74896 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
74897@@ -442,6 +445,9 @@ static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
74898 size_t size;
74899 cpumask_var_t mask;
74900
74901+ if (gr_is_taskstats_denied(current->pid))
74902+ return -EACCES;
74903+
74904 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
74905 return -ENOMEM;
74906
74907diff --git a/kernel/time.c b/kernel/time.c
74908index 33df60e..ca768bd 100644
74909--- a/kernel/time.c
74910+++ b/kernel/time.c
74911@@ -165,6 +165,11 @@ int do_sys_settimeofday(struct timespec *tv, struct timezone *tz)
74912 return error;
74913
74914 if (tz) {
74915+ /* we log in do_settimeofday called below, so don't log twice
74916+ */
74917+ if (!tv)
74918+ gr_log_timechange();
74919+
74920 /* SMP safe, global irq locking makes it work. */
74921 sys_tz = *tz;
74922 update_vsyscall_tz();
74923@@ -240,7 +245,7 @@ EXPORT_SYMBOL(current_fs_time);
74924 * Avoid unnecessary multiplications/divisions in the
74925 * two most common HZ cases:
74926 */
74927-unsigned int inline jiffies_to_msecs(const unsigned long j)
74928+inline unsigned int jiffies_to_msecs(const unsigned long j)
74929 {
74930 #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
74931 return (MSEC_PER_SEC / HZ) * j;
74932@@ -256,7 +261,7 @@ unsigned int inline jiffies_to_msecs(const unsigned long j)
74933 }
74934 EXPORT_SYMBOL(jiffies_to_msecs);
74935
74936-unsigned int inline jiffies_to_usecs(const unsigned long j)
74937+inline unsigned int jiffies_to_usecs(const unsigned long j)
74938 {
74939 #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
74940 return (USEC_PER_SEC / HZ) * j;
74941diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
74942index 57b953f..06f149f 100644
74943--- a/kernel/time/tick-broadcast.c
74944+++ b/kernel/time/tick-broadcast.c
74945@@ -116,7 +116,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
74946 * then clear the broadcast bit.
74947 */
74948 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
74949- int cpu = smp_processor_id();
74950+ cpu = smp_processor_id();
74951
74952 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
74953 tick_broadcast_clear_oneshot(cpu);
74954diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
74955index 4a71cff..ffb5548 100644
74956--- a/kernel/time/timekeeping.c
74957+++ b/kernel/time/timekeeping.c
74958@@ -14,6 +14,7 @@
74959 #include <linux/init.h>
74960 #include <linux/mm.h>
74961 #include <linux/sched.h>
74962+#include <linux/grsecurity.h>
74963 #include <linux/sysdev.h>
74964 #include <linux/clocksource.h>
74965 #include <linux/jiffies.h>
74966@@ -180,7 +181,7 @@ void update_xtime_cache(u64 nsec)
74967 */
74968 struct timespec ts = xtime;
74969 timespec_add_ns(&ts, nsec);
74970- ACCESS_ONCE(xtime_cache) = ts;
74971+ ACCESS_ONCE_RW(xtime_cache) = ts;
74972 }
74973
74974 /* must hold xtime_lock */
74975@@ -337,6 +338,8 @@ int do_settimeofday(struct timespec *tv)
74976 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
74977 return -EINVAL;
74978
74979+ gr_log_timechange();
74980+
74981 write_seqlock_irqsave(&xtime_lock, flags);
74982
74983 timekeeping_forward_now();
74984diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
74985index 54c0dda..e9095d9 100644
74986--- a/kernel/time/timer_list.c
74987+++ b/kernel/time/timer_list.c
74988@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
74989
74990 static void print_name_offset(struct seq_file *m, void *sym)
74991 {
74992+#ifdef CONFIG_GRKERNSEC_HIDESYM
74993+ SEQ_printf(m, "<%p>", NULL);
74994+#else
74995 char symname[KSYM_NAME_LEN];
74996
74997 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
74998 SEQ_printf(m, "<%p>", sym);
74999 else
75000 SEQ_printf(m, "%s", symname);
75001+#endif
75002 }
75003
75004 static void
75005@@ -112,7 +116,11 @@ next_one:
75006 static void
75007 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
75008 {
75009+#ifdef CONFIG_GRKERNSEC_HIDESYM
75010+ SEQ_printf(m, " .base: %p\n", NULL);
75011+#else
75012 SEQ_printf(m, " .base: %p\n", base);
75013+#endif
75014 SEQ_printf(m, " .index: %d\n",
75015 base->index);
75016 SEQ_printf(m, " .resolution: %Lu nsecs\n",
75017@@ -289,7 +297,11 @@ static int __init init_timer_list_procfs(void)
75018 {
75019 struct proc_dir_entry *pe;
75020
75021+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75022+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
75023+#else
75024 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
75025+#endif
75026 if (!pe)
75027 return -ENOMEM;
75028 return 0;
75029diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
75030index ee5681f..634089b 100644
75031--- a/kernel/time/timer_stats.c
75032+++ b/kernel/time/timer_stats.c
75033@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
75034 static unsigned long nr_entries;
75035 static struct entry entries[MAX_ENTRIES];
75036
75037-static atomic_t overflow_count;
75038+static atomic_unchecked_t overflow_count;
75039
75040 /*
75041 * The entries are in a hash-table, for fast lookup:
75042@@ -140,7 +140,7 @@ static void reset_entries(void)
75043 nr_entries = 0;
75044 memset(entries, 0, sizeof(entries));
75045 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
75046- atomic_set(&overflow_count, 0);
75047+ atomic_set_unchecked(&overflow_count, 0);
75048 }
75049
75050 static struct entry *alloc_entry(void)
75051@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
75052 if (likely(entry))
75053 entry->count++;
75054 else
75055- atomic_inc(&overflow_count);
75056+ atomic_inc_unchecked(&overflow_count);
75057
75058 out_unlock:
75059 spin_unlock_irqrestore(lock, flags);
75060@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
75061
75062 static void print_name_offset(struct seq_file *m, unsigned long addr)
75063 {
75064+#ifdef CONFIG_GRKERNSEC_HIDESYM
75065+ seq_printf(m, "<%p>", NULL);
75066+#else
75067 char symname[KSYM_NAME_LEN];
75068
75069 if (lookup_symbol_name(addr, symname) < 0)
75070 seq_printf(m, "<%p>", (void *)addr);
75071 else
75072 seq_printf(m, "%s", symname);
75073+#endif
75074 }
75075
75076 static int tstats_show(struct seq_file *m, void *v)
75077@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
75078
75079 seq_puts(m, "Timer Stats Version: v0.2\n");
75080 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
75081- if (atomic_read(&overflow_count))
75082+ if (atomic_read_unchecked(&overflow_count))
75083 seq_printf(m, "Overflow: %d entries\n",
75084- atomic_read(&overflow_count));
75085+ atomic_read_unchecked(&overflow_count));
75086
75087 for (i = 0; i < nr_entries; i++) {
75088 entry = entries + i;
75089@@ -415,7 +419,11 @@ static int __init init_tstats_procfs(void)
75090 {
75091 struct proc_dir_entry *pe;
75092
75093+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75094+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
75095+#else
75096 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
75097+#endif
75098 if (!pe)
75099 return -ENOMEM;
75100 return 0;
75101diff --git a/kernel/timer.c b/kernel/timer.c
75102index cb3c1f1..8bf5526 100644
75103--- a/kernel/timer.c
75104+++ b/kernel/timer.c
75105@@ -1213,7 +1213,7 @@ void update_process_times(int user_tick)
75106 /*
75107 * This function runs timers and the timer-tq in bottom half context.
75108 */
75109-static void run_timer_softirq(struct softirq_action *h)
75110+static void run_timer_softirq(void)
75111 {
75112 struct tvec_base *base = __get_cpu_var(tvec_bases);
75113
75114diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
75115index d9d6206..f19467e 100644
75116--- a/kernel/trace/blktrace.c
75117+++ b/kernel/trace/blktrace.c
75118@@ -313,7 +313,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
75119 struct blk_trace *bt = filp->private_data;
75120 char buf[16];
75121
75122- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
75123+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
75124
75125 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
75126 }
75127@@ -376,7 +376,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
75128 return 1;
75129
75130 bt = buf->chan->private_data;
75131- atomic_inc(&bt->dropped);
75132+ atomic_inc_unchecked(&bt->dropped);
75133 return 0;
75134 }
75135
75136@@ -477,7 +477,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
75137
75138 bt->dir = dir;
75139 bt->dev = dev;
75140- atomic_set(&bt->dropped, 0);
75141+ atomic_set_unchecked(&bt->dropped, 0);
75142
75143 ret = -EIO;
75144 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
75145diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
75146index 4872937..c794d40 100644
75147--- a/kernel/trace/ftrace.c
75148+++ b/kernel/trace/ftrace.c
75149@@ -1100,13 +1100,18 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
75150
75151 ip = rec->ip;
75152
75153+ ret = ftrace_arch_code_modify_prepare();
75154+ FTRACE_WARN_ON(ret);
75155+ if (ret)
75156+ return 0;
75157+
75158 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
75159+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
75160 if (ret) {
75161 ftrace_bug(ret, ip);
75162 rec->flags |= FTRACE_FL_FAILED;
75163- return 0;
75164 }
75165- return 1;
75166+ return ret ? 0 : 1;
75167 }
75168
75169 /*
75170diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
75171index e749a05..19c6e94 100644
75172--- a/kernel/trace/ring_buffer.c
75173+++ b/kernel/trace/ring_buffer.c
75174@@ -606,7 +606,7 @@ static struct list_head *rb_list_head(struct list_head *list)
75175 * the reader page). But if the next page is a header page,
75176 * its flags will be non zero.
75177 */
75178-static int inline
75179+static inline int
75180 rb_is_head_page(struct ring_buffer_per_cpu *cpu_buffer,
75181 struct buffer_page *page, struct list_head *list)
75182 {
75183diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
75184index a2a2d1f..7f32b09 100644
75185--- a/kernel/trace/trace.c
75186+++ b/kernel/trace/trace.c
75187@@ -3193,6 +3193,8 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
75188 size_t rem;
75189 unsigned int i;
75190
75191+ pax_track_stack();
75192+
75193 /* copy the tracer to avoid using a global lock all around */
75194 mutex_lock(&trace_types_lock);
75195 if (unlikely(old_tracer != current_trace && current_trace)) {
75196@@ -3659,6 +3661,8 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
75197 int entries, size, i;
75198 size_t ret;
75199
75200+ pax_track_stack();
75201+
75202 if (*ppos & (PAGE_SIZE - 1)) {
75203 WARN_ONCE(1, "Ftrace: previous read must page-align\n");
75204 return -EINVAL;
75205@@ -3816,10 +3820,9 @@ static const struct file_operations tracing_dyn_info_fops = {
75206 };
75207 #endif
75208
75209-static struct dentry *d_tracer;
75210-
75211 struct dentry *tracing_init_dentry(void)
75212 {
75213+ static struct dentry *d_tracer;
75214 static int once;
75215
75216 if (d_tracer)
75217@@ -3839,10 +3842,9 @@ struct dentry *tracing_init_dentry(void)
75218 return d_tracer;
75219 }
75220
75221-static struct dentry *d_percpu;
75222-
75223 struct dentry *tracing_dentry_percpu(void)
75224 {
75225+ static struct dentry *d_percpu;
75226 static int once;
75227 struct dentry *d_tracer;
75228
75229diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
75230index d128f65..f37b4af 100644
75231--- a/kernel/trace/trace_events.c
75232+++ b/kernel/trace/trace_events.c
75233@@ -951,13 +951,10 @@ static LIST_HEAD(ftrace_module_file_list);
75234 * Modules must own their file_operations to keep up with
75235 * reference counting.
75236 */
75237+
75238 struct ftrace_module_file_ops {
75239 struct list_head list;
75240 struct module *mod;
75241- struct file_operations id;
75242- struct file_operations enable;
75243- struct file_operations format;
75244- struct file_operations filter;
75245 };
75246
75247 static void remove_subsystem_dir(const char *name)
75248@@ -1004,17 +1001,12 @@ trace_create_file_ops(struct module *mod)
75249
75250 file_ops->mod = mod;
75251
75252- file_ops->id = ftrace_event_id_fops;
75253- file_ops->id.owner = mod;
75254-
75255- file_ops->enable = ftrace_enable_fops;
75256- file_ops->enable.owner = mod;
75257-
75258- file_ops->filter = ftrace_event_filter_fops;
75259- file_ops->filter.owner = mod;
75260-
75261- file_ops->format = ftrace_event_format_fops;
75262- file_ops->format.owner = mod;
75263+ pax_open_kernel();
75264+ *(void **)&mod->trace_id.owner = mod;
75265+ *(void **)&mod->trace_enable.owner = mod;
75266+ *(void **)&mod->trace_filter.owner = mod;
75267+ *(void **)&mod->trace_format.owner = mod;
75268+ pax_close_kernel();
75269
75270 list_add(&file_ops->list, &ftrace_module_file_list);
75271
75272@@ -1063,8 +1055,8 @@ static void trace_module_add_events(struct module *mod)
75273 call->mod = mod;
75274 list_add(&call->list, &ftrace_events);
75275 event_create_dir(call, d_events,
75276- &file_ops->id, &file_ops->enable,
75277- &file_ops->filter, &file_ops->format);
75278+ &mod->trace_id, &mod->trace_enable,
75279+ &mod->trace_filter, &mod->trace_format);
75280 }
75281 }
75282
75283diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
75284index 0acd834..b800b56 100644
75285--- a/kernel/trace/trace_mmiotrace.c
75286+++ b/kernel/trace/trace_mmiotrace.c
75287@@ -23,7 +23,7 @@ struct header_iter {
75288 static struct trace_array *mmio_trace_array;
75289 static bool overrun_detected;
75290 static unsigned long prev_overruns;
75291-static atomic_t dropped_count;
75292+static atomic_unchecked_t dropped_count;
75293
75294 static void mmio_reset_data(struct trace_array *tr)
75295 {
75296@@ -126,7 +126,7 @@ static void mmio_close(struct trace_iterator *iter)
75297
75298 static unsigned long count_overruns(struct trace_iterator *iter)
75299 {
75300- unsigned long cnt = atomic_xchg(&dropped_count, 0);
75301+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
75302 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
75303
75304 if (over > prev_overruns)
75305@@ -316,7 +316,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
75306 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
75307 sizeof(*entry), 0, pc);
75308 if (!event) {
75309- atomic_inc(&dropped_count);
75310+ atomic_inc_unchecked(&dropped_count);
75311 return;
75312 }
75313 entry = ring_buffer_event_data(event);
75314@@ -346,7 +346,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
75315 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
75316 sizeof(*entry), 0, pc);
75317 if (!event) {
75318- atomic_inc(&dropped_count);
75319+ atomic_inc_unchecked(&dropped_count);
75320 return;
75321 }
75322 entry = ring_buffer_event_data(event);
75323diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
75324index b6c12c6..41fdc53 100644
75325--- a/kernel/trace/trace_output.c
75326+++ b/kernel/trace/trace_output.c
75327@@ -237,7 +237,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
75328 return 0;
75329 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
75330 if (!IS_ERR(p)) {
75331- p = mangle_path(s->buffer + s->len, p, "\n");
75332+ p = mangle_path(s->buffer + s->len, p, "\n\\");
75333 if (p) {
75334 s->len = p - s->buffer;
75335 return 1;
75336diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
75337index 8504ac7..ecf0adb 100644
75338--- a/kernel/trace/trace_stack.c
75339+++ b/kernel/trace/trace_stack.c
75340@@ -50,7 +50,7 @@ static inline void check_stack(void)
75341 return;
75342
75343 /* we do not handle interrupt stacks yet */
75344- if (!object_is_on_stack(&this_size))
75345+ if (!object_starts_on_stack(&this_size))
75346 return;
75347
75348 local_irq_save(flags);
75349diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
75350index 40cafb0..d5ead43 100644
75351--- a/kernel/trace/trace_workqueue.c
75352+++ b/kernel/trace/trace_workqueue.c
75353@@ -21,7 +21,7 @@ struct cpu_workqueue_stats {
75354 int cpu;
75355 pid_t pid;
75356 /* Can be inserted from interrupt or user context, need to be atomic */
75357- atomic_t inserted;
75358+ atomic_unchecked_t inserted;
75359 /*
75360 * Don't need to be atomic, works are serialized in a single workqueue thread
75361 * on a single CPU.
75362@@ -58,7 +58,7 @@ probe_workqueue_insertion(struct task_struct *wq_thread,
75363 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
75364 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
75365 if (node->pid == wq_thread->pid) {
75366- atomic_inc(&node->inserted);
75367+ atomic_inc_unchecked(&node->inserted);
75368 goto found;
75369 }
75370 }
75371@@ -205,7 +205,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
75372 tsk = get_pid_task(pid, PIDTYPE_PID);
75373 if (tsk) {
75374 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
75375- atomic_read(&cws->inserted), cws->executed,
75376+ atomic_read_unchecked(&cws->inserted), cws->executed,
75377 tsk->comm);
75378 put_task_struct(tsk);
75379 }
75380diff --git a/kernel/user.c b/kernel/user.c
75381index 1b91701..8795237 100644
75382--- a/kernel/user.c
75383+++ b/kernel/user.c
75384@@ -159,6 +159,7 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
75385 spin_lock_irq(&uidhash_lock);
75386 up = uid_hash_find(uid, hashent);
75387 if (up) {
75388+ put_user_ns(ns);
75389 key_put(new->uid_keyring);
75390 key_put(new->session_keyring);
75391 kmem_cache_free(uid_cachep, new);
75392diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
75393index 234ceb1..ad74049 100644
75394--- a/lib/Kconfig.debug
75395+++ b/lib/Kconfig.debug
75396@@ -905,7 +905,7 @@ config LATENCYTOP
75397 select STACKTRACE
75398 select SCHEDSTATS
75399 select SCHED_DEBUG
75400- depends on HAVE_LATENCYTOP_SUPPORT
75401+ depends on HAVE_LATENCYTOP_SUPPORT && !GRKERNSEC_HIDESYM
75402 help
75403 Enable this option if you want to use the LatencyTOP tool
75404 to find out which userspace is blocking on what kernel operations.
75405diff --git a/lib/bitmap.c b/lib/bitmap.c
75406index 7025658..8d14cab 100644
75407--- a/lib/bitmap.c
75408+++ b/lib/bitmap.c
75409@@ -341,7 +341,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
75410 {
75411 int c, old_c, totaldigits, ndigits, nchunks, nbits;
75412 u32 chunk;
75413- const char __user *ubuf = buf;
75414+ const char __user *ubuf = (const char __force_user *)buf;
75415
75416 bitmap_zero(maskp, nmaskbits);
75417
75418@@ -426,7 +426,7 @@ int bitmap_parse_user(const char __user *ubuf,
75419 {
75420 if (!access_ok(VERIFY_READ, ubuf, ulen))
75421 return -EFAULT;
75422- return __bitmap_parse((const char *)ubuf, ulen, 1, maskp, nmaskbits);
75423+ return __bitmap_parse((const char __force_kernel *)ubuf, ulen, 1, maskp, nmaskbits);
75424 }
75425 EXPORT_SYMBOL(bitmap_parse_user);
75426
75427diff --git a/lib/bug.c b/lib/bug.c
75428index 300e41a..2779eb0 100644
75429--- a/lib/bug.c
75430+++ b/lib/bug.c
75431@@ -135,6 +135,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
75432 return BUG_TRAP_TYPE_NONE;
75433
75434 bug = find_bug(bugaddr);
75435+ if (!bug)
75436+ return BUG_TRAP_TYPE_NONE;
75437
75438 printk(KERN_EMERG "------------[ cut here ]------------\n");
75439
75440diff --git a/lib/debugobjects.c b/lib/debugobjects.c
75441index 2b413db..e21d207 100644
75442--- a/lib/debugobjects.c
75443+++ b/lib/debugobjects.c
75444@@ -277,7 +277,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
75445 if (limit > 4)
75446 return;
75447
75448- is_on_stack = object_is_on_stack(addr);
75449+ is_on_stack = object_starts_on_stack(addr);
75450 if (is_on_stack == onstack)
75451 return;
75452
75453diff --git a/lib/devres.c b/lib/devres.c
75454index 72c8909..7543868 100644
75455--- a/lib/devres.c
75456+++ b/lib/devres.c
75457@@ -80,7 +80,7 @@ void devm_iounmap(struct device *dev, void __iomem *addr)
75458 {
75459 iounmap(addr);
75460 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
75461- (void *)addr));
75462+ (void __force *)addr));
75463 }
75464 EXPORT_SYMBOL(devm_iounmap);
75465
75466@@ -140,7 +140,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
75467 {
75468 ioport_unmap(addr);
75469 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
75470- devm_ioport_map_match, (void *)addr));
75471+ devm_ioport_map_match, (void __force *)addr));
75472 }
75473 EXPORT_SYMBOL(devm_ioport_unmap);
75474
75475diff --git a/lib/dma-debug.c b/lib/dma-debug.c
75476index 084e879..0674448 100644
75477--- a/lib/dma-debug.c
75478+++ b/lib/dma-debug.c
75479@@ -861,7 +861,7 @@ out:
75480
75481 static void check_for_stack(struct device *dev, void *addr)
75482 {
75483- if (object_is_on_stack(addr))
75484+ if (object_starts_on_stack(addr))
75485 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
75486 "stack [addr=%p]\n", addr);
75487 }
75488diff --git a/lib/idr.c b/lib/idr.c
75489index eda7ba3..915dfae 100644
75490--- a/lib/idr.c
75491+++ b/lib/idr.c
75492@@ -156,7 +156,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa)
75493 id = (id | ((1 << (IDR_BITS * l)) - 1)) + 1;
75494
75495 /* if already at the top layer, we need to grow */
75496- if (id >= 1 << (idp->layers * IDR_BITS)) {
75497+ if (id >= (1 << (idp->layers * IDR_BITS))) {
75498 *starting_id = id;
75499 return IDR_NEED_TO_GROW;
75500 }
75501diff --git a/lib/inflate.c b/lib/inflate.c
75502index d102559..4215f31 100644
75503--- a/lib/inflate.c
75504+++ b/lib/inflate.c
75505@@ -266,7 +266,7 @@ static void free(void *where)
75506 malloc_ptr = free_mem_ptr;
75507 }
75508 #else
75509-#define malloc(a) kmalloc(a, GFP_KERNEL)
75510+#define malloc(a) kmalloc((a), GFP_KERNEL)
75511 #define free(a) kfree(a)
75512 #endif
75513
75514diff --git a/lib/kobject.c b/lib/kobject.c
75515index b512b74..8115eb1 100644
75516--- a/lib/kobject.c
75517+++ b/lib/kobject.c
75518@@ -700,7 +700,7 @@ static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
75519 return ret;
75520 }
75521
75522-struct sysfs_ops kobj_sysfs_ops = {
75523+const struct sysfs_ops kobj_sysfs_ops = {
75524 .show = kobj_attr_show,
75525 .store = kobj_attr_store,
75526 };
75527@@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
75528 * If the kset was not able to be created, NULL will be returned.
75529 */
75530 static struct kset *kset_create(const char *name,
75531- struct kset_uevent_ops *uevent_ops,
75532+ const struct kset_uevent_ops *uevent_ops,
75533 struct kobject *parent_kobj)
75534 {
75535 struct kset *kset;
75536@@ -832,7 +832,7 @@ static struct kset *kset_create(const char *name,
75537 * If the kset was not able to be created, NULL will be returned.
75538 */
75539 struct kset *kset_create_and_add(const char *name,
75540- struct kset_uevent_ops *uevent_ops,
75541+ const struct kset_uevent_ops *uevent_ops,
75542 struct kobject *parent_kobj)
75543 {
75544 struct kset *kset;
75545diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
75546index 507b821..0bf8ed0 100644
75547--- a/lib/kobject_uevent.c
75548+++ b/lib/kobject_uevent.c
75549@@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
75550 const char *subsystem;
75551 struct kobject *top_kobj;
75552 struct kset *kset;
75553- struct kset_uevent_ops *uevent_ops;
75554+ const struct kset_uevent_ops *uevent_ops;
75555 u64 seq;
75556 int i = 0;
75557 int retval = 0;
75558diff --git a/lib/kref.c b/lib/kref.c
75559index 9ecd6e8..12c94c1 100644
75560--- a/lib/kref.c
75561+++ b/lib/kref.c
75562@@ -61,7 +61,7 @@ void kref_get(struct kref *kref)
75563 */
75564 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
75565 {
75566- WARN_ON(release == NULL);
75567+ BUG_ON(release == NULL);
75568 WARN_ON(release == (void (*)(struct kref *))kfree);
75569
75570 if (atomic_dec_and_test(&kref->refcount)) {
75571diff --git a/lib/parser.c b/lib/parser.c
75572index b00d020..1b34325 100644
75573--- a/lib/parser.c
75574+++ b/lib/parser.c
75575@@ -126,7 +126,7 @@ static int match_number(substring_t *s, int *result, int base)
75576 char *buf;
75577 int ret;
75578
75579- buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
75580+ buf = kmalloc((s->to - s->from) + 1, GFP_KERNEL);
75581 if (!buf)
75582 return -ENOMEM;
75583 memcpy(buf, s->from, s->to - s->from);
75584diff --git a/lib/radix-tree.c b/lib/radix-tree.c
75585index 92cdd99..a8149d7 100644
75586--- a/lib/radix-tree.c
75587+++ b/lib/radix-tree.c
75588@@ -81,7 +81,7 @@ struct radix_tree_preload {
75589 int nr;
75590 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
75591 };
75592-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
75593+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
75594
75595 static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
75596 {
75597diff --git a/lib/random32.c b/lib/random32.c
75598index 217d5c4..45aba8a 100644
75599--- a/lib/random32.c
75600+++ b/lib/random32.c
75601@@ -61,7 +61,7 @@ static u32 __random32(struct rnd_state *state)
75602 */
75603 static inline u32 __seed(u32 x, u32 m)
75604 {
75605- return (x < m) ? x + m : x;
75606+ return (x <= m) ? x + m + 1 : x;
75607 }
75608
75609 /**
75610diff --git a/lib/vsprintf.c b/lib/vsprintf.c
75611index 33bed5e..1477e46 100644
75612--- a/lib/vsprintf.c
75613+++ b/lib/vsprintf.c
75614@@ -16,6 +16,9 @@
75615 * - scnprintf and vscnprintf
75616 */
75617
75618+#ifdef CONFIG_GRKERNSEC_HIDESYM
75619+#define __INCLUDED_BY_HIDESYM 1
75620+#endif
75621 #include <stdarg.h>
75622 #include <linux/module.h>
75623 #include <linux/types.h>
75624@@ -546,12 +549,12 @@ static char *number(char *buf, char *end, unsigned long long num,
75625 return buf;
75626 }
75627
75628-static char *string(char *buf, char *end, char *s, struct printf_spec spec)
75629+static char *string(char *buf, char *end, const char *s, struct printf_spec spec)
75630 {
75631 int len, i;
75632
75633 if ((unsigned long)s < PAGE_SIZE)
75634- s = "<NULL>";
75635+ s = "(null)";
75636
75637 len = strnlen(s, spec.precision);
75638
75639@@ -581,7 +584,7 @@ static char *symbol_string(char *buf, char *end, void *ptr,
75640 unsigned long value = (unsigned long) ptr;
75641 #ifdef CONFIG_KALLSYMS
75642 char sym[KSYM_SYMBOL_LEN];
75643- if (ext != 'f' && ext != 's')
75644+ if (ext != 'f' && ext != 's' && ext != 'a')
75645 sprint_symbol(sym, value);
75646 else
75647 kallsyms_lookup(value, NULL, NULL, NULL, sym);
75648@@ -801,6 +804,8 @@ static char *ip4_addr_string(char *buf, char *end, const u8 *addr,
75649 * - 'f' For simple symbolic function names without offset
75650 * - 'S' For symbolic direct pointers with offset
75651 * - 's' For symbolic direct pointers without offset
75652+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
75653+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
75654 * - 'R' For a struct resource pointer, it prints the range of
75655 * addresses (not the name nor the flags)
75656 * - 'M' For a 6-byte MAC address, it prints the address in the
75657@@ -822,7 +827,7 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75658 struct printf_spec spec)
75659 {
75660 if (!ptr)
75661- return string(buf, end, "(null)", spec);
75662+ return string(buf, end, "(nil)", spec);
75663
75664 switch (*fmt) {
75665 case 'F':
75666@@ -831,6 +836,14 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75667 case 's':
75668 /* Fallthrough */
75669 case 'S':
75670+#ifdef CONFIG_GRKERNSEC_HIDESYM
75671+ break;
75672+#else
75673+ return symbol_string(buf, end, ptr, spec, *fmt);
75674+#endif
75675+ case 'a':
75676+ /* Fallthrough */
75677+ case 'A':
75678 return symbol_string(buf, end, ptr, spec, *fmt);
75679 case 'R':
75680 return resource_string(buf, end, ptr, spec);
75681@@ -1445,7 +1458,7 @@ do { \
75682 size_t len;
75683 if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
75684 || (unsigned long)save_str < PAGE_SIZE)
75685- save_str = "<NULL>";
75686+ save_str = "(null)";
75687 len = strlen(save_str);
75688 if (str + len + 1 < end)
75689 memcpy(str, save_str, len + 1);
75690@@ -1555,11 +1568,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75691 typeof(type) value; \
75692 if (sizeof(type) == 8) { \
75693 args = PTR_ALIGN(args, sizeof(u32)); \
75694- *(u32 *)&value = *(u32 *)args; \
75695- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75696+ *(u32 *)&value = *(const u32 *)args; \
75697+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75698 } else { \
75699 args = PTR_ALIGN(args, sizeof(type)); \
75700- value = *(typeof(type) *)args; \
75701+ value = *(const typeof(type) *)args; \
75702 } \
75703 args += sizeof(type); \
75704 value; \
75705@@ -1622,7 +1635,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75706 const char *str_arg = args;
75707 size_t len = strlen(str_arg);
75708 args += len + 1;
75709- str = string(str, end, (char *)str_arg, spec);
75710+ str = string(str, end, str_arg, spec);
75711 break;
75712 }
75713
75714diff --git a/localversion-grsec b/localversion-grsec
75715new file mode 100644
75716index 0000000..7cd6065
75717--- /dev/null
75718+++ b/localversion-grsec
75719@@ -0,0 +1 @@
75720+-grsec
75721diff --git a/mm/Kconfig b/mm/Kconfig
75722index 2c19c0b..f3c3f83 100644
75723--- a/mm/Kconfig
75724+++ b/mm/Kconfig
75725@@ -228,7 +228,7 @@ config KSM
75726 config DEFAULT_MMAP_MIN_ADDR
75727 int "Low address space to protect from user allocation"
75728 depends on MMU
75729- default 4096
75730+ default 65536
75731 help
75732 This is the portion of low virtual memory which should be protected
75733 from userspace allocation. Keeping a user from writing to low pages
75734diff --git a/mm/backing-dev.c b/mm/backing-dev.c
75735index 67a33a5..094dcf1 100644
75736--- a/mm/backing-dev.c
75737+++ b/mm/backing-dev.c
75738@@ -272,7 +272,7 @@ static void bdi_task_init(struct backing_dev_info *bdi,
75739 list_add_tail_rcu(&wb->list, &bdi->wb_list);
75740 spin_unlock(&bdi->wb_lock);
75741
75742- tsk->flags |= PF_FLUSHER | PF_SWAPWRITE;
75743+ tsk->flags |= PF_SWAPWRITE;
75744 set_freezable();
75745
75746 /*
75747@@ -484,7 +484,7 @@ static void bdi_add_to_pending(struct rcu_head *head)
75748 * Add the default flusher task that gets created for any bdi
75749 * that has dirty data pending writeout
75750 */
75751-void static bdi_add_default_flusher_task(struct backing_dev_info *bdi)
75752+static void bdi_add_default_flusher_task(struct backing_dev_info *bdi)
75753 {
75754 if (!bdi_cap_writeback_dirty(bdi))
75755 return;
75756diff --git a/mm/filemap.c b/mm/filemap.c
75757index a1fe378..e26702f 100644
75758--- a/mm/filemap.c
75759+++ b/mm/filemap.c
75760@@ -1631,7 +1631,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75761 struct address_space *mapping = file->f_mapping;
75762
75763 if (!mapping->a_ops->readpage)
75764- return -ENOEXEC;
75765+ return -ENODEV;
75766 file_accessed(file);
75767 vma->vm_ops = &generic_file_vm_ops;
75768 vma->vm_flags |= VM_CAN_NONLINEAR;
75769@@ -2024,6 +2024,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75770 *pos = i_size_read(inode);
75771
75772 if (limit != RLIM_INFINITY) {
75773+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75774 if (*pos >= limit) {
75775 send_sig(SIGXFSZ, current, 0);
75776 return -EFBIG;
75777diff --git a/mm/fremap.c b/mm/fremap.c
75778index b6ec85a..a24ac22 100644
75779--- a/mm/fremap.c
75780+++ b/mm/fremap.c
75781@@ -153,6 +153,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75782 retry:
75783 vma = find_vma(mm, start);
75784
75785+#ifdef CONFIG_PAX_SEGMEXEC
75786+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75787+ goto out;
75788+#endif
75789+
75790 /*
75791 * Make sure the vma is shared, that it supports prefaulting,
75792 * and that the remapped range is valid and fully within
75793@@ -221,7 +226,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75794 /*
75795 * drop PG_Mlocked flag for over-mapped range
75796 */
75797- unsigned int saved_flags = vma->vm_flags;
75798+ unsigned long saved_flags = vma->vm_flags;
75799 munlock_vma_pages_range(vma, start, start + size);
75800 vma->vm_flags = saved_flags;
75801 }
75802diff --git a/mm/highmem.c b/mm/highmem.c
75803index 9c1e627..5ca9447 100644
75804--- a/mm/highmem.c
75805+++ b/mm/highmem.c
75806@@ -116,9 +116,10 @@ static void flush_all_zero_pkmaps(void)
75807 * So no dangers, even with speculative execution.
75808 */
75809 page = pte_page(pkmap_page_table[i]);
75810+ pax_open_kernel();
75811 pte_clear(&init_mm, (unsigned long)page_address(page),
75812 &pkmap_page_table[i]);
75813-
75814+ pax_close_kernel();
75815 set_page_address(page, NULL);
75816 need_flush = 1;
75817 }
75818@@ -177,9 +178,11 @@ start:
75819 }
75820 }
75821 vaddr = PKMAP_ADDR(last_pkmap_nr);
75822+
75823+ pax_open_kernel();
75824 set_pte_at(&init_mm, vaddr,
75825 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
75826-
75827+ pax_close_kernel();
75828 pkmap_count[last_pkmap_nr] = 1;
75829 set_page_address(page, (void *)vaddr);
75830
75831diff --git a/mm/hugetlb.c b/mm/hugetlb.c
75832index 5e1e508..ac70275 100644
75833--- a/mm/hugetlb.c
75834+++ b/mm/hugetlb.c
75835@@ -869,6 +869,7 @@ free:
75836 list_del(&page->lru);
75837 enqueue_huge_page(h, page);
75838 }
75839+ spin_unlock(&hugetlb_lock);
75840
75841 /* Free unnecessary surplus pages to the buddy allocator */
75842 if (!list_empty(&surplus_list)) {
75843@@ -1933,6 +1934,26 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
75844 return 1;
75845 }
75846
75847+#ifdef CONFIG_PAX_SEGMEXEC
75848+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
75849+{
75850+ struct mm_struct *mm = vma->vm_mm;
75851+ struct vm_area_struct *vma_m;
75852+ unsigned long address_m;
75853+ pte_t *ptep_m;
75854+
75855+ vma_m = pax_find_mirror_vma(vma);
75856+ if (!vma_m)
75857+ return;
75858+
75859+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75860+ address_m = address + SEGMEXEC_TASK_SIZE;
75861+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
75862+ get_page(page_m);
75863+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
75864+}
75865+#endif
75866+
75867 static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
75868 unsigned long address, pte_t *ptep, pte_t pte,
75869 struct page *pagecache_page)
75870@@ -2004,6 +2025,11 @@ retry_avoidcopy:
75871 huge_ptep_clear_flush(vma, address, ptep);
75872 set_huge_pte_at(mm, address, ptep,
75873 make_huge_pte(vma, new_page, 1));
75874+
75875+#ifdef CONFIG_PAX_SEGMEXEC
75876+ pax_mirror_huge_pte(vma, address, new_page);
75877+#endif
75878+
75879 /* Make the old page be freed below */
75880 new_page = old_page;
75881 }
75882@@ -2135,6 +2161,10 @@ retry:
75883 && (vma->vm_flags & VM_SHARED)));
75884 set_huge_pte_at(mm, address, ptep, new_pte);
75885
75886+#ifdef CONFIG_PAX_SEGMEXEC
75887+ pax_mirror_huge_pte(vma, address, page);
75888+#endif
75889+
75890 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
75891 /* Optimization, do the COW without a second fault */
75892 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
75893@@ -2163,6 +2193,28 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75894 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
75895 struct hstate *h = hstate_vma(vma);
75896
75897+#ifdef CONFIG_PAX_SEGMEXEC
75898+ struct vm_area_struct *vma_m;
75899+
75900+ vma_m = pax_find_mirror_vma(vma);
75901+ if (vma_m) {
75902+ unsigned long address_m;
75903+
75904+ if (vma->vm_start > vma_m->vm_start) {
75905+ address_m = address;
75906+ address -= SEGMEXEC_TASK_SIZE;
75907+ vma = vma_m;
75908+ h = hstate_vma(vma);
75909+ } else
75910+ address_m = address + SEGMEXEC_TASK_SIZE;
75911+
75912+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
75913+ return VM_FAULT_OOM;
75914+ address_m &= HPAGE_MASK;
75915+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
75916+ }
75917+#endif
75918+
75919 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
75920 if (!ptep)
75921 return VM_FAULT_OOM;
75922diff --git a/mm/internal.h b/mm/internal.h
75923index f03e8e2..7354343 100644
75924--- a/mm/internal.h
75925+++ b/mm/internal.h
75926@@ -49,6 +49,7 @@ extern void putback_lru_page(struct page *page);
75927 * in mm/page_alloc.c
75928 */
75929 extern void __free_pages_bootmem(struct page *page, unsigned int order);
75930+extern void free_compound_page(struct page *page);
75931 extern void prep_compound_page(struct page *page, unsigned long order);
75932
75933
75934diff --git a/mm/kmemleak.c b/mm/kmemleak.c
75935index c346660..b47382f 100644
75936--- a/mm/kmemleak.c
75937+++ b/mm/kmemleak.c
75938@@ -358,7 +358,7 @@ static void print_unreferenced(struct seq_file *seq,
75939
75940 for (i = 0; i < object->trace_len; i++) {
75941 void *ptr = (void *)object->trace[i];
75942- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
75943+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
75944 }
75945 }
75946
75947diff --git a/mm/maccess.c b/mm/maccess.c
75948index 9073695..1127f348 100644
75949--- a/mm/maccess.c
75950+++ b/mm/maccess.c
75951@@ -14,7 +14,7 @@
75952 * Safely read from address @src to the buffer at @dst. If a kernel fault
75953 * happens, handle that and return -EFAULT.
75954 */
75955-long probe_kernel_read(void *dst, void *src, size_t size)
75956+long probe_kernel_read(void *dst, const void *src, size_t size)
75957 {
75958 long ret;
75959 mm_segment_t old_fs = get_fs();
75960@@ -22,7 +22,7 @@ long probe_kernel_read(void *dst, void *src, size_t size)
75961 set_fs(KERNEL_DS);
75962 pagefault_disable();
75963 ret = __copy_from_user_inatomic(dst,
75964- (__force const void __user *)src, size);
75965+ (const void __force_user *)src, size);
75966 pagefault_enable();
75967 set_fs(old_fs);
75968
75969@@ -39,14 +39,14 @@ EXPORT_SYMBOL_GPL(probe_kernel_read);
75970 * Safely write to address @dst from the buffer at @src. If a kernel fault
75971 * happens, handle that and return -EFAULT.
75972 */
75973-long notrace __weak probe_kernel_write(void *dst, void *src, size_t size)
75974+long notrace __weak probe_kernel_write(void *dst, const void *src, size_t size)
75975 {
75976 long ret;
75977 mm_segment_t old_fs = get_fs();
75978
75979 set_fs(KERNEL_DS);
75980 pagefault_disable();
75981- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
75982+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
75983 pagefault_enable();
75984 set_fs(old_fs);
75985
75986diff --git a/mm/madvise.c b/mm/madvise.c
75987index 35b1479..499f7d4 100644
75988--- a/mm/madvise.c
75989+++ b/mm/madvise.c
75990@@ -44,6 +44,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
75991 pgoff_t pgoff;
75992 unsigned long new_flags = vma->vm_flags;
75993
75994+#ifdef CONFIG_PAX_SEGMEXEC
75995+ struct vm_area_struct *vma_m;
75996+#endif
75997+
75998 switch (behavior) {
75999 case MADV_NORMAL:
76000 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
76001@@ -103,6 +107,13 @@ success:
76002 /*
76003 * vm_flags is protected by the mmap_sem held in write mode.
76004 */
76005+
76006+#ifdef CONFIG_PAX_SEGMEXEC
76007+ vma_m = pax_find_mirror_vma(vma);
76008+ if (vma_m)
76009+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
76010+#endif
76011+
76012 vma->vm_flags = new_flags;
76013
76014 out:
76015@@ -161,6 +172,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
76016 struct vm_area_struct ** prev,
76017 unsigned long start, unsigned long end)
76018 {
76019+
76020+#ifdef CONFIG_PAX_SEGMEXEC
76021+ struct vm_area_struct *vma_m;
76022+#endif
76023+
76024 *prev = vma;
76025 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
76026 return -EINVAL;
76027@@ -173,6 +189,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
76028 zap_page_range(vma, start, end - start, &details);
76029 } else
76030 zap_page_range(vma, start, end - start, NULL);
76031+
76032+#ifdef CONFIG_PAX_SEGMEXEC
76033+ vma_m = pax_find_mirror_vma(vma);
76034+ if (vma_m) {
76035+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
76036+ struct zap_details details = {
76037+ .nonlinear_vma = vma_m,
76038+ .last_index = ULONG_MAX,
76039+ };
76040+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
76041+ } else
76042+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
76043+ }
76044+#endif
76045+
76046 return 0;
76047 }
76048
76049@@ -359,6 +390,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
76050 if (end < start)
76051 goto out;
76052
76053+#ifdef CONFIG_PAX_SEGMEXEC
76054+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
76055+ if (end > SEGMEXEC_TASK_SIZE)
76056+ goto out;
76057+ } else
76058+#endif
76059+
76060+ if (end > TASK_SIZE)
76061+ goto out;
76062+
76063 error = 0;
76064 if (end == start)
76065 goto out;
76066diff --git a/mm/memory-failure.c b/mm/memory-failure.c
76067index 8aeba53..b4a4198 100644
76068--- a/mm/memory-failure.c
76069+++ b/mm/memory-failure.c
76070@@ -46,7 +46,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
76071
76072 int sysctl_memory_failure_recovery __read_mostly = 1;
76073
76074-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
76075+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
76076
76077 /*
76078 * Send all the processes who have the page mapped an ``action optional''
76079@@ -64,7 +64,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
76080 si.si_signo = SIGBUS;
76081 si.si_errno = 0;
76082 si.si_code = BUS_MCEERR_AO;
76083- si.si_addr = (void *)addr;
76084+ si.si_addr = (void __user *)addr;
76085 #ifdef __ARCH_SI_TRAPNO
76086 si.si_trapno = trapno;
76087 #endif
76088@@ -745,7 +745,7 @@ int __memory_failure(unsigned long pfn, int trapno, int ref)
76089 return 0;
76090 }
76091
76092- atomic_long_add(1, &mce_bad_pages);
76093+ atomic_long_add_unchecked(1, &mce_bad_pages);
76094
76095 /*
76096 * We need/can do nothing about count=0 pages.
76097diff --git a/mm/memory.c b/mm/memory.c
76098index 6c836d3..48f3264 100644
76099--- a/mm/memory.c
76100+++ b/mm/memory.c
76101@@ -187,8 +187,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
76102 return;
76103
76104 pmd = pmd_offset(pud, start);
76105+
76106+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
76107 pud_clear(pud);
76108 pmd_free_tlb(tlb, pmd, start);
76109+#endif
76110+
76111 }
76112
76113 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
76114@@ -219,9 +223,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
76115 if (end - 1 > ceiling - 1)
76116 return;
76117
76118+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
76119 pud = pud_offset(pgd, start);
76120 pgd_clear(pgd);
76121 pud_free_tlb(tlb, pud, start);
76122+#endif
76123+
76124 }
76125
76126 /*
76127@@ -1251,10 +1258,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
76128 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
76129 i = 0;
76130
76131- do {
76132+ while (nr_pages) {
76133 struct vm_area_struct *vma;
76134
76135- vma = find_extend_vma(mm, start);
76136+ vma = find_vma(mm, start);
76137 if (!vma && in_gate_area(tsk, start)) {
76138 unsigned long pg = start & PAGE_MASK;
76139 struct vm_area_struct *gate_vma = get_gate_vma(tsk);
76140@@ -1306,7 +1313,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
76141 continue;
76142 }
76143
76144- if (!vma ||
76145+ if (!vma || start < vma->vm_start ||
76146 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
76147 !(vm_flags & vma->vm_flags))
76148 return i ? : -EFAULT;
76149@@ -1381,7 +1388,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
76150 start += PAGE_SIZE;
76151 nr_pages--;
76152 } while (nr_pages && start < vma->vm_end);
76153- } while (nr_pages);
76154+ }
76155 return i;
76156 }
76157
76158@@ -1526,6 +1533,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
76159 page_add_file_rmap(page);
76160 set_pte_at(mm, addr, pte, mk_pte(page, prot));
76161
76162+#ifdef CONFIG_PAX_SEGMEXEC
76163+ pax_mirror_file_pte(vma, addr, page, ptl);
76164+#endif
76165+
76166 retval = 0;
76167 pte_unmap_unlock(pte, ptl);
76168 return retval;
76169@@ -1560,10 +1571,22 @@ out:
76170 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
76171 struct page *page)
76172 {
76173+
76174+#ifdef CONFIG_PAX_SEGMEXEC
76175+ struct vm_area_struct *vma_m;
76176+#endif
76177+
76178 if (addr < vma->vm_start || addr >= vma->vm_end)
76179 return -EFAULT;
76180 if (!page_count(page))
76181 return -EINVAL;
76182+
76183+#ifdef CONFIG_PAX_SEGMEXEC
76184+ vma_m = pax_find_mirror_vma(vma);
76185+ if (vma_m)
76186+ vma_m->vm_flags |= VM_INSERTPAGE;
76187+#endif
76188+
76189 vma->vm_flags |= VM_INSERTPAGE;
76190 return insert_page(vma, addr, page, vma->vm_page_prot);
76191 }
76192@@ -1649,6 +1672,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
76193 unsigned long pfn)
76194 {
76195 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
76196+ BUG_ON(vma->vm_mirror);
76197
76198 if (addr < vma->vm_start || addr >= vma->vm_end)
76199 return -EFAULT;
76200@@ -1977,6 +2001,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
76201 copy_user_highpage(dst, src, va, vma);
76202 }
76203
76204+#ifdef CONFIG_PAX_SEGMEXEC
76205+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
76206+{
76207+ struct mm_struct *mm = vma->vm_mm;
76208+ spinlock_t *ptl;
76209+ pte_t *pte, entry;
76210+
76211+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
76212+ entry = *pte;
76213+ if (!pte_present(entry)) {
76214+ if (!pte_none(entry)) {
76215+ BUG_ON(pte_file(entry));
76216+ free_swap_and_cache(pte_to_swp_entry(entry));
76217+ pte_clear_not_present_full(mm, address, pte, 0);
76218+ }
76219+ } else {
76220+ struct page *page;
76221+
76222+ flush_cache_page(vma, address, pte_pfn(entry));
76223+ entry = ptep_clear_flush(vma, address, pte);
76224+ BUG_ON(pte_dirty(entry));
76225+ page = vm_normal_page(vma, address, entry);
76226+ if (page) {
76227+ update_hiwater_rss(mm);
76228+ if (PageAnon(page))
76229+ dec_mm_counter(mm, anon_rss);
76230+ else
76231+ dec_mm_counter(mm, file_rss);
76232+ page_remove_rmap(page);
76233+ page_cache_release(page);
76234+ }
76235+ }
76236+ pte_unmap_unlock(pte, ptl);
76237+}
76238+
76239+/* PaX: if vma is mirrored, synchronize the mirror's PTE
76240+ *
76241+ * the ptl of the lower mapped page is held on entry and is not released on exit
76242+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
76243+ */
76244+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
76245+{
76246+ struct mm_struct *mm = vma->vm_mm;
76247+ unsigned long address_m;
76248+ spinlock_t *ptl_m;
76249+ struct vm_area_struct *vma_m;
76250+ pmd_t *pmd_m;
76251+ pte_t *pte_m, entry_m;
76252+
76253+ BUG_ON(!page_m || !PageAnon(page_m));
76254+
76255+ vma_m = pax_find_mirror_vma(vma);
76256+ if (!vma_m)
76257+ return;
76258+
76259+ BUG_ON(!PageLocked(page_m));
76260+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
76261+ address_m = address + SEGMEXEC_TASK_SIZE;
76262+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
76263+ pte_m = pte_offset_map_nested(pmd_m, address_m);
76264+ ptl_m = pte_lockptr(mm, pmd_m);
76265+ if (ptl != ptl_m) {
76266+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
76267+ if (!pte_none(*pte_m))
76268+ goto out;
76269+ }
76270+
76271+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
76272+ page_cache_get(page_m);
76273+ page_add_anon_rmap(page_m, vma_m, address_m);
76274+ inc_mm_counter(mm, anon_rss);
76275+ set_pte_at(mm, address_m, pte_m, entry_m);
76276+ update_mmu_cache(vma_m, address_m, entry_m);
76277+out:
76278+ if (ptl != ptl_m)
76279+ spin_unlock(ptl_m);
76280+ pte_unmap_nested(pte_m);
76281+ unlock_page(page_m);
76282+}
76283+
76284+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
76285+{
76286+ struct mm_struct *mm = vma->vm_mm;
76287+ unsigned long address_m;
76288+ spinlock_t *ptl_m;
76289+ struct vm_area_struct *vma_m;
76290+ pmd_t *pmd_m;
76291+ pte_t *pte_m, entry_m;
76292+
76293+ BUG_ON(!page_m || PageAnon(page_m));
76294+
76295+ vma_m = pax_find_mirror_vma(vma);
76296+ if (!vma_m)
76297+ return;
76298+
76299+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
76300+ address_m = address + SEGMEXEC_TASK_SIZE;
76301+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
76302+ pte_m = pte_offset_map_nested(pmd_m, address_m);
76303+ ptl_m = pte_lockptr(mm, pmd_m);
76304+ if (ptl != ptl_m) {
76305+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
76306+ if (!pte_none(*pte_m))
76307+ goto out;
76308+ }
76309+
76310+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
76311+ page_cache_get(page_m);
76312+ page_add_file_rmap(page_m);
76313+ inc_mm_counter(mm, file_rss);
76314+ set_pte_at(mm, address_m, pte_m, entry_m);
76315+ update_mmu_cache(vma_m, address_m, entry_m);
76316+out:
76317+ if (ptl != ptl_m)
76318+ spin_unlock(ptl_m);
76319+ pte_unmap_nested(pte_m);
76320+}
76321+
76322+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
76323+{
76324+ struct mm_struct *mm = vma->vm_mm;
76325+ unsigned long address_m;
76326+ spinlock_t *ptl_m;
76327+ struct vm_area_struct *vma_m;
76328+ pmd_t *pmd_m;
76329+ pte_t *pte_m, entry_m;
76330+
76331+ vma_m = pax_find_mirror_vma(vma);
76332+ if (!vma_m)
76333+ return;
76334+
76335+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
76336+ address_m = address + SEGMEXEC_TASK_SIZE;
76337+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
76338+ pte_m = pte_offset_map_nested(pmd_m, address_m);
76339+ ptl_m = pte_lockptr(mm, pmd_m);
76340+ if (ptl != ptl_m) {
76341+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
76342+ if (!pte_none(*pte_m))
76343+ goto out;
76344+ }
76345+
76346+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
76347+ set_pte_at(mm, address_m, pte_m, entry_m);
76348+out:
76349+ if (ptl != ptl_m)
76350+ spin_unlock(ptl_m);
76351+ pte_unmap_nested(pte_m);
76352+}
76353+
76354+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
76355+{
76356+ struct page *page_m;
76357+ pte_t entry;
76358+
76359+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
76360+ goto out;
76361+
76362+ entry = *pte;
76363+ page_m = vm_normal_page(vma, address, entry);
76364+ if (!page_m)
76365+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
76366+ else if (PageAnon(page_m)) {
76367+ if (pax_find_mirror_vma(vma)) {
76368+ pte_unmap_unlock(pte, ptl);
76369+ lock_page(page_m);
76370+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
76371+ if (pte_same(entry, *pte))
76372+ pax_mirror_anon_pte(vma, address, page_m, ptl);
76373+ else
76374+ unlock_page(page_m);
76375+ }
76376+ } else
76377+ pax_mirror_file_pte(vma, address, page_m, ptl);
76378+
76379+out:
76380+ pte_unmap_unlock(pte, ptl);
76381+}
76382+#endif
76383+
76384 /*
76385 * This routine handles present pages, when users try to write
76386 * to a shared page. It is done by copying the page to a new address
76387@@ -2156,6 +2360,12 @@ gotten:
76388 */
76389 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76390 if (likely(pte_same(*page_table, orig_pte))) {
76391+
76392+#ifdef CONFIG_PAX_SEGMEXEC
76393+ if (pax_find_mirror_vma(vma))
76394+ BUG_ON(!trylock_page(new_page));
76395+#endif
76396+
76397 if (old_page) {
76398 if (!PageAnon(old_page)) {
76399 dec_mm_counter(mm, file_rss);
76400@@ -2207,6 +2417,10 @@ gotten:
76401 page_remove_rmap(old_page);
76402 }
76403
76404+#ifdef CONFIG_PAX_SEGMEXEC
76405+ pax_mirror_anon_pte(vma, address, new_page, ptl);
76406+#endif
76407+
76408 /* Free the old page.. */
76409 new_page = old_page;
76410 ret |= VM_FAULT_WRITE;
76411@@ -2606,6 +2820,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76412 swap_free(entry);
76413 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
76414 try_to_free_swap(page);
76415+
76416+#ifdef CONFIG_PAX_SEGMEXEC
76417+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
76418+#endif
76419+
76420 unlock_page(page);
76421
76422 if (flags & FAULT_FLAG_WRITE) {
76423@@ -2617,6 +2836,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76424
76425 /* No need to invalidate - it was non-present before */
76426 update_mmu_cache(vma, address, pte);
76427+
76428+#ifdef CONFIG_PAX_SEGMEXEC
76429+ pax_mirror_anon_pte(vma, address, page, ptl);
76430+#endif
76431+
76432 unlock:
76433 pte_unmap_unlock(page_table, ptl);
76434 out:
76435@@ -2632,40 +2856,6 @@ out_release:
76436 }
76437
76438 /*
76439- * This is like a special single-page "expand_{down|up}wards()",
76440- * except we must first make sure that 'address{-|+}PAGE_SIZE'
76441- * doesn't hit another vma.
76442- */
76443-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
76444-{
76445- address &= PAGE_MASK;
76446- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
76447- struct vm_area_struct *prev = vma->vm_prev;
76448-
76449- /*
76450- * Is there a mapping abutting this one below?
76451- *
76452- * That's only ok if it's the same stack mapping
76453- * that has gotten split..
76454- */
76455- if (prev && prev->vm_end == address)
76456- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
76457-
76458- expand_stack(vma, address - PAGE_SIZE);
76459- }
76460- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
76461- struct vm_area_struct *next = vma->vm_next;
76462-
76463- /* As VM_GROWSDOWN but s/below/above/ */
76464- if (next && next->vm_start == address + PAGE_SIZE)
76465- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
76466-
76467- expand_upwards(vma, address + PAGE_SIZE);
76468- }
76469- return 0;
76470-}
76471-
76472-/*
76473 * We enter with non-exclusive mmap_sem (to exclude vma changes,
76474 * but allow concurrent faults), and pte mapped but not yet locked.
76475 * We return with mmap_sem still held, but pte unmapped and unlocked.
76476@@ -2674,27 +2864,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76477 unsigned long address, pte_t *page_table, pmd_t *pmd,
76478 unsigned int flags)
76479 {
76480- struct page *page;
76481+ struct page *page = NULL;
76482 spinlock_t *ptl;
76483 pte_t entry;
76484
76485- pte_unmap(page_table);
76486-
76487- /* Check if we need to add a guard page to the stack */
76488- if (check_stack_guard_page(vma, address) < 0)
76489- return VM_FAULT_SIGBUS;
76490-
76491- /* Use the zero-page for reads */
76492 if (!(flags & FAULT_FLAG_WRITE)) {
76493 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
76494 vma->vm_page_prot));
76495- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76496+ ptl = pte_lockptr(mm, pmd);
76497+ spin_lock(ptl);
76498 if (!pte_none(*page_table))
76499 goto unlock;
76500 goto setpte;
76501 }
76502
76503 /* Allocate our own private page. */
76504+ pte_unmap(page_table);
76505+
76506 if (unlikely(anon_vma_prepare(vma)))
76507 goto oom;
76508 page = alloc_zeroed_user_highpage_movable(vma, address);
76509@@ -2713,6 +2899,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76510 if (!pte_none(*page_table))
76511 goto release;
76512
76513+#ifdef CONFIG_PAX_SEGMEXEC
76514+ if (pax_find_mirror_vma(vma))
76515+ BUG_ON(!trylock_page(page));
76516+#endif
76517+
76518 inc_mm_counter(mm, anon_rss);
76519 page_add_new_anon_rmap(page, vma, address);
76520 setpte:
76521@@ -2720,6 +2911,12 @@ setpte:
76522
76523 /* No need to invalidate - it was non-present before */
76524 update_mmu_cache(vma, address, entry);
76525+
76526+#ifdef CONFIG_PAX_SEGMEXEC
76527+ if (page)
76528+ pax_mirror_anon_pte(vma, address, page, ptl);
76529+#endif
76530+
76531 unlock:
76532 pte_unmap_unlock(page_table, ptl);
76533 return 0;
76534@@ -2862,6 +3059,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76535 */
76536 /* Only go through if we didn't race with anybody else... */
76537 if (likely(pte_same(*page_table, orig_pte))) {
76538+
76539+#ifdef CONFIG_PAX_SEGMEXEC
76540+ if (anon && pax_find_mirror_vma(vma))
76541+ BUG_ON(!trylock_page(page));
76542+#endif
76543+
76544 flush_icache_page(vma, page);
76545 entry = mk_pte(page, vma->vm_page_prot);
76546 if (flags & FAULT_FLAG_WRITE)
76547@@ -2881,6 +3084,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76548
76549 /* no need to invalidate: a not-present page won't be cached */
76550 update_mmu_cache(vma, address, entry);
76551+
76552+#ifdef CONFIG_PAX_SEGMEXEC
76553+ if (anon)
76554+ pax_mirror_anon_pte(vma, address, page, ptl);
76555+ else
76556+ pax_mirror_file_pte(vma, address, page, ptl);
76557+#endif
76558+
76559 } else {
76560 if (charged)
76561 mem_cgroup_uncharge_page(page);
76562@@ -3028,6 +3239,12 @@ static inline int handle_pte_fault(struct mm_struct *mm,
76563 if (flags & FAULT_FLAG_WRITE)
76564 flush_tlb_page(vma, address);
76565 }
76566+
76567+#ifdef CONFIG_PAX_SEGMEXEC
76568+ pax_mirror_pte(vma, address, pte, pmd, ptl);
76569+ return 0;
76570+#endif
76571+
76572 unlock:
76573 pte_unmap_unlock(pte, ptl);
76574 return 0;
76575@@ -3044,6 +3261,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76576 pmd_t *pmd;
76577 pte_t *pte;
76578
76579+#ifdef CONFIG_PAX_SEGMEXEC
76580+ struct vm_area_struct *vma_m;
76581+#endif
76582+
76583 __set_current_state(TASK_RUNNING);
76584
76585 count_vm_event(PGFAULT);
76586@@ -3051,6 +3272,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76587 if (unlikely(is_vm_hugetlb_page(vma)))
76588 return hugetlb_fault(mm, vma, address, flags);
76589
76590+#ifdef CONFIG_PAX_SEGMEXEC
76591+ vma_m = pax_find_mirror_vma(vma);
76592+ if (vma_m) {
76593+ unsigned long address_m;
76594+ pgd_t *pgd_m;
76595+ pud_t *pud_m;
76596+ pmd_t *pmd_m;
76597+
76598+ if (vma->vm_start > vma_m->vm_start) {
76599+ address_m = address;
76600+ address -= SEGMEXEC_TASK_SIZE;
76601+ vma = vma_m;
76602+ } else
76603+ address_m = address + SEGMEXEC_TASK_SIZE;
76604+
76605+ pgd_m = pgd_offset(mm, address_m);
76606+ pud_m = pud_alloc(mm, pgd_m, address_m);
76607+ if (!pud_m)
76608+ return VM_FAULT_OOM;
76609+ pmd_m = pmd_alloc(mm, pud_m, address_m);
76610+ if (!pmd_m)
76611+ return VM_FAULT_OOM;
76612+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
76613+ return VM_FAULT_OOM;
76614+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76615+ }
76616+#endif
76617+
76618 pgd = pgd_offset(mm, address);
76619 pud = pud_alloc(mm, pgd, address);
76620 if (!pud)
76621@@ -3148,7 +3397,7 @@ static int __init gate_vma_init(void)
76622 gate_vma.vm_start = FIXADDR_USER_START;
76623 gate_vma.vm_end = FIXADDR_USER_END;
76624 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76625- gate_vma.vm_page_prot = __P101;
76626+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76627 /*
76628 * Make sure the vDSO gets into every core dump.
76629 * Dumping its contents makes post-mortem fully interpretable later
76630diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76631index 3c6e3e2..ad9871c 100644
76632--- a/mm/mempolicy.c
76633+++ b/mm/mempolicy.c
76634@@ -573,6 +573,10 @@ static int mbind_range(struct vm_area_struct *vma, unsigned long start,
76635 struct vm_area_struct *next;
76636 int err;
76637
76638+#ifdef CONFIG_PAX_SEGMEXEC
76639+ struct vm_area_struct *vma_m;
76640+#endif
76641+
76642 err = 0;
76643 for (; vma && vma->vm_start < end; vma = next) {
76644 next = vma->vm_next;
76645@@ -584,6 +588,16 @@ static int mbind_range(struct vm_area_struct *vma, unsigned long start,
76646 err = policy_vma(vma, new);
76647 if (err)
76648 break;
76649+
76650+#ifdef CONFIG_PAX_SEGMEXEC
76651+ vma_m = pax_find_mirror_vma(vma);
76652+ if (vma_m) {
76653+ err = policy_vma(vma_m, new);
76654+ if (err)
76655+ break;
76656+ }
76657+#endif
76658+
76659 }
76660 return err;
76661 }
76662@@ -1002,6 +1016,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76663
76664 if (end < start)
76665 return -EINVAL;
76666+
76667+#ifdef CONFIG_PAX_SEGMEXEC
76668+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76669+ if (end > SEGMEXEC_TASK_SIZE)
76670+ return -EINVAL;
76671+ } else
76672+#endif
76673+
76674+ if (end > TASK_SIZE)
76675+ return -EINVAL;
76676+
76677 if (end == start)
76678 return 0;
76679
76680@@ -1207,6 +1232,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76681 if (!mm)
76682 return -EINVAL;
76683
76684+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76685+ if (mm != current->mm &&
76686+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76687+ err = -EPERM;
76688+ goto out;
76689+ }
76690+#endif
76691+
76692 /*
76693 * Check if this process has the right to modify the specified
76694 * process. The right exists if the process has administrative
76695@@ -1216,8 +1249,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76696 rcu_read_lock();
76697 tcred = __task_cred(task);
76698 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
76699- cred->uid != tcred->suid && cred->uid != tcred->uid &&
76700- !capable(CAP_SYS_NICE)) {
76701+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
76702 rcu_read_unlock();
76703 err = -EPERM;
76704 goto out;
76705@@ -2396,7 +2428,7 @@ int show_numa_map(struct seq_file *m, void *v)
76706
76707 if (file) {
76708 seq_printf(m, " file=");
76709- seq_path(m, &file->f_path, "\n\t= ");
76710+ seq_path(m, &file->f_path, "\n\t\\= ");
76711 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
76712 seq_printf(m, " heap");
76713 } else if (vma->vm_start <= mm->start_stack &&
76714diff --git a/mm/migrate.c b/mm/migrate.c
76715index aaca868..2ebecdc 100644
76716--- a/mm/migrate.c
76717+++ b/mm/migrate.c
76718@@ -916,6 +916,8 @@ static int do_pages_move(struct mm_struct *mm, struct task_struct *task,
76719 unsigned long chunk_start;
76720 int err;
76721
76722+ pax_track_stack();
76723+
76724 task_nodes = cpuset_mems_allowed(task);
76725
76726 err = -ENOMEM;
76727@@ -1106,6 +1108,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76728 if (!mm)
76729 return -EINVAL;
76730
76731+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76732+ if (mm != current->mm &&
76733+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76734+ err = -EPERM;
76735+ goto out;
76736+ }
76737+#endif
76738+
76739 /*
76740 * Check if this process has the right to modify the specified
76741 * process. The right exists if the process has administrative
76742@@ -1115,8 +1125,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76743 rcu_read_lock();
76744 tcred = __task_cred(task);
76745 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
76746- cred->uid != tcred->suid && cred->uid != tcred->uid &&
76747- !capable(CAP_SYS_NICE)) {
76748+ cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
76749 rcu_read_unlock();
76750 err = -EPERM;
76751 goto out;
76752diff --git a/mm/mlock.c b/mm/mlock.c
76753index 2d846cf..98134d2 100644
76754--- a/mm/mlock.c
76755+++ b/mm/mlock.c
76756@@ -13,6 +13,7 @@
76757 #include <linux/pagemap.h>
76758 #include <linux/mempolicy.h>
76759 #include <linux/syscalls.h>
76760+#include <linux/security.h>
76761 #include <linux/sched.h>
76762 #include <linux/module.h>
76763 #include <linux/rmap.h>
76764@@ -138,13 +139,6 @@ void munlock_vma_page(struct page *page)
76765 }
76766 }
76767
76768-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
76769-{
76770- return (vma->vm_flags & VM_GROWSDOWN) &&
76771- (vma->vm_start == addr) &&
76772- !vma_stack_continue(vma->vm_prev, addr);
76773-}
76774-
76775 /**
76776 * __mlock_vma_pages_range() - mlock a range of pages in the vma.
76777 * @vma: target vma
76778@@ -177,12 +171,6 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
76779 if (vma->vm_flags & VM_WRITE)
76780 gup_flags |= FOLL_WRITE;
76781
76782- /* We don't try to access the guard page of a stack vma */
76783- if (stack_guard_page(vma, start)) {
76784- addr += PAGE_SIZE;
76785- nr_pages--;
76786- }
76787-
76788 while (nr_pages > 0) {
76789 int i;
76790
76791@@ -440,7 +428,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76792 {
76793 unsigned long nstart, end, tmp;
76794 struct vm_area_struct * vma, * prev;
76795- int error;
76796+ int error = -EINVAL;
76797
76798 len = PAGE_ALIGN(len);
76799 end = start + len;
76800@@ -448,6 +436,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76801 return -EINVAL;
76802 if (end == start)
76803 return 0;
76804+ if (end > TASK_SIZE)
76805+ return -EINVAL;
76806+
76807 vma = find_vma_prev(current->mm, start, &prev);
76808 if (!vma || vma->vm_start > start)
76809 return -ENOMEM;
76810@@ -458,6 +449,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
76811 for (nstart = start ; ; ) {
76812 unsigned int newflags;
76813
76814+#ifdef CONFIG_PAX_SEGMEXEC
76815+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76816+ break;
76817+#endif
76818+
76819 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
76820
76821 newflags = vma->vm_flags | VM_LOCKED;
76822@@ -507,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
76823 lock_limit >>= PAGE_SHIFT;
76824
76825 /* check against resource limits */
76826+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
76827 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
76828 error = do_mlock(start, len, 1);
76829 up_write(&current->mm->mmap_sem);
76830@@ -528,17 +525,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
76831 static int do_mlockall(int flags)
76832 {
76833 struct vm_area_struct * vma, * prev = NULL;
76834- unsigned int def_flags = 0;
76835
76836 if (flags & MCL_FUTURE)
76837- def_flags = VM_LOCKED;
76838- current->mm->def_flags = def_flags;
76839+ current->mm->def_flags |= VM_LOCKED;
76840+ else
76841+ current->mm->def_flags &= ~VM_LOCKED;
76842 if (flags == MCL_FUTURE)
76843 goto out;
76844
76845 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
76846- unsigned int newflags;
76847+ unsigned long newflags;
76848
76849+#ifdef CONFIG_PAX_SEGMEXEC
76850+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76851+ break;
76852+#endif
76853+
76854+ BUG_ON(vma->vm_end > TASK_SIZE);
76855 newflags = vma->vm_flags | VM_LOCKED;
76856 if (!(flags & MCL_CURRENT))
76857 newflags &= ~VM_LOCKED;
76858@@ -570,6 +573,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
76859 lock_limit >>= PAGE_SHIFT;
76860
76861 ret = -ENOMEM;
76862+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
76863 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
76864 capable(CAP_IPC_LOCK))
76865 ret = do_mlockall(flags);
76866diff --git a/mm/mmap.c b/mm/mmap.c
76867index 4b80cbf..c5ce1df 100644
76868--- a/mm/mmap.c
76869+++ b/mm/mmap.c
76870@@ -45,6 +45,16 @@
76871 #define arch_rebalance_pgtables(addr, len) (addr)
76872 #endif
76873
76874+static inline void verify_mm_writelocked(struct mm_struct *mm)
76875+{
76876+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
76877+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76878+ up_read(&mm->mmap_sem);
76879+ BUG();
76880+ }
76881+#endif
76882+}
76883+
76884 static void unmap_region(struct mm_struct *mm,
76885 struct vm_area_struct *vma, struct vm_area_struct *prev,
76886 unsigned long start, unsigned long end);
76887@@ -70,22 +80,32 @@ static void unmap_region(struct mm_struct *mm,
76888 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
76889 *
76890 */
76891-pgprot_t protection_map[16] = {
76892+pgprot_t protection_map[16] __read_only = {
76893 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
76894 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
76895 };
76896
76897 pgprot_t vm_get_page_prot(unsigned long vm_flags)
76898 {
76899- return __pgprot(pgprot_val(protection_map[vm_flags &
76900+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
76901 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
76902 pgprot_val(arch_vm_get_page_prot(vm_flags)));
76903+
76904+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76905+ if (!nx_enabled &&
76906+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
76907+ (vm_flags & (VM_READ | VM_WRITE)))
76908+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
76909+#endif
76910+
76911+ return prot;
76912 }
76913 EXPORT_SYMBOL(vm_get_page_prot);
76914
76915 int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
76916 int sysctl_overcommit_ratio = 50; /* default is 50% */
76917 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
76918+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
76919 struct percpu_counter vm_committed_as;
76920
76921 /*
76922@@ -231,6 +251,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
76923 struct vm_area_struct *next = vma->vm_next;
76924
76925 might_sleep();
76926+ BUG_ON(vma->vm_mirror);
76927 if (vma->vm_ops && vma->vm_ops->close)
76928 vma->vm_ops->close(vma);
76929 if (vma->vm_file) {
76930@@ -267,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
76931 * not page aligned -Ram Gupta
76932 */
76933 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
76934+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
76935 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
76936 (mm->end_data - mm->start_data) > rlim)
76937 goto out;
76938@@ -704,6 +726,12 @@ static int
76939 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
76940 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76941 {
76942+
76943+#ifdef CONFIG_PAX_SEGMEXEC
76944+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
76945+ return 0;
76946+#endif
76947+
76948 if (is_mergeable_vma(vma, file, vm_flags) &&
76949 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
76950 if (vma->vm_pgoff == vm_pgoff)
76951@@ -723,6 +751,12 @@ static int
76952 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76953 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76954 {
76955+
76956+#ifdef CONFIG_PAX_SEGMEXEC
76957+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
76958+ return 0;
76959+#endif
76960+
76961 if (is_mergeable_vma(vma, file, vm_flags) &&
76962 is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
76963 pgoff_t vm_pglen;
76964@@ -765,12 +799,19 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76965 struct vm_area_struct *vma_merge(struct mm_struct *mm,
76966 struct vm_area_struct *prev, unsigned long addr,
76967 unsigned long end, unsigned long vm_flags,
76968- struct anon_vma *anon_vma, struct file *file,
76969+ struct anon_vma *anon_vma, struct file *file,
76970 pgoff_t pgoff, struct mempolicy *policy)
76971 {
76972 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
76973 struct vm_area_struct *area, *next;
76974
76975+#ifdef CONFIG_PAX_SEGMEXEC
76976+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
76977+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
76978+
76979+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
76980+#endif
76981+
76982 /*
76983 * We later require that vma->vm_flags == vm_flags,
76984 * so this tests vma->vm_flags & VM_SPECIAL, too.
76985@@ -786,6 +827,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76986 if (next && next->vm_end == end) /* cases 6, 7, 8 */
76987 next = next->vm_next;
76988
76989+#ifdef CONFIG_PAX_SEGMEXEC
76990+ if (prev)
76991+ prev_m = pax_find_mirror_vma(prev);
76992+ if (area)
76993+ area_m = pax_find_mirror_vma(area);
76994+ if (next)
76995+ next_m = pax_find_mirror_vma(next);
76996+#endif
76997+
76998 /*
76999 * Can it merge with the predecessor?
77000 */
77001@@ -805,9 +855,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
77002 /* cases 1, 6 */
77003 vma_adjust(prev, prev->vm_start,
77004 next->vm_end, prev->vm_pgoff, NULL);
77005- } else /* cases 2, 5, 7 */
77006+
77007+#ifdef CONFIG_PAX_SEGMEXEC
77008+ if (prev_m)
77009+ vma_adjust(prev_m, prev_m->vm_start,
77010+ next_m->vm_end, prev_m->vm_pgoff, NULL);
77011+#endif
77012+
77013+ } else { /* cases 2, 5, 7 */
77014 vma_adjust(prev, prev->vm_start,
77015 end, prev->vm_pgoff, NULL);
77016+
77017+#ifdef CONFIG_PAX_SEGMEXEC
77018+ if (prev_m)
77019+ vma_adjust(prev_m, prev_m->vm_start,
77020+ end_m, prev_m->vm_pgoff, NULL);
77021+#endif
77022+
77023+ }
77024 return prev;
77025 }
77026
77027@@ -818,12 +883,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
77028 mpol_equal(policy, vma_policy(next)) &&
77029 can_vma_merge_before(next, vm_flags,
77030 anon_vma, file, pgoff+pglen)) {
77031- if (prev && addr < prev->vm_end) /* case 4 */
77032+ if (prev && addr < prev->vm_end) { /* case 4 */
77033 vma_adjust(prev, prev->vm_start,
77034 addr, prev->vm_pgoff, NULL);
77035- else /* cases 3, 8 */
77036+
77037+#ifdef CONFIG_PAX_SEGMEXEC
77038+ if (prev_m)
77039+ vma_adjust(prev_m, prev_m->vm_start,
77040+ addr_m, prev_m->vm_pgoff, NULL);
77041+#endif
77042+
77043+ } else { /* cases 3, 8 */
77044 vma_adjust(area, addr, next->vm_end,
77045 next->vm_pgoff - pglen, NULL);
77046+
77047+#ifdef CONFIG_PAX_SEGMEXEC
77048+ if (area_m)
77049+ vma_adjust(area_m, addr_m, next_m->vm_end,
77050+ next_m->vm_pgoff - pglen, NULL);
77051+#endif
77052+
77053+ }
77054 return area;
77055 }
77056
77057@@ -898,14 +978,11 @@ none:
77058 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
77059 struct file *file, long pages)
77060 {
77061- const unsigned long stack_flags
77062- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
77063-
77064 if (file) {
77065 mm->shared_vm += pages;
77066 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
77067 mm->exec_vm += pages;
77068- } else if (flags & stack_flags)
77069+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
77070 mm->stack_vm += pages;
77071 if (flags & (VM_RESERVED|VM_IO))
77072 mm->reserved_vm += pages;
77073@@ -932,7 +1009,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77074 * (the exception is when the underlying filesystem is noexec
77075 * mounted, in which case we dont add PROT_EXEC.)
77076 */
77077- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
77078+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
77079 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
77080 prot |= PROT_EXEC;
77081
77082@@ -958,7 +1035,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77083 /* Obtain the address to map to. we verify (or select) it and ensure
77084 * that it represents a valid section of the address space.
77085 */
77086- addr = get_unmapped_area(file, addr, len, pgoff, flags);
77087+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
77088 if (addr & ~PAGE_MASK)
77089 return addr;
77090
77091@@ -969,6 +1046,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77092 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
77093 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
77094
77095+#ifdef CONFIG_PAX_MPROTECT
77096+ if (mm->pax_flags & MF_PAX_MPROTECT) {
77097+#ifndef CONFIG_PAX_MPROTECT_COMPAT
77098+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
77099+ gr_log_rwxmmap(file);
77100+
77101+#ifdef CONFIG_PAX_EMUPLT
77102+ vm_flags &= ~VM_EXEC;
77103+#else
77104+ return -EPERM;
77105+#endif
77106+
77107+ }
77108+
77109+ if (!(vm_flags & VM_EXEC))
77110+ vm_flags &= ~VM_MAYEXEC;
77111+#else
77112+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77113+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77114+#endif
77115+ else
77116+ vm_flags &= ~VM_MAYWRITE;
77117+ }
77118+#endif
77119+
77120+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
77121+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
77122+ vm_flags &= ~VM_PAGEEXEC;
77123+#endif
77124+
77125 if (flags & MAP_LOCKED)
77126 if (!can_do_mlock())
77127 return -EPERM;
77128@@ -980,6 +1087,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77129 locked += mm->locked_vm;
77130 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
77131 lock_limit >>= PAGE_SHIFT;
77132+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
77133 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
77134 return -EAGAIN;
77135 }
77136@@ -1053,6 +1161,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
77137 if (error)
77138 return error;
77139
77140+ if (!gr_acl_handle_mmap(file, prot))
77141+ return -EACCES;
77142+
77143 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
77144 }
77145 EXPORT_SYMBOL(do_mmap_pgoff);
77146@@ -1065,10 +1176,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
77147 */
77148 int vma_wants_writenotify(struct vm_area_struct *vma)
77149 {
77150- unsigned int vm_flags = vma->vm_flags;
77151+ unsigned long vm_flags = vma->vm_flags;
77152
77153 /* If it was private or non-writable, the write bit is already clear */
77154- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
77155+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
77156 return 0;
77157
77158 /* The backer wishes to know when pages are first written to? */
77159@@ -1117,14 +1228,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
77160 unsigned long charged = 0;
77161 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
77162
77163+#ifdef CONFIG_PAX_SEGMEXEC
77164+ struct vm_area_struct *vma_m = NULL;
77165+#endif
77166+
77167+ /*
77168+ * mm->mmap_sem is required to protect against another thread
77169+ * changing the mappings in case we sleep.
77170+ */
77171+ verify_mm_writelocked(mm);
77172+
77173 /* Clear old maps */
77174 error = -ENOMEM;
77175-munmap_back:
77176 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77177 if (vma && vma->vm_start < addr + len) {
77178 if (do_munmap(mm, addr, len))
77179 return -ENOMEM;
77180- goto munmap_back;
77181+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77182+ BUG_ON(vma && vma->vm_start < addr + len);
77183 }
77184
77185 /* Check against address space limit. */
77186@@ -1173,6 +1294,16 @@ munmap_back:
77187 goto unacct_error;
77188 }
77189
77190+#ifdef CONFIG_PAX_SEGMEXEC
77191+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
77192+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77193+ if (!vma_m) {
77194+ error = -ENOMEM;
77195+ goto free_vma;
77196+ }
77197+ }
77198+#endif
77199+
77200 vma->vm_mm = mm;
77201 vma->vm_start = addr;
77202 vma->vm_end = addr + len;
77203@@ -1195,6 +1326,19 @@ munmap_back:
77204 error = file->f_op->mmap(file, vma);
77205 if (error)
77206 goto unmap_and_free_vma;
77207+
77208+#ifdef CONFIG_PAX_SEGMEXEC
77209+ if (vma_m && (vm_flags & VM_EXECUTABLE))
77210+ added_exe_file_vma(mm);
77211+#endif
77212+
77213+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
77214+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
77215+ vma->vm_flags |= VM_PAGEEXEC;
77216+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77217+ }
77218+#endif
77219+
77220 if (vm_flags & VM_EXECUTABLE)
77221 added_exe_file_vma(mm);
77222
77223@@ -1218,6 +1362,11 @@ munmap_back:
77224 vma_link(mm, vma, prev, rb_link, rb_parent);
77225 file = vma->vm_file;
77226
77227+#ifdef CONFIG_PAX_SEGMEXEC
77228+ if (vma_m)
77229+ pax_mirror_vma(vma_m, vma);
77230+#endif
77231+
77232 /* Once vma denies write, undo our temporary denial count */
77233 if (correct_wcount)
77234 atomic_inc(&inode->i_writecount);
77235@@ -1226,6 +1375,7 @@ out:
77236
77237 mm->total_vm += len >> PAGE_SHIFT;
77238 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
77239+ track_exec_limit(mm, addr, addr + len, vm_flags);
77240 if (vm_flags & VM_LOCKED) {
77241 /*
77242 * makes pages present; downgrades, drops, reacquires mmap_sem
77243@@ -1248,6 +1398,12 @@ unmap_and_free_vma:
77244 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
77245 charged = 0;
77246 free_vma:
77247+
77248+#ifdef CONFIG_PAX_SEGMEXEC
77249+ if (vma_m)
77250+ kmem_cache_free(vm_area_cachep, vma_m);
77251+#endif
77252+
77253 kmem_cache_free(vm_area_cachep, vma);
77254 unacct_error:
77255 if (charged)
77256@@ -1255,6 +1411,44 @@ unacct_error:
77257 return error;
77258 }
77259
77260+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
77261+{
77262+ if (!vma) {
77263+#ifdef CONFIG_STACK_GROWSUP
77264+ if (addr > sysctl_heap_stack_gap)
77265+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
77266+ else
77267+ vma = find_vma(current->mm, 0);
77268+ if (vma && (vma->vm_flags & VM_GROWSUP))
77269+ return false;
77270+#endif
77271+ return true;
77272+ }
77273+
77274+ if (addr + len > vma->vm_start)
77275+ return false;
77276+
77277+ if (vma->vm_flags & VM_GROWSDOWN)
77278+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
77279+#ifdef CONFIG_STACK_GROWSUP
77280+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
77281+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
77282+#endif
77283+
77284+ return true;
77285+}
77286+
77287+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
77288+{
77289+ if (vma->vm_start < len)
77290+ return -ENOMEM;
77291+ if (!(vma->vm_flags & VM_GROWSDOWN))
77292+ return vma->vm_start - len;
77293+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
77294+ return vma->vm_start - len - sysctl_heap_stack_gap;
77295+ return -ENOMEM;
77296+}
77297+
77298 /* Get an address range which is currently unmapped.
77299 * For shmat() with addr=0.
77300 *
77301@@ -1281,18 +1475,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
77302 if (flags & MAP_FIXED)
77303 return addr;
77304
77305+#ifdef CONFIG_PAX_RANDMMAP
77306+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
77307+#endif
77308+
77309 if (addr) {
77310 addr = PAGE_ALIGN(addr);
77311- vma = find_vma(mm, addr);
77312- if (TASK_SIZE - len >= addr &&
77313- (!vma || addr + len <= vma->vm_start))
77314- return addr;
77315+ if (TASK_SIZE - len >= addr) {
77316+ vma = find_vma(mm, addr);
77317+ if (check_heap_stack_gap(vma, addr, len))
77318+ return addr;
77319+ }
77320 }
77321 if (len > mm->cached_hole_size) {
77322- start_addr = addr = mm->free_area_cache;
77323+ start_addr = addr = mm->free_area_cache;
77324 } else {
77325- start_addr = addr = TASK_UNMAPPED_BASE;
77326- mm->cached_hole_size = 0;
77327+ start_addr = addr = mm->mmap_base;
77328+ mm->cached_hole_size = 0;
77329 }
77330
77331 full_search:
77332@@ -1303,34 +1502,40 @@ full_search:
77333 * Start a new search - just in case we missed
77334 * some holes.
77335 */
77336- if (start_addr != TASK_UNMAPPED_BASE) {
77337- addr = TASK_UNMAPPED_BASE;
77338- start_addr = addr;
77339+ if (start_addr != mm->mmap_base) {
77340+ start_addr = addr = mm->mmap_base;
77341 mm->cached_hole_size = 0;
77342 goto full_search;
77343 }
77344 return -ENOMEM;
77345 }
77346- if (!vma || addr + len <= vma->vm_start) {
77347- /*
77348- * Remember the place where we stopped the search:
77349- */
77350- mm->free_area_cache = addr + len;
77351- return addr;
77352- }
77353+ if (check_heap_stack_gap(vma, addr, len))
77354+ break;
77355 if (addr + mm->cached_hole_size < vma->vm_start)
77356 mm->cached_hole_size = vma->vm_start - addr;
77357 addr = vma->vm_end;
77358 }
77359+
77360+ /*
77361+ * Remember the place where we stopped the search:
77362+ */
77363+ mm->free_area_cache = addr + len;
77364+ return addr;
77365 }
77366 #endif
77367
77368 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
77369 {
77370+
77371+#ifdef CONFIG_PAX_SEGMEXEC
77372+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77373+ return;
77374+#endif
77375+
77376 /*
77377 * Is this a new hole at the lowest possible address?
77378 */
77379- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
77380+ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
77381 mm->free_area_cache = addr;
77382 mm->cached_hole_size = ~0UL;
77383 }
77384@@ -1348,7 +1553,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77385 {
77386 struct vm_area_struct *vma;
77387 struct mm_struct *mm = current->mm;
77388- unsigned long addr = addr0;
77389+ unsigned long base = mm->mmap_base, addr = addr0;
77390
77391 /* requested length too big for entire address space */
77392 if (len > TASK_SIZE)
77393@@ -1357,13 +1562,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77394 if (flags & MAP_FIXED)
77395 return addr;
77396
77397+#ifdef CONFIG_PAX_RANDMMAP
77398+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
77399+#endif
77400+
77401 /* requesting a specific address */
77402 if (addr) {
77403 addr = PAGE_ALIGN(addr);
77404- vma = find_vma(mm, addr);
77405- if (TASK_SIZE - len >= addr &&
77406- (!vma || addr + len <= vma->vm_start))
77407- return addr;
77408+ if (TASK_SIZE - len >= addr) {
77409+ vma = find_vma(mm, addr);
77410+ if (check_heap_stack_gap(vma, addr, len))
77411+ return addr;
77412+ }
77413 }
77414
77415 /* check if free_area_cache is useful for us */
77416@@ -1378,7 +1588,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77417 /* make sure it can fit in the remaining address space */
77418 if (addr > len) {
77419 vma = find_vma(mm, addr-len);
77420- if (!vma || addr <= vma->vm_start)
77421+ if (check_heap_stack_gap(vma, addr - len, len))
77422 /* remember the address as a hint for next time */
77423 return (mm->free_area_cache = addr-len);
77424 }
77425@@ -1395,7 +1605,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77426 * return with success:
77427 */
77428 vma = find_vma(mm, addr);
77429- if (!vma || addr+len <= vma->vm_start)
77430+ if (check_heap_stack_gap(vma, addr, len))
77431 /* remember the address as a hint for next time */
77432 return (mm->free_area_cache = addr);
77433
77434@@ -1404,8 +1614,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77435 mm->cached_hole_size = vma->vm_start - addr;
77436
77437 /* try just below the current vma->vm_start */
77438- addr = vma->vm_start-len;
77439- } while (len < vma->vm_start);
77440+ addr = skip_heap_stack_gap(vma, len);
77441+ } while (!IS_ERR_VALUE(addr));
77442
77443 bottomup:
77444 /*
77445@@ -1414,13 +1624,21 @@ bottomup:
77446 * can happen with large stack limits and large mmap()
77447 * allocations.
77448 */
77449+ mm->mmap_base = TASK_UNMAPPED_BASE;
77450+
77451+#ifdef CONFIG_PAX_RANDMMAP
77452+ if (mm->pax_flags & MF_PAX_RANDMMAP)
77453+ mm->mmap_base += mm->delta_mmap;
77454+#endif
77455+
77456+ mm->free_area_cache = mm->mmap_base;
77457 mm->cached_hole_size = ~0UL;
77458- mm->free_area_cache = TASK_UNMAPPED_BASE;
77459 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
77460 /*
77461 * Restore the topdown base:
77462 */
77463- mm->free_area_cache = mm->mmap_base;
77464+ mm->mmap_base = base;
77465+ mm->free_area_cache = base;
77466 mm->cached_hole_size = ~0UL;
77467
77468 return addr;
77469@@ -1429,6 +1647,12 @@ bottomup:
77470
77471 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77472 {
77473+
77474+#ifdef CONFIG_PAX_SEGMEXEC
77475+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77476+ return;
77477+#endif
77478+
77479 /*
77480 * Is this a new hole at the highest possible address?
77481 */
77482@@ -1436,8 +1660,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77483 mm->free_area_cache = addr;
77484
77485 /* dont allow allocations above current base */
77486- if (mm->free_area_cache > mm->mmap_base)
77487+ if (mm->free_area_cache > mm->mmap_base) {
77488 mm->free_area_cache = mm->mmap_base;
77489+ mm->cached_hole_size = ~0UL;
77490+ }
77491 }
77492
77493 unsigned long
77494@@ -1545,6 +1771,27 @@ out:
77495 return prev ? prev->vm_next : vma;
77496 }
77497
77498+#ifdef CONFIG_PAX_SEGMEXEC
77499+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
77500+{
77501+ struct vm_area_struct *vma_m;
77502+
77503+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
77504+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
77505+ BUG_ON(vma->vm_mirror);
77506+ return NULL;
77507+ }
77508+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
77509+ vma_m = vma->vm_mirror;
77510+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
77511+ BUG_ON(vma->vm_file != vma_m->vm_file);
77512+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
77513+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
77514+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
77515+ return vma_m;
77516+}
77517+#endif
77518+
77519 /*
77520 * Verify that the stack growth is acceptable and
77521 * update accounting. This is shared with both the
77522@@ -1561,6 +1808,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77523 return -ENOMEM;
77524
77525 /* Stack limit test */
77526+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
77527 if (size > rlim[RLIMIT_STACK].rlim_cur)
77528 return -ENOMEM;
77529
77530@@ -1570,6 +1818,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77531 unsigned long limit;
77532 locked = mm->locked_vm + grow;
77533 limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
77534+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
77535 if (locked > limit && !capable(CAP_IPC_LOCK))
77536 return -ENOMEM;
77537 }
77538@@ -1600,37 +1849,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77539 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
77540 * vma is the last one with address > vma->vm_end. Have to extend vma.
77541 */
77542+#ifndef CONFIG_IA64
77543+static
77544+#endif
77545 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77546 {
77547 int error;
77548+ bool locknext;
77549
77550 if (!(vma->vm_flags & VM_GROWSUP))
77551 return -EFAULT;
77552
77553+ /* Also guard against wrapping around to address 0. */
77554+ if (address < PAGE_ALIGN(address+1))
77555+ address = PAGE_ALIGN(address+1);
77556+ else
77557+ return -ENOMEM;
77558+
77559 /*
77560 * We must make sure the anon_vma is allocated
77561 * so that the anon_vma locking is not a noop.
77562 */
77563 if (unlikely(anon_vma_prepare(vma)))
77564 return -ENOMEM;
77565+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
77566+ if (locknext && anon_vma_prepare(vma->vm_next))
77567+ return -ENOMEM;
77568 anon_vma_lock(vma);
77569+ if (locknext)
77570+ anon_vma_lock(vma->vm_next);
77571
77572 /*
77573 * vma->vm_start/vm_end cannot change under us because the caller
77574 * is required to hold the mmap_sem in read mode. We need the
77575- * anon_vma lock to serialize against concurrent expand_stacks.
77576- * Also guard against wrapping around to address 0.
77577+ * anon_vma locks to serialize against concurrent expand_stacks
77578+ * and expand_upwards.
77579 */
77580- if (address < PAGE_ALIGN(address+4))
77581- address = PAGE_ALIGN(address+4);
77582- else {
77583- anon_vma_unlock(vma);
77584- return -ENOMEM;
77585- }
77586 error = 0;
77587
77588 /* Somebody else might have raced and expanded it already */
77589- if (address > vma->vm_end) {
77590+ 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)
77591+ error = -ENOMEM;
77592+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
77593 unsigned long size, grow;
77594
77595 size = address - vma->vm_start;
77596@@ -1643,6 +1903,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77597 vma->vm_end = address;
77598 }
77599 }
77600+ if (locknext)
77601+ anon_vma_unlock(vma->vm_next);
77602 anon_vma_unlock(vma);
77603 return error;
77604 }
77605@@ -1655,6 +1917,8 @@ static int expand_downwards(struct vm_area_struct *vma,
77606 unsigned long address)
77607 {
77608 int error;
77609+ bool lockprev = false;
77610+ struct vm_area_struct *prev;
77611
77612 /*
77613 * We must make sure the anon_vma is allocated
77614@@ -1668,6 +1932,15 @@ static int expand_downwards(struct vm_area_struct *vma,
77615 if (error)
77616 return error;
77617
77618+ prev = vma->vm_prev;
77619+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
77620+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
77621+#endif
77622+ if (lockprev && anon_vma_prepare(prev))
77623+ return -ENOMEM;
77624+ if (lockprev)
77625+ anon_vma_lock(prev);
77626+
77627 anon_vma_lock(vma);
77628
77629 /*
77630@@ -1677,9 +1950,17 @@ static int expand_downwards(struct vm_area_struct *vma,
77631 */
77632
77633 /* Somebody else might have raced and expanded it already */
77634- if (address < vma->vm_start) {
77635+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
77636+ error = -ENOMEM;
77637+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
77638 unsigned long size, grow;
77639
77640+#ifdef CONFIG_PAX_SEGMEXEC
77641+ struct vm_area_struct *vma_m;
77642+
77643+ vma_m = pax_find_mirror_vma(vma);
77644+#endif
77645+
77646 size = vma->vm_end - address;
77647 grow = (vma->vm_start - address) >> PAGE_SHIFT;
77648
77649@@ -1689,10 +1970,22 @@ static int expand_downwards(struct vm_area_struct *vma,
77650 if (!error) {
77651 vma->vm_start = address;
77652 vma->vm_pgoff -= grow;
77653+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
77654+
77655+#ifdef CONFIG_PAX_SEGMEXEC
77656+ if (vma_m) {
77657+ vma_m->vm_start -= grow << PAGE_SHIFT;
77658+ vma_m->vm_pgoff -= grow;
77659+ }
77660+#endif
77661+
77662+
77663 }
77664 }
77665 }
77666 anon_vma_unlock(vma);
77667+ if (lockprev)
77668+ anon_vma_unlock(prev);
77669 return error;
77670 }
77671
77672@@ -1768,6 +2061,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
77673 do {
77674 long nrpages = vma_pages(vma);
77675
77676+#ifdef CONFIG_PAX_SEGMEXEC
77677+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
77678+ vma = remove_vma(vma);
77679+ continue;
77680+ }
77681+#endif
77682+
77683 mm->total_vm -= nrpages;
77684 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77685 vma = remove_vma(vma);
77686@@ -1813,6 +2113,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77687 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77688 vma->vm_prev = NULL;
77689 do {
77690+
77691+#ifdef CONFIG_PAX_SEGMEXEC
77692+ if (vma->vm_mirror) {
77693+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77694+ vma->vm_mirror->vm_mirror = NULL;
77695+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
77696+ vma->vm_mirror = NULL;
77697+ }
77698+#endif
77699+
77700 rb_erase(&vma->vm_rb, &mm->mm_rb);
77701 mm->map_count--;
77702 tail_vma = vma;
77703@@ -1840,10 +2150,25 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77704 struct mempolicy *pol;
77705 struct vm_area_struct *new;
77706
77707+#ifdef CONFIG_PAX_SEGMEXEC
77708+ struct vm_area_struct *vma_m, *new_m = NULL;
77709+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77710+#endif
77711+
77712 if (is_vm_hugetlb_page(vma) && (addr &
77713 ~(huge_page_mask(hstate_vma(vma)))))
77714 return -EINVAL;
77715
77716+#ifdef CONFIG_PAX_SEGMEXEC
77717+ vma_m = pax_find_mirror_vma(vma);
77718+
77719+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77720+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77721+ if (mm->map_count >= sysctl_max_map_count-1)
77722+ return -ENOMEM;
77723+ } else
77724+#endif
77725+
77726 if (mm->map_count >= sysctl_max_map_count)
77727 return -ENOMEM;
77728
77729@@ -1851,6 +2176,16 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77730 if (!new)
77731 return -ENOMEM;
77732
77733+#ifdef CONFIG_PAX_SEGMEXEC
77734+ if (vma_m) {
77735+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77736+ if (!new_m) {
77737+ kmem_cache_free(vm_area_cachep, new);
77738+ return -ENOMEM;
77739+ }
77740+ }
77741+#endif
77742+
77743 /* most fields are the same, copy all, and then fixup */
77744 *new = *vma;
77745
77746@@ -1861,8 +2196,29 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77747 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77748 }
77749
77750+#ifdef CONFIG_PAX_SEGMEXEC
77751+ if (vma_m) {
77752+ *new_m = *vma_m;
77753+ new_m->vm_mirror = new;
77754+ new->vm_mirror = new_m;
77755+
77756+ if (new_below)
77757+ new_m->vm_end = addr_m;
77758+ else {
77759+ new_m->vm_start = addr_m;
77760+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77761+ }
77762+ }
77763+#endif
77764+
77765 pol = mpol_dup(vma_policy(vma));
77766 if (IS_ERR(pol)) {
77767+
77768+#ifdef CONFIG_PAX_SEGMEXEC
77769+ if (new_m)
77770+ kmem_cache_free(vm_area_cachep, new_m);
77771+#endif
77772+
77773 kmem_cache_free(vm_area_cachep, new);
77774 return PTR_ERR(pol);
77775 }
77776@@ -1883,6 +2239,28 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77777 else
77778 vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77779
77780+#ifdef CONFIG_PAX_SEGMEXEC
77781+ if (vma_m) {
77782+ mpol_get(pol);
77783+ vma_set_policy(new_m, pol);
77784+
77785+ if (new_m->vm_file) {
77786+ get_file(new_m->vm_file);
77787+ if (vma_m->vm_flags & VM_EXECUTABLE)
77788+ added_exe_file_vma(mm);
77789+ }
77790+
77791+ if (new_m->vm_ops && new_m->vm_ops->open)
77792+ new_m->vm_ops->open(new_m);
77793+
77794+ if (new_below)
77795+ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77796+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77797+ else
77798+ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77799+ }
77800+#endif
77801+
77802 return 0;
77803 }
77804
77805@@ -1891,11 +2269,30 @@ int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77806 * work. This now handles partial unmappings.
77807 * Jeremy Fitzhardinge <jeremy@goop.org>
77808 */
77809+#ifdef CONFIG_PAX_SEGMEXEC
77810 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77811 {
77812+ int ret = __do_munmap(mm, start, len);
77813+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
77814+ return ret;
77815+
77816+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
77817+}
77818+
77819+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77820+#else
77821+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77822+#endif
77823+{
77824 unsigned long end;
77825 struct vm_area_struct *vma, *prev, *last;
77826
77827+ /*
77828+ * mm->mmap_sem is required to protect against another thread
77829+ * changing the mappings in case we sleep.
77830+ */
77831+ verify_mm_writelocked(mm);
77832+
77833 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
77834 return -EINVAL;
77835
77836@@ -1959,6 +2356,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77837 /* Fix up all other VM information */
77838 remove_vma_list(mm, vma);
77839
77840+ track_exec_limit(mm, start, end, 0UL);
77841+
77842 return 0;
77843 }
77844
77845@@ -1971,22 +2370,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
77846
77847 profile_munmap(addr);
77848
77849+#ifdef CONFIG_PAX_SEGMEXEC
77850+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
77851+ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
77852+ return -EINVAL;
77853+#endif
77854+
77855 down_write(&mm->mmap_sem);
77856 ret = do_munmap(mm, addr, len);
77857 up_write(&mm->mmap_sem);
77858 return ret;
77859 }
77860
77861-static inline void verify_mm_writelocked(struct mm_struct *mm)
77862-{
77863-#ifdef CONFIG_DEBUG_VM
77864- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77865- WARN_ON(1);
77866- up_read(&mm->mmap_sem);
77867- }
77868-#endif
77869-}
77870-
77871 /*
77872 * this is really a simplified "do_mmap". it only handles
77873 * anonymous maps. eventually we may be able to do some
77874@@ -2000,6 +2395,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77875 struct rb_node ** rb_link, * rb_parent;
77876 pgoff_t pgoff = addr >> PAGE_SHIFT;
77877 int error;
77878+ unsigned long charged;
77879
77880 len = PAGE_ALIGN(len);
77881 if (!len)
77882@@ -2011,16 +2407,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77883
77884 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
77885
77886+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
77887+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
77888+ flags &= ~VM_EXEC;
77889+
77890+#ifdef CONFIG_PAX_MPROTECT
77891+ if (mm->pax_flags & MF_PAX_MPROTECT)
77892+ flags &= ~VM_MAYEXEC;
77893+#endif
77894+
77895+ }
77896+#endif
77897+
77898 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
77899 if (error & ~PAGE_MASK)
77900 return error;
77901
77902+ charged = len >> PAGE_SHIFT;
77903+
77904 /*
77905 * mlock MCL_FUTURE?
77906 */
77907 if (mm->def_flags & VM_LOCKED) {
77908 unsigned long locked, lock_limit;
77909- locked = len >> PAGE_SHIFT;
77910+ locked = charged;
77911 locked += mm->locked_vm;
77912 lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
77913 lock_limit >>= PAGE_SHIFT;
77914@@ -2037,22 +2447,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77915 /*
77916 * Clear old maps. this also does some error checking for us
77917 */
77918- munmap_back:
77919 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77920 if (vma && vma->vm_start < addr + len) {
77921 if (do_munmap(mm, addr, len))
77922 return -ENOMEM;
77923- goto munmap_back;
77924+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
77925+ BUG_ON(vma && vma->vm_start < addr + len);
77926 }
77927
77928 /* Check against address space limits *after* clearing old maps... */
77929- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
77930+ if (!may_expand_vm(mm, charged))
77931 return -ENOMEM;
77932
77933 if (mm->map_count > sysctl_max_map_count)
77934 return -ENOMEM;
77935
77936- if (security_vm_enough_memory(len >> PAGE_SHIFT))
77937+ if (security_vm_enough_memory(charged))
77938 return -ENOMEM;
77939
77940 /* Can we just expand an old private anonymous mapping? */
77941@@ -2066,7 +2476,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77942 */
77943 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77944 if (!vma) {
77945- vm_unacct_memory(len >> PAGE_SHIFT);
77946+ vm_unacct_memory(charged);
77947 return -ENOMEM;
77948 }
77949
77950@@ -2078,11 +2488,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
77951 vma->vm_page_prot = vm_get_page_prot(flags);
77952 vma_link(mm, vma, prev, rb_link, rb_parent);
77953 out:
77954- mm->total_vm += len >> PAGE_SHIFT;
77955+ mm->total_vm += charged;
77956 if (flags & VM_LOCKED) {
77957 if (!mlock_vma_pages_range(vma, addr, addr + len))
77958- mm->locked_vm += (len >> PAGE_SHIFT);
77959+ mm->locked_vm += charged;
77960 }
77961+ track_exec_limit(mm, addr, addr + len, flags);
77962 return addr;
77963 }
77964
77965@@ -2129,8 +2540,10 @@ void exit_mmap(struct mm_struct *mm)
77966 * Walk the list again, actually closing and freeing it,
77967 * with preemption enabled, without holding any MM locks.
77968 */
77969- while (vma)
77970+ while (vma) {
77971+ vma->vm_mirror = NULL;
77972 vma = remove_vma(vma);
77973+ }
77974
77975 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
77976 }
77977@@ -2144,6 +2557,10 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
77978 struct vm_area_struct * __vma, * prev;
77979 struct rb_node ** rb_link, * rb_parent;
77980
77981+#ifdef CONFIG_PAX_SEGMEXEC
77982+ struct vm_area_struct *vma_m = NULL;
77983+#endif
77984+
77985 /*
77986 * The vm_pgoff of a purely anonymous vma should be irrelevant
77987 * until its first write fault, when page's anon_vma and index
77988@@ -2166,7 +2583,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
77989 if ((vma->vm_flags & VM_ACCOUNT) &&
77990 security_vm_enough_memory_mm(mm, vma_pages(vma)))
77991 return -ENOMEM;
77992+
77993+#ifdef CONFIG_PAX_SEGMEXEC
77994+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
77995+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77996+ if (!vma_m)
77997+ return -ENOMEM;
77998+ }
77999+#endif
78000+
78001 vma_link(mm, vma, prev, rb_link, rb_parent);
78002+
78003+#ifdef CONFIG_PAX_SEGMEXEC
78004+ if (vma_m)
78005+ pax_mirror_vma(vma_m, vma);
78006+#endif
78007+
78008 return 0;
78009 }
78010
78011@@ -2184,6 +2616,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
78012 struct rb_node **rb_link, *rb_parent;
78013 struct mempolicy *pol;
78014
78015+ BUG_ON(vma->vm_mirror);
78016+
78017 /*
78018 * If anonymous vma has not yet been faulted, update new pgoff
78019 * to match new location, to increase its chance of merging.
78020@@ -2227,6 +2661,35 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
78021 return new_vma;
78022 }
78023
78024+#ifdef CONFIG_PAX_SEGMEXEC
78025+void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
78026+{
78027+ struct vm_area_struct *prev_m;
78028+ struct rb_node **rb_link_m, *rb_parent_m;
78029+ struct mempolicy *pol_m;
78030+
78031+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
78032+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
78033+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
78034+ *vma_m = *vma;
78035+ pol_m = vma_policy(vma_m);
78036+ mpol_get(pol_m);
78037+ vma_set_policy(vma_m, pol_m);
78038+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
78039+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
78040+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
78041+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
78042+ if (vma_m->vm_file)
78043+ get_file(vma_m->vm_file);
78044+ if (vma_m->vm_ops && vma_m->vm_ops->open)
78045+ vma_m->vm_ops->open(vma_m);
78046+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
78047+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
78048+ vma_m->vm_mirror = vma;
78049+ vma->vm_mirror = vma_m;
78050+}
78051+#endif
78052+
78053 /*
78054 * Return true if the calling process may expand its vm space by the passed
78055 * number of pages
78056@@ -2237,7 +2700,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
78057 unsigned long lim;
78058
78059 lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
78060-
78061+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
78062 if (cur + npages > lim)
78063 return 0;
78064 return 1;
78065@@ -2307,6 +2770,22 @@ int install_special_mapping(struct mm_struct *mm,
78066 vma->vm_start = addr;
78067 vma->vm_end = addr + len;
78068
78069+#ifdef CONFIG_PAX_MPROTECT
78070+ if (mm->pax_flags & MF_PAX_MPROTECT) {
78071+#ifndef CONFIG_PAX_MPROTECT_COMPAT
78072+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
78073+ return -EPERM;
78074+ if (!(vm_flags & VM_EXEC))
78075+ vm_flags &= ~VM_MAYEXEC;
78076+#else
78077+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
78078+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
78079+#endif
78080+ else
78081+ vm_flags &= ~VM_MAYWRITE;
78082+ }
78083+#endif
78084+
78085 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
78086 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
78087
78088diff --git a/mm/mprotect.c b/mm/mprotect.c
78089index 1737c7e..c7faeb4 100644
78090--- a/mm/mprotect.c
78091+++ b/mm/mprotect.c
78092@@ -24,10 +24,16 @@
78093 #include <linux/mmu_notifier.h>
78094 #include <linux/migrate.h>
78095 #include <linux/perf_event.h>
78096+
78097+#ifdef CONFIG_PAX_MPROTECT
78098+#include <linux/elf.h>
78099+#endif
78100+
78101 #include <asm/uaccess.h>
78102 #include <asm/pgtable.h>
78103 #include <asm/cacheflush.h>
78104 #include <asm/tlbflush.h>
78105+#include <asm/mmu_context.h>
78106
78107 #ifndef pgprot_modify
78108 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
78109@@ -132,6 +138,48 @@ static void change_protection(struct vm_area_struct *vma,
78110 flush_tlb_range(vma, start, end);
78111 }
78112
78113+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
78114+/* called while holding the mmap semaphor for writing except stack expansion */
78115+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
78116+{
78117+ unsigned long oldlimit, newlimit = 0UL;
78118+
78119+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
78120+ return;
78121+
78122+ spin_lock(&mm->page_table_lock);
78123+ oldlimit = mm->context.user_cs_limit;
78124+ if ((prot & VM_EXEC) && oldlimit < end)
78125+ /* USER_CS limit moved up */
78126+ newlimit = end;
78127+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
78128+ /* USER_CS limit moved down */
78129+ newlimit = start;
78130+
78131+ if (newlimit) {
78132+ mm->context.user_cs_limit = newlimit;
78133+
78134+#ifdef CONFIG_SMP
78135+ wmb();
78136+ cpus_clear(mm->context.cpu_user_cs_mask);
78137+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
78138+#endif
78139+
78140+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
78141+ }
78142+ spin_unlock(&mm->page_table_lock);
78143+ if (newlimit == end) {
78144+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
78145+
78146+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
78147+ if (is_vm_hugetlb_page(vma))
78148+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
78149+ else
78150+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
78151+ }
78152+}
78153+#endif
78154+
78155 int
78156 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
78157 unsigned long start, unsigned long end, unsigned long newflags)
78158@@ -144,11 +192,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
78159 int error;
78160 int dirty_accountable = 0;
78161
78162+#ifdef CONFIG_PAX_SEGMEXEC
78163+ struct vm_area_struct *vma_m = NULL;
78164+ unsigned long start_m, end_m;
78165+
78166+ start_m = start + SEGMEXEC_TASK_SIZE;
78167+ end_m = end + SEGMEXEC_TASK_SIZE;
78168+#endif
78169+
78170 if (newflags == oldflags) {
78171 *pprev = vma;
78172 return 0;
78173 }
78174
78175+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
78176+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
78177+
78178+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
78179+ return -ENOMEM;
78180+
78181+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
78182+ return -ENOMEM;
78183+ }
78184+
78185 /*
78186 * If we make a private mapping writable we increase our commit;
78187 * but (without finer accounting) cannot reduce our commit if we
78188@@ -165,6 +231,38 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
78189 }
78190 }
78191
78192+#ifdef CONFIG_PAX_SEGMEXEC
78193+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
78194+ if (start != vma->vm_start) {
78195+ error = split_vma(mm, vma, start, 1);
78196+ if (error)
78197+ goto fail;
78198+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
78199+ *pprev = (*pprev)->vm_next;
78200+ }
78201+
78202+ if (end != vma->vm_end) {
78203+ error = split_vma(mm, vma, end, 0);
78204+ if (error)
78205+ goto fail;
78206+ }
78207+
78208+ if (pax_find_mirror_vma(vma)) {
78209+ error = __do_munmap(mm, start_m, end_m - start_m);
78210+ if (error)
78211+ goto fail;
78212+ } else {
78213+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
78214+ if (!vma_m) {
78215+ error = -ENOMEM;
78216+ goto fail;
78217+ }
78218+ vma->vm_flags = newflags;
78219+ pax_mirror_vma(vma_m, vma);
78220+ }
78221+ }
78222+#endif
78223+
78224 /*
78225 * First try to merge with previous and/or next vma.
78226 */
78227@@ -195,9 +293,21 @@ success:
78228 * vm_flags and vm_page_prot are protected by the mmap_sem
78229 * held in write mode.
78230 */
78231+
78232+#ifdef CONFIG_PAX_SEGMEXEC
78233+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
78234+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
78235+#endif
78236+
78237 vma->vm_flags = newflags;
78238+
78239+#ifdef CONFIG_PAX_MPROTECT
78240+ if (mm->binfmt && mm->binfmt->handle_mprotect)
78241+ mm->binfmt->handle_mprotect(vma, newflags);
78242+#endif
78243+
78244 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
78245- vm_get_page_prot(newflags));
78246+ vm_get_page_prot(vma->vm_flags));
78247
78248 if (vma_wants_writenotify(vma)) {
78249 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
78250@@ -239,6 +349,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78251 end = start + len;
78252 if (end <= start)
78253 return -ENOMEM;
78254+
78255+#ifdef CONFIG_PAX_SEGMEXEC
78256+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
78257+ if (end > SEGMEXEC_TASK_SIZE)
78258+ return -EINVAL;
78259+ } else
78260+#endif
78261+
78262+ if (end > TASK_SIZE)
78263+ return -EINVAL;
78264+
78265 if (!arch_validate_prot(prot))
78266 return -EINVAL;
78267
78268@@ -246,7 +367,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78269 /*
78270 * Does the application expect PROT_READ to imply PROT_EXEC:
78271 */
78272- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
78273+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
78274 prot |= PROT_EXEC;
78275
78276 vm_flags = calc_vm_prot_bits(prot);
78277@@ -278,6 +399,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78278 if (start > vma->vm_start)
78279 prev = vma;
78280
78281+#ifdef CONFIG_PAX_MPROTECT
78282+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
78283+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
78284+#endif
78285+
78286 for (nstart = start ; ; ) {
78287 unsigned long newflags;
78288
78289@@ -287,6 +413,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78290
78291 /* newflags >> 4 shift VM_MAY% in place of VM_% */
78292 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
78293+ if (prot & (PROT_WRITE | PROT_EXEC))
78294+ gr_log_rwxmprotect(vma->vm_file);
78295+
78296+ error = -EACCES;
78297+ goto out;
78298+ }
78299+
78300+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
78301 error = -EACCES;
78302 goto out;
78303 }
78304@@ -301,6 +435,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78305 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
78306 if (error)
78307 goto out;
78308+
78309+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
78310+
78311 nstart = tmp;
78312
78313 if (nstart < prev->vm_end)
78314diff --git a/mm/mremap.c b/mm/mremap.c
78315index 3e98d79..1706cec 100644
78316--- a/mm/mremap.c
78317+++ b/mm/mremap.c
78318@@ -112,6 +112,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
78319 continue;
78320 pte = ptep_clear_flush(vma, old_addr, old_pte);
78321 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
78322+
78323+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
78324+ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
78325+ pte = pte_exprotect(pte);
78326+#endif
78327+
78328 set_pte_at(mm, new_addr, new_pte, pte);
78329 }
78330
78331@@ -271,6 +277,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
78332 if (is_vm_hugetlb_page(vma))
78333 goto Einval;
78334
78335+#ifdef CONFIG_PAX_SEGMEXEC
78336+ if (pax_find_mirror_vma(vma))
78337+ goto Einval;
78338+#endif
78339+
78340 /* We can't remap across vm area boundaries */
78341 if (old_len > vma->vm_end - addr)
78342 goto Efault;
78343@@ -327,20 +338,25 @@ static unsigned long mremap_to(unsigned long addr,
78344 unsigned long ret = -EINVAL;
78345 unsigned long charged = 0;
78346 unsigned long map_flags;
78347+ unsigned long pax_task_size = TASK_SIZE;
78348
78349 if (new_addr & ~PAGE_MASK)
78350 goto out;
78351
78352- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
78353+#ifdef CONFIG_PAX_SEGMEXEC
78354+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
78355+ pax_task_size = SEGMEXEC_TASK_SIZE;
78356+#endif
78357+
78358+ pax_task_size -= PAGE_SIZE;
78359+
78360+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
78361 goto out;
78362
78363 /* Check if the location we're moving into overlaps the
78364 * old location at all, and fail if it does.
78365 */
78366- if ((new_addr <= addr) && (new_addr+new_len) > addr)
78367- goto out;
78368-
78369- if ((addr <= new_addr) && (addr+old_len) > new_addr)
78370+ if (addr + old_len > new_addr && new_addr + new_len > addr)
78371 goto out;
78372
78373 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
78374@@ -412,6 +428,7 @@ unsigned long do_mremap(unsigned long addr,
78375 struct vm_area_struct *vma;
78376 unsigned long ret = -EINVAL;
78377 unsigned long charged = 0;
78378+ unsigned long pax_task_size = TASK_SIZE;
78379
78380 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
78381 goto out;
78382@@ -430,6 +447,17 @@ unsigned long do_mremap(unsigned long addr,
78383 if (!new_len)
78384 goto out;
78385
78386+#ifdef CONFIG_PAX_SEGMEXEC
78387+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
78388+ pax_task_size = SEGMEXEC_TASK_SIZE;
78389+#endif
78390+
78391+ pax_task_size -= PAGE_SIZE;
78392+
78393+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
78394+ old_len > pax_task_size || addr > pax_task_size-old_len)
78395+ goto out;
78396+
78397 if (flags & MREMAP_FIXED) {
78398 if (flags & MREMAP_MAYMOVE)
78399 ret = mremap_to(addr, old_len, new_addr, new_len);
78400@@ -476,6 +504,7 @@ unsigned long do_mremap(unsigned long addr,
78401 addr + new_len);
78402 }
78403 ret = addr;
78404+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
78405 goto out;
78406 }
78407 }
78408@@ -502,7 +531,13 @@ unsigned long do_mremap(unsigned long addr,
78409 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
78410 if (ret)
78411 goto out;
78412+
78413+ map_flags = vma->vm_flags;
78414 ret = move_vma(vma, addr, old_len, new_len, new_addr);
78415+ if (!(ret & ~PAGE_MASK)) {
78416+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
78417+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
78418+ }
78419 }
78420 out:
78421 if (ret & ~PAGE_MASK)
78422diff --git a/mm/nommu.c b/mm/nommu.c
78423index 406e8d4..53970d3 100644
78424--- a/mm/nommu.c
78425+++ b/mm/nommu.c
78426@@ -67,7 +67,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
78427 int sysctl_overcommit_ratio = 50; /* default is 50% */
78428 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
78429 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
78430-int heap_stack_gap = 0;
78431
78432 atomic_long_t mmap_pages_allocated;
78433
78434@@ -761,15 +760,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
78435 EXPORT_SYMBOL(find_vma);
78436
78437 /*
78438- * find a VMA
78439- * - we don't extend stack VMAs under NOMMU conditions
78440- */
78441-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
78442-{
78443- return find_vma(mm, addr);
78444-}
78445-
78446-/*
78447 * expand a stack to a given address
78448 * - not supported under NOMMU conditions
78449 */
78450diff --git a/mm/page_alloc.c b/mm/page_alloc.c
78451index 3ecab7e..594a471 100644
78452--- a/mm/page_alloc.c
78453+++ b/mm/page_alloc.c
78454@@ -289,7 +289,7 @@ out:
78455 * This usage means that zero-order pages may not be compound.
78456 */
78457
78458-static void free_compound_page(struct page *page)
78459+void free_compound_page(struct page *page)
78460 {
78461 __free_pages_ok(page, compound_order(page));
78462 }
78463@@ -587,6 +587,10 @@ static void __free_pages_ok(struct page *page, unsigned int order)
78464 int bad = 0;
78465 int wasMlocked = __TestClearPageMlocked(page);
78466
78467+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78468+ unsigned long index = 1UL << order;
78469+#endif
78470+
78471 kmemcheck_free_shadow(page, order);
78472
78473 for (i = 0 ; i < (1 << order) ; ++i)
78474@@ -599,6 +603,12 @@ static void __free_pages_ok(struct page *page, unsigned int order)
78475 debug_check_no_obj_freed(page_address(page),
78476 PAGE_SIZE << order);
78477 }
78478+
78479+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78480+ for (; index; --index)
78481+ sanitize_highpage(page + index - 1);
78482+#endif
78483+
78484 arch_free_page(page, order);
78485 kernel_map_pages(page, 1 << order, 0);
78486
78487@@ -702,8 +712,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
78488 arch_alloc_page(page, order);
78489 kernel_map_pages(page, 1 << order, 1);
78490
78491+#ifndef CONFIG_PAX_MEMORY_SANITIZE
78492 if (gfp_flags & __GFP_ZERO)
78493 prep_zero_page(page, order, gfp_flags);
78494+#endif
78495
78496 if (order && (gfp_flags & __GFP_COMP))
78497 prep_compound_page(page, order);
78498@@ -1097,6 +1109,11 @@ static void free_hot_cold_page(struct page *page, int cold)
78499 debug_check_no_locks_freed(page_address(page), PAGE_SIZE);
78500 debug_check_no_obj_freed(page_address(page), PAGE_SIZE);
78501 }
78502+
78503+#ifdef CONFIG_PAX_MEMORY_SANITIZE
78504+ sanitize_highpage(page);
78505+#endif
78506+
78507 arch_free_page(page, 0);
78508 kernel_map_pages(page, 1, 0);
78509
78510@@ -2179,6 +2196,8 @@ void show_free_areas(void)
78511 int cpu;
78512 struct zone *zone;
78513
78514+ pax_track_stack();
78515+
78516 for_each_populated_zone(zone) {
78517 show_node(zone);
78518 printk("%s per-cpu:\n", zone->name);
78519@@ -3736,7 +3755,7 @@ static void __init setup_usemap(struct pglist_data *pgdat,
78520 zone->pageblock_flags = alloc_bootmem_node(pgdat, usemapsize);
78521 }
78522 #else
78523-static void inline setup_usemap(struct pglist_data *pgdat,
78524+static inline void setup_usemap(struct pglist_data *pgdat,
78525 struct zone *zone, unsigned long zonesize) {}
78526 #endif /* CONFIG_SPARSEMEM */
78527
78528diff --git a/mm/percpu.c b/mm/percpu.c
78529index c90614a..5f7b7b8 100644
78530--- a/mm/percpu.c
78531+++ b/mm/percpu.c
78532@@ -115,7 +115,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
78533 static unsigned int pcpu_high_unit_cpu __read_mostly;
78534
78535 /* the address of the first chunk which starts with the kernel static area */
78536-void *pcpu_base_addr __read_mostly;
78537+void *pcpu_base_addr __read_only;
78538 EXPORT_SYMBOL_GPL(pcpu_base_addr);
78539
78540 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
78541diff --git a/mm/rmap.c b/mm/rmap.c
78542index dd43373..d848cd7 100644
78543--- a/mm/rmap.c
78544+++ b/mm/rmap.c
78545@@ -121,6 +121,17 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78546 /* page_table_lock to protect against threads */
78547 spin_lock(&mm->page_table_lock);
78548 if (likely(!vma->anon_vma)) {
78549+
78550+#ifdef CONFIG_PAX_SEGMEXEC
78551+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
78552+
78553+ if (vma_m) {
78554+ BUG_ON(vma_m->anon_vma);
78555+ vma_m->anon_vma = anon_vma;
78556+ list_add_tail(&vma_m->anon_vma_node, &anon_vma->head);
78557+ }
78558+#endif
78559+
78560 vma->anon_vma = anon_vma;
78561 list_add_tail(&vma->anon_vma_node, &anon_vma->head);
78562 allocated = NULL;
78563diff --git a/mm/shmem.c b/mm/shmem.c
78564index 3e0005b..1d659a8 100644
78565--- a/mm/shmem.c
78566+++ b/mm/shmem.c
78567@@ -31,7 +31,7 @@
78568 #include <linux/swap.h>
78569 #include <linux/ima.h>
78570
78571-static struct vfsmount *shm_mnt;
78572+struct vfsmount *shm_mnt;
78573
78574 #ifdef CONFIG_SHMEM
78575 /*
78576@@ -1061,6 +1061,8 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
78577 goto unlock;
78578 }
78579 entry = shmem_swp_entry(info, index, NULL);
78580+ if (!entry)
78581+ goto unlock;
78582 if (entry->val) {
78583 /*
78584 * The more uptodate page coming down from a stacked
78585@@ -1144,6 +1146,8 @@ static struct page *shmem_swapin(swp_entry_t entry, gfp_t gfp,
78586 struct vm_area_struct pvma;
78587 struct page *page;
78588
78589+ pax_track_stack();
78590+
78591 spol = mpol_cond_copy(&mpol,
78592 mpol_shared_policy_lookup(&info->policy, idx));
78593
78594@@ -1962,7 +1966,7 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s
78595
78596 info = SHMEM_I(inode);
78597 inode->i_size = len-1;
78598- if (len <= (char *)inode - (char *)info) {
78599+ if (len <= (char *)inode - (char *)info && len <= 64) {
78600 /* do it inline */
78601 memcpy(info, symname, len);
78602 inode->i_op = &shmem_symlink_inline_operations;
78603@@ -2310,8 +2314,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78604 int err = -ENOMEM;
78605
78606 /* Round up to L1_CACHE_BYTES to resist false sharing */
78607- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78608- L1_CACHE_BYTES), GFP_KERNEL);
78609+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78610 if (!sbinfo)
78611 return -ENOMEM;
78612
78613diff --git a/mm/slab.c b/mm/slab.c
78614index c8d466a..909e01e 100644
78615--- a/mm/slab.c
78616+++ b/mm/slab.c
78617@@ -174,7 +174,7 @@
78618
78619 /* Legal flag mask for kmem_cache_create(). */
78620 #if DEBUG
78621-# define CREATE_MASK (SLAB_RED_ZONE | \
78622+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
78623 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
78624 SLAB_CACHE_DMA | \
78625 SLAB_STORE_USER | \
78626@@ -182,7 +182,7 @@
78627 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
78628 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
78629 #else
78630-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
78631+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
78632 SLAB_CACHE_DMA | \
78633 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
78634 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
78635@@ -308,7 +308,7 @@ struct kmem_list3 {
78636 * Need this for bootstrapping a per node allocator.
78637 */
78638 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78639-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78640+struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78641 #define CACHE_CACHE 0
78642 #define SIZE_AC MAX_NUMNODES
78643 #define SIZE_L3 (2 * MAX_NUMNODES)
78644@@ -409,10 +409,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78645 if ((x)->max_freeable < i) \
78646 (x)->max_freeable = i; \
78647 } while (0)
78648-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78649-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78650-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78651-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78652+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78653+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78654+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78655+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78656 #else
78657 #define STATS_INC_ACTIVE(x) do { } while (0)
78658 #define STATS_DEC_ACTIVE(x) do { } while (0)
78659@@ -558,7 +558,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78660 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78661 */
78662 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78663- const struct slab *slab, void *obj)
78664+ const struct slab *slab, const void *obj)
78665 {
78666 u32 offset = (obj - slab->s_mem);
78667 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78668@@ -1453,7 +1453,7 @@ void __init kmem_cache_init(void)
78669 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
78670 sizes[INDEX_AC].cs_size,
78671 ARCH_KMALLOC_MINALIGN,
78672- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78673+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78674 NULL);
78675
78676 if (INDEX_AC != INDEX_L3) {
78677@@ -1461,7 +1461,7 @@ void __init kmem_cache_init(void)
78678 kmem_cache_create(names[INDEX_L3].name,
78679 sizes[INDEX_L3].cs_size,
78680 ARCH_KMALLOC_MINALIGN,
78681- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78682+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78683 NULL);
78684 }
78685
78686@@ -1479,7 +1479,7 @@ void __init kmem_cache_init(void)
78687 sizes->cs_cachep = kmem_cache_create(names->name,
78688 sizes->cs_size,
78689 ARCH_KMALLOC_MINALIGN,
78690- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
78691+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
78692 NULL);
78693 }
78694 #ifdef CONFIG_ZONE_DMA
78695@@ -4211,10 +4211,10 @@ static int s_show(struct seq_file *m, void *p)
78696 }
78697 /* cpu stats */
78698 {
78699- unsigned long allochit = atomic_read(&cachep->allochit);
78700- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78701- unsigned long freehit = atomic_read(&cachep->freehit);
78702- unsigned long freemiss = atomic_read(&cachep->freemiss);
78703+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78704+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78705+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78706+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78707
78708 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78709 allochit, allocmiss, freehit, freemiss);
78710@@ -4471,15 +4471,70 @@ static const struct file_operations proc_slabstats_operations = {
78711
78712 static int __init slab_proc_init(void)
78713 {
78714- proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
78715+ mode_t gr_mode = S_IRUGO;
78716+
78717+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78718+ gr_mode = S_IRUSR;
78719+#endif
78720+
78721+ proc_create("slabinfo",S_IWUSR|gr_mode,NULL,&proc_slabinfo_operations);
78722 #ifdef CONFIG_DEBUG_SLAB_LEAK
78723- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78724+ proc_create("slab_allocators", gr_mode, NULL, &proc_slabstats_operations);
78725 #endif
78726 return 0;
78727 }
78728 module_init(slab_proc_init);
78729 #endif
78730
78731+void check_object_size(const void *ptr, unsigned long n, bool to)
78732+{
78733+
78734+#ifdef CONFIG_PAX_USERCOPY
78735+ struct page *page;
78736+ struct kmem_cache *cachep = NULL;
78737+ struct slab *slabp;
78738+ unsigned int objnr;
78739+ unsigned long offset;
78740+ const char *type;
78741+
78742+ if (!n)
78743+ return;
78744+
78745+ type = "<null>";
78746+ if (ZERO_OR_NULL_PTR(ptr))
78747+ goto report;
78748+
78749+ if (!virt_addr_valid(ptr))
78750+ return;
78751+
78752+ page = virt_to_head_page(ptr);
78753+
78754+ type = "<process stack>";
78755+ if (!PageSlab(page)) {
78756+ if (object_is_on_stack(ptr, n) == -1)
78757+ goto report;
78758+ return;
78759+ }
78760+
78761+ cachep = page_get_cache(page);
78762+ type = cachep->name;
78763+ if (!(cachep->flags & SLAB_USERCOPY))
78764+ goto report;
78765+
78766+ slabp = page_get_slab(page);
78767+ objnr = obj_to_index(cachep, slabp, ptr);
78768+ BUG_ON(objnr >= cachep->num);
78769+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78770+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
78771+ return;
78772+
78773+report:
78774+ pax_report_usercopy(ptr, n, to, type);
78775+#endif
78776+
78777+}
78778+EXPORT_SYMBOL(check_object_size);
78779+
78780 /**
78781 * ksize - get the actual amount of memory allocated for a given object
78782 * @objp: Pointer to the object
78783diff --git a/mm/slob.c b/mm/slob.c
78784index 837ebd6..4712174 100644
78785--- a/mm/slob.c
78786+++ b/mm/slob.c
78787@@ -29,7 +29,7 @@
78788 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
78789 * alloc_pages() directly, allocating compound pages so the page order
78790 * does not have to be separately tracked, and also stores the exact
78791- * allocation size in page->private so that it can be used to accurately
78792+ * allocation size in slob_page->size so that it can be used to accurately
78793 * provide ksize(). These objects are detected in kfree() because slob_page()
78794 * is false for them.
78795 *
78796@@ -58,6 +58,7 @@
78797 */
78798
78799 #include <linux/kernel.h>
78800+#include <linux/sched.h>
78801 #include <linux/slab.h>
78802 #include <linux/mm.h>
78803 #include <linux/swap.h> /* struct reclaim_state */
78804@@ -100,7 +101,8 @@ struct slob_page {
78805 unsigned long flags; /* mandatory */
78806 atomic_t _count; /* mandatory */
78807 slobidx_t units; /* free units left in page */
78808- unsigned long pad[2];
78809+ unsigned long pad[1];
78810+ unsigned long size; /* size when >=PAGE_SIZE */
78811 slob_t *free; /* first free slob_t in page */
78812 struct list_head list; /* linked list of free pages */
78813 };
78814@@ -133,7 +135,7 @@ static LIST_HEAD(free_slob_large);
78815 */
78816 static inline int is_slob_page(struct slob_page *sp)
78817 {
78818- return PageSlab((struct page *)sp);
78819+ return PageSlab((struct page *)sp) && !sp->size;
78820 }
78821
78822 static inline void set_slob_page(struct slob_page *sp)
78823@@ -148,7 +150,7 @@ static inline void clear_slob_page(struct slob_page *sp)
78824
78825 static inline struct slob_page *slob_page(const void *addr)
78826 {
78827- return (struct slob_page *)virt_to_page(addr);
78828+ return (struct slob_page *)virt_to_head_page(addr);
78829 }
78830
78831 /*
78832@@ -208,7 +210,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
78833 /*
78834 * Return the size of a slob block.
78835 */
78836-static slobidx_t slob_units(slob_t *s)
78837+static slobidx_t slob_units(const slob_t *s)
78838 {
78839 if (s->units > 0)
78840 return s->units;
78841@@ -218,7 +220,7 @@ static slobidx_t slob_units(slob_t *s)
78842 /*
78843 * Return the next free slob block pointer after this one.
78844 */
78845-static slob_t *slob_next(slob_t *s)
78846+static slob_t *slob_next(const slob_t *s)
78847 {
78848 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
78849 slobidx_t next;
78850@@ -233,7 +235,7 @@ static slob_t *slob_next(slob_t *s)
78851 /*
78852 * Returns true if s is the last free block in its page.
78853 */
78854-static int slob_last(slob_t *s)
78855+static int slob_last(const slob_t *s)
78856 {
78857 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
78858 }
78859@@ -252,6 +254,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
78860 if (!page)
78861 return NULL;
78862
78863+ set_slob_page(page);
78864 return page_address(page);
78865 }
78866
78867@@ -368,11 +371,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
78868 if (!b)
78869 return NULL;
78870 sp = slob_page(b);
78871- set_slob_page(sp);
78872
78873 spin_lock_irqsave(&slob_lock, flags);
78874 sp->units = SLOB_UNITS(PAGE_SIZE);
78875 sp->free = b;
78876+ sp->size = 0;
78877 INIT_LIST_HEAD(&sp->list);
78878 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
78879 set_slob_page_free(sp, slob_list);
78880@@ -475,10 +478,9 @@ out:
78881 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long)
78882 #endif
78883
78884-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78885+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
78886 {
78887- unsigned int *m;
78888- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78889+ slob_t *m;
78890 void *ret;
78891
78892 lockdep_trace_alloc(gfp);
78893@@ -491,7 +493,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78894
78895 if (!m)
78896 return NULL;
78897- *m = size;
78898+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
78899+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
78900+ m[0].units = size;
78901+ m[1].units = align;
78902 ret = (void *)m + align;
78903
78904 trace_kmalloc_node(_RET_IP_, ret,
78905@@ -501,16 +506,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78906
78907 ret = slob_new_pages(gfp | __GFP_COMP, get_order(size), node);
78908 if (ret) {
78909- struct page *page;
78910- page = virt_to_page(ret);
78911- page->private = size;
78912+ struct slob_page *sp;
78913+ sp = slob_page(ret);
78914+ sp->size = size;
78915 }
78916
78917 trace_kmalloc_node(_RET_IP_, ret,
78918 size, PAGE_SIZE << order, gfp, node);
78919 }
78920
78921- kmemleak_alloc(ret, size, 1, gfp);
78922+ return ret;
78923+}
78924+
78925+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
78926+{
78927+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78928+ void *ret = __kmalloc_node_align(size, gfp, node, align);
78929+
78930+ if (!ZERO_OR_NULL_PTR(ret))
78931+ kmemleak_alloc(ret, size, 1, gfp);
78932 return ret;
78933 }
78934 EXPORT_SYMBOL(__kmalloc_node);
78935@@ -528,13 +542,92 @@ void kfree(const void *block)
78936 sp = slob_page(block);
78937 if (is_slob_page(sp)) {
78938 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78939- unsigned int *m = (unsigned int *)(block - align);
78940- slob_free(m, *m + align);
78941- } else
78942+ slob_t *m = (slob_t *)(block - align);
78943+ slob_free(m, m[0].units + align);
78944+ } else {
78945+ clear_slob_page(sp);
78946+ free_slob_page(sp);
78947+ sp->size = 0;
78948 put_page(&sp->page);
78949+ }
78950 }
78951 EXPORT_SYMBOL(kfree);
78952
78953+void check_object_size(const void *ptr, unsigned long n, bool to)
78954+{
78955+
78956+#ifdef CONFIG_PAX_USERCOPY
78957+ struct slob_page *sp;
78958+ const slob_t *free;
78959+ const void *base;
78960+ unsigned long flags;
78961+ const char *type;
78962+
78963+ if (!n)
78964+ return;
78965+
78966+ type = "<null>";
78967+ if (ZERO_OR_NULL_PTR(ptr))
78968+ goto report;
78969+
78970+ if (!virt_addr_valid(ptr))
78971+ return;
78972+
78973+ type = "<process stack>";
78974+ sp = slob_page(ptr);
78975+ if (!PageSlab((struct page*)sp)) {
78976+ if (object_is_on_stack(ptr, n) == -1)
78977+ goto report;
78978+ return;
78979+ }
78980+
78981+ type = "<slob>";
78982+ if (sp->size) {
78983+ base = page_address(&sp->page);
78984+ if (base <= ptr && n <= sp->size - (ptr - base))
78985+ return;
78986+ goto report;
78987+ }
78988+
78989+ /* some tricky double walking to find the chunk */
78990+ spin_lock_irqsave(&slob_lock, flags);
78991+ base = (void *)((unsigned long)ptr & PAGE_MASK);
78992+ free = sp->free;
78993+
78994+ while (!slob_last(free) && (void *)free <= ptr) {
78995+ base = free + slob_units(free);
78996+ free = slob_next(free);
78997+ }
78998+
78999+ while (base < (void *)free) {
79000+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
79001+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
79002+ int offset;
79003+
79004+ if (ptr < base + align)
79005+ break;
79006+
79007+ offset = ptr - base - align;
79008+ if (offset >= m) {
79009+ base += size;
79010+ continue;
79011+ }
79012+
79013+ if (n > m - offset)
79014+ break;
79015+
79016+ spin_unlock_irqrestore(&slob_lock, flags);
79017+ return;
79018+ }
79019+
79020+ spin_unlock_irqrestore(&slob_lock, flags);
79021+report:
79022+ pax_report_usercopy(ptr, n, to, type);
79023+#endif
79024+
79025+}
79026+EXPORT_SYMBOL(check_object_size);
79027+
79028 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
79029 size_t ksize(const void *block)
79030 {
79031@@ -547,10 +640,10 @@ size_t ksize(const void *block)
79032 sp = slob_page(block);
79033 if (is_slob_page(sp)) {
79034 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
79035- unsigned int *m = (unsigned int *)(block - align);
79036- return SLOB_UNITS(*m) * SLOB_UNIT;
79037+ slob_t *m = (slob_t *)(block - align);
79038+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
79039 } else
79040- return sp->page.private;
79041+ return sp->size;
79042 }
79043 EXPORT_SYMBOL(ksize);
79044
79045@@ -566,8 +659,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
79046 {
79047 struct kmem_cache *c;
79048
79049+#ifdef CONFIG_PAX_USERCOPY
79050+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
79051+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
79052+#else
79053 c = slob_alloc(sizeof(struct kmem_cache),
79054 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
79055+#endif
79056
79057 if (c) {
79058 c->name = name;
79059@@ -605,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
79060 {
79061 void *b;
79062
79063+#ifdef CONFIG_PAX_USERCOPY
79064+ b = __kmalloc_node_align(c->size, flags, node, c->align);
79065+#else
79066 if (c->size < PAGE_SIZE) {
79067 b = slob_alloc(c->size, flags, c->align, node);
79068 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
79069 SLOB_UNITS(c->size) * SLOB_UNIT,
79070 flags, node);
79071 } else {
79072+ struct slob_page *sp;
79073+
79074 b = slob_new_pages(flags, get_order(c->size), node);
79075+ sp = slob_page(b);
79076+ sp->size = c->size;
79077 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
79078 PAGE_SIZE << get_order(c->size),
79079 flags, node);
79080 }
79081+#endif
79082
79083 if (c->ctor)
79084 c->ctor(b);
79085@@ -627,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
79086
79087 static void __kmem_cache_free(void *b, int size)
79088 {
79089- if (size < PAGE_SIZE)
79090+ struct slob_page *sp = slob_page(b);
79091+
79092+ if (is_slob_page(sp))
79093 slob_free(b, size);
79094- else
79095+ else {
79096+ clear_slob_page(sp);
79097+ free_slob_page(sp);
79098+ sp->size = 0;
79099 slob_free_pages(b, get_order(size));
79100+ }
79101 }
79102
79103 static void kmem_rcu_free(struct rcu_head *head)
79104@@ -643,18 +755,32 @@ static void kmem_rcu_free(struct rcu_head *head)
79105
79106 void kmem_cache_free(struct kmem_cache *c, void *b)
79107 {
79108+ int size = c->size;
79109+
79110+#ifdef CONFIG_PAX_USERCOPY
79111+ if (size + c->align < PAGE_SIZE) {
79112+ size += c->align;
79113+ b -= c->align;
79114+ }
79115+#endif
79116+
79117 kmemleak_free_recursive(b, c->flags);
79118 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
79119 struct slob_rcu *slob_rcu;
79120- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
79121+ slob_rcu = b + (size - sizeof(struct slob_rcu));
79122 INIT_RCU_HEAD(&slob_rcu->head);
79123- slob_rcu->size = c->size;
79124+ slob_rcu->size = size;
79125 call_rcu(&slob_rcu->head, kmem_rcu_free);
79126 } else {
79127- __kmem_cache_free(b, c->size);
79128+ __kmem_cache_free(b, size);
79129 }
79130
79131+#ifdef CONFIG_PAX_USERCOPY
79132+ trace_kfree(_RET_IP_, b);
79133+#else
79134 trace_kmem_cache_free(_RET_IP_, b);
79135+#endif
79136+
79137 }
79138 EXPORT_SYMBOL(kmem_cache_free);
79139
79140diff --git a/mm/slub.c b/mm/slub.c
79141index 4996fc7..87e01d0 100644
79142--- a/mm/slub.c
79143+++ b/mm/slub.c
79144@@ -201,7 +201,7 @@ struct track {
79145
79146 enum track_item { TRACK_ALLOC, TRACK_FREE };
79147
79148-#ifdef CONFIG_SLUB_DEBUG
79149+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79150 static int sysfs_slab_add(struct kmem_cache *);
79151 static int sysfs_slab_alias(struct kmem_cache *, const char *);
79152 static void sysfs_slab_remove(struct kmem_cache *);
79153@@ -410,7 +410,7 @@ static void print_track(const char *s, struct track *t)
79154 if (!t->addr)
79155 return;
79156
79157- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
79158+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
79159 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
79160 }
79161
79162@@ -1893,6 +1893,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
79163
79164 page = virt_to_head_page(x);
79165
79166+ BUG_ON(!PageSlab(page));
79167+
79168 slab_free(s, page, x, _RET_IP_);
79169
79170 trace_kmem_cache_free(_RET_IP_, x);
79171@@ -1937,7 +1939,7 @@ static int slub_min_objects;
79172 * Merge control. If this is set then no merging of slab caches will occur.
79173 * (Could be removed. This was introduced to pacify the merge skeptics.)
79174 */
79175-static int slub_nomerge;
79176+static int slub_nomerge = 1;
79177
79178 /*
79179 * Calculate the order of allocation given an slab object size.
79180@@ -2493,7 +2495,7 @@ static int kmem_cache_open(struct kmem_cache *s, gfp_t gfpflags,
79181 * list to avoid pounding the page allocator excessively.
79182 */
79183 set_min_partial(s, ilog2(s->size));
79184- s->refcount = 1;
79185+ atomic_set(&s->refcount, 1);
79186 #ifdef CONFIG_NUMA
79187 s->remote_node_defrag_ratio = 1000;
79188 #endif
79189@@ -2630,8 +2632,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
79190 void kmem_cache_destroy(struct kmem_cache *s)
79191 {
79192 down_write(&slub_lock);
79193- s->refcount--;
79194- if (!s->refcount) {
79195+ if (atomic_dec_and_test(&s->refcount)) {
79196 list_del(&s->list);
79197 up_write(&slub_lock);
79198 if (kmem_cache_close(s)) {
79199@@ -2691,12 +2692,10 @@ static int __init setup_slub_nomerge(char *str)
79200 __setup("slub_nomerge", setup_slub_nomerge);
79201
79202 static struct kmem_cache *create_kmalloc_cache(struct kmem_cache *s,
79203- const char *name, int size, gfp_t gfp_flags)
79204+ const char *name, int size, gfp_t gfp_flags, unsigned int flags)
79205 {
79206- unsigned int flags = 0;
79207-
79208 if (gfp_flags & SLUB_DMA)
79209- flags = SLAB_CACHE_DMA;
79210+ flags |= SLAB_CACHE_DMA;
79211
79212 /*
79213 * This function is called with IRQs disabled during early-boot on
79214@@ -2915,6 +2914,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
79215 EXPORT_SYMBOL(__kmalloc_node);
79216 #endif
79217
79218+void check_object_size(const void *ptr, unsigned long n, bool to)
79219+{
79220+
79221+#ifdef CONFIG_PAX_USERCOPY
79222+ struct page *page;
79223+ struct kmem_cache *s = NULL;
79224+ unsigned long offset;
79225+ const char *type;
79226+
79227+ if (!n)
79228+ return;
79229+
79230+ type = "<null>";
79231+ if (ZERO_OR_NULL_PTR(ptr))
79232+ goto report;
79233+
79234+ if (!virt_addr_valid(ptr))
79235+ return;
79236+
79237+ page = get_object_page(ptr);
79238+
79239+ type = "<process stack>";
79240+ if (!page) {
79241+ if (object_is_on_stack(ptr, n) == -1)
79242+ goto report;
79243+ return;
79244+ }
79245+
79246+ s = page->slab;
79247+ type = s->name;
79248+ if (!(s->flags & SLAB_USERCOPY))
79249+ goto report;
79250+
79251+ offset = (ptr - page_address(page)) % s->size;
79252+ if (offset <= s->objsize && n <= s->objsize - offset)
79253+ return;
79254+
79255+report:
79256+ pax_report_usercopy(ptr, n, to, type);
79257+#endif
79258+
79259+}
79260+EXPORT_SYMBOL(check_object_size);
79261+
79262 size_t ksize(const void *object)
79263 {
79264 struct page *page;
79265@@ -3185,8 +3228,8 @@ void __init kmem_cache_init(void)
79266 * kmem_cache_open for slab_state == DOWN.
79267 */
79268 create_kmalloc_cache(&kmalloc_caches[0], "kmem_cache_node",
79269- sizeof(struct kmem_cache_node), GFP_NOWAIT);
79270- kmalloc_caches[0].refcount = -1;
79271+ sizeof(struct kmem_cache_node), GFP_NOWAIT, 0);
79272+ atomic_set(&kmalloc_caches[0].refcount, -1);
79273 caches++;
79274
79275 hotplug_memory_notifier(slab_memory_callback, SLAB_CALLBACK_PRI);
79276@@ -3198,18 +3241,18 @@ void __init kmem_cache_init(void)
79277 /* Caches that are not of the two-to-the-power-of size */
79278 if (KMALLOC_MIN_SIZE <= 32) {
79279 create_kmalloc_cache(&kmalloc_caches[1],
79280- "kmalloc-96", 96, GFP_NOWAIT);
79281+ "kmalloc-96", 96, GFP_NOWAIT, SLAB_USERCOPY);
79282 caches++;
79283 }
79284 if (KMALLOC_MIN_SIZE <= 64) {
79285 create_kmalloc_cache(&kmalloc_caches[2],
79286- "kmalloc-192", 192, GFP_NOWAIT);
79287+ "kmalloc-192", 192, GFP_NOWAIT, SLAB_USERCOPY);
79288 caches++;
79289 }
79290
79291 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
79292 create_kmalloc_cache(&kmalloc_caches[i],
79293- "kmalloc", 1 << i, GFP_NOWAIT);
79294+ "kmalloc", 1 << i, GFP_NOWAIT, SLAB_USERCOPY);
79295 caches++;
79296 }
79297
79298@@ -3293,7 +3336,7 @@ static int slab_unmergeable(struct kmem_cache *s)
79299 /*
79300 * We may have set a slab to be unmergeable during bootstrap.
79301 */
79302- if (s->refcount < 0)
79303+ if (atomic_read(&s->refcount) < 0)
79304 return 1;
79305
79306 return 0;
79307@@ -3353,7 +3396,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
79308 if (s) {
79309 int cpu;
79310
79311- s->refcount++;
79312+ atomic_inc(&s->refcount);
79313 /*
79314 * Adjust the object sizes so that we clear
79315 * the complete object on kzalloc.
79316@@ -3372,7 +3415,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
79317
79318 if (sysfs_slab_alias(s, name)) {
79319 down_write(&slub_lock);
79320- s->refcount--;
79321+ atomic_dec(&s->refcount);
79322 up_write(&slub_lock);
79323 goto err;
79324 }
79325@@ -4101,7 +4144,7 @@ SLAB_ATTR_RO(ctor);
79326
79327 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
79328 {
79329- return sprintf(buf, "%d\n", s->refcount - 1);
79330+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
79331 }
79332 SLAB_ATTR_RO(aliases);
79333
79334@@ -4503,7 +4546,7 @@ static void kmem_cache_release(struct kobject *kobj)
79335 kfree(s);
79336 }
79337
79338-static struct sysfs_ops slab_sysfs_ops = {
79339+static const struct sysfs_ops slab_sysfs_ops = {
79340 .show = slab_attr_show,
79341 .store = slab_attr_store,
79342 };
79343@@ -4522,7 +4565,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
79344 return 0;
79345 }
79346
79347-static struct kset_uevent_ops slab_uevent_ops = {
79348+static const struct kset_uevent_ops slab_uevent_ops = {
79349 .filter = uevent_filter,
79350 };
79351
79352@@ -4564,6 +4607,7 @@ static char *create_unique_id(struct kmem_cache *s)
79353 return name;
79354 }
79355
79356+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79357 static int sysfs_slab_add(struct kmem_cache *s)
79358 {
79359 int err;
79360@@ -4619,6 +4663,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
79361 kobject_del(&s->kobj);
79362 kobject_put(&s->kobj);
79363 }
79364+#endif
79365
79366 /*
79367 * Need to buffer aliases during bootup until sysfs becomes
79368@@ -4632,6 +4677,7 @@ struct saved_alias {
79369
79370 static struct saved_alias *alias_list;
79371
79372+#if defined(CONFIG_SLUB_DEBUG) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79373 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79374 {
79375 struct saved_alias *al;
79376@@ -4654,6 +4700,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79377 alias_list = al;
79378 return 0;
79379 }
79380+#endif
79381
79382 static int __init slab_sysfs_init(void)
79383 {
79384@@ -4785,7 +4832,13 @@ static const struct file_operations proc_slabinfo_operations = {
79385
79386 static int __init slab_proc_init(void)
79387 {
79388- proc_create("slabinfo", S_IRUGO, NULL, &proc_slabinfo_operations);
79389+ mode_t gr_mode = S_IRUGO;
79390+
79391+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79392+ gr_mode = S_IRUSR;
79393+#endif
79394+
79395+ proc_create("slabinfo", gr_mode, NULL, &proc_slabinfo_operations);
79396 return 0;
79397 }
79398 module_init(slab_proc_init);
79399diff --git a/mm/swap.c b/mm/swap.c
79400index 308e57d..5de19c0 100644
79401--- a/mm/swap.c
79402+++ b/mm/swap.c
79403@@ -30,6 +30,7 @@
79404 #include <linux/notifier.h>
79405 #include <linux/backing-dev.h>
79406 #include <linux/memcontrol.h>
79407+#include <linux/hugetlb.h>
79408
79409 #include "internal.h"
79410
79411@@ -65,6 +66,8 @@ static void put_compound_page(struct page *page)
79412 compound_page_dtor *dtor;
79413
79414 dtor = get_compound_page_dtor(page);
79415+ if (!PageHuge(page))
79416+ BUG_ON(dtor != free_compound_page);
79417 (*dtor)(page);
79418 }
79419 }
79420diff --git a/mm/util.c b/mm/util.c
79421index e48b493..24a601d 100644
79422--- a/mm/util.c
79423+++ b/mm/util.c
79424@@ -228,6 +228,12 @@ EXPORT_SYMBOL(strndup_user);
79425 void arch_pick_mmap_layout(struct mm_struct *mm)
79426 {
79427 mm->mmap_base = TASK_UNMAPPED_BASE;
79428+
79429+#ifdef CONFIG_PAX_RANDMMAP
79430+ if (mm->pax_flags & MF_PAX_RANDMMAP)
79431+ mm->mmap_base += mm->delta_mmap;
79432+#endif
79433+
79434 mm->get_unmapped_area = arch_get_unmapped_area;
79435 mm->unmap_area = arch_unmap_area;
79436 }
79437diff --git a/mm/vmalloc.c b/mm/vmalloc.c
79438index f34ffd0..e60c44f 100644
79439--- a/mm/vmalloc.c
79440+++ b/mm/vmalloc.c
79441@@ -40,8 +40,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
79442
79443 pte = pte_offset_kernel(pmd, addr);
79444 do {
79445- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79446- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79447+
79448+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79449+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
79450+ BUG_ON(!pte_exec(*pte));
79451+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
79452+ continue;
79453+ }
79454+#endif
79455+
79456+ {
79457+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79458+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79459+ }
79460 } while (pte++, addr += PAGE_SIZE, addr != end);
79461 }
79462
79463@@ -92,6 +103,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79464 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
79465 {
79466 pte_t *pte;
79467+ int ret = -ENOMEM;
79468
79469 /*
79470 * nr is a running index into the array which helps higher level
79471@@ -101,17 +113,32 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79472 pte = pte_alloc_kernel(pmd, addr);
79473 if (!pte)
79474 return -ENOMEM;
79475+
79476+ pax_open_kernel();
79477 do {
79478 struct page *page = pages[*nr];
79479
79480- if (WARN_ON(!pte_none(*pte)))
79481- return -EBUSY;
79482- if (WARN_ON(!page))
79483- return -ENOMEM;
79484+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79485+ if (!(pgprot_val(prot) & _PAGE_NX))
79486+ BUG_ON(!pte_exec(*pte) || pte_pfn(*pte) != __pa(addr) >> PAGE_SHIFT);
79487+ else
79488+#endif
79489+
79490+ if (WARN_ON(!pte_none(*pte))) {
79491+ ret = -EBUSY;
79492+ goto out;
79493+ }
79494+ if (WARN_ON(!page)) {
79495+ ret = -ENOMEM;
79496+ goto out;
79497+ }
79498 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
79499 (*nr)++;
79500 } while (pte++, addr += PAGE_SIZE, addr != end);
79501- return 0;
79502+ ret = 0;
79503+out:
79504+ pax_close_kernel();
79505+ return ret;
79506 }
79507
79508 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
79509@@ -192,11 +219,20 @@ int is_vmalloc_or_module_addr(const void *x)
79510 * and fall back on vmalloc() if that fails. Others
79511 * just put it in the vmalloc space.
79512 */
79513-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
79514+#ifdef CONFIG_MODULES
79515+#ifdef MODULES_VADDR
79516 unsigned long addr = (unsigned long)x;
79517 if (addr >= MODULES_VADDR && addr < MODULES_END)
79518 return 1;
79519 #endif
79520+
79521+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79522+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
79523+ return 1;
79524+#endif
79525+
79526+#endif
79527+
79528 return is_vmalloc_addr(x);
79529 }
79530
79531@@ -217,8 +253,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
79532
79533 if (!pgd_none(*pgd)) {
79534 pud_t *pud = pud_offset(pgd, addr);
79535+#ifdef CONFIG_X86
79536+ if (!pud_large(*pud))
79537+#endif
79538 if (!pud_none(*pud)) {
79539 pmd_t *pmd = pmd_offset(pud, addr);
79540+#ifdef CONFIG_X86
79541+ if (!pmd_large(*pmd))
79542+#endif
79543 if (!pmd_none(*pmd)) {
79544 pte_t *ptep, pte;
79545
79546@@ -292,13 +334,13 @@ static void __insert_vmap_area(struct vmap_area *va)
79547 struct rb_node *tmp;
79548
79549 while (*p) {
79550- struct vmap_area *tmp;
79551+ struct vmap_area *varea;
79552
79553 parent = *p;
79554- tmp = rb_entry(parent, struct vmap_area, rb_node);
79555- if (va->va_start < tmp->va_end)
79556+ varea = rb_entry(parent, struct vmap_area, rb_node);
79557+ if (va->va_start < varea->va_end)
79558 p = &(*p)->rb_left;
79559- else if (va->va_end > tmp->va_start)
79560+ else if (va->va_end > varea->va_start)
79561 p = &(*p)->rb_right;
79562 else
79563 BUG();
79564@@ -1245,6 +1287,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79565 struct vm_struct *area;
79566
79567 BUG_ON(in_interrupt());
79568+
79569+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79570+ if (flags & VM_KERNEXEC) {
79571+ if (start != VMALLOC_START || end != VMALLOC_END)
79572+ return NULL;
79573+ start = (unsigned long)MODULES_EXEC_VADDR;
79574+ end = (unsigned long)MODULES_EXEC_END;
79575+ }
79576+#endif
79577+
79578 if (flags & VM_IOREMAP) {
79579 int bit = fls(size);
79580
79581@@ -1484,6 +1536,11 @@ void *vmap(struct page **pages, unsigned int count,
79582 if (count > totalram_pages)
79583 return NULL;
79584
79585+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79586+ if (!(pgprot_val(prot) & _PAGE_NX))
79587+ flags |= VM_KERNEXEC;
79588+#endif
79589+
79590 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79591 __builtin_return_address(0));
79592 if (!area)
79593@@ -1594,6 +1651,14 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
79594 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79595 return NULL;
79596
79597+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79598+ if (!(pgprot_val(prot) & _PAGE_NX))
79599+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79600+ VMALLOC_START, VMALLOC_END, node,
79601+ gfp_mask, caller);
79602+ else
79603+#endif
79604+
79605 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79606 VMALLOC_START, VMALLOC_END, node,
79607 gfp_mask, caller);
79608@@ -1619,6 +1684,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
79609 return addr;
79610 }
79611
79612+#undef __vmalloc
79613 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
79614 {
79615 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
79616@@ -1635,6 +1701,7 @@ EXPORT_SYMBOL(__vmalloc);
79617 * For tight control over page level allocator and protection flags
79618 * use __vmalloc() instead.
79619 */
79620+#undef vmalloc
79621 void *vmalloc(unsigned long size)
79622 {
79623 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
79624@@ -1649,6 +1716,7 @@ EXPORT_SYMBOL(vmalloc);
79625 * The resulting memory area is zeroed so it can be mapped to userspace
79626 * without leaking data.
79627 */
79628+#undef vmalloc_user
79629 void *vmalloc_user(unsigned long size)
79630 {
79631 struct vm_struct *area;
79632@@ -1676,6 +1744,7 @@ EXPORT_SYMBOL(vmalloc_user);
79633 * For tight control over page level allocator and protection flags
79634 * use __vmalloc() instead.
79635 */
79636+#undef vmalloc_node
79637 void *vmalloc_node(unsigned long size, int node)
79638 {
79639 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
79640@@ -1698,10 +1767,10 @@ EXPORT_SYMBOL(vmalloc_node);
79641 * For tight control over page level allocator and protection flags
79642 * use __vmalloc() instead.
79643 */
79644-
79645+#undef vmalloc_exec
79646 void *vmalloc_exec(unsigned long size)
79647 {
79648- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79649+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79650 -1, __builtin_return_address(0));
79651 }
79652
79653@@ -1720,6 +1789,7 @@ void *vmalloc_exec(unsigned long size)
79654 * Allocate enough 32bit PA addressable pages to cover @size from the
79655 * page level allocator and map them into contiguous kernel virtual space.
79656 */
79657+#undef vmalloc_32
79658 void *vmalloc_32(unsigned long size)
79659 {
79660 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
79661@@ -1734,6 +1804,7 @@ EXPORT_SYMBOL(vmalloc_32);
79662 * The resulting memory area is 32bit addressable and zeroed so it can be
79663 * mapped to userspace without leaking data.
79664 */
79665+#undef vmalloc_32_user
79666 void *vmalloc_32_user(unsigned long size)
79667 {
79668 struct vm_struct *area;
79669@@ -1998,6 +2069,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79670 unsigned long uaddr = vma->vm_start;
79671 unsigned long usize = vma->vm_end - vma->vm_start;
79672
79673+ BUG_ON(vma->vm_mirror);
79674+
79675 if ((PAGE_SIZE-1) & (unsigned long)addr)
79676 return -EINVAL;
79677
79678diff --git a/mm/vmstat.c b/mm/vmstat.c
79679index 42d76c6..5643dc4 100644
79680--- a/mm/vmstat.c
79681+++ b/mm/vmstat.c
79682@@ -74,7 +74,7 @@ void vm_events_fold_cpu(int cpu)
79683 *
79684 * vm_stat contains the global counters
79685 */
79686-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79687+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79688 EXPORT_SYMBOL(vm_stat);
79689
79690 #ifdef CONFIG_SMP
79691@@ -324,7 +324,7 @@ void refresh_cpu_vm_stats(int cpu)
79692 v = p->vm_stat_diff[i];
79693 p->vm_stat_diff[i] = 0;
79694 local_irq_restore(flags);
79695- atomic_long_add(v, &zone->vm_stat[i]);
79696+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79697 global_diff[i] += v;
79698 #ifdef CONFIG_NUMA
79699 /* 3 seconds idle till flush */
79700@@ -362,7 +362,7 @@ void refresh_cpu_vm_stats(int cpu)
79701
79702 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79703 if (global_diff[i])
79704- atomic_long_add(global_diff[i], &vm_stat[i]);
79705+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79706 }
79707
79708 #endif
79709@@ -953,10 +953,20 @@ static int __init setup_vmstat(void)
79710 start_cpu_timer(cpu);
79711 #endif
79712 #ifdef CONFIG_PROC_FS
79713- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79714- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79715- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79716- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79717+ {
79718+ mode_t gr_mode = S_IRUGO;
79719+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79720+ gr_mode = S_IRUSR;
79721+#endif
79722+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79723+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79724+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79725+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79726+#else
79727+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79728+#endif
79729+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79730+ }
79731 #endif
79732 return 0;
79733 }
79734diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79735index a29c5ab..6143f20 100644
79736--- a/net/8021q/vlan.c
79737+++ b/net/8021q/vlan.c
79738@@ -622,8 +622,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79739 err = -EPERM;
79740 if (!capable(CAP_NET_ADMIN))
79741 break;
79742- if ((args.u.name_type >= 0) &&
79743- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79744+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79745 struct vlan_net *vn;
79746
79747 vn = net_generic(net, vlan_net_id);
79748diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79749index a2d2984..f9eb711 100644
79750--- a/net/9p/trans_fd.c
79751+++ b/net/9p/trans_fd.c
79752@@ -419,7 +419,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79753 oldfs = get_fs();
79754 set_fs(get_ds());
79755 /* The cast to a user pointer is valid due to the set_fs() */
79756- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79757+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79758 set_fs(oldfs);
79759
79760 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79761diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79762index 02cc7e7..4514f1b 100644
79763--- a/net/atm/atm_misc.c
79764+++ b/net/atm/atm_misc.c
79765@@ -19,7 +19,7 @@ int atm_charge(struct atm_vcc *vcc,int truesize)
79766 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79767 return 1;
79768 atm_return(vcc,truesize);
79769- atomic_inc(&vcc->stats->rx_drop);
79770+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79771 return 0;
79772 }
79773
79774@@ -41,7 +41,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
79775 }
79776 }
79777 atm_return(vcc,guess);
79778- atomic_inc(&vcc->stats->rx_drop);
79779+ atomic_inc_unchecked(&vcc->stats->rx_drop);
79780 return NULL;
79781 }
79782
79783@@ -88,7 +88,7 @@ int atm_pcr_goal(const struct atm_trafprm *tp)
79784
79785 void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79786 {
79787-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79788+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79789 __SONET_ITEMS
79790 #undef __HANDLE_ITEM
79791 }
79792@@ -96,7 +96,7 @@ void sonet_copy_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79793
79794 void sonet_subtract_stats(struct k_sonet_stats *from,struct sonet_stats *to)
79795 {
79796-#define __HANDLE_ITEM(i) atomic_sub(to->i,&from->i)
79797+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79798 __SONET_ITEMS
79799 #undef __HANDLE_ITEM
79800 }
79801diff --git a/net/atm/lec.h b/net/atm/lec.h
79802index 9d14d19..5c145f3 100644
79803--- a/net/atm/lec.h
79804+++ b/net/atm/lec.h
79805@@ -48,7 +48,7 @@ struct lane2_ops {
79806 const u8 *tlvs, u32 sizeoftlvs);
79807 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
79808 const u8 *tlvs, u32 sizeoftlvs);
79809-};
79810+} __no_const;
79811
79812 /*
79813 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
79814diff --git a/net/atm/mpc.h b/net/atm/mpc.h
79815index 0919a88..a23d54e 100644
79816--- a/net/atm/mpc.h
79817+++ b/net/atm/mpc.h
79818@@ -33,7 +33,7 @@ struct mpoa_client {
79819 struct mpc_parameters parameters; /* parameters for this client */
79820
79821 const struct net_device_ops *old_ops;
79822- struct net_device_ops new_ops;
79823+ net_device_ops_no_const new_ops;
79824 };
79825
79826
79827diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
79828index 4504a4b..1733f1e 100644
79829--- a/net/atm/mpoa_caches.c
79830+++ b/net/atm/mpoa_caches.c
79831@@ -498,6 +498,8 @@ static void clear_expired(struct mpoa_client *client)
79832 struct timeval now;
79833 struct k_message msg;
79834
79835+ pax_track_stack();
79836+
79837 do_gettimeofday(&now);
79838
79839 write_lock_irq(&client->egress_lock);
79840diff --git a/net/atm/proc.c b/net/atm/proc.c
79841index ab8419a..aa91497 100644
79842--- a/net/atm/proc.c
79843+++ b/net/atm/proc.c
79844@@ -43,9 +43,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
79845 const struct k_atm_aal_stats *stats)
79846 {
79847 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
79848- atomic_read(&stats->tx),atomic_read(&stats->tx_err),
79849- atomic_read(&stats->rx),atomic_read(&stats->rx_err),
79850- atomic_read(&stats->rx_drop));
79851+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
79852+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
79853+ atomic_read_unchecked(&stats->rx_drop));
79854 }
79855
79856 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
79857@@ -188,7 +188,12 @@ static void vcc_info(struct seq_file *seq, struct atm_vcc *vcc)
79858 {
79859 struct sock *sk = sk_atm(vcc);
79860
79861+#ifdef CONFIG_GRKERNSEC_HIDESYM
79862+ seq_printf(seq, "%p ", NULL);
79863+#else
79864 seq_printf(seq, "%p ", vcc);
79865+#endif
79866+
79867 if (!vcc->dev)
79868 seq_printf(seq, "Unassigned ");
79869 else
79870@@ -214,7 +219,11 @@ static void svc_info(struct seq_file *seq, struct atm_vcc *vcc)
79871 {
79872 if (!vcc->dev)
79873 seq_printf(seq, sizeof(void *) == 4 ?
79874+#ifdef CONFIG_GRKERNSEC_HIDESYM
79875+ "N/A@%p%10s" : "N/A@%p%2s", NULL, "");
79876+#else
79877 "N/A@%p%10s" : "N/A@%p%2s", vcc, "");
79878+#endif
79879 else
79880 seq_printf(seq, "%3d %3d %5d ",
79881 vcc->dev->number, vcc->vpi, vcc->vci);
79882diff --git a/net/atm/resources.c b/net/atm/resources.c
79883index 56b7322..c48b84e 100644
79884--- a/net/atm/resources.c
79885+++ b/net/atm/resources.c
79886@@ -161,7 +161,7 @@ void atm_dev_deregister(struct atm_dev *dev)
79887 static void copy_aal_stats(struct k_atm_aal_stats *from,
79888 struct atm_aal_stats *to)
79889 {
79890-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79891+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79892 __AAL_STAT_ITEMS
79893 #undef __HANDLE_ITEM
79894 }
79895@@ -170,7 +170,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
79896 static void subtract_aal_stats(struct k_atm_aal_stats *from,
79897 struct atm_aal_stats *to)
79898 {
79899-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79900+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
79901 __AAL_STAT_ITEMS
79902 #undef __HANDLE_ITEM
79903 }
79904diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
79905index 8567d47..bba2292 100644
79906--- a/net/bridge/br_private.h
79907+++ b/net/bridge/br_private.h
79908@@ -255,7 +255,7 @@ extern void br_ifinfo_notify(int event, struct net_bridge_port *port);
79909
79910 #ifdef CONFIG_SYSFS
79911 /* br_sysfs_if.c */
79912-extern struct sysfs_ops brport_sysfs_ops;
79913+extern const struct sysfs_ops brport_sysfs_ops;
79914 extern int br_sysfs_addif(struct net_bridge_port *p);
79915
79916 /* br_sysfs_br.c */
79917diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c
79918index 9a52ac5..c97538e 100644
79919--- a/net/bridge/br_stp_if.c
79920+++ b/net/bridge/br_stp_if.c
79921@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridge *br)
79922 char *envp[] = { NULL };
79923
79924 if (br->stp_enabled == BR_USER_STP) {
79925- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
79926+ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
79927 printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
79928 br->dev->name, r);
79929
79930diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
79931index 820643a..ce77fb3 100644
79932--- a/net/bridge/br_sysfs_if.c
79933+++ b/net/bridge/br_sysfs_if.c
79934@@ -220,7 +220,7 @@ static ssize_t brport_store(struct kobject * kobj,
79935 return ret;
79936 }
79937
79938-struct sysfs_ops brport_sysfs_ops = {
79939+const struct sysfs_ops brport_sysfs_ops = {
79940 .show = brport_show,
79941 .store = brport_store,
79942 };
79943diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
79944index d73d47f..72df42a 100644
79945--- a/net/bridge/netfilter/ebtables.c
79946+++ b/net/bridge/netfilter/ebtables.c
79947@@ -1337,6 +1337,8 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user,
79948 unsigned int entries_size, nentries;
79949 char *entries;
79950
79951+ pax_track_stack();
79952+
79953 if (cmd == EBT_SO_GET_ENTRIES) {
79954 entries_size = t->private->entries_size;
79955 nentries = t->private->nentries;
79956diff --git a/net/can/bcm.c b/net/can/bcm.c
79957index 2ffd2e0..72a7486 100644
79958--- a/net/can/bcm.c
79959+++ b/net/can/bcm.c
79960@@ -164,9 +164,15 @@ static int bcm_proc_show(struct seq_file *m, void *v)
79961 struct bcm_sock *bo = bcm_sk(sk);
79962 struct bcm_op *op;
79963
79964+#ifdef CONFIG_GRKERNSEC_HIDESYM
79965+ seq_printf(m, ">>> socket %p", NULL);
79966+ seq_printf(m, " / sk %p", NULL);
79967+ seq_printf(m, " / bo %p", NULL);
79968+#else
79969 seq_printf(m, ">>> socket %p", sk->sk_socket);
79970 seq_printf(m, " / sk %p", sk);
79971 seq_printf(m, " / bo %p", bo);
79972+#endif
79973 seq_printf(m, " / dropped %lu", bo->dropped_usr_msgs);
79974 seq_printf(m, " / bound %s", bcm_proc_getifname(ifname, bo->ifindex));
79975 seq_printf(m, " <<<\n");
79976diff --git a/net/compat.c b/net/compat.c
79977index 9559afc..ccd74e1 100644
79978--- a/net/compat.c
79979+++ b/net/compat.c
79980@@ -69,9 +69,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
79981 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
79982 __get_user(kmsg->msg_flags, &umsg->msg_flags))
79983 return -EFAULT;
79984- kmsg->msg_name = compat_ptr(tmp1);
79985- kmsg->msg_iov = compat_ptr(tmp2);
79986- kmsg->msg_control = compat_ptr(tmp3);
79987+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
79988+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
79989+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
79990 return 0;
79991 }
79992
79993@@ -94,7 +94,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79994 kern_msg->msg_name = NULL;
79995
79996 tot_len = iov_from_user_compat_to_kern(kern_iov,
79997- (struct compat_iovec __user *)kern_msg->msg_iov,
79998+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
79999 kern_msg->msg_iovlen);
80000 if (tot_len >= 0)
80001 kern_msg->msg_iov = kern_iov;
80002@@ -114,20 +114,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80003
80004 #define CMSG_COMPAT_FIRSTHDR(msg) \
80005 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
80006- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
80007+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
80008 (struct compat_cmsghdr __user *)NULL)
80009
80010 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
80011 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
80012 (ucmlen) <= (unsigned long) \
80013 ((mhdr)->msg_controllen - \
80014- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
80015+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
80016
80017 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
80018 struct compat_cmsghdr __user *cmsg, int cmsg_len)
80019 {
80020 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
80021- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
80022+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
80023 msg->msg_controllen)
80024 return NULL;
80025 return (struct compat_cmsghdr __user *)ptr;
80026@@ -219,7 +219,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
80027 {
80028 struct compat_timeval ctv;
80029 struct compat_timespec cts[3];
80030- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80031+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80032 struct compat_cmsghdr cmhdr;
80033 int cmlen;
80034
80035@@ -271,7 +271,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
80036
80037 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
80038 {
80039- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80040+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80041 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
80042 int fdnum = scm->fp->count;
80043 struct file **fp = scm->fp->fp;
80044@@ -433,7 +433,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
80045 len = sizeof(ktime);
80046 old_fs = get_fs();
80047 set_fs(KERNEL_DS);
80048- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
80049+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
80050 set_fs(old_fs);
80051
80052 if (!err) {
80053@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80054 case MCAST_JOIN_GROUP:
80055 case MCAST_LEAVE_GROUP:
80056 {
80057- struct compat_group_req __user *gr32 = (void *)optval;
80058+ struct compat_group_req __user *gr32 = (void __user *)optval;
80059 struct group_req __user *kgr =
80060 compat_alloc_user_space(sizeof(struct group_req));
80061 u32 interface;
80062@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80063 case MCAST_BLOCK_SOURCE:
80064 case MCAST_UNBLOCK_SOURCE:
80065 {
80066- struct compat_group_source_req __user *gsr32 = (void *)optval;
80067+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
80068 struct group_source_req __user *kgsr = compat_alloc_user_space(
80069 sizeof(struct group_source_req));
80070 u32 interface;
80071@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80072 }
80073 case MCAST_MSFILTER:
80074 {
80075- struct compat_group_filter __user *gf32 = (void *)optval;
80076+ struct compat_group_filter __user *gf32 = (void __user *)optval;
80077 struct group_filter __user *kgf;
80078 u32 interface, fmode, numsrc;
80079
80080diff --git a/net/core/dev.c b/net/core/dev.c
80081index 84a0705..575db4c 100644
80082--- a/net/core/dev.c
80083+++ b/net/core/dev.c
80084@@ -1047,10 +1047,14 @@ void dev_load(struct net *net, const char *name)
80085 if (no_module && capable(CAP_NET_ADMIN))
80086 no_module = request_module("netdev-%s", name);
80087 if (no_module && capable(CAP_SYS_MODULE)) {
80088+#ifdef CONFIG_GRKERNSEC_MODHARDEN
80089+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
80090+#else
80091 if (!request_module("%s", name))
80092 pr_err("Loading kernel module for a network device "
80093 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
80094 "instead\n", name);
80095+#endif
80096 }
80097 }
80098 EXPORT_SYMBOL(dev_load);
80099@@ -1654,7 +1658,7 @@ static inline int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
80100
80101 struct dev_gso_cb {
80102 void (*destructor)(struct sk_buff *skb);
80103-};
80104+} __no_const;
80105
80106 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
80107
80108@@ -2063,7 +2067,7 @@ int netif_rx_ni(struct sk_buff *skb)
80109 }
80110 EXPORT_SYMBOL(netif_rx_ni);
80111
80112-static void net_tx_action(struct softirq_action *h)
80113+static void net_tx_action(void)
80114 {
80115 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80116
80117@@ -2827,7 +2831,7 @@ void netif_napi_del(struct napi_struct *napi)
80118 EXPORT_SYMBOL(netif_napi_del);
80119
80120
80121-static void net_rx_action(struct softirq_action *h)
80122+static void net_rx_action(void)
80123 {
80124 struct list_head *list = &__get_cpu_var(softnet_data).poll_list;
80125 unsigned long time_limit = jiffies + 2;
80126diff --git a/net/core/flow.c b/net/core/flow.c
80127index 9601587..8c4824e 100644
80128--- a/net/core/flow.c
80129+++ b/net/core/flow.c
80130@@ -35,11 +35,11 @@ struct flow_cache_entry {
80131 atomic_t *object_ref;
80132 };
80133
80134-atomic_t flow_cache_genid = ATOMIC_INIT(0);
80135+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
80136
80137 static u32 flow_hash_shift;
80138 #define flow_hash_size (1 << flow_hash_shift)
80139-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
80140+static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
80141
80142 #define flow_table(cpu) (per_cpu(flow_tables, cpu))
80143
80144@@ -52,7 +52,7 @@ struct flow_percpu_info {
80145 u32 hash_rnd;
80146 int count;
80147 };
80148-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
80149+static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
80150
80151 #define flow_hash_rnd_recalc(cpu) \
80152 (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
80153@@ -69,7 +69,7 @@ struct flow_flush_info {
80154 atomic_t cpuleft;
80155 struct completion completion;
80156 };
80157-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
80158+static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
80159
80160 #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
80161
80162@@ -190,7 +190,7 @@ void *flow_cache_lookup(struct net *net, struct flowi *key, u16 family, u8 dir,
80163 if (fle->family == family &&
80164 fle->dir == dir &&
80165 flow_key_compare(key, &fle->key) == 0) {
80166- if (fle->genid == atomic_read(&flow_cache_genid)) {
80167+ if (fle->genid == atomic_read_unchecked(&flow_cache_genid)) {
80168 void *ret = fle->object;
80169
80170 if (ret)
80171@@ -228,7 +228,7 @@ nocache:
80172 err = resolver(net, key, family, dir, &obj, &obj_ref);
80173
80174 if (fle && !err) {
80175- fle->genid = atomic_read(&flow_cache_genid);
80176+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
80177
80178 if (fle->object)
80179 atomic_dec(fle->object_ref);
80180@@ -258,7 +258,7 @@ static void flow_cache_flush_tasklet(unsigned long data)
80181
80182 fle = flow_table(cpu)[i];
80183 for (; fle; fle = fle->next) {
80184- unsigned genid = atomic_read(&flow_cache_genid);
80185+ unsigned genid = atomic_read_unchecked(&flow_cache_genid);
80186
80187 if (!fle->object || fle->genid == genid)
80188 continue;
80189diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
80190index d4fd895..ac9b1e6 100644
80191--- a/net/core/rtnetlink.c
80192+++ b/net/core/rtnetlink.c
80193@@ -57,7 +57,7 @@ struct rtnl_link
80194 {
80195 rtnl_doit_func doit;
80196 rtnl_dumpit_func dumpit;
80197-};
80198+} __no_const;
80199
80200 static DEFINE_MUTEX(rtnl_mutex);
80201
80202diff --git a/net/core/scm.c b/net/core/scm.c
80203index d98eafc..1a190a9 100644
80204--- a/net/core/scm.c
80205+++ b/net/core/scm.c
80206@@ -191,7 +191,7 @@ error:
80207 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80208 {
80209 struct cmsghdr __user *cm
80210- = (__force struct cmsghdr __user *)msg->msg_control;
80211+ = (struct cmsghdr __force_user *)msg->msg_control;
80212 struct cmsghdr cmhdr;
80213 int cmlen = CMSG_LEN(len);
80214 int err;
80215@@ -214,7 +214,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80216 err = -EFAULT;
80217 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
80218 goto out;
80219- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
80220+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
80221 goto out;
80222 cmlen = CMSG_SPACE(len);
80223 if (msg->msg_controllen < cmlen)
80224@@ -229,7 +229,7 @@ out:
80225 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80226 {
80227 struct cmsghdr __user *cm
80228- = (__force struct cmsghdr __user*)msg->msg_control;
80229+ = (struct cmsghdr __force_user *)msg->msg_control;
80230
80231 int fdmax = 0;
80232 int fdnum = scm->fp->count;
80233@@ -249,7 +249,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80234 if (fdnum < fdmax)
80235 fdmax = fdnum;
80236
80237- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
80238+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
80239 i++, cmfptr++)
80240 {
80241 int new_fd;
80242diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
80243index 45329d7..626aaa6 100644
80244--- a/net/core/secure_seq.c
80245+++ b/net/core/secure_seq.c
80246@@ -57,7 +57,7 @@ __u32 secure_tcpv6_sequence_number(__be32 *saddr, __be32 *daddr,
80247 EXPORT_SYMBOL(secure_tcpv6_sequence_number);
80248
80249 u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
80250- __be16 dport)
80251+ __be16 dport)
80252 {
80253 u32 secret[MD5_MESSAGE_BYTES / 4];
80254 u32 hash[MD5_DIGEST_WORDS];
80255@@ -71,7 +71,6 @@ u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
80256 secret[i] = net_secret[i];
80257
80258 md5_transform(hash, secret);
80259-
80260 return hash[0];
80261 }
80262 #endif
80263diff --git a/net/core/skbuff.c b/net/core/skbuff.c
80264index a807f8c..65f906f 100644
80265--- a/net/core/skbuff.c
80266+++ b/net/core/skbuff.c
80267@@ -1544,6 +1544,8 @@ int skb_splice_bits(struct sk_buff *skb, unsigned int offset,
80268 struct sk_buff *frag_iter;
80269 struct sock *sk = skb->sk;
80270
80271+ pax_track_stack();
80272+
80273 /*
80274 * __skb_splice_bits() only fails if the output has no room left,
80275 * so no point in going over the frag_list for the error case.
80276diff --git a/net/core/sock.c b/net/core/sock.c
80277index 6605e75..3acebda 100644
80278--- a/net/core/sock.c
80279+++ b/net/core/sock.c
80280@@ -864,11 +864,15 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80281 break;
80282
80283 case SO_PEERCRED:
80284+ {
80285+ struct ucred peercred;
80286 if (len > sizeof(sk->sk_peercred))
80287 len = sizeof(sk->sk_peercred);
80288- if (copy_to_user(optval, &sk->sk_peercred, len))
80289+ peercred = sk->sk_peercred;
80290+ if (copy_to_user(optval, &peercred, len))
80291 return -EFAULT;
80292 goto lenout;
80293+ }
80294
80295 case SO_PEERNAME:
80296 {
80297@@ -1892,7 +1896,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
80298 */
80299 smp_wmb();
80300 atomic_set(&sk->sk_refcnt, 1);
80301- atomic_set(&sk->sk_drops, 0);
80302+ atomic_set_unchecked(&sk->sk_drops, 0);
80303 }
80304 EXPORT_SYMBOL(sock_init_data);
80305
80306diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
80307index 2036568..c55883d 100644
80308--- a/net/decnet/sysctl_net_decnet.c
80309+++ b/net/decnet/sysctl_net_decnet.c
80310@@ -206,7 +206,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
80311
80312 if (len > *lenp) len = *lenp;
80313
80314- if (copy_to_user(buffer, addr, len))
80315+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
80316 return -EFAULT;
80317
80318 *lenp = len;
80319@@ -327,7 +327,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
80320
80321 if (len > *lenp) len = *lenp;
80322
80323- if (copy_to_user(buffer, devname, len))
80324+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
80325 return -EFAULT;
80326
80327 *lenp = len;
80328diff --git a/net/econet/Kconfig b/net/econet/Kconfig
80329index 39a2d29..f39c0fe 100644
80330--- a/net/econet/Kconfig
80331+++ b/net/econet/Kconfig
80332@@ -4,7 +4,7 @@
80333
80334 config ECONET
80335 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
80336- depends on EXPERIMENTAL && INET
80337+ depends on EXPERIMENTAL && INET && BROKEN
80338 ---help---
80339 Econet is a fairly old and slow networking protocol mainly used by
80340 Acorn computers to access file and print servers. It uses native
80341diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
80342index a413b1b..380849c 100644
80343--- a/net/ieee802154/dgram.c
80344+++ b/net/ieee802154/dgram.c
80345@@ -318,7 +318,7 @@ out:
80346 static int dgram_rcv_skb(struct sock *sk, struct sk_buff *skb)
80347 {
80348 if (sock_queue_rcv_skb(sk, skb) < 0) {
80349- atomic_inc(&sk->sk_drops);
80350+ atomic_inc_unchecked(&sk->sk_drops);
80351 kfree_skb(skb);
80352 return NET_RX_DROP;
80353 }
80354diff --git a/net/ieee802154/raw.c b/net/ieee802154/raw.c
80355index 30e74ee..bfc6ee0 100644
80356--- a/net/ieee802154/raw.c
80357+++ b/net/ieee802154/raw.c
80358@@ -206,7 +206,7 @@ out:
80359 static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
80360 {
80361 if (sock_queue_rcv_skb(sk, skb) < 0) {
80362- atomic_inc(&sk->sk_drops);
80363+ atomic_inc_unchecked(&sk->sk_drops);
80364 kfree_skb(skb);
80365 return NET_RX_DROP;
80366 }
80367diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
80368index dba56d2..acee5d6 100644
80369--- a/net/ipv4/inet_diag.c
80370+++ b/net/ipv4/inet_diag.c
80371@@ -113,8 +113,13 @@ static int inet_csk_diag_fill(struct sock *sk,
80372 r->idiag_retrans = 0;
80373
80374 r->id.idiag_if = sk->sk_bound_dev_if;
80375+#ifdef CONFIG_GRKERNSEC_HIDESYM
80376+ r->id.idiag_cookie[0] = 0;
80377+ r->id.idiag_cookie[1] = 0;
80378+#else
80379 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
80380 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
80381+#endif
80382
80383 r->id.idiag_sport = inet->sport;
80384 r->id.idiag_dport = inet->dport;
80385@@ -200,8 +205,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
80386 r->idiag_family = tw->tw_family;
80387 r->idiag_retrans = 0;
80388 r->id.idiag_if = tw->tw_bound_dev_if;
80389+
80390+#ifdef CONFIG_GRKERNSEC_HIDESYM
80391+ r->id.idiag_cookie[0] = 0;
80392+ r->id.idiag_cookie[1] = 0;
80393+#else
80394 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
80395 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
80396+#endif
80397+
80398 r->id.idiag_sport = tw->tw_sport;
80399 r->id.idiag_dport = tw->tw_dport;
80400 r->id.idiag_src[0] = tw->tw_rcv_saddr;
80401@@ -284,12 +296,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
80402 if (sk == NULL)
80403 goto unlock;
80404
80405+#ifndef CONFIG_GRKERNSEC_HIDESYM
80406 err = -ESTALE;
80407 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
80408 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
80409 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
80410 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
80411 goto out;
80412+#endif
80413
80414 err = -ENOMEM;
80415 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
80416@@ -579,8 +593,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
80417 r->idiag_retrans = req->retrans;
80418
80419 r->id.idiag_if = sk->sk_bound_dev_if;
80420+
80421+#ifdef CONFIG_GRKERNSEC_HIDESYM
80422+ r->id.idiag_cookie[0] = 0;
80423+ r->id.idiag_cookie[1] = 0;
80424+#else
80425 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
80426 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
80427+#endif
80428
80429 tmo = req->expires - jiffies;
80430 if (tmo < 0)
80431diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
80432index d717267..56de7e7 100644
80433--- a/net/ipv4/inet_hashtables.c
80434+++ b/net/ipv4/inet_hashtables.c
80435@@ -18,12 +18,15 @@
80436 #include <linux/sched.h>
80437 #include <linux/slab.h>
80438 #include <linux/wait.h>
80439+#include <linux/security.h>
80440
80441 #include <net/inet_connection_sock.h>
80442 #include <net/inet_hashtables.h>
80443 #include <net/secure_seq.h>
80444 #include <net/ip.h>
80445
80446+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
80447+
80448 /*
80449 * Allocate and initialize a new local port bind bucket.
80450 * The bindhash mutex for snum's hash chain must be held here.
80451@@ -491,6 +494,8 @@ ok:
80452 }
80453 spin_unlock(&head->lock);
80454
80455+ gr_update_task_in_ip_table(current, inet_sk(sk));
80456+
80457 if (tw) {
80458 inet_twsk_deschedule(tw, death_row);
80459 inet_twsk_put(tw);
80460diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
80461index 13b229f..6956484 100644
80462--- a/net/ipv4/inetpeer.c
80463+++ b/net/ipv4/inetpeer.c
80464@@ -367,6 +367,8 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
80465 struct inet_peer *p, *n;
80466 struct inet_peer **stack[PEER_MAXDEPTH], ***stackptr;
80467
80468+ pax_track_stack();
80469+
80470 /* Look up for the address quickly. */
80471 read_lock_bh(&peer_pool_lock);
80472 p = lookup(daddr, NULL);
80473@@ -390,7 +392,7 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
80474 return NULL;
80475 n->v4daddr = daddr;
80476 atomic_set(&n->refcnt, 1);
80477- atomic_set(&n->rid, 0);
80478+ atomic_set_unchecked(&n->rid, 0);
80479 n->ip_id_count = secure_ip_id(daddr);
80480 n->tcp_ts_stamp = 0;
80481
80482diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
80483index d3fe10b..feeafc9 100644
80484--- a/net/ipv4/ip_fragment.c
80485+++ b/net/ipv4/ip_fragment.c
80486@@ -255,7 +255,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
80487 return 0;
80488
80489 start = qp->rid;
80490- end = atomic_inc_return(&peer->rid);
80491+ end = atomic_inc_return_unchecked(&peer->rid);
80492 qp->rid = end;
80493
80494 rc = qp->q.fragments && (end - start) > max;
80495diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
80496index e982b5c..f079d75 100644
80497--- a/net/ipv4/ip_sockglue.c
80498+++ b/net/ipv4/ip_sockglue.c
80499@@ -1015,6 +1015,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80500 int val;
80501 int len;
80502
80503+ pax_track_stack();
80504+
80505 if (level != SOL_IP)
80506 return -EOPNOTSUPP;
80507
80508@@ -1173,7 +1175,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80509 if (sk->sk_type != SOCK_STREAM)
80510 return -ENOPROTOOPT;
80511
80512- msg.msg_control = optval;
80513+ msg.msg_control = (void __force_kernel *)optval;
80514 msg.msg_controllen = len;
80515 msg.msg_flags = 0;
80516
80517diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
80518index f8d04c2..c1188f2 100644
80519--- a/net/ipv4/ipconfig.c
80520+++ b/net/ipv4/ipconfig.c
80521@@ -295,7 +295,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
80522
80523 mm_segment_t oldfs = get_fs();
80524 set_fs(get_ds());
80525- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80526+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80527 set_fs(oldfs);
80528 return res;
80529 }
80530@@ -306,7 +306,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
80531
80532 mm_segment_t oldfs = get_fs();
80533 set_fs(get_ds());
80534- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80535+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80536 set_fs(oldfs);
80537 return res;
80538 }
80539@@ -317,7 +317,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
80540
80541 mm_segment_t oldfs = get_fs();
80542 set_fs(get_ds());
80543- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
80544+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
80545 set_fs(oldfs);
80546 return res;
80547 }
80548diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
80549index c8b0cc3..4da5ae2 100644
80550--- a/net/ipv4/netfilter/arp_tables.c
80551+++ b/net/ipv4/netfilter/arp_tables.c
80552@@ -934,6 +934,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80553 private = &tmp;
80554 }
80555 #endif
80556+ memset(&info, 0, sizeof(info));
80557 info.valid_hooks = t->valid_hooks;
80558 memcpy(info.hook_entry, private->hook_entry,
80559 sizeof(info.hook_entry));
80560diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c
80561index c156db2..e772975 100644
80562--- a/net/ipv4/netfilter/ip_queue.c
80563+++ b/net/ipv4/netfilter/ip_queue.c
80564@@ -286,6 +286,9 @@ ipq_mangle_ipv4(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
80565
80566 if (v->data_len < sizeof(*user_iph))
80567 return 0;
80568+ if (v->data_len > 65535)
80569+ return -EMSGSIZE;
80570+
80571 diff = v->data_len - e->skb->len;
80572 if (diff < 0) {
80573 if (pskb_trim(e->skb, v->data_len))
80574@@ -409,7 +412,8 @@ ipq_dev_drop(int ifindex)
80575 static inline void
80576 __ipq_rcv_skb(struct sk_buff *skb)
80577 {
80578- int status, type, pid, flags, nlmsglen, skblen;
80579+ int status, type, pid, flags;
80580+ unsigned int nlmsglen, skblen;
80581 struct nlmsghdr *nlh;
80582
80583 skblen = skb->len;
80584diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
80585index 0606db1..02e7e4c 100644
80586--- a/net/ipv4/netfilter/ip_tables.c
80587+++ b/net/ipv4/netfilter/ip_tables.c
80588@@ -1141,6 +1141,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
80589 private = &tmp;
80590 }
80591 #endif
80592+ memset(&info, 0, sizeof(info));
80593 info.valid_hooks = t->valid_hooks;
80594 memcpy(info.hook_entry, private->hook_entry,
80595 sizeof(info.hook_entry));
80596diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
80597index d9521f6..3c3eb25 100644
80598--- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
80599+++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
80600@@ -397,7 +397,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
80601
80602 *len = 0;
80603
80604- *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
80605+ *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
80606 if (*octets == NULL) {
80607 if (net_ratelimit())
80608 printk("OOM in bsalg (%d)\n", __LINE__);
80609diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
80610index ab996f9..3da5f96 100644
80611--- a/net/ipv4/raw.c
80612+++ b/net/ipv4/raw.c
80613@@ -292,7 +292,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
80614 /* Charge it to the socket. */
80615
80616 if (sock_queue_rcv_skb(sk, skb) < 0) {
80617- atomic_inc(&sk->sk_drops);
80618+ atomic_inc_unchecked(&sk->sk_drops);
80619 kfree_skb(skb);
80620 return NET_RX_DROP;
80621 }
80622@@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
80623 int raw_rcv(struct sock *sk, struct sk_buff *skb)
80624 {
80625 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
80626- atomic_inc(&sk->sk_drops);
80627+ atomic_inc_unchecked(&sk->sk_drops);
80628 kfree_skb(skb);
80629 return NET_RX_DROP;
80630 }
80631@@ -724,16 +724,23 @@ static int raw_init(struct sock *sk)
80632
80633 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
80634 {
80635+ struct icmp_filter filter;
80636+
80637+ if (optlen < 0)
80638+ return -EINVAL;
80639 if (optlen > sizeof(struct icmp_filter))
80640 optlen = sizeof(struct icmp_filter);
80641- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
80642+ if (copy_from_user(&filter, optval, optlen))
80643 return -EFAULT;
80644+ raw_sk(sk)->filter = filter;
80645+
80646 return 0;
80647 }
80648
80649 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
80650 {
80651 int len, ret = -EFAULT;
80652+ struct icmp_filter filter;
80653
80654 if (get_user(len, optlen))
80655 goto out;
80656@@ -743,8 +750,9 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
80657 if (len > sizeof(struct icmp_filter))
80658 len = sizeof(struct icmp_filter);
80659 ret = -EFAULT;
80660- if (put_user(len, optlen) ||
80661- copy_to_user(optval, &raw_sk(sk)->filter, len))
80662+ filter = raw_sk(sk)->filter;
80663+ if (put_user(len, optlen) || len > sizeof filter ||
80664+ copy_to_user(optval, &filter, len))
80665 goto out;
80666 ret = 0;
80667 out: return ret;
80668@@ -954,7 +962,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80669 sk_wmem_alloc_get(sp),
80670 sk_rmem_alloc_get(sp),
80671 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
80672- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80673+ atomic_read(&sp->sk_refcnt),
80674+#ifdef CONFIG_GRKERNSEC_HIDESYM
80675+ NULL,
80676+#else
80677+ sp,
80678+#endif
80679+ atomic_read_unchecked(&sp->sk_drops));
80680 }
80681
80682 static int raw_seq_show(struct seq_file *seq, void *v)
80683diff --git a/net/ipv4/route.c b/net/ipv4/route.c
80684index 58f141b..b759702 100644
80685--- a/net/ipv4/route.c
80686+++ b/net/ipv4/route.c
80687@@ -269,7 +269,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
80688
80689 static inline int rt_genid(struct net *net)
80690 {
80691- return atomic_read(&net->ipv4.rt_genid);
80692+ return atomic_read_unchecked(&net->ipv4.rt_genid);
80693 }
80694
80695 #ifdef CONFIG_PROC_FS
80696@@ -889,7 +889,7 @@ static void rt_cache_invalidate(struct net *net)
80697 unsigned char shuffle;
80698
80699 get_random_bytes(&shuffle, sizeof(shuffle));
80700- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
80701+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
80702 }
80703
80704 /*
80705@@ -3357,7 +3357,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
80706
80707 static __net_init int rt_secret_timer_init(struct net *net)
80708 {
80709- atomic_set(&net->ipv4.rt_genid,
80710+ atomic_set_unchecked(&net->ipv4.rt_genid,
80711 (int) ((num_physpages ^ (num_physpages>>8)) ^
80712 (jiffies ^ (jiffies >> 7))));
80713
80714diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
80715index f095659..adc892a 100644
80716--- a/net/ipv4/tcp.c
80717+++ b/net/ipv4/tcp.c
80718@@ -2085,6 +2085,8 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
80719 int val;
80720 int err = 0;
80721
80722+ pax_track_stack();
80723+
80724 /* This is a string value all the others are int's */
80725 if (optname == TCP_CONGESTION) {
80726 char name[TCP_CA_NAME_MAX];
80727@@ -2355,6 +2357,8 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
80728 struct tcp_sock *tp = tcp_sk(sk);
80729 int val, len;
80730
80731+ pax_track_stack();
80732+
80733 if (get_user(len, optlen))
80734 return -EFAULT;
80735
80736diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
80737index 6fc7961..33bad4a 100644
80738--- a/net/ipv4/tcp_ipv4.c
80739+++ b/net/ipv4/tcp_ipv4.c
80740@@ -85,6 +85,9 @@
80741 int sysctl_tcp_tw_reuse __read_mostly;
80742 int sysctl_tcp_low_latency __read_mostly;
80743
80744+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80745+extern int grsec_enable_blackhole;
80746+#endif
80747
80748 #ifdef CONFIG_TCP_MD5SIG
80749 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
80750@@ -1543,6 +1546,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
80751 return 0;
80752
80753 reset:
80754+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80755+ if (!grsec_enable_blackhole)
80756+#endif
80757 tcp_v4_send_reset(rsk, skb);
80758 discard:
80759 kfree_skb(skb);
80760@@ -1604,12 +1610,20 @@ int tcp_v4_rcv(struct sk_buff *skb)
80761 TCP_SKB_CB(skb)->sacked = 0;
80762
80763 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80764- if (!sk)
80765+ if (!sk) {
80766+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80767+ ret = 1;
80768+#endif
80769 goto no_tcp_socket;
80770+ }
80771
80772 process:
80773- if (sk->sk_state == TCP_TIME_WAIT)
80774+ if (sk->sk_state == TCP_TIME_WAIT) {
80775+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80776+ ret = 2;
80777+#endif
80778 goto do_time_wait;
80779+ }
80780
80781 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
80782 goto discard_and_relse;
80783@@ -1651,6 +1665,10 @@ no_tcp_socket:
80784 bad_packet:
80785 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80786 } else {
80787+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80788+ if (!grsec_enable_blackhole || (ret == 1 &&
80789+ (skb->dev->flags & IFF_LOOPBACK)))
80790+#endif
80791 tcp_v4_send_reset(NULL, skb);
80792 }
80793
80794@@ -2238,7 +2256,11 @@ static void get_openreq4(struct sock *sk, struct request_sock *req,
80795 0, /* non standard timer */
80796 0, /* open_requests have no inode */
80797 atomic_read(&sk->sk_refcnt),
80798+#ifdef CONFIG_GRKERNSEC_HIDESYM
80799+ NULL,
80800+#else
80801 req,
80802+#endif
80803 len);
80804 }
80805
80806@@ -2280,7 +2302,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
80807 sock_i_uid(sk),
80808 icsk->icsk_probes_out,
80809 sock_i_ino(sk),
80810- atomic_read(&sk->sk_refcnt), sk,
80811+ atomic_read(&sk->sk_refcnt),
80812+#ifdef CONFIG_GRKERNSEC_HIDESYM
80813+ NULL,
80814+#else
80815+ sk,
80816+#endif
80817 jiffies_to_clock_t(icsk->icsk_rto),
80818 jiffies_to_clock_t(icsk->icsk_ack.ato),
80819 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
80820@@ -2308,7 +2335,13 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
80821 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
80822 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
80823 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
80824- atomic_read(&tw->tw_refcnt), tw, len);
80825+ atomic_read(&tw->tw_refcnt),
80826+#ifdef CONFIG_GRKERNSEC_HIDESYM
80827+ NULL,
80828+#else
80829+ tw,
80830+#endif
80831+ len);
80832 }
80833
80834 #define TMPSZ 150
80835diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
80836index 4c03598..e09a8e8 100644
80837--- a/net/ipv4/tcp_minisocks.c
80838+++ b/net/ipv4/tcp_minisocks.c
80839@@ -26,6 +26,10 @@
80840 #include <net/inet_common.h>
80841 #include <net/xfrm.h>
80842
80843+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80844+extern int grsec_enable_blackhole;
80845+#endif
80846+
80847 #ifdef CONFIG_SYSCTL
80848 #define SYNC_INIT 0 /* let the user enable it */
80849 #else
80850@@ -672,6 +676,10 @@ listen_overflow:
80851
80852 embryonic_reset:
80853 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
80854+
80855+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80856+ if (!grsec_enable_blackhole)
80857+#endif
80858 if (!(flg & TCP_FLAG_RST))
80859 req->rsk_ops->send_reset(sk, skb);
80860
80861diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
80862index af83bdf..ec91cb2 100644
80863--- a/net/ipv4/tcp_output.c
80864+++ b/net/ipv4/tcp_output.c
80865@@ -2234,6 +2234,8 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
80866 __u8 *md5_hash_location;
80867 int mss;
80868
80869+ pax_track_stack();
80870+
80871 skb = sock_wmalloc(sk, MAX_TCP_HEADER + 15, 1, GFP_ATOMIC);
80872 if (skb == NULL)
80873 return NULL;
80874diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
80875index 59f5b5e..193860f 100644
80876--- a/net/ipv4/tcp_probe.c
80877+++ b/net/ipv4/tcp_probe.c
80878@@ -200,7 +200,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
80879 if (cnt + width >= len)
80880 break;
80881
80882- if (copy_to_user(buf + cnt, tbuf, width))
80883+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
80884 return -EFAULT;
80885 cnt += width;
80886 }
80887diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
80888index 57d5501..a9ed13a 100644
80889--- a/net/ipv4/tcp_timer.c
80890+++ b/net/ipv4/tcp_timer.c
80891@@ -21,6 +21,10 @@
80892 #include <linux/module.h>
80893 #include <net/tcp.h>
80894
80895+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80896+extern int grsec_lastack_retries;
80897+#endif
80898+
80899 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80900 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80901 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80902@@ -164,6 +168,13 @@ static int tcp_write_timeout(struct sock *sk)
80903 }
80904 }
80905
80906+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80907+ if ((sk->sk_state == TCP_LAST_ACK) &&
80908+ (grsec_lastack_retries > 0) &&
80909+ (grsec_lastack_retries < retry_until))
80910+ retry_until = grsec_lastack_retries;
80911+#endif
80912+
80913 if (retransmits_timed_out(sk, retry_until)) {
80914 /* Has it gone just too far? */
80915 tcp_write_err(sk);
80916diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
80917index 0ac8833..58d8c43 100644
80918--- a/net/ipv4/udp.c
80919+++ b/net/ipv4/udp.c
80920@@ -86,6 +86,7 @@
80921 #include <linux/types.h>
80922 #include <linux/fcntl.h>
80923 #include <linux/module.h>
80924+#include <linux/security.h>
80925 #include <linux/socket.h>
80926 #include <linux/sockios.h>
80927 #include <linux/igmp.h>
80928@@ -106,6 +107,10 @@
80929 #include <net/xfrm.h>
80930 #include "udp_impl.h"
80931
80932+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80933+extern int grsec_enable_blackhole;
80934+#endif
80935+
80936 struct udp_table udp_table;
80937 EXPORT_SYMBOL(udp_table);
80938
80939@@ -371,6 +376,9 @@ found:
80940 return s;
80941 }
80942
80943+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
80944+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
80945+
80946 /*
80947 * This routine is called by the ICMP module when it gets some
80948 * sort of error condition. If err < 0 then the socket should
80949@@ -639,9 +647,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
80950 dport = usin->sin_port;
80951 if (dport == 0)
80952 return -EINVAL;
80953+
80954+ err = gr_search_udp_sendmsg(sk, usin);
80955+ if (err)
80956+ return err;
80957 } else {
80958 if (sk->sk_state != TCP_ESTABLISHED)
80959 return -EDESTADDRREQ;
80960+
80961+ err = gr_search_udp_sendmsg(sk, NULL);
80962+ if (err)
80963+ return err;
80964+
80965 daddr = inet->daddr;
80966 dport = inet->dport;
80967 /* Open fast path for connected socket.
80968@@ -945,6 +962,10 @@ try_again:
80969 if (!skb)
80970 goto out;
80971
80972+ err = gr_search_udp_recvmsg(sk, skb);
80973+ if (err)
80974+ goto out_free;
80975+
80976 ulen = skb->len - sizeof(struct udphdr);
80977 copied = len;
80978 if (copied > ulen)
80979@@ -1068,7 +1089,7 @@ static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80980 if (rc == -ENOMEM) {
80981 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80982 is_udplite);
80983- atomic_inc(&sk->sk_drops);
80984+ atomic_inc_unchecked(&sk->sk_drops);
80985 }
80986 goto drop;
80987 }
80988@@ -1338,6 +1359,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80989 goto csum_error;
80990
80991 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80992+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80993+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80994+#endif
80995 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
80996
80997 /*
80998@@ -1758,8 +1782,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
80999 sk_wmem_alloc_get(sp),
81000 sk_rmem_alloc_get(sp),
81001 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
81002- atomic_read(&sp->sk_refcnt), sp,
81003- atomic_read(&sp->sk_drops), len);
81004+ atomic_read(&sp->sk_refcnt),
81005+#ifdef CONFIG_GRKERNSEC_HIDESYM
81006+ NULL,
81007+#else
81008+ sp,
81009+#endif
81010+ atomic_read_unchecked(&sp->sk_drops), len);
81011 }
81012
81013 int udp4_seq_show(struct seq_file *seq, void *v)
81014diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
81015index 8ac3d09..fc58c5f 100644
81016--- a/net/ipv6/addrconf.c
81017+++ b/net/ipv6/addrconf.c
81018@@ -2053,7 +2053,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
81019 p.iph.ihl = 5;
81020 p.iph.protocol = IPPROTO_IPV6;
81021 p.iph.ttl = 64;
81022- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
81023+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
81024
81025 if (ops->ndo_do_ioctl) {
81026 mm_segment_t oldfs = get_fs();
81027diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
81028index cc4797d..7cfdfcc 100644
81029--- a/net/ipv6/inet6_connection_sock.c
81030+++ b/net/ipv6/inet6_connection_sock.c
81031@@ -152,7 +152,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
81032 #ifdef CONFIG_XFRM
81033 {
81034 struct rt6_info *rt = (struct rt6_info *)dst;
81035- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
81036+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
81037 }
81038 #endif
81039 }
81040@@ -167,7 +167,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
81041 #ifdef CONFIG_XFRM
81042 if (dst) {
81043 struct rt6_info *rt = (struct rt6_info *)dst;
81044- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
81045+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
81046 sk->sk_dst_cache = NULL;
81047 dst_release(dst);
81048 dst = NULL;
81049diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
81050index 093e9b2..f72cddb 100644
81051--- a/net/ipv6/inet6_hashtables.c
81052+++ b/net/ipv6/inet6_hashtables.c
81053@@ -119,7 +119,7 @@ out:
81054 }
81055 EXPORT_SYMBOL(__inet6_lookup_established);
81056
81057-static int inline compute_score(struct sock *sk, struct net *net,
81058+static inline int compute_score(struct sock *sk, struct net *net,
81059 const unsigned short hnum,
81060 const struct in6_addr *daddr,
81061 const int dif)
81062diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
81063index 4f7aaf6..f7acf45 100644
81064--- a/net/ipv6/ipv6_sockglue.c
81065+++ b/net/ipv6/ipv6_sockglue.c
81066@@ -130,6 +130,8 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
81067 int val, valbool;
81068 int retv = -ENOPROTOOPT;
81069
81070+ pax_track_stack();
81071+
81072 if (optval == NULL)
81073 val=0;
81074 else {
81075@@ -881,6 +883,8 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
81076 int len;
81077 int val;
81078
81079+ pax_track_stack();
81080+
81081 if (ip6_mroute_opt(optname))
81082 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
81083
81084@@ -922,7 +926,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
81085 if (sk->sk_type != SOCK_STREAM)
81086 return -ENOPROTOOPT;
81087
81088- msg.msg_control = optval;
81089+ msg.msg_control = (void __force_kernel *)optval;
81090 msg.msg_controllen = len;
81091 msg.msg_flags = 0;
81092
81093diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
81094index 1cf3f0c..1d4376f 100644
81095--- a/net/ipv6/netfilter/ip6_queue.c
81096+++ b/net/ipv6/netfilter/ip6_queue.c
81097@@ -287,6 +287,9 @@ ipq_mangle_ipv6(ipq_verdict_msg_t *v, struct nf_queue_entry *e)
81098
81099 if (v->data_len < sizeof(*user_iph))
81100 return 0;
81101+ if (v->data_len > 65535)
81102+ return -EMSGSIZE;
81103+
81104 diff = v->data_len - e->skb->len;
81105 if (diff < 0) {
81106 if (pskb_trim(e->skb, v->data_len))
81107@@ -411,7 +414,8 @@ ipq_dev_drop(int ifindex)
81108 static inline void
81109 __ipq_rcv_skb(struct sk_buff *skb)
81110 {
81111- int status, type, pid, flags, nlmsglen, skblen;
81112+ int status, type, pid, flags;
81113+ unsigned int nlmsglen, skblen;
81114 struct nlmsghdr *nlh;
81115
81116 skblen = skb->len;
81117diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
81118index 78b5a36..7f37433 100644
81119--- a/net/ipv6/netfilter/ip6_tables.c
81120+++ b/net/ipv6/netfilter/ip6_tables.c
81121@@ -1173,6 +1173,7 @@ static int get_info(struct net *net, void __user *user, int *len, int compat)
81122 private = &tmp;
81123 }
81124 #endif
81125+ memset(&info, 0, sizeof(info));
81126 info.valid_hooks = t->valid_hooks;
81127 memcpy(info.hook_entry, private->hook_entry,
81128 sizeof(info.hook_entry));
81129diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
81130index 4f24570..b813b34 100644
81131--- a/net/ipv6/raw.c
81132+++ b/net/ipv6/raw.c
81133@@ -375,14 +375,14 @@ static inline int rawv6_rcv_skb(struct sock * sk, struct sk_buff * skb)
81134 {
81135 if ((raw6_sk(sk)->checksum || sk->sk_filter) &&
81136 skb_checksum_complete(skb)) {
81137- atomic_inc(&sk->sk_drops);
81138+ atomic_inc_unchecked(&sk->sk_drops);
81139 kfree_skb(skb);
81140 return NET_RX_DROP;
81141 }
81142
81143 /* Charge it to the socket. */
81144 if (sock_queue_rcv_skb(sk,skb)<0) {
81145- atomic_inc(&sk->sk_drops);
81146+ atomic_inc_unchecked(&sk->sk_drops);
81147 kfree_skb(skb);
81148 return NET_RX_DROP;
81149 }
81150@@ -403,7 +403,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81151 struct raw6_sock *rp = raw6_sk(sk);
81152
81153 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
81154- atomic_inc(&sk->sk_drops);
81155+ atomic_inc_unchecked(&sk->sk_drops);
81156 kfree_skb(skb);
81157 return NET_RX_DROP;
81158 }
81159@@ -427,7 +427,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81160
81161 if (inet->hdrincl) {
81162 if (skb_checksum_complete(skb)) {
81163- atomic_inc(&sk->sk_drops);
81164+ atomic_inc_unchecked(&sk->sk_drops);
81165 kfree_skb(skb);
81166 return NET_RX_DROP;
81167 }
81168@@ -518,7 +518,7 @@ csum_copy_err:
81169 as some normal condition.
81170 */
81171 err = (flags&MSG_DONTWAIT) ? -EAGAIN : -EHOSTUNREACH;
81172- atomic_inc(&sk->sk_drops);
81173+ atomic_inc_unchecked(&sk->sk_drops);
81174 goto out;
81175 }
81176
81177@@ -600,7 +600,7 @@ out:
81178 return err;
81179 }
81180
81181-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
81182+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
81183 struct flowi *fl, struct rt6_info *rt,
81184 unsigned int flags)
81185 {
81186@@ -738,6 +738,8 @@ static int rawv6_sendmsg(struct kiocb *iocb, struct sock *sk,
81187 u16 proto;
81188 int err;
81189
81190+ pax_track_stack();
81191+
81192 /* Rough check on arithmetic overflow,
81193 better check is made in ip6_append_data().
81194 */
81195@@ -916,12 +918,17 @@ do_confirm:
81196 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
81197 char __user *optval, int optlen)
81198 {
81199+ struct icmp6_filter filter;
81200+
81201 switch (optname) {
81202 case ICMPV6_FILTER:
81203+ if (optlen < 0)
81204+ return -EINVAL;
81205 if (optlen > sizeof(struct icmp6_filter))
81206 optlen = sizeof(struct icmp6_filter);
81207- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
81208+ if (copy_from_user(&filter, optval, optlen))
81209 return -EFAULT;
81210+ raw6_sk(sk)->filter = filter;
81211 return 0;
81212 default:
81213 return -ENOPROTOOPT;
81214@@ -934,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81215 char __user *optval, int __user *optlen)
81216 {
81217 int len;
81218+ struct icmp6_filter filter;
81219
81220 switch (optname) {
81221 case ICMPV6_FILTER:
81222@@ -945,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81223 len = sizeof(struct icmp6_filter);
81224 if (put_user(len, optlen))
81225 return -EFAULT;
81226- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
81227+ filter = raw6_sk(sk)->filter;
81228+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
81229 return -EFAULT;
81230 return 0;
81231 default:
81232@@ -1241,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81233 0, 0L, 0,
81234 sock_i_uid(sp), 0,
81235 sock_i_ino(sp),
81236- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81237+ atomic_read(&sp->sk_refcnt),
81238+#ifdef CONFIG_GRKERNSEC_HIDESYM
81239+ NULL,
81240+#else
81241+ sp,
81242+#endif
81243+ atomic_read_unchecked(&sp->sk_drops));
81244 }
81245
81246 static int raw6_seq_show(struct seq_file *seq, void *v)
81247diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
81248index faae6df..d4430c1 100644
81249--- a/net/ipv6/tcp_ipv6.c
81250+++ b/net/ipv6/tcp_ipv6.c
81251@@ -89,6 +89,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
81252 }
81253 #endif
81254
81255+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81256+extern int grsec_enable_blackhole;
81257+#endif
81258+
81259 static void tcp_v6_hash(struct sock *sk)
81260 {
81261 if (sk->sk_state != TCP_CLOSE) {
81262@@ -1579,6 +1583,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
81263 return 0;
81264
81265 reset:
81266+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81267+ if (!grsec_enable_blackhole)
81268+#endif
81269 tcp_v6_send_reset(sk, skb);
81270 discard:
81271 if (opt_skb)
81272@@ -1656,12 +1663,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
81273 TCP_SKB_CB(skb)->sacked = 0;
81274
81275 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81276- if (!sk)
81277+ if (!sk) {
81278+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81279+ ret = 1;
81280+#endif
81281 goto no_tcp_socket;
81282+ }
81283
81284 process:
81285- if (sk->sk_state == TCP_TIME_WAIT)
81286+ if (sk->sk_state == TCP_TIME_WAIT) {
81287+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81288+ ret = 2;
81289+#endif
81290 goto do_time_wait;
81291+ }
81292
81293 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
81294 goto discard_and_relse;
81295@@ -1701,6 +1716,10 @@ no_tcp_socket:
81296 bad_packet:
81297 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81298 } else {
81299+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81300+ if (!grsec_enable_blackhole || (ret == 1 &&
81301+ (skb->dev->flags & IFF_LOOPBACK)))
81302+#endif
81303 tcp_v6_send_reset(NULL, skb);
81304 }
81305
81306@@ -1916,7 +1935,13 @@ static void get_openreq6(struct seq_file *seq,
81307 uid,
81308 0, /* non standard timer */
81309 0, /* open_requests have no inode */
81310- 0, req);
81311+ 0,
81312+#ifdef CONFIG_GRKERNSEC_HIDESYM
81313+ NULL
81314+#else
81315+ req
81316+#endif
81317+ );
81318 }
81319
81320 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
81321@@ -1966,7 +1991,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
81322 sock_i_uid(sp),
81323 icsk->icsk_probes_out,
81324 sock_i_ino(sp),
81325- atomic_read(&sp->sk_refcnt), sp,
81326+ atomic_read(&sp->sk_refcnt),
81327+#ifdef CONFIG_GRKERNSEC_HIDESYM
81328+ NULL,
81329+#else
81330+ sp,
81331+#endif
81332 jiffies_to_clock_t(icsk->icsk_rto),
81333 jiffies_to_clock_t(icsk->icsk_ack.ato),
81334 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
81335@@ -2001,7 +2031,13 @@ static void get_timewait6_sock(struct seq_file *seq,
81336 dest->s6_addr32[2], dest->s6_addr32[3], destp,
81337 tw->tw_substate, 0, 0,
81338 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
81339- atomic_read(&tw->tw_refcnt), tw);
81340+ atomic_read(&tw->tw_refcnt),
81341+#ifdef CONFIG_GRKERNSEC_HIDESYM
81342+ NULL
81343+#else
81344+ tw
81345+#endif
81346+ );
81347 }
81348
81349 static int tcp6_seq_show(struct seq_file *seq, void *v)
81350diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
81351index 9cc6289..052c521 100644
81352--- a/net/ipv6/udp.c
81353+++ b/net/ipv6/udp.c
81354@@ -49,6 +49,10 @@
81355 #include <linux/seq_file.h>
81356 #include "udp_impl.h"
81357
81358+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81359+extern int grsec_enable_blackhole;
81360+#endif
81361+
81362 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
81363 {
81364 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
81365@@ -391,7 +395,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
81366 if (rc == -ENOMEM) {
81367 UDP6_INC_STATS_BH(sock_net(sk),
81368 UDP_MIB_RCVBUFERRORS, is_udplite);
81369- atomic_inc(&sk->sk_drops);
81370+ atomic_inc_unchecked(&sk->sk_drops);
81371 }
81372 goto drop;
81373 }
81374@@ -590,6 +594,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81375 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
81376 proto == IPPROTO_UDPLITE);
81377
81378+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81379+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81380+#endif
81381 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, dev);
81382
81383 kfree_skb(skb);
81384@@ -1209,8 +1216,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
81385 0, 0L, 0,
81386 sock_i_uid(sp), 0,
81387 sock_i_ino(sp),
81388- atomic_read(&sp->sk_refcnt), sp,
81389- atomic_read(&sp->sk_drops));
81390+ atomic_read(&sp->sk_refcnt),
81391+#ifdef CONFIG_GRKERNSEC_HIDESYM
81392+ NULL,
81393+#else
81394+ sp,
81395+#endif
81396+ atomic_read_unchecked(&sp->sk_drops));
81397 }
81398
81399 int udp6_seq_show(struct seq_file *seq, void *v)
81400diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
81401index 811984d..11f59b7 100644
81402--- a/net/irda/ircomm/ircomm_tty.c
81403+++ b/net/irda/ircomm/ircomm_tty.c
81404@@ -280,16 +280,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81405 add_wait_queue(&self->open_wait, &wait);
81406
81407 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
81408- __FILE__,__LINE__, tty->driver->name, self->open_count );
81409+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
81410
81411 /* As far as I can see, we protect open_count - Jean II */
81412 spin_lock_irqsave(&self->spinlock, flags);
81413 if (!tty_hung_up_p(filp)) {
81414 extra_count = 1;
81415- self->open_count--;
81416+ local_dec(&self->open_count);
81417 }
81418 spin_unlock_irqrestore(&self->spinlock, flags);
81419- self->blocked_open++;
81420+ local_inc(&self->blocked_open);
81421
81422 while (1) {
81423 if (tty->termios->c_cflag & CBAUD) {
81424@@ -329,7 +329,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81425 }
81426
81427 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
81428- __FILE__,__LINE__, tty->driver->name, self->open_count );
81429+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
81430
81431 schedule();
81432 }
81433@@ -340,13 +340,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81434 if (extra_count) {
81435 /* ++ is not atomic, so this should be protected - Jean II */
81436 spin_lock_irqsave(&self->spinlock, flags);
81437- self->open_count++;
81438+ local_inc(&self->open_count);
81439 spin_unlock_irqrestore(&self->spinlock, flags);
81440 }
81441- self->blocked_open--;
81442+ local_dec(&self->blocked_open);
81443
81444 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
81445- __FILE__,__LINE__, tty->driver->name, self->open_count);
81446+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
81447
81448 if (!retval)
81449 self->flags |= ASYNC_NORMAL_ACTIVE;
81450@@ -415,14 +415,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
81451 }
81452 /* ++ is not atomic, so this should be protected - Jean II */
81453 spin_lock_irqsave(&self->spinlock, flags);
81454- self->open_count++;
81455+ local_inc(&self->open_count);
81456
81457 tty->driver_data = self;
81458 self->tty = tty;
81459 spin_unlock_irqrestore(&self->spinlock, flags);
81460
81461 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
81462- self->line, self->open_count);
81463+ self->line, local_read(&self->open_count));
81464
81465 /* Not really used by us, but lets do it anyway */
81466 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
81467@@ -511,7 +511,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
81468 return;
81469 }
81470
81471- if ((tty->count == 1) && (self->open_count != 1)) {
81472+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
81473 /*
81474 * Uh, oh. tty->count is 1, which means that the tty
81475 * structure will be freed. state->count should always
81476@@ -521,16 +521,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
81477 */
81478 IRDA_DEBUG(0, "%s(), bad serial port count; "
81479 "tty->count is 1, state->count is %d\n", __func__ ,
81480- self->open_count);
81481- self->open_count = 1;
81482+ local_read(&self->open_count));
81483+ local_set(&self->open_count, 1);
81484 }
81485
81486- if (--self->open_count < 0) {
81487+ if (local_dec_return(&self->open_count) < 0) {
81488 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
81489- __func__, self->line, self->open_count);
81490- self->open_count = 0;
81491+ __func__, self->line, local_read(&self->open_count));
81492+ local_set(&self->open_count, 0);
81493 }
81494- if (self->open_count) {
81495+ if (local_read(&self->open_count)) {
81496 spin_unlock_irqrestore(&self->spinlock, flags);
81497
81498 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
81499@@ -562,7 +562,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
81500 tty->closing = 0;
81501 self->tty = NULL;
81502
81503- if (self->blocked_open) {
81504+ if (local_read(&self->blocked_open)) {
81505 if (self->close_delay)
81506 schedule_timeout_interruptible(self->close_delay);
81507 wake_up_interruptible(&self->open_wait);
81508@@ -1017,7 +1017,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
81509 spin_lock_irqsave(&self->spinlock, flags);
81510 self->flags &= ~ASYNC_NORMAL_ACTIVE;
81511 self->tty = NULL;
81512- self->open_count = 0;
81513+ local_set(&self->open_count, 0);
81514 spin_unlock_irqrestore(&self->spinlock, flags);
81515
81516 wake_up_interruptible(&self->open_wait);
81517@@ -1369,7 +1369,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
81518 seq_putc(m, '\n');
81519
81520 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
81521- seq_printf(m, "Open count: %d\n", self->open_count);
81522+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
81523 seq_printf(m, "Max data size: %d\n", self->max_data_size);
81524 seq_printf(m, "Max header size: %d\n", self->max_header_size);
81525
81526diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
81527index bada1b9..f325943 100644
81528--- a/net/iucv/af_iucv.c
81529+++ b/net/iucv/af_iucv.c
81530@@ -651,10 +651,10 @@ static int iucv_sock_autobind(struct sock *sk)
81531
81532 write_lock_bh(&iucv_sk_list.lock);
81533
81534- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
81535+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81536 while (__iucv_get_sock_by_name(name)) {
81537 sprintf(name, "%08x",
81538- atomic_inc_return(&iucv_sk_list.autobind_name));
81539+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81540 }
81541
81542 write_unlock_bh(&iucv_sk_list.lock);
81543diff --git a/net/key/af_key.c b/net/key/af_key.c
81544index 4e98193..439b449 100644
81545--- a/net/key/af_key.c
81546+++ b/net/key/af_key.c
81547@@ -2489,6 +2489,8 @@ static int pfkey_migrate(struct sock *sk, struct sk_buff *skb,
81548 struct xfrm_migrate m[XFRM_MAX_DEPTH];
81549 struct xfrm_kmaddress k;
81550
81551+ pax_track_stack();
81552+
81553 if (!present_and_same_family(ext_hdrs[SADB_EXT_ADDRESS_SRC - 1],
81554 ext_hdrs[SADB_EXT_ADDRESS_DST - 1]) ||
81555 !ext_hdrs[SADB_X_EXT_POLICY - 1]) {
81556@@ -3660,7 +3662,11 @@ static int pfkey_seq_show(struct seq_file *f, void *v)
81557 seq_printf(f ,"sk RefCnt Rmem Wmem User Inode\n");
81558 else
81559 seq_printf(f ,"%p %-6d %-6u %-6u %-6u %-6lu\n",
81560+#ifdef CONFIG_GRKERNSEC_HIDESYM
81561+ NULL,
81562+#else
81563 s,
81564+#endif
81565 atomic_read(&s->sk_refcnt),
81566 sk_rmem_alloc_get(s),
81567 sk_wmem_alloc_get(s),
81568diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
81569index bda96d1..c038b72 100644
81570--- a/net/lapb/lapb_iface.c
81571+++ b/net/lapb/lapb_iface.c
81572@@ -157,7 +157,7 @@ int lapb_register(struct net_device *dev, struct lapb_register_struct *callbacks
81573 goto out;
81574
81575 lapb->dev = dev;
81576- lapb->callbacks = *callbacks;
81577+ lapb->callbacks = callbacks;
81578
81579 __lapb_insert_cb(lapb);
81580
81581@@ -379,32 +379,32 @@ int lapb_data_received(struct net_device *dev, struct sk_buff *skb)
81582
81583 void lapb_connect_confirmation(struct lapb_cb *lapb, int reason)
81584 {
81585- if (lapb->callbacks.connect_confirmation)
81586- lapb->callbacks.connect_confirmation(lapb->dev, reason);
81587+ if (lapb->callbacks->connect_confirmation)
81588+ lapb->callbacks->connect_confirmation(lapb->dev, reason);
81589 }
81590
81591 void lapb_connect_indication(struct lapb_cb *lapb, int reason)
81592 {
81593- if (lapb->callbacks.connect_indication)
81594- lapb->callbacks.connect_indication(lapb->dev, reason);
81595+ if (lapb->callbacks->connect_indication)
81596+ lapb->callbacks->connect_indication(lapb->dev, reason);
81597 }
81598
81599 void lapb_disconnect_confirmation(struct lapb_cb *lapb, int reason)
81600 {
81601- if (lapb->callbacks.disconnect_confirmation)
81602- lapb->callbacks.disconnect_confirmation(lapb->dev, reason);
81603+ if (lapb->callbacks->disconnect_confirmation)
81604+ lapb->callbacks->disconnect_confirmation(lapb->dev, reason);
81605 }
81606
81607 void lapb_disconnect_indication(struct lapb_cb *lapb, int reason)
81608 {
81609- if (lapb->callbacks.disconnect_indication)
81610- lapb->callbacks.disconnect_indication(lapb->dev, reason);
81611+ if (lapb->callbacks->disconnect_indication)
81612+ lapb->callbacks->disconnect_indication(lapb->dev, reason);
81613 }
81614
81615 int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
81616 {
81617- if (lapb->callbacks.data_indication)
81618- return lapb->callbacks.data_indication(lapb->dev, skb);
81619+ if (lapb->callbacks->data_indication)
81620+ return lapb->callbacks->data_indication(lapb->dev, skb);
81621
81622 kfree_skb(skb);
81623 return NET_RX_SUCCESS; /* For now; must be != NET_RX_DROP */
81624@@ -414,8 +414,8 @@ int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
81625 {
81626 int used = 0;
81627
81628- if (lapb->callbacks.data_transmit) {
81629- lapb->callbacks.data_transmit(lapb->dev, skb);
81630+ if (lapb->callbacks->data_transmit) {
81631+ lapb->callbacks->data_transmit(lapb->dev, skb);
81632 used = 1;
81633 }
81634
81635diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81636index fe2d3f8..e57f683 100644
81637--- a/net/mac80211/cfg.c
81638+++ b/net/mac80211/cfg.c
81639@@ -1369,7 +1369,7 @@ static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
81640 return err;
81641 }
81642
81643-struct cfg80211_ops mac80211_config_ops = {
81644+const struct cfg80211_ops mac80211_config_ops = {
81645 .add_virtual_intf = ieee80211_add_iface,
81646 .del_virtual_intf = ieee80211_del_iface,
81647 .change_virtual_intf = ieee80211_change_iface,
81648diff --git a/net/mac80211/cfg.h b/net/mac80211/cfg.h
81649index 7d7879f..2d51f62 100644
81650--- a/net/mac80211/cfg.h
81651+++ b/net/mac80211/cfg.h
81652@@ -4,6 +4,6 @@
81653 #ifndef __CFG_H
81654 #define __CFG_H
81655
81656-extern struct cfg80211_ops mac80211_config_ops;
81657+extern const struct cfg80211_ops mac80211_config_ops;
81658
81659 #endif /* __CFG_H */
81660diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
81661index 99c7525..9cb4937 100644
81662--- a/net/mac80211/debugfs_key.c
81663+++ b/net/mac80211/debugfs_key.c
81664@@ -211,9 +211,13 @@ static ssize_t key_key_read(struct file *file, char __user *userbuf,
81665 size_t count, loff_t *ppos)
81666 {
81667 struct ieee80211_key *key = file->private_data;
81668- int i, res, bufsize = 2 * key->conf.keylen + 2;
81669+ int i, bufsize = 2 * key->conf.keylen + 2;
81670 char *buf = kmalloc(bufsize, GFP_KERNEL);
81671 char *p = buf;
81672+ ssize_t res;
81673+
81674+ if (buf == NULL)
81675+ return -ENOMEM;
81676
81677 for (i = 0; i < key->conf.keylen; i++)
81678 p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
81679diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
81680index 33a2e89..08650c8 100644
81681--- a/net/mac80211/debugfs_sta.c
81682+++ b/net/mac80211/debugfs_sta.c
81683@@ -124,6 +124,8 @@ static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
81684 int i;
81685 struct sta_info *sta = file->private_data;
81686
81687+ pax_track_stack();
81688+
81689 spin_lock_bh(&sta->lock);
81690 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n",
81691 sta->ampdu_mlme.dialog_token_allocator + 1);
81692diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81693index ca62bfe..6657a03 100644
81694--- a/net/mac80211/ieee80211_i.h
81695+++ b/net/mac80211/ieee80211_i.h
81696@@ -25,6 +25,7 @@
81697 #include <linux/etherdevice.h>
81698 #include <net/cfg80211.h>
81699 #include <net/mac80211.h>
81700+#include <asm/local.h>
81701 #include "key.h"
81702 #include "sta_info.h"
81703
81704@@ -635,7 +636,7 @@ struct ieee80211_local {
81705 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81706 spinlock_t queue_stop_reason_lock;
81707
81708- int open_count;
81709+ local_t open_count;
81710 int monitors, cooked_mntrs;
81711 /* number of interfaces with corresponding FIF_ flags */
81712 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll;
81713diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
81714index 079c500..eb3c6d4 100644
81715--- a/net/mac80211/iface.c
81716+++ b/net/mac80211/iface.c
81717@@ -166,7 +166,7 @@ static int ieee80211_open(struct net_device *dev)
81718 break;
81719 }
81720
81721- if (local->open_count == 0) {
81722+ if (local_read(&local->open_count) == 0) {
81723 res = drv_start(local);
81724 if (res)
81725 goto err_del_bss;
81726@@ -196,7 +196,7 @@ static int ieee80211_open(struct net_device *dev)
81727 * Validate the MAC address for this device.
81728 */
81729 if (!is_valid_ether_addr(dev->dev_addr)) {
81730- if (!local->open_count)
81731+ if (!local_read(&local->open_count))
81732 drv_stop(local);
81733 return -EADDRNOTAVAIL;
81734 }
81735@@ -292,7 +292,7 @@ static int ieee80211_open(struct net_device *dev)
81736
81737 hw_reconf_flags |= __ieee80211_recalc_idle(local);
81738
81739- local->open_count++;
81740+ local_inc(&local->open_count);
81741 if (hw_reconf_flags) {
81742 ieee80211_hw_config(local, hw_reconf_flags);
81743 /*
81744@@ -320,7 +320,7 @@ static int ieee80211_open(struct net_device *dev)
81745 err_del_interface:
81746 drv_remove_interface(local, &conf);
81747 err_stop:
81748- if (!local->open_count)
81749+ if (!local_read(&local->open_count))
81750 drv_stop(local);
81751 err_del_bss:
81752 sdata->bss = NULL;
81753@@ -420,7 +420,7 @@ static int ieee80211_stop(struct net_device *dev)
81754 WARN_ON(!list_empty(&sdata->u.ap.vlans));
81755 }
81756
81757- local->open_count--;
81758+ local_dec(&local->open_count);
81759
81760 switch (sdata->vif.type) {
81761 case NL80211_IFTYPE_AP_VLAN:
81762@@ -526,7 +526,7 @@ static int ieee80211_stop(struct net_device *dev)
81763
81764 ieee80211_recalc_ps(local, -1);
81765
81766- if (local->open_count == 0) {
81767+ if (local_read(&local->open_count) == 0) {
81768 ieee80211_clear_tx_pending(local);
81769 ieee80211_stop_device(local);
81770
81771diff --git a/net/mac80211/main.c b/net/mac80211/main.c
81772index 2dfe176..74e4388 100644
81773--- a/net/mac80211/main.c
81774+++ b/net/mac80211/main.c
81775@@ -145,7 +145,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
81776 local->hw.conf.power_level = power;
81777 }
81778
81779- if (changed && local->open_count) {
81780+ if (changed && local_read(&local->open_count)) {
81781 ret = drv_config(local, changed);
81782 /*
81783 * Goal:
81784diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
81785index e67eea7..fcc227e 100644
81786--- a/net/mac80211/mlme.c
81787+++ b/net/mac80211/mlme.c
81788@@ -1438,6 +1438,8 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
81789 bool have_higher_than_11mbit = false, newsta = false;
81790 u16 ap_ht_cap_flags;
81791
81792+ pax_track_stack();
81793+
81794 /*
81795 * AssocResp and ReassocResp have identical structure, so process both
81796 * of them in this function.
81797diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
81798index e535f1c..4d733d1 100644
81799--- a/net/mac80211/pm.c
81800+++ b/net/mac80211/pm.c
81801@@ -107,7 +107,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
81802 }
81803
81804 /* stop hardware - this must stop RX */
81805- if (local->open_count)
81806+ if (local_read(&local->open_count))
81807 ieee80211_stop_device(local);
81808
81809 local->suspended = true;
81810diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
81811index b33efc4..0a2efb6 100644
81812--- a/net/mac80211/rate.c
81813+++ b/net/mac80211/rate.c
81814@@ -287,7 +287,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
81815 struct rate_control_ref *ref, *old;
81816
81817 ASSERT_RTNL();
81818- if (local->open_count)
81819+ if (local_read(&local->open_count))
81820 return -EBUSY;
81821
81822 ref = rate_control_alloc(name, local);
81823diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
81824index b1d7904..57e4da7 100644
81825--- a/net/mac80211/tx.c
81826+++ b/net/mac80211/tx.c
81827@@ -173,7 +173,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
81828 return cpu_to_le16(dur);
81829 }
81830
81831-static int inline is_ieee80211_device(struct ieee80211_local *local,
81832+static inline int is_ieee80211_device(struct ieee80211_local *local,
81833 struct net_device *dev)
81834 {
81835 return local == wdev_priv(dev->ieee80211_ptr);
81836diff --git a/net/mac80211/util.c b/net/mac80211/util.c
81837index 31b1085..48fb26d 100644
81838--- a/net/mac80211/util.c
81839+++ b/net/mac80211/util.c
81840@@ -1042,7 +1042,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
81841 local->resuming = true;
81842
81843 /* restart hardware */
81844- if (local->open_count) {
81845+ if (local_read(&local->open_count)) {
81846 /*
81847 * Upon resume hardware can sometimes be goofy due to
81848 * various platform / driver / bus issues, so restarting
81849diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
81850index 634d14a..b35a608 100644
81851--- a/net/netfilter/Kconfig
81852+++ b/net/netfilter/Kconfig
81853@@ -635,6 +635,16 @@ config NETFILTER_XT_MATCH_ESP
81854
81855 To compile it as a module, choose M here. If unsure, say N.
81856
81857+config NETFILTER_XT_MATCH_GRADM
81858+ tristate '"gradm" match support'
81859+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
81860+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
81861+ ---help---
81862+ The gradm match allows to match on grsecurity RBAC being enabled.
81863+ It is useful when iptables rules are applied early on bootup to
81864+ prevent connections to the machine (except from a trusted host)
81865+ while the RBAC system is disabled.
81866+
81867 config NETFILTER_XT_MATCH_HASHLIMIT
81868 tristate '"hashlimit" match support'
81869 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
81870diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
81871index 49f62ee..a17b2c6 100644
81872--- a/net/netfilter/Makefile
81873+++ b/net/netfilter/Makefile
81874@@ -68,6 +68,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_CONNTRACK) += xt_conntrack.o
81875 obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
81876 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
81877 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
81878+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
81879 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
81880 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
81881 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
81882diff --git a/net/netfilter/ipvs/ip_vs_app.c b/net/netfilter/ipvs/ip_vs_app.c
81883index 3c7e427..724043c 100644
81884--- a/net/netfilter/ipvs/ip_vs_app.c
81885+++ b/net/netfilter/ipvs/ip_vs_app.c
81886@@ -564,7 +564,7 @@ static const struct file_operations ip_vs_app_fops = {
81887 .open = ip_vs_app_open,
81888 .read = seq_read,
81889 .llseek = seq_lseek,
81890- .release = seq_release,
81891+ .release = seq_release_net,
81892 };
81893 #endif
81894
81895diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
81896index 95682e5..457dbac 100644
81897--- a/net/netfilter/ipvs/ip_vs_conn.c
81898+++ b/net/netfilter/ipvs/ip_vs_conn.c
81899@@ -453,10 +453,10 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
81900 /* if the connection is not template and is created
81901 * by sync, preserve the activity flag.
81902 */
81903- cp->flags |= atomic_read(&dest->conn_flags) &
81904+ cp->flags |= atomic_read_unchecked(&dest->conn_flags) &
81905 (~IP_VS_CONN_F_INACTIVE);
81906 else
81907- cp->flags |= atomic_read(&dest->conn_flags);
81908+ cp->flags |= atomic_read_unchecked(&dest->conn_flags);
81909 cp->dest = dest;
81910
81911 IP_VS_DBG_BUF(7, "Bind-dest %s c:%s:%d v:%s:%d "
81912@@ -723,7 +723,7 @@ ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport,
81913 atomic_set(&cp->refcnt, 1);
81914
81915 atomic_set(&cp->n_control, 0);
81916- atomic_set(&cp->in_pkts, 0);
81917+ atomic_set_unchecked(&cp->in_pkts, 0);
81918
81919 atomic_inc(&ip_vs_conn_count);
81920 if (flags & IP_VS_CONN_F_NO_CPORT)
81921@@ -871,7 +871,7 @@ static const struct file_operations ip_vs_conn_fops = {
81922 .open = ip_vs_conn_open,
81923 .read = seq_read,
81924 .llseek = seq_lseek,
81925- .release = seq_release,
81926+ .release = seq_release_net,
81927 };
81928
81929 static const char *ip_vs_origin_name(unsigned flags)
81930@@ -934,7 +934,7 @@ static const struct file_operations ip_vs_conn_sync_fops = {
81931 .open = ip_vs_conn_sync_open,
81932 .read = seq_read,
81933 .llseek = seq_lseek,
81934- .release = seq_release,
81935+ .release = seq_release_net,
81936 };
81937
81938 #endif
81939@@ -961,7 +961,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
81940
81941 /* Don't drop the entry if its number of incoming packets is not
81942 located in [0, 8] */
81943- i = atomic_read(&cp->in_pkts);
81944+ i = atomic_read_unchecked(&cp->in_pkts);
81945 if (i > 8 || i < 0) return 0;
81946
81947 if (!todrop_rate[i]) return 0;
81948diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
81949index b95699f..5fee919 100644
81950--- a/net/netfilter/ipvs/ip_vs_core.c
81951+++ b/net/netfilter/ipvs/ip_vs_core.c
81952@@ -485,7 +485,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
81953 ret = cp->packet_xmit(skb, cp, pp);
81954 /* do not touch skb anymore */
81955
81956- atomic_inc(&cp->in_pkts);
81957+ atomic_inc_unchecked(&cp->in_pkts);
81958 ip_vs_conn_put(cp);
81959 return ret;
81960 }
81961@@ -1357,7 +1357,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb,
81962 * Sync connection if it is about to close to
81963 * encorage the standby servers to update the connections timeout
81964 */
81965- pkts = atomic_add_return(1, &cp->in_pkts);
81966+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81967 if (af == AF_INET &&
81968 (ip_vs_sync_state & IP_VS_STATE_MASTER) &&
81969 (((cp->protocol != IPPROTO_TCP ||
81970diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
81971index 02b2610..2d89424 100644
81972--- a/net/netfilter/ipvs/ip_vs_ctl.c
81973+++ b/net/netfilter/ipvs/ip_vs_ctl.c
81974@@ -792,7 +792,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc,
81975 ip_vs_rs_hash(dest);
81976 write_unlock_bh(&__ip_vs_rs_lock);
81977 }
81978- atomic_set(&dest->conn_flags, conn_flags);
81979+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
81980
81981 /* bind the service */
81982 if (!dest->svc) {
81983@@ -1888,7 +1888,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81984 " %-7s %-6d %-10d %-10d\n",
81985 &dest->addr.in6,
81986 ntohs(dest->port),
81987- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81988+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81989 atomic_read(&dest->weight),
81990 atomic_read(&dest->activeconns),
81991 atomic_read(&dest->inactconns));
81992@@ -1899,7 +1899,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81993 "%-7s %-6d %-10d %-10d\n",
81994 ntohl(dest->addr.ip),
81995 ntohs(dest->port),
81996- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81997+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81998 atomic_read(&dest->weight),
81999 atomic_read(&dest->activeconns),
82000 atomic_read(&dest->inactconns));
82001@@ -1927,7 +1927,7 @@ static const struct file_operations ip_vs_info_fops = {
82002 .open = ip_vs_info_open,
82003 .read = seq_read,
82004 .llseek = seq_lseek,
82005- .release = seq_release_private,
82006+ .release = seq_release_net,
82007 };
82008
82009 #endif
82010@@ -1976,7 +1976,7 @@ static const struct file_operations ip_vs_stats_fops = {
82011 .open = ip_vs_stats_seq_open,
82012 .read = seq_read,
82013 .llseek = seq_lseek,
82014- .release = single_release,
82015+ .release = single_release_net,
82016 };
82017
82018 #endif
82019@@ -2292,7 +2292,7 @@ __ip_vs_get_dest_entries(const struct ip_vs_get_dests *get,
82020
82021 entry.addr = dest->addr.ip;
82022 entry.port = dest->port;
82023- entry.conn_flags = atomic_read(&dest->conn_flags);
82024+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
82025 entry.weight = atomic_read(&dest->weight);
82026 entry.u_threshold = dest->u_threshold;
82027 entry.l_threshold = dest->l_threshold;
82028@@ -2353,6 +2353,8 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
82029 unsigned char arg[128];
82030 int ret = 0;
82031
82032+ pax_track_stack();
82033+
82034 if (!capable(CAP_NET_ADMIN))
82035 return -EPERM;
82036
82037@@ -2802,7 +2804,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
82038 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
82039
82040 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
82041- atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
82042+ atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
82043 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
82044 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
82045 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
82046diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
82047index e177f0d..55e8581 100644
82048--- a/net/netfilter/ipvs/ip_vs_sync.c
82049+++ b/net/netfilter/ipvs/ip_vs_sync.c
82050@@ -438,7 +438,7 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen)
82051
82052 if (opt)
82053 memcpy(&cp->in_seq, opt, sizeof(*opt));
82054- atomic_set(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
82055+ atomic_set_unchecked(&cp->in_pkts, sysctl_ip_vs_sync_threshold[0]);
82056 cp->state = state;
82057 cp->old_state = cp->state;
82058 /*
82059diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
82060index 30b3189..e2e4b55 100644
82061--- a/net/netfilter/ipvs/ip_vs_xmit.c
82062+++ b/net/netfilter/ipvs/ip_vs_xmit.c
82063@@ -875,7 +875,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
82064 else
82065 rc = NF_ACCEPT;
82066 /* do not touch skb anymore */
82067- atomic_inc(&cp->in_pkts);
82068+ atomic_inc_unchecked(&cp->in_pkts);
82069 goto out;
82070 }
82071
82072@@ -949,7 +949,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
82073 else
82074 rc = NF_ACCEPT;
82075 /* do not touch skb anymore */
82076- atomic_inc(&cp->in_pkts);
82077+ atomic_inc_unchecked(&cp->in_pkts);
82078 goto out;
82079 }
82080
82081diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
82082index d521718..d0fd7a1 100644
82083--- a/net/netfilter/nf_conntrack_netlink.c
82084+++ b/net/netfilter/nf_conntrack_netlink.c
82085@@ -706,7 +706,7 @@ ctnetlink_parse_tuple_proto(struct nlattr *attr,
82086 static int
82087 ctnetlink_parse_tuple(const struct nlattr * const cda[],
82088 struct nf_conntrack_tuple *tuple,
82089- enum ctattr_tuple type, u_int8_t l3num)
82090+ enum ctattr_type type, u_int8_t l3num)
82091 {
82092 struct nlattr *tb[CTA_TUPLE_MAX+1];
82093 int err;
82094diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
82095index f900dc3..5e45346 100644
82096--- a/net/netfilter/nfnetlink_log.c
82097+++ b/net/netfilter/nfnetlink_log.c
82098@@ -68,7 +68,7 @@ struct nfulnl_instance {
82099 };
82100
82101 static DEFINE_RWLOCK(instances_lock);
82102-static atomic_t global_seq;
82103+static atomic_unchecked_t global_seq;
82104
82105 #define INSTANCE_BUCKETS 16
82106 static struct hlist_head instance_table[INSTANCE_BUCKETS];
82107@@ -493,7 +493,7 @@ __build_packet_message(struct nfulnl_instance *inst,
82108 /* global sequence number */
82109 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
82110 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
82111- htonl(atomic_inc_return(&global_seq)));
82112+ htonl(atomic_inc_return_unchecked(&global_seq)));
82113
82114 if (data_len) {
82115 struct nlattr *nla;
82116diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
82117new file mode 100644
82118index 0000000..b1bac76
82119--- /dev/null
82120+++ b/net/netfilter/xt_gradm.c
82121@@ -0,0 +1,51 @@
82122+/*
82123+ * gradm match for netfilter
82124